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