Added feature #15668: TYPO3 Backend should display flags for translations as sprite...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tstemplate.php
index 117cd15..71c24b3 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2009 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]
@@ -99,7 +99,7 @@
 /**
  * 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,7 +225,7 @@ class t3lib_TStemplate      {
                        // Sets the paths from where TypoScript resources are allowed to be used:
                $this->allowedPaths = Array(
                        'media/',
-                       'fileadmin/',
+                       $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'],      // fileadmin/ path
                        'uploads/',
                        'typo3temp/',
                        't3lib/fonts/',
@@ -279,9 +279,10 @@ class t3lib_TStemplate     {
                        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;
        }
 
        /**
@@ -510,6 +511,7 @@ class t3lib_TStemplate      {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        $this->rootLine[] = $this->absoluteRootLine[$a];
                }
+               $this->processIncludes();
        }
 
        /**
@@ -547,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);
                }
 
@@ -569,18 +572,30 @@ class t3lib_TStemplate    {
                                        }
                                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                                }
-                       } else {        // NORMAL OPERATION:
-                               $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
-                                                       $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);
                                        }
                                }
                        }
@@ -602,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.
@@ -636,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"
@@ -647,17 +662,16 @@ 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']);
-                       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
-                                               $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);
                        }
                }
 
@@ -691,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);
+                       }
+               }
        }
 
        /**
@@ -793,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;
@@ -951,12 +978,25 @@ 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() {
+       public function processIncludes() {
                $files = array();
                foreach ($this->constants as &$value) {
                        $includeData = t3lib_TSparser::checkIncludeLines($value, 1, true);
@@ -978,7 +1018,7 @@ class t3lib_TStemplate     {
                if (count($files)) {
                        $files = array_unique($files);
                        foreach ($files as $file) {
-                               $this->rowSum[] = Array($file, filemtime($file));
+                               $this->rowSum[] = array($file, filemtime($file));
                        }
                }
        }
@@ -999,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);
@@ -1197,9 +1237,13 @@ 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);
                                $OK=0;
@@ -1258,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 since TYPO3 3.6
+        * @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;
@@ -1312,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()
         */
@@ -1575,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))      {