[BUGFIX] Fix SQL error on recursive TypoScript template inclusion
[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'], TRUE);
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 if (!empty($basedOnIds)) {
670 $subTemplates = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_template', 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause, '', '', '', 'uid');
671 // Traversing list again to ensure the sorting of the templates
672 foreach ($basedOnIds as $id) {
673 if (is_array($subTemplates[$id])) {
674 $this->versionOL($subTemplates[$id]);
675 $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
676 }
677 }
678 }
679 }
680 // Include static records (static_template) or files (from extensions) (#2/2)
681 if ($row['includeStaticAfterBasedOn']) {
682 $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
683 }
684 // Creating hierarchy information; Used by backend analysis tools
685 $this->hierarchyInfo[] = ($this->hierarchyInfoToRoot[] = array(
686 'root' => trim($row['root']),
687 'next' => $row['nextLevel'],
688 'clConst' => $clConst,
689 'clConf' => $clConf,
690 'templateID' => $templateID,
691 'templateParent' => $templateParent,
692 'title' => $row['title'],
693 'uid' => $row['uid'],
694 'pid' => $row['pid'],
695 'configLines' => substr_count($row['config'], LF) + 1
696 ));
697 // Adding the content of the fields constants (Constants) and config (Setup)
698 $this->constants[] = $row['constants'];
699 $this->config[] = $row['config'];
700 $this->templateIncludePaths[] = $includePath;
701 // For backend analysis (Template Analyser) provide the order of added constants/config template IDs
702 $this->clearList_const[] = $templateID;
703 $this->clearList_setup[] = $templateID;
704 if (trim($row['sitetitle'])) {
705 $this->sitetitle = $row['sitetitle'];
706 }
707 // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
708 if (trim($row['root'])) {
709 $this->rootId = $pid;
710 $this->rootLine = array();
711 }
712 // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
713 if ($row['nextLevel']) {
714 $this->nextLevel = $row['nextLevel'];
715 } else {
716 $this->nextLevel = 0;
717 }
718 }
719
720 /**
721 * This function can be used to update the data of the current rootLine
722 * e.g. when a different language is used.
723 *
724 * This function must not be used if there are different pages in the
725 * rootline as before!
726 *
727 * @param array $fullRootLine Array containing the FULL rootline (up to the TYPO3 root)
728 * @return void
729 * @throws \RuntimeException If the given $fullRootLine does not contain all pages that are in the current template rootline
730 */
731 public function updateRootlineData($fullRootLine) {
732 if (!is_array($this->rootLine) || count($this->rootLine) === 0) {
733 return;
734 }
735
736 $fullRootLineByUid = array();
737 foreach ($fullRootLine as $rootLineData) {
738 $fullRootLineByUid[$rootLineData['uid']] = $rootLineData;
739 }
740
741 foreach ($this->rootLine as $level => $dataArray) {
742 $currentUid = $dataArray['uid'];
743
744 if (!array_key_exists($currentUid, $fullRootLineByUid)) {
745 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);
746 }
747
748 $this->rootLine[$level] = $fullRootLineByUid[$currentUid];
749 }
750 }
751
752 /**
753 * Includes static template records (from static_template table, loaded through a hook) and static template files (from extensions) for the input template record row.
754 *
755 * @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.
756 * @param string $templateID The id of the current template. Same syntax as $idList ids, eg. "sys_123
757 * @param int $pid The PID of the input template record
758 * @param array $row A full TypoScript template record
759 * @return void
760 * @see processTemplate()
761 */
762 public function includeStaticTypoScriptSources($idList, $templateID, $pid, $row) {
763 // Static Template Records (static_template): include_static is a list of static templates to include
764 // Call function for link rendering:
765 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'])) {
766 $_params = array(
767 'idList' => &$idList,
768 'templateId' => &$templateID,
769 'pid' => &$pid,
770 'row' => &$row
771 );
772 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] as $_funcRef) {
773 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
774 }
775 }
776 // If "Include before all static templates if root-flag is set" is set:
777 if ($row['static_file_mode'] == 3 && substr($templateID, 0, 4) == 'sys_' && $row['root']) {
778 $this->addExtensionStatics($idList, $templateID, $pid, $row);
779 }
780 // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
781 if (trim($row['include_static_file'])) {
782 $include_static_fileArr = GeneralUtility::trimExplode(',', $row['include_static_file'], TRUE);
783 // Traversing list
784 foreach ($include_static_fileArr as $ISF_file) {
785 if (substr($ISF_file, 0, 4) == 'EXT:') {
786 list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2);
787 if ((string)$ISF_extKey !== '' && ExtensionManagementUtility::isLoaded($ISF_extKey) && (string)$ISF_localPath !== '') {
788 $ISF_localPath = rtrim($ISF_localPath, '/') . '/';
789 $ISF_filePath = ExtensionManagementUtility::extPath($ISF_extKey) . $ISF_localPath;
790 if (@is_dir($ISF_filePath)) {
791 $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
792 $subrow = array(
793 'constants' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'constants'),
794 'config' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'setup'),
795 'include_static' => @file_exists(($ISF_filePath . 'include_static.txt')) ? implode(',', array_unique(GeneralUtility::intExplode(',', GeneralUtility::getUrl($ISF_filePath . 'include_static.txt')))) : '',
796 'include_static_file' => @file_exists(($ISF_filePath . 'include_static_file.txt')) ? implode(',', array_unique(explode(',', GeneralUtility::getUrl($ISF_filePath . 'include_static_file.txt')))) : '',
797 'title' => $ISF_file,
798 'uid' => $mExtKey
799 );
800 $subrow = $this->prependStaticExtra($subrow);
801 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID, $ISF_filePath);
802 }
803 }
804 }
805 }
806 }
807 // If "Default (include before if root flag is set)" is set OR
808 // "Always include before this template record" AND root-flag are set
809 if ($row['static_file_mode'] == 1 || $row['static_file_mode'] == 0 && substr($templateID, 0, 4) == 'sys_' && $row['root']) {
810 $this->addExtensionStatics($idList, $templateID, $pid, $row);
811 }
812 // Include Static Template Records after all other TypoScript has been included.
813 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'])) {
814 $_params = array(
815 'idList' => &$idList,
816 'templateId' => &$templateID,
817 'pid' => &$pid,
818 'row' => &$row
819 );
820 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] as $_funcRef) {
821 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
822 }
823 }
824 }
825
826 /**
827 * Retrieves the content of the first existing file by extension order.
828 * Returns the empty string if no file is found.
829 *
830 * @param string $filePath The location of the file.
831 * @param string $baseName The base file name. "constants" or "setup".
832 * @return string
833 */
834 protected function getTypoScriptSourceFileContent($filePath, $baseName) {
835 $extensions = array('.ts', '.txt');
836 foreach ($extensions as $extension) {
837 $fileName = $filePath . $baseName . $extension;
838 if (@file_exists($fileName)) {
839 return GeneralUtility::getUrl($fileName);
840 }
841 }
842 return '';
843 }
844
845 /**
846 * Adds the default TypoScript files for extensions if any.
847 *
848 * @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.
849 * @param string $templateID The id of the current template. Same syntax as $idList ids, eg. "sys_123
850 * @param int $pid The PID of the input template record
851 * @param array $row A full TypoScript template record
852 * @return void
853 * @access private
854 * @see includeStaticTypoScriptSources()
855 */
856 public function addExtensionStatics($idList, $templateID, $pid, $row) {
857 $this->extensionStaticsProcessed = TRUE;
858
859 // @todo Change to use new API
860 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $files) {
861 if ((is_array($files) || $files instanceof \ArrayAccess) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'])) {
862 $mExtKey = str_replace('_', '', $extKey);
863 $subrow = array(
864 'constants' => $files['ext_typoscript_constants.txt'] ? GeneralUtility::getUrl($files['ext_typoscript_constants.txt']) : '',
865 'config' => $files['ext_typoscript_setup.txt'] ? GeneralUtility::getUrl($files['ext_typoscript_setup.txt']) : '',
866 'title' => $extKey,
867 'uid' => $mExtKey
868 );
869 $subrow = $this->prependStaticExtra($subrow);
870 $extPath = ExtensionManagementUtility::extPath($extKey);
871 $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID, $extPath);
872 }
873 }
874 }
875
876 /**
877 * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS
878 * For DB records the "uid" value is the integer of the "static_template" record.
879 * 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
880 *
881 * @param array $subrow Static template record/file
882 * @return array Returns the input array where the values for keys "config" and "constants" may have been modified with prepended code.
883 * @access private
884 * @see addExtensionStatics(), includeStaticTypoScriptSources()
885 */
886 public function prependStaticExtra($subrow) {
887 // the identifier can be "43" if coming from "static template" extension or a path like "cssstyledcontent/static/"
888 $identifier = $subrow['uid'];
889 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$identifier];
890 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$identifier];
891 // 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
892 if (in_array($identifier, $GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'], TRUE)) {
893 $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
894 $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.']['defaultContentRendering'];
895 }
896 return $subrow;
897 }
898
899 /**
900 * Creating versioning overlay of a sys_template record.
901 * This will use either frontend or backend overlay functionality depending on environment.
902 *
903 * @param array $row Row to overlay (passed by reference)
904 * @return void
905 */
906 public function versionOL(&$row) {
907 // Distinguish frontend and backend call:
908 // To do the fronted call a full frontend is required, just checking for
909 // TYPO3_MODE === 'FE' is not enough. This could otherwise lead to fatals in
910 // eId scripts that run in frontend scope, but do not have a full blown frontend.
911 if (is_object($this->getTypoScriptFrontendController()) && property_exists($this->getTypoScriptFrontendController(), 'sys_page') && method_exists($this->getTypoScriptFrontendController()->sys_page, 'versionOL')) {
912 // Frontend
913 $this->getTypoScriptFrontendController()->sys_page->versionOL('sys_template', $row);
914 } else {
915 // Backend
916 BackendUtility::workspaceOL('sys_template', $row);
917 }
918 }
919
920 /*******************************************************************
921 *
922 * Parsing TypoScript code text from Template Records into PHP array
923 *
924 *******************************************************************/
925 /**
926 * Generates the configuration array by replacing constants and parsing the whole thing.
927 * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates)
928 *
929 * @return void
930 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser, start()
931 */
932 public function generateConfig() {
933 // Add default TS for all code types
934 $this->addDefaultTypoScript();
935
936 // Parse the TypoScript code text for include-instructions!
937 $this->processIncludes();
938 // These vars are also set lateron...
939 $this->setup['sitetitle'] = $this->sitetitle;
940 // ****************************
941 // Parse TypoScript Constants
942 // ****************************
943 // Initialize parser and match-condition classes:
944 /** @var $constants Parser\TypoScriptParser */
945 $constants = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
946 $constants->breakPointLN = (int)$this->ext_constants_BRP;
947 $constants->setup = $this->mergeConstantsFromPageTSconfig(array());
948 /** @var $matchObj ConditionMatcher */
949 $matchObj = GeneralUtility::makeInstance(ConditionMatcher::class);
950 $matchObj->setSimulateMatchConditions($this->matchAlternative);
951 $matchObj->setSimulateMatchResult((bool)$this->matchAll);
952 // Traverse constants text fields and parse them
953 foreach ($this->constants as $str) {
954 $constants->parse($str, $matchObj);
955 }
956 // Read out parse errors if any
957 $this->parserErrors['constants'] = $constants->errors;
958 // 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)
959 $this->flatSetup = array();
960 $this->flattenSetup($constants->setup, '', '');
961 // ***********************************************
962 // Parse TypoScript Setup (here called "config")
963 // ***********************************************
964 // Initialize parser and match-condition classes:
965 /** @var $config Parser\TypoScriptParser */
966 $config = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
967 $config->breakPointLN = (int)$this->ext_config_BRP;
968 $config->regLinenumbers = $this->ext_regLinenumbers;
969 $config->regComments = $this->ext_regComments;
970 $config->setup = $this->setup;
971 // Transfer information about conditions found in "Constants" and which of them returned TRUE.
972 $config->sections = $constants->sections;
973 $config->sectionsMatch = $constants->sectionsMatch;
974 // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition
975 $all = '';
976 foreach ($this->config as $str) {
977 $all .= '
978 [GLOBAL]
979 ' . $str;
980 }
981 // Substitute constants in the Setup code:
982 if ($this->tt_track) {
983 $this->getTimeTracker()->push('Substitute Constants (' . count($this->flatSetup) . ')');
984 }
985 $all = $this->substituteConstants($all);
986 if ($this->tt_track) {
987 $this->getTimeTracker()->pull();
988 }
989
990 // Searching for possible unsubstituted constants left (only for information)
991 if ($this->verbose) {
992 if (strstr($all, '{$')) {
993 $theConstList = array();
994 $findConst = explode('{$', $all);
995 array_shift($findConst);
996 foreach ($findConst as $constVal) {
997 $constLen = MathUtility::forceIntegerInRange(strcspn($constVal, '}'), 0, 50);
998 $theConstList[] = '{$' . substr($constVal, 0, ($constLen + 1));
999 }
1000 if ($this->tt_track) {
1001 $this->getTimeTracker()->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2);
1002 }
1003 }
1004
1005 }
1006
1007 // Logging the textual size of the TypoScript Setup field text with all constants substituted:
1008 if ($this->tt_track) {
1009 $this->getTimeTracker()->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes');
1010 }
1011 // Finally parse the Setup field TypoScript code (where constants are now substituted)
1012 $config->parse($all, $matchObj);
1013 // Read out parse errors if any
1014 $this->parserErrors['config'] = $config->errors;
1015 // Transfer the TypoScript array from the parser object to the internal $this->setup array:
1016 $this->setup = $config->setup;
1017 if ($this->backend_info) {
1018 // Used for backend purposes only
1019 $this->setup_constants = $constants->setup;
1020 }
1021 // ****************************************************************
1022 // Final processing of the $this->setup TypoScript Template array
1023 // Basically: This is unsetting/setting of certain reserved keys.
1024 // ****************************************************************
1025 // 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!
1026 unset($this->setup['sitetitle']);
1027 unset($this->setup['sitetitle.']);
1028 $this->setup['sitetitle'] = $this->sitetitle;
1029 // Unsetting some vars...
1030 unset($this->setup['types.']);
1031 unset($this->setup['types']);
1032 if (is_array($this->setup)) {
1033 foreach ($this->setup as $key => $value) {
1034 if ($value == 'PAGE') {
1035 // Set the typeNum of the current page object:
1036 if (isset($this->setup[$key . '.']['typeNum'])) {
1037 $typeNum = $this->setup[$key . '.']['typeNum'];
1038 $this->setup['types.'][$typeNum] = $key;
1039 } elseif (!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) {
1040 $this->setup['types.'][0] = $key;
1041 }
1042 }
1043 }
1044 }
1045 unset($this->setup['temp.']);
1046 unset($constants);
1047 // Storing the conditions found/matched information:
1048 $this->sections = $config->sections;
1049 $this->sectionsMatch = $config->sectionsMatch;
1050 }
1051
1052 /**
1053 * Searching TypoScript code text (for constants and config (Setup))
1054 * for include instructions and does the inclusion of external TypoScript files
1055 * if needed.
1056 *
1057 * @return void
1058 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser, generateConfig()
1059 */
1060 public function processIncludes() {
1061 if ($this->processIncludesHasBeenRun) {
1062 return;
1063 }
1064
1065 $paths = $this->templateIncludePaths;
1066 $files = array();
1067 foreach ($this->constants as &$value) {
1068 $includeData = Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE, array_shift($paths));
1069 $files = array_merge($files, $includeData['files']);
1070 $value = $includeData['typoscript'];
1071 }
1072 unset($value);
1073 $paths = $this->templateIncludePaths;
1074 foreach ($this->config as &$value) {
1075 $includeData = Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE, array_shift($paths));
1076 $files = array_merge($files, $includeData['files']);
1077 $value = $includeData['typoscript'];
1078 }
1079 unset($value);
1080
1081 if (!empty($files)) {
1082 $files = array_unique($files);
1083 foreach ($files as $file) {
1084 $this->rowSum[] = array($file, filemtime($file));
1085 }
1086 }
1087
1088 $this->processIncludesHasBeenRun = TRUE;
1089 }
1090
1091 /**
1092 * 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!
1093 *
1094 * @param array $constArray Constants array, default input.
1095 * @return array Constants array, modified
1096 * @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...)
1097 */
1098 public function mergeConstantsFromPageTSconfig($constArray) {
1099 $TSdataArray = array();
1100 // Setting default configuration:
1101 $TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
1102 for ($a = 0; $a <= $this->outermostRootlineIndexWithTemplate; $a++) {
1103 $TSdataArray[] = $this->absoluteRootLine[$a]['TSconfig'];
1104 }
1105 // Parsing the user TS (or getting from cache)
1106 $TSdataArray = Parser\TypoScriptParser::checkIncludeLines_array($TSdataArray);
1107 $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
1108 /** @var $parseObj Parser\TypoScriptParser */
1109 $parseObj = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
1110 $parseObj->parse($userTS);
1111 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
1112 ArrayUtility::mergeRecursiveWithOverrule($constArray, $parseObj->setup['TSFE.']['constants.']);
1113 }
1114 return $constArray;
1115 }
1116
1117 /**
1118 * This flattens a hierarchical TypoScript array to $this->flatSetup
1119 *
1120 * @param array $setupArray TypoScript array
1121 * @param string $prefix Prefix to the object path. Used for recursive calls to this function.
1122 * @return void
1123 * @see generateConfig()
1124 */
1125 public function flattenSetup($setupArray, $prefix) {
1126 if (is_array($setupArray)) {
1127 foreach ($setupArray as $key => $val) {
1128 if ($prefix || !StringUtility::beginsWith($key, 'TSConstantEditor')) {
1129 // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
1130 if (is_array($val)) {
1131 $this->flattenSetup($val, $prefix . $key);
1132 } else {
1133 $this->flatSetup[$prefix . $key] = $val;
1134 }
1135 }
1136 }
1137 }
1138 }
1139
1140 /**
1141 * Substitutes the constants from $this->flatSetup in the text string $all
1142 *
1143 * @param string $all TypoScript code text string
1144 * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted.
1145 * @see generateConfig(), flattenSetup()
1146 */
1147 public function substituteConstants($all) {
1148 if ($this->tt_track) {
1149 $this->getTimeTracker()->setTSlogMessage('Constants to substitute: ' . count($this->flatSetup));
1150 }
1151 $noChange = FALSE;
1152 // Recursive substitution of constants (up to 10 nested levels)
1153 for ($i = 0; $i < 10 && !$noChange; $i++) {
1154 $old_all = $all;
1155 $all = preg_replace_callback('/\\{\\$(.[^}]*)\\}/', array($this, 'substituteConstantsCallBack'), $all);
1156 if ($old_all == $all) {
1157 $noChange = TRUE;
1158 }
1159 }
1160 return $all;
1161 }
1162
1163 /**
1164 * Call back method for preg_replace_callback in substituteConstants
1165 *
1166 * @param array $matches Regular expression matches
1167 * @return string Replacement
1168 * @see substituteConstants()
1169 */
1170 public function substituteConstantsCallBack($matches) {
1171 // Replace {$CONST} if found in $this->flatSetup, else leave unchanged
1172 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
1173 }
1174
1175 /*******************************************************************
1176 *
1177 * Various API functions, used from elsewhere in the frontend classes
1178 *
1179 *******************************************************************/
1180 /**
1181 * Implementation of the "optionSplit" feature in TypoScript (used eg. for MENU objects)
1182 * 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.
1183 * The concept is known as "optionSplit" and is rather advanced to handle but quite powerful, in particular for creating menus in TYPO3.
1184 *
1185 * @param array $conf A TypoScript array
1186 * @param int $splitCount The number of items for which to generated individual TypoScript arrays
1187 * @return array The individualized TypoScript array.
1188 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::IMGTEXT(), \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject::procesItemStates()
1189 */
1190 public function splitConfArray($conf, $splitCount) {
1191 // Initialize variables:
1192 $splitCount = (int)$splitCount;
1193 $conf2 = array();
1194 if ($splitCount && is_array($conf)) {
1195 // Initialize output to carry at least the keys:
1196 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1197 $conf2[$aKey] = array();
1198 }
1199 // Recursive processing of array keys:
1200 foreach ($conf as $cKey => $val) {
1201 if (is_array($val)) {
1202 $tempConf = $this->splitConfArray($val, $splitCount);
1203 foreach ($tempConf as $aKey => $val2) {
1204 $conf2[$aKey][$cKey] = $val2;
1205 }
1206 } else {
1207 // Splitting of all values on this level of the TypoScript object tree:
1208 if ($cKey === 'noTrimWrap' || (!strstr($val, '|*|') && !strstr($val, '||'))) {
1209 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1210 $conf2[$aKey][$cKey] = $val;
1211 }
1212 } else {
1213 $main = explode('|*|', $val);
1214 $lastC = 0;
1215 $middleC = 0;
1216 $firstC = 0;
1217 if ($main[0]) {
1218 $first = explode('||', $main[0]);
1219 $firstC = count($first);
1220 }
1221 $middle = array();
1222 if ($main[1]) {
1223 $middle = explode('||', $main[1]);
1224 $middleC = count($middle);
1225 }
1226 $last = array();
1227 $value = '';
1228 if ($main[2]) {
1229 $last = explode('||', $main[2]);
1230 $lastC = count($last);
1231 $value = $last[0];
1232 }
1233 for ($aKey = 0; $aKey < $splitCount; $aKey++) {
1234 if ($firstC && isset($first[$aKey])) {
1235 $value = $first[$aKey];
1236 } elseif ($middleC) {
1237 $value = $middle[($aKey - $firstC) % $middleC];
1238 }
1239 if ($lastC && $lastC >= $splitCount - $aKey) {
1240 $value = $last[$lastC - ($splitCount - $aKey)];
1241 }
1242 $conf2[$aKey][$cKey] = trim($value);
1243 }
1244 }
1245 }
1246 }
1247 }
1248 return $conf2;
1249 }
1250
1251 /**
1252 * Returns the reference used for the frontend inclusion, checks against allowed paths for inclusion.
1253 *
1254 * @param string $fileFromSetup TypoScript "resource" data type value.
1255 * @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
1256 */
1257 public function getFileName($fileFromSetup) {
1258 $file = trim($fileFromSetup);
1259 if (!$file) {
1260 return NULL;
1261 } elseif (strpos($file, '../') !== FALSE) {
1262 if ($this->tt_track) {
1263 $this->getTimeTracker()->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3);
1264 }
1265 return NULL;
1266 }
1267 // Cache
1268 $hash = md5($file);
1269 if (isset($this->fileCache[$hash])) {
1270 return $this->fileCache[$hash];
1271 }
1272
1273 // if this is an URL, it can be returned directly
1274 $urlScheme = parse_url($file, PHP_URL_SCHEME);
1275 if ($urlScheme === 'https' || $urlScheme === 'http' || is_file(PATH_site . $file)) {
1276 return $file;
1277 }
1278
1279 // this call also resolves EXT:myext/ files
1280 $file = GeneralUtility::getFileAbsFileName($file);
1281 if (!$file) {
1282 if ($this->tt_track) {
1283 $this->getTimeTracker()->setTSlogMessage('File "' . $fileFromSetup . '" was not found!', 3);
1284 }
1285 return NULL;
1286 }
1287
1288 $file = PathUtility::stripPathSitePrefix($file);
1289
1290 // Check if the found file is in the allowed paths
1291 foreach ($this->allowedPaths as $val) {
1292 if (GeneralUtility::isFirstPartOfStr($file, $val)) {
1293 $this->fileCache[$hash] = $file;
1294 return $file;
1295 }
1296 }
1297
1298 if ($this->tt_track) {
1299 $this->getTimeTracker()->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
1300 }
1301 return NULL;
1302 }
1303
1304 /**
1305 * Compiles the content for the page <title> tag.
1306 *
1307 * @param string $pageTitle The input title string, typically the "title" field of a page's record.
1308 * @param bool $noTitle If set, then only the site title is outputted (from $this->setup['sitetitle'])
1309 * @param bool $showTitleFirst If set, then "sitetitle" and $title is swapped
1310 * @param string $pageTitleSeparator an alternative to the ": " as the separator between site title and page title
1311 * @return string The page title on the form "[sitetitle]: [input-title]". Not htmlspecialchar()'ed.
1312 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::tempPageCacheContent(), \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader()
1313 */
1314 public function printTitle($pageTitle, $noTitle = FALSE, $showTitleFirst = FALSE, $pageTitleSeparator = '') {
1315 $siteTitle = trim($this->setup['sitetitle']);
1316 $pageTitle = $noTitle ? '' : $pageTitle;
1317 if ($showTitleFirst) {
1318 $temp = $siteTitle;
1319 $siteTitle = $pageTitle;
1320 $pageTitle = $temp;
1321 }
1322 // only show a separator if there are both site title and page title
1323 if ($pageTitle === '' || $siteTitle === '') {
1324 $pageTitleSeparator = '';
1325 // use the default separator if non given
1326 } elseif (empty($pageTitleSeparator)) {
1327 $pageTitleSeparator = ': ';
1328 }
1329 return $siteTitle . $pageTitleSeparator . $pageTitle;
1330 }
1331
1332 /**
1333 * Reads the fileContent of $fileName and returns it.
1334 * Similar to GeneralUtility::getUrl() but with an additional check if the path is allowed
1335 *
1336 * @param string $fileName Absolute filepath to record
1337 * @return NULL|string The content returned
1338 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::fileResource(), \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::MULTIMEDIA(), GeneralUtility::getUrl()
1339 */
1340 public function fileContent($fileName) {
1341 $fileName = $this->getFileName($fileName);
1342 if ($fileName) {
1343 return GeneralUtility::getUrl($fileName);
1344 }
1345 return NULL;
1346 }
1347
1348 /**
1349 * Ordinary "wrapping" function. Used in the AbstractMenuContentObject class and extension classes instead of the similar function in ContentObjectRenderer
1350 *
1351 * @param string $content The content to wrap
1352 * @param string $wrap The wrap value, eg. "<strong> | </strong>
1353 * @return string Wrapped input string
1354 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::wrap() instead
1355 * @see \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::wrap()
1356 */
1357 public function wrap($content, $wrap) {
1358 GeneralUtility::logDeprecatedFunction();
1359 if ($wrap) {
1360 $wrapArr = explode('|', $wrap);
1361 return trim($wrapArr[0]) . $content . trim($wrapArr[1]);
1362 } else {
1363 return $content;
1364 }
1365 }
1366
1367 /**
1368 * Removes the "?" of input string IF the "?" is the last character.
1369 *
1370 * @param string $url Input string
1371 * @return string Output string, free of "?" in the end, if any such character.
1372 * @see linkData(), \TYPO3\CMS\Frontend\Page\FramesetRenderer::frameParams()
1373 */
1374 public function removeQueryString($url) {
1375 if (substr($url, -1) == '?') {
1376 return substr($url, 0, -1);
1377 } else {
1378 return $url;
1379 }
1380 }
1381
1382 /**
1383 * 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.
1384 * Call it like \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList()
1385 *
1386 * @param array $setupArr TypoScript array with numerical array in
1387 * @param bool $acceptOnlyProperties If set, then a value is not required - the properties alone will be enough.
1388 * @return array An array with all integer properties listed in numeric order.
1389 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::cObjGet(), \TYPO3\CMS\Frontend\Imaging\GifBuilder, \TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject::makeImageMap()
1390 */
1391 static public function sortedKeyList($setupArr, $acceptOnlyProperties = FALSE) {
1392 $keyArr = array();
1393 $setupArrKeys = array_keys($setupArr);
1394 foreach ($setupArrKeys as $key) {
1395 if ($acceptOnlyProperties || MathUtility::canBeInterpretedAsInteger($key)) {
1396 $keyArr[] = (int)$key;
1397 }
1398 }
1399 $keyArr = array_unique($keyArr);
1400 sort($keyArr);
1401 return $keyArr;
1402 }
1403
1404 /**
1405 * Returns the level of the given page in the rootline - Multiple pages can be given by separating the UIDs by comma.
1406 *
1407 * @param string $list A list of UIDs for which the rootline-level should get returned
1408 * @return int The level in the rootline. If more than one page was given the lowest level will get returned.
1409 */
1410 public function getRootlineLevel($list) {
1411 $idx = 0;
1412 foreach ($this->rootLine as $page) {
1413 if (GeneralUtility::inList($list, $page['uid'])) {
1414 return $idx;
1415 }
1416 $idx++;
1417 }
1418 return FALSE;
1419 }
1420
1421 /*******************************************************************
1422 *
1423 * Functions for creating links
1424 *
1425 *******************************************************************/
1426 /**
1427 * The mother of all functions creating links/URLs etc in a TypoScript environment.
1428 * See the references below.
1429 * Basically this function takes care of issues such as type,id,alias and Mount Points, URL rewriting (through hooks), M5/B6 encoded parameters etc.
1430 * 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.
1431 *
1432 * @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.
1433 * @param string $oTarget Default target string to use IF not $page['target'] is set.
1434 * @param bool $no_cache If set, then the "&no_cache=1" parameter is included in the URL.
1435 * @param string $script Alternative script name if you don't want to use $this->getTypoScriptFrontendController()->config['mainScript'] (normally set to "index.php")
1436 * @param array $overrideArray Array with overriding values for the $page array.
1437 * @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.
1438 * @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.
1439 * @param string $targetDomain The target Doamin, if any was detected in typolink
1440 * @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
1441 * @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()
1442 */
1443 public function linkData($page, $oTarget, $no_cache, $script, $overrideArray = NULL, $addParams = '', $typeOverride = '', $targetDomain = '') {
1444 $LD = array();
1445 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
1446 if (is_array($overrideArray)) {
1447 foreach ($overrideArray as $theKey => $theNewVal) {
1448 $addParams .= '&real_' . $theKey . '=' . rawurlencode($page[$theKey]);
1449 $page[$theKey] = $theNewVal;
1450 }
1451 }
1452 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
1453 if (!strstr($addParams, '&MP=')) {
1454 // Looking for hardcoded defaults:
1455 if (trim($this->getTypoScriptFrontendController()->MP_defaults[$page['uid']])) {
1456 $addParams .= '&MP=' . rawurlencode(trim($this->getTypoScriptFrontendController()->MP_defaults[$page['uid']]));
1457 } elseif ($this->getTypoScriptFrontendController()->config['config']['MP_mapRootPoints']) {
1458 // Else look in automatically created map:
1459 $m = $this->getFromMPmap($page['uid']);
1460 if ($m) {
1461 $addParams .= '&MP=' . rawurlencode($m);
1462 }
1463 }
1464 }
1465 // Setting ID/alias:
1466 if (!$script) {
1467 $script = $this->getTypoScriptFrontendController()->config['mainScript'];
1468 }
1469 if ($page['alias']) {
1470 $LD['url'] = $script . '?id=' . rawurlencode($page['alias']);
1471 } else {
1472 $LD['url'] = $script . '?id=' . $page['uid'];
1473 }
1474 // Setting target
1475 $LD['target'] = trim($page['target']) ?: $oTarget;
1476 // typeNum
1477 $typeNum = $this->setup[$LD['target'] . '.']['typeNum'];
1478 if (!MathUtility::canBeInterpretedAsInteger($typeOverride) && (int)$this->getTypoScriptFrontendController()->config['config']['forceTypeValue']) {
1479 $typeOverride = (int)$this->getTypoScriptFrontendController()->config['config']['forceTypeValue'];
1480 }
1481 if ((string)$typeOverride !== '') {
1482 $typeNum = $typeOverride;
1483 }
1484 // Override...
1485 if ($typeNum) {
1486 $LD['type'] = '&type=' . (int)$typeNum;
1487 } else {
1488 $LD['type'] = '';
1489 }
1490 // Preserving the type number.
1491 $LD['orig_type'] = $LD['type'];
1492 // noCache
1493 $LD['no_cache'] = trim($page['no_cache']) || $no_cache ? '&no_cache=1' : '';
1494 // linkVars
1495 if ($addParams) {
1496 $LD['linkVars'] = GeneralUtility::implodeArrayForUrl('', GeneralUtility::explodeUrl2Array($this->getTypoScriptFrontendController()->linkVars . $addParams), '', FALSE, TRUE);
1497 } else {
1498 $LD['linkVars'] = $this->getTypoScriptFrontendController()->linkVars;
1499 }
1500 // Add absRefPrefix if exists.
1501 $LD['url'] = $this->getTypoScriptFrontendController()->absRefPrefix . $LD['url'];
1502 // 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.
1503 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#c' . $page['sectionIndex_uid'] : '';
1504 // Compile the normal total url
1505 $LD['totalURL'] = $this->removeQueryString(($LD['url'] . $LD['type'] . $LD['no_cache'] . $LD['linkVars'] . $this->getTypoScriptFrontendController()->getMethodUrlIdToken)) . $LD['sectionIndex'];
1506 // Call post processing function for link rendering:
1507 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) {
1508 $_params = array(
1509 'LD' => &$LD,
1510 'args' => array('page' => $page, 'oTarget' => $oTarget, 'no_cache' => $no_cache, 'script' => $script, 'overrideArray' => $overrideArray, 'addParams' => $addParams, 'typeOverride' => $typeOverride, 'targetDomain' => $targetDomain),
1511 'typeNum' => $typeNum
1512 );
1513 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) {
1514 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1515 }
1516 }
1517 // Return the LD-array
1518 return $LD;
1519 }
1520
1521 /**
1522 * Initializes the automatically created MPmap coming from the "config.MP_mapRootPoints" setting
1523 * Can be called many times with overhead only the first time since then the map is generated and cached in memory.
1524 *
1525 * @param int $pageId Page id to return MPvar value for.
1526 * @return string
1527 * @see initMPmap_create()
1528 * @todo Implement some caching of the result between hits. (more than just the memory caching used here)
1529 */
1530 public function getFromMPmap($pageId = 0) {
1531 // Create map if not found already:
1532 if (!is_array($this->MPmap)) {
1533 $this->MPmap = array();
1534 $rootPoints = GeneralUtility::trimExplode(',', strtolower($this->getTypoScriptFrontendController()->config['config']['MP_mapRootPoints']), TRUE);
1535 // Traverse rootpoints:
1536 foreach ($rootPoints as $p) {
1537 $initMParray = array();
1538 if ($p == 'root') {
1539 $p = $this->rootLine[0]['uid'];
1540 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) {
1541 $initMParray[] = $this->rootLine[0]['_MP_PARAM'];
1542 }
1543 }
1544 $this->initMPmap_create($p, $initMParray);
1545 }
1546 }
1547 // Finding MP var for Page ID:
1548 if ($pageId) {
1549 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) {
1550 return implode(',', $this->MPmap[$pageId]);
1551 }
1552 }
1553 return '';
1554 }
1555
1556 /**
1557 * Creating MPmap for a certain ID root point.
1558 *
1559 * @param int $id Root id from which to start map creation.
1560 * @param array $MP_array MP_array passed from root page.
1561 * @param int $level Recursion brake. Incremented for each recursive call. 20 is the limit.
1562 * @return void
1563 * @see getFromMPvar()
1564 */
1565 public function initMPmap_create($id, $MP_array = array(), $level = 0) {
1566 $id = (int)$id;
1567 if ($id <= 0) {
1568 return;
1569 }
1570 // First level, check id
1571 if (!$level) {
1572 // Find mount point if any:
1573 $mount_info = $this->getTypoScriptFrontendController()->sys_page->getMountPointInfo($id);
1574 // Overlay mode:
1575 if (is_array($mount_info) && $mount_info['overlay']) {
1576 $MP_array[] = $mount_info['MPvar'];
1577 $id = $mount_info['mount_pid'];
1578 }
1579 // Set mapping information for this level:
1580 $this->MPmap[$id] = $MP_array;
1581 // Normal mode:
1582 if (is_array($mount_info) && !$mount_info['overlay']) {
1583 $MP_array[] = $mount_info['MPvar'];
1584 $id = $mount_info['mount_pid'];
1585 }
1586 }
1587 if ($id && $level < 20) {
1588 $nextLevelAcc = array();
1589 // Select and traverse current level pages:
1590 $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);
1591 while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
1592 // Find mount point if any:
1593 $next_id = $row['uid'];
1594 $next_MP_array = $MP_array;
1595 $mount_info = $this->getTypoScriptFrontendController()->sys_page->getMountPointInfo($next_id, $row);
1596 // Overlay mode:
1597 if (is_array($mount_info) && $mount_info['overlay']) {
1598 $next_MP_array[] = $mount_info['MPvar'];
1599 $next_id = $mount_info['mount_pid'];
1600 }
1601 if (!isset($this->MPmap[$next_id])) {
1602 // Set mapping information for this level:
1603 $this->MPmap[$next_id] = $next_MP_array;
1604 // Normal mode:
1605 if (is_array($mount_info) && !$mount_info['overlay']) {
1606 $next_MP_array[] = $mount_info['MPvar'];
1607 $next_id = $mount_info['mount_pid'];
1608 }
1609 // Register recursive call
1610 // (have to do it this way since ALL of the current level should be registered BEFORE the sublevel at any time)
1611 $nextLevelAcc[] = array($next_id, $next_MP_array);
1612 }
1613 }
1614 $this->getDatabaseConnection()->sql_free_result($res);
1615 // Call recursively, if any:
1616 foreach ($nextLevelAcc as $pSet) {
1617 $this->initMPmap_create($pSet[0], $pSet[1], $level + 1);
1618 }
1619 }
1620 }
1621
1622 /**
1623 * Adds the TypoScript from the global array.
1624 * The class property isDefaultTypoScriptAdded ensures
1625 * that the adding only happens once.
1626 *
1627 * @return void
1628 * @see isDefaultTypoScriptAdded
1629 */
1630 protected function addDefaultTypoScript() {
1631 // Add default TS for all code types, if not done already
1632 if (!$this->isDefaultTypoScriptAdded) {
1633 // adding default setup and constants
1634 // defaultTypoScript_setup is *very* unlikely to be empty
1635 // the count of elements in ->constants, ->config and ->templateIncludePaths have to be in sync
1636 array_unshift($this->constants, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
1637 array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
1638 array_unshift($this->templateIncludePaths, '');
1639 // prepare a proper entry to hierachyInfo (used by TemplateAnalyzer in BE)
1640 $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo)-1]['templateID'];
1641 $defaultTemplateInfo = array(
1642 'root' => '',
1643 'next' => '',
1644 'clConst' => '',
1645 'clConf' => '',
1646 'templateID' => '_defaultTypoScript_',
1647 'templateParent' => $rootTemplateId,
1648 'title' => 'SYS:TYPO3_CONF_VARS:FE:defaultTypoScript',
1649 'uid' => '_defaultTypoScript_',
1650 'pid' => '',
1651 'configLines' => substr_count((string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'], LF) + 1
1652 );
1653 // push info to information arrays used in BE by TemplateTools (Analyzer)
1654 array_unshift($this->clearList_const, $defaultTemplateInfo['uid']);
1655 array_unshift($this->clearList_setup, $defaultTemplateInfo['uid']);
1656 array_unshift($this->hierarchyInfo, $defaultTemplateInfo);
1657 $this->isDefaultTypoScriptAdded = TRUE;
1658 }
1659 }
1660
1661 /**
1662 * @return DatabaseConnection
1663 */
1664 protected function getDatabaseConnection() {
1665 return $GLOBALS['TYPO3_DB'];
1666 }
1667
1668 /**
1669 * @return TypoScriptFrontendController
1670 */
1671 protected function getTypoScriptFrontendController() {
1672 return $GLOBALS['TSFE'];
1673 }
1674
1675 /**
1676 * @return TimeTracker
1677 */
1678 protected function getTimeTracker() {
1679 return $GLOBALS['TT'];
1680 }
1681
1682 }