diff --git a/core/SSViewer.php b/core/SSViewer.php index 31477dc13..ec7eed8a6 100644 --- a/core/SSViewer.php +++ b/core/SSViewer.php @@ -39,6 +39,7 @@ class SSViewer extends Object { $this->chosenTemplates['main'] = $templateList; } else { if(!is_array($templateList)) $templateList = array($templateList); + if(isset($_GET['debug_request'])) Debug::message("Selecting templates from the following list: " . implode(", ", $templateList)); $this->chosenTemplates = array(); global $_TEMPLATE_MANIFEST; @@ -49,22 +50,27 @@ class SSViewer extends Object { else $templateFolder = null; // Base templates - if(isset($_TEMPLATE_MANIFEST[$template])) { + if(isset($_TEMPLATE_MANIFEST[$template]) && (array_keys($_TEMPLATE_MANIFEST[$template]) != array('themes'))) { $this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template], $this->chosenTemplates); + if(isset($_GET['debug_request'])) Debug::message("Found template '$template' from main template archive, containing the following items: " . var_export($_TEMPLATE_MANIFEST[$template], true)); unset($this->chosenTemplates['themes']); } // Use the theme template if available if(self::$current_theme && isset($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme])) { + if(isset($_GET['debug_request'])) Debug::message("Found template '$template' from main theme '" . self::$current_theme . "': " . var_export($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme], true)); $this->chosenTemplates = array_merge($_TEMPLATE_MANIFEST[$template]['themes'][self::$current_theme], $this->chosenTemplates); } - + if($templateFolder) { $this->chosenTemplates['main'] = $this->chosenTemplates[$templateFolder]; unset($this->chosenTemplates[$templateFolder]); } } + + if(isset($_GET['debug_request'])) Debug::message("Final template selections made: " . var_export($this->chosenTemplates, true)); + } if(!$this->chosenTemplates) user_error("None of these templates can be found: ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING); diff --git a/core/control/Controller.php b/core/control/Controller.php index 64b36681c..6c19c4ca3 100644 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -105,7 +105,7 @@ class Controller extends RequestHandlingData { $this->requestParams = $request->requestVars(); if(!$this->action) $this->action = 'index'; $methodName = $this->action; - + // run & init are manually disabled, because they create infinite loops and other dodgy situations if($this->checkAccessAction($this->action) && !in_array(strtolower($this->action), array('run', 'init'))) { if($this->hasMethod($methodName)) { @@ -226,19 +226,22 @@ class Controller extends RequestHandlingData { } else if($this->template) { $templates = $this->template; } else { + $parentClass = $this->class; + if($action && $action != 'index') { + $parentClass = $this->class; + while($parentClass != "Controller") { + $templates[] = strtok($parentClass,'_') . '_' . $action; + $parentClass = get_parent_class($parentClass); + } + } $parentClass = $this->class; while($parentClass != "Controller") { - $templateName = $parentClass; - if(($pos = strpos($templateName,'_')) !== false) $templateName = substr($templateName, 0, $pos); - - if($action && $action != "index") $templates[] = $templateName . '_' . $action; - $templates[] = $templateName; - + $templates[] = strtok($parentClass,'_'); $parentClass = get_parent_class($parentClass); } + $templates = array_unique($templates); } - if(isset($_GET['showtemplate'])) Debug::show($templates); return new SSViewer($templates); } diff --git a/core/control/RequestHandlingData.php b/core/control/RequestHandlingData.php index c45d0a7a7..0eb16eb2d 100644 --- a/core/control/RequestHandlingData.php +++ b/core/control/RequestHandlingData.php @@ -76,7 +76,9 @@ class RequestHandlingData extends ViewableData { foreach($this->stat('url_handlers') as $rule => $action) { if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class"); if($params = $request->match($rule, true)) { - if(isset($_REQUEST['debug_request'])) Debug::message("Rule '$rule' matched to action '$action' on $this->class"); + if(isset($_REQUEST['debug_request'])) { + Debug::message("Rule '$rule' matched to action '$action' on $this->class. Latest request params: " . var_export($request->latestParams(), true)); + } // Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action', if($action[0] == '$') $action = $params[substr($action,1)];