diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
commit | 3060a6f662da66008d57a461bf1c9b5b4aa2b002 (patch) | |
tree | 442fd290505817efc0324f2af6e01805cb7396aa /system/libraries/Router.php | |
parent | 1cd6a615bb47a33794e4a4f690c87a348ab752d7 (diff) | |
parent | 32d25dafd5b033338b6a9bb8c7c53edab462543a (diff) |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/gallery/controllers/albums.php
modules/gallery/controllers/movies.php
modules/gallery/controllers/photos.php
Diffstat (limited to 'system/libraries/Router.php')
-rw-r--r-- | system/libraries/Router.php | 103 |
1 files changed, 57 insertions, 46 deletions
diff --git a/system/libraries/Router.php b/system/libraries/Router.php index ef0e1e47..18e01af2 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -2,12 +2,12 @@ /** * Router * - * $Id: Router.php 4391 2009-06-04 03:10:12Z zombor $ + * $Id: Router.php 4693 2009-12-04 17:11:16Z cbandy $ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team - * @license http://kohanaphp.com/license.html + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license */ class Router_Core { @@ -38,7 +38,7 @@ class Router_Core { if ( ! empty($_SERVER['QUERY_STRING'])) { // Set the query string to the current query string - Router::$query_string = '?'.trim($_SERVER['QUERY_STRING'], '&/'); + Router::$query_string = '?'.urldecode(trim($_SERVER['QUERY_STRING'], '&')); } if (Router::$routes === NULL) @@ -53,8 +53,8 @@ class Router_Core { if (Router::$current_uri === '') { // Make sure the default route is set - if ( ! isset(Router::$routes['_default'])) - throw new Kohana_Exception('core.no_default_route'); + if (empty(Router::$routes['_default'])) + throw new Kohana_Exception('Please set a default route in config/routes.php.'); // Use the default route when no segments exist Router::$current_uri = Router::$routes['_default']; @@ -63,32 +63,34 @@ class Router_Core { $default_route = TRUE; } - // Make sure the URL is not tainted with HTML characters - Router::$current_uri = html::specialchars(Router::$current_uri, FALSE); - // Remove all dot-paths from the URI, they are not valid Router::$current_uri = preg_replace('#\.[\s./]*/#', '', Router::$current_uri); - // At this point segments, rsegments, and current URI are all the same - Router::$segments = Router::$rsegments = Router::$current_uri = trim(Router::$current_uri, '/'); - - // Set the complete URI - Router::$complete_uri = Router::$current_uri.Router::$query_string; + // At this point routed URI and current URI are the same + Router::$routed_uri = Router::$current_uri = trim(Router::$current_uri, '/'); - // Explode the segments by slashes - Router::$segments = ($default_route === TRUE OR Router::$segments === '') ? array() : explode('/', Router::$segments); - - if ($default_route === FALSE AND count(Router::$routes) > 1) + if ($default_route === TRUE) { - // Custom routing - Router::$rsegments = Router::routed_uri(Router::$current_uri); + Router::$complete_uri = Router::$query_string; + Router::$current_uri = ''; + Router::$segments = array(); } + else + { + Router::$complete_uri = Router::$current_uri.Router::$query_string; - // The routed URI is now complete - Router::$routed_uri = Router::$rsegments; + // Explode the segments by slashes + Router::$segments = explode('/', Router::$current_uri); - // Routed segments will never be empty - Router::$rsegments = explode('/', Router::$rsegments); + if (count(Router::$routes) > 1) + { + // Custom routing + Router::$routed_uri = Router::routed_uri(Router::$current_uri); + } + } + + // Explode the routed segments by slashes + Router::$rsegments = explode('/', Router::$routed_uri); // Prepare to find the controller $controller_path = ''; @@ -171,7 +173,7 @@ class Router_Core { */ public static function find_uri() { - if (PHP_SAPI === 'cli') + if (Kohana::$server_api === 'cli') { // Command line requires a bit of hacking if (isset($_SERVER['argv'][1])) @@ -179,15 +181,15 @@ class Router_Core { Router::$current_uri = $_SERVER['argv'][1]; // Remove GET string from segments - if (($query = strpos(Router::$current_uri, '?')) !== FALSE) + if (strpos(Router::$current_uri, '?') !== FALSE) { - list (Router::$current_uri, $query) = explode('?', Router::$current_uri, 2); + list(Router::$current_uri, $query) = explode('?', Router::$current_uri, 2); // Parse the query string into $_GET parse_str($query, $_GET); // Convert $_GET to UTF-8 - $_GET = utf8::clean($_GET); + $_GET = Input::clean($_GET); } } } @@ -202,28 +204,37 @@ class Router_Core { // 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']) - { - Router::$current_uri = $_SERVER['PATH_INFO']; - } - elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) - { - Router::$current_uri = $_SERVER['ORIG_PATH_INFO']; - } - elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) - { - Router::$current_uri = $_SERVER['PHP_SELF']; - } - - if (($strpos_fc = strpos(Router::$current_uri, KOHANA)) !== FALSE) + else { - // Remove the front controller from the current uri - Router::$current_uri = (string) substr(Router::$current_uri, $strpos_fc + strlen(KOHANA)); + if (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO']) + { + Router::$current_uri = $_SERVER['PATH_INFO']; + } + elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) + { + Router::$current_uri = $_SERVER['ORIG_PATH_INFO']; + } + elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) + { + // PATH_INFO is empty during requests to the front controller + Router::$current_uri = $_SERVER['PHP_SELF']; + } + + if (isset($_SERVER['SCRIPT_NAME']) AND $_SERVER['SCRIPT_NAME']) + { + // Clean up PATH_INFO fallbacks + // PATH_INFO may be formatted for ISAPI instead of CGI on IIS + if (strncmp(Router::$current_uri, $_SERVER['SCRIPT_NAME'], strlen($_SERVER['SCRIPT_NAME'])) === 0) + { + // Remove the front controller from the current uri + Router::$current_uri = (string) substr(Router::$current_uri, strlen($_SERVER['SCRIPT_NAME'])); + } + } } - + // Remove slashes from the start and end of the URI Router::$current_uri = trim(Router::$current_uri, '/'); - + if (Router::$current_uri !== '') { if ($suffix = Kohana::config('core.url_suffix') AND strpos(Router::$current_uri, $suffix) !== FALSE) |