707c516234fe95ff267e32013803307a8f924b11
[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\Cache\CacheManager;
18 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
19 use TYPO3\CMS\Core\Context\Context;
20 use TYPO3\CMS\Core\Context\TypoScriptAspect;
21 use TYPO3\CMS\Core\Database\Connection;
22 use TYPO3\CMS\Core\Database\ConnectionPool;
23 use TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer;
24 use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
25 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
26 use TYPO3\CMS\Core\Domain\Repository\PageRepository;
27 use TYPO3\CMS\Core\Package\PackageManager;
28 use TYPO3\CMS\Core\Site\Entity\Site;
29 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
30 use TYPO3\CMS\Core\Utility\ArrayUtility;
31 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
34 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
35
36 /**
37 * Template object that is responsible for generating the TypoScript template based on template records.
38 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
39 * @see \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher
40 */
41 class TemplateService
42 {
43 use PublicPropertyDeprecationTrait;
44
45 private $deprecatedPublicProperties = [
46 'forceTemplateParsing' => 'Using tmpl->forceTemplateParsing is deprecated and will no longer work with TYPO3 v11.0. Use TypoScriptAspect from Context instead.'
47 ];
48
49 /**
50 * option to enable logging, time-tracking (FE-only)
51 * usually, this is only done when
52 * - in FE a BE_USER is logged-in
53 * - in BE when the BE_USER needs information about the template (TypoScript module)
54 * @var bool
55 */
56 protected $verbose = false;
57
58 /**
59 * If set, the global tt-timeobject is used to log the performance.
60 *
61 * @var bool
62 */
63 public $tt_track = true;
64
65 /**
66 * If set, the template is always rendered. Used from Admin Panel.
67 *
68 * @var bool
69 * @deprecated
70 */
71 private $forceTemplateParsing = false;
72
73 /**
74 * This array is passed on to matchObj by generateConfig().
75 * If it holds elements, they are used for matching instead. See comment at the match-class.
76 * Used for backend modules only. Never frontend!
77 *
78 * @var array
79 * @internal
80 */
81 public $matchAlternative = [];
82
83 /**
84 * If set, the match-class matches everything! Used for backend modules only. Never frontend!
85 *
86 * @var bool
87 */
88 protected $matchAll = false;
89
90 /**
91 * Externally set breakpoints (used by Backend Modules)
92 *
93 * @var int
94 */
95 public $ext_constants_BRP = 0;
96
97 /**
98 * @var int
99 */
100 public $ext_config_BRP = 0;
101
102 /**
103 * @var bool
104 */
105 public $ext_regLinenumbers = false;
106
107 /**
108 * @var bool
109 */
110 public $ext_regComments = false;
111
112 /**
113 * Set if preview of some kind is enabled.
114 *
115 * @var bool
116 */
117 protected $simulationHiddenOrTime = false;
118
119 /**
120 * Set, if the TypoScript template structure is loaded and OK, see ->start()
121 *
122 * @var bool
123 */
124 public $loaded = false;
125
126 /**
127 * @var array Contains TypoScript setup part after parsing
128 */
129 public $setup = [];
130
131 /**
132 * @var array
133 */
134 public $flatSetup = [];
135
136 /**
137 * For fetching TypoScript code from template hierarchy before parsing it.
138 * Each array contains code field values from template records/files:
139 * Setup field
140 *
141 * @var array
142 */
143 public $config = [];
144
145 /**
146 * Constant field
147 *
148 * @var array
149 */
150 public $constants = [];
151
152 /**
153 * Holds the include paths of the templates (empty if from database)
154 *
155 * @var array
156 */
157 protected $templateIncludePaths = [];
158
159 /**
160 * For Template Analyzer in backend
161 *
162 * @var array
163 */
164 public $hierarchyInfo = [];
165
166 /**
167 * For Template Analyzer in backend (setup content only)
168 *
169 * @var array
170 */
171 protected $hierarchyInfoToRoot = [];
172
173 /**
174 * The Page UID of the root page
175 *
176 * @var int
177 */
178 protected $rootId;
179
180 /**
181 * The rootline from current page to the root page
182 *
183 * @var array
184 */
185 public $rootLine;
186
187 /**
188 * Rootline all the way to the root. Set but runThroughTemplates
189 *
190 * @var array
191 */
192 protected $absoluteRootLine;
193
194 /**
195 * Array of arrays with title/uid of templates in hierarchy
196 *
197 * @var array
198 */
199 protected $rowSum;
200
201 /**
202 * The current site title field.
203 *
204 * @var string
205 */
206 protected $sitetitle = '';
207
208 /**
209 * Tracking all conditions found during parsing of TypoScript. Used for the "all" key in currentPageData
210 *
211 * @var array|null
212 */
213 public $sections;
214
215 /**
216 * Tracking all matching conditions found
217 *
218 * @var array
219 */
220 protected $sectionsMatch;
221
222 /**
223 * Used by Backend only (Typoscript Template Analyzer)
224 */
225 public $clearList_const = [];
226
227 /**
228 * Used by Backend only (Typoscript Template Analyzer)
229 *
230 * @var array
231 */
232 public $clearList_setup = [];
233
234 /**
235 * @var array
236 */
237 public $parserErrors = [];
238
239 /**
240 * @var array
241 */
242 public $setup_constants = [];
243
244 /**
245 * Indicator that extension statics are processed.
246 *
247 * These files are considered if either a root template
248 * has been processed or the $processExtensionStatics
249 * property has been set to TRUE.
250 *
251 * @var bool
252 */
253 protected $extensionStaticsProcessed = false;
254
255 /**
256 * Trigger value, to ensure that extension statics are processed.
257 *
258 * @var bool
259 */
260 protected $processExtensionStatics = false;
261
262 /**
263 * Set to TRUE after the default TypoScript was added during parsing.
264 * This prevents double inclusion of the same TypoScript code.
265 *
266 * @see addDefaultTypoScript()
267 * @var bool
268 */
269 protected $isDefaultTypoScriptAdded = false;
270
271 /**
272 * Set to TRUE after $this->config and $this->constants have processed all <INCLUDE_TYPOSCRIPT:> instructions.
273 *
274 * This prevents double processing of INCLUDES.
275 *
276 * @see processIncludes()
277 * @var bool
278 */
279 protected $processIncludesHasBeenRun = false;
280
281 /**
282 * Contains the restrictions about deleted, and some frontend related topics
283 * @var AbstractRestrictionContainer
284 */
285 protected $queryBuilderRestrictions;
286
287 /**
288 * @var Context
289 */
290 protected $context;
291
292 /**
293 * @var PackageManager
294 */
295 protected $packageManager;
296
297 /**
298 * @var Site|null
299 */
300 protected $site;
301
302 /**
303 * @param Context|null $context
304 * @param PackageManager|null $packageManager
305 * @param Site|null $site
306 */
307 public function __construct(Context $context = null, PackageManager $packageManager = null, Site $site = null)
308 {
309 $this->context = $context ?? GeneralUtility::makeInstance(Context::class);
310 $this->packageManager = $packageManager ?? GeneralUtility::makeInstance(PackageManager::class);
311 $this->initializeDatabaseQueryRestrictions();
312 if ($this->context->getPropertyFromAspect('visibility', 'includeHiddenContent', false) || $GLOBALS['SIM_ACCESS_TIME'] !== $GLOBALS['ACCESS_TIME']) {
313 // Set the simulation flag, if simulation is detected!
314 $this->simulationHiddenOrTime = true;
315 }
316 $this->tt_track = $this->verbose = (bool)$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false);
317 $this->site = $site ?? (isset($GLOBALS['TYPO3_REQUEST']) ? $GLOBALS['TYPO3_REQUEST']->getAttribute('site', null) : null);
318 }
319
320 /**
321 * @return bool
322 */
323 public function getProcessExtensionStatics()
324 {
325 return $this->processExtensionStatics;
326 }
327
328 /**
329 * @param bool $processExtensionStatics
330 */
331 public function setProcessExtensionStatics($processExtensionStatics)
332 {
333 $this->processExtensionStatics = (bool)$processExtensionStatics;
334 }
335
336 /**
337 * sets the verbose parameter
338 * @param bool $verbose
339 */
340 public function setVerbose($verbose)
341 {
342 $this->verbose = (bool)$verbose;
343 }
344
345 /**
346 * Set up the query builder restrictions, optionally include hidden records
347 */
348 protected function initializeDatabaseQueryRestrictions()
349 {
350 $this->queryBuilderRestrictions = GeneralUtility::makeInstance(DefaultRestrictionContainer::class);
351
352 if ($this->context->getPropertyFromAspect('visibility', 'includeHiddenContent', false)) {
353 $this->queryBuilderRestrictions->removeByType(HiddenRestriction::class);
354 }
355 }
356
357 /**
358 * Fetches the "currentPageData" array from cache
359 *
360 * NOTE about currentPageData:
361 * It holds information about the TypoScript conditions along with the list
362 * of template uid's which is used on the page. In the getFromCache() function
363 * in TSFE, currentPageData is used to evaluate if there is a template and
364 * if the matching conditions are alright. Unfortunately this does not take
365 * into account if the templates in the rowSum of currentPageData has
366 * changed composition, eg. due to hidden fields or start/end time. So if a
367 * template is hidden or times out, it'll not be discovered unless the page
368 * is regenerated - at least the this->start function must be called,
369 * because this will make a new portion of data in currentPageData string.
370 *
371 * @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
372 * @internal
373 */
374 public function getCurrentPageData()
375 {
376 return GeneralUtility::makeInstance(CacheManager::class)->getCache('pagesection')->get((int)$this->getTypoScriptFrontendController()->id . '_' . GeneralUtility::md5int($this->getTypoScriptFrontendController()->MP));
377 }
378
379 /**
380 * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
381 *
382 * @param array $cc An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array
383 * @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.
384 */
385 public function matching($cc)
386 {
387 if (is_array($cc['all'])) {
388 /** @var ConditionMatcher $matchObj */
389 $matchObj = GeneralUtility::makeInstance(ConditionMatcher::class);
390 $matchObj->setRootline((array)$cc['rootLine']);
391 $sectionsMatch = [];
392 foreach ($cc['all'] as $key => $pre) {
393 if ($matchObj->match($pre)) {
394 $sectionsMatch[$key] = $pre;
395 }
396 }
397 $cc['match'] = $sectionsMatch;
398 }
399 return $cc;
400 }
401
402 /**
403 * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
404 * 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.
405 * Sets $this->setup to the parsed TypoScript template array
406 *
407 * @param array $theRootLine The rootline of the current page (going ALL the way to tree root)
408 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getConfigArray()
409 */
410 public function start($theRootLine)
411 {
412 // @deprecated - can be removed with TYPO3 v11.0
413 if ((bool)$this->forceTemplateParsing) {
414 $this->context->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true));
415 }
416 if (is_array($theRootLine)) {
417 $constantsData = [];
418 $setupData = [];
419 $cacheIdentifier = '';
420 // Flag that indicates that the existing data in cache_pagesection
421 // could be used (this is the case if $TSFE->all is set, and the
422 // rowSum still matches). Based on this we decide if cache_pagesection
423 // needs to be updated...
424 $isCached = false;
425 $this->runThroughTemplates($theRootLine);
426 if ($this->getTypoScriptFrontendController()->all) {
427 $cc = $this->getTypoScriptFrontendController()->all;
428 // The two rowSums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
429 if (serialize($this->rowSum) !== serialize($cc['rowSum'])) {
430 unset($cc);
431 } else {
432 // If $TSFE->all contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already)
433 if (serialize($this->rootLine) === serialize($cc['rootLine'])) {
434 $isCached = true;
435 }
436 // 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)...
437 unset($cc['rootLine']);
438 }
439 }
440 // This is about getting the hash string which is used to fetch the cached TypoScript template.
441 // If there was some cached currentPageData ($cc) then that's good (it gives us the hash).
442 if (isset($cc) && is_array($cc)) {
443 // If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...)
444 if (!$cc['match']) {
445 // @todo check if this can ever be the case - otherwise remove
446 $cc = $this->matching($cc);
447 ksort($cc);
448 }
449 $cacheIdentifier = md5(serialize($cc));
450 } else {
451 // 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.
452 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
453 $result = $this->getCacheEntry($rowSumHash);
454 if (is_array($result)) {
455 $cc = [];
456 $cc['all'] = $result;
457 $cc['rowSum'] = $this->rowSum;
458 $cc = $this->matching($cc);
459 ksort($cc);
460 $cacheIdentifier = md5(serialize($cc));
461 }
462 }
463 if ($cacheIdentifier) {
464 // Get TypoScript setup array
465 $cachedData = $this->getCacheEntry($cacheIdentifier);
466 if (is_array($cachedData)) {
467 $constantsData = $cachedData['constants'];
468 $setupData = $cachedData['setup'];
469 }
470 }
471 if (!empty($setupData) && !$this->context->getPropertyFromAspect('typoscript', 'forcedTemplateParsing')) {
472 // TypoScript constants + setup are found in the cache
473 $this->setup_constants = $constantsData;
474 $this->setup = $setupData;
475 if ($this->tt_track) {
476 $this->getTimeTracker()->setTSlogMessage('Using cached TS template data');
477 }
478 } else {
479 if ($this->tt_track) {
480 $this->getTimeTracker()->setTSlogMessage('Not using any cached TS data');
481 }
482
483 // Make configuration
484 $this->generateConfig();
485 // This stores the template hash thing
486 $cc = [];
487 // All sections in the template at this point is found
488 $cc['all'] = $this->sections;
489 // The line of templates is collected
490 $cc['rowSum'] = $this->rowSum;
491 $cc = $this->matching($cc);
492 ksort($cc);
493 $cacheIdentifier = md5(serialize($cc));
494 // This stores the data.
495 $this->setCacheEntry($cacheIdentifier, ['constants' => $this->setup_constants, 'setup' => $this->setup], 'TS_TEMPLATE');
496 if ($this->tt_track) {
497 $this->getTimeTracker()->setTSlogMessage('TS template size, serialized: ' . strlen(serialize($this->setup)) . ' bytes');
498 }
499 $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
500 $this->setCacheEntry($rowSumHash, $cc['all'], 'TMPL_CONDITIONS_ALL');
501 }
502 // Add rootLine
503 $cc['rootLine'] = $this->rootLine;
504 ksort($cc);
505 // Make global and save
506 $this->getTypoScriptFrontendController()->all = $cc;
507 // Matching must be executed for every request, so this must never be part of the pagesection cache!
508 unset($cc['match']);
509 if (!$isCached && !$this->simulationHiddenOrTime && !$this->getTypoScriptFrontendController()->no_cache) {
510 // Only save the data if we're not simulating by hidden/starttime/endtime
511 $mpvarHash = GeneralUtility::md5int($this->getTypoScriptFrontendController()->MP);
512 /** @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $pageSectionCache */
513 $pageSectionCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('pagesection');
514 $pageSectionCache->set((int)$this->getTypoScriptFrontendController()->id . '_' . $mpvarHash, $cc, [
515 'pageId_' . (int)$this->getTypoScriptFrontendController()->id,
516 'mpvarHash_' . $mpvarHash
517 ]);
518 }
519 // If everything OK.
520 if ($this->rootId && $this->rootLine && $this->setup) {
521 $this->loaded = true;
522 }
523 }
524 }
525
526 /*******************************************************************
527 *
528 * Fetching TypoScript code text for the Template Hierarchy
529 *
530 *******************************************************************/
531 /**
532 * 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.
533 * Resets and affects internal variables like $this->constants, $this->config and $this->rowSum
534 * 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
535 *
536 * @param array $theRootLine The rootline of the current page (going ALL the way to tree root)
537 * @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)
538 * @see start()
539 */
540 public function runThroughTemplates($theRootLine, $start_template_uid = 0)
541 {
542 $this->constants = [];
543 $this->config = [];
544 $this->rowSum = [];
545 $this->hierarchyInfoToRoot = [];
546 $this->absoluteRootLine = $theRootLine;
547 $this->isDefaultTypoScriptAdded = false;
548
549 reset($this->absoluteRootLine);
550 $c = count($this->absoluteRootLine);
551 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_template');
552 for ($a = 0; $a < $c; $a++) {
553 $where = [
554 $queryBuilder->expr()->eq(
555 'pid',
556 $queryBuilder->createNamedParameter($this->absoluteRootLine[$a]['uid'], \PDO::PARAM_INT)
557 )
558 ];
559 // If first loop AND there is set an alternative template uid, use that
560 if ($a === $c - 1 && $start_template_uid) {
561 $where[] = $queryBuilder->expr()->eq(
562 'uid',
563 $queryBuilder->createNamedParameter($start_template_uid, \PDO::PARAM_INT)
564 );
565 }
566 $queryBuilder->setRestrictions($this->queryBuilderRestrictions);
567 $queryResult = $queryBuilder
568 ->select('*')
569 ->from('sys_template')
570 ->where(...$where)
571 ->orderBy('root', 'DESC')
572 ->addOrderBy('sorting')
573 ->setMaxResults(1)
574 ->execute();
575 if ($row = $queryResult->fetch()) {
576 $this->versionOL($row);
577 if (is_array($row)) {
578 $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
579 }
580 }
581 $this->rootLine[] = $this->absoluteRootLine[$a];
582 }
583
584 // Hook into the default TypoScript to add custom typoscript logic
585 $hookParameters = [
586 'extensionStaticsProcessed' => &$this->extensionStaticsProcessed,
587 'isDefaultTypoScriptAdded' => &$this->isDefaultTypoScriptAdded,
588 'absoluteRootLine' => &$this->absoluteRootLine,
589 'rootLine' => &$this->rootLine,
590 'startTemplateUid' => $start_template_uid,
591 ];
592 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Core/TypoScript/TemplateService']['runThroughTemplatesPostProcessing'] ?? [] as $listener) {
593 GeneralUtility::callUserFunction($listener, $hookParameters, $this);
594 }
595
596 // Process extension static files if not done yet, but explicitly requested
597 if (!$this->extensionStaticsProcessed && $this->processExtensionStatics) {
598 $this->addExtensionStatics('sys_0', 'sys_0', 0);
599 }
600
601 // Add the global default TypoScript from the TYPO3_CONF_VARS
602 $this->addDefaultTypoScript();
603
604 $this->processIncludes();
605 }
606
607 /**
608 * Checks if the template ($row) has some included templates and after including them it fills the arrays with the setup
609 * Builds up $this->rowSum
610 *
611 * @param array $row A full TypoScript template record (sys_template/forged "dummy" record made from static template file)
612 * @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, 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.
613 * @param int $pid The PID of the input template record
614 * @param string $templateID The id of the current template. Same syntax as $idList ids, eg. "sys_123
615 * @param string $templateParent Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123
616 * @param string $includePath Specifies the path from which the template was included (used with static_includes)
617 * @see runThroughTemplates()
618 */
619 public function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '', $includePath = '')
620 {
621 // Adding basic template record information to rowSum array
622 $this->rowSum[] = [$row['uid'] ?? null, $row['title'] ?? null, $row['tstamp'] ?? null];
623 // Processing "Clear"-flags
624 $clConst = 0;
625 $clConf = 0;
626 if (!empty($row['clear'])) {
627 $clConst = $row['clear'] & 1;
628 $clConf = $row['clear'] & 2;
629 if ($clConst) {
630 // Keep amount of items to stay in sync with $this->templateIncludePaths so processIncludes() does not break
631 foreach ($this->constants as &$constantConfiguration) {
632 $constantConfiguration = '';
633 }
634 unset($constantConfiguration);
635 $this->clearList_const = [];
636 }
637 if ($clConf) {
638 // Keep amount of items to stay in sync with $this->templateIncludePaths so processIncludes() does not break
639 foreach ($this->config as &$configConfiguration) {
640 $configConfiguration = '';
641 }
642 unset($configConfiguration);
643 $this->hierarchyInfoToRoot = [];
644 $this->clearList_setup = [];
645 }
646 }
647 // Include files (from extensions) (#1/2)
648 // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
649 if (!isset($row['includeStaticAfterBasedOn']) || !$row['includeStaticAfterBasedOn']) {
650 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
651 }
652 // Include "Based On" sys_templates:
653 // 'basedOn' is a list of templates to include
654 if (trim($row['basedOn'] ?? '')) {
655 // Normal Operation, which is to include the "based-on" sys_templates,
656 // if they are not already included, and maintaining the sorting of the templates
657 $basedOnIds = GeneralUtility::intExplode(',', $row['basedOn'], true);
658 // skip template if it's already included
659 foreach ($basedOnIds as $key => $basedOnId) {
660 if (GeneralUtility::inList($idList, 'sys_' . $basedOnId)) {
661 unset($basedOnIds[$key]);
662 }
663 }
664 if (!empty($basedOnIds)) {
665 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_template');
666 $queryBuilder->setRestrictions($this->queryBuilderRestrictions);
667 $queryResult = $queryBuilder
668 ->select('*')
669 ->from('sys_template')
670 ->where(
671 $queryBuilder->expr()->in(
672 'uid',
673 $queryBuilder->createNamedParameter($basedOnIds, Connection::PARAM_INT_ARRAY)
674 )
675 )
676 ->execute();
677 // make it an associative array with the UID as key
678 $subTemplates = [];
679 while ($rowItem = $queryResult->fetch()) {
680 $subTemplates[(int)$rowItem['uid']] = $rowItem;
681 }
682 // Traversing list again to ensure the sorting of the templates
683 foreach ($basedOnIds as $id) {
684 if (is_array($subTemplates[$id])) {
685 $this->versionOL($subTemplates[$id]);
686 $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
687 }
688 }
689 }
690 }
691 // Include files (from extensions) (#2/2)
692 if (!empty($row['includeStaticAfterBasedOn'])) {
693 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
694 }
695 // Creating hierarchy information; Used by backend analysis tools
696 $this->hierarchyInfo[] = ($this->hierarchyInfoToRoot[] = [
697 'root' => trim($row['root'] ?? ''),
698 'clConst' => $clConst,
699 'clConf' => $clConf,
700 'templateID' => $templateID,
701 'templateParent' => $templateParent,
702 'title' => $row['title'],
703 'uid' => $row['uid'],
704 'pid' => $row['pid'] ?? null,
705 'configLines' => substr_count($row['config'], LF) + 1
706 ]);
707 // Adding the content of the fields constants (Constants) and config (Setup)
708 $this->constants[] = $row['constants'];
709 $this->config[] = $row['config'];
710 $this->templateIncludePaths[] = $includePath;
711 // For backend analysis (Template Analyzer) provide the order of added constants/config template IDs
712 $this->clearList_const[] = $templateID;
713 $this->clearList_setup[] = $templateID;
714 if (trim($row['sitetitle'] ?? null)) {
715 $this->sitetitle = $row['sitetitle'];
716 }
717 // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
718 if (trim($row['root'] ?? null)) {
719 $this->rootId = $pid;
720 $this->rootLine = [];
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 * @throws \RuntimeException If the given $fullRootLine does not contain all pages that are in the current template rootline
733 */
734 public function updateRootlineData($fullRootLine)
735 {
736 if (!is_array($this->rootLine) || empty($this->rootLine)) {
737 return;
738 }
739
740 $fullRootLineByUid = [];
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 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 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 int $pid The PID of the input template record
762 * @param array $row A full TypoScript template record
763 * @see processTemplate()
764 * @internal
765 */
766 public function includeStaticTypoScriptSources($idList, $templateID, $pid, $row)
767 {
768 // Call function for link rendering:
769 $_params = [
770 'idList' => &$idList,
771 'templateId' => &$templateID,
772 'pid' => &$pid,
773 'row' => &$row
774 ];
775 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] ?? [] as $_funcRef) {
776 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
777 }
778 // If "Include before all static templates if root-flag is set" is set:
779 $staticFileMode = $row['static_file_mode'] ?? null;
780 if ($staticFileMode == 3 && strpos($templateID, 'sys_') === 0 && $row['root']) {
781 $this->addExtensionStatics($idList, $templateID, $pid);
782 }
783 // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
784 if (trim($row['include_static_file'] ?? '')) {
785 $include_static_fileArr = GeneralUtility::trimExplode(',', $row['include_static_file'], true);
786 // Traversing list
787 foreach ($include_static_fileArr as $ISF_file) {
788 if (strpos($ISF_file, 'EXT:') === 0) {
789 list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2);
790 if ((string)$ISF_extKey !== '' && ExtensionManagementUtility::isLoaded($ISF_extKey) && (string)$ISF_localPath !== '') {
791 $ISF_localPath = rtrim($ISF_localPath, '/') . '/';
792 $ISF_filePath = ExtensionManagementUtility::extPath($ISF_extKey) . $ISF_localPath;
793 if (@is_dir($ISF_filePath)) {
794 $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
795 $subrow = [
796 'constants' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'constants'),
797 'config' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'setup'),
798 'include_static' => @file_exists($ISF_filePath . 'include_static.txt') ? implode(',', array_unique(GeneralUtility::intExplode(',', file_get_contents($ISF_filePath . 'include_static.txt')))) : '',
799 'include_static_file' => @file_exists($ISF_filePath . 'include_static_file.txt') ? implode(',', array_unique(explode(',', file_get_contents($ISF_filePath . 'include_static_file.txt')))) : '',
800 'title' => $ISF_file,
801 'uid' => $mExtKey
802 ];
803 $subrow = $this->prependStaticExtra($subrow);
804 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID, $ISF_filePath);
805 }
806 }
807 }
808 }
809 }
810 // If "Default (include before if root flag is set)" is set OR
811 // "Always include before this template record" AND root-flag are set
812 if ($staticFileMode == 1 || $staticFileMode == 0 && strpos($templateID, 'sys_') === 0 && $row['root']) {
813 $this->addExtensionStatics($idList, $templateID, $pid);
814 }
815 // Include Static Template Records after all other TypoScript has been included.
816 $_params = [
817 'idList' => &$idList,
818 'templateId' => &$templateID,
819 'pid' => &$pid,
820 'row' => &$row
821 ];
822 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] ?? [] as $_funcRef) {
823 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
824 }
825 }
826
827 /**
828 * Retrieves the content of the first existing file by extension order.
829 * Returns the empty string if no file is found.
830 *
831 * @param string $filePath The location of the file.
832 * @param string $baseName The base file name. "constants" or "setup".
833 * @return string
834 */
835 protected function getTypoScriptSourceFileContent($filePath, $baseName)
836 {
837 $extensions = ['.typoscript', '.ts', '.txt'];
838 foreach ($extensions as $extension) {
839 $fileName = $filePath . $baseName . $extension;
840 if (@file_exists($fileName)) {
841 return file_get_contents($fileName);
842 }
843 }
844 return '';
845 }
846
847 /**
848 * Adds the default TypoScript files for extensions if any.
849 *
850 * @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 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.
851 * @param string $templateID The id of the current template. Same syntax as $idList ids, eg. "sys_123
852 * @param int $pid The PID of the input template record
853 * @internal
854 * @see includeStaticTypoScriptSources()
855 */
856 public function addExtensionStatics($idList, $templateID, $pid)
857 {
858 $this->extensionStaticsProcessed = true;
859
860 foreach ($this->packageManager->getActivePackages() as $package) {
861 $extKey = $package->getPackageKey();
862 $packagePath = $package->getPackagePath();
863 $filesToCheck = [
864 'ext_typoscript_constants.txt',
865 'ext_typoscript_constants.typoscript',
866 'ext_typoscript_setup.txt',
867 'ext_typoscript_setup.typoscript',
868 ];
869 $files = [];
870 $hasExtensionStatics = false;
871 foreach ($filesToCheck as $file) {
872 $path = $packagePath . $file;
873 if (@file_exists($path)) {
874 $files[$file] = $path;
875 $hasExtensionStatics = true;
876 } else {
877 $files[$file] = null;
878 }
879 }
880
881 if ($hasExtensionStatics) {
882 $mExtKey = str_replace('_', '', $extKey);
883 $constants = '';
884 $config = '';
885
886 if (!empty($files['ext_typoscript_constants.typoscript'])) {
887 $constants = @file_get_contents($files['ext_typoscript_constants.typoscript']);
888 } elseif (!empty($files['ext_typoscript_constants.txt'])) {
889 $constants = @file_get_contents($files['ext_typoscript_constants.txt']);
890 }
891
892 if (!empty($files['ext_typoscript_setup.typoscript'])) {
893 $config = @file_get_contents($files['ext_typoscript_setup.typoscript']);
894 } elseif (!empty($files['ext_typoscript_setup.txt'])) {
895 $config = @file_get_contents($files['ext_typoscript_setup.txt']);
896 }
897
898 $this->processTemplate(
899 $this->prependStaticExtra([
900 'constants' => $constants,
901 'config' => $config,
902 'title' => $extKey,
903 'uid' => $mExtKey
904 ]),
905 $idList . ',ext_' . $mExtKey,
906 $pid,
907 'ext_' . $mExtKey,
908 $templateID,
909 $packagePath
910 );
911 }
912 }
913 }
914
915 /**
916 * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS
917 * 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
918 *
919 * @param array $subrow Static template record/file
920 * @return array Returns the input array where the values for keys "config" and "constants" may have been modified with prepended code.
921 * @see addExtensionStatics()
922 * @see includeStaticTypoScriptSources()
923 */
924 protected function prependStaticExtra($subrow)
925 {
926 // the identifier can be "43" if coming from "static template" extension or a path like "cssstyledcontent/static/"
927 $identifier = $subrow['uid'];
928 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$identifier] ?? null;
929 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$identifier] ?? null;
930 // 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
931 if (in_array($identifier, $GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'], true)) {
932 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
933 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.']['defaultContentRendering'];
934 }
935 return $subrow;
936 }
937
938 /**
939 * Creating versioning overlay of a sys_template record.
940 *
941 * @param array $row Row to overlay (passed by reference)
942 */
943 protected function versionOL(&$row)
944 {
945 if ($this->context->getPropertyFromAspect('workspace', 'isOffline')) {
946 $pageRepository = GeneralUtility::makeInstance(PageRepository::class, $this->context);
947 $pageRepository->versionOL('sys_template', $row);
948 }
949 }
950
951 /*******************************************************************
952 *
953 * Parsing TypoScript code text from Template Records into PHP array
954 *
955 *******************************************************************/
956 /**
957 * Generates the configuration array by replacing constants and parsing the whole thing.
958 * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates)
959 *
960 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
961 * @see start()
962 */
963 public function generateConfig()
964 {
965 // Add default TS for all code types
966 $this->addDefaultTypoScript();
967
968 // Parse the TypoScript code text for include-instructions!
969 $this->processIncludes();
970 // These vars are also set lateron...
971 $this->setup['sitetitle'] = $this->sitetitle;
972 // ****************************
973 // Parse TypoScript Constants
974 // ****************************
975 // Initialize parser and match-condition classes:
976 /** @var Parser\TypoScriptParser $constants */
977 $constants = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
978 $constants->breakPointLN = (int)$this->ext_constants_BRP;
979 /** @var ConditionMatcher $matchObj */
980 $matchObj = GeneralUtility::makeInstance(ConditionMatcher::class);
981 $matchObj->setSimulateMatchConditions($this->matchAlternative);
982 $matchObj->setSimulateMatchResult((bool)$this->matchAll);
983 // Traverse constants text fields and parse them
984 foreach ($this->constants as $str) {
985 $constants->parse($str, $matchObj);
986 }
987 // Read out parse errors if any
988 $this->parserErrors['constants'] = $constants->errors;
989 // 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)
990 $this->flatSetup = ArrayUtility::flatten($constants->setup, '', true);
991 // ***********************************************
992 // Parse TypoScript Setup (here called "config")
993 // ***********************************************
994 // Initialize parser and match-condition classes:
995 /** @var Parser\TypoScriptParser $config */
996 $config = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
997 $config->breakPointLN = (int)$this->ext_config_BRP;
998 $config->regLinenumbers = $this->ext_regLinenumbers;
999 $config->regComments = $this->ext_regComments;
1000 $config->setup = $this->setup;
1001 // Transfer information about conditions found in "Constants" and which of them returned TRUE.
1002 $config->sections = $constants->sections;
1003 $config->sectionsMatch = $constants->sectionsMatch;
1004 // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition
1005 $all = '';
1006 foreach ($this->config as $str) {
1007 $all .= '
1008 [GLOBAL]
1009 ' . $str;
1010 }
1011 // Substitute constants in the Setup code:
1012 if ($this->tt_track) {
1013 $this->getTimeTracker()->push('Substitute Constants (' . count($this->flatSetup) . ')');
1014 }
1015 $all = $this->substituteConstants($all);
1016 if ($this->tt_track) {
1017 $this->getTimeTracker()->pull();
1018 }
1019
1020 // Searching for possible unsubstituted constants left (only for information)
1021 if ($this->verbose) {
1022 if (preg_match_all('/\\{\\$.[^}]*\\}/', $all, $constantList) > 0) {
1023 if ($this->tt_track) {
1024 $this->getTimeTracker()->setTSlogMessage(implode(', ', $constantList[0]) . ': Constants may remain un-substituted!!', 2);
1025 }
1026 }
1027 }
1028
1029 // Logging the textual size of the TypoScript Setup field text with all constants substituted:
1030 if ($this->tt_track) {
1031 $this->getTimeTracker()->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes');
1032 }
1033 // Finally parse the Setup field TypoScript code (where constants are now substituted)
1034 $config->parse($all, $matchObj);
1035 // Read out parse errors if any
1036 $this->parserErrors['config'] = $config->errors;
1037 // Transfer the TypoScript array from the parser object to the internal $this->setup array:
1038 $this->setup = $config->setup;
1039 // Do the same for the constants
1040 $this->setup_constants = $constants->setup;
1041 // ****************************************************************
1042 // Final processing of the $this->setup TypoScript Template array
1043 // Basically: This is unsetting/setting of certain reserved keys.
1044 // ****************************************************************
1045 // These vars are already 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!
1046 unset($this->setup['sitetitle']);
1047 unset($this->setup['sitetitle.']);
1048 $this->setup['sitetitle'] = $this->sitetitle;
1049 // Unsetting some vars...
1050 unset($this->setup['types.']);
1051 unset($this->setup['types']);
1052 if (is_array($this->setup)) {
1053 foreach ($this->setup as $key => $value) {
1054 if ($value === 'PAGE') {
1055 // Set the typeNum of the current page object:
1056 if (isset($this->setup[$key . '.']['typeNum'])) {
1057 $typeNum = $this->setup[$key . '.']['typeNum'];
1058 $this->setup['types.'][$typeNum] = $key;
1059 } elseif (!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) {
1060 $this->setup['types.'][0] = $key;
1061 }
1062 }
1063 }
1064 }
1065 unset($this->setup['temp.']);
1066 unset($constants);
1067 // Storing the conditions found/matched information:
1068 $this->sections = $config->sections;
1069 $this->sectionsMatch = $config->sectionsMatch;
1070 }
1071
1072 /**
1073 * Searching TypoScript code text (for constants and config (Setup))
1074 * for include instructions and does the inclusion of external TypoScript files
1075 * if needed.
1076 *
1077 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
1078 * @see generateConfig()
1079 */
1080 protected function processIncludes()
1081 {
1082 if ($this->processIncludesHasBeenRun) {
1083 return;
1084 }
1085
1086 $paths = $this->templateIncludePaths;
1087 $files = [[]];
1088 foreach ($this->constants as &$value) {
1089 $includeData = Parser\TypoScriptParser::checkIncludeLines($value, 1, true, array_shift($paths));
1090 $files[] = $includeData['files'];
1091 $value = $includeData['typoscript'];
1092 }
1093 unset($value);
1094 $paths = $this->templateIncludePaths;
1095 foreach ($this->config as &$value) {
1096 $includeData = Parser\TypoScriptParser::checkIncludeLines($value, 1, true, array_shift($paths));
1097 $files[] = $includeData['files'];
1098 $value = $includeData['typoscript'];
1099 }
1100 unset($value);
1101
1102 $files = array_merge(...$files);
1103 if (!empty($files)) {
1104 $files = array_unique($files);
1105 foreach ($files as $file) {
1106 $this->rowSum[] = [$file, filemtime($file)];
1107 }
1108 }
1109
1110 $this->processIncludesHasBeenRun = true;
1111 }
1112
1113 /**
1114 * Substitutes the constants from $this->flatSetup in the text string $all
1115 *
1116 * @param string $all TypoScript code text string
1117 * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted.
1118 * @see generateConfig()
1119 */
1120 protected function substituteConstants($all)
1121 {
1122 if ($this->tt_track) {
1123 $this->getTimeTracker()->setTSlogMessage('Constants to substitute: ' . count($this->flatSetup));
1124 }
1125 $noChange = false;
1126 // Recursive substitution of constants (up to 10 nested levels)
1127 for ($i = 0; $i < 10 && !$noChange; $i++) {
1128 $old_all = $all;
1129 $all = preg_replace_callback('/\\{\\$(.[^}]*)\\}/', [$this, 'substituteConstantsCallBack'], $all);
1130 if ($old_all == $all) {
1131 $noChange = true;
1132 }
1133 }
1134 return $all;
1135 }
1136
1137 /**
1138 * Call back method for preg_replace_callback in substituteConstants
1139 *
1140 * @param array $matches Regular expression matches
1141 * @return string Replacement
1142 * @see substituteConstants()
1143 * @internal
1144 */
1145 public function substituteConstantsCallBack($matches)
1146 {
1147 // Replace {$CONST} if found in $this->flatSetup, else leave unchanged
1148 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
1149 }
1150
1151 /*******************************************************************
1152 *
1153 * Various API functions, used from elsewhere in the frontend classes
1154 *
1155 *******************************************************************/
1156
1157 /**
1158 * Returns the level of the given page in the rootline - Multiple pages can be given by separating the UIDs by comma.
1159 *
1160 * @param string $list A list of UIDs for which the rootline-level should get returned
1161 * @return int The level in the rootline. If more than one page was given the lowest level will get returned.
1162 */
1163 public function getRootlineLevel($list)
1164 {
1165 $idx = 0;
1166 foreach ($this->rootLine as $page) {
1167 if (GeneralUtility::inList($list, $page['uid'])) {
1168 return $idx;
1169 }
1170 $idx++;
1171 }
1172 return false;
1173 }
1174
1175 /**
1176 * Returns the page ID of the rootlevel
1177 *
1178 * @return int
1179 */
1180 public function getRootId(): int
1181 {
1182 return (int)$this->rootId;
1183 }
1184
1185 /*******************************************************************
1186 *
1187 * Functions for creating links
1188 *
1189 *******************************************************************/
1190
1191 /**
1192 * Adds the TypoScript from the global array.
1193 * The class property isDefaultTypoScriptAdded ensures
1194 * that the adding only happens once.
1195 *
1196 * @see isDefaultTypoScriptAdded
1197 */
1198 protected function addDefaultTypoScript()
1199 {
1200 // Add default TS for all code types, if not done already
1201 if (!$this->isDefaultTypoScriptAdded) {
1202 if ($this->site !== null) {
1203 $settingsLines = [];
1204 foreach (ArrayUtility::flatten($this->site->getSettings()) as $setting => $value) {
1205 $settingsLines[] = $setting . ' = ' . $value;
1206 }
1207 array_unshift($this->constants, implode("\n", $settingsLines));
1208 }
1209 // adding default setup and constants
1210 // defaultTypoScript_setup is *very* unlikely to be empty
1211 // the count of elements in ->constants, ->config and ->templateIncludePaths have to be in sync
1212 array_unshift($this->constants, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
1213 array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
1214 array_unshift($this->templateIncludePaths, '');
1215 // prepare a proper entry to hierachyInfo (used by TemplateAnalyzer in BE)
1216 $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo) - 1]['templateID'] ?? null;
1217 $defaultTemplateInfo = [
1218 'root' => '',
1219 'clConst' => '',
1220 'clConf' => '',
1221 'templateID' => '_defaultTypoScript_',
1222 'templateParent' => $rootTemplateId,
1223 'title' => 'SYS:TYPO3_CONF_VARS:FE:defaultTypoScript',
1224 'uid' => '_defaultTypoScript_',
1225 'pid' => '',
1226 'configLines' => substr_count((string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'], LF) + 1
1227 ];
1228 // push info to information arrays used in BE by TemplateTools (Analyzer)
1229 array_unshift($this->clearList_const, $defaultTemplateInfo['uid']);
1230 array_unshift($this->clearList_setup, $defaultTemplateInfo['uid']);
1231 array_unshift($this->hierarchyInfo, $defaultTemplateInfo);
1232 $this->isDefaultTypoScriptAdded = true;
1233 }
1234 }
1235
1236 /**
1237 * @return TypoScriptFrontendController
1238 */
1239 protected function getTypoScriptFrontendController()
1240 {
1241 return $GLOBALS['TSFE'];
1242 }
1243
1244 /**
1245 * @return TimeTracker
1246 */
1247 protected function getTimeTracker()
1248 {
1249 return GeneralUtility::makeInstance(TimeTracker::class);
1250 }
1251
1252 /**
1253 * Returns data stored for the hash string in the cache "cache_hash"
1254 * used to store the parsed TypoScript template structures.
1255 *
1256 * @param string $identifier The hash-string which was used to store the data value
1257 * @return mixed The data from the cache
1258 */
1259 protected function getCacheEntry($identifier)
1260 {
1261 return GeneralUtility::makeInstance(CacheManager::class)->getCache('hash')->get($identifier);
1262 }
1263
1264 /**
1265 * Stores $data in the 'hash' cache with the hash key $identifier
1266 *
1267 * @param string $identifier 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
1268 * @param mixed $data The data to store
1269 * @param string $tag Is just a textual identification in order to inform about the content
1270 */
1271 protected function setCacheEntry($identifier, $data, $tag)
1272 {
1273 GeneralUtility::makeInstance(CacheManager::class)->getCache('hash')->set($identifier, $data, ['ident_' . $tag], 0);
1274 }
1275 }