/** * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. * * @return void */ public static function find_uri() { if (PHP_SAPI === 'cli') { // Command line requires a bit of hacking if (isset($_SERVER['argv'][1])) { self::$current_uri = $_SERVER['argv'][1]; // Remove GET string from segments if (($query = strpos(self::$current_uri, '?')) !== FALSE) { list(self::$current_uri, $query) = explode('?', self::$current_uri, 2); // Parse the query string into $_GET parse_str($query, $_GET); // Convert $_GET to UTF-8 $_GET = utf8::clean($_GET); } } } elseif (isset($_GET['kohana_uri'])) { // Use the URI defined in the query string self::$current_uri = $_GET['kohana_uri']; // Remove the URI from $_GET unset($_GET['kohana_uri']); // Remove the URI from $_SERVER['QUERY_STRING'] $_SERVER['QUERY_STRING'] = preg_replace('~\\bkohana_uri\\b[^&]*+&?~', '', $_SERVER['QUERY_STRING']); } elseif (isset($_SERVER['PATH_INFO']) and $_SERVER['PATH_INFO']) { self::$current_uri = $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) { self::$current_uri = $_SERVER['ORIG_PATH_INFO']; } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) { self::$current_uri = $_SERVER['PHP_SELF']; } // The front controller directory and filename $fc = substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(DOCROOT)); if (($strpos_fc = strpos(self::$current_uri, $fc)) !== FALSE) { // Remove the front controller from the current uri self::$current_uri = substr(self::$current_uri, $strpos_fc + strlen($fc)); } // Remove slashes from the start and end of the URI self::$current_uri = trim(self::$current_uri, '/'); if (self::$current_uri !== '') { if ($suffix = Kohana::config('core.url_suffix') and strpos(self::$current_uri, $suffix) !== FALSE) { // Remove the URL suffix self::$current_uri = preg_replace('#' . preg_quote($suffix) . '$#u', '', self::$current_uri); // Set the URL suffix self::$url_suffix = $suffix; } // Reduce multiple slashes into single slashes self::$current_uri = preg_replace('#//+#', '/', self::$current_uri); } }
/** * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. * * @return void */ public static function find_uri() { if (PHP_SAPI === 'cli') { // Command line requires a bit of hacking if (isset($_SERVER['argv'][1])) { self::$current_uri = $_SERVER['argv'][1]; // Remove GET string from segments if (($query = strpos(self::$current_uri, '?')) !== FALSE) { list(self::$current_uri, $query) = explode('?', self::$current_uri, 2); // Parse the query string into $_GET parse_str($query, $_GET); // Convert $_GET to UTF-8 $_GET = utf8::clean($_GET); } } } elseif (isset($_GET['Eight_uri'])) { // Use the URI defined in the query string self::$current_uri = $_GET['Eight_uri']; // Remove the URI from $_GET unset($_GET['Eight_uri']); // Remove the URI from $_SERVER['QUERY_STRING'] $_SERVER['QUERY_STRING'] = preg_replace('~\\bEight_uri\\b[^&]*+&?~', '', $_SERVER['QUERY_STRING']); // Fixes really strange handling of a suffix in a GET string if ($suffix = Eight::config('core.url_suffix') and substr(self::$current_uri, -strlen($suffix)) === '_' . substr($suffix, 1)) { self::$current_uri = substr(self::$current_uri, 0, -strlen($suffix)); } } elseif (isset($_SERVER['PATH_INFO']) and $_SERVER['PATH_INFO']) { self::$current_uri = $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) { self::$current_uri = $_SERVER['ORIG_PATH_INFO']; } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) { self::$current_uri = $_SERVER['PHP_SELF']; } // The front controller directory and filename $fc = substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(DOCROOT)); if (($strpos_fc = strpos(self::$current_uri, $fc)) !== FALSE) { // Remove the front controller from the current URI self::$current_uri = substr(self::$current_uri, $strpos_fc + strlen($fc)); } // Remove all dot-paths from the URI, they are not valid self::$current_uri = preg_replace('#\\.[\\s./]*/#', '', self::$current_uri); // Reduce multiple slashes into single slashes, remove trailing slashes self::$current_uri = trim(preg_replace('#//+#', '/', self::$current_uri), '/'); // Make sure the URL is not tainted with HTML characters self::$current_uri = html::specialchars(self::$current_uri, FALSE); if (!empty($_SERVER['QUERY_STRING'])) { // Set the query string to the current query string self::$query_string = '?' . trim($_SERVER['QUERY_STRING'], '&'); } }