| 37 | | // The follow block of if/else attempts to retrieve the URI segments automagically |
| 38 | | // Supported methods: CLI, GET, PATH_INFO, ORIG_PATH_INFO, PHP_SELF |
| 39 | | if (PHP_SAPI === 'cli') |
| 40 | | { |
| 41 | | // Command line requires a bit of hacking |
| 42 | | if (isset($_SERVER['argv'][1])) |
| 43 | | { |
| 44 | | self::$segments = $_SERVER['argv'][1]; |
| 45 | | |
| 46 | | // Remove GET string from segments |
| 47 | | if (($query = strrpos(self::$segments, '?')) !== FALSE) |
| 48 | | { |
| 49 | | list (self::$segments, $query) = explode('?', self::$segments); |
| 50 | | |
| 51 | | // Insert query into GET array |
| 52 | | foreach(explode('&', $query) as $pair) |
| 53 | | { |
| 54 | | list ($key, $val) = array_pad(explode('=', $pair), 1, ''); |
| 55 | | |
| 56 | | $_GET[utf8::clean($key)] = utf8::clean($val); |
| 57 | | } |
| 58 | | } |
| 59 | | } |
| 60 | | } |
| 61 | | elseif (count($_GET) === 1 AND current($_GET) == '') |
| 62 | | { |
| 63 | | self::$segments = current(array_keys($_GET)); |
| 64 | | |
| 65 | | // Fixes really stange handling of a suffix in a GET string |
| 66 | | if ($suffix = Config::item('core.url_suffix') AND substr(self::$segments, -(strlen($suffix))) === '_'.substr($suffix, 1)) |
| 67 | | { |
| 68 | | self::$segments = substr(self::$segments, 0, -(strlen($suffix))); |
| 69 | | } |
| 70 | | |
| 71 | | // Destroy GET |
| 72 | | $_GET = array(); |
| 73 | | } |
| 74 | | elseif (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO']) |
| 75 | | { |
| 76 | | self::$segments = $_SERVER['PATH_INFO']; |
| 77 | | } |
| 78 | | elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) |
| 79 | | { |
| 80 | | self::$segments = $_SERVER['ORIG_PATH_INFO']; |
| 81 | | } |
| 82 | | elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) |
| 83 | | { |
| 84 | | self::$segments = $_SERVER['PHP_SELF']; |
| 85 | | } |
| 86 | | |
| 87 | | // Find the URI string based on the location of the front controller |
| 88 | | if (($offset = strpos(self::$segments, KOHANA)) !== FALSE) |
| 89 | | { |
| 90 | | // Add the length of the index file to the offset |
| 91 | | $offset += strlen(KOHANA); |
| 92 | | |
| 93 | | // Get the segment part of the URL |
| 94 | | self::$segments = substr(self::$segments, $offset); |
| 95 | | self::$segments = trim(self::$segments, '/'); |
| 96 | | } |
| 97 | | |
| 98 | | |
| | 183 | } |
| | 184 | } |
| | 185 | |
| | 186 | /* |
| | 187 | * Method: find_uri |
| | 188 | * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. |
| | 189 | */ |
| | 190 | public static function find_uri() |
| | 191 | { |
| | 192 | if (PHP_SAPI === 'cli') |
| | 193 | { |
| | 194 | // Command line requires a bit of hacking |
| | 195 | if (isset($_SERVER['argv'][1])) |
| | 196 | { |
| | 197 | self::$current_uri = $_SERVER['argv'][1]; |
| | 198 | |
| | 199 | // Remove GET string from segments |
| | 200 | if (($query = strpos(self::$current_uri, '?')) !== FALSE) |
| | 201 | { |
| | 202 | list (self::$current_uri, $query) = explode('?', self::$segments, 2); |
| | 203 | |
| | 204 | // Insert query into GET array |
| | 205 | foreach(explode('&', $query) as $pair) |
| | 206 | { |
| | 207 | list ($key, $val) = array_pad(explode('=', $pair), 1, ''); |
| | 208 | |
| | 209 | $_GET[utf8::clean($key)] = utf8::clean($val); |
| | 210 | } |
| | 211 | } |
| | 212 | } |
| | 213 | } |
| | 214 | elseif (count($_GET) === 1 AND current($_GET) == '') |
| | 215 | { |
| | 216 | self::$current_uri = current(array_keys($_GET)); |
| | 217 | |
| | 218 | // Fixes really stange handling of a suffix in a GET string |
| | 219 | if ($suffix = Config::item('core.url_suffix') AND substr(self::$current_uri, -(strlen($suffix))) === '_'.substr($suffix, 1)) |
| | 220 | { |
| | 221 | self::$current_uri = substr(self::$current_uri, 0, -(strlen($suffix))); |
| | 222 | } |
| | 223 | |
| | 224 | // Destroy GET |
| | 225 | $_GET = array(); |
| | 226 | } |
| | 227 | elseif (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO']) |
| | 228 | { |
| | 229 | self::$current_uri = $_SERVER['PATH_INFO']; |
| | 230 | } |
| | 231 | elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) |
| | 232 | { |
| | 233 | self::$current_uri = $_SERVER['ORIG_PATH_INFO']; |
| | 234 | } |
| | 235 | elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) |
| | 236 | { |
| | 237 | self::$current_uri = $_SERVER['PHP_SELF']; |
| | 238 | } |
| | 239 | |
| | 240 | // Find the URI string based on the location of the front controller |
| | 241 | if (($offset = strpos(self::$current_uri, KOHANA)) !== FALSE) |
| | 242 | { |
| | 243 | // Add the length of the index file to the offset |
| | 244 | $offset += strlen(KOHANA); |
| | 245 | |
| | 246 | // Get the segment part of the URL |
| | 247 | self::$current_uri = substr(self::$current_uri, $offset); |
| | 248 | self::$current_uri = trim(self::$current_uri, '/'); |