diff --git a/core/SSViewer.php b/core/SSViewer.php index cd2c45afc..a225d9f09 100755 --- a/core/SSViewer.php +++ b/core/SSViewer.php @@ -87,11 +87,6 @@ class SSViewer { */ protected static $current_theme = null; - /** - * @var string - */ - protected static $cached_theme = null; - /** * Create a template from a string instead of a .ss file * @@ -111,18 +106,8 @@ class SSViewer { /** * @return string */ - static function current_theme($cached = true) { - if($cached && self::$cached_theme) { - // First case is to return the cached user theme so we don't requery SiteConfig again - return self::$cached_theme; - } else { - // Need to refresh the cache from the SiteConfig - $theme = SiteConfig::current_site_config()->Theme; - self::$cached_theme = $theme; - } - // Fall back to the default SSViewer::set_theme() behaviour - if(!$theme) $theme = self::$current_theme; - return $theme; + static function current_theme() { + return self::$current_theme; } /** @@ -187,7 +172,8 @@ class SSViewer { } - if(!$this->chosenTemplates) user_error("None of these templates can be found: ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING); + if(!$this->chosenTemplates) user_error("None of these templates can be found in theme '" + . self::current_theme() . "': ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING); } /** @@ -642,7 +628,7 @@ class SSViewer_FromString extends SSViewer { $this->content = $content; } - public function process($item) { + public function process($item, $cache = null) { $template = SSViewer::parseTemplateContent($this->content, "string sha1=".sha1($this->content)); $tmpFile = tempnam(TEMP_FOLDER,""); diff --git a/core/control/ContentController.php b/core/control/ContentController.php index c47f781c6..ce83f828c 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -120,8 +120,12 @@ class ContentController extends Controller { return Security::permissionFailure($this, sprintf($message, "$link?stage=Live")); } - } + } + // Use theme from the site config + if(($config = SiteConfig::current_site_config()) && $config->Theme) { + SSViewer::set_theme($config->Theme); + } } /** diff --git a/tests/SSViewerTest.php b/tests/SSViewerTest.php index 7adc8ff28..e4c4a1dd2 100644 --- a/tests/SSViewerTest.php +++ b/tests/SSViewerTest.php @@ -12,12 +12,17 @@ class SSViewerTest extends SapphireTest { $oldTheme = $config->Theme; $config->Theme = ''; $config->write(); - + SSViewer::set_theme('mytheme'); $this->assertEquals('mytheme', SSViewer::current_theme(), 'Current theme is the default - user has not defined one'); $config->Theme = 'myusertheme'; $config->write(); + + // Pretent to load the page + $c = new ContentController(); + $c->init(); + $this->assertEquals('myusertheme', SSViewer::current_theme(), 'Current theme is a user defined one'); // Set the theme back to the original