|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Class with template object that is responsible for generating the template 00029 * 00030 * $Id: class.t3lib_tstemplate.php 10663 2011-02-28 19:33:43Z lolli $ 00031 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj 00032 * 00033 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00034 */ 00035 /** 00036 * [CLASS/FUNCTION INDEX of SCRIPT] 00037 * 00038 * 00039 * 00040 * 109: class t3lib_TStemplate 00041 * 211: function init() 00042 * 249: function getCurrentPageData() 00043 * 266: function matching($cc) 00044 * 290: function start($theRootLine) 00045 * 00046 * SECTION: Fetching TypoScript code text for the Template Hierarchy 00047 * 406: function runThroughTemplates($theRootLine,$start_template_uid=0) 00048 * 459: function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') 00049 * 580: function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) 00050 * 642: function addExtensionStatics($idList,$templateID,$pid,$row) 00051 * 675: function prependStaticExtra($subrow) 00052 * 688: function versionOL(&$row) 00053 * 00054 * SECTION: Parsing TypoScript code text from Template Records into PHP array 00055 * 725: function generateConfig() 00056 * 891: function procesIncludes() 00057 * 915: function mergeConstantsFromPageTSconfig($constArray) 00058 * 944: function flattenSetup($setupArray, $prefix, $resourceFlag) 00059 * 968: function substituteConstants($all) 00060 * 991: function substituteConstantsCallBack($matches) 00061 * 00062 * SECTION: Various API functions, used from elsewhere in the frontend classes 00063 * 1022: function splitConfArray($conf,$splitCount) 00064 * 1099: function getFileName($fileFromSetup) 00065 * 1156: function extractFromResources($res,$file) 00066 * 1184: function checkFile($name,$menuArr) 00067 * 1201: function printTitle($title,$no_title=0,$titleFirst=0) 00068 * 1224: function fileContent($fName) 00069 * 1244: function wrap($content,$wrap) 00070 * 1258: function removeQueryString($url) 00071 * 1275: function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE) 00072 * 00073 * SECTION: Functions for creating links 00074 * 1322: function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') 00075 * 1449: function getFromMPmap($pageId=0) 00076 * 1485: function initMPmap_create($id,$MP_array=array(),$level=0) 00077 * 00078 * TOTAL FUNCTIONS: 28 00079 * (This index is automatically created/updated by the extension "extdeveval") 00080 * 00081 */ 00082 00083 00084 /** 00085 * Template object that is responsible for generating the TypoScript template based on template records. 00086 * 00087 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00088 * @package TYPO3 00089 * @subpackage t3lib 00090 * @see t3lib_tsparser, t3lib_matchcondition_abstract 00091 */ 00092 class t3lib_TStemplate { 00093 00094 // Debugging, analysis: 00095 var $tt_track = 1; // If set, the global tt-timeobject is used to log the performance. 00096 var $forceTemplateParsing = 0; // If set, the template is always rendered. Used from Admin Panel. 00097 00098 // Backend Analysis modules settings: 00099 var $matchAlternative = array(); // This array is passed on to matchObj by generateConfig(). If it holds elements, they are used for matching instead. See commment at the match-class. Used for backend modules only. Never frontend! 00100 var $matchAll = 0; // If set, the match-class matches everything! Used for backend modules only. Never frontend! 00101 var $parseEditorCfgField = 0; // If set, the Backend Editor Configuration TypoScript is also parsed (this is not needed for the frontend) 00102 var $backend_info = 0; 00103 var $getFileName_backPath = ''; // Set from the backend - used to set an absolute path (PATH_site) so that relative resources are properly found with getFileName() 00104 00105 // Externally set breakpoints (used by Backend Modules) 00106 var $ext_constants_BRP = 0; 00107 var $ext_config_BRP = 0; 00108 var $ext_editorcfg_BRP = 0; 00109 var $ext_regLinenumbers = FALSE; 00110 var $ext_regComments = FALSE; 00111 00112 // Constants: 00113 var $uplPath = 'uploads/tf/'; 00114 var $tempPath = 'typo3temp/'; 00115 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu'; 00116 00117 // Set Internally: 00118 var $whereClause = ''; // This MUST be initialized by the init() function 00119 var $debug = 0; 00120 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. 00121 var $simulationHiddenOrTime = 0; // See init(); Set if preview of some kind is enabled. 00122 00123 var $loaded = 0; // Set, if the TypoScript template structure is loaded and OK, see ->start() 00124 var $setup = array( // Default TypoScript Setup code 00125 'styles.' => array( 00126 'insertContent' => 'CONTENT', 00127 'insertContent.' => array( 00128 'table' => 'tt_content', 00129 'select.' => array( 00130 'orderBy' => 'sorting', 00131 'where' => 'colPos=0', 00132 'languageField' => 'sys_language_uid' 00133 ) 00134 ) 00135 ), 00136 'config.' => array( 00137 'extTarget' => '_top', 00138 'stat' => 1, 00139 'stat_typeNumList' => '0,1', 00140 'uniqueLinkVars' => 1 00141 ) 00142 ); 00143 var $flatSetup = array( 00144 ); 00145 var $const = array( // Default TypoScript Constants code: 00146 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />', 00147 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>', 00148 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>', 00149 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>', 00150 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"', 00151 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"' 00152 ); 00153 00154 00155 // For fetching TypoScript code from template hierarchy before parsing it. Each array contains code field values from template records/files: 00156 var $config = array(); // Setup field 00157 var $constants = array(); // Constant field 00158 var $editorcfg = array(); // Backend Editor Configuration field 00159 00160 var $hierarchyInfo = array(); // For Template Analyser in backend 00161 var $hierarchyInfoToRoot = array(); // For Template Analyser in backend (setup content only) 00162 var $nextLevel = 0; // Next-level flag (see runThroughTemplates()) 00163 var $rootId; // The Page UID of the root page 00164 var $rootLine; // The rootline from current page to the root page 00165 var $absoluteRootLine; // Rootline all the way to the root. Set but runThroughTemplates 00166 var $outermostRootlineIndexWithTemplate = 0; // A pointer to the last entry in the rootline where a template was found. 00167 var $rowSum; // Array of arrays with title/uid of templates in hierarchy 00168 var $resources = ''; // Resources for the template hierarchy in a comma list 00169 var $sitetitle = ''; // The current site title field. 00170 var $sections; // Tracking all conditions found during parsing of TypoScript. Used for the "all" key in currentPageData 00171 var $sectionsMatch; // Tracking all matching conditions found 00172 00173 // Backend: ts_analyzer 00174 var $clearList_const = array(); 00175 var $clearList_setup = array(); 00176 var $clearList_editorcfg = array(); 00177 var $parserErrors = array(); 00178 var $setup_constants = array(); 00179 00180 // Other: 00181 var $fileCache = array(); // Used by getFileName for caching of references to file resources 00182 var $frames = array(); // Keys are frame names and values are type-values, which must be used to refer correctly to the content of the frames. 00183 var $MPmap = ''; // Contains mapping of Page id numbers to MP variables. 00184 00185 00186 /** 00187 * Initialize 00188 * MUST be called directly after creating a new template-object 00189 * 00190 * @return void 00191 * @see tslib_fe::initTemplate() 00192 */ 00193 function init() { 00194 // $this->whereClause is used only to select templates from sys_template. 00195 // $GLOBALS['SIM_ACCESS_TIME'] is used so that we're able to simulate a later time as a test... 00196 $this->whereClause = 'AND deleted=0 '; 00197 if (!$GLOBALS['TSFE']->showHiddenRecords) { 00198 $this->whereClause .= 'AND hidden=0 '; 00199 } 00200 if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_ACCESS_TIME'] != $GLOBALS['ACCESS_TIME']) { // Set the simulation flag, if simulation is detected! 00201 $this->simulationHiddenOrTime = 1; 00202 } 00203 $this->whereClause .= 'AND (starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ') AND (endtime=0 OR endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ')'; 00204 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { 00205 $this->menuclasses = 'tmenu,jsmenu,gmenu'; 00206 } 00207 00208 // Sets the paths from where TypoScript resources are allowed to be used: 00209 $this->allowedPaths = array( 00210 'media/', 00211 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], // fileadmin/ path 00212 'uploads/', 00213 'typo3temp/', 00214 't3lib/fonts/', 00215 TYPO3_mainDir . 'ext/', 00216 TYPO3_mainDir . 'sysext/', 00217 TYPO3_mainDir . 'contrib/', 00218 'typo3conf/ext/' 00219 ); 00220 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) { 00221 $pathArr = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'], TRUE); 00222 foreach ($pathArr as $p) { 00223 // 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. 00224 $this->allowedPaths[] = $p; 00225 } 00226 } 00227 } 00228 00229 /** 00230 * Fetches the "currentPageData" array from cache 00231 * 00232 * NOTE about currentPageData: 00233 * It holds information about the TypoScript conditions along with the list 00234 * of template uid's which is used on the page. In the getFromCache function 00235 * in TSFE, currentPageData is used to evaluate if there is a template and 00236 * if the matching conditions are alright. Unfortunately this does not take 00237 * into account if the templates in the rowSum of currentPageData has 00238 * changed composition, eg. due to hidden fields or start/end time. So if a 00239 * template is hidden or times out, it'll not be discovered unless the page 00240 * is regenerated - at least the this->start function must be called, 00241 * because this will make a new portion of data in currentPageData string. 00242 * 00243 * @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 00244 * @see start(), tslib_fe::getFromCache() 00245 */ 00246 function getCurrentPageData() { 00247 $currentPageData = FALSE; 00248 if (TYPO3_UseCachingFramework) { 00249 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection'); 00250 /* @var $pageSectionCache t3lib_cache_AbstractCache */ 00251 00252 $currentPageData = $pageSectionCache->get( 00253 intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP) 00254 ); 00255 } else { 00256 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00257 'content', 'cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . t3lib_div::md5int($GLOBALS['TSFE']->MP)); 00258 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00259 $currentPageData = unserialize($row['content']); 00260 } 00261 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00262 } 00263 00264 return $currentPageData; 00265 } 00266 00267 /** 00268 * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest. 00269 * 00270 * @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array 00271 * @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. 00272 * @see t3lib_matchCondition, tslib_fe::getFromCache() 00273 */ 00274 function matching($cc) { 00275 if (is_array($cc['all'])) { 00276 /* @var $matchObj t3lib_matchCondition_frontend */ 00277 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend'); 00278 $matchObj->setRootline((array) $cc['rootLine']); 00279 foreach ($cc['all'] as $key => $pre) { 00280 if ($matchObj->match($pre)) { 00281 $sectionsMatch[$key] = $pre; 00282 } 00283 } 00284 $cc['match'] = $sectionsMatch; 00285 } 00286 return $cc; 00287 } 00288 00289 /** 00290 * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached! 00291 * 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. 00292 * Sets $this->setup to the parsed TypoScript template array 00293 * 00294 * @param array The rootline of the current page (going ALL the way to tree root) 00295 * @return void 00296 * @see tslib_fe::getConfigArray() 00297 */ 00298 function start($theRootLine) { 00299 if (is_array($theRootLine)) { 00300 $setupData = ''; 00301 $hash = ''; 00302 00303 // Flag that indicates that the existing data in cache_pagesection 00304 // could be used (this is the case if $TSFE->all is set, and the 00305 // rowSum still matches). Based on this we decide if cache_pagesection 00306 // needs to be updated... 00307 $isCached = FALSE; 00308 00309 $this->runThroughTemplates($theRootLine); 00310 00311 if ($GLOBALS['TSFE']->all) { 00312 $cc = $GLOBALS['TSFE']->all; 00313 00314 // The two rowSums must NOT be different from each other - which they will be if start/endtime or hidden has changed! 00315 if (strcmp(serialize($this->rowSum), serialize($cc['rowSum']))) { 00316 unset($cc); // If the two rowSums differ, we need to re-make the current page data and therefore clear the existing values. 00317 } else { 00318 // If $TSFE->all contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already) 00319 if (!strcmp(serialize($this->rootLine), serialize($cc['rootLine']))) { 00320 $isCached = TRUE; 00321 } 00322 // 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)... 00323 unset($cc['rootLine']); 00324 } 00325 } 00326 00327 // This is about getting the hash string which is used to fetch the cached TypoScript template. 00328 // If there was some cached currentPageData ($cc) then that's good (it gives us the hash). 00329 if (is_array($cc)) { 00330 // If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...) 00331 if (!$cc['match']) { 00332 // TODO: check if this can ever be the case - otherwise remove 00333 $cc = $this->matching($cc); 00334 ksort($cc); 00335 } 00336 $hash = md5(serialize($cc)); 00337 } else { 00338 // 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. 00339 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum)); 00340 $result = t3lib_pageSelect::getHash($rowSumHash); 00341 00342 if ($result) { 00343 $cc = array(); 00344 $cc['all'] = unserialize($result); 00345 $cc['rowSum'] = $this->rowSum; 00346 $cc = $this->matching($cc); 00347 ksort($cc); 00348 $hash = md5(serialize($cc)); 00349 } 00350 } 00351 00352 if ($hash) { 00353 // Get TypoScript setup array 00354 $setupData = t3lib_pageSelect::getHash($hash); 00355 } 00356 00357 if ($setupData && !$this->forceTemplateParsing) { 00358 // If TypoScript setup structure was cached we unserialize it here: 00359 $this->setup = unserialize($setupData); 00360 } else { 00361 // Make configuration 00362 $this->generateConfig(); 00363 00364 // This stores the template hash thing 00365 $cc = array(); 00366 $cc['all'] = $this->sections; // All sections in the template at this point is found 00367 $cc['rowSum'] = $this->rowSum; // The line of templates is collected 00368 $cc = $this->matching($cc); 00369 ksort($cc); 00370 00371 $hash = md5(serialize($cc)); 00372 00373 // This stores the data. 00374 t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS_TEMPLATE'); 00375 00376 if ($this->tt_track) { 00377 $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: ' . strlen(serialize($this->setup)) . ' bytes'); 00378 } 00379 00380 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum)); 00381 t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL_CONDITIONS_ALL'); 00382 } 00383 // Add rootLine 00384 $cc['rootLine'] = $this->rootLine; 00385 ksort($cc); 00386 00387 // Make global and save 00388 $GLOBALS['TSFE']->all = $cc; 00389 00390 // Matching must be executed for every request, so this must never be part of the pagesection cache! 00391 unset($cc['match']); 00392 00393 if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) { // Only save the data if we're not simulating by hidden/starttime/endtime 00394 $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP); 00395 if (TYPO3_UseCachingFramework) { 00396 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection'); 00397 /* @var $pageSectionCache t3lib_cache_AbstractCache */ 00398 $pageSectionCache->set( 00399 intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash, 00400 $cc, 00401 array( 00402 'pageId_' . intval($GLOBALS['TSFE']->id), 00403 'mpvarHash_' . $mpvarHash 00404 ) 00405 ); 00406 } else { 00407 $dbFields = array( 00408 'content' => serialize($cc), 00409 'tstamp' => $GLOBALS['EXEC_TIME'] 00410 ); 00411 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvarHash, $dbFields); 00412 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) { 00413 $dbFields['page_id'] = intval($GLOBALS['TSFE']->id); 00414 $dbFields['mpvar_hash'] = $mpvarHash; 00415 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields); 00416 } 00417 } 00418 } 00419 // If everything OK. 00420 if ($this->rootId && $this->rootLine && $this->setup) { 00421 $this->loaded = 1; 00422 } 00423 } 00424 } 00425 00426 00427 /******************************************************************* 00428 * 00429 * Fetching TypoScript code text for the Template Hierarchy 00430 * 00431 *******************************************************************/ 00432 00433 /** 00434 * Traverses the rootLine from the root and out. For each page it checks if there is a template record. If there is a template record, $this->processTemplate() is called. 00435 * Resets and affects internal variables like $this->constants, $this->config, $this->editorcfg and $this->rowSum 00436 * Also creates $this->rootLine which is a root line stopping at the root template (contrary to $GLOBALS['TSFE']->rootLine which goes all the way to the root of the tree 00437 * 00438 * @param array The rootline of the current page (going ALL the way to tree root) 00439 * @param integer Set specific template record UID to select; this is only for debugging/development/analysis use in backend modules like "Web > Template". For parsing TypoScript templates in the frontend it should be 0 (zero) 00440 * @return void 00441 * @see start() 00442 */ 00443 function runThroughTemplates($theRootLine, $start_template_uid = 0) { 00444 $this->constants = array(); 00445 $this->config = array(); 00446 $this->editorcfg = array(); 00447 $this->rowSum = array(); 00448 $this->hierarchyInfoToRoot = array(); 00449 $this->absoluteRootLine = $theRootLine; // Is the TOTAL rootline 00450 00451 reset($this->absoluteRootLine); 00452 $c = count($this->absoluteRootLine); 00453 for ($a = 0; $a < $c; $a++) { 00454 if ($this->nextLevel) { // If some template loaded before has set a template-id for the next level, then load this template first! 00455 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . intval($this->nextLevel) . ' ' . $this->whereClause); 00456 $this->nextLevel = 0; 00457 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00458 $this->versionOL($row); 00459 if (is_array($row)) { 00460 $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']); 00461 $this->outermostRootlineIndexWithTemplate = $a; 00462 } 00463 } 00464 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00465 } 00466 $addC = ''; 00467 if ($a == ($c - 1) && $start_template_uid) { // If first loop AND there is set an alternative template uid, use that 00468 $addC = ' AND uid=' . intval($start_template_uid); 00469 } 00470 00471 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($this->absoluteRootLine[$a]['uid']) . $addC . ' ' . $this->whereClause, '', 'sorting', 1); 00472 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00473 $this->versionOL($row); 00474 if (is_array($row)) { 00475 $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']); 00476 $this->outermostRootlineIndexWithTemplate = $a; 00477 } 00478 } 00479 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00480 $this->rootLine[] = $this->absoluteRootLine[$a]; 00481 } 00482 $this->processIncludes(); 00483 } 00484 00485 /** 00486 * Checks if the template ($row) has some included templates and after including them it fills the arrays with the setup 00487 * Builds up $this->rowSum 00488 * 00489 * @param array A full TypoScript template record (sys_template/static_template/forged "dummy" record made from static template file) 00490 * @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. 00491 * @param array The PID of the input template record 00492 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123" 00493 * @param string Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123" 00494 * @return void 00495 * @see runThroughTemplates() 00496 */ 00497 function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '') { 00498 // Adding basic template record information to rowSum array 00499 $this->rowSum[] = array($row['uid'], $row['title'], $row['tstamp']); 00500 00501 // Processing "Clear"-flags 00502 if ($row['clear']) { 00503 $clConst = $row['clear'] & 1; 00504 $clConf = $row['clear'] & 2; 00505 if ($clConst) { 00506 $this->constants = array(); 00507 $this->clearList_const = array(); 00508 } 00509 if ($clConf) { 00510 $this->config = array(); 00511 $this->hierarchyInfoToRoot = array(); 00512 $this->clearList_setup = array(); 00513 00514 $this->editorcfg = array(); 00515 $this->clearList_editorcfg = array(); 00516 } 00517 } 00518 00519 // Include static records (static_template) or files (from extensions) (#1/2) 00520 // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!! 00521 if (!$row['includeStaticAfterBasedOn']) { 00522 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row); 00523 } 00524 00525 // Include "Based On" sys_templates: 00526 if (trim($row['basedOn'])) { // 'basedOn' is a list of templates to include 00527 // Manually you can put this value in the field and then the based_on ID will be taken from the $_GET var defined by '=....'. 00528 // Example: If $row['basedOn'] is 'EXTERNAL_BASED_ON_TEMPLATE_ID=based_on_uid', then the global var, based_on_uid - given by the URL like '&based_on_uid=999' - is included instead! 00529 // This feature allows us a hack to test/demonstrate various included templates on the same set of content bearing pages. Used by the "freesite" extension. 00530 $basedOn_hackFeature = explode('=', $row['basedOn']); 00531 if ($basedOn_hackFeature[0] == 'EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) { 00532 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1])); 00533 if ($id && !t3lib_div::inList($idList, 'sys_' . $id)) { // if $id is not allready included ... 00534 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . $id . ' ' . $this->whereClause); 00535 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // there was a template, then we fetch that 00536 $this->versionOL($subrow); 00537 if (is_array($subrow)) { 00538 $this->processTemplate($subrow, $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID); 00539 } 00540 } 00541 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00542 } 00543 } else { 00544 // Normal Operation, which is to include the "based-on" sys_templates, 00545 // if they are not already included, and maintaining the sorting of the templates 00546 $basedOnIds = t3lib_div::intExplode(',', $row['basedOn']); 00547 00548 // skip template if it's already included 00549 foreach ($basedOnIds as $key => $basedOnId) { 00550 if (t3lib_div::inList($idList, 'sys_' . $basedOnId)) { 00551 unset($basedOnIds[$key]); 00552 } 00553 } 00554 00555 $subTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00556 '*', 'sys_template', 00557 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause, 00558 '', '', '', 00559 'uid' // the associative array that is returned will contain this field as key 00560 ); 00561 00562 // traversing list again to ensure the sorting of the templates 00563 foreach ($basedOnIds as $id) { 00564 if (is_array($subTemplates[$id])) { 00565 $this->versionOL($subTemplates[$id]); 00566 $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID); 00567 } 00568 } 00569 } 00570 } 00571 00572 // Include static records (static_template) or files (from extensions) (#2/2) 00573 if ($row['includeStaticAfterBasedOn']) { 00574 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row); 00575 } 00576 00577 // Creating hierarchy information; Used by backend analysis tools 00578 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array( 00579 'root' => trim($row['root']), 00580 'next' => $row['nextLevel'], 00581 'clConst' => $clConst, 00582 'clConf' => $clConf, 00583 'templateID' => $templateID, 00584 'templateParent' => $templateParent, 00585 'title' => $row['title'], 00586 'uid' => $row['uid'], 00587 'pid' => $row['pid'], 00588 'configLines' => substr_count($row['config'], LF) + 1 00589 ); 00590 00591 // Adding the content of the fields constants (Constants), config (Setup) and editorcfg (Backend Editor Configuration) to the internal arrays. 00592 $this->constants[] = $row['constants']; 00593 $this->config[] = $row['config']; 00594 if ($this->parseEditorCfgField) { 00595 $this->editorcfg[] = $row['editorcfg']; 00596 } 00597 00598 // For backend analysis (Template Analyser) provide the order of added constants/config/editorcfg template IDs 00599 $this->clearList_const[] = $templateID; 00600 $this->clearList_setup[] = $templateID; 00601 if ($this->parseEditorCfgField) { 00602 $this->clearList_editorcfg[] = $templateID; 00603 } 00604 00605 // Add resources and sitetitle if found: 00606 if (trim($row['resources'])) { 00607 $this->resources = $row['resources'] . ',' . $this->resources; 00608 } 00609 if (trim($row['sitetitle'])) { 00610 $this->sitetitle = $row['sitetitle']; 00611 } 00612 // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point) 00613 if (trim($row['root'])) { 00614 $this->rootId = $pid; 00615 $this->rootLine = array(); 00616 } 00617 // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates()) 00618 if ($row['nextLevel']) { 00619 $this->nextLevel = $row['nextLevel']; 00620 } else { 00621 $this->nextLevel = 0; 00622 } 00623 } 00624 00625 /** 00626 * Includes static template records (from static_template table, loaded through a hook) and static template files (from extensions) for the input template record row. 00627 * 00628 * @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. 00629 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123" 00630 * @param array The PID of the input template record 00631 * @param array A full TypoScript template record 00632 * @return void 00633 * @see processTemplate() 00634 */ 00635 function includeStaticTypoScriptSources($idList, $templateID, $pid, $row) { 00636 // Static Template Records (static_template): include_static is a list of static templates to include 00637 // Call function for link rendering: 00638 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'])) { 00639 $_params = array( 00640 'idList' => &$idList, 00641 'templateId' => &$templateID, 00642 'pid' => &$pid, 00643 'row' => &$row 00644 ); 00645 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] as $_funcRef) { 00646 t3lib_div::callUserFunction($_funcRef, $_params, $this); 00647 } 00648 } 00649 00650 // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions) 00651 if (trim($row['include_static_file'])) { 00652 $include_static_fileArr = t3lib_div::trimExplode(',', $row['include_static_file'], TRUE); 00653 foreach ($include_static_fileArr as $ISF_file) { // traversing list 00654 if (substr($ISF_file, 0, 4) == 'EXT:') { 00655 list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2); 00656 if (strcmp($ISF_extKey, '') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath, '')) { 00657 $ISF_localPath = rtrim($ISF_localPath, '/') . '/'; 00658 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey) . $ISF_localPath; 00659 if (@is_dir($ISF_filePath)) { 00660 $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath); 00661 $subrow = array( 00662 'constants' => @is_file($ISF_filePath . 'constants.txt') ? t3lib_div::getUrl($ISF_filePath . 'constants.txt') : '', 00663 'config' => @is_file($ISF_filePath . 'setup.txt') ? t3lib_div::getUrl($ISF_filePath . 'setup.txt') : '', 00664 'editorcfg' => @is_file($ISF_filePath . 'editorcfg.txt') ? t3lib_div::getUrl($ISF_filePath . 'editorcfg.txt') : '', 00665 'include_static' => @is_file($ISF_filePath . 'include_static.txt') ? implode(',', array_unique(t3lib_div::intExplode(',', t3lib_div::getUrl($ISF_filePath . 'include_static.txt')))) : '', 00666 'include_static_file' => @is_file($ISF_filePath . 'include_static_file.txt') ? implode(',', array_unique(explode(',', t3lib_div::getUrl($ISF_filePath . 'include_static_file.txt')))) : '', 00667 'title' => $ISF_file, 00668 'uid' => $mExtKey 00669 ); 00670 $subrow = $this->prependStaticExtra($subrow); 00671 00672 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID); 00673 } 00674 } 00675 } 00676 } 00677 } 00678 00679 $this->addExtensionStatics($idList, $templateID, $pid, $row); 00680 00681 // Include Static Template Records after all other TypoScript has been included. 00682 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'])) { 00683 $_params = array( 00684 'idList' => &$idList, 00685 'templateId' => &$templateID, 00686 'pid' => &$pid, 00687 'row' => &$row 00688 ); 00689 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] as $_funcRef) { 00690 t3lib_div::callUserFunction($_funcRef, $_params, $this); 00691 } 00692 } 00693 } 00694 00695 /** 00696 * Adds the default TypoScript files for extensions if any. 00697 * 00698 * @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. 00699 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123" 00700 * @param array The PID of the input template record 00701 * @param array A full TypoScript template record 00702 * @return void 00703 * @access private 00704 * @see includeStaticTypoScriptSources() 00705 */ 00706 function addExtensionStatics($idList, $templateID, $pid, $row) { 00707 global $TYPO3_LOADED_EXT; 00708 00709 if ($row['static_file_mode'] == 1 || ($row['static_file_mode'] == 0 && substr($templateID, 0, 4) == 'sys_' && $row['root'])) { 00710 foreach ($TYPO3_LOADED_EXT as $extKey => $files) { 00711 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) { 00712 $mExtKey = str_replace('_', '', $extKey); 00713 $subrow = array( 00714 'constants' => $files['ext_typoscript_constants.txt'] ? t3lib_div::getUrl($files['ext_typoscript_constants.txt']) : '', 00715 'config' => $files['ext_typoscript_setup.txt'] ? t3lib_div::getUrl($files['ext_typoscript_setup.txt']) : '', 00716 'editorcfg' => $files['ext_typoscript_editorcfg.txt'] ? t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']) : '', 00717 'title' => $extKey, 00718 'uid' => $mExtKey 00719 ); 00720 $subrow = $this->prependStaticExtra($subrow); 00721 00722 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID); 00723 } 00724 } 00725 } 00726 } 00727 00728 /** 00729 * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS 00730 * For records the "uid" value is the integer of the "static_template" record 00731 * For files the "uid" value is the extension key but with any underscores removed. Possibly with a path if its a static file selected in the template record 00732 * 00733 * @param array Static template record/file 00734 * @return array Returns the input array where the values for keys "config", "constants" and "editorcfg" may have been modified with prepended code. 00735 * @access private 00736 * @see addExtensionStatics(), includeStaticTypoScriptSources() 00737 */ 00738 function prependStaticExtra($subrow) { 00739 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']]; 00740 $subrow['editorcfg'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']]; 00741 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']]; 00742 return $subrow; 00743 } 00744 00745 /** 00746 * Creating versioning overlay of a sys_template record. This will use either frontend or backend overlay functionality depending on environment. 00747 * 00748 * @param array Row to overlay. 00749 * @return void Row is passed by reference. 00750 */ 00751 function versionOL(&$row) { 00752 if (is_object($GLOBALS['TSFE'])) { // Frontend: 00753 $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row); 00754 } else { // Backend: 00755 t3lib_BEfunc::workspaceOL('sys_template', $row); 00756 } 00757 } 00758 00759 00760 /******************************************************************* 00761 * 00762 * Parsing TypoScript code text from Template Records into PHP array 00763 * 00764 *******************************************************************/ 00765 00766 /** 00767 * Generates the configuration array by replacing constants and parsing the whole thing. 00768 * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates) 00769 * 00770 * @return void 00771 * @see t3lib_TSparser, start() 00772 */ 00773 function generateConfig() { 00774 // Add default TS for all three code types: 00775 array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']); // Adding default TS/constants 00776 array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']); // Adding default TS/setup 00777 array_unshift($this->editorcfg, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']); // Adding default TS/editorcfg 00778 00779 // Parse the TypoScript code text for include-instructions! 00780 $this->processIncludes(); 00781 00782 // These vars are also set lateron... 00783 $this->setup['resources'] = $this->resources; 00784 $this->setup['sitetitle'] = $this->sitetitle; 00785 00786 00787 // **************************** 00788 // Parse TypoScript Constants 00789 // **************************** 00790 00791 // Initialize parser and match-condition classes: 00792 $constants = t3lib_div::makeInstance('t3lib_TSparser'); 00793 $constants->breakPointLN = intval($this->ext_constants_BRP); 00794 $constants->setup = $this->const; 00795 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup); 00796 00797 /* @var $matchObj t3lib_matchCondition_frontend */ 00798 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend'); 00799 $matchObj->setSimulateMatchConditions($this->matchAlternative); 00800 $matchObj->setSimulateMatchResult((bool) $this->matchAll); 00801 00802 // Traverse constants text fields and parse them 00803 foreach ($this->constants as $str) { 00804 $constants->parse($str, $matchObj); 00805 } 00806 00807 // Read out parse errors if any 00808 $this->parserErrors['constants'] = $constants->errors; 00809 00810 // Then flatten the structure from a multi-dim array to a single dim array with all constants listed as key/value pairs (ready for substitution) 00811 $this->flatSetup = array(); 00812 $this->flattenSetup($constants->setup, '', ''); 00813 00814 00815 // *********************************************** 00816 // Parse TypoScript Setup (here called "config") 00817 // *********************************************** 00818 // Initialize parser and match-condition classes: 00819 $config = t3lib_div::makeInstance('t3lib_TSparser'); 00820 $config->breakPointLN = intval($this->ext_config_BRP); 00821 $config->regLinenumbers = $this->ext_regLinenumbers; 00822 $config->regComments = $this->ext_regComments; 00823 $config->setup = $this->setup; 00824 00825 // Transfer information about conditions found in "Constants" and which of them returned true. 00826 $config->sections = $constants->sections; 00827 $config->sectionsMatch = $constants->sectionsMatch; 00828 00829 // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition 00830 $all = ''; 00831 foreach ($this->config as $str) { 00832 $all .= "\n[GLOBAL]\n" . $str; 00833 } 00834 00835 // Substitute constants in the Setup code: 00836 if ($this->tt_track) { 00837 $GLOBALS['TT']->push('Substitute Constants (' . count($this->flatSetup) . ')'); 00838 } 00839 $all = $this->substituteConstants($all); 00840 if ($this->tt_track) { 00841 $GLOBALS['TT']->pull(); 00842 } 00843 00844 // Searching for possible unsubstituted constants left (only for information) 00845 if (strstr($all, '{$')) { 00846 $theConstList = array(); 00847 $findConst = explode('{$', $all); 00848 array_shift($findConst); 00849 foreach ($findConst as $constVal) { 00850 $constLen = t3lib_div::intInRange(strcspn($constVal, '}'), 0, 50); 00851 $theConstList[] = '{$' . substr($constVal, 0, $constLen + 1); 00852 } 00853 if ($this->tt_track) { 00854 $GLOBALS['TT']->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2); 00855 } 00856 } 00857 00858 // Logging the textual size of the TypoScript Setup field text with all constants substituted: 00859 if ($this->tt_track) { 00860 $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes'); 00861 } 00862 00863 // Finally parse the Setup field TypoScript code (where constants are now substituted) 00864 $config->parse($all, $matchObj); 00865 00866 // Read out parse errors if any 00867 $this->parserErrors['config'] = $config->errors; 00868 00869 // Transfer the TypoScript array from the parser object to the internal $this->setup array: 00870 $this->setup = $config->setup; 00871 if ($this->backend_info) { 00872 $this->setup_constants = $constants->setup; // Used for backend purposes only 00873 } 00874 00875 00876 // ************************************************** 00877 // Parse Backend Editor Configuration (backend only) 00878 // ************************************************** 00879 if ($this->parseEditorCfgField) { 00880 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser'); 00881 $editorcfg->breakPointLN = intval($this->ext_editorcfg_BRP); 00882 $editorcfg->setup = array(); // Empty as a start... 00883 00884 $all = implode("\n[GLOBAL]\n", $this->editorcfg); 00885 00886 // substitute constants in config 00887 $all = $this->substituteConstants($all); 00888 00889 // parse Config 00890 $matchObj->matchAll = 1; // This should make sure that conditions are disabled. For now they are NOT active for the backend. 00891 $editorcfg->parse($all, $matchObj); 00892 $this->parserErrors['editorcfg'] = $editorcfg->errors; 00893 $this->setup_editorcfg = $editorcfg->setup; 00894 } 00895 00896 00897 // **************************************************************** 00898 // Final processing of the $this->setup TypoScript Template array 00899 // Basically: This is unsetting/setting of certain reserved keys. 00900 // **************************************************************** 00901 00902 // These vars are allready set after 'processTemplate', but because $config->setup overrides them (in the line above!), we set them again. They are not changed compared to the value they had in the top of the page! 00903 unset($this->setup['resources']); 00904 unset($this->setup['resources.']); 00905 $this->setup['resources'] = implode(',', t3lib_div::trimExplode(',', $this->resources, 1)); 00906 00907 unset($this->setup['sitetitle']); 00908 unset($this->setup['sitetitle.']); 00909 $this->setup['sitetitle'] = $this->sitetitle; 00910 00911 // Unsetting some vars... 00912 unset($this->setup['types.']); 00913 unset($this->setup['types']); 00914 if (is_array($this->setup)) { 00915 foreach ($this->setup as $key => $value) { 00916 if ($value == 'PAGE') { 00917 // Set the typeNum of the current page object: 00918 if (isset($this->setup[$key . '.']['typeNum'])) { 00919 $typeNum = $this->setup[$key . '.']['typeNum']; 00920 $this->setup['types.'][$typeNum] = $key; 00921 // If there is no type 0 yet and typeNum was not set, we use the current object as the default 00922 } elseif (!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) { 00923 $this->setup['types.'][0] = $key; 00924 } 00925 } 00926 } 00927 } 00928 unset($this->setup['styles.']); 00929 unset($this->setup['temp.']); 00930 unset($constants); 00931 00932 // Storing the conditions found/matched information: 00933 $this->sections = $config->sections; 00934 $this->sectionsMatch = $config->sectionsMatch; 00935 } 00936 00937 /** 00938 * Searching TypoScript code text (for constants, config (Setup) and editorcfg) 00939 * for include instructions and does the inclusion of external TypoScript files 00940 * if needed. 00941 * 00942 * @return void 00943 * @see t3lib_TSparser, generateConfig() 00944 */ 00945 public function processIncludes() { 00946 $files = array(); 00947 foreach ($this->constants as &$value) { 00948 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE); 00949 $files = array_merge($files, $includeData['files']); 00950 $value = $includeData['typoscript']; 00951 } 00952 00953 foreach ($this->config as &$value) { 00954 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE); 00955 $files = array_merge($files, $includeData['files']); 00956 $value = $includeData['typoscript']; 00957 } 00958 00959 foreach ($this->editorcfg as &$value) { 00960 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE); 00961 $files = array_merge($files, $includeData['files']); 00962 $value = $includeData['typoscript']; 00963 } 00964 if (count($files)) { 00965 $files = array_unique($files); 00966 foreach ($files as $file) { 00967 $this->rowSum[] = array($file, filemtime($file)); 00968 } 00969 } 00970 } 00971 00972 /** 00973 * Loads Page TSconfig until the outermost template record and parses the configuration - if TSFE.constants object path is found it is merged with the default data in here! 00974 * 00975 * @param array Constants array, default input. 00976 * @return array Constants array, modified 00977 * @todo Apply caching to the parsed Page TSconfig. This is done in the other similar functions for both frontend and backend. However, since this functions works for BOTH frontend and backend we will have to either write our own local caching function or (more likely) detect if we are in FE or BE and use caching functions accordingly. Not having caching affects mostly the backend modules inside the "Template" module since the overhead in the frontend is only seen when TypoScript templates are parsed anyways (after which point they are cached anyways...) 00978 */ 00979 function mergeConstantsFromPageTSconfig($constArray) { 00980 $TSdataArray = array(); 00981 $TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration: 00982 00983 for ($a = 0; $a <= $this->outermostRootlineIndexWithTemplate; $a++) { 00984 $TSdataArray[] = $this->absoluteRootLine[$a]['TSconfig']; 00985 } 00986 // Parsing the user TS (or getting from cache) 00987 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray); 00988 $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray); 00989 00990 $parseObj = t3lib_div::makeInstance('t3lib_TSparser'); 00991 $parseObj->parse($userTS); 00992 00993 if (is_array($parseObj->setup['TSFE.']['constants.'])) { 00994 $constArray = t3lib_div::array_merge_recursive_overrule($constArray, $parseObj->setup['TSFE.']['constants.']); 00995 } 00996 return $constArray; 00997 } 00998 00999 /** 01000 * This flattens a hierarchical TypoScript array to $this->flatSetup 01001 * 01002 * @param array TypoScript array 01003 * @param string Prefix to the object path. Used for recursive calls to this function. 01004 * @param boolean If set, then the constant value will be resolved as a TypoScript "resource" data type. Also used internally during recursive calls so that all subproperties for properties named "file." will be resolved as resources. 01005 * @return void 01006 * @see generateConfig() 01007 */ 01008 function flattenSetup($setupArray, $prefix, $resourceFlag) { 01009 if (is_array($setupArray)) { 01010 foreach ($setupArray as $key => $val) { 01011 if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201) 01012 if (is_array($val)) { 01013 $this->flattenSetup($val, $prefix . $key, ($key == 'file.')); 01014 } elseif ($resourceFlag) { 01015 $this->flatSetup[$prefix . $key] = $this->getFileName($val); 01016 } else { 01017 $this->flatSetup[$prefix . $key] = $val; 01018 } 01019 } 01020 } 01021 } 01022 } 01023 01024 /** 01025 * Substitutes the constants from $this->flatSetup in the text string $all 01026 * 01027 * @param string TypoScript code text string 01028 * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted. 01029 * @see generateConfig(), flattenSetup() 01030 */ 01031 function substituteConstants($all) { 01032 if ($this->tt_track) { 01033 $GLOBALS['TT']->setTSlogMessage('Constants to substitute: ' . count($this->flatSetup)); 01034 } 01035 01036 $noChange = FALSE; 01037 // recursive substitution of constants (up to 10 nested levels) 01038 for ($i = 0; $i < 10 && !$noChange; $i++) { 01039 $old_all = $all; 01040 $all = preg_replace_callback('/\{\$(.[^}]*)\}/', array($this, 'substituteConstantsCallBack'), $all); 01041 if ($old_all == $all) { 01042 $noChange = TRUE; 01043 } 01044 } 01045 01046 return $all; 01047 } 01048 01049 /** 01050 * Call back method for preg_replace_callback in substituteConstants 01051 * 01052 * @param array Regular expression matches 01053 * @return string Replacement 01054 * @see substituteConstants() 01055 */ 01056 function substituteConstantsCallBack($matches) { 01057 // replace {$CONST} if found in $this->flatSetup, else leave unchanged 01058 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0]; 01059 } 01060 01061 01062 /******************************************************************* 01063 * 01064 * Various API functions, used from elsewhere in the frontend classes 01065 * 01066 *******************************************************************/ 01067 01068 /** 01069 * Implementation of the "optionSplit" feature in TypoScript (used eg. for MENU objects) 01070 * What it does is to split the incoming TypoScript array so that the values are exploded by certain strings ("||" and "|*|") and each part distributed into individual TypoScript arrays with a similar structure, but individualized values. 01071 * The concept is known as "optionSplit" and is rather advanced to handle but quite powerful, in particular for creating menus in TYPO3. 01072 * 01073 * @param array A TypoScript array 01074 * @param integer The number of items for which to generated individual TypoScript arrays 01075 * @return array The individualized TypoScript array. 01076 * @see tslib_cObj::IMGTEXT(), tslib_menu::procesItemStates() 01077 */ 01078 function splitConfArray($conf, $splitCount) { 01079 01080 // Initialize variables: 01081 $splitCount = intval($splitCount); 01082 $conf2 = array(); 01083 01084 if ($splitCount && is_array($conf)) { 01085 01086 // Initialize output to carry at least the keys: 01087 for ($aKey = 0; $aKey < $splitCount; $aKey++) { 01088 $conf2[$aKey] = array(); 01089 } 01090 01091 // Recursive processing of array keys: 01092 foreach ($conf as $cKey => $val) { 01093 if (is_array($val)) { 01094 $tempConf = $this->splitConfArray($val, $splitCount); 01095 foreach ($tempConf as $aKey => $val) { 01096 $conf2[$aKey][$cKey] = $val; 01097 } 01098 } else { 01099 // Splitting of all values on this level of the TypoScript object tree: 01100 if (!strstr($val, '|*|') && !strstr($val, '||')) { 01101 for ($aKey = 0; $aKey < $splitCount; $aKey++) { 01102 $conf2[$aKey][$cKey] = $val; 01103 } 01104 } else { 01105 $main = explode('|*|', $val); 01106 $mainCount = count($main); 01107 01108 $lastC = 0; 01109 $middleC = 0; 01110 $firstC = 0; 01111 01112 if ($main[0]) { 01113 $first = explode('||', $main[0]); 01114 $firstC = count($first); 01115 } 01116 if ($main[1]) { 01117 $middle = explode('||', $main[1]); 01118 $middleC = count($middle); 01119 } 01120 if ($main[2]) { 01121 $last = explode('||', $main[2]); 01122 $lastC = count($last); 01123 $value = $last[0]; 01124 } 01125 01126 for ($aKey = 0; $aKey < $splitCount; $aKey++) { 01127 if ($firstC && isset($first[$aKey])) { 01128 $value = $first[$aKey]; 01129 } elseif ($middleC) { 01130 $value = $middle[($aKey - $firstC) % $middleC]; 01131 } 01132 if ($lastC && $lastC >= ($splitCount - $aKey)) { 01133 $value = $last[$lastC - ($splitCount - $aKey)]; 01134 } 01135 $conf2[$aKey][$cKey] = trim($value); 01136 } 01137 } 01138 } 01139 } 01140 } 01141 return $conf2; 01142 } 01143 01144 /** 01145 * Returns the reference to a 'resource' in TypoScript. 01146 * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list 01147 * 01148 * @param string TypoScript "resource" data type value. 01149 * @return string Resulting filename, if any. 01150 */ 01151 function getFileName($fileFromSetup) { 01152 $file = trim($fileFromSetup); 01153 if (!$file) { 01154 return; 01155 } elseif (strstr($file, '../')) { 01156 if ($this->tt_track) { 01157 $GLOBALS['TT']->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3); 01158 } 01159 return; 01160 } 01161 // cache 01162 $hash = md5($file); 01163 if (isset($this->fileCache[$hash])) { 01164 return $this->fileCache[$hash]; 01165 } 01166 01167 if (!strcmp(substr($file, 0, 4), 'EXT:')) { 01168 $newFile = ''; 01169 list($extKey, $script) = explode('/', substr($file, 4), 2); 01170 if ($extKey && t3lib_extMgm::isLoaded($extKey)) { 01171 $extPath = t3lib_extMgm::extPath($extKey); 01172 $newFile = substr($extPath, strlen(PATH_site)) . $script; 01173 } 01174 if (!@is_file(PATH_site . $newFile)) { 01175 if ($this->tt_track) { 01176 $GLOBALS['TT']->setTSlogMessage('Extension media file "' . $newFile . '" was not found!', 3); 01177 } 01178 return; 01179 } else { 01180 $file = $newFile; 01181 } 01182 } 01183 01184 // find 01185 if (strpos($file, '/') !== FALSE) { 01186 // if the file is in the media/ folder but it doesn't exist, 01187 // it is assumed that it's in the tslib folder 01188 if (t3lib_div::isFirstPartOfStr($file, 'media/') && !is_file($this->getFileName_backPath . $file)) { 01189 $file = t3lib_extMgm::siteRelPath('cms') . 'tslib/' . $file; 01190 } 01191 if (is_file($this->getFileName_backPath . $file)) { 01192 $outFile = $file; 01193 $fileInfo = t3lib_div::split_fileref($outFile); 01194 $OK = 0; 01195 foreach ($this->allowedPaths as $val) { 01196 if (substr($fileInfo['path'], 0, strlen($val)) == $val) { 01197 $OK = 1; 01198 break; 01199 } 01200 } 01201 if ($OK) { 01202 $this->fileCache[$hash] = $outFile; 01203 return $outFile; 01204 } elseif ($this->tt_track) { 01205 $GLOBALS['TT']->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3); 01206 } 01207 } elseif ($this->tt_track) { 01208 $GLOBALS['TT']->setTSlogMessage('"' . $this->getFileName_backPath . $file . '" is not a file (non-uploads/.. resource, did not exist).', 3); 01209 } 01210 } else { // Here it is uploaded media: 01211 $outFile = $this->extractFromResources($this->setup['resources'], $file); 01212 if ($outFile) { 01213 if (@is_file($this->uplPath . $outFile)) { 01214 $this->fileCache[$hash] = $this->uplPath . $outFile; 01215 return $this->uplPath . $outFile; 01216 } elseif ($this->tt_track) { 01217 $GLOBALS['TT']->setTSlogMessage('"' . $this->uplPath . $outFile . '" is not a file (did not exist).', 3); 01218 } 01219 } elseif ($this->tt_track) { 01220 $GLOBALS['TT']->setTSlogMessage('"' . $file . '" is not a file (uploads/.. resource).', 3); 01221 } 01222 } 01223 } 01224 01225 /** 01226 * Searches for the TypoScript resource filename in the list of resource filenames. 01227 * 01228 * @param string The resource file name list (from $this->setup['resources']) 01229 * @param string The resource value to match 01230 * @return string If found, this will be the resource filename that matched. Typically this file is found in "uploads/tf/" 01231 * @access private 01232 * @see getFileName() 01233 */ 01234 function extractFromResources($res, $file) { 01235 if (t3lib_div::inList($res, $file)) { 01236 $outFile = $file; 01237 } elseif (strstr($file, '*')) { 01238 $fileparts = explode('*', $file); 01239 $c = count($fileparts); 01240 $files = t3lib_div::trimExplode(',', $res); 01241 foreach ($files as $file) { 01242 if (preg_match('/^' . quotemeta($fileparts[0]) . '.*' . quotemeta($fileparts[$c - 1]) . '$/', $file)) { 01243 $outFile = $file; 01244 break; 01245 } 01246 } 01247 } 01248 return $outFile; 01249 } 01250 01251 /** 01252 * Compiles the content for the page <title> tag. 01253 * 01254 * @param string The input title string, typically the "title" field of a page's record. 01255 * @param boolean If set, then only the site title is outputted (from $this->setup['sitetitle']) 01256 * @param boolean If set, then "sitetitle" and $title is swapped 01257 * @return string The page title on the form "[sitetitle]: [input-title]". Not htmlspecialchar()'ed. 01258 * @see tslib_fe::tempPageCacheContent(), TSpagegen::renderContentWithHeader() 01259 */ 01260 function printTitle($title, $no_title = 0, $titleFirst = 0) { 01261 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle'] : ''; 01262 $title = $no_title ? '' : $title; 01263 if ($titleFirst) { 01264 $temp = $st; 01265 $st = $title; 01266 $title = $temp; 01267 } 01268 if ($title && $st) { 01269 return $st . ': ' . $title; 01270 } else { 01271 return $st . $title; 01272 } 01273 } 01274 01275 /** 01276 * Reads the fileContent of $fName and returns it. 01277 * Similar to t3lib_div::getUrl() 01278 * 01279 * @param string Absolute filepath to record 01280 * @return string The content returned 01281 * @see tslib_cObj::fileResource(), tslib_cObj::MULTIMEDIA(), t3lib_div::getUrl() 01282 */ 01283 function fileContent($fName) { 01284 $incFile = $this->getFileName($fName); 01285 if ($incFile) { 01286 return @file_get_contents($incFile); 01287 } 01288 } 01289 01290 /** 01291 * Ordinary "wrapping" function. Used in the tslib_menu class and extension classes instead of the similar function in tslib_cObj 01292 * 01293 * @param string The content to wrap 01294 * @param string The wrap value, eg. "<strong> | </strong>" 01295 * @return string Wrapped input string 01296 * @see tslib_menu, tslib_cObj::wrap() 01297 */ 01298 function wrap($content, $wrap) { 01299 if ($wrap) { 01300 $wrapArr = explode('|', $wrap); 01301 return trim($wrapArr[0]) . $content . trim($wrapArr[1]); 01302 } else { 01303 return $content; 01304 } 01305 } 01306 01307 /** 01308 * Removes the "?" of input string IF the "?" is the last character. 01309 * 01310 * @param string Input string 01311 * @return string Output string, free of "?" in the end, if any such character. 01312 * @see linkData(), tslib_frameset::frameParams() 01313 */ 01314 function removeQueryString($url) { 01315 if (substr($url, -1) == '?') { 01316 return substr($url, 0, -1); 01317 } else { 01318 return $url; 01319 } 01320 } 01321 01322 /** 01323 * Takes a TypoScript array as input and returns an array which contains all integer properties found which had a value (not only properties). The output array will be sorted numerically. 01324 * Call it like t3lib_TStemplate::sortedKeyList() 01325 * 01326 * @param array TypoScript array with numerical array in 01327 * @param boolean If set, then a value is not required - the properties alone will be enough. 01328 * @return array An array with all integer properties listed in numeric order. 01329 * @see tslib_cObj::cObjGet(), tslib_gifBuilder, tslib_imgmenu::makeImageMap() 01330 */ 01331 function sortedKeyList($setupArr, $acceptOnlyProperties = FALSE) { 01332 $keyArr = array(); 01333 $setupArrKeys = array_keys($setupArr); 01334 foreach ($setupArrKeys as $key) { 01335 if ($acceptOnlyProperties || t3lib_div::testInt($key)) { 01336 $keyArr[] = intval($key); 01337 } 01338 } 01339 $keyArr = array_unique($keyArr); 01340 sort($keyArr); 01341 return $keyArr; 01342 } 01343 01344 01345 /** 01346 * Returns the level of the given page in the rootline - Multiple pages can be given by separating the UIDs by comma. 01347 * 01348 * @param string A list of UIDs for which the rootline-level should get returned 01349 * @return integer The level in the rootline. If more than one page was given the lowest level will get returned. 01350 */ 01351 function getRootlineLevel($list) { 01352 $idx = 0; 01353 foreach ($this->rootLine as $page) { 01354 if (t3lib_div::inList($list, $page['uid'])) { 01355 return $idx; 01356 } 01357 $idx++; 01358 } 01359 return FALSE; 01360 } 01361 01362 01363 /******************************************************************* 01364 * 01365 * Functions for creating links 01366 * 01367 *******************************************************************/ 01368 01369 /** 01370 * The mother of all functions creating links/URLs etc in a TypoScript environment. 01371 * See the references below. 01372 * Basically this function takes care of issues such as type,id,alias and Mount Points, URL rewriting (through hooks), M5/B6 encoded parameters etc. 01373 * 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. 01374 * 01375 * @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. 01376 * @param string Default target string to use IF not $page['target'] is set. 01377 * @param boolean If set, then the "&no_cache=1" parameter is included in the URL. 01378 * @param string Alternative script name if you don't want to use $GLOBALS['TSFE']->config['mainScript'] (normally set to "index.php") 01379 * @param array Array with overriding values for the $page array. 01380 * @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. 01381 * @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. 01382 * @param string The target Doamin, if any was detected in typolink 01383 * @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" 01384 * @see tslib_frameset::frameParams(), tslib_cObj::typoLink(), tslib_cObj::SEARCHRESULT(), TSpagegen::pagegenInit(), tslib_menu::link() 01385 */ 01386 function linkData($page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '', $targetDomain = '') { 01387 global $TYPO3_CONF_VARS; 01388 01389 $LD = array(); 01390 01391 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function. 01392 if (is_array($overrideArray)) { 01393 foreach ($overrideArray as $theKey => $theNewVal) { 01394 $addParams .= '&real_' . $theKey . '=' . rawurlencode($page[$theKey]); 01395 $page[$theKey] = $theNewVal; 01396 } 01397 } 01398 01399 // Adding Mount Points, "&MP=", parameter for the current page if any is set: 01400 if (!strstr($addParams, '&MP=')) { 01401 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) { // Looking for hardcoded defaults: 01402 $addParams .= '&MP=' . rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])); 01403 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) { // Else look in automatically created map: 01404 $m = $this->getFromMPmap($page['uid']); 01405 if ($m) { 01406 $addParams .= '&MP=' . rawurlencode($m); 01407 } 01408 } 01409 } 01410 01411 // Setting ID/alias: 01412 if (!$script) { 01413 $script = $GLOBALS['TSFE']->config['mainScript']; 01414 } 01415 if ($page['alias']) { 01416 $LD['url'] = $script . '?id=' . rawurlencode($page['alias']); 01417 } else { 01418 $LD['url'] = $script . '?id=' . $page['uid']; 01419 } 01420 // Setting target 01421 $LD['target'] = trim($page['target']) ? trim($page['target']) : $oTarget; 01422 01423 // typeNum 01424 $typeNum = $this->setup[$LD['target'] . '.']['typeNum']; 01425 if (!t3lib_div::testInt($typeOverride) && intval($GLOBALS['TSFE']->config['config']['forceTypeValue'])) { 01426 $typeOverride = intval($GLOBALS['TSFE']->config['config']['forceTypeValue']); 01427 } 01428 if (strcmp($typeOverride, '')) { 01429 $typeNum = $typeOverride; 01430 } // Override... 01431 if ($typeNum) { 01432 $LD['type'] = '&type=' . intval($typeNum); 01433 } else { 01434 $LD['type'] = ''; 01435 } 01436 $LD['orig_type'] = $LD['type']; // Preserving the type number. 01437 01438 // noCache 01439 $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : ''; 01440 01441 // linkVars 01442 if ($GLOBALS['TSFE']->config['config']['uniqueLinkVars']) { 01443 if ($addParams) { 01444 $LD['linkVars'] = t3lib_div::implodeArrayForUrl('', t3lib_div::explodeUrl2Array($GLOBALS['TSFE']->linkVars . $addParams)); 01445 } else { 01446 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars; 01447 } 01448 } else { 01449 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars . $addParams; 01450 } 01451 01452 // Add absRefPrefix if exists. 01453 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix . $LD['url']; 01454 01455 // If the special key 'sectionIndex_uid' (added 'manually' in tslib/menu.php to the page-record) is set, then the link jumps directly to a section on the page. 01456 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#c' . $page['sectionIndex_uid'] : ''; 01457 01458 // Compile the normal total url 01459 $LD['totalURL'] = $this->removeQueryString($LD['url'] . $LD['type'] . $LD['no_cache'] . $LD['linkVars'] . $GLOBALS['TSFE']->getMethodUrlIdToken) . $LD['sectionIndex']; 01460 01461 // Call post processing function for link rendering: 01462 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) { 01463 $_params = array( 01464 'LD' => &$LD, 01465 'args' => array('page' => $page, 'oTarget' => $oTarget, 'no_cache' => $no_cache, 'script' => $script, 'overrideArray' => $overrideArray, 'addParams' => $addParams, 'typeOverride' => $typeOverride, 'targetDomain' => $targetDomain), 01466 'typeNum' => $typeNum 01467 ); 01468 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) { 01469 t3lib_div::callUserFunction($_funcRef, $_params, $this); 01470 } 01471 } 01472 01473 // Return the LD-array 01474 return $LD; 01475 } 01476 01477 /** 01478 * Initializes the automatically created MPmap coming from the "config.MP_mapRootPoints" setting 01479 * Can be called many times with overhead only the first time since then the map is generated and cached in memory. 01480 * 01481 * @param integer Page id to return MPvar value for. 01482 * @return void 01483 * @see initMPmap_create() 01484 * @todo Implement some caching of the result between hits. (more than just the memory caching used here) 01485 */ 01486 function getFromMPmap($pageId = 0) { 01487 01488 // Create map if not found already: 01489 if (!is_array($this->MPmap)) { 01490 $this->MPmap = array(); 01491 01492 $rootPoints = t3lib_div::trimExplode(',', strtolower($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']), 1); 01493 foreach ($rootPoints as $p) { // Traverse rootpoints: 01494 if ($p == 'root') { 01495 $p = $this->rootLine[0]['uid']; 01496 $initMParray = array(); 01497 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) { 01498 $initMParray[] = $this->rootLine[0]['_MP_PARAM']; 01499 } 01500 } 01501 $this->initMPmap_create($p, $initMParray); 01502 } 01503 } 01504 01505 // Finding MP var for Page ID: 01506 if ($pageId) { 01507 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) { 01508 return implode(',', $this->MPmap[$pageId]); 01509 } 01510 } 01511 } 01512 01513 /** 01514 * Creating MPmap for a certain ID root point. 01515 * 01516 * @param integer Root id from which to start map creation. 01517 * @param array MP_array passed from root page. 01518 * @param integer Recursion brake. Incremented for each recursive call. 20 is the limit. 01519 * @return void 01520 * @see getFromMPvar() 01521 */ 01522 function initMPmap_create($id, $MP_array = array(), $level = 0) { 01523 01524 $id = intval($id); 01525 if ($id <= 0) { 01526 return; 01527 } 01528 01529 // First level, check id 01530 if (!$level) { 01531 01532 // Find mount point if any: 01533 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($id); 01534 01535 // Overlay mode: 01536 if (is_array($mount_info) && $mount_info['overlay']) { 01537 $MP_array[] = $mount_info['MPvar']; 01538 $id = $mount_info['mount_pid']; 01539 } 01540 01541 // Set mapping information for this level: 01542 $this->MPmap[$id] = $MP_array; 01543 01544 // Normal mode: 01545 if (is_array($mount_info) && !$mount_info['overlay']) { 01546 $MP_array[] = $mount_info['MPvar']; 01547 $id = $mount_info['mount_pid']; 01548 } 01549 } 01550 01551 if ($id && $level < 20) { 01552 01553 $nextLevelAcc = array(); 01554 01555 // Select and traverse current level pages: 01556 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 01557 'uid,pid,doktype,mount_pid,mount_pid_ol', 01558 'pages', 01559 'pid=' . intval($id) . ' AND deleted=0 AND doktype!=' . t3lib_pageSelect::DOKTYPE_RECYCLER . 01560 ' AND doktype!=' . t3lib_pageSelect::DOKTYPE_BE_USER_SECTION 01561 ); 01562 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01563 01564 // Find mount point if any: 01565 $next_id = $row['uid']; 01566 $next_MP_array = $MP_array; 01567 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row); 01568 01569 // Overlay mode: 01570 if (is_array($mount_info) && $mount_info['overlay']) { 01571 $next_MP_array[] = $mount_info['MPvar']; 01572 $next_id = $mount_info['mount_pid']; 01573 } 01574 01575 if (!isset($this->MPmap[$next_id])) { 01576 01577 // Set mapping information for this level: 01578 $this->MPmap[$next_id] = $next_MP_array; 01579 01580 // Normal mode: 01581 if (is_array($mount_info) && !$mount_info['overlay']) { 01582 $next_MP_array[] = $mount_info['MPvar']; 01583 $next_id = $mount_info['mount_pid']; 01584 } 01585 01586 // Register recursive call 01587 // (have to do it this way since ALL of the current level should be registered BEFORE the sublevel at any time) 01588 $nextLevelAcc[] = array($next_id, $next_MP_array); 01589 } 01590 } 01591 01592 // Call recursively, if any: 01593 foreach ($nextLevelAcc as $pSet) { 01594 $this->initMPmap_create($pSet[0], $pSet[1], $level + 1); 01595 } 01596 } 01597 } 01598 } 01599 01600 01601 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php'])) { 01602 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']); 01603 } 01604 01605 ?>
1.8.0