From: Alexander Ebert Date: Mon, 5 Nov 2012 22:15:50 +0000 (+0100) Subject: Changed handling of PACKAGE_ID and templates X-Git-Tag: 2.0.0_Beta_1~810 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e9a062f91892cc4adb36e14ca61312cf2481637f;p=GitHub%2FWoltLab%2FWCF.git Changed handling of PACKAGE_ID and templates --- diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 2c23413aa7..53334cb41d 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -114,7 +114,7 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject * @param string $filename * @param integer $packageID */ - public static function rebuildFile($filename, $packageID = PACKAGE_ID) { + public static function rebuildFile($filename, $packageID) { $buffer = ''; // file header diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 7c83387aee..20d926c3f6 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -600,10 +600,23 @@ class Package extends DatabaseObject { $file->write("\n"); } + // get primary application + $sql = "SELECT applications.packageID + FROM wcf".WCF_N."_application application, + wcf".WCF_N."_application applications + WHERE application.packageID = ? + AND applications.groupID = application.groupID + AND applications.groupID IS NOT NULL + AND applications.isPrimary = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($packageID, 1)); + $row = $statement->fetchArray(); + $packageID = ($row === false) ? $packageID : $row['packageID']; + // write general information $file->write("// general info\n"); $file->write("if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', RELATIVE_".$currentPrefix."_DIR.'".FileUtil::getRelativePath($packageDir, WCF_DIR)."');\n"); - $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', ".$package->packageID.");\n"); + $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', ".$row['packageID'].");\n"); $file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '".str_replace("'", "\'", $package->getName())."');\n"); $file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '".$package->packageVersion."');\n"); diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 2ecb05f661..65a4e6cca3 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -451,6 +451,9 @@ 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/'); + call_user_func(array($className, 'getInstance')); } } @@ -461,7 +464,7 @@ class WCF { // register template path in ACP if (class_exists('wcf\system\WCFACP', false)) { - $this->getTPL()->addTemplatePath($application->packageID, $packageDir . 'acp/templates/'); + $this->getTPL()->addApplication($abbreviation, $application->packageID, $packageDir . 'acp/templates/'); } else if (!$isDependentApplication) { // assign base tag diff --git a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php index 669afe7581..b880045418 100755 --- a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php @@ -20,6 +20,12 @@ use wcf\util\StringUtil; * @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 @@ -102,6 +108,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->pluginNamespace = 'wcf\system\template\plugin\\'; $this->compileDir = WCF_DIR.'templates/compiled/'; @@ -112,12 +119,14 @@ class TemplateEngine extends SingletonFactory { } /** - * Adds a new template path for given package id. + * Adds a new application. * + * @param string $abbreviation * @param integer $packageID * @param string $templatePath */ - public function addTemplatePath($packageID, $templatePath) { + public function addApplication($abbreviation, $packageID, $templatePath) { + $this->abbreviations[$abbreviation] = $packageID; $this->templatePaths[$packageID] = $templatePath; } @@ -284,10 +293,10 @@ class TemplateEngine extends SingletonFactory { * Outputs a template. * * @param string $templateName - * @param integer $packageID + * @param string $application * @param boolean $sendHeaders */ - public function display($templateName, $packageID = PACKAGE_ID, $sendHeaders = true) { + public function display($templateName, $application = 'wcf', $sendHeaders = true) { if ($sendHeaders) { HeaderUtil::sendHeaders(); @@ -295,24 +304,24 @@ class TemplateEngine extends SingletonFactory { if (!defined('NO_IMPORTS')) EventHandler::getInstance()->fireAction($this, 'shouldDisplay'); } - $tplPackageID = $this->getPackageID($templateName, $packageID); - $compiledFilename = $this->getCompiledFilename($templateName, $packageID); + $tplPackageID = $this->getPackageID($templateName, $application); + $compiledFilename = $this->getCompiledFilename($templateName, $tplPackageID); $sourceFilename = $this->getSourceFilename($templateName, $tplPackageID); - $metaDataFilename = $this->getMetaDataFilename($templateName, $packageID); + $metaDataFilename = $this->getMetaDataFilename($templateName, $tplPackageID); $metaData = $this->getMetaData($templateName, $metaDataFilename); // check if compilation is necessary - if (($metaData === null) || !$this->isCompiled($templateName, $sourceFilename, $compiledFilename, $packageID, $metaData)) { + if (($metaData === null) || !$this->isCompiled($templateName, $sourceFilename, $compiledFilename, $application, $metaData)) { // compile $this->compileTemplate($templateName, $sourceFilename, $compiledFilename, array( + 'application' => $application, 'data' => $metaData, - 'filename' => $metaDataFilename, - 'packageID' => $tplPackageID + 'filename' => $metaDataFilename )); } // assign current package id - $this->assign('__PACKAGE_ID', $packageID); + $this->assign('__APPLICATION', $application); include($compiledFilename); @@ -326,10 +335,16 @@ class TemplateEngine extends SingletonFactory { * Returns path and corresponding file path. * * @param string $templateName - * @param integer $packageID + * @param string $application * @return integer */ - public function getPackageID($templateName, $packageID) { + 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."'"); + } + + // search within application if ($packageID != 1 && isset($this->templatePaths[$packageID])) { $path = $this->getPath($this->templatePaths[$packageID], $templateName); @@ -338,6 +353,7 @@ class TemplateEngine extends SingletonFactory { } } + // search within WCF $path = $this->getPath($this->templatePaths[1], $templateName); if (!empty($path)) { return 1; @@ -415,11 +431,11 @@ class TemplateEngine extends SingletonFactory { * @param string $templateName * @param string $sourceFilename * @param string $compiledFilename - * @param integer $packageID + * @param string $application * @param array $metaData * @return boolean $isCompiled */ - protected function isCompiled($templateName, $sourceFilename, $compiledFilename, $packageID, array $metaData) { + protected function isCompiled($templateName, $sourceFilename, $compiledFilename, $application, array $metaData) { if ($this->forceCompile || !file_exists($compiledFilename)) { return false; } @@ -434,7 +450,7 @@ class TemplateEngine extends SingletonFactory { // check for meta data if (!empty($metaData['include'])) { foreach ($metaData['include'] as $includedTemplate) { - $tplPackageID = $this->getPackageID($includedTemplate, $packageID); + $tplPackageID = $this->getPackageID($includedTemplate, $application); $includedTemplateFilename = $this->getSourceFilename($includedTemplate, $tplPackageID); $includedMTime = @filemtime($includedTemplateFilename); @@ -544,12 +560,12 @@ class TemplateEngine extends SingletonFactory { * Returns the output of a template. * * @param string $templateName + * @param string $application * @param array $variables * @param boolean $sandbox enables execution in sandbox - * @param integer $packageID * @return string */ - public function fetch($templateName, array $variables = array(), $sandbox = false, $packageID = PACKAGE_ID) { + public function fetch($templateName, $application = 'wcf', array $variables = array(), $sandbox = false) { // enable sandbox if ($sandbox) { $this->enableSandbox(); @@ -562,7 +578,7 @@ class TemplateEngine extends SingletonFactory { // get output ob_start(); - $this->display($templateName, $packageID, false); + $this->display($templateName, $application, false); $output = ob_get_contents(); ob_end_clean(); @@ -690,10 +706,11 @@ class TemplateEngine extends SingletonFactory { * Includes a template. * * @param string $templateName + * @param string $application * @param array $variables * @param boolean $sandbox enables execution in sandbox */ - protected function includeTemplate($templateName, array $variables = array(), $sandbox = true, $packageID = PACKAGE_ID) { + protected function includeTemplate($templateName, $application, array $variables = array(), $sandbox = true) { // enable sandbox if ($sandbox) { $this->enableSandbox(); @@ -705,7 +722,7 @@ class TemplateEngine extends SingletonFactory { } // display template - $this->display($templateName, $packageID, false); + $this->display($templateName, $application, false); // disable sandbox if ($sandbox) { @@ -745,10 +762,11 @@ class TemplateEngine extends SingletonFactory { * Returns true if requested template has assigned template listeners. * * @param string $templateName + * @param string $application * @return boolean */ - public function hasTemplateListeners($templateName) { - if (isset($this->templateListeners[$templateName])) { + public function hasTemplateListeners($templateName, $application = 'wcf') { + if (isset($this->templateListeners[$application]) && isset($this->templateListeners[$application][$templateName])) { return true; } diff --git a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php index 2d62963cd4..246dc4c9ce 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php @@ -783,14 +783,14 @@ class TemplateScriptingCompiler { } if (!empty($phpCode)) $phpCode = ""; - $tplPackageID = WCF::getTPL()->getPackageID($templateName, $metaData['packageID']); + $tplPackageID = WCF::getTPL()->getPackageID($templateName, $metaData['application']); $sourceFilename = WCF::getTPL()->getSourceFilename($templateName, $tplPackageID); $metaDataFilename = WCF::getTPL()->getMetaDataFilename($templateName, $tplPackageID); $data = $this->compileString($templateName, file_get_contents($sourceFilename), array( + 'application' => $metaData['application'], 'data' => null, - 'filename' => '', - 'packageID' => $tplPackageID + 'filename' => '' ), true); return $phpCode . $data['template']; @@ -809,7 +809,7 @@ class TemplateScriptingCompiler { $phpCode .= "ob_start();\n"; } - $phpCode .= '$this->includeTemplate('.$file.', array('.$argString.'), ('.$sandbox.' ? 1 : 0), $this->v[\'__PACKAGE_ID\']);'."\n"; + $phpCode .= '$this->includeTemplate('.$file.', $this->v[\'__APPLICATION\'], array('.$argString.'), ('.$sandbox.' ? 1 : 0));'."\n"; if ($assignVar !== false) { $phpCode .= '$this->'.($append ? 'append' : 'assign').'('.$assignVar.', ob_get_clean());'."\n";