* Fixed bug #6395: External TypoScripts files will always be cached
authorBernhard Kraft <kraftb@think-open.at>
Wed, 6 May 2009 21:08:36 +0000 (21:08 +0000)
committerBernhard Kraft <kraftb@think-open.at>
Wed, 6 May 2009 21:08:36 +0000 (21:08 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5395 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tsparser.php
t3lib/class.t3lib_tstemplate.php

index 6c61b9d..6b425ee 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-05-06  Bernhard Kraft  <bernhard@typo3.org>
+
+       * Fixed bug #6395: External TypoScripts files will always be cached
+
 2009-05-06  Oliver Hader  <oliver@typo3.org>
 
        * Cleanup: Added public static definitions to TSpagegen
index fc95ea7..26a9837 100644 (file)
@@ -45,7 +45,7 @@
  *  413:     function getVal($string,$setup)
  *  439:     function setVal($string,&$setup,$value,$wipeOut=0)
  *  485:     function error($err,$num=2)
- *  497:     function checkIncludeLines($string)
+ *  497:     function checkIncludeLines($string, $cycle_counter=1, $returnFiles=false)
  *  541:     function checkIncludeLines_array($array)
  *
  *              SECTION: Syntax highlighting
@@ -499,12 +499,20 @@ class t3lib_TSparser {
         *
         * @param       string          Unparsed TypoScript
         * @param       integer         Counter for detecting endless loops
+        * @param       boolean         When set an array containing the resulting typoscript and all included files will get returned
         * @return      string          Complete TypoScript with includes added.
         * @static
         */
-       function checkIncludeLines($string, $cycle_counter=1)   {
+       function checkIncludeLines($string, $cycle_counter=1, $returnFiles=false) {
+               $includedFiles = array();
                if ($cycle_counter>100) {
                        t3lib_div::sysLog('It appears like TypoScript code is looping over itself. Check your templates for "&lt;INCLUDE_TYPOSCRIPT: ..." tags','Core',2);
+                       if ($returnFiles) {
+                               return array(
+                                       'typoscript' => '',
+                                       'files' => $includedFiles,
+                               );
+                       }
                        return '';
                }
                $splitStr='<INCLUDE_TYPOSCRIPT:';
@@ -529,7 +537,14 @@ class t3lib_TSparser {
                                                                        if (strcmp($filename,''))       {       // Must exist and must not contain '..' and must be relative
                                                                                if (@is_file($filename) && filesize($filename)<100000)  {       // Max. 100 KB include files!
                                                                                                // check for includes in included text
-                                                                                       $included_text = self::checkIncludeLines(t3lib_div::getUrl($filename),$cycle_counter+1);
+                                                                                       $includedFiles[] = $filename;
+                                                                                       $included_text = self::checkIncludeLines(t3lib_div::getUrl($filename),$cycle_counter+1, $returnFiles);
+                                                                                               // If the method also has to return all included files, merge currently included
+                                                                                               // files with files included by recursively calling itself
+                                                                                       if ($returnFiles && is_array($included_text)) {
+                                                                                               $includedFiles = array_merge($includedFiles, $included_text['files']);
+                                                                                               $included_text = $included_text['typoscript'];
+                                                                                       }
                                                                                        $newString.= $included_text.chr(10);
                                                                                }
                                                                        }
@@ -543,6 +558,14 @@ class t3lib_TSparser {
                        }
                        $string=substr($newString,1,-1);        // not the first/last linebreak char.
                }
+                       // When all included files should get returned, simply return an compound array containing
+                       // the TypoScript with all "includes" processed and the files which got included
+               if ($returnFiles) {
+                       return array(
+                               'typoscript' => $string,
+                               'files' => $includedFiles,
+                       );
+               }
                return $string;
        }
 
@@ -687,4 +710,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser.php']);
 }
 
-?>
\ No newline at end of file
+?>
index c9903b3..976ae7d 100644 (file)
@@ -938,16 +938,29 @@ class t3lib_TStemplate    {
         * @see t3lib_TSparser, generateConfig()
         */
        function procesIncludes() {
+               $files = array();
                foreach ($this->constants as &$value) {
-                       $value = t3lib_TSparser::checkIncludeLines($value);
+                       $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
+                       $files = array_merge($files, $includeData['files']);
+                       $value = $includeData['typoscript'];
                }
 
                foreach ($this->config as &$value) {
-                       $value = t3lib_TSparser::checkIncludeLines($value);
+                       $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
+                       $files = array_merge($files, $includeData['files']);
+                       $value = $includeData['typoscript'];
                }
 
                foreach ($this->editorcfg as &$value) {
-                       $value = t3lib_TSparser::checkIncludeLines($value);
+                       $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
+                       $files = array_merge($files, $includeData['files']);
+                       $value = $includeData['typoscript'];
+               }
+               if (count($files)) {
+                       $files = array_unique($files);
+                       foreach ($files as $file) {
+                               $this->rowSum[] = Array($file, filemtime($file));
+                       }
                }
        }