From 58fda665e24e97b7c9b05d6f70e3e2edfa8483e7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 4 Jan 2013 17:17:02 +0100 Subject: [PATCH] Fixed template handling in multi-app environment Fixes #1076 --- .../install/files/lib/system/WCF.class.php | 6 +- .../template/SetupTemplateEngine.class.php | 23 +++--- .../system/template/TemplateEngine.class.php | 72 ++++++------------- 3 files changed, 33 insertions(+), 68 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 70b0ed763a..4b1553bb94 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -39,7 +39,7 @@ if (!defined('NO_IMPORTS')) { * It holds the database connection, access to template and language engine. * * @author Marcel Werk - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system @@ -473,7 +473,7 @@ class WCF { // start application if not within ACP if (!class_exists('wcf\system\WCFACP', false)) { // add template path and abbreviation - $this->getTPL()->addApplication($abbreviation, $application->packageID, $packageDir . 'templates/'); + $this->getTPL()->addApplication($abbreviation, $packageDir . 'templates/'); // init application and assign it as template variable $applicationObject = call_user_func(array($className, 'getInstance')); @@ -487,7 +487,7 @@ class WCF { // register template path in ACP if (class_exists('wcf\system\WCFACP', false)) { - $this->getTPL()->addApplication($abbreviation, $application->packageID, $packageDir . 'acp/templates/'); + $this->getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/'); } else if (!$isDependentApplication) { // assign base tag diff --git a/wcfsetup/install/files/lib/system/template/SetupTemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/SetupTemplateEngine.class.php index 3268c0ba55..5c17ec23f7 100644 --- a/wcfsetup/install/files/lib/system/template/SetupTemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/SetupTemplateEngine.class.php @@ -6,7 +6,7 @@ use wcf\system\exception\SystemException; * Loads and displays template during the setup process. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template @@ -23,8 +23,13 @@ class SetupTemplateEngine extends TemplateEngine { /** * @see wcf\system\template\TemplateEngine::getSourceFilename() */ - public function getSourceFilename($templateName, $packageID) { - return $this->templatePaths[PACKAGE_ID].'setup/template/'.$templateName.'.tpl'; + public function getSourceFilename($templateName, $application) { + $sourceFilename = $this->templatePaths[$application].'setup/template/'.$templateName.'.tpl'; + if (!empty($sourceFilename)) { + return $sourceFilename; + } + + throw new SystemException("Unable to find template '".$templateName."'"); } /** @@ -40,18 +45,6 @@ class SetupTemplateEngine extends TemplateEngine { public function getMetaDataFilename($templateName) { return $this->compileDir.'setup/template/compiled/'.$this->languageID.'_'.$templateName.'.meta.php'; } - - /** - * @see wcf\system\template\TemplateEngine::getPackageID() - */ - public function getPackageID($templateName, $application = 'wcf') { - $path = $this->templatePaths[PACKAGE_ID].'setup/template/'.$templateName.'.tpl'; - if (file_exists($path)) { - return PACKAGE_ID; - } - - throw new SystemException("Unable to find template '$templateName'"); - } /** * @see wcf\system\template\TemplateEngine::loadTemplateListeners() diff --git a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php index 851d189608..7103d89f8e 100755 --- a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php @@ -13,19 +13,13 @@ use wcf\util\StringUtil; * Loads and displays template. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template * @category Community Framework */ class TemplateEngine extends SingletonFactory { - /** - * list of abbreviations to package id - * @var array - */ - public $abbreviations = array(); - /** * directory used to cache previously compiled templates * @var string @@ -108,8 +102,7 @@ class TemplateEngine extends SingletonFactory { * @see wcf\system\SingletonFactory::init() */ protected function init() { - $this->abbreviations['wcf'] = 1; - $this->templatePaths = array(1 => WCF_DIR.'templates/'); + $this->templatePaths = array('wcf' => WCF_DIR.'templates/'); $this->pluginNamespace = 'wcf\system\template\plugin\\'; $this->compileDir = WCF_DIR.'templates/compiled/'; @@ -122,12 +115,10 @@ class TemplateEngine extends SingletonFactory { * Adds a new application. * * @param string $abbreviation - * @param integer $packageID * @param string $templatePath */ - public function addApplication($abbreviation, $packageID, $templatePath) { - $this->abbreviations[$abbreviation] = $packageID; - $this->templatePaths[$packageID] = $templatePath; + public function addApplication($abbreviation, $templatePath) { + $this->templatePaths[$abbreviation] = $templatePath; } /** @@ -304,9 +295,8 @@ class TemplateEngine extends SingletonFactory { if (!defined('NO_IMPORTS')) EventHandler::getInstance()->fireAction($this, 'shouldDisplay'); } - $tplPackageID = $this->getPackageID($templateName, $application); - $compiledFilename = $this->getCompiledFilename($templateName); - $sourceFilename = $this->getSourceFilename($templateName, $tplPackageID); + $sourceFilename = $this->getSourceFilename($templateName, $application); + $compiledFilename = $this->getCompiledFilename($templateName, $application); $metaDataFilename = $this->getMetaDataFilename($templateName); $metaData = $this->getMetaData($templateName, $metaDataFilename); @@ -332,45 +322,27 @@ class TemplateEngine extends SingletonFactory { } /** - * Returns path and corresponding file path. + * Returns the absolute filename of a template source. * * @param string $templateName * @param string $application - * @return integer + * @return string $path */ - public function getPackageID($templateName, $application = 'wcf') { - $packageID = (isset($this->abbreviations[$application])) ? $this->abbreviations[$application] : null; - if ($packageID === null) { - throw new SystemException("Unable to find application for abbreviation '".$application."'"); + public function getSourceFilename($templateName, $application) { + $sourceFilename = $this->getPath($this->templatePaths[$application], $templateName); + if (!empty($sourceFilename)) { + return $sourceFilename; } - // search within application - if ($packageID != 1 && isset($this->templatePaths[$packageID])) { - $path = $this->getPath($this->templatePaths[$packageID], $templateName); - - if (!empty($path)) { - return $packageID; + // try to find template within WCF if not already searching WCF + if ($application != 'wcf') { + $sourceFilename = $this->getSourceFilename($templateName, 'wcf'); + if (!empty($sourceFilename)) { + return $sourceFilename; } } - // search within WCF - $path = $this->getPath($this->templatePaths[1], $templateName); - if (!empty($path)) { - return 1; - } - - throw new SystemException("Unable to find template '$templateName'"); - } - - /** - * Returns the absolute filename of a template source. - * - * @param string $templateName - * @param integer $packageID - * @return string $path - */ - public function getSourceFilename($templateName, $packageID) { - return $this->getPath($this->templatePaths[$packageID], $templateName); + throw new SystemException("Unable to find template '".$templateName."'"); } /** @@ -408,10 +380,11 @@ class TemplateEngine extends SingletonFactory { * Returns the absolute filename of a compiled template. * * @param string $templateName + * @param string $application * @return string */ - public function getCompiledFilename($templateName) { - return $this->compileDir.$this->templateGroupID.'_'.$this->languageID.'_'.$templateName.'.php'; + public function getCompiledFilename($templateName, $application) { + return $this->compileDir.$this->templateGroupID.'_'.$application.'_'.$this->languageID.'_'.$templateName.'.php'; } /** @@ -449,8 +422,7 @@ class TemplateEngine extends SingletonFactory { // check for meta data if (!empty($metaData['include'])) { foreach ($metaData['include'] as $includedTemplate) { - $tplPackageID = $this->getPackageID($includedTemplate, $application); - $includedTemplateFilename = $this->getSourceFilename($includedTemplate, $tplPackageID); + $includedTemplateFilename = $this->getSourceFilename($includedTemplate, $application); $includedMTime = @filemtime($includedTemplateFilename); if ($includedMTime >= $compileMTime) { -- 2.20.1