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