Added feature #15668: TYPO3 Backend should display flags for translations as sprite...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tstemplate.php
old mode 100755 (executable)
new mode 100644 (file)
index e0f8988..71c24b3
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -28,9 +28,9 @@
  * Class with template object that is responsible for generating the template
  *
  * $Id$
- * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -80,8 +80,6 @@
  *
  */
 
-require_once (PATH_t3lib.'class.t3lib_tsparser.php');
-require_once (PATH_t3lib.'class.t3lib_matchcondition.php');
 
 
 
@@ -101,7 +99,7 @@ require_once (PATH_t3lib.'class.t3lib_matchcondition.php');
 /**
  * Template object that is responsible for generating the TypoScript template based on template records.
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  * @see        t3lib_tsparser.php, t3lib_matchcondition.php
@@ -225,10 +223,20 @@ class t3lib_TStemplate    {
                }
 
                        // 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/',
+                       $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'],      // fileadmin/ path
+                       '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;
                        }
@@ -254,18 +262,27 @@ class t3lib_TStemplate    {
         */
        function getCurrentPageData() {
                $currentPageData = false;
-               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
-               /* @var $pageSectionCache t3lib_cache_AbstractCache */
+               if (TYPO3_UseCachingFramework) {
+                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                       /* @var $pageSectionCache t3lib_cache_AbstractCache */
 
-               $cacheEntry = $pageSectionCache->load(
-                       intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
-               );
+                       $cacheEntry = $pageSectionCache->get(
+                               intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
+                       );
 
-               if ($cacheEntry) {
-                       $currentPageData = unserialize($cacheEntry);
+                       if ($cacheEntry) {
+                               $currentPageData = unserialize($cacheEntry);
+                       }
+               } else {
+                       $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']);
+                       }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
 
-               return $currentPageData;        // 2008-02-03 / Stucki: Notice that $this->currentPageData is not used anymore!
+               return $currentPageData;
        }
 
        /**
@@ -277,10 +294,10 @@ class t3lib_TStemplate    {
         */
        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;
                                }
