From 57b496a33474106945e43fc2307b5078e17c92a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kasper=20Sk=C3=A5rh=C3=B8j?= Date: Wed, 12 Nov 2003 09:56:41 +0000 Subject: [PATCH] Added an object path in Page TSconfig called "TSFE.constants" which allows developers to set defaults for TypoScript Template constants from the Page TSconfig fields. Useful for shared configuration between frontend and backend. git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@55 709f56b5-9817-0410-a4d7-c38de5d9e867 --- t3lib/class.t3lib_tsparser_ext.php | 1 + t3lib/class.t3lib_tstemplate.php | 48 +++++++++++++++++++---- typo3/sysext/cms/tslib/class.tslib_fe.php | 4 ++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/t3lib/class.t3lib_tsparser_ext.php b/t3lib/class.t3lib_tsparser_ext.php index 0c4d688b4d88..66038047bb56 100755 --- a/t3lib/class.t3lib_tsparser_ext.php +++ b/t3lib/class.t3lib_tsparser_ext.php @@ -277,6 +277,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate { $constants = t3lib_div::makeInstance("t3lib_TSparser"); $constants->regComments=1; // Register comments! $constants->setup = $this->const; + $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup); $matchObj = t3lib_div::makeInstance("t3lib_matchCondition"); // $matchObj->matchAlternative = array("[globalString = page | title = *test*]"); diff --git a/t3lib/class.t3lib_tstemplate.php b/t3lib/class.t3lib_tstemplate.php index 9b53db1e726b..f8dee8437590 100755 --- a/t3lib/class.t3lib_tstemplate.php +++ b/t3lib/class.t3lib_tstemplate.php @@ -169,6 +169,8 @@ class t3lib_TStemplate { var $nextLevel=0; // Next-level flag (see runThroughTemplates()) var $rootId; // The Page UID of the root page var $rootLine; // The rootline from current page to the root page + var $absoluteRootLine; // Rootline all the way to the root. Set but runThroughTemplates + var $outermostRootlineIndexWithTemplate=0; // A pointer to the last entry in the rootline where a template was found. var $rowSum; // Array of arrays with title/uid of templates in hierarchy var $resources=''; // Resources for the template hierarchy in a comma list var $sitetitle=''; // The current site title field. @@ -390,28 +392,31 @@ class t3lib_TStemplate { $this->config = Array(); $this->editorcfg = Array(); $this->rowSum = Array(); - - reset ($theRootLine); - $c=count($theRootLine); + $this->absoluteRootLine=$theRootLine; // Is the TOTAL rootline + + reset ($this->absoluteRootLine); + $c=count($this->absoluteRootLine); for ($a=0;$a<$c;$a++) { if ($this->nextLevel) { // If some template loaded before has set a template-id for the next level, then load this template first! $res = mysql(TYPO3_db, 'SELECT * FROM sys_template WHERE uid='.intval($this->nextLevel).' '.$this->whereClause); $this->nextLevel = 0; if ($row = mysql_fetch_assoc($res)) { - $this->processTemplate($row,'sys_'.$row['uid'],$theRootLine[$a]['uid'],'sys_'.$row['uid']); + $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']); + $this->outermostRootlineIndexWithTemplate=$a; } } $addC=''; if ($a==($c-1) && $start_template_uid) { // If first loop AND there is set an alternative template uid, use that $addC=' AND uid='.intval($start_template_uid); } - $query = 'SELECT * FROM sys_template WHERE pid='.$theRootLine[$a]['uid'].$addC.' '.$this->whereClause.' ORDER BY sorting LIMIT 1'; + $query = 'SELECT * FROM sys_template WHERE pid='.$this->absoluteRootLine[$a]['uid'].$addC.' '.$this->whereClause.' ORDER BY sorting LIMIT 1'; $res = mysql(TYPO3_db, $query); if ($row = mysql_fetch_assoc($res)) { - $this->processTemplate($row,'sys_'.$row['uid'],$theRootLine[$a]['uid'],'sys_'.$row['uid']); + $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']); + $this->outermostRootlineIndexWithTemplate=$a; } - $this->rootLine[] = $theRootLine[$a]; + $this->rootLine[] = $this->absoluteRootLine[$a]; } } @@ -675,6 +680,7 @@ class t3lib_TStemplate { array_unshift($this->constants,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']); // Adding default TS/constants array_unshift($this->config,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']); // Adding default TS/setup array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']); // Adding default TS/editorcfg + // Parse the TypoScript code text for include-instructions! $this->procesIncludes(); @@ -692,6 +698,7 @@ class t3lib_TStemplate { $constants = t3lib_div::makeInstance('t3lib_TSparser'); $constants->breakPointLN=intval($this->ext_constants_BRP); $constants->setup = $this->const; + $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup); $matchObj = t3lib_div::makeInstance('t3lib_matchCondition'); $matchObj->matchAlternative = $this->matchAlternative; $matchObj->matchAll = $this->matchAll; // Matches ALL conditions in TypoScript @@ -847,6 +854,33 @@ class t3lib_TStemplate { $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]); } } + + /** + * 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! + * + * @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...) + * @param array Constants array, default input. + * @return array Constants array, modified + */ + function mergeConstantsFromPageTSconfig($constArray) { + $TSdataArray = array(); + $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration: + + for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate;$a++) { + $TSdataArray[]=$this->absoluteRootLine[$a]['TSconfig']; + } + // Parsing the user TS (or getting from cache) + $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray); + $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10)); + + $parseObj = t3lib_div::makeInstance('t3lib_TSparser'); + $parseObj->parse($userTS); + + if (is_array($parseObj->setup['TSFE.']['constants.'])) { + $constArray = t3lib_div::array_merge_recursive_overrule($constArray,$parseObj->setup['TSFE.']['constants.']); + } + return $constArray; + } /** * This flattens a hierarchical TypoScript array to $this->flatSetup diff --git a/typo3/sysext/cms/tslib/class.tslib_fe.php b/typo3/sysext/cms/tslib/class.tslib_fe.php index 148ee6fc981c..5c6f53318d65 100755 --- a/typo3/sysext/cms/tslib/class.tslib_fe.php +++ b/typo3/sysext/cms/tslib/class.tslib_fe.php @@ -1170,7 +1170,11 @@ function getConfigArray() { if (!is_array($this->config) || is_array($this->config['INTincScript']) || $this->forceTemplateParsing) { // If config is not set by the cache (which would be a major mistake somewhere) OR if INTincScripts-include-scripts have been registered, then we must parse the template in order to get it $GLOBALS['TT']->push('Parse template',''); + + // Force parsing, if set?: $this->tmpl->forceTemplateParsing = $this->forceTemplateParsing; + + // Start parsing the TS template. Might return cached version. $this->tmpl->start($this->rootLine); $GLOBALS['TT']->pull(); -- 2.20.1