Fixed and improved static includes
authorAlexander Ebert <ebert@woltlab.com>
Sat, 28 Jun 2014 13:33:57 +0000 (15:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 28 Jun 2014 13:33:57 +0000 (15:33 +0200)
wcfsetup/install/files/lib/system/template/TemplateEngine.class.php
wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php

index a405665b5e345cd4460db1f580f8f0194ea6b101..52c18605a2792db204bcc97823de292c63e4ee2c 100755 (executable)
@@ -428,12 +428,14 @@ class TemplateEngine extends SingletonFactory {
                        else {
                                // check for meta data
                                if (!empty($metaData['include'])) {
-                                       foreach ($metaData['include'] as $includedTemplate) {
-                                               $includedTemplateFilename = $this->getSourceFilename($includedTemplate, $application);
-                                               $includedMTime = @filemtime($includedTemplateFilename);
-                                               
-                                               if ($includedMTime >= $compileMTime) {
-                                                       return false;
+                                       foreach ($metaData['include'] as $application => $includedTemplates) {
+                                               foreach ($includedTemplates as $includedTemplate) {
+                                                       $includedTemplateFilename = $this->getSourceFilename($includedTemplate, $application);
+                                                       $includedMTime = @filemtime($includedTemplateFilename);
+                                                       
+                                                       if ($includedMTime >= $compileMTime) {
+                                                               return false;
+                                                       }
                                                }
                                        }
                                }
index de507635408d7eff4b205ddad06628faa82f23e3..983855b1b0385e34cf2d11c0367089b940c2d0f4 100644 (file)
@@ -708,7 +708,7 @@ class TemplateScriptingCompiler {
         * @param       array           $metaData
         * @return      string
         */
-       protected function compileIncludeTag($includeTag, $identifier, array &$metaData) {
+       protected function compileIncludeTag($includeTag, $identifier, array $metaData) {
                $args = $this->parseTagArgs($includeTag, 'include');
                $append = false;
                
@@ -734,12 +734,6 @@ class TemplateScriptingCompiler {
                        unset($args['append']);
                }
                
-               $sandbox = 0;
-               if (isset($args['sandbox'])) {
-                       $sandbox = $args['sandbox'];
-                       unset($args['sandbox']);
-               }
-               
                $once = false;
                if (isset($args['once'])) {
                        $once = $args['once'];
@@ -752,12 +746,32 @@ class TemplateScriptingCompiler {
                        unset($args['application']);
                }
                
+               if (preg_match('~^\'(.*)\'$~', $application, $matches)) {
+                       $application = $matches[1];
+               }
+               
+               $sandbox = false;
+               if (isset($args['sandbox'])) {
+                       $sandbox = $args['sandbox'];
+                       unset($args['sandbox']);
+               }
+               
+               $sandbox = ($sandbox === 'true' || $sandbox === true || $sandbox == 1);
+               if (!$sandbox && !empty($args)) {
+                       $sandbox = true;
+               }
+               
                $templateName = substr($file, 1, -1);
+               
                // check for static includes
-               if ($sandbox === 'false' && $assignVar === false && $once === false) {
+               if (!$sandbox && $assignVar === false && $once === false) {
                        $phpCode = '';
-                       if (!in_array($templateName, $this->staticIncludes)) {
-                               $this->staticIncludes[] = $templateName;
+                       if (!isset($this->staticIncludes[$application])) {
+                               $this->staticIncludes[$application] = array();
+                       }
+                       
+                       if (!in_array($templateName, $this->staticIncludes[$application])) {
+                               $this->staticIncludes[$application][] = $templateName;
                        }
                        
                        // pass remaining tag args as variables
@@ -782,11 +796,12 @@ class TemplateScriptingCompiler {
                        }
                        if (!empty($phpCode)) $phpCode = "<?php\n".$phpCode."\n?>";
                        
-                       $sourceFilename = WCF::getTPL()->getSourceFilename($templateName, $metaData['application']);
+                       
+                       $sourceFilename = WCF::getTPL()->getSourceFilename($templateName, $application);
                        $metaDataFilename = WCF::getTPL()->getMetaDataFilename($templateName);
                        
                        $data = $this->compileString($templateName, file_get_contents($sourceFilename), array(
-                               'application' => $metaData['application'],
+                               'application' => $application,
                                'data' => null,
                                'filename' => ''
                        ), true);
@@ -807,7 +822,7 @@ class TemplateScriptingCompiler {
                        $phpCode .= "ob_start();\n";
                }
                
-               $phpCode .= '$this->includeTemplate('.$file.', '.$application.', array('.$argString.'), ('.$sandbox.' ? 1 : 0));'."\n";
+               $phpCode .= '$this->includeTemplate('.$file.', \''.$application.'\', array('.$argString.'), ('.$sandbox.' ? 1 : 0));'."\n";
                
                if ($assignVar !== false) {
                        $phpCode .= '$this->'.($append ? 'append' : 'assign').'('.$assignVar.', ob_get_clean());'."\n";