@@ -393,20 +410,30 @@ class t3lib_TStemplate    {
                        unset($cc['match']);
 
                        if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) {      // Only save the data if we're not simulating by hidden/starttime/endtime
-                               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
-                               /* @var $pageSectionCache t3lib_cache_AbstractCache */
-
                                $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
-
-                               $pageSectionCache->save(
-                                       intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
-                                       serialize($cc),
-                                       array(
-                                               'pageId_' . intval($GLOBALS['TSFE']->id),
-                                               'mpvarHash_' . $mpvarHash
-                                       )
-                               );
-
+                               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.
                        if ($this->rootId && $this->rootLine && $this->setup)   {
@@ -484,6 +511,7 @@ class t3lib_TStemplate      {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        $this->rootLine[] = $this->absoluteRootLine[$a];
                }
+               $this->processIncludes();
        }
 
        /**
@@ -521,7 +549,8 @@ class t3lib_TStemplate      {
                }
 
                        // Include static records (static_template) or files (from extensions) (#1/2)
-               if (!$row['includeStaticAfterBasedOn'])         {               // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
+                       // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
+               if (!$row['includeStaticAfterBasedOn'])         {
                        $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
                }
 
@@ -543,18 +572,30 @@ 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
-                                       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
-                                                       $this->versionOL($subrow);
-                                                       if (is_array($subrow))  {
-                                                               $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
-                                                       }
-                                               }
-                                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       } else {
+                                       // Normal Operation, which is to include the "based-on" sys_templates,
+                                       // if they are not already included, and maintaining the sorting of the templates
+                               $basedOnIds = t3lib_div::intExplode(',', $row['basedOn']);
+
+                                       // skip template if it's already included
+                               foreach ($basedOnIds as $key => $basedOnId) {
+                                       if (t3lib_div::inList($idList, 'sys_' . $basedOnId)) {
+                                               unset($basedOnIds[$key]);
+                                       }
+                               }
+
+                               $subTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       '*', 'sys_template',
+                                       'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause,
+                                       '', '', '',
+                                       'uid'   // the associative array that is returned will contain this field as key
+                               );
+
+                                       // traversing list again to ensure the sorting of the templates
+                               foreach ($basedOnIds as $id) {
+                                       if (is_array($subTemplates[$id])) {
+                                               $this->versionOL($subTemplates[$id]);
+                                               $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
                                        }
                                }
                        }
@@ -576,7 +617,7 @@ class t3lib_TStemplate      {
                        'title'=>$row['title'],
                        'uid'=>$row['uid'],
                        'pid'=>$row['pid'],
-                       'configLines' => substr_count($row['config'], chr(10))+1
+                       'configLines' => substr_count($row['config'], LF)+1
                );
 
                        // Adding the content of the fields constants (Constants), config (Setup) and editorcfg (Backend Editor Configuration) to the internal arrays.
@@ -610,7 +651,7 @@ class t3lib_TStemplate      {
        }
 
        /**
-        * Includes static template records (from static_template table) and static template files (from extensions) for the input template record row.
+        * Includes static template records (from static_template table, loaded through a hook) and static template files (from extensions) for the input template record row.
         *
         * @param       string          A list of already processed template ids including the current; The list is on the form "[prefix]_[uid]" where [prefix] is "sys" for "sys_template" records, "static" for "static_template" records and "ext_" for static include files (from extensions). The list is used to check that the recursive inclusion of templates does not go into circles: Simply it is used to NOT include a template record/file which has already BEEN included somewhere in the recursion.
         * @param       string          The id of the current template. Same syntax as $idList ids, eg. "sys_123"
@@ -621,31 +662,27 @@ 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
-                               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
-                                               $subrow = $this->prependStaticExtra($subrow);
-                                               $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
-                                       }
-                                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
-                               }
+                       // Call function for link rendering:
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'])) {
+                       $_params = array(
+                                       'idList' => &$idList,
+                                       'templateId' => &$templateID,
+                                       'pid' => &$pid,
+                                       'row' => &$row
+                       );
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] as $_funcRef)  {
+                               t3lib_div::callUserFunction($_funcRef, $_params, $this);
                        }
                }
 
                        // 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);
@@ -668,6 +705,19 @@ class t3lib_TStemplate     {
                }
 
                $this->addExtensionStatics($idList,$templateID,$pid,$row);
+
+                       // Include Static Template Records after all other TypoScript has been included.
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'])) {
+                       $_params = array(
+                                       'idList' => &$idList,
+                                       'templateId' => &$templateID,
+                                       'pid' => &$pid,
+                                       'row' => &$row
+                       );
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] as $_funcRef)     {
+                               t3lib_div::callUserFunction($_funcRef, $_params, $this);
+                       }
+               }
        }
 
        /**
@@ -685,8 +735,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(
@@ -771,7 +820,7 @@ class t3lib_TStemplate      {
                array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']);    // Adding default TS/editorcfg
 
                        // Parse the TypoScript code text for include-instructions!
-               $this->procesIncludes();
+               $this->processIncludes();
 
                        // These vars are also set lateron...
                $this->setup['resources']= $this->resources;
@@ -788,9 +837,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)       {
@@ -833,10 +884,10 @@ 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);
                        }
@@ -903,14 +954,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;
                                        }
                                }
                        }
@@ -926,25 +978,48 @@ class t3lib_TStemplate    {
 
        /**
         * Searching TypoScript code text (for constants, config (Setup) and editorcfg) for include instructions and does the inclusion if needed.
-        * Modifies
+        *
+        * @return      void
+        * @deprecated since TYPO3 4.4 - Method name misspelled. Use "processIncludes" instead! This function will be removed in TYPO3 4.6.
+        * @see t3lib_TSparser, processIncludes()
+        */
+       public function procesIncludes() {
+               t3lib_div::logDeprecatedFunction();
+               $this->processIncludes();
+       }
+
+       /**
+        * Searching TypoScript code text (for constants, config (Setup) and editorcfg)
+        * for include instructions and does the inclusion of external TypoScript files
+        * if needed.
         *
         * @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]);
+       public function processIncludes() {
+               $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));
+                       }
                }
        }
 
@@ -964,7 +1039,7 @@ class t3lib_TStemplate     {
                }
                        // Parsing the user TS (or getting from cache)
                $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
-               $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
+               $userTS = implode(LF.'[GLOBAL]'.LF,$TSdataArray);
 
                $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
                $parseObj->parse($userTS);
@@ -986,8 +1061,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.'));
@@ -1082,12 +1156,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;
@@ -1167,15 +1237,21 @@ class t3lib_TStemplate  {
                }
 
                        // find
-               if (strstr($file,'/')) {        // here it is manual media
-                       if(!strcmp(substr($file,0,6),'media/')) $file = 'typo3/sysext/cms/tslib/'.$file;
-                       if (@is_file($this->getFileName_backPath.$file))        {
+               if (strpos($file, '/') !== false) {
+                               // if the file is in the media/ folder but it doesn't exist,
+                               // it is assumed that it's in the tslib folder
+                       if (t3lib_div::isFirstPartOfStr($file, 'media/') && !is_file($this->getFileName_backPath . $file)) {
+                               $file = t3lib_extMgm::siteRelPath('cms') . 'tslib/' . $file;
+                       }
+                       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;
@@ -1208,11 +1284,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;
                                }
                        }
@@ -1227,12 +1302,13 @@ 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.6.
         * @internal
         */
        function checkFile($name,$menuArr)      {
-               reset ($menuArr);
-               while (list($aKey,)=each($menuArr))     {
+               t3lib_div::logDeprecatedFunction();
+
+               foreach ($menuArr as $aKey => $value) {
                        $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
                }
                return $menuArr;
@@ -1281,7 +1357,7 @@ class t3lib_TStemplate    {
         * Ordinary "wrapping" function. Used in the tslib_menu class and extension classes instead of the similar function in tslib_cObj
         *
         * @param       string          The content to wrap
-        * @param       string          The wrap value, eg. "<b> | </b>"
+        * @param       string          The wrap value, eg. "<strong> | </strong>"
         * @return      string          Wrapped input string
         * @see tslib_menu, tslib_cObj::wrap()
         */
@@ -1316,17 +1392,14 @@ 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;
@@ -1366,7 +1439,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.
@@ -1376,10 +1449,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();
@@ -1425,7 +1499,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' : '';
@@ -1441,37 +1515,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'];
 
@@ -1485,7 +1528,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)  {
@@ -1577,7 +1620,8 @@ class t3lib_TStemplate    {
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                                'uid,pid,doktype,mount_pid,mount_pid_ol',
                                                'pages',
-                                               'pid='.intval($id).' AND deleted=0 AND doktype!=255 AND doktype!=6'     // 255 = Garbage bin, 6 = Backend User Section
+                                               'pid='.intval($id).' AND deleted=0 AND doktype!=' . t3lib_pageSelect::DOKTYPE_RECYCLER .
+                                                       ' AND doktype!=' . t3lib_pageSelect::DOKTYPE_BE_USER_SECTION
                                        );
                        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
 
@@ -1621,4 +1665,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']);
 }
+
 ?>