Fixed bug #12295: Cleaning config_default, exclude values from being listed in instal...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tstemplate.php
old mode 100755 (executable)
new mode 100644 (file)
index 4cd1af5..e5dc1fc
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2007 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -80,8 +80,6 @@
  *
  */
 
-require_once (PATH_t3lib.'class.t3lib_tsparser.php');
-require_once (PATH_t3lib.'class.t3lib_matchcondition.php');
 
 
 
@@ -135,7 +133,6 @@ class t3lib_TStemplate      {
        var $whereClause = '';                          // This MUST be initialized by the init() function
        var $debug = 0;
        var $allowedPaths = array();            // This is the only paths (relative!!) that are allowed for resources in TypoScript. Should all be appended with '/'. You can extend these by the global array TYPO3_CONF_VARS. See init() function.
-       var $currentPageData = '';                      // Contains "currentPageData" when rendered/fetched from cache. See getCurrentPageData()
        var $simulationHiddenOrTime=0;          // See init(); Set if preview of some kind is enabled.
 
        var $loaded = 0;                                        // Set, if the TypoScript template structure is loaded and OK, see ->start()
@@ -212,24 +209,34 @@ class t3lib_TStemplate    {
         */
        function init() {
                        // $this->whereClause is used only to select templates from sys_template.
-                       // $GLOBALS['SIM_EXEC_TIME'] is used so that we're able to simulate a later time as a test...
+                       // $GLOBALS['SIM_ACCESS_TIME'] is used so that we're able to simulate a later time as a test...
                $this->whereClause='AND deleted=0 ';
                if (!$GLOBALS['TSFE']->showHiddenRecords)       {
                        $this->whereClause.='AND hidden=0 ';
                }
-               if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_EXEC_TIME']!=$GLOBALS['EXEC_TIME'])    {       // Set the simulation flag, if simulation is detected!
+               if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_ACCESS_TIME']!=$GLOBALS['ACCESS_TIME'])        {       // Set the simulation flag, if simulation is detected!
                        $this->simulationHiddenOrTime=1;
                }
-               $this->whereClause.= 'AND (starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_EXEC_TIME'].')';
+               $this->whereClause.= 'AND (starttime<='.$GLOBALS['SIM_ACCESS_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_ACCESS_TIME'].')';
                if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'])       {
                        $this->menuclasses='tmenu,jsmenu,gmenu';
                }
 
                        // Sets the paths from where TypoScript resources are allowed to be used:
-               $this->allowedPaths = Array ('media/','fileadmin/','uploads/','typo3temp/','t3lib/fonts/',TYPO3_mainDir.'ext/',TYPO3_mainDir.'sysext/','typo3conf/ext/');
+               $this->allowedPaths = Array(
+                       'media/',
+                       'fileadmin/',
+                       'uploads/',
+                       'typo3temp/',
+                       't3lib/fonts/',
+                       TYPO3_mainDir . 'ext/',
+                       TYPO3_mainDir . 'sysext/',
+                       TYPO3_mainDir . 'contrib/',
+                       'typo3conf/ext/'
+               );
                if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'])       {
