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