From 898d897c9ed0accad46b3cd81eac5bf2b73250bf Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 14 Sep 2007 17:47:45 +0000 Subject: [PATCH] mlantahler: Bugfix: $URL != $url. The variable names are case-sensitive in PHP (http://www.php.net/manual/en/language.variables.php) (merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41777 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Director.php | 100 +++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/core/control/Director.php b/core/control/Director.php index 6a505e9c1..2b1daf93d 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -2,7 +2,7 @@ /** * Director is responsible for processing the URL - * Director is the first step in the "execution pipeline". It parses the URL, matching it to + * Director is the first step in the "execution pipeline". It parses the URL, matching it to * one of a number of patterns, and determines the controller, action and any argument to be * used. It then runs the controller, which will finally run the viewer and/or perform processing * steps. @@ -10,15 +10,15 @@ class Director { static private $urlSegment; static private $urlParams; - + static private $rules = array(); - + function __construct() { if(isset($_GET['debug_profile'])) Profiler::mark("Director", "construct"); Session::addToArray('history', substr($_SERVER['REQUEST_URI'], strlen(Director::baseURL()))); if(isset($_GET['debug_profile'])) Profiler::unmark("Director", "construct"); } - + /** * Return a URL from this user's navigation history. * @param pagesBack The number of pages back to go. The default, 1, returns the previous @@ -27,8 +27,8 @@ class Director { static function history($pagesBack = 1) { return Session::get('history.' . sizeof(Session::get('history')) - $pagesBack - 1); } - - + + /** * Add new rules */ @@ -38,7 +38,7 @@ class Director { /** * Process the given URL, creating the appropriate controller and executing it - */ + */ function direct($url) { if(isset($_GET['debug_profile'])) Profiler::mark("Director","direct"); $controllerObj = Director::getControllerForURL($url); @@ -92,12 +92,12 @@ class Director { if(isset($_GET['debug_profile'])) Profiler::mark("Director","getControllerForURL"); $url = preg_replace( array( '/\/+/','/^\//', '/\/$/'),array('/','',''),$url); $urlParts = split('/+', $url); - + krsort(Director::$rules); - + if(isset($_REQUEST['debug'])) Debug::show(Director::$rules); - - foreach(Director::$rules as $priority => $rules) { + + foreach(Director::$rules as $priority => $rules) { foreach($rules as $pattern => $controller) { $patternParts = explode('/', $pattern); $matched = true; @@ -120,10 +120,10 @@ class Director { if(substr($controller,0,2) == '->') { if($_REQUEST['debug'] == 1) Debug::message("Redirecting to $controller"); - + if(isset($_GET['debug_profile'])) Profiler::unmark("Director","getControllerForURL"); return "redirect:" . Director::absoluteURL(substr($controller,2), true); - + } else { if(isset($arguments['Controller']) && $controller == "*") { $controller = $arguments['Controller']; @@ -134,15 +134,15 @@ class Director { $arguments['Action'] = str_replace('-','',$arguments['Action']); } if(isset($arguments['Action']) && ClassInfo::exists($controller.'_'.$arguments['Action'])) - $controller = $controller.'_'.$arguments['Action']; - + $controller = $controller.'_'.$arguments['Action']; + Director::$urlParams = $arguments; $controllerObj = new $controller(); - + $controllerObj->setURLParams($arguments); - + if(isset($arguments['URLSegment'])) self::$urlSegment = $arguments['URLSegment'] . "/"; - + if(isset($_GET['debug_profile'])) Profiler::unmark("Director","getControllerForURL"); return $controllerObj; } @@ -151,14 +151,14 @@ class Director { } } - + static function urlParam($name) { return Director::$urlParams[$name]; } static function urlParams() { return Director::$urlParams; } - + static function currentPage() { if(isset(Director::$urlParams['URLSegment'])) { $SQL_urlSegment = Convert::raw2sql(Director::$urlParams['URLSegment']); @@ -167,11 +167,11 @@ class Director { return Controller::currentController(); } } - - + + static function absoluteURL($url, $relativeToSiteBase = false) { if(strpos($url,'/') === false && !$relativeToSiteBase) $url = dirname($_SERVER['REQUEST_URI'] . 'x') . '/' . $url; - + if(substr($url,0,4) != "http") { if($url[0] != "/") $url = Director::baseURL() . $url; $url = self::protocolAndHost() . $url; @@ -184,8 +184,8 @@ class Director { $s = (isset($_SERVER['SSL']) || isset($_SERVER['HTTPS'])) ? 's' : ''; return "http$s://" . $_SERVER['HTTP_HOST']; } - - + + /** * Redirect to another page. * - $url can be an absolute URL @@ -210,14 +210,14 @@ class Director { * by location.href in IE). */ static function redirectBack() { - $url = (isset($_REQUEST['_REDIRECT_BACK_URL'])) ? $_REQUEST['_REDIRECT_BACK_URL'] : $_SERVER['HTTP_REFERER']; + $url = (isset($_REQUEST['_REDIRECT_BACK_URL'])) ? $_REQUEST['_REDIRECT_BACK_URL'] : $_SERVER['HTTP_REFERER']; Director::redirect($url); } - + static function currentURLSegment() { return Director::$urlSegment; } - + /** * Returns a URL to composed of the given segments - usually controller, action, parameter */ @@ -225,7 +225,7 @@ class Director { $parts = func_get_args(); return Director::baseURL() . implode("/",$parts) . (sizeof($parts) > 2 ? "" : "/"); } - + /** * Returns a URL for the given controller */ @@ -241,7 +241,7 @@ class Director { static function setBaseURL($baseURL) { self::$alternateBaseURL = $baseURL; } - + static $alternateBaseFolder; static function baseFolder() { if(self::$alternateBaseFolder) return self::$alternateBaseFolder; @@ -250,14 +250,14 @@ class Director { static function setBaseFolder($baseFolder) { self::$alternateBaseFolder = $baseFolder; } - + static function makeRelative($url) { $base1 = self::absoluteBaseURL(); $base2 = self::baseFolder(); - + // Allow for the accidental inclusion of a // in the URL $url = ereg_replace('([^:])//','\\1/',$url); - + if(substr($url,0,strlen($base1)) == $base1) return substr($url,strlen($base1)); if(substr($url,0,strlen($base2)) == $base2) return substr($url,strlen($base2)); return $url; @@ -273,7 +273,7 @@ class Director { static function fileExists($file) { return file_exists(Director::getAbsFile($file)); } - + /** * Returns the Absolute URL for the given controller */ @@ -283,23 +283,23 @@ class Director { static function absoluteBaseURLWithAuth() { if($_SERVER['PHP_AUTH_USER']) $login = "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@"; - + if($_SERVER['SSL']) $s = "s"; return "http$s://" . $login . $_SERVER['HTTP_HOST'] . Director::baseURL(); } - + /** * Force the site to run on SSL. To use, call from _config.php */ static function forceSSL() { if(!isset($_SERVER['HTTPS']) && !Director::isDev()){ $destURL = str_replace('http:','https:',Director::absoluteURL($_SERVER['REQUEST_URI'])); - + header("Location: $destURL"); die("

Your browser is not accepting header redirects

Please click here"); } } - + /** * Force a redirect to www.domain */ @@ -309,17 +309,17 @@ class Director { $destURL = str_replace('https://','https://www.',Director::absoluteURL($_SERVER['REQUEST_URI'])); else $destURL = str_replace('http://','http://www.',Director::absoluteURL($_SERVER['REQUEST_URI'])); - + header("Location: $destURL"); die("

Your browser is not accepting header redirects

Please click here"); } } - + /** * Checks if the current HTTP-Request is an "Ajax-Request" * by checking for a custom header set by prototype.js or * wether a manually set request-parameter 'ajax' is present. - * + * * @return boolean */ static function is_ajax() { @@ -332,9 +332,9 @@ class Director { ); } } - - - + + + static $siteMode; static protected $mode_additions; @@ -366,7 +366,7 @@ class Director { } static protected $environment_type; - + /** * Force the environment type to be dev, test or live. * This will affect the results of isLive, isDev, and isTest @@ -378,13 +378,13 @@ class Director { self::$environment_type = $et; } } - + static function isLive() { return !(Director::isDev() || Director::isTest()); } static function isDev() { if(self::$environment_type) return self::$environment_type == 'dev'; - + // Use ?isDev=1 to get development access on the live server if(isset($_GET['isDev'])) { if(ClassInfo::ready()) { @@ -396,7 +396,7 @@ class Director { } if(isset($_SESSION['isDev']) && $_SESSION['isDev']) return true; - + // Anything running on localhost is automatically dev if($_SERVER['SERVER_ADDR'] == '0.0.0.0' || $_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) return true; @@ -405,8 +405,8 @@ class Director { } static function isTest() { if(self::$environment_type) return self::$environment_type == 'test'; - - $testURL = ".$_SERVER[HTTP_HOST]."; + + $testURL = ".$_SERVER[HTTP_HOST]."; return (strpos($testURL, '.test.') !== false); }