| 91 | | /** |
| 92 | | * Return the URL for the set of $options provided. |
| 93 | | */ |
| 94 | | function url_for($options = array()) { |
| 95 | | $url_base = null; |
| 96 | | $url = array(); |
| 97 | | if(is_string($options)) { |
| 98 | | //$url[] = $options; |
| 99 | | return $options; |
| 100 | | } else { |
| 101 | | $url_base = $_SERVER['HTTP_HOST']; |
| 102 | | if(substr($url_base, -1) == "/") { |
| 103 | | # remove the ending slash |
| 104 | | $url_base = substr($url_base, 0, -1); |
| 105 | | } |
| 106 | | |
| 107 | | if($_SERVER['SERVER_PORT'] == 443) { |
| 108 | | $url_base = "https://".$url_base; |
| 109 | | } else { |
| 110 | | $url_base = "http://".$url_base; |
| 111 | | } |
| 112 | | if(!is_null(TRAX_URL_PREFIX)) { |
| 113 | | $url_base .= "/".TRAX_URL_PREFIX; |
| 114 | | } |
| 115 | | |
| 116 | | if(array_key_exists(":controller", $options)) { |
| 117 | | if($controller = $options[":controller"]) { |
| 118 | | $url[] = $controller; |
| 119 | | } |
| 120 | | } else { |
| 121 | | $controller = $this->controller_path; |
| 122 | | if(substr($controller, 0, 1) == "/") { |
| 123 | | # remove the beginning slash |
| 124 | | $controller = substr($controller, 1); |
| 125 | | } |
| 126 | | $url[] = $controller; |
| 127 | | } |
| 128 | | |
| 129 | | if(count($url)) { |
| 130 | | if(array_key_exists(":action", $options)) { |
| 131 | | if($action = $options[":action"]) { |
| 132 | | $url[] = $action; |
| 133 | | } |
| 134 | | } |
| 135 | | } |
| 136 | | if(count($url) > 1) { |
| 137 | | if(array_key_exists(":id", $options)) { |
| 138 | | if(is_object($options[":id"])) { |
| 139 | | if($id = $options[":id"]->id) { |
| 140 | | $url[] = $id; |
| 141 | | } |
| 142 | | } else { |
| 143 | | if($id = $options[":id"]) { |
| 144 | | $url[] = $id; |
| 145 | | } |
| 146 | | } |
| 147 | | } |
| 148 | | } |
| 149 | | } |
| 150 | | |
| 151 | | if(count($url) && substr($url_base,-1) != "/") { |
| 152 | | $url_base .= "/"; |
| 153 | | } |
| 154 | | |
| 155 | | return $url_base . implode("/", $url); |
| 156 | | } |
| 157 | | |