Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tstemplate.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class with template object that is responsible for generating the template
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 109: class t3lib_TStemplate
41 * 211: function init()
42 * 249: function getCurrentPageData()
43 * 266: function matching($cc)
44 * 290: function start($theRootLine)
45 *
46 * SECTION: Fetching TypoScript code text for the Template Hierarchy
47 * 406: function runThroughTemplates($theRootLine,$start_template_uid=0)
48 * 459: function processTemplate($row, $idList,$pid,$templateID='',$templateParent='')
49 * 580: function includeStaticTypoScriptSources($idList,$templateID,$pid,$row)
50 * 642: function addExtensionStatics($idList,$templateID,$pid,$row)
51 * 675: function prependStaticExtra($subrow)
52 * 688: function versionOL(&$row)
53 *
54 * SECTION: Parsing TypoScript code text from Template Records into PHP array
55 * 725: function generateConfig()
56 * 891: function procesIncludes()
57 * 915: function mergeConstantsFromPageTSconfig($constArray)
58 * 944: function flattenSetup($setupArray, $prefix, $resourceFlag)
59 * 968: function substituteConstants($all)
60 * 991: function substituteConstantsCallBack($matches)
61 *
62 * SECTION: Various API functions, used from elsewhere in the frontend classes
63 * 1022: function splitConfArray($conf,$splitCount)
64 * 1099: function getFileName($fileFromSetup)
65 * 1156: function extractFromResources($res,$file)
66 * 1184: function checkFile($name,$menuArr)
67 * 1201: function printTitle($title,$no_title=0,$titleFirst=0)
68 * 1224: function fileContent($fName)
69 * 1244: function wrap($content,$wrap)
70 * 1258: function removeQueryString($url)
71 * 1275: function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE)
72 *
73 * SECTION: Functions for creating links
74 * 1322: function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='')
75 * 1449: function getFromMPmap($pageId=0)
76 * 1485: function initMPmap_create($id,$MP_array=array(),$level=0)
77 *
78 * TOTAL FUNCTIONS: 28
79 * (This index is automatically created/updated by the extension "extdeveval")
80 *
81 */
82
83
84 /**
85 * Template object that is responsible for generating the TypoScript template based on template records.
86 *
87 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
88 * @package TYPO3
89 * @subpackage t3lib
90 * @see t3lib_tsparser.php, t3lib_matchcondition.php
91 */
92 class t3lib_TStemplate {
93
94 // Debugging, analysis:
95 var $tt_track = 1; // If set, the global tt-timeobject is used to log the performance.
96 var $forceTemplateParsing = 0; // If set, the template is always rendered. Used from Admin Panel.
97
98 // Backend Analysis modules settings:
99 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!
100 var $matchAll = 0; // If set, the match-class matches everything! Used for backend modules only. Never frontend!
101 var $parseEditorCfgField = 0; // If set, the Backend Editor Configuration TypoScript is also parsed (this is not needed for the frontend)
102 var $backend_info = 0;
103 var $getFileName_backPath = ''; // Set from the backend - used to set an absolute path (PATH_site) so that relative resources are properly found with getFileName()
104
105 // Externally set breakpoints (used by Backend Modules)
106 var $ext_constants_BRP = 0;
107 var $ext_config_BRP = 0;
108 var $ext_editorcfg_BRP = 0;
109 var $ext_regLinenumbers = FALSE;
110 var $ext_regComments = FALSE;
111
112 // Constants:
113 var $uplPath = 'uploads/tf/';
114 var $tempPath = 'typo3temp/';
115 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
116
117 // Set Internally:
118 var $whereClause = ''; // This MUST be initialized by the init() function
119 var $debug = 0;
120 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.
121 var $simulationHiddenOrTime = 0; // See init(); Set if preview of some kind is enabled.
122
123 var $loaded = 0; // Set, if the TypoScript template structure is loaded and OK, see ->start()
124 var $setup = array( // Default TypoScript Setup code
125 'styles.' => array(
126 'insertContent' => 'CONTENT',
127 'insertContent.' => array(
128 'table' => 'tt_content',
129 'select.' => array(
130 'orderBy' => 'sorting',
131 'where' => 'colPos=0',
132 'languageField' => 'sys_language_uid'
133 )
134 )
135 ),
136 'config.' => array(
137 'extTarget' => '_top',
138 'stat' => 1,
139 'stat_typeNumList' => '0,1',
140 'uniqueLinkVars' => 1
141 )
142 );
143 var $flatSetup = array(
144 );
145 var $const = array( // Default TypoScript Constants code:
146 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
147 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
148 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
149 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
150 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
151 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
152 );
153
154
155 // For fetching TypoScript code from template hierarchy before parsing it. Each array contains code field values from template records/files:
156 var $config = array(); // Setup field
157 var $constants = array(); // Constant field
158 var $editorcfg = array(); // Backend Editor Configuration field
159
160 var $hierarchyInfo = array(); // For Template Analyser in backend
161 var $hierarchyInfoToRoot = array(); // For Template Analyser in backend (setup content only)
162 var $nextLevel = 0; // Next-level flag (see runThroughTemplates())
163 var $rootId; // The Page UID of the root page
164 var $rootLine; // The rootline from current page to the root page
165 var $absoluteRootLine; // Rootline all the way to the root. Set but runThroughTemplates
166 var $outermostRootlineIndexWithTemplate = 0; // A pointer to the last entry in the rootline where a template was found.
167 var $rowSum; // Array of arrays with title/uid of templates in hierarchy
168 var $resources = ''; // Resources for the template hierarchy in a comma list
169 var $sitetitle = ''; // The current site title field.
170 var $sections; // Tracking all conditions found during parsing of TypoScript. Used for the "all" key in currentPageData
171 var $sectionsMatch; // Tracking all matching conditions found
172
173 // Backend: ts_analyzer
174 var $clearList_const = array();
175 var $clearList_setup = array();
176 var $clearList_editorcfg = array();
177 var $parserErrors = array();
178 var $setup_constants = array();
179
180 // Other:
181 var $fileCache = array(); // Used by getFileName for caching of references to file resources
182 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.
183 var $MPmap = ''; // Contains mapping of Page id numbers to MP variables.
184
185
186 /**
187 * Initialize
188 * MUST be called directly after creating a new template-object
189 *
190 * @return void
191 * @see tslib_fe::initTemplate()
192 */
193 function init() {
194 // $this->whereClause is used only to select templates from sys_template.
195 // $GLOBALS['SIM_ACCESS_TIME'] is used so that we're able to simulate a later time as a test...
196 $this->whereClause = 'AND deleted=0 ';
197 if (!$GLOBALS['TSFE']->showHiddenRecords) {
198 $this->whereClause .= 'AND hidden=0 ';
199 }
200 if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_ACCESS_TIME'] != $GLOBALS['ACCESS_TIME']) { // Set the simulation flag, if simulation is detected!
201 $this->simulationHiddenOrTime = 1;
202 }
203 $this->whereClause .= 'AND (starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ') AND (endtime=0 OR endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
204 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
205 $this->menuclasses = 'tmenu,jsmenu,gmenu';
206 }
207
208 // Sets the paths from where TypoScript resources are allowed to be used:
209 $this->allowedPaths = array(
210 'media/',
211 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], // fileadmin/ path
212 'uploads/',
213 'typo3temp/',
214 't3lib/fonts/',
215 TYPO3_mainDir . 'ext/',
216 TYPO3_mainDir . 'sysext/',
217 TYPO3_mainDir . 'contrib/',
218 'typo3conf/ext/'
219 );
220 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
221 $pathArr = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'], TRUE);
222 foreach ($pathArr as $p) {
223 // 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.
224 $this->allowedPaths[] = $p;
225 }
226 }
227 }
228
229 /**
230 * Fetches the "currentPageData" array from cache
231 *
232 * NOTE about currentPageData:
233 * It holds information about the TypoScript conditions along with the list
234 * of template uid's which is used on the page. In the getFromCache function
235 * in TSFE, currentPageData is used to evaluate if there is a template and
236 * if the matching conditions are alright. Unfortunately this does not take
237 * into account if the templates in the rowSum of currentPageData has
238 * changed composition, eg. due to hidden fields or start/end time. So if a
239 * template is hidden or times out, it'll not be discovered unless the page
240 * is regenerated - at least the this->start function must be called,
241 * because this will make a new portion of data in currentPageData string.
242 *
243 * @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
244 * @see start(), tslib_fe::getFromCache()
245 */
246 function getCurrentPageData() {
247 $currentPageData = FALSE;
248 if (TYPO3_UseCachingFramework) {
249 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
250 /* @var $pageSectionCache t3lib_cache_AbstractCache */
251
252 $currentPageData = $pageSectionCache->get(
253 intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
254 );
255 } else {
256 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
257 'content', 'cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . t3lib_div::md5int($GLOBALS['TSFE']->MP));
258 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
259 $currentPageData = unserialize($row['content']);
260 }
261 $GLOBALS['TYPO3_DB']->sql_free_result($res);
262 }
263
264 return $currentPageData;
265 }
266
267 /**
268 * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
269 *
270 * @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array
271 * @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.
272 * @see t3lib_matchCondition, tslib_fe::getFromCache()
273 */
274 function matching($cc) {
275 if (is_array($cc['all'])) {
276 /* @var $matchObj t3lib_matchCondition_frontend */
277 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
278 $matchObj->setRootline((array) $cc['rootLine']);
279 foreach ($cc['all'] as $key => $pre) {
280 if ($matchObj->match($pre)) {
281 $sectionsMatch[$key] = $pre;
282 }
283 }
284 $cc['match'] = $sectionsMatch;
285 }
286 return $cc;
287 }
288
289 /**
290 * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
291 * 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.
292 * Sets $this->setup to the parsed TypoScript template array
293 *
294 * @param array The rootline of the current page (going ALL the way to tree root)
295 * @return void
296 * @see tslib_fe::getConfigArray()
297 */
298 function start($theRootLine) {
299 if (is_array($theRootLine)) {
300 $setupData = '';
301 $hash = '';
302
303 // Flag that indicates that the existing data in cache_pagesection
304 // could be used (this is the case if $TSFE->all is set, and the
305 // rowSum still matches). Based on this we decide if cache_pagesection
306 // needs to be updated...
307 $isCached = FALSE;
308
309 $this->runThroughTemplates($theRootLine);
310
311 if ($GLOBALS['TSFE']->all) {
312 $cc = $GLOBALS['TSFE']->all;
313
314 // The two rowSums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
315 if (strcmp(serialize($this->rowSum), serialize($cc['rowSum']))) {
316 unset($cc); // If the two rowSums differ, we need to re-make the current page data and therefore clear the existing values.
317 } else {
318 // If $TSFE->all contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already)
319 if (!strcmp(serialize($this->rootLine), serialize($cc['rootLine']))) {
320 $isCached = TRUE;
321 }
322 // 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)...
323 unset($cc['rootLine']);
324 }
325 }
326
327 // This is about getting the hash string which is used to fetch the cached TypoScript template.
328 // If there was some cached currentPageData ($cc) then that's good (it gives us the hash).
329 if (is_array($cc)) {
330 // If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...)
331 if (!$cc['match']) {
332 // TODO: check if this can ever be the case - otherwise remove
333 $cc = $this->matching($cc);
334 ksort($cc);
335 }
336 $hash = md5(serialize($cc));
337 } else {
338 // 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.
339 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
340 $result = t3lib_pageSelect::getHash($rowSumHash);
341
342 if ($result) {
343 $cc = array();
344 $cc['all'] = unserialize($result);
345 $cc['rowSum'] = $this->rowSum;
346 $cc = $this->matching($cc);
347 ksort($cc);
348 $hash = md5(serialize($cc));
349 }
350 }
351
352 if ($hash) {
353 // Get TypoScript setup array
354 $setupData = t3lib_pageSelect::getHash($hash);
355 }
356
357 if ($setupData && !$this->forceTemplateParsing) {
358 // If TypoScript setup structure was cached we unserialize it here:
359 $this->setup = unserialize($setupData);
360 } else {
361 // Make configuration
362 $this->generateConfig();
363
364 // This stores the template hash thing
365 $cc = array();
366 $cc['all'] = $this->sections; // All sections in the template at this point is found
367 $cc['rowSum'] = $this->rowSum; // The line of templates is collected
368 $cc = $this->matching($cc);
369 ksort($cc);
370
371 $hash = md5(serialize($cc));
372
373 // This stores the data.
374 t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS_TEMPLATE');
375
376 if ($this->tt_track) {
377 $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: ' . strlen(serialize($this->setup)) . ' bytes');
378 }
379
380 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
381 t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL_CONDITIONS_ALL');
382 }
383 // Add rootLine
384 $cc['rootLine'] = $this->rootLine;
385 ksort($cc);
386
387 // Make global and save
388 $GLOBALS['TSFE']->all = $cc;
389
390 // Matching must be executed for every request, so this must never be part of the pagesection cache!
391 unset($cc['match']);
392
393 if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) { // Only save the data if we're not simulating by hidden/starttime/endtime
394 $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
395 if (TYPO3_UseCachingFramework) {
396 $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
397 /* @var $pageSectionCache t3lib_cache_AbstractCache */
398 $pageSectionCache->set(
399 intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
400 $cc,
401 array(
402 'pageId_' . intval($GLOBALS['TSFE']->id),
403 'mpvarHash_' . $mpvarHash
404 )
405 );
406 } else {
407 $dbFields = array(
408 'content' => serialize($cc),
409 'tstamp' => $GLOBALS['EXEC_TIME']
410 );
411 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvarHash, $dbFields);
412 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
413 $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
414 $dbFields['mpvar_hash'] = $mpvarHash;
415 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
416 }
417 }
418 }
419 // If everything OK.
420 if ($this->rootId && $this->rootLine && $this->setup) {
421 $this->loaded = 1;
422 }
423 }
424 }
425
426
427 /*******************************************************************
428 *
429 * Fetching TypoScript code text for the Template Hierarchy
430 *
431 *******************************************************************/
432
433 /**
434 * 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.
435 * Resets and affects internal variables like $this->constants, $this->config, $this->editorcfg and $this->rowSum
436 * 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
437 *
438 * @param array The rootline of the current page (going ALL the way to tree root)
439 * @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)
440 * @return void
441 * @see start()
442 */
443 function runThroughTemplates($theRootLine, $start_template_uid = 0) {
444 $this->constants = array();
445 $this->config = array();
446 $this->editorcfg = array();
447 $this->rowSum = array();
448 $this->hierarchyInfoToRoot = array();
449 $this->absoluteRootLine = $theRootLine; // Is the TOTAL rootline
450
451 reset($this->absoluteRootLine);
452 $c = count($this->absoluteRootLine);
453 for ($a = 0; $a < $c; $a++) {
454 if ($this->nextLevel) { // If some template loaded before has set a template-id for the next level, then load this template first!
455 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . intval($this->nextLevel) . ' ' . $this->whereClause);
456 $this->nextLevel = 0;
457 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
458 $this->versionOL($row);
459 if (is_array($row)) {
460 $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
461 $this->outermostRootlineIndexWithTemplate = $a;
462 }
463 }
464 $GLOBALS['TYPO3_DB']->sql_free_result($res);
465 }
466 $addC = '';
467 if ($a == ($c - 1) && $start_template_uid) { // If first loop AND there is set an alternative template uid, use that
468 $addC = ' AND uid=' . intval($start_template_uid);
469 }
470
471 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($this->absoluteRootLine[$a]['uid']) . $addC . ' ' . $this->whereClause, '', 'sorting', 1);
472 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
473 $this->versionOL($row);
474 if (is_array($row)) {
475 $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
476 $this->outermostRootlineIndexWithTemplate = $a;
477 }
478 }
479 $GLOBALS['TYPO3_DB']->sql_free_result($res);
480 $this->rootLine[] = $this->absoluteRootLine[$a];
481 }
482 $this->processIncludes();
483 }
484
485 /**
486 * Checks if the template ($row) has some included templates and after including them it fills the arrays with the setup
487 * Builds up $this->rowSum
488 *
489 * @param array A full TypoScript template record (sys_template/static_template/forged "dummy" record made from static template file)
490 * @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.
491 * @param array The PID of the input template record
492 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
493 * @param string Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123"
494 * @return void
495 * @see runThroughTemplates()
496 */
497 function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '') {
498 // Adding basic template record information to rowSum array
499 $this->rowSum[] = array($row['uid'], $row['title'], $row['tstamp']);
500
501 // Processing "Clear"-flags
502 if ($row['clear']) {
503 $clConst = $row['clear'] & 1;
504 $clConf = $row['clear'] & 2;
505 if ($clConst) {
506 $this->constants = array();
507 $this->clearList_const = array();
508 }
509 if ($clConf) {
510 $this->config = array();
511 $this->hierarchyInfoToRoot = array();
512 $this->clearList_setup = array();
513
514 $this->editorcfg = array();
515 $this->clearList_editorcfg = array();
516 }
517 }
518
519 // Include static records (static_template) or files (from extensions) (#1/2)
520 // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
521 if (!$row['includeStaticAfterBasedOn']) {
522 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
523 }
524
525 // Include "Based On" sys_templates:
526 if (trim($row['basedOn'])) { // 'basedOn' is a list of templates to include
527 // Manually you can put this value in the field and then the based_on ID will be taken from the $_GET var defined by '=....'.
528 // 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!
529 // 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.
530 $basedOn_hackFeature = explode('=', $row['basedOn']);
531 if ($basedOn_hackFeature[0] == 'EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
532 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
533 if ($id && !t3lib_div::inList($idList, 'sys_' . $id)) { // if $id is not allready included ...
534 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . $id . ' ' . $this->whereClause);
535 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // there was a template, then we fetch that
536 $this->versionOL($subrow);
537 if (is_array($subrow)) {
538 $this->processTemplate($subrow, $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
539 }
540 }
541 $GLOBALS['TYPO3_DB']->sql_free_result($res);
542 }
543 } else {
544 // Normal Operation, which is to include the "based-on" sys_templates,
545 // if they are not already included, and maintaining the sorting of the templates
546 $basedOnIds = t3lib_div::intExplode(',', $row['basedOn']);
547
548 // skip template if it's already included
549 foreach ($basedOnIds as $key => $basedOnId) {
550 if (t3lib_div::inList($idList, 'sys_' . $basedOnId)) {
551 unset($basedOnIds[$key]);
552 }
553 }
554
555 $subTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
556 '*', 'sys_template',
557 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause,
558 '', '', '',
559 'uid' // the associative array that is returned will contain this field as key
560 );
561
562 // traversing list again to ensure the sorting of the templates
563 foreach ($basedOnIds as $id) {
564 if (is_array($subTemplates[$id])) {
565 $this->versionOL($subTemplates[$id]);
566 $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
567 }
568 }
569 }
570 }
571
572 // Include static records (static_template) or files (from extensions) (#2/2)
573 if ($row['includeStaticAfterBasedOn']) {
574 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
575 }
576
577 // Creating hierarchy information; Used by backend analysis tools
578 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
579 'root' => trim($row['root']),
580 'next' => $row['nextLevel'],
581 'clConst' => $clConst,
582 'clConf' => $clConf,
583 'templateID' => $templateID,
584 'templateParent' => $templateParent,
585 'title' => $row['title'],
586 'uid' => $row['uid'],
587 'pid' => $row['pid'],
588 'configLines' => substr_count($row['config'], LF) + 1
589 );
590
591 // Adding the content of the fields constants (Constants), config (Setup) and editorcfg (Backend Editor Configuration) to the internal arrays.
592 $this->constants[] = $row['constants'];
593 $this->config[] = $row['config'];
594 if ($this->parseEditorCfgField) {
595 $this->editorcfg[] = $row['editorcfg'];
596 }
597
598 // For backend analysis (Template Analyser) provide the order of added constants/config/editorcfg template IDs
599 $this->clearList_const[] = $templateID;
600 $this->clearList_setup[] = $templateID;
601 if ($this->parseEditorCfgField) {
602 $this->clearList_editorcfg[] = $templateID;
603 }
604
605 // Add resources and sitetitle if found:
606 if (trim($row['resources'])) {
607 $this->resources = $row['resources'] . ',' . $this->resources;
608 }
609 if (trim($row['sitetitle'])) {
610 $this->sitetitle = $row['sitetitle'];
611 }
612 // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
613 if (trim($row['root'])) {
614 $this->rootId = $pid;
615 $this->rootLine = array();
616 }
617 // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
618 if ($row['nextLevel']) {
619 $this->nextLevel = $row['nextLevel'];
620 } else {
621 $this->nextLevel = 0;
622 }
623 }
624
625 /**
626 * Includes static template records (from static_template table, loaded through a hook) and static template files (from extensions) for the input template record row.
627 *
628 * @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.
629 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
630 * @param array The PID of the input template record
631 * @param array A full TypoScript template record
632 * @return void
633 * @see processTemplate()
634 */
635 function includeStaticTypoScriptSources($idList, $templateID, $pid, $row) {
636 // Static Template Records (static_template): include_static is a list of static templates to include
637 // Call function for link rendering:
638 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'])) {
639 $_params = array(
640 'idList' => &$idList,
641 'templateId' => &$templateID,
642 'pid' => &$pid,
643 'row' => &$row
644 );
645 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] as $_funcRef) {
646 t3lib_div::callUserFunction($_funcRef, $_params, $this);
647 }
648 }
649
650 // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
651 if (trim($row['include_static_file'])) {
652 $include_static_fileArr = t3lib_div::trimExplode(',', $row['include_static_file'], TRUE);
653 foreach ($include_static_fileArr as $ISF_file) { // traversing list
654 if (substr($ISF_file, 0, 4) == 'EXT:') {
655 list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2);
656 if (strcmp($ISF_extKey, '') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath, '')) {
657 $ISF_localPath = rtrim($ISF_localPath, '/') . '/';
658 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey) . $ISF_localPath;
659 if (@is_dir($ISF_filePath)) {
660 $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
661 $subrow = array(
662 'constants' => @is_file($ISF_filePath . 'constants.txt') ? t3lib_div::getUrl($ISF_filePath . 'constants.txt') : '',
663 'config' => @is_file($ISF_filePath . 'setup.txt') ? t3lib_div::getUrl($ISF_filePath . 'setup.txt') : '',
664 'editorcfg' => @is_file($ISF_filePath . 'editorcfg.txt') ? t3lib_div::getUrl($ISF_filePath . 'editorcfg.txt') : '',
665 'include_static' => @is_file($ISF_filePath . 'include_static.txt') ? implode(',', array_unique(t3lib_div::intExplode(',', t3lib_div::getUrl($ISF_filePath . 'include_static.txt')))) : '',
666 'include_static_file' => @is_file($ISF_filePath . 'include_static_file.txt') ? implode(',', array_unique(explode(',', t3lib_div::getUrl($ISF_filePath . 'include_static_file.txt')))) : '',
667 'title' => $ISF_file,
668 'uid' => $mExtKey
669 );
670 $subrow = $this->prependStaticExtra($subrow);
671
672 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
673 }
674 }
675 }
676 }
677 }
678
679 $this->addExtensionStatics($idList, $templateID, $pid, $row);
680
681 // Include Static Template Records after all other TypoScript has been included.
682 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'])) {
683 $_params = array(
684 'idList' => &$idList,
685 'templateId' => &$templateID,
686 'pid' => &$pid,
687 'row' => &$row
688 );
689 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] as $_funcRef) {
690 t3lib_div::callUserFunction($_funcRef, $_params, $this);
691 }
692 }
693 }
694
695 /**
696 * Adds the default TypoScript files for extensions if any.
697 *
698 * @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.
699 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
700 * @param array The PID of the input template record
701 * @param array A full TypoScript template record
702 * @return void
703 * @access private
704 * @see includeStaticTypoScriptSources()
705 */
706 function addExtensionStatics($idList, $templateID, $pid, $row) {
707 global $TYPO3_LOADED_EXT;
708
709 if ($row['static_file_mode'] == 1 || ($row['static_file_mode'] == 0 && substr($templateID, 0, 4) == 'sys_' && $row['root'])) {
710 foreach ($TYPO3_LOADED_EXT as $extKey => $files) {
711 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
712 $mExtKey = str_replace('_', '', $extKey);
713 $subrow = array(
714 'constants' => $files['ext_typoscript_constants.txt'] ? t3lib_div::getUrl($files['ext_typoscript_constants.txt']) : '',
715 'config' => $files['ext_typoscript_setup.txt'] ? t3lib_div::getUrl($files['ext_typoscript_setup.txt']) : '',
716 'editorcfg' => $files['ext_typoscript_editorcfg.txt'] ? t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']) : '',
717 'title' => $extKey,
718 'uid' => $mExtKey
719 );
720 $subrow = $this->prependStaticExtra($subrow);
721
722 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
723 }
724 }
725 }
726 }
727
728 /**
729 * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS
730 * For records the "uid" value is the integer of the "static_template" record
731 * 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
732 *
733 * @param array Static template record/file
734 * @return array Returns the input array where the values for keys "config", "constants" and "editorcfg" may have been modified with prepended code.
735 * @access private
736 * @see addExtensionStatics(), includeStaticTypoScriptSources()
737 */
738 function prependStaticExtra($subrow) {
739 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
740 $subrow['editorcfg'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
741 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
742 return $subrow;
743 }
744
745 /**
746 * Creating versioning overlay of a sys_template record. This will use either frontend or backend overlay functionality depending on environment.
747 *
748 * @param array Row to overlay.
749 * @return void Row is passed by reference.
750 */
751 function versionOL(&$row) {
752 if (is_object($GLOBALS['TSFE'])) { // Frontend:
753 $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
754 } else { // Backend:
755 t3lib_BEfunc::workspaceOL('sys_template', $row);
756 }
757 }
758
759
760 /*******************************************************************
761 *
762 * Parsing TypoScript code text from Template Records into PHP array
763 *
764 *******************************************************************/
765
766 /**
767 * Generates the configuration array by replacing constants and parsing the whole thing.
768 * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates)
769 *
770 * @return void
771 * @see t3lib_TSparser, start()
772 */
773 function generateConfig() {
774 // Add default TS for all three code types:
775 array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']); // Adding default TS/constants
776 array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']); // Adding default TS/setup
777 array_unshift($this->editorcfg, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']); // Adding default TS/editorcfg
778
779 // Parse the TypoScript code text for include-instructions!
780 $this->processIncludes();
781
782 // These vars are also set lateron...
783 $this->setup['resources'] = $this->resources;
784 $this->setup['sitetitle'] = $this->sitetitle;
785
786
787 // ****************************
788 // Parse TypoScript Constants
789 // ****************************
790
791 // Initialize parser and match-condition classes:
792 $constants = t3lib_div::makeInstance('t3lib_TSparser');
793 $constants->breakPointLN = intval($this->ext_constants_BRP);
794 $constants->setup = $this->const;
795 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
796
797 /* @var $matchObj t3lib_matchCondition_frontend */
798 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
799 $matchObj->setSimulateMatchConditions($this->matchAlternative);
800 $matchObj->setSimulateMatchResult((bool) $this->matchAll);
801
802 // Traverse constants text fields and parse them
803 foreach ($this->constants as $str) {
804 $constants->parse($str, $matchObj);
805 }
806
807 // Read out parse errors if any
808 $this->parserErrors['constants'] = $constants->errors;
809
810 // 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)
811 $this->flatSetup = array();
812 $this->flattenSetup($constants->setup, '', '');
813
814
815 // ***********************************************
816 // Parse TypoScript Setup (here called "config")
817 // ***********************************************
818 // Initialize parser and match-condition classes:
819 $config = t3lib_div::makeInstance('t3lib_TSparser');
820 $config->breakPointLN = intval($this->ext_config_BRP);
821 $config->regLinenumbers = $this->ext_regLinenumbers;
822 $config->regComments = $this->ext_regComments;
823 $config->setup = $this->setup;
824
825 // Transfer information about conditions found in "Constants" and which of them returned true.
826 $config->sections = $constants->sections;
827 $config->sectionsMatch = $constants->sectionsMatch;
828
829 // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition
830 $all = '';
831 foreach ($this->config as $str) {
832 $all .= "\n[GLOBAL]\n" . $str;
833 }
834
835 // Substitute constants in the Setup code:
836 if ($this->tt_track) {
837 $GLOBALS['TT']->push('Substitute Constants (' . count($this->flatSetup) . ')');
838 }
839 $all = $this->substituteConstants($all);
840 if ($this->tt_track) {
841 $GLOBALS['TT']->pull();
842 }
843
844 // Searching for possible unsubstituted constants left (only for information)
845 if (strstr($all, '{$')) {
846 $theConstList = array();
847 $findConst = explode('{$', $all);
848 array_shift($findConst);
849 foreach ($findConst as $constVal) {
850 $constLen = t3lib_div::intInRange(strcspn($constVal, '}'), 0, 50);
851 $theConstList[] = '{$' . substr($constVal, 0, $constLen + 1);
852 }
853 if ($this->tt_track) {
854 $GLOBALS['TT']->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2);
855 }
856 }
857
858 // Logging the textual size of the TypoScript Setup field text with all constants substituted:
859 if ($this->tt_track) {
860 $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes');
861 }
862
863 // Finally parse the Setup field TypoScript code (where constants are now substituted)
864 $config->parse($all, $matchObj);
865
866 // Read out parse errors if any
867 $this->parserErrors['config'] = $config->errors;
868
869 // Transfer the TypoScript array from the parser object to the internal $this->setup array:
870 $this->setup = $config->setup;
871 if ($this->backend_info) {
872 $this->setup_constants = $constants->setup; // Used for backend purposes only
873 }
874
875
876 // **************************************************
877 // Parse Backend Editor Configuration (backend only)
878 // **************************************************
879 if ($this->parseEditorCfgField) {
880 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
881 $editorcfg->breakPointLN = intval($this->ext_editorcfg_BRP);
882 $editorcfg->setup = array(); // Empty as a start...
883
884 $all = implode("\n[GLOBAL]\n", $this->editorcfg);
885
886 // substitute constants in config
887 $all = $this->substituteConstants($all);
888
889 // parse Config
890 $matchObj->matchAll = 1; // This should make sure that conditions are disabled. For now they are NOT active for the backend.
891 $editorcfg->parse($all, $matchObj);
892 $this->parserErrors['editorcfg'] = $editorcfg->errors;
893 $this->setup_editorcfg = $editorcfg->setup;
894 }
895
896
897 // ****************************************************************
898 // Final processing of the $this->setup TypoScript Template array
899 // Basically: This is unsetting/setting of certain reserved keys.
900 // ****************************************************************
901
902 // 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!
903 unset($this->setup['resources']);
904 unset($this->setup['resources.']);
905 $this->setup['resources'] = implode(',', t3lib_div::trimExplode(',', $this->resources, 1));
906
907 unset($this->setup['sitetitle']);
908 unset($this->setup['sitetitle.']);
909 $this->setup['sitetitle'] = $this->sitetitle;
910
911 // Unsetting some vars...
912 unset($this->setup['types.']);
913 unset($this->setup['types']);
914 if (is_array($this->setup)) {
915 foreach ($this->setup as $key => $value) {
916 if ($value == 'PAGE') {
917 // Set the typeNum of the current page object:
918 if (isset($this->setup[$key . '.']['typeNum'])) {
919 $typeNum = $this->setup[$key . '.']['typeNum'];
920 $this->setup['types.'][$typeNum] = $key;
921 // If there is no type 0 yet and typeNum was not set, we use the current object as the default
922 } elseif (!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) {
923 $this->setup['types.'][0] = $key;
924 }
925 }
926 }
927 }
928 unset($this->setup['styles.']);
929 unset($this->setup['temp.']);
930 unset($constants);
931
932 // Storing the conditions found/matched information:
933 $this->sections = $config->sections;
934 $this->sectionsMatch = $config->sectionsMatch;
935 }
936
937 /**
938 * Searching TypoScript code text (for constants, config (Setup) and editorcfg) for include instructions and does the inclusion if needed.
939 *
940 * @return void
941 * @deprecated since TYPO3 4.4 - Method name misspelled. Use "processIncludes" instead! This function will be removed in TYPO3 4.6.
942 * @see t3lib_TSparser, processIncludes()
943 */
944 public function procesIncludes() {
945 t3lib_div::logDeprecatedFunction();
946 $this->processIncludes();
947 }
948
949 /**
950 * Searching TypoScript code text (for constants, config (Setup) and editorcfg)
951 * for include instructions and does the inclusion of external TypoScript files
952 * if needed.
953 *
954 * @return void
955 * @see t3lib_TSparser, generateConfig()
956 */
957 public function processIncludes() {
958 $files = array();
959 foreach ($this->constants as &$value) {
960 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
961 $files = array_merge($files, $includeData['files']);
962 $value = $includeData['typoscript'];
963 }
964
965 foreach ($this->config as &$value) {
966 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
967 $files = array_merge($files, $includeData['files']);
968 $value = $includeData['typoscript'];
969 }
970
971 foreach ($this->editorcfg as &$value) {
972 $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
973 $files = array_merge($files, $includeData['files']);
974 $value = $includeData['typoscript'];
975 }
976 if (count($files)) {
977 $files = array_unique($files);
978 foreach ($files as $file) {
979 $this->rowSum[] = array($file, filemtime($file));
980 }
981 }
982 }
983
984 /**
985 * 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!
986 *
987 * @param array Constants array, default input.
988 * @return array Constants array, modified
989 * @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...)
990 */
991 function mergeConstantsFromPageTSconfig($constArray) {
992 $TSdataArray = array();
993 $TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
994
995 for ($a = 0; $a <= $this->outermostRootlineIndexWithTemplate; $a++) {
996 $TSdataArray[] = $this->absoluteRootLine[$a]['TSconfig'];
997 }
998 // Parsing the user TS (or getting from cache)
999 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
1000 $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
1001
1002 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
1003 $parseObj->parse($userTS);
1004
1005 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
1006 $constArray = t3lib_div::array_merge_recursive_overrule($constArray, $parseObj->setup['TSFE.']['constants.']);
1007 }
1008 return $constArray;
1009 }
1010
1011 /**
1012 * This flattens a hierarchical TypoScript array to $this->flatSetup
1013 *
1014 * @param array TypoScript array
1015 * @param string Prefix to the object path. Used for recursive calls to this function.
1016 * @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.
1017 * @return void
1018 * @see generateConfig()
1019 */
1020 function flattenSetup($setupArray, $prefix, $resourceFlag) {
1021 if (is_array($setupArray)) {
1022 foreach ($setupArray as $key => $val) {
1023 if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
1024 if (is_array($val)) {
1025 $this->flattenSetup($val, $prefix . $key, ($key == 'file.'));
1026 } elseif ($resourceFlag) {
1027 $this->flatSetup[$prefix . $key] = $this->getFileName($val);
1028 } else {
1029 $this->flatSetup[$prefix . $key] = $val;
1030 }
1031 }
1032 }
1033 }
1034 }
1035
1036 /**
1037 * Substitutes the constants from $this->flatSetup in the text string $all
1038 *
1039 * @param string TypoScript code text string
1040 * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted.
1041 * @see generateConfig(), flattenSetup()
1042 */
1043 function substituteConstants($all) {
1044 if ($this->tt_track) {
1045 $GLOBALS['TT']->setTSlogMessage('Constants to substitute: ' . count($this->flatSetup));
1046 }
1047
1048 $noChange = FALSE;
1049 // recursive substitution of constants (up to 10 nested levels)
1050 for ($i = 0; $i < 10 && !$noChange; $i++) {
1051 $old_all = $all;
1052 $all = preg_replace_callback('/\{\$(.[^}]*)\}/', array($this, 'substituteConstantsCallBack'), $all);
1053 if ($old_all == $all) {
1054 $noChange = TRUE;
1055 }
1056 }
1057
1058 return $all;
1059 }
1060
1061 /**
1062 * Call back method for preg_replace_callback in substituteConstants
1063 *
1064 * @param array Regular expression matches
1065 * @return string Replacement
1066 * @see substituteConstants()
1067 */
1068 function substituteConstantsCallBack($matches) {
1069 // replace {$CONST} if found in $this->flatSetup, else leave unchanged
1070 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
1071 }
1072
1073
1074 /*******************************************************************
1075 *
1076 * Various API functions, used from elsewhere in the frontend classes
1077 *
1078 *******************************************************************/
1079
1080 /**
1081 * Implementation of the "optionSplit" feature in TypoScript (used eg. for MENU objects)
1082 * 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.
1083 * The concept is known as "optionSplit" and is rather advanced to handle but quite powerful, in particular for creating menus in TYPO3.
1084 *
1085 * @param array A TypoScript array
1086 * @param integer The number of items for which to generated individual TypoScript arrays
1087 * @return array The individualized TypoScript array.
1088 * @see tslib_cObj::IMGTEXT(), tslib_menu::procesItemStates()
1089 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=289&cHash=6604390b37
1090 */
1091 function splitConfArray($conf, $splitCount) {
1092
1093 // Initialize variables:
1094 $splitCount = intval($splitCount);
1095 $conf2 = array();
1096
1097 if ($splitCount && is_array($conf)) {
1098
1099 // Initialize output to carry at least the keys:
1100 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1101 $conf2[$aKey] = array();
1102 }
1103
1104 // Recursive processing of array keys:
1105 foreach ($conf as $cKey => $val) {
1106 if (is_array($val)) {
1107 $tempConf = $this->splitConfArray($val, $splitCount);
1108 foreach ($tempConf as $aKey => $val) {
1109 $conf2[$aKey][$cKey] = $val;
1110 }
1111 } else {
1112 // Splitting of all values on this level of the TypoScript object tree:
1113 if (!strstr($val, '|*|') && !strstr($val, '||')) {
1114 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1115 $conf2[$aKey][$cKey] = $val;
1116 }
1117 } else {
1118 $main = explode('|*|', $val);
1119 $mainCount = count($main);
1120
1121 $lastC = 0;
1122 $middleC = 0;
1123 $firstC = 0;
1124
1125 if ($main[0]) {
1126 $first = explode('||', $main[0]);
1127 $firstC = count($first);
1128 }
1129 if ($main[1]) {
1130 $middle = explode('||', $main[1]);
1131 $middleC = count($middle);
1132 }
1133 if ($main[2]) {
1134 $last = explode('||', $main[2]);
1135 $lastC = count($last);
1136 $value = $last[0];
1137 }
1138
1139 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1140 if ($firstC && isset($first[$aKey])) {
1141 $value = $first[$aKey];
1142 } elseif ($middleC) {
1143 $value = $middle[($aKey - $firstC) % $middleC];
1144 }
1145 if ($lastC && $lastC >= ($splitCount - $aKey)) {
1146 $value = $last[$lastC - ($splitCount - $aKey)];
1147 }
1148 $conf2[$aKey][$cKey] = trim($value);
1149 }
1150 }
1151 }
1152 }
1153 }
1154 return $conf2;
1155 }
1156
1157 /**
1158 * Returns the reference to a 'resource' in TypoScript.
1159 * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list
1160 *
1161 * @param string TypoScript "resource" data type value.
1162 * @return string Resulting filename, if any.
1163 */
1164 function getFileName($fileFromSetup) {
1165 $file = trim($fileFromSetup);
1166 if (!$file) {
1167 return;
1168 } elseif (strstr($file, '../')) {
1169 if ($this->tt_track) {
1170 $GLOBALS['TT']->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3);
1171 }
1172 return;
1173 }
1174 // cache
1175 $hash = md5($file);
1176 if (isset($this->fileCache[$hash])) {
1177 return $this->fileCache[$hash];
1178 }
1179
1180 if (!strcmp(substr($file, 0, 4), 'EXT:')) {
1181 $newFile = '';
1182 list($extKey, $script) = explode('/', substr($file, 4), 2);
1183 if ($extKey && t3lib_extMgm::isLoaded($extKey)) {
1184 $extPath = t3lib_extMgm::extPath($extKey);
1185 $newFile = substr($extPath, strlen(PATH_site)) . $script;
1186 }
1187 if (!@is_file(PATH_site . $newFile)) {
1188 if ($this->tt_track) {
1189 $GLOBALS['TT']->setTSlogMessage('Extension media file "' . $newFile . '" was not found!', 3);
1190 }
1191 return;
1192 } else {
1193 $file = $newFile;
1194 }
1195 }
1196
1197 // find
1198 if (strpos($file, '/') !== FALSE) {
1199 // if the file is in the media/ folder but it doesn't exist,
1200 // it is assumed that it's in the tslib folder
1201 if (t3lib_div::isFirstPartOfStr($file, 'media/') && !is_file($this->getFileName_backPath . $file)) {
1202 $file = t3lib_extMgm::siteRelPath('cms') . 'tslib/' . $file;
1203 }
1204 if (is_file($this->getFileName_backPath . $file)) {
1205 $outFile = $file;
1206 $fileInfo = t3lib_div::split_fileref($outFile);
1207 $OK = 0;
1208 foreach ($this->allowedPaths as $val) {
1209 if (substr($fileInfo['path'], 0, strlen($val)) == $val) {
1210 $OK = 1;
1211 break;
1212 }
1213 }
1214 if ($OK) {
1215 $this->fileCache[$hash] = $outFile;
1216 return $outFile;
1217 } elseif ($this->tt_track) {
1218 $GLOBALS['TT']->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
1219 }
1220 } elseif ($this->tt_track) {
1221 $GLOBALS['TT']->setTSlogMessage('"' . $this->getFileName_backPath . $file . '" is not a file (non-uploads/.. resource, did not exist).', 3);
1222 }
1223 } else { // Here it is uploaded media:
1224 $outFile = $this->extractFromResources($this->setup['resources'], $file);
1225 if ($outFile) {
1226 if (@is_file($this->uplPath . $outFile)) {
1227 $this->fileCache[$hash] = $this->uplPath . $outFile;
1228 return $this->uplPath . $outFile;
1229 } elseif ($this->tt_track) {
1230 $GLOBALS['TT']->setTSlogMessage('"' . $this->uplPath . $outFile . '" is not a file (did not exist).', 3);
1231 }
1232 } elseif ($this->tt_track) {
1233 $GLOBALS['TT']->setTSlogMessage('"' . $file . '" is not a file (uploads/.. resource).', 3);
1234 }
1235 }
1236 }
1237
1238 /**
1239 * Searches for the TypoScript resource filename in the list of resource filenames.
1240 *
1241 * @param string The resource file name list (from $this->setup['resources'])
1242 * @param string The resource value to match
1243 * @return string If found, this will be the resource filename that matched. Typically this file is found in "uploads/tf/"
1244 * @access private
1245 * @see getFileName()
1246 */
1247 function extractFromResources($res, $file) {
1248 if (t3lib_div::inList($res, $file)) {
1249 $outFile = $file;
1250 } elseif (strstr($file, '*')) {
1251 $fileparts = explode('*', $file);
1252 $c = count($fileparts);
1253 $files = t3lib_div::trimExplode(',', $res);
1254 foreach ($files as $file) {
1255 if (preg_match('/^' . quotemeta($fileparts[0]) . '.*' . quotemeta($fileparts[$c - 1]) . '$/', $file)) {
1256 $outFile = $file;
1257 break;
1258 }
1259 }
1260 }
1261 return $outFile;
1262 }
1263
1264 /**
1265 * CheckFile runs through the $menuArr and checks every file-reference in $name
1266 * (Not used anywhere)
1267 *
1268 * @param string Property name in the menu array
1269 * @param array Menu array to traverse
1270 * @return array Modified menu array
1271 * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.6.
1272 * @internal
1273 */
1274 function checkFile($name, $menuArr) {
1275 t3lib_div::logDeprecatedFunction();
1276
1277 foreach ($menuArr as $aKey => $value) {
1278 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
1279 }
1280 return $menuArr;
1281 }
1282
1283 /**
1284 * Compiles the content for the page <title> tag.
1285 *
1286 * @param string The input title string, typically the "title" field of a page's record.
1287 * @param boolean If set, then only the site title is outputted (from $this->setup['sitetitle'])
1288 * @param boolean If set, then "sitetitle" and $title is swapped
1289 * @return string The page title on the form "[sitetitle]: [input-title]". Not htmlspecialchar()'ed.
1290 * @see tslib_fe::tempPageCacheContent(), TSpagegen::renderContentWithHeader()
1291 */
1292 function printTitle($title, $no_title = 0, $titleFirst = 0) {
1293 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle'] : '';
1294 $title = $no_title ? '' : $title;
1295 if ($titleFirst) {
1296 $temp = $st;
1297 $st = $title;
1298 $title = $temp;
1299 }
1300 if ($title && $st) {
1301 return $st . ': ' . $title;
1302 } else {
1303 return $st . $title;
1304 }
1305 }
1306
1307 /**
1308 * Reads the fileContent of $fName and returns it.
1309 * Similar to t3lib_div::getUrl()
1310 *
1311 * @param string Absolute filepath to record
1312 * @return string The content returned
1313 * @see tslib_cObj::fileResource(), tslib_cObj::MULTIMEDIA(), t3lib_div::getUrl()
1314 */
1315 function fileContent($fName) {
1316 $incFile = $this->getFileName($fName);
1317 if ($incFile) {
1318 return @file_get_contents($incFile);
1319 }
1320 }
1321
1322 /**
1323 * Ordinary "wrapping" function. Used in the tslib_menu class and extension classes instead of the similar function in tslib_cObj
1324 *
1325 * @param string The content to wrap
1326 * @param string The wrap value, eg. "<strong> | </strong>"
1327 * @return string Wrapped input string
1328 * @see tslib_menu, tslib_cObj::wrap()
1329 */
1330 function wrap($content, $wrap) {
1331 if ($wrap) {
1332 $wrapArr = explode('|', $wrap);
1333 return trim($wrapArr[0]) . $content . trim($wrapArr[1]);
1334 } else {
1335 return $content;
1336 }
1337 }
1338
1339 /**
1340 * Removes the "?" of input string IF the "?" is the last character.
1341 *
1342 * @param string Input string
1343 * @return string Output string, free of "?" in the end, if any such character.
1344 * @see linkData(), tslib_frameset::frameParams()
1345 */
1346 function removeQueryString($url) {
1347 if (substr($url, -1) == '?') {
1348 return substr($url, 0, -1);
1349 } else {
1350 return $url;
1351 }
1352 }
1353
1354 /**
1355 * 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.
1356 * Call it like t3lib_TStemplate::sortedKeyList()
1357 *
1358 * @param array TypoScript array with numerical array in
1359 * @param boolean If set, then a value is not required - the properties alone will be enough.
1360 * @return array An array with all integer properties listed in numeric order.
1361 * @see tslib_cObj::cObjGet(), tslib_gifBuilder, tslib_imgmenu::makeImageMap()
1362 */
1363 function sortedKeyList($setupArr, $acceptOnlyProperties = FALSE) {
1364 $keyArr = array();
1365 $setupArrKeys = array_keys($setupArr);
1366 foreach ($setupArrKeys as $key) {
1367 if ($acceptOnlyProperties || t3lib_div::testInt($key)) {
1368 $keyArr[] = intval($key);
1369 }
1370 }
1371 $keyArr = array_unique($keyArr);
1372 sort($keyArr);
1373 return $keyArr;
1374 }
1375
1376
1377 /**
1378 * Returns the level of the given page in the rootline - Multiple pages can be given by separating the UIDs by comma.
1379 *
1380 * @param string A list of UIDs for which the rootline-level should get returned
1381 * @return integer The level in the rootline. If more than one page was given the lowest level will get returned.
1382 */
1383 function getRootlineLevel($list) {
1384 $idx = 0;
1385 foreach ($this->rootLine as $page) {
1386 if (t3lib_div::inList($list, $page['uid'])) {
1387 return $idx;
1388 }
1389 $idx++;
1390 }
1391 return FALSE;
1392 }
1393
1394
1395 /*******************************************************************
1396 *
1397 * Functions for creating links
1398 *
1399 *******************************************************************/
1400
1401 /**
1402 * The mother of all functions creating links/URLs etc in a TypoScript environment.
1403 * See the references below.
1404 * Basically this function takes care of issues such as type,id,alias and Mount Points, URL rewriting (through hooks), M5/B6 encoded parameters etc.
1405 * 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.
1406 *
1407 * @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.
1408 * @param string Default target string to use IF not $page['target'] is set.
1409 * @param boolean If set, then the "&no_cache=1" parameter is included in the URL.
1410 * @param string Alternative script name if you don't want to use $GLOBALS['TSFE']->config['mainScript'] (normally set to "index.php")
1411 * @param array Array with overriding values for the $page array.
1412 * @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.
1413 * @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.
1414 * @param string The target Doamin, if any was detected in typolink
1415 * @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"
1416 * @see tslib_frameset::frameParams(), tslib_cObj::typoLink(), tslib_cObj::SEARCHRESULT(), TSpagegen::pagegenInit(), tslib_menu::link()
1417 */
1418 function linkData($page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '', $targetDomain = '') {
1419 global $TYPO3_CONF_VARS;
1420
1421 $LD = array();
1422
1423 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
1424 if (is_array($overrideArray)) {
1425 foreach ($overrideArray as $theKey => $theNewVal) {
1426 $addParams .= '&real_' . $theKey . '=' . rawurlencode($page[$theKey]);
1427 $page[$theKey] = $theNewVal;
1428 }
1429 }
1430
1431 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
1432 if (!strstr($addParams, '&MP=')) {
1433 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) { // Looking for hardcoded defaults:
1434 $addParams .= '&MP=' . rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']]));
1435 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) { // Else look in automatically created map:
1436 $m = $this->getFromMPmap($page['uid']);
1437 if ($m) {
1438 $addParams .= '&MP=' . rawurlencode($m);
1439 }
1440 }
1441 }
1442
1443 // Setting ID/alias:
1444 if (!$script) {
1445 $script = $GLOBALS['TSFE']->config['mainScript'];
1446 }
1447 if ($page['alias']) {
1448 $LD['url'] = $script . '?id=' . rawurlencode($page['alias']);
1449 } else {
1450 $LD['url'] = $script . '?id=' . $page['uid'];
1451 }
1452 // Setting target
1453 $LD['target'] = trim($page['target']) ? trim($page['target']) : $oTarget;
1454
1455 // typeNum
1456 $typeNum = $this->setup[$LD['target'] . '.']['typeNum'];
1457 if (!t3lib_div::testInt($typeOverride) && intval($GLOBALS['TSFE']->config['config']['forceTypeValue'])) {
1458 $typeOverride = intval($GLOBALS['TSFE']->config['config']['forceTypeValue']);
1459 }
1460 if (strcmp($typeOverride, '')) {
1461 $typeNum = $typeOverride;
1462 } // Override...
1463 if ($typeNum) {
1464 $LD['type'] = '&type=' . intval($typeNum);
1465 } else {
1466 $LD['type'] = '';
1467 }
1468 $LD['orig_type'] = $LD['type']; // Preserving the type number.
1469
1470 // noCache
1471 $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : '';
1472
1473 // linkVars
1474 if ($GLOBALS['TSFE']->config['config']['uniqueLinkVars']) {
1475 if ($addParams) {
1476 $LD['linkVars'] = t3lib_div::implodeArrayForUrl('', t3lib_div::explodeUrl2Array($GLOBALS['TSFE']->linkVars . $addParams));
1477 } else {
1478 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars;
1479 }
1480 } else {
1481 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars . $addParams;
1482 }
1483
1484 // Add absRefPrefix if exists.
1485 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix . $LD['url'];
1486
1487 // 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.
1488 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#c' . $page['sectionIndex_uid'] : '';
1489
1490 // Compile the normal total url
1491 $LD['totalURL'] = $this->removeQueryString($LD['url'] . $LD['type'] . $LD['no_cache'] . $LD['linkVars'] . $GLOBALS['TSFE']->getMethodUrlIdToken) . $LD['sectionIndex'];
1492
1493 // Call post processing function for link rendering:
1494 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) {
1495 $_params = array(
1496 'LD' => &$LD,
1497 'args' => array('page' => $page, 'oTarget' => $oTarget, 'no_cache' => $no_cache, 'script' => $script, 'overrideArray' => $overrideArray, 'addParams' => $addParams, 'typeOverride' => $typeOverride, 'targetDomain' => $targetDomain),
1498 'typeNum' => $typeNum
1499 );
1500 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) {
1501 t3lib_div::callUserFunction($_funcRef, $_params, $this);
1502 }
1503 }
1504
1505 // Return the LD-array
1506 return $LD;
1507 }
1508
1509 /**
1510 * Initializes the automatically created MPmap coming from the "config.MP_mapRootPoints" setting
1511 * Can be called many times with overhead only the first time since then the map is generated and cached in memory.
1512 *
1513 * @param integer Page id to return MPvar value for.
1514 * @return void
1515 * @see initMPmap_create()
1516 * @todo Implement some caching of the result between hits. (more than just the memory caching used here)
1517 */
1518 function getFromMPmap($pageId = 0) {
1519
1520 // Create map if not found already:
1521 if (!is_array($this->MPmap)) {
1522 $this->MPmap = array();
1523
1524 $rootPoints = t3lib_div::trimExplode(',', strtolower($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']), 1);
1525 foreach ($rootPoints as $p) { // Traverse rootpoints:
1526 if ($p == 'root') {
1527 $p = $this->rootLine[0]['uid'];
1528 $initMParray = array();
1529 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) {
1530 $initMParray[] = $this->rootLine[0]['_MP_PARAM'];
1531 }
1532 }
1533 $this->initMPmap_create($p, $initMParray);
1534 }
1535 }
1536
1537 // Finding MP var for Page ID:
1538 if ($pageId) {
1539 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) {
1540 return implode(',', $this->MPmap[$pageId]);
1541 }
1542 }
1543 }
1544
1545 /**
1546 * Creating MPmap for a certain ID root point.
1547 *
1548 * @param integer Root id from which to start map creation.
1549 * @param array MP_array passed from root page.
1550 * @param integer Recursion brake. Incremented for each recursive call. 20 is the limit.
1551 * @return void
1552 * @see getFromMPvar()
1553 */
1554 function initMPmap_create($id, $MP_array = array(), $level = 0) {
1555
1556 $id = intval($id);
1557 if ($id <= 0) {
1558 return;
1559 }
1560
1561 // First level, check id
1562 if (!$level) {
1563
1564 // Find mount point if any:
1565 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($id);
1566
1567 // Overlay mode:
1568 if (is_array($mount_info) && $mount_info['overlay']) {
1569 $MP_array[] = $mount_info['MPvar'];
1570 $id = $mount_info['mount_pid'];
1571 }
1572
1573 // Set mapping information for this level:
1574 $this->MPmap[$id] = $MP_array;
1575
1576 // Normal mode:
1577 if (is_array($mount_info) && !$mount_info['overlay']) {
1578 $MP_array[] = $mount_info['MPvar'];
1579 $id = $mount_info['mount_pid'];
1580 }
1581 }
1582
1583 if ($id && $level < 20) {
1584
1585 $nextLevelAcc = array();
1586
1587 // Select and traverse current level pages:
1588 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1589 'uid,pid,doktype,mount_pid,mount_pid_ol',
1590 'pages',
1591 'pid=' . intval($id) . ' AND deleted=0 AND doktype!=' . t3lib_pageSelect::DOKTYPE_RECYCLER .
1592 ' AND doktype!=' . t3lib_pageSelect::DOKTYPE_BE_USER_SECTION
1593 );
1594 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1595
1596 // Find mount point if any:
1597 $next_id = $row['uid'];
1598 $next_MP_array = $MP_array;
1599 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
1600
1601 // Overlay mode:
1602 if (is_array($mount_info) && $mount_info['overlay']) {
1603 $next_MP_array[] = $mount_info['MPvar'];
1604 $next_id = $mount_info['mount_pid'];
1605 }
1606
1607 if (!isset($this->MPmap[$next_id])) {
1608
1609 // Set mapping information for this level:
1610 $this->MPmap[$next_id] = $next_MP_array;
1611
1612 // Normal mode:
1613 if (is_array($mount_info) && !$mount_info['overlay']) {
1614 $next_MP_array[] = $mount_info['MPvar'];
1615 $next_id = $mount_info['mount_pid'];
1616 }
1617
1618 // Register recursive call
1619 // (have to do it this way since ALL of the current level should be registered BEFORE the sublevel at any time)
1620 $nextLevelAcc[] = array($next_id, $next_MP_array);
1621 }
1622 }
1623
1624 // Call recursively, if any:
1625 foreach ($nextLevelAcc as $pSet) {
1626 $this->initMPmap_create($pSet[0], $pSet[1], $level + 1);
1627 }
1628 }
1629 }
1630 }
1631
1632
1633 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php'])) {
1634 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
1635 }
1636
1637 ?>