2 /***************************************************************
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Class with template object that is responsible for generating the template
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
33 * @author Kasper Skaarhoj <kasper@typo3.com>
36 * [CLASS/FUNCTION INDEX of SCRIPT]
40 * 103: class t3lib_TStemplate
41 * 203: function init()
42 * 241: function getCurrentPageData()
43 * 258: function matching($cc)
44 * 282: function start($theRootLine)
46 * SECTION: Fetching TypoScript code text for the Template Hierarchy
47 * 391: function runThroughTemplates($theRootLine,$start_template_uid=0)
48 * 436: function processTemplate($row, $idList,$pid,$templateID='',$templateParent='')
49 * 549: function includeStaticTypoScriptSources($idList,$templateID,$pid,$row)
50 * 610: function addExtensionStatics($idList,$templateID,$pid,$row)
51 * 643: function prependStaticExtra($subrow)
53 * SECTION: Parsing TypoScript code text from Template Records into PHP array
54 * 679: function generateConfig()
55 * 842: function procesIncludes()
56 * 866: function mergeConstantsFromPageTSconfig($constArray)
57 * 895: function flattenSetup($setupArray, $prefix, $resourceFlag)
58 * 919: function substituteConstants($all)
60 * SECTION: Various API functions, used from elsewhere in the frontend classes
61 * 969: function splitConfArray($conf,$splitCount)
62 * 1035: function getFileName($fileFromSetup)
63 * 1092: function extractFromResources($res,$file)
64 * 1120: function checkFile($name,$menuArr)
65 * 1137: function printTitle($title,$no_title=0,$titleFirst=0)
66 * 1160: function fileContent($fName)
67 * 1180: function wrap($content,$wrap)
68 * 1203: function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='')
69 * 1296: function removeQueryString($url)
70 * 1312: function sortedKeyList($setupArr)
73 * (This index is automatically created/updated by the extension "extdeveval")
77 require_once (PATH_t3lib
.'class.t3lib_tsparser.php');
78 require_once (PATH_t3lib
.'class.t3lib_matchcondition.php');
96 * Template object that is responsible for generating the TypoScript template based on template records.
98 * @author Kasper Skaarhoj <kasper@typo3.com>
101 * @see t3lib_tsparser.php, t3lib_matchcondition.php
103 class t3lib_TStemplate
{
105 // Debugging, analysis:
106 var $tt_track = 1; // If set, the global tt-timeobject is used to log the performance.
107 var $forceTemplateParsing=0; // If set, the template is always rendered. Used from Admin Panel.
109 // Backend Analysis modules settings:
110 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!
111 var $matchAll=0; // If set, the match-class matches everything! Used for backend modules only. Never frontend!
112 var $parseEditorCfgField=0; // If set, the Backend Editor Configuration TypoScript is also parsed (this is not needed for the frontend)
113 var $backend_info = 0;
114 var $getFileName_backPath=''; // Set from the backend - used to set an absolute path (PATH_site) so that relative resources are properly found with getFileName()
116 // Externally set breakpoints (used by Backend Modules)
117 var $ext_constants_BRP=0;
118 var $ext_config_BRP=0;
119 var $ext_editorcfg_BRP=0;
122 var $uplPath = 'uploads/tf/';
123 var $tempPath = 'typo3temp/';
124 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
127 var $whereClause = ''; // This MUST be initialized by the init() function
129 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.
130 var $currentPageData = ''; // Contains "currentPageData" when rendered/fetched from cache. See getCurrentPageData()
131 var $simulationHiddenOrTime=0; // See init(); Set if preview of some kind is enabled.
133 var $loaded = 0; // Set, if the TypoScript template structure is loaded and OK, see ->start()
134 var $setup = Array( // Default TypoScript Setup code
136 'insertContent' => 'CONTENT',
137 'insertContent.' => Array (
138 'table' => 'tt_content',
140 'orderBy' => 'sorting',
141 'where' => 'colPos=0',
142 'languageField' => 'sys_language_uid'
147 'extTarget' => '_top',
149 'stat_typeNumList' => '0,1'
152 var $flatSetup = Array (
154 var $const = Array ( // Default TypoScript Constants code:
155 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
156 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
157 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
158 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
159 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
160 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
164 // For fetching TypoScript code from template hierarchy before parsing it. Each array contains code field values from template records/files:
165 var $config = array(); // Setup field
166 var $constants = array(); // Constant field
167 var $editorcfg = array(); // Backend Editor Configuration field
169 var $hierarchyInfo = array(); // For Template Analyser in backend
170 var $nextLevel=0; // Next-level flag (see runThroughTemplates())
171 var $rootId; // The Page UID of the root page
172 var $rootLine; // The rootline from current page to the root page
173 var $absoluteRootLine; // Rootline all the way to the root. Set but runThroughTemplates
174 var $outermostRootlineIndexWithTemplate=0; // A pointer to the last entry in the rootline where a template was found.
175 var $rowSum; // Array of arrays with title/uid of templates in hierarchy
176 var $resources=''; // Resources for the template hierarchy in a comma list
177 var $sitetitle=''; // The current site title field.
178 var $sections; // Tracking all conditions found during parsing of TypoScript. Used for the "all" key in currentPageData
179 var $sectionsMatch; // Tracking all matching conditions found
181 // Backend: ts_analyzer
182 var $clearList_const=array();
183 var $clearList_setup=array();
184 var $clearList_editorcfg=array();
185 var $parserErrors=array();
186 var $setup_constants = array();
189 var $fileCache = Array(); // Used by getFileName for caching of references to file resources
190 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.
198 * MUST be called directly after creating a new template-object
201 * @see tslib_fe::initTemplate()
204 // $this->whereClause is used only to select templates from sys_template.
205 // $GLOBALS['SIM_EXEC_TIME'] is used so that we're able to simulate a later time as a test...
206 $this->whereClause
='AND NOT deleted ';
207 if (!$GLOBALS['TSFE']->showHiddenRecords
) {
208 $this->whereClause
.='AND NOT hidden ';
210 if ($GLOBALS['TSFE']->showHiddenRecords ||
$GLOBALS['SIM_EXEC_TIME']!=$GLOBALS['EXEC_TIME']) { // Set the simulation flag, if simulation is detected!
211 $this->simulationHiddenOrTime
=1;
213 $this->whereClause
.= 'AND (starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_EXEC_TIME'].')';
214 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
215 $this->menuclasses
='tmenu,jsmenu,gmenu';
218 // Sets the paths from where TypoScript resources are allowed to be used:
219 $this->allowedPaths
= Array ('media/','fileadmin/','uploads/','typo3temp/','t3lib/fonts/',TYPO3_mainDir
.'ext/',TYPO3_mainDir
.'sysext/','typo3conf/ext/');
220 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
221 $pathArr = t3lib_div
::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'],1);
222 while(list(,$p)=each($pathArr)) {
223 // 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.
224 $this->allowedPaths
[] = $p;
230 * Fetches the "currentPageData" array from cache
232 * NOTE about currentPageData:
233 * It holds information about the TypoScript conditions along with the list of template uid's which is used on the page.
234 * In the getFromCache function in TSFE, currentPageData is used to evaluate if there is a template and if the matching conditions are alright
235 * Unfortunately this does not take into account if the templates in the rowSum of currentPageData has changed composition, eg. due to hidden fields or start/end time.
236 * So if a template is hidden or times out, it'll not be discovered unless the page is regenerated - at least the this->start function must be called, because this will make a new portion of data in currentPageData string
238 * @return mixed The array $this->currentPageData if found cached in "cache_pagesection". If the string "none" was returned it means the array must be generated and stored in the cache-table
239 * @see start(), t3lib_fe::getFromCache()
241 function getCurrentPageData() {
242 $res = mysql(TYPO3_db
, 'SELECT content FROM cache_pagesection WHERE page_id='.intval($GLOBALS['TSFE']->id
));
243 if ($row=mysql_fetch_assoc($res)) {
244 $this->currentPageData
= unserialize($row['content']);
246 $this->currentPageData
= 'none';
248 return $this->currentPageData
;
252 * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
254 * @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the $this->currentPageData array
255 * @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.
256 * @see t3lib_matchCondition, t3lib_fe::getFromCache()
258 function matching($cc) {
259 if (is_array($cc['all'])) {
261 $matchObj = t3lib_div
::makeInstance('t3lib_matchCondition');
262 $matchObj->altRootLine
=$cc['rootLine'];
263 while(list($key,$pre)=each($cc['all'])) {
264 if ($matchObj->match($pre)) {
265 $sectionsMatch[$key]=$pre;
268 $cc['match']=$sectionsMatch;
274 * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
275 * The method traverse 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.
276 * Sets $this->setup to the parsed TypoScript Template array
278 * @param array The rootline of the current page (going ALL the way to tree root)
280 * @see tslib_fe::getConfigArray()
282 function start($theRootLine) {
283 if (is_array($theRootLine)) {
287 $this->runThroughTemplates($theRootLine);
289 // Getting the currentPageData if not already found
290 if (!$this->currentPageData
) {
291 $this->getCurrentPageData();
294 // This is about getting the hash string which is used to fetch the cached TypoScript template.
295 // If there was some cached currentPageData that's good (it gives us the hash),
296 // However if the actual rowSum and the rowSum of currentPageData is different from each other, thats a problem, and we should re-make the current page data.
297 if (is_array($this->currentPageData
) &&
298 !strcmp(serialize($this->rowSum
), serialize($this->currentPageData
['rowSum'])) // The two ROWsums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
300 // If currentPageData was actually there, we match the result...
301 $cc['all'] = $this->currentPageData
['all'];
302 $cc['rowSum'] = $this->currentPageData
['rowSum'];
303 $cc = $this->matching($cc);
304 $hash = md5(serialize($cc));
306 // If currentPageData was not there, we first find $rowSum (freshly generated). After that we try to see, if rowSum is stored with a list of all matching-parameters. If so we match the result
307 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum
));
308 $result = t3lib_pageSelect
::getHash($rowSumHash, 0);
310 $cc['all'] = unserialize($result);
311 $cc['rowSum'] = $this->rowSum
;
312 $cc = $this->matching($cc);
313 $hash = md5(serialize($cc));
318 // Get TypoScript setup array
319 $setupData = t3lib_pageSelect
::getHash($hash, 0);
322 if ($hash && $setupData && !$this->forceTemplateParsing
) {
323 // If TypoScript setup structure was cached we unserialize it here:
324 $this->setup
= unserialize($setupData);
326 // Make configuration
327 $this->generateConfig();
329 // This stores the template hash thing
331 $cc['all']=$this->sections
; // All sections in the template at this point is found
332 $cc['rowSum']=$this->rowSum
; // The line of templates is collected
333 $cc = $this->matching($cc);
335 $hash = md5(serialize($cc));
337 // This stores the data.
338 t3lib_pageSelect
::storeHash($hash, serialize($this->setup
), 'TS TEMPLATE');
340 if ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup
)).' bytes');
342 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum
));
343 t3lib_pageSelect
::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - ALL');
346 $cc['rootLine'] = $this->rootLine
;
347 // Make global and save.
348 $GLOBALS['TSFE']->all
=$cc;
350 if (!$this->simulationHiddenOrTime
) { // Only save currentPageData, if we're not simulating by hidden/starttime/endtime
351 $res = mysql (TYPO3_db
, 'DELETE FROM cache_pagesection WHERE page_id='.intval($GLOBALS['TSFE']->id
));
352 $res = mysql(TYPO3_db
, 'INSERT INTO cache_pagesection (page_id, content, tstamp) VALUES ('.intval($GLOBALS['TSFE']->id
).', "'.addslashes(serialize($cc)).'", '.$GLOBALS['EXEC_TIME'].')');
355 if ($this->rootId
&& $this->rootLine
&& $this->setup
) {
375 /*******************************************************************
377 * Fetching TypoScript code text for the Template Hierarchy
379 *******************************************************************/
382 * 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.
383 * Resets and affects internal variables like $this->constants, $this->config, $this->editorcfg and $this->rowSum
384 * 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
386 * @param array The rootline of the current page (going ALL the way to tree root)
387 * @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)
391 function runThroughTemplates($theRootLine,$start_template_uid=0) {
392 $this->constants
= Array();
393 $this->config
= Array();
394 $this->editorcfg
= Array();
395 $this->rowSum
= Array();
396 $this->absoluteRootLine
=$theRootLine; // Is the TOTAL rootline
398 reset ($this->absoluteRootLine
);
399 $c=count($this->absoluteRootLine
);
400 for ($a=0;$a<$c;$a++
) {
401 if ($this->nextLevel
) { // If some template loaded before has set a template-id for the next level, then load this template first!
402 $res = mysql(TYPO3_db
, 'SELECT * FROM sys_template WHERE uid='.intval($this->nextLevel
).' '.$this->whereClause
);
403 $this->nextLevel
= 0;
404 if ($row = mysql_fetch_assoc($res)) {
405 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine
[$a]['uid'],'sys_'.$row['uid']);
406 $this->outermostRootlineIndexWithTemplate
=$a;
410 if ($a==($c-1) && $start_template_uid) { // If first loop AND there is set an alternative template uid, use that
411 $addC=' AND uid='.intval($start_template_uid);
413 $query = 'SELECT * FROM sys_template WHERE pid='.$this->absoluteRootLine
[$a]['uid'].$addC.' '.$this->whereClause
.' ORDER BY sorting LIMIT 1';
415 $res = mysql(TYPO3_db
, $query);
416 if ($row = mysql_fetch_assoc($res)) {
417 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine
[$a]['uid'],'sys_'.$row['uid']);
418 $this->outermostRootlineIndexWithTemplate
=$a;
420 $this->rootLine
[] = $this->absoluteRootLine
[$a];
425 * Checks if the template ($row) has some included templates and after including them it fills the arrays with the setup
426 * Builds up $this->rowSum
428 * @param array A full TypoScript template record (sys_template/static_template/forged "dummy" record made from static template file)
429 * @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.
430 * @param array The PID of the input template record
431 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
432 * @param string Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123"
434 * @see runThroughTemplates()
436 function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') {
437 // Adding basic template record information to rowSum array
438 $this->rowSum
[]=Array($row['uid'],$row['title'],$row['tstamp']);
440 // Processing "Clear"-flags
442 $clConst = $row['clear']&1;
443 $clConf = $row['clear']&2;
445 $this->constants
= Array();
446 $this->clearList_const
=array();
449 $this->config
= Array();
450 $this->clearList_setup
=array();
452 $this->editorcfg
= Array();
453 $this->clearList_editorcfg
=array();
457 // Include static records (static_template) or files (from extensions) (#1/2)
458 if (!$row['includeStaticAfterBasedOn']) { // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
459 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
462 // Include "Based On" sys_templates:
463 if (trim($row['basedOn'])) { // 'basedOn' is a list of templates to include
464 // Manually you can put this value in the field and then the based_on ID will be taken from the HTTP_GET_VARS var defined by '=....'.
465 // 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!
466 // 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.
467 $basedOn_hackFeature = explode('=',$row['basedOn']);
468 if ($basedOn_hackFeature[0]=='EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
469 $id=intval($GLOBALS['HTTP_GET_VARS'][$basedOn_hackFeature[1]]);
470 if ($id && !t3lib_div
::inList($idList,'sys_'.$id)) { // if $id is not allready included ...
471 $res = mysql(TYPO3_db
, 'SELECT * FROM sys_template WHERE uid='.$id.' '.$this->whereClause
);
473 if ($subrow = mysql_fetch_assoc($res)) { // there was a template, then we fetch that
474 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
477 } else { // NORMAL OPERATION:
478 $basedOnArr = t3lib_div
::intExplode(',',$row['basedOn']);
479 while(list(,$id)=each($basedOnArr)) { // traversing list
480 if (!t3lib_div
::inList($idList,'sys_'.$id)) { // if $id is not allready included ...
481 $res = mysql(TYPO3_db
, 'SELECT * FROM sys_template WHERE uid='.$id.' '.$this->whereClause
);
483 if ($subrow = mysql_fetch_assoc($res)) { // there was a template, then we fetch that
484 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
491 // Include static records (static_template) or files (from extensions) (#2/2)
492 if ($row['includeStaticAfterBasedOn']) {
493 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
496 // Creating hierarchy information; Used by backend analysis tools
497 $this->hierarchyInfo
[] = array(
498 'root'=>trim($row['root']),
499 'next'=>$row['nextLevel'],
502 'templateID'=>$templateID,
503 'templateParent'=>$templateParent,
504 'title'=>$row['title'],
509 // Adding the content of the fields constants (Constants), config (Setup) and editorcfg (Backend Editor Configuration) to the internal arrays.
510 $this->constants
[] = $row['constants'];
511 $this->config
[] = $row['config'];
512 if ($this->parseEditorCfgField
) $this->editorcfg
[] = $row['editorcfg'];
514 // For backend analysis (Template Analyser) provide the order of added constants/config/editorcfg template IDs
515 $this->clearList_const
[]=$templateID;
516 $this->clearList_setup
[]=$templateID;
517 if ($this->parseEditorCfgField
) $this->clearList_editorcfg
[]=$templateID;
519 // Add resources and sitetitle if found:
520 if (trim($row['resources'])) {
521 $this->resources
= $row['resources'].','.$this->resources
;
523 if (trim($row['sitetitle'])) {
524 $this->sitetitle
= $row['sitetitle'];
526 // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
527 if (trim($row['root'])) {
528 $this->rootId
= $pid;
529 $this->rootLine
= Array();
531 // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
532 if ($row['nextLevel']) {
533 $this->nextLevel
= $row['nextLevel'];
535 $this->nextLevel
= 0;
540 * Includes static template records (from static_template table) and static template files (from extensions) for the input template record row.
542 * @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.
543 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
544 * @param array The PID of the input template record
545 * @param array A full TypoScript template record
547 * @see processTemplate()
549 function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) {
550 // Static Template Records (static_template): include_static is a list of static templates to include
551 if (trim($row['include_static'])) {
552 $include_staticArr = t3lib_div
::intExplode(',',$row['include_static']);
553 reset($include_staticArr);
554 while(list(,$id)=each($include_staticArr)) { // traversing list
555 if (!t3lib_div
::inList($idList,'static_'.$id)) { // if $id is not allready included ...
556 $res = mysql(TYPO3_db
, 'SELECT * FROM static_template WHERE uid='.$id);
558 if ($subrow = mysql_fetch_assoc($res)) { // there was a template, then we fetch that
559 $subrow = $this->prependStaticExtra($subrow);
560 $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
566 // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
567 if (trim($row['include_static_file'])) {
568 $include_static_fileArr = t3lib_div
::trimExplode(',',$row['include_static_file'],1);
569 reset($include_static_fileArr);
570 while(list(,$ISF_file)=each($include_static_fileArr)) { // traversing list
571 $ISF_file = trim($ISF_file);
572 if (substr($ISF_file,0,4)=='EXT:') {
573 list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
574 if (strcmp($ISF_extKey,'') && t3lib_extMgm
::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
575 $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
576 $ISF_filePath = t3lib_extMgm
::extPath($ISF_extKey).$ISF_localPath;
577 if (@is_dir
($ISF_filePath)) {
578 $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
580 'constants'=> @is_file
($ISF_filePath.'constants.txt') ?t3lib_div
::getUrl($ISF_filePath.'constants.txt'):'',
581 'config'=> @is_file
($ISF_filePath.'setup.txt') ?t3lib_div
::getUrl($ISF_filePath.'setup.txt'):'',
582 'editorcfg'=> @is_file
($ISF_filePath.'editorcfg.txt') ?t3lib_div
::getUrl($ISF_filePath.'editorcfg.txt'):'',
583 'include_static'=> @is_file
($ISF_filePath.'include_static.txt')?
implode(',',array_unique(t3lib_div
::intExplode(',',t3lib_div
::getUrl($ISF_filePath.'include_static.txt')))):'',
584 'title' => $ISF_file,
587 $subrow = $this->prependStaticExtra($subrow);
589 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
596 $this->addExtensionStatics($idList,$templateID,$pid,$row);
600 * Adds the default TypoScript files for extensions if any.
602 * @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.
603 * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
604 * @param array The PID of the input template record
605 * @param array A full TypoScript template record
608 * @see includeStaticTypoScriptSources()
610 function addExtensionStatics($idList,$templateID,$pid,$row) {
611 global $TYPO3_LOADED_EXT;
613 if ($row['static_file_mode']==1 ||
($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root'])) {
614 reset($TYPO3_LOADED_EXT);
615 while(list($extKey,$files)=each($TYPO3_LOADED_EXT)) {
616 if (is_array($files) && ($files['ext_typoscript_constants.txt'] ||
$files['ext_typoscript_setup.txt'] ||
$files['ext_typoscript_editorcfg.txt'])) {
617 $mExtKey = str_replace('_','',$extKey);
619 'constants'=> $files['ext_typoscript_constants.txt']?t3lib_div
::getUrl($files['ext_typoscript_constants.txt']):'',
620 'config'=> $files['ext_typoscript_setup.txt']?t3lib_div
::getUrl($files['ext_typoscript_setup.txt']):'',
621 'editorcfg'=> $files['ext_typoscript_editorcfg.txt']?t3lib_div
::getUrl($files['ext_typoscript_editorcfg.txt']):'',
625 $subrow = $this->prependStaticExtra($subrow);
627 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
634 * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS
635 * For records the "uid" value is the integer of the "static_template" record
636 * 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
638 * @param array Static template record/file
639 * @return array Returns the input array where the values for keys "config", "constants" and "editorcfg" may have been modified with prepended code.
641 * @see addExtensionStatics(), includeStaticTypoScriptSources()
643 function prependStaticExtra($subrow) {
644 $subrow['config'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
645 $subrow['editorcfg'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
646 $subrow['constants'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
666 /*******************************************************************
668 * Parsing TypoScript code text from Template Records into PHP array
670 *******************************************************************/
673 * Generates the configuration array by replacing constants and parsing the whole thing.
674 * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates)
677 * @see t3lib_TSparser, start()
679 function generateConfig() {
680 // Add default TS for all three code types:
681 array_unshift($this->constants
,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']); // Adding default TS/constants
682 array_unshift($this->config
,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']); // Adding default TS/setup
683 array_unshift($this->editorcfg
,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']); // Adding default TS/editorcfg
685 // Parse the TypoScript code text for include-instructions!
686 $this->procesIncludes();
688 // These vars are also set lateron...
689 $this->setup
['resources']= $this->resources
;
690 $this->setup
['sitetitle']= $this->sitetitle
;
694 // ****************************
695 // Parse TypoScript Constants
696 // ****************************
698 // Initialize parser and match-condition classes:
699 $constants = t3lib_div
::makeInstance('t3lib_TSparser');
700 $constants->breakPointLN
=intval($this->ext_constants_BRP
);
701 $constants->setup
= $this->const;
702 $constants->setup
= $this->mergeConstantsFromPageTSconfig($constants->setup
);
703 $matchObj = t3lib_div
::makeInstance('t3lib_matchCondition');
704 $matchObj->matchAlternative
= $this->matchAlternative
;
705 $matchObj->matchAll
= $this->matchAll
; // Matches ALL conditions in TypoScript
707 // Traverse constants text fields and parse them
708 foreach($this->constants
as $str) {
709 $constants->parse($str,$matchObj);
712 // Read out parse errors if any
713 $this->parserErrors
['constants']=$constants->errors
;
715 // 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)
716 $this->flatSetup
= Array();
717 $this->flattenSetup($constants->setup
,'','');
721 // ***********************************************
722 // Parse TypoScript Setup (here called "config")
723 // ***********************************************
724 // Initialize parser and match-condition classes:
725 $config = t3lib_div
::makeInstance('t3lib_TSparser');
726 $config->breakPointLN
=intval($this->ext_config_BRP
);
727 $config->setup
= $this->setup
;
729 // Transfer information about conditions found in "Constants" and which of them returned true.
730 $config->sections
= $constants->sections
;
731 $config->sectionsMatch
= $constants->sectionsMatch
;
733 // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition
735 foreach($this->config
as $str) {
736 $all.="\n[GLOBAL]\n".$str;
739 // Substitute constants in the Setup code:
740 if ($this->tt_track
) $GLOBALS['TT']->push('Substitute Constants ('.count($this->flatSetup
).')');
741 $all = $this->substituteConstants($all);
742 if ($this->tt_track
) $GLOBALS['TT']->pull();
744 // Searching for possible unsubstituted constants left (only for information)
745 if (strstr($all,'{$')) {
746 $findConst = explode('{$',$all);
747 $theConstList=Array();
749 while(list(,$constVal)=each($findConst)) {
750 $constLen=t3lib_div
::intInRange(strcspn($constVal,'}'),0,50);
751 $theConstList[]='{$'.substr($constVal,0,$constLen+
1);
753 if ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage(implode($theConstList,',').': Constants may remain un-substituted!!',2);
756 // Logging the textual size of the TypoScript Setup field text with all constants substituted:
757 if ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: '.strlen($all).' bytes');
759 // Finally parse the Setup field TypoScript code (where constants are now substituted)
760 $config->parse($all,$matchObj);
762 // Read out parse errors if any
763 $this->parserErrors
['config']=$config->errors
;
765 // Transfer the TypoScript array from the parser object to the internal $this->setup array:
766 $this->setup
= $config->setup
;
767 if ($this->backend_info
) {
768 $this->setup_constants
= $constants->setup
; // Used for backend purposes only
774 // **************************************************
775 // Parse Backend Editor Configuration (backend only)
776 // **************************************************
777 if ($this->parseEditorCfgField
) {
778 $editorcfg = t3lib_div
::makeInstance('t3lib_TSparser');
779 $editorcfg->breakPointLN
=intval($this->ext_editorcfg_BRP
);
780 $editorcfg->setup
= array(); // Empty as a start...
782 $all = implode("\n[GLOBAL]\n",$this->editorcfg
);
784 // substitute constants in config
785 $all = $this->substituteConstants($all);
788 $matchObj->matchAll
=1; // This should make sure that conditions are disabled. For now they are NOT active for the backend.
789 $editorcfg->parse($all,$matchObj);
790 $this->parserErrors
['editorcfg']=$editorcfg->errors
;
791 $this->setup_editorcfg
= $editorcfg->setup
;
798 // ****************************************************************
799 // Final processing of the $this->setup TypoScript Template array
800 // Basically: This is unsetting/setting of certain reserved keys.
801 // ****************************************************************
803 // 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!
804 unset($this->setup
['resources']);
805 unset($this->setup
['resources.']);
806 $this->setup
['resources']= implode(',',t3lib_div
::trimExplode(',',$this->resources
,1));
808 unset($this->setup
['sitetitle']);
809 unset($this->setup
['sitetitle.']);
810 $this->setup
['sitetitle']= $this->sitetitle
;
812 // Unsetting some vars...
813 unset($this->setup
['types.']);
814 unset($this->setup
['types']);
815 if (is_array($this->setup
)) {
816 reset ($this->setup
);
817 while(list($theKey,)=each($this->setup
)) {
818 if ($this->setup
[$theKey]=='PAGE') {
819 $tN = $this->setup
[$theKey.'.']['typeNum'];
821 $this->setup
['types.'][$tN] = $theKey;
826 unset($this->setup
['styles.']);
827 unset($this->setup
['temp.']);
830 // Storing the conditions found/matched information:
831 $this->sections
= $config->sections
;
832 $this->sectionsMatch
= $config->sectionsMatch
;
836 * Searching TypoScript code text (for constants, config (Setup) and editorcfg) for include instructions and does the inclusion if needed.
840 * @see t3lib_TSparser, generateConfig()
842 function procesIncludes() {
843 reset($this->constants
);
844 while(list($k)=each($this->constants
)) {
845 $this->constants
[$k]=t3lib_TSparser
::checkIncludeLines($this->constants
[$k]);
848 reset($this->config
);
849 while(list($k)=each($this->config
)) {
850 $this->config
[$k]=t3lib_TSparser
::checkIncludeLines($this->config
[$k]);
853 reset($this->editorcfg
);
854 while(list($k)=each($this->editorcfg
)) {
855 $this->editorcfg
[$k]=t3lib_TSparser
::checkIncludeLines($this->editorcfg
[$k]);
860 * 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!
862 * @param array Constants array, default input.
863 * @return array Constants array, modified
864 * @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...)
866 function mergeConstantsFromPageTSconfig($constArray) {
867 $TSdataArray = array();
868 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
870 for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate
;$a++
) {
871 $TSdataArray[]=$this->absoluteRootLine
[$a]['TSconfig'];
873 // Parsing the user TS (or getting from cache)
874 $TSdataArray = t3lib_TSparser
::checkIncludeLines_array($TSdataArray);
875 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
877 $parseObj = t3lib_div
::makeInstance('t3lib_TSparser');
878 $parseObj->parse($userTS);
880 if (is_array($parseObj->setup
['TSFE.']['constants.'])) {
881 $constArray = t3lib_div
::array_merge_recursive_overrule($constArray,$parseObj->setup
['TSFE.']['constants.']);
887 * This flattens a hierarchical TypoScript array to $this->flatSetup
889 * @param array TypoScript array
890 * @param string Prefix to the object path. Used for recursive calls to this function.
891 * @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.
893 * @see generateConfig()
895 function flattenSetup($setupArray, $prefix, $resourceFlag) {
896 if (is_array($setupArray)) {
898 while(list($key,$val)=each($setupArray)) {
899 if ($prefix ||
substr($key,0,16)!='TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
900 if (is_array($val)) {
901 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
902 } elseif ($resourceFlag) {
903 $this->flatSetup
[$prefix.$key] = $this->getFileName($val);
905 $this->flatSetup
[$prefix.$key] = $val;
913 * Substitutes the constants from $this->flatSetup in the text string $all
915 * @param string TypoScript code text string
916 * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted.
917 * @see generateConfig(), flattenSetup()
919 function substituteConstants($all) {
920 if ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup
));
921 reset($this->flatSetup
);
922 while (list($const,$val)=each($this->flatSetup
)) {
923 if (!is_array($val)) {
924 $all = str_replace('{$'.$const.'}',$val,$all);
952 /*******************************************************************
954 * Various API functions, used from elsewhere in the frontend classes
956 *******************************************************************/
959 * Implementation of the "optionSplit" feature in TypoScript (used eg. for MENU objects)
960 * 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.
961 * The concept is known as "optionSplit" and is rather advanced to handle but quite powerful, in particular for creating menus in TYPO3.
963 * @param array A TypoScript array
964 * @param integer The number of items for which to generated individual TypoScript arrays
965 * @return array The individualized TypoScript array.
966 * @see tslib_cObj::IMGTEXT(), tslib_menu::procesItemStates()
967 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=289&cHash=6604390b37
969 function splitConfArray($conf,$splitCount) {
970 $splitCount = intval($splitCount);
972 if ($splitCount && is_array($conf)) {
973 while (list($cKey,$val)=each($conf)) {
974 if (is_array($val)) {
975 $tempConf = $this->splitConfArray($val,$splitCount);
976 while (list($aKey,$val)=each($tempConf)) {
977 $conf2[$aKey][$cKey] = $val;
982 while (list($cKey,$val)=each($conf)) {
983 if (!is_array($val)) {
984 if (!strstr($val,'|*|') && !strstr($val,'||')) {
985 for ($aKey=0;$aKey<$splitCount;$aKey++
) {
986 $conf2[$aKey][$cKey] = $val;
989 $main = explode ('|*|',$val);
990 $mainCount = count($main);
997 $first = explode('||',$main[0]);
998 $firstC = count($first);
1001 $middle = explode('||',$main[1]);
1002 $middleC = count($middle);
1005 $last = explode('||',$main[2]);
1006 $lastC = count($last);
1010 for ($aKey=0;$aKey<$splitCount;$aKey++
) {
1011 if ($firstC && isset($first[$aKey])) {
1012 $value = $first[$aKey];
1013 } elseif ($middleC) {
1014 $value = $middle[($aKey-$firstC)%
$middleC];
1016 if ($lastC && $lastC>=($splitCount-$aKey)) {
1017 $value = $last[$lastC-($splitCount-$aKey)];
1019 $conf2[$aKey][$cKey] = trim($value);
1029 * Returns the reference to a 'resource' in TypoScript.
1030 * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list
1032 * @param string TypoScript "resource" data type value.
1033 * @return string Resulting filename, if any.
1035 function getFileName($fileFromSetup) {
1036 $file = trim($fileFromSetup);
1040 if (isset($this->fileCache
[$hash])) {
1041 return $this->fileCache
[$hash];
1044 if (!strcmp(substr($file,0,4),'EXT:')) {
1046 list($extKey,$script)=explode('/',substr($file,4),2);
1047 if ($extKey && t3lib_extMgm
::isLoaded($extKey)) {
1048 $extPath=t3lib_extMgm
::extPath($extKey);
1049 $newFile=substr($extPath,strlen(PATH_site
)).$script;
1051 if (!@is_file
(PATH_site
.$newFile)) {
1052 if ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('Extension media file "'.$newFile.'" was not found!',3);
1054 } else $file=$newFile;
1058 if (strstr($file,'/')) { // here it is manual media
1059 if (@is_file
($this->getFileName_backPath
.$file)) {
1061 $fileInfo = t3lib_div
::split_fileref($outFile);
1062 reset($this->allowedPaths
);
1064 while(list(,$val)=each($this->allowedPaths
)) {
1065 if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
1068 $this->fileCache
[$hash]=$outFile;
1070 } elseif ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" was not located in the allowed paths: ('.implode($this->allowedPaths
,',').')',3);
1071 } elseif ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('"'.$this->getFileName_backPath
.$file.'" is not a file (non-uploads/.. resource, did not exist).',3);
1072 } else { // Here it is uploaded media:
1073 $outFile = $this->extractFromResources($this->setup
['resources'],$file);
1075 if (@is_file
($this->uplPath
.$outFile)) {
1076 $this->fileCache
[$hash] = $this->uplPath
.$outFile;
1077 return $this->uplPath
.$outFile;
1078 } elseif ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('"'.$this->uplPath
.$outFile.'" is not a file (did not exist).',3);
1079 } elseif ($this->tt_track
) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" is not a file (uploads/.. resource).',3);
1084 * Searches for the TypoScript resource filename in the list of resource filenames.
1086 * @param string The resource file name list (from $this->setup['resources'])
1087 * @param string The resource value to match
1088 * @return string If found, this will be the resource filename that matched. Typically this file is found in "uploads/tf/"
1090 * @see getFileName()
1092 function extractFromResources($res,$file) {
1093 if (t3lib_div
::inList($res,$file)) {
1095 } elseif (strstr($file,'*')) {
1096 $fileparts=explode('*',$file);
1097 $c=count($fileparts);
1098 $files = explode(',',$res);
1099 while(list(,$val)=each($files)) {
1101 if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test)) {
1111 * CheckFile runs through the $menuArr and checks every file-reference in $name
1112 * (Not used anywhere)
1114 * @param string Property name in the menu array
1115 * @param array Menu array to traverse
1116 * @return array Modified menu array
1120 function checkFile($name,$menuArr) {
1122 while (list($aKey,)=each($menuArr)) {
1123 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
1129 * Compiles the content for the page <title> tag.
1131 * @param string The input title string, typically the "title" field of a page's record.
1132 * @param boolean If set, then only the site title is outputted (from $this->setup['sitetitle'])
1133 * @param boolean If set, then "sitetitle" and $title is swapped
1134 * @return string The page title on the form "[sitetitle]: [input-title]". Not htmlspecialchar()'ed.
1135 * @see tslib_fe::tempPageCacheContent(), TSpagegen::renderContentWithHeader()
1137 function printTitle($title,$no_title=0,$titleFirst=0) {
1138 $st = trim($this->setup
['sitetitle']) ?
$this->setup
['sitetitle']:'';
1139 $title = $no_title ?
'' : $title;
1145 if ($title && $st) {
1146 return $st.': '.$title;
1153 * Reads the fileContent of $fName and returns it.
1154 * The same as t3lib_div::getUrl()
1156 * @param string Absolute filepath to record
1157 * @return string The content returned
1158 * @see tslib_cObj::fileResource(), tslib_cObj::MULTIMEDIA(), t3lib_div::getUrl()
1160 function fileContent($fName) {
1161 $incFile = $this->getFileName($fName);
1162 if ($incFile && $fd=fopen($incFile,'rb')) {
1164 while (!feof($fd)) {
1165 $content.=fread($fd, 5000);
1173 * Ordinary "wrapping" function. Used in the tslib_menu class and extension classes instead of the similar function in tslib_cObj
1175 * @param string The content to wrap
1176 * @param string The wrap value, eg. "<b> | </b>"
1177 * @return string Wrapped input string
1178 * @see tslib_menu, tslib_cObj::wrap()
1180 function wrap($content,$wrap) {
1182 $wrapArr = explode('|', $wrap);
1183 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
1184 } else return $content;
1188 * The mother of all functions creating links/URLs etc in a TypoScript environment.
1189 * See the references below.
1190 * Basically this function takes care of issues such as type,id,alias and Mount Points, simulate static documents, M5/B6 encoded parameters etc.
1191 * 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.
1193 * @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.
1194 * @param string Default target string to use IF not $page['target'] is set.
1195 * @param boolean If set, then the "&no_cache=1" parameter is included in the URL.
1196 * @param string Alternative script name if you don't want to use $GLOBALS['TSFE']->config['mainScript'] (normally set to "index.php")
1197 * @param array Array with overriding values for the $page array.
1198 * @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.
1199 * @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.
1200 * @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"
1201 * @see tslib_frameset::frameParams(), tslib_cObj::typoLink(), tslib_cObj::SEARCHRESULT(), TSpagegen::pagegenInit(), tslib_menu::link()
1203 function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') {
1206 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
1207 if (is_array($overrideArray)) {
1208 reset($overrideArray);
1209 while(list($theKey,$theNewVal)=each($overrideArray)) {
1210 $addParams.='&real_'.$theKey.'='.rawurlencode($page[$theKey]);
1211 $page[$theKey] = $theNewVal;
1214 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
1215 if (trim($GLOBALS['TSFE']->MP_defaults
[$page['uid']]) && !strstr($addParams,'&MP=')) {
1216 $addParams.='&MP='.rawurlencode(trim($GLOBALS['TSFE']->MP_defaults
[$page['uid']]));
1218 // Setting ID/alias:
1219 if (!$script) {$script = $GLOBALS['TSFE']->config
['mainScript'];}
1220 if ($page['alias']) {
1221 $LD['url']=$script.'?id='.$page['alias'];
1223 $LD['url']=$script.'?id='.$page['uid'];
1226 $LD['target']= trim($page['target']) ?
trim($page['target']) : $oTarget;
1229 $typeNum = $this->setup
[$LD['target'].'.']['typeNum'];
1230 if (!$typeOverride && intval($GLOBALS['TSFE']->config
['config']['forceTypeValue'])) {
1231 $typeOverride=intval($GLOBALS['TSFE']->config
['config']['forceTypeValue']);
1233 if (strcmp($typeOverride,'')) {$typeNum=$typeOverride;} // Override...
1235 $LD['type']='&type='.intval($typeNum);
1239 $LD['orig_type'] = $LD['type']; // Preserving the type number. Will not be cleared if simulateStaticDocuments.
1242 $LD['no_cache'] = (trim($page['no_cache']) ||
$no_cache) ?
'&no_cache=1' : '';
1245 $LD['linkVars']= $GLOBALS['TSFE']->linkVars
.$addParams;
1247 // If simulateStaticDocuments is enabled:
1248 if ($GLOBALS['TSFE']->config
['config']['simulateStaticDocuments']) {
1252 // MD5/base64 method limitation:
1254 $flag_simulateStaticDocuments_pEnc = t3lib_div
::inList('md5,base64',$GLOBALS['TSFE']->config
['config']['simulateStaticDocuments_pEnc']) && !$LD['no_cache'];
1255 if ($flag_simulateStaticDocuments_pEnc) {
1256 list($LD['linkVars'], $remainLinkVars) = $GLOBALS['TSFE']->simulateStaticDocuments_pEnc_onlyP_proc($LD['linkVars']);
1259 $LD['url'].=$GLOBALS['TSFE']->makeSimulFileName($page['title'],
1260 $page['alias'] ?
$page['alias'] : $page['uid'],
1263 $LD['no_cache']?
1:0);
1265 if ($flag_simulateStaticDocuments_pEnc) {
1266 $LD['linkVars']=$remainLinkVars;
1268 if ($GLOBALS['TSFE']->config
['config']['simulateStaticDocuments']=='PATH_INFO') {
1269 $LD['url'] = str_replace('.','/',$LD['url']);
1270 $LD['url'] = 'index.php/'.$LD['url'].'/?';
1272 $LD['url'].= '.html?';
1276 // Add absRefPrefix if exists.
1277 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix
.$LD['url'];
1279 // 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.
1280 $LD['sectionIndex'] = $page['sectionIndex_uid'] ?
'#'.$page['sectionIndex_uid'] : '';
1282 // Compile the normal total url
1283 $LD['totalURL']= $this->removeQueryString($LD['url'].$LD['type'].$LD['no_cache'].$LD['linkVars'].$GLOBALS['TSFE']->getMethodUrlIdToken
).$LD['sectionIndex'];
1285 // Return the LD-array
1290 * Removes the "?" of input string IF the "?" is the last character.
1292 * @param string Input string
1293 * @return string Output string, free of "?" in the end, if any such character.
1294 * @see linkData(), tslib_frameset::frameParams()
1296 function removeQueryString($url) {
1297 if (substr($url,-1)=='?') {
1298 return substr($url,0,-1);
1305 * 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.
1306 * Call it like t3lib_TStemplate::sortedKeyList()
1308 * @param array TypoScript array with numerical array in
1309 * @return array An array with all integer properties listed in numeric order.
1310 * @see tslib_cObj::cObjGet(), tslib_gifBuilder, tslib_imgmenu::makeImageMap()
1312 function sortedKeyList($setupArr) {
1315 while(list($key,)=each($setupArr)) {
1317 if (!strcmp($ikey,$key)) {
1327 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tstemplate.php']) {
1328 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);