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