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