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