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