-                       $pathArr = t3lib_div::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'],1);
-                       while(list(,$p)=each($pathArr)) {
+                       $pathArr = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'], true);
+                       foreach ($pathArr as $p) {
                                        // Once checked for path, but as this may run from typo3/mod/web/ts/ dir, that'll not work!! So the paths ar uncritically included here.
                                $this->allowedPaths[] = $p;
                        }
@@ -240,37 +247,56 @@ class t3lib_TStemplate    {
         * Fetches the "currentPageData" array from cache
         *
         * NOTE about currentPageData:
-        * It holds information about the TypoScript conditions along with the list of template uid's which is used on the page.
-        * In the getFromCache function in TSFE, currentPageData is used to evaluate if there is a template and if the matching conditions are alright
-        * Unfortunately this does not take into account if the templates in the rowSum of currentPageData has changed composition, eg. due to hidden fields or start/end time.
-        * So if a template is hidden or times out, it'll not be discovered unless the page is regenerated - at least the this->start function must be called, because this will make a new portion of data in currentPageData string
+        * It holds information about the TypoScript conditions along with the list
+        * of template uid's which is used on the page. In the getFromCache function
+        * in TSFE, currentPageData is used to evaluate if there is a template and
+        * if the matching conditions are alright. Unfortunately this does not take
+        * into account if the templates in the rowSum of currentPageData has
+        * changed composition, eg. due to hidden fields or start/end time. So if a
+        * template is hidden or times out, it'll not be discovered unless the page
+        * is regenerated - at least the this->start function must be called,
+        * because this will make a new portion of data in currentPageData string.
         *
-        * @return      mixed           The array $this->currentPageData if found cached in "cache_pagesection". If the string "none" was returned it means the array must be generated and stored in the cache-table
+        * @return      array           Returns the unmatched array $currentPageData if found cached in "cache_pagesection". Otherwise false is returned which means that the array must be generated and stored in the cache-table
         * @see start(), tslib_fe::getFromCache()
         */
-       function getCurrentPageData()   {
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
-               if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                       $this->currentPageData = unserialize($row['content']);
+       function getCurrentPageData() {
+               $currentPageData = false;
+               if (TYPO3_UseCachingFramework) {
+                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                       /* @var $pageSectionCache t3lib_cache_AbstractCache */
+
+                       $cacheEntry = $pageSectionCache->get(
+                               intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
+                       );
+
+                       if ($cacheEntry) {
+                               $currentPageData = unserialize($cacheEntry);
+                       }
                } else {
-                       $this->currentPageData = 'none';
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               'content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
+                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                               $currentPageData = unserialize($row['content']);
+                       }
                }
-               return $this->currentPageData;
+
+               return $currentPageData;        // 2008-02-03 / Stucki: Notice that $this->currentPageData is not used anymore!
        }
 
        /**
         * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
         *
-        * @param       array           An array with three keys, "all", "rowSum" and "rootLine" - all coming from the $this->currentPageData array
+        * @param       array           An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array
         * @return      array           The input array but with a new key added, "match" which contains the items from the "all" key which when passed to tslib_matchCondition returned true.
         * @see t3lib_matchCondition, tslib_fe::getFromCache()
         */
        function matching($cc)  {
                if (is_array($cc['all']))       {
-                       reset($cc['all']);
-                       $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
-                       $matchObj->altRootLine=$cc['rootLine'];
-                       while(list($key,$pre)=each($cc['all'])) {
+                       /* @var $matchObj t3lib_matchCondition_frontend */
+                       $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
+                       $matchObj->setRootline((array)$cc['rootLine']);
+                       foreach ($cc['all'] as $key => $pre) {
                                if ($matchObj->match($pre))     {
                                        $sectionsMatch[$key]=$pre;
                                }
@@ -282,54 +308,73 @@ class t3lib_TStemplate    {
 
        /**
         * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
-        * The method traverse the rootline structure from out to in, fetches the hierarchy of template records and based on this either finds the cached TypoScript template structure or parses the template and caches it for next time.
-        * Sets $this->setup to the parsed TypoScript Template array
+        * The method traverses the rootline structure from out to in, fetches the hierarchy of template records and based on this either finds the cached TypoScript template structure or parses the template and caches it for next time.
+        * Sets $this->setup to the parsed TypoScript template array
         *
         * @param       array           The rootline of the current page (going ALL the way to tree root)
         * @return      void
         * @see tslib_fe::getConfigArray()
         */
        function start($theRootLine)    {
-               if (is_array($theRootLine))     {
-                       $setupData='';
-                       $cc=Array();
-                       $hash='';
+               if (is_array($theRootLine)) {
+                       $setupData = '';
+                       $hash = '';
+
+                               // Flag that indicates that the existing data in cache_pagesection
+                               // could be used (this is the case if $TSFE->all is set, and the
+                               // rowSum still matches). Based on this we decide if cache_pagesection
+                               // needs to be updated...
+                       $isCached = false;
+
                        $this->runThroughTemplates($theRootLine);
 
-                               // Getting the currentPageData if not already found
-                       if (!$this->currentPageData && !$GLOBALS['TSFE']->no_cache)     {
-                               $this->getCurrentPageData();
+                       if ($GLOBALS['TSFE']->all) {
+                               $cc = $GLOBALS['TSFE']->all;
+
+                                       // The two rowSums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
+                               if (strcmp(serialize($this->rowSum),serialize($cc['rowSum']))) {
+                                       unset($cc);     // If the two rowSums differ, we need to re-make the current page data and therefore clear the existing values.
+                               } else {
+                                               // If $TSFE->all contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already)
+                                       if (!strcmp(serialize($this->rootLine), serialize($cc['rootLine']))) {
+                                               $isCached = true;
+                                       }
+                                               // When the data is serialized below (ROWSUM hash), it must not contain the rootline by concept. So this must be removed (and added again later)...
+                                       unset($cc['rootLine']);
+                               }
                        }
 
                                // This is about getting the hash string which is used to fetch the cached TypoScript template.
-                               // If there was some cached currentPageData that's good (it gives us the hash),
-                               // However if the actual rowSum and the rowSum of currentPageData is different from each other, thats a problem, and we should re-make the current page data.
-                       if (is_array($this->currentPageData) &&
-                               !strcmp(serialize($this->rowSum), serialize($this->currentPageData['rowSum']))  // The two ROWsums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
-                       )       {
-                                       // If currentPageData was actually there, we match the result...
-                               $cc['all'] = $this->currentPageData['all'];
-                               $cc['rowSum'] = $this->currentPageData['rowSum'];
-                               $cc = $this->matching($cc);
+                               // If there was some cached currentPageData ($cc) then that's good (it gives us the hash).
+                       if (is_array($cc)) {
+                                       // If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...)
+                               if (!$cc['match']) {
+                                               // TODO: check if this can ever be the case - otherwise remove
+                                       $cc = $this->matching($cc);
+                                       ksort($cc);
+                               }
                                $hash = md5(serialize($cc));
                        } else {
-                                       // If currentPageData was not there, we first find $rowSum (freshly generated). After that we try to see, if rowSum is stored with a list of all matching-parameters. If so we match the result
+                                       // If currentPageData was not there, we first find $rowSum (freshly generated). After that we try to see, if it is stored with a list of all conditions. If so we match the result.
                                $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
-                               $result = t3lib_pageSelect::getHash($rowSumHash, 0);
-                               if ($result)    {
+                               $result = t3lib_pageSelect::getHash($rowSumHash);
+
+                               if ($result) {
+                                       $cc = array();
                                        $cc['all'] = unserialize($result);
                                        $cc['rowSum'] = $this->rowSum;
                                        $cc = $this->matching($cc);
+                                       ksort($cc);
                                        $hash = md5(serialize($cc));
                                }
                        }
 
-                       if ($hash)      {
+                       if ($hash) {
                                        // Get TypoScript setup array
-                               $setupData = t3lib_pageSelect::getHash($hash, 0);
+                               $setupData = t3lib_pageSelect::getHash($hash);
                        }
 
-                       if ($hash && $setupData && !$this->forceTemplateParsing)                {
+                       if ($setupData && !$this->forceTemplateParsing) {
                                        // If TypoScript setup structure was cached we unserialize it here:
                                $this->setup = unserialize($setupData);
                        } else {
@@ -337,37 +382,56 @@ class t3lib_TStemplate    {
                                $this->generateConfig();
 
                                        // This stores the template hash thing
-                               $cc=Array();
-                               $cc['all']=$this->sections;     // All sections in the template at this point is found
-                               $cc['rowSum']=$this->rowSum;    // The line of templates is collected
+                               $cc = array();
+                               $cc['all'] = $this->sections;   // All sections in the template at this point is found
+                               $cc['rowSum'] = $this->rowSum;  // The line of templates is collected
                                $cc = $this->matching($cc);
+                               ksort($cc);
 
                                $hash = md5(serialize($cc));
 
                                        // This stores the data.
-                               t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS TEMPLATE');
+                               t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS_TEMPLATE');
 
                                if ($this->tt_track)    $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup)).' bytes');
 
                                $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
-                               t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - AL');
+                               t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL_CONDITIONS_ALL');
                        }
                                // Add rootLine
                        $cc['rootLine'] = $this->rootLine;
-                               // Make global and save.
-                       $GLOBALS['TSFE']->all=$cc;
-
-                       if (!$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache)      {       // Only save currentPageData, if we're not simulating by hidden/starttime/endtime
-                               $dbFields = array(
-                                       'content' => serialize($cc),
-                                       'tstamp' => $GLOBALS['EXEC_TIME']
-                               );
-                               $mpvar_hash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
-                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvar_hash, $dbFields);
-                               if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
-                                       $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
-                                       $dbFields['mpvar_hash'] = $mpvar_hash;
-                                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
+                       ksort($cc);
+
+                               // Make global and save
+                       $GLOBALS['TSFE']->all = $cc;
+
+                               // Matching must be executed for every request, so this must never be part of the pagesection cache!
+                       unset($cc['match']);
+
+                       if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) {      // Only save the data if we're not simulating by hidden/starttime/endtime
+                               $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
+                               if (TYPO3_UseCachingFramework) {
+                                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                                       /* @var $pageSectionCache t3lib_cache_AbstractCache */
+                                       $pageSectionCache->set(
+                                               intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
+                                               serialize($cc),
+                                               array(
+                                                       'pageId_' . intval($GLOBALS['TSFE']->id),
+                                                       'mpvarHash_' . $mpvarHash
+                                               )
+                                       );
+                               } else {
+                                       $dbFields = array(
+                                               'content' => serialize($cc),
+                                               'tstamp' => $GLOBALS['EXEC_TIME']
+                                       );
+                                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvarHash, $dbFields);
+                                       if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
+                                               $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
+                                               $dbFields['mpvar_hash'] = $mpvarHash;
+                                               $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
+                                       }
                                }
                        }
                                // If everything OK.
@@ -506,8 +570,8 @@ class t3lib_TStemplate      {
                                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                                }
                        } else {        // NORMAL OPERATION:
-                               $basedOnArr = t3lib_div::intExplode(',',$row['basedOn']);
-                               while(list(,$id)=each($basedOnArr))     {       // traversing list
+                               $basedOnArr = t3lib_div::intExplode(',', $row['basedOn']);
+                               foreach ($basedOnArr as $id) { // traversing list
                                        if (!t3lib_div::inList($idList,'sys_'.$id))     {       // if $id is not allready included ...
                                                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
                                                if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {       // there was a template, then we fetch that
@@ -584,9 +648,8 @@ class t3lib_TStemplate      {
        function includeStaticTypoScriptSources($idList,$templateID,$pid,$row)  {
                        // Static Template Records (static_template): include_static is a list of static templates to include
                if (trim($row['include_static']))       {
-                       $include_staticArr = t3lib_div::intExplode(',',$row['include_static']);
-                       reset($include_staticArr);
-                       while(list(,$id)=each($include_staticArr))      {       // traversing list
+                       $include_staticArr = t3lib_div::intExplode(',', $row['include_static']);
+                       foreach ($include_staticArr as $id) { // traversing list
                                if (!t3lib_div::inList($idList,'static_'.$id))  {       // if $id is not allready included ...
                                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_template', 'uid='.intval($id));
                                        if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {       // there was a template, then we fetch that
@@ -600,14 +663,12 @@ class t3lib_TStemplate    {
 
                        // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
                if (trim($row['include_static_file']))  {
-                       $include_static_fileArr = t3lib_div::trimExplode(',',$row['include_static_file'],1);
-                       reset($include_static_fileArr);
-                       while(list(,$ISF_file)=each($include_static_fileArr))   {       // traversing list
-                               $ISF_file = trim($ISF_file);
+                       $include_static_fileArr = t3lib_div::trimExplode(',', $row['include_static_file'], true);
+                       foreach ($include_static_fileArr as $ISF_file) { // traversing list
                                if (substr($ISF_file,0,4)=='EXT:')      {
                                        list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
                                        if (strcmp($ISF_extKey,'') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
-                                               $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
+                                               $ISF_localPath = rtrim($ISF_localPath, '/').'/';
                                                $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey).$ISF_localPath;
                                                if (@is_dir($ISF_filePath))     {
                                                        $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
@@ -647,8 +708,7 @@ class t3lib_TStemplate      {
                global $TYPO3_LOADED_EXT;
 
                if ($row['static_file_mode']==1 || ($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root']))    {
-                       reset($TYPO3_LOADED_EXT);
-                       while(list($extKey,$files)=each($TYPO3_LOADED_EXT))     {
+                       foreach ($TYPO3_LOADED_EXT as $extKey => $files) {
                                if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt']))       {
                                        $mExtKey = str_replace('_','',$extKey);
                                        $subrow=array(
@@ -750,9 +810,11 @@ class t3lib_TStemplate     {
                $constants->breakPointLN=intval($this->ext_constants_BRP);
                $constants->setup = $this->const;
                $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
-               $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
-               $matchObj->matchAlternative = $this->matchAlternative;
-               $matchObj->matchAll = $this->matchAll;          // Matches ALL conditions in TypoScript
+
+               /* @var $matchObj t3lib_matchCondition_frontend */
+               $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
+               $matchObj->setSimulateMatchConditions($this->matchAlternative);
+               $matchObj->setSimulateMatchResult((bool)$this->matchAll);
 
                        // Traverse constants text fields and parse them
                foreach($this->constants as $str)       {
@@ -795,14 +857,14 @@ class t3lib_TStemplate    {
 
                        // Searching for possible unsubstituted constants left (only for information)
                if (strstr($all,'{$'))  {
-                       $findConst = explode('{$',$all);
-                       $theConstList=Array();
-                       next($findConst);
-                       while(list(,$constVal)=each($findConst))        {
+                       $theConstList = array();
+                       $findConst = explode('{$', $all);
+                       array_shift($findConst);
+                       foreach ($findConst as $constVal) {
                                $constLen=t3lib_div::intInRange(strcspn($constVal,'}'),0,50);
                                $theConstList[]='{$'.substr($constVal,0,$constLen+1);
                        }
-                       if ($this->tt_track)    $GLOBALS['TT']->setTSlogMessage(implode(',',$theConstList).': Constants may remain un-substituted!!',2);
+                       if ($this->tt_track)    $GLOBALS['TT']->setTSlogMessage(implode(', ',$theConstList).': Constants may remain un-substituted!!',2);
                }
 
                        // Logging the textual size of the TypoScript Setup field text with all constants substituted:
@@ -865,14 +927,15 @@ class t3lib_TStemplate    {
                unset($this->setup['types.']);
                unset($this->setup['types']);
                if (is_array($this->setup)) {
-                       reset ($this->setup);
-                       while(list($theKey,)=each($this->setup))        {
-                               if ($this->setup[$theKey]=='PAGE')      {
-                                       $tN = $this->setup[$theKey.'.']['typeNum'];
-                                       if (isset($tN)) {
-                                               $this->setup['types.'][$tN] = $theKey;
-                                       } elseif(!$this->setup['types.'][0])    {       // If there is no type 0 yet and typeNum was not set, we use the current object as the default
-                                               $this->setup['types.'][0] = $theKey;
+                       foreach ($this->setup as $key => $value) {
+                               if ($value=='PAGE')     {
+                                               // Set the typeNum of the current page object:
+                                       if (isset($this->setup[$key.'.']['typeNum'])) {
+                                               $typeNum = $this->setup[$key.'.']['typeNum'];
+                                               $this->setup['types.'][$typeNum] = $key;
+                                               // If there is no type 0 yet and typeNum was not set, we use the current object as the default
+                                       } elseif(!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) {
+                                               $this->setup['types.'][0] = $key;
                                        }
                                }
                        }
@@ -893,20 +956,30 @@ class t3lib_TStemplate    {
         * @return      void
         * @see t3lib_TSparser, generateConfig()
         */
-       function procesIncludes()       {
-               reset($this->constants);
-               while(list($k)=each($this->constants))  {
-                       $this->constants[$k]=t3lib_TSparser::checkIncludeLines($this->constants[$k]);
+       function procesIncludes() {
+               $files = array();
+               foreach ($this->constants as &$value) {
+                       $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
+                       $files = array_merge($files, $includeData['files']);
+                       $value = $includeData['typoscript'];
                }
 
-               reset($this->config);
-               while(list($k)=each($this->config))     {
-                       $this->config[$k]=t3lib_TSparser::checkIncludeLines($this->config[$k]);
+               foreach ($this->config as &$value) {
+                       $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
+                       $files = array_merge($files, $includeData['files']);
+                       $value = $includeData['typoscript'];
                }
 
-               reset($this->editorcfg);
-               while(list($k)=each($this->editorcfg))  {
-                       $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]);
+               foreach ($this->editorcfg as &$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));
+                       }
                }
        }
 
@@ -948,8 +1021,7 @@ class t3lib_TStemplate     {
         */
        function flattenSetup($setupArray, $prefix, $resourceFlag)      {
                if (is_array($setupArray))      {
-                       reset($setupArray);
-                       while(list($key,$val)=each($setupArray))        {
+                       foreach ($setupArray as $key => $val) {
                                if ($prefix || substr($key,0,16)!='TSConstantEditor')   {               // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
                                        if (is_array($val))     {
                                                $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
@@ -1044,12 +1116,8 @@ class t3lib_TStemplate   {
                                        foreach($tempConf as $aKey => $val)     {
                                                $conf2[$aKey][$cKey] = $val;
                                        }
-                               }
-                       }
-
-                               // Splitting of all values on this level of the TypoScript object tree:
-                       foreach($conf as $cKey => $val) {
-                               if (!is_array($val))    {
+                               } else {
+                                               // Splitting of all values on this level of the TypoScript object tree:
                                        if (!strstr($val,'|*|') && !strstr($val,'||'))  {
                                                for ($aKey=0;$aKey<$splitCount;$aKey++) {
                                                        $conf2[$aKey][$cKey] = $val;
@@ -1134,10 +1202,12 @@ class t3lib_TStemplate  {
                        if (@is_file($this->getFileName_backPath.$file))        {
                                $outFile = $file;
                                $fileInfo = t3lib_div::split_fileref($outFile);
-                               reset($this->allowedPaths);
                                $OK=0;
-                               while(list(,$val)=each($this->allowedPaths))    {
-                                       if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
+                               foreach ($this->allowedPaths as $val) {
+                                       if (substr($fileInfo['path'], 0, strlen($val))==$val) {
+                                               $OK=1;
+                                               break;
+                                       }
                                }
                                if ($OK)        {
                                        $this->fileCache[$hash]=$outFile;
@@ -1170,11 +1240,10 @@ class t3lib_TStemplate  {
                } elseif (strstr($file,'*')) {
                        $fileparts=explode('*',$file);
                        $c=count($fileparts);
-                       $files = explode(',',$res);
-                       while(list(,$val)=each($files)) {
-                               $test = trim($val);
-                               if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test))     {
-                                       $outFile = $test;
+                       $files = t3lib_div::trimExplode(',', $res);
+                       foreach ($files as $file) {
+                               if (preg_match('/^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$/', $file)) {
+                                       $outFile = $file;
                                        break;
                                }
                        }
@@ -1189,10 +1258,12 @@ class t3lib_TStemplate  {
         * @param       string          Property name in the menu array
         * @param       array           Menu array to traverse
         * @return      array           Modified menu array
-        * @deprecated
+        * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5.
         * @internal
         */
        function checkFile($name,$menuArr)      {
+               t3lib_div::logDeprecatedFunction();
+
                reset ($menuArr);
                while (list($aKey,)=each($menuArr))     {
                        $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
@@ -1278,23 +1349,36 @@ class t3lib_TStemplate  {
         * @return      array           An array with all integer properties listed in numeric order.
         * @see tslib_cObj::cObjGet(), tslib_gifBuilder, tslib_imgmenu::makeImageMap()
         */
-       function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE)  {
-               $keyArr = Array();
-
-               reset($setupArr);
-               while(list($key,)=each($setupArr))      {
-                       $ikey = intval($key);
-                       if (!strcmp($ikey,$key) || $acceptOnlyProperties)       {
-                               $keyArr[] = $ikey;
+       function sortedKeyList($setupArr, $acceptOnlyProperties=false) {
+               $keyArr = array();
+               $setupArrKeys = array_keys($setupArr);
+               foreach ($setupArrKeys as $key) {
+                       if ($acceptOnlyProperties || t3lib_div::testInt($key)) {
+                               $keyArr[] = intval($key);
                        }
                }
-
                $keyArr = array_unique($keyArr);
                sort($keyArr);
                return $keyArr;
        }
 
 
+       /**
+        * Returns the level of the given page in the rootline - Multiple pages can be given by separating the UIDs by comma.
+        *
+        * @param       string          A list of UIDs for which the rootline-level should get returned
+        * @return      integer The level in the rootline. If more than one page was given the lowest level will get returned.
+        */
+       function getRootlineLevel($list)        {
+               $idx = 0;
+               foreach($this->rootLine as $page)       {
+                       if (t3lib_div::inList($list, $page['uid'])) {
+                               return $idx;
+                       }
+                       $idx++;
+               }
+               return false;
+       }
 
 
 
@@ -1312,7 +1396,7 @@ class t3lib_TStemplate    {
        /**
         * The mother of all functions creating links/URLs etc in a TypoScript environment.
         * See the references below.
-        * Basically this function takes care of issues such as type,id,alias and Mount Points, simulate static documents, M5/B6 encoded parameters etc.
+        * Basically this function takes care of issues such as type,id,alias and Mount Points, URL rewriting (through hooks), M5/B6 encoded parameters etc.
         * It is important to pass all links created through this function since this is the guarantee that globally configured settings for link creating are observed and that your applications will conform to the various/many configuration options in TypoScript Templates regarding this.
         *
         * @param       array           The page record of the page to which we are creating a link. Needed due to fields like uid, alias, target, no_cache, title and sectionIndex_uid.
@@ -1322,10 +1406,11 @@ class t3lib_TStemplate  {
         * @param       array           Array with overriding values for the $page array.
         * @param       string          Additional URL parameters to set in the URL. Syntax is "&foo=bar&foo2=bar2" etc. Also used internally to add parameters if needed.
         * @param       string          If you set this value to something else than a blank string, then the typeNumber used in the link will be forced to this value. Normally the typeNum is based on the target set OR on $GLOBALS['TSFE']->config['config']['forceTypeValue'] if found.
+        * @param       string          The target Doamin, if any was detected in typolink
         * @return      array           Contains keys like "totalURL", "url", "sectionIndex", "linkVars", "no_cache", "type", "target" of which "totalURL" is normally the value you would use while the other keys contains various parts that was used to construct "totalURL"
         * @see tslib_frameset::frameParams(), tslib_cObj::typoLink(), tslib_cObj::SEARCHRESULT(), TSpagegen::pagegenInit(), tslib_menu::link()
         */
-       function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='')    {
+       function linkData($page, $oTarget, $no_cache, $script, $overrideArray='', $addParams='', $typeOverride='', $targetDomain='') {
                global $TYPO3_CONF_VARS;
 
                $LD = Array();
@@ -1371,7 +1456,7 @@ class t3lib_TStemplate    {
                } else {
                        $LD['type'] = '';
                }
-               $LD['orig_type'] = $LD['type'];         // Preserving the type number. Will not be cleared if simulateStaticDocuments.
+               $LD['orig_type'] = $LD['type'];         // Preserving the type number.
 
                        // noCache
                $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : '';
@@ -1387,37 +1472,6 @@ class t3lib_TStemplate   {
                        $LD['linkVars'] = $GLOBALS['TSFE']->linkVars.$addParams;
                }
 
-                       // If simulateStaticDocuments is enabled:
-               if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments'])      {
-                       $LD['type'] = '';
-                       $LD['url'] = '';
-
-                               // MD5/base64 method limitation:
-                       $remainLinkVars='';
-                       $flag_simulateStaticDocuments_pEnc = t3lib_div::inList('md5,base64',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc']) && !$LD['no_cache'];
-                       if ($flag_simulateStaticDocuments_pEnc) {
-                               list($LD['linkVars'], $remainLinkVars) = $GLOBALS['TSFE']->simulateStaticDocuments_pEnc_onlyP_proc($LD['linkVars']);
-                       }
-
-                       $LD['url'].=$GLOBALS['TSFE']->makeSimulFileName(
-                                                       $page['title'],
-                                                       $page['alias'] ? $page['alias'] : $page['uid'],
-                                                       intval($typeNum),
-                                                       $LD['linkVars'],
-                                                       $LD['no_cache'] ? true : false
-                                               );
-
-                       if ($flag_simulateStaticDocuments_pEnc) {
-                               $LD['linkVars']=$remainLinkVars;
-                       }
-                       if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']=='PATH_INFO') {
-                               $LD['url'] = str_replace('.','/',$LD['url']);
-                               $LD['url'] = 'index.php/'.$LD['url'].'/?';
-                       } else {
-                               $LD['url'].= '.html?';
-                       }
-               }
-
                        // Add absRefPrefix if exists.
                $LD['url'] = $GLOBALS['TSFE']->absRefPrefix.$LD['url'];
 
@@ -1431,7 +1485,7 @@ class t3lib_TStemplate    {
                if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc']))  {
                        $_params = array(
                                                        'LD' => &$LD,
-                                                       'args' => array('page'=>$page, 'oTarget'=>$oTarget, 'no_cache'=>$no_cache, 'script'=>$script, 'overrideArray'=>$overrideArray, 'addParams'=>$addParams, 'typeOverride'=>$typeOverride),
+                                                       'args' => array('page'=>$page, 'oTarget'=>$oTarget, 'no_cache'=>$no_cache, 'script'=>$script, 'overrideArray'=>$overrideArray, 'addParams'=>$addParams, 'typeOverride'=>$typeOverride,'targetDomain'=>$targetDomain),
                                                        'typeNum' => $typeNum
                                                );
                        foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef)  {
@@ -1567,4 +1621,5 @@ class t3lib_TStemplate    {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php'])       {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
 }
+
 ?>