Fixed template handling in multi-app environment
authorAlexander Ebert <ebert@woltlab.com>
Fri, 4 Jan 2013 16:17:02 +0000 (17:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 4 Jan 2013 16:17:02 +0000 (17:17 +0100)
Fixes #1076

wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/template/SetupTemplateEngine.class.php
wcfsetup/install/files/lib/system/template/TemplateEngine.class.php

index 70b0ed763a450bc587e80f74cbf55f02bee8a09e..4b1553bb94675c439110bd820672956b5038c2c9 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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
index 3268c0ba55312c477d05f59d15633b4c19289c1a..5c17ec23f754fa1d9838e0522e1fefddcb73e29d 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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()
index 851d18960816ea5ef589c58817727493ac8e136e..7103d89f8ef359345e2a04b896cc520b03ec0694 100755 (executable)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.template
  * @category   Community Framework
  */
 class TemplateEngine extends SingletonFactory {
-       /**
-        * list of abbreviations to package id
-        * @var array<integer>
-        */
-       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) {