PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/t3lib/class.t3lib_tstemplate.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 1605 lines | 941 code | 170 blank | 494 comment | 210 complexity | f8002f923c900a0e750b500ab5cd1f70 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  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. * $Id$
  31. * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  32. *
  33. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  34. */
  35. /**
  36. * [CLASS/FUNCTION INDEX of SCRIPT]
  37. *
  38. *
  39. *
  40. * 109: class t3lib_TStemplate
  41. * 211: function init()
  42. * 249: function getCurrentPageData()
  43. * 266: function matching($cc)
  44. * 290: function start($theRootLine)
  45. *
  46. * SECTION: Fetching TypoScript code text for the Template Hierarchy
  47. * 406: function runThroughTemplates($theRootLine,$start_template_uid=0)
  48. * 459: function processTemplate($row, $idList,$pid,$templateID='',$templateParent='')
  49. * 580: function includeStaticTypoScriptSources($idList,$templateID,$pid,$row)
  50. * 642: function addExtensionStatics($idList,$templateID,$pid,$row)
  51. * 675: function prependStaticExtra($subrow)
  52. * 688: function versionOL(&$row)
  53. *
  54. * SECTION: Parsing TypoScript code text from Template Records into PHP array
  55. * 725: function generateConfig()
  56. * 891: function procesIncludes()
  57. * 915: function mergeConstantsFromPageTSconfig($constArray)
  58. * 944: function flattenSetup($setupArray, $prefix, $resourceFlag)
  59. * 968: function substituteConstants($all)
  60. * 991: function substituteConstantsCallBack($matches)
  61. *
  62. * SECTION: Various API functions, used from elsewhere in the frontend classes
  63. * 1022: function splitConfArray($conf,$splitCount)
  64. * 1099: function getFileName($fileFromSetup)
  65. * 1156: function extractFromResources($res,$file)
  66. * 1184: function checkFile($name,$menuArr)
  67. * 1201: function printTitle($title,$no_title=0,$titleFirst=0)
  68. * 1224: function fileContent($fName)
  69. * 1244: function wrap($content,$wrap)
  70. * 1258: function removeQueryString($url)
  71. * 1275: function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE)
  72. *
  73. * SECTION: Functions for creating links
  74. * 1322: function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='')
  75. * 1449: function getFromMPmap($pageId=0)
  76. * 1485: function initMPmap_create($id,$MP_array=array(),$level=0)
  77. *
  78. * TOTAL FUNCTIONS: 28
  79. * (This index is automatically created/updated by the extension "extdeveval")
  80. *
  81. */
  82. /**
  83. * Template object that is responsible for generating the TypoScript template based on template records.
  84. *
  85. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  86. * @package TYPO3
  87. * @subpackage t3lib
  88. * @see t3lib_tsparser, t3lib_matchcondition_abstract
  89. */
  90. class t3lib_TStemplate {
  91. // Debugging, analysis:
  92. var $tt_track = 1; // If set, the global tt-timeobject is used to log the performance.
  93. var $forceTemplateParsing = 0; // If set, the template is always rendered. Used from Admin Panel.
  94. // Backend Analysis modules settings:
  95. 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!
  96. var $matchAll = 0; // If set, the match-class matches everything! Used for backend modules only. Never frontend!
  97. var $parseEditorCfgField = 0; // If set, the Backend Editor Configuration TypoScript is also parsed (this is not needed for the frontend)
  98. var $backend_info = 0;
  99. var $getFileName_backPath = ''; // Set from the backend - used to set an absolute path (PATH_site) so that relative resources are properly found with getFileName()
  100. // Externally set breakpoints (used by Backend Modules)
  101. var $ext_constants_BRP = 0;
  102. var $ext_config_BRP = 0;
  103. var $ext_editorcfg_BRP = 0;
  104. var $ext_regLinenumbers = FALSE;
  105. var $ext_regComments = FALSE;
  106. // Constants:
  107. var $uplPath = 'uploads/tf/';
  108. var $tempPath = 'typo3temp/';
  109. var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
  110. // Set Internally:
  111. var $whereClause = ''; // This MUST be initialized by the init() function
  112. var $debug = 0;
  113. 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.
  114. var $simulationHiddenOrTime = 0; // See init(); Set if preview of some kind is enabled.
  115. var $loaded = 0; // Set, if the TypoScript template structure is loaded and OK, see ->start()
  116. var $setup = array( // Default TypoScript Setup code
  117. 'styles.' => array(
  118. 'insertContent' => 'CONTENT',
  119. 'insertContent.' => array(
  120. 'table' => 'tt_content',
  121. 'select.' => array(
  122. 'orderBy' => 'sorting',
  123. 'where' => 'colPos=0',
  124. 'languageField' => 'sys_language_uid'
  125. )
  126. )
  127. ),
  128. 'config.' => array(
  129. 'extTarget' => '_top',
  130. 'stat' => 1,
  131. 'stat_typeNumList' => '0,1',
  132. 'uniqueLinkVars' => 1
  133. )
  134. );
  135. var $flatSetup = array(
  136. );
  137. var $const = array( // Default TypoScript Constants code:
  138. '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
  139. '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
  140. '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
  141. '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
  142. '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
  143. '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
  144. );
  145. // For fetching TypoScript code from template hierarchy before parsing it. Each array contains code field values from template records/files:
  146. var $config = array(); // Setup field
  147. var $constants = array(); // Constant field
  148. var $editorcfg = array(); // Backend Editor Configuration field
  149. var $hierarchyInfo = array(); // For Template Analyser in backend
  150. var $hierarchyInfoToRoot = array(); // For Template Analyser in backend (setup content only)
  151. var $nextLevel = 0; // Next-level flag (see runThroughTemplates())
  152. var $rootId; // The Page UID of the root page
  153. var $rootLine; // The rootline from current page to the root page
  154. var $absoluteRootLine; // Rootline all the way to the root. Set but runThroughTemplates
  155. var $outermostRootlineIndexWithTemplate = 0; // A pointer to the last entry in the rootline where a template was found.
  156. var $rowSum; // Array of arrays with title/uid of templates in hierarchy
  157. var $resources = ''; // Resources for the template hierarchy in a comma list
  158. var $sitetitle = ''; // The current site title field.
  159. var $sections; // Tracking all conditions found during parsing of TypoScript. Used for the "all" key in currentPageData
  160. var $sectionsMatch; // Tracking all matching conditions found
  161. // Backend: ts_analyzer
  162. var $clearList_const = array();
  163. var $clearList_setup = array();
  164. var $clearList_editorcfg = array();
  165. var $parserErrors = array();
  166. var $setup_constants = array();
  167. // Other:
  168. var $fileCache = array(); // Used by getFileName for caching of references to file resources
  169. 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.
  170. var $MPmap = ''; // Contains mapping of Page id numbers to MP variables.
  171. /**
  172. * Initialize
  173. * MUST be called directly after creating a new template-object
  174. *
  175. * @return void
  176. * @see tslib_fe::initTemplate()
  177. */
  178. function init() {
  179. // $this->whereClause is used only to select templates from sys_template.
  180. // $GLOBALS['SIM_ACCESS_TIME'] is used so that we're able to simulate a later time as a test...
  181. $this->whereClause = 'AND deleted=0 ';
  182. if (!$GLOBALS['TSFE']->showHiddenRecords) {
  183. $this->whereClause .= 'AND hidden=0 ';
  184. }
  185. if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_ACCESS_TIME'] != $GLOBALS['ACCESS_TIME']) { // Set the simulation flag, if simulation is detected!
  186. $this->simulationHiddenOrTime = 1;
  187. }
  188. $this->whereClause .= 'AND (starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ') AND (endtime=0 OR endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
  189. if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
  190. $this->menuclasses = 'tmenu,jsmenu,gmenu';
  191. }
  192. // Sets the paths from where TypoScript resources are allowed to be used:
  193. $this->allowedPaths = array(
  194. 'media/',
  195. $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], // fileadmin/ path
  196. 'uploads/',
  197. 'typo3temp/',
  198. 't3lib/fonts/',
  199. TYPO3_mainDir . 'ext/',
  200. TYPO3_mainDir . 'sysext/',
  201. TYPO3_mainDir . 'contrib/',
  202. 'typo3conf/ext/'
  203. );
  204. if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
  205. $pathArr = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'], TRUE);
  206. foreach ($pathArr as $p) {
  207. // 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.
  208. $this->allowedPaths[] = $p;
  209. }
  210. }
  211. }
  212. /**
  213. * Fetches the "currentPageData" array from cache
  214. *
  215. * NOTE about currentPageData:
  216. * It holds information about the TypoScript conditions along with the list
  217. * of template uid's which is used on the page. In the getFromCache function
  218. * in TSFE, currentPageData is used to evaluate if there is a template and
  219. * if the matching conditions are alright. Unfortunately this does not take
  220. * into account if the templates in the rowSum of currentPageData has
  221. * changed composition, eg. due to hidden fields or start/end time. So if a
  222. * template is hidden or times out, it'll not be discovered unless the page
  223. * is regenerated - at least the this->start function must be called,
  224. * because this will make a new portion of data in currentPageData string.
  225. *
  226. * @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
  227. * @see start(), tslib_fe::getFromCache()
  228. */
  229. function getCurrentPageData() {
  230. $currentPageData = FALSE;
  231. if (TYPO3_UseCachingFramework) {
  232. $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
  233. /* @var $pageSectionCache t3lib_cache_AbstractCache */
  234. $currentPageData = $pageSectionCache->get(
  235. intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
  236. );
  237. } else {
  238. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  239. 'content', 'cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . t3lib_div::md5int($GLOBALS['TSFE']->MP));
  240. if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  241. $currentPageData = unserialize($row['content']);
  242. }
  243. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  244. }
  245. return $currentPageData;
  246. }
  247. /**
  248. * Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
  249. *
  250. * @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array
  251. * @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.
  252. * @see t3lib_matchCondition, tslib_fe::getFromCache()
  253. */
  254. function matching($cc) {
  255. if (is_array($cc['all'])) {
  256. /* @var $matchObj t3lib_matchCondition_frontend */
  257. $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
  258. $matchObj->setRootline((array) $cc['rootLine']);
  259. foreach ($cc['all'] as $key => $pre) {
  260. if ($matchObj->match($pre)) {
  261. $sectionsMatch[$key] = $pre;
  262. }
  263. }
  264. $cc['match'] = $sectionsMatch;
  265. }
  266. return $cc;
  267. }
  268. /**
  269. * This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
  270. * 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.
  271. * Sets $this->setup to the parsed TypoScript template array
  272. *
  273. * @param array The rootline of the current page (going ALL the way to tree root)
  274. * @return void
  275. * @see tslib_fe::getConfigArray()
  276. */
  277. function start($theRootLine) {
  278. if (is_array($theRootLine)) {
  279. $setupData = '';
  280. $hash = '';
  281. // Flag that indicates that the existing data in cache_pagesection
  282. // could be used (this is the case if $TSFE->all is set, and the
  283. // rowSum still matches). Based on this we decide if cache_pagesection
  284. // needs to be updated...
  285. $isCached = FALSE;
  286. $this->runThroughTemplates($theRootLine);
  287. if ($GLOBALS['TSFE']->all) {
  288. $cc = $GLOBALS['TSFE']->all;
  289. // The two rowSums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
  290. if (strcmp(serialize($this->rowSum), serialize($cc['rowSum']))) {
  291. unset($cc); // If the two rowSums differ, we need to re-make the current page data and therefore clear the existing values.
  292. } else {
  293. // If $TSFE->all contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already)
  294. if (!strcmp(serialize($this->rootLine), serialize($cc['rootLine']))) {
  295. $isCached = TRUE;
  296. }
  297. // 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)...
  298. unset($cc['rootLine']);
  299. }
  300. }
  301. // This is about getting the hash string which is used to fetch the cached TypoScript template.
  302. // If there was some cached currentPageData ($cc) then that's good (it gives us the hash).
  303. if (is_array($cc)) {
  304. // If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...)
  305. if (!$cc['match']) {
  306. // TODO: check if this can ever be the case - otherwise remove
  307. $cc = $this->matching($cc);
  308. ksort($cc);
  309. }
  310. $hash = md5(serialize($cc));
  311. } else {
  312. // 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.
  313. $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
  314. $result = t3lib_pageSelect::getHash($rowSumHash);
  315. if ($result) {
  316. $cc = array();
  317. $cc['all'] = unserialize($result);
  318. $cc['rowSum'] = $this->rowSum;
  319. $cc = $this->matching($cc);
  320. ksort($cc);
  321. $hash = md5(serialize($cc));
  322. }
  323. }
  324. if ($hash) {
  325. // Get TypoScript setup array
  326. $setupData = t3lib_pageSelect::getHash($hash);
  327. }
  328. if ($setupData && !$this->forceTemplateParsing) {
  329. // If TypoScript setup structure was cached we unserialize it here:
  330. $this->setup = unserialize($setupData);
  331. } else {
  332. // Make configuration
  333. $this->generateConfig();
  334. // This stores the template hash thing
  335. $cc = array();
  336. $cc['all'] = $this->sections; // All sections in the template at this point is found
  337. $cc['rowSum'] = $this->rowSum; // The line of templates is collected
  338. $cc = $this->matching($cc);
  339. ksort($cc);
  340. $hash = md5(serialize($cc));
  341. // This stores the data.
  342. t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS_TEMPLATE');
  343. if ($this->tt_track) {
  344. $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: ' . strlen(serialize($this->setup)) . ' bytes');
  345. }
  346. $rowSumHash = md5('ROWSUM:' . serialize($this->rowSum));
  347. t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL_CONDITIONS_ALL');
  348. }
  349. // Add rootLine
  350. $cc['rootLine'] = $this->rootLine;
  351. ksort($cc);
  352. // Make global and save
  353. $GLOBALS['TSFE']->all = $cc;
  354. // Matching must be executed for every request, so this must never be part of the pagesection cache!
  355. unset($cc['match']);
  356. if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) { // Only save the data if we're not simulating by hidden/starttime/endtime
  357. $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
  358. if (TYPO3_UseCachingFramework) {
  359. $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
  360. /* @var $pageSectionCache t3lib_cache_AbstractCache */
  361. $pageSectionCache->set(
  362. intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
  363. $cc,
  364. array(
  365. 'pageId_' . intval($GLOBALS['TSFE']->id),
  366. 'mpvarHash_' . $mpvarHash
  367. )
  368. );
  369. } else {
  370. $dbFields = array(
  371. 'content' => serialize($cc),
  372. 'tstamp' => $GLOBALS['EXEC_TIME']
  373. );
  374. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvarHash, $dbFields);
  375. if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
  376. $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
  377. $dbFields['mpvar_hash'] = $mpvarHash;
  378. $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
  379. }
  380. }
  381. }
  382. // If everything OK.
  383. if ($this->rootId && $this->rootLine && $this->setup) {
  384. $this->loaded = 1;
  385. }
  386. }
  387. }
  388. /*******************************************************************
  389. *
  390. * Fetching TypoScript code text for the Template Hierarchy
  391. *
  392. *******************************************************************/
  393. /**
  394. * 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.
  395. * Resets and affects internal variables like $this->constants, $this->config, $this->editorcfg and $this->rowSum
  396. * 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
  397. *
  398. * @param array The rootline of the current page (going ALL the way to tree root)
  399. * @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)
  400. * @return void
  401. * @see start()
  402. */
  403. function runThroughTemplates($theRootLine, $start_template_uid = 0) {
  404. $this->constants = array();
  405. $this->config = array();
  406. $this->editorcfg = array();
  407. $this->rowSum = array();
  408. $this->hierarchyInfoToRoot = array();
  409. $this->absoluteRootLine = $theRootLine; // Is the TOTAL rootline
  410. reset($this->absoluteRootLine);
  411. $c = count($this->absoluteRootLine);
  412. for ($a = 0; $a < $c; $a++) {
  413. if ($this->nextLevel) { // If some template loaded before has set a template-id for the next level, then load this template first!
  414. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . intval($this->nextLevel) . ' ' . $this->whereClause);
  415. $this->nextLevel = 0;
  416. if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  417. $this->versionOL($row);
  418. if (is_array($row)) {
  419. $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
  420. $this->outermostRootlineIndexWithTemplate = $a;
  421. }
  422. }
  423. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  424. }
  425. $addC = '';
  426. if ($a == ($c - 1) && $start_template_uid) { // If first loop AND there is set an alternative template uid, use that
  427. $addC = ' AND uid=' . intval($start_template_uid);
  428. }
  429. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($this->absoluteRootLine[$a]['uid']) . $addC . ' ' . $this->whereClause, '', 'sorting', 1);
  430. if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  431. $this->versionOL($row);
  432. if (is_array($row)) {
  433. $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
  434. $this->outermostRootlineIndexWithTemplate = $a;
  435. }
  436. }
  437. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  438. $this->rootLine[] = $this->absoluteRootLine[$a];
  439. }
  440. $this->processIncludes();
  441. }
  442. /**
  443. * Checks if the template ($row) has some included templates and after including them it fills the arrays with the setup
  444. * Builds up $this->rowSum
  445. *
  446. * @param array A full TypoScript template record (sys_template/static_template/forged "dummy" record made from static template file)
  447. * @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.
  448. * @param array The PID of the input template record
  449. * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
  450. * @param string Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123"
  451. * @return void
  452. * @see runThroughTemplates()
  453. */
  454. function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '') {
  455. // Adding basic template record information to rowSum array
  456. $this->rowSum[] = array($row['uid'], $row['title'], $row['tstamp']);
  457. // Processing "Clear"-flags
  458. if ($row['clear']) {
  459. $clConst = $row['clear'] & 1;
  460. $clConf = $row['clear'] & 2;
  461. if ($clConst) {
  462. $this->constants = array();
  463. $this->clearList_const = array();
  464. }
  465. if ($clConf) {
  466. $this->config = array();
  467. $this->hierarchyInfoToRoot = array();
  468. $this->clearList_setup = array();
  469. $this->editorcfg = array();
  470. $this->clearList_editorcfg = array();
  471. }
  472. }
  473. // Include static records (static_template) or files (from extensions) (#1/2)
  474. // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
  475. if (!$row['includeStaticAfterBasedOn']) {
  476. $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
  477. }
  478. // Include "Based On" sys_templates:
  479. if (trim($row['basedOn'])) { // 'basedOn' is a list of templates to include
  480. // Manually you can put this value in the field and then the based_on ID will be taken from the $_GET var defined by '=....'.
  481. // 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!
  482. // 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.
  483. $basedOn_hackFeature = explode('=', $row['basedOn']);
  484. if ($basedOn_hackFeature[0] == 'EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
  485. $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
  486. if ($id && !t3lib_div::inList($idList, 'sys_' . $id)) { // if $id is not allready included ...
  487. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid=' . $id . ' ' . $this->whereClause);
  488. if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // there was a template, then we fetch that
  489. $this->versionOL($subrow);
  490. if (is_array($subrow)) {
  491. $this->processTemplate($subrow, $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
  492. }
  493. }
  494. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  495. }
  496. } else {
  497. // Normal Operation, which is to include the "based-on" sys_templates,
  498. // if they are not already included, and maintaining the sorting of the templates
  499. $basedOnIds = t3lib_div::intExplode(',', $row['basedOn']);
  500. // skip template if it's already included
  501. foreach ($basedOnIds as $key => $basedOnId) {
  502. if (t3lib_div::inList($idList, 'sys_' . $basedOnId)) {
  503. unset($basedOnIds[$key]);
  504. }
  505. }
  506. $subTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
  507. '*', 'sys_template',
  508. 'uid IN (' . implode(',', $basedOnIds) . ') ' . $this->whereClause,
  509. '', '', '',
  510. 'uid' // the associative array that is returned will contain this field as key
  511. );
  512. // traversing list again to ensure the sorting of the templates
  513. foreach ($basedOnIds as $id) {
  514. if (is_array($subTemplates[$id])) {
  515. $this->versionOL($subTemplates[$id]);
  516. $this->processTemplate($subTemplates[$id], $idList . ',sys_' . $id, $pid, 'sys_' . $id, $templateID);
  517. }
  518. }
  519. }
  520. }
  521. // Include static records (static_template) or files (from extensions) (#2/2)
  522. if ($row['includeStaticAfterBasedOn']) {
  523. $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
  524. }
  525. // Creating hierarchy information; Used by backend analysis tools
  526. $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
  527. 'root' => trim($row['root']),
  528. 'next' => $row['nextLevel'],
  529. 'clConst' => $clConst,
  530. 'clConf' => $clConf,
  531. 'templateID' => $templateID,
  532. 'templateParent' => $templateParent,
  533. 'title' => $row['title'],
  534. 'uid' => $row['uid'],
  535. 'pid' => $row['pid'],
  536. 'configLines' => substr_count($row['config'], LF) + 1
  537. );
  538. // Adding the content of the fields constants (Constants), config (Setup) and editorcfg (Backend Editor Configuration) to the internal arrays.
  539. $this->constants[] = $row['constants'];
  540. $this->config[] = $row['config'];
  541. if ($this->parseEditorCfgField) {
  542. $this->editorcfg[] = $row['editorcfg'];
  543. }
  544. // For backend analysis (Template Analyser) provide the order of added constants/config/editorcfg template IDs
  545. $this->clearList_const[] = $templateID;
  546. $this->clearList_setup[] = $templateID;
  547. if ($this->parseEditorCfgField) {
  548. $this->clearList_editorcfg[] = $templateID;
  549. }
  550. // Add resources and sitetitle if found:
  551. if (trim($row['resources'])) {
  552. $this->resources = $row['resources'] . ',' . $this->resources;
  553. }
  554. if (trim($row['sitetitle'])) {
  555. $this->sitetitle = $row['sitetitle'];
  556. }
  557. // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
  558. if (trim($row['root'])) {
  559. $this->rootId = $pid;
  560. $this->rootLine = array();
  561. }
  562. // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
  563. if ($row['nextLevel']) {
  564. $this->nextLevel = $row['nextLevel'];
  565. } else {
  566. $this->nextLevel = 0;
  567. }
  568. }
  569. /**
  570. * Includes static template records (from static_template table, loaded through a hook) and static template files (from extensions) for the input template record row.
  571. *
  572. * @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.
  573. * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
  574. * @param array The PID of the input template record
  575. * @param array A full TypoScript template record
  576. * @return void
  577. * @see processTemplate()
  578. */
  579. function includeStaticTypoScriptSources($idList, $templateID, $pid, $row) {
  580. // Static Template Records (static_template): include_static is a list of static templates to include
  581. // Call function for link rendering:
  582. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'])) {
  583. $_params = array(
  584. 'idList' => &$idList,
  585. 'templateId' => &$templateID,
  586. 'pid' => &$pid,
  587. 'row' => &$row
  588. );
  589. foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSources'] as $_funcRef) {
  590. t3lib_div::callUserFunction($_funcRef, $_params, $this);
  591. }
  592. }
  593. // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
  594. if (trim($row['include_static_file'])) {
  595. $include_static_fileArr = t3lib_div::trimExplode(',', $row['include_static_file'], TRUE);
  596. foreach ($include_static_fileArr as $ISF_file) { // traversing list
  597. if (substr($ISF_file, 0, 4) == 'EXT:') {
  598. list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2);
  599. if (strcmp($ISF_extKey, '') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath, '')) {
  600. $ISF_localPath = rtrim($ISF_localPath, '/') . '/';
  601. $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey) . $ISF_localPath;
  602. if (@is_dir($ISF_filePath)) {
  603. $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
  604. $subrow = array(
  605. 'constants' => @is_file($ISF_filePath . 'constants.txt') ? t3lib_div::getUrl($ISF_filePath . 'constants.txt') : '',
  606. 'config' => @is_file($ISF_filePath . 'setup.txt') ? t3lib_div::getUrl($ISF_filePath . 'setup.txt') : '',
  607. 'editorcfg' => @is_file($ISF_filePath . 'editorcfg.txt') ? t3lib_div::getUrl($ISF_filePath . 'editorcfg.txt') : '',
  608. 'include_static' => @is_file($ISF_filePath . 'include_static.txt') ? implode(',', array_unique(t3lib_div::intExplode(',', t3lib_div::getUrl($ISF_filePath . 'include_static.txt')))) : '',
  609. 'include_static_file' => @is_file($ISF_filePath . 'include_static_file.txt') ? implode(',', array_unique(explode(',', t3lib_div::getUrl($ISF_filePath . 'include_static_file.txt')))) : '',
  610. 'title' => $ISF_file,
  611. 'uid' => $mExtKey
  612. );
  613. $subrow = $this->prependStaticExtra($subrow);
  614. $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
  615. }
  616. }
  617. }
  618. }
  619. }
  620. $this->addExtensionStatics($idList, $templateID, $pid, $row);
  621. // Include Static Template Records after all other TypoScript has been included.
  622. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'])) {
  623. $_params = array(
  624. 'idList' => &$idList,
  625. 'templateId' => &$templateID,
  626. 'pid' => &$pid,
  627. 'row' => &$row
  628. );
  629. foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['includeStaticTypoScriptSourcesAtEnd'] as $_funcRef) {
  630. t3lib_div::callUserFunction($_funcRef, $_params, $this);
  631. }
  632. }
  633. }
  634. /**
  635. * Adds the default TypoScript files for extensions if any.
  636. *
  637. * @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.
  638. * @param string The id of the current template. Same syntax as $idList ids, eg. "sys_123"
  639. * @param array The PID of the input template record
  640. * @param array A full TypoScript template record
  641. * @return void
  642. * @access private
  643. * @see includeStaticTypoScriptSources()
  644. */
  645. function addExtensionStatics($idList, $templateID, $pid, $row) {
  646. global $TYPO3_LOADED_EXT;
  647. if ($row['static_file_mode'] == 1 || ($row['static_file_mode'] == 0 && substr($templateID, 0, 4) == 'sys_' && $row['root'])) {
  648. foreach ($TYPO3_LOADED_EXT as $extKey => $files) {
  649. if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
  650. $mExtKey = str_replace('_', '', $extKey);
  651. $subrow = array(
  652. 'constants' => $files['ext_typoscript_constants.txt'] ? t3lib_div::getUrl($files['ext_typoscript_constants.txt']) : '',
  653. 'config' => $files['ext_typoscript_setup.txt'] ? t3lib_div::getUrl($files['ext_typoscript_setup.txt']) : '',
  654. 'editorcfg' => $files['ext_typoscript_editorcfg.txt'] ? t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']) : '',
  655. 'title' => $extKey,
  656. 'uid' => $mExtKey
  657. );
  658. $subrow = $this->prependStaticExtra($subrow);
  659. $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
  660. }
  661. }
  662. }
  663. }
  664. /**
  665. * Appends (not prepends) additional TypoScript code to static template records/files as set in TYPO3_CONF_VARS
  666. * For records the "uid" value is the integer of the "static_template" record
  667. * 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
  668. *
  669. * @param array Static template record/file
  670. * @return array Returns the input array where the values for keys "config", "constants" and "editorcfg" may have been modified with prepended code.
  671. * @access private
  672. * @see addExtensionStatics(), includeStaticTypoScriptSources()
  673. */
  674. function prependStaticExtra($subrow) {
  675. $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
  676. $subrow['editorcfg'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
  677. $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
  678. return $subrow;
  679. }
  680. /**
  681. * Creating versioning overlay of a sys_template record. This will use either frontend or backend overlay functionality depending on environment.
  682. *
  683. * @param array Row to overlay.
  684. * @return void Row is passed by reference.
  685. */
  686. function versionOL(&$row) {
  687. if (is_object($GLOBALS['TSFE'])) { // Frontend:
  688. $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
  689. } else { // Backend:
  690. t3lib_BEfunc::workspaceOL('sys_template', $row);
  691. }
  692. }
  693. /*******************************************************************
  694. *
  695. * Parsing TypoScript code text from Template Records into PHP array
  696. *
  697. *******************************************************************/
  698. /**
  699. * Generates the configuration array by replacing constants and parsing the whole thing.
  700. * Depends on $this->config and $this->constants to be set prior to this! (done by processTemplate/runThroughTemplates)
  701. *
  702. * @return void
  703. * @see t3lib_TSparser, start()
  704. */
  705. function generateConfig() {
  706. // Add default TS for all three code types:
  707. array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']); // Adding default TS/constants
  708. array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']); // Adding default TS/setup
  709. array_unshift($this->editorcfg, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']); // Adding default TS/editorcfg
  710. // Parse the TypoScript code text for include-instructions!
  711. $this->processIncludes();
  712. // These vars are also set lateron...
  713. $this->setup['resources'] = $this->resources;
  714. $this->setup['sitetitle'] = $this->sitetitle;
  715. // ****************************
  716. // Parse TypoScript Constants
  717. // ****************************
  718. // Initialize parser and match-condition classes:
  719. $constants = t3lib_div::makeInstance('t3lib_TSparser');
  720. $constants->breakPointLN = intval($this->ext_constants_BRP);
  721. $constants->setup = $this->const;
  722. $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
  723. /* @var $matchObj t3lib_matchCondition_frontend */
  724. $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
  725. $matchObj->setSimulateMatchConditions($this->matchAlternative);
  726. $matchObj->setSimulateMatchResult((bool) $this->matchAll);
  727. // Traverse constants text fields and parse them
  728. foreach ($this->constants as $str) {
  729. $constants->parse($str, $matchObj);
  730. }
  731. // Read out parse errors if any
  732. $this->parserErrors['constants'] = $constants->errors;
  733. // 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)
  734. $this->flatSetup = array();
  735. $this->flattenSetup($constants->setup, '', '');
  736. // ***********************************************
  737. // Parse TypoScript Setup (here called "config")
  738. // ***********************************************
  739. // Initialize parser and match-condition classes:
  740. $config = t3lib_div::makeInstance('t3lib_TSparser');
  741. $config->breakPointLN = intval($this->ext_config_BRP);
  742. $config->regLinenumbers = $this->ext_regLinenumbers;
  743. $config->regComments = $this->ext_regComments;
  744. $config->setup = $this->setup;
  745. // Transfer information about conditions found in "Constants" and which of them returned true.
  746. $config->sections = $constants->sections;
  747. $config->sectionsMatch = $constants->sectionsMatch;
  748. // Traverse setup text fields and concatenate them into one, single string separated by a [GLOBAL] condition
  749. $all = '';
  750. foreach ($this->config as $str) {
  751. $all .= "\n[GLOBAL]\n" . $str;
  752. }
  753. // Substitute constants in the Setup code:
  754. if ($this->tt_track) {
  755. $GLOBALS['TT']->push('Substitute Constants (' . count($this->flatSetup) . ')');
  756. }
  757. $all = $this->substituteConstants($all);
  758. if ($this->tt_track) {
  759. $GLOBALS['TT']->pull();
  760. }
  761. // Searching for possible unsubstituted constants left (only for information)
  762. if (strstr($all, '{$')) {
  763. $theConstList = array();
  764. $findConst = explode('{$', $all);
  765. array_shift($findConst);
  766. foreach ($findConst as $constVal) {
  767. $constLen = t3lib_div::intInRange(strcspn($constVal, '}'), 0, 50);
  768. $theConstList[] = '{$' . substr($constVal, 0, $constLen + 1);
  769. }
  770. if ($this->tt_track) {
  771. $GLOBALS['TT']->setTSlogMessage(implode(', ', $theConstList) . ': Constants may remain un-substituted!!', 2);
  772. }
  773. }
  774. // Logging the textual size of the TypoScript Setup field text with all constants substituted:
  775. if ($this->tt_track) {
  776. $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: ' . strlen($all) . ' bytes');
  777. }
  778. // Finally parse the Setup field TypoScript code (where constants are now substituted)
  779. $config->parse($all, $matchObj);
  780. // Read out parse errors if any
  781. $this->parserErrors['config'] = $config->errors;
  782. // Transfer the TypoScript array from the parser object to the internal $this->setup array:
  783. $this->setup = $config->setup;
  784. if ($this->backend_info) {
  785. $this->setup_constants = $constants->setup; // Used for backend purposes only
  786. }
  787. // **************************************************
  788. // Parse Backend Editor Configuration (backend only)
  789. // **************************************************
  790. if ($this->parseEditorCfgField) {
  791. $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
  792. $editorcfg->breakPointLN = intval($this->ext_editorcfg_BRP);
  793. $editorcfg->setup = array(); // Empty as a start...
  794. $all = implode("\n[GLOBAL]\n", $this->editorcfg);
  795. // substitute constants in config
  796. $all = $this->substituteConstants($all);
  797. // parse Config
  798. $matchObj->matchAll = 1; // This should make sure that conditions are disabled. For now they are NOT active for the backend.
  799. $editorcfg->parse($all, $matchObj);
  800. $this->parserErrors['editorcfg'] = $editorcfg->errors;
  801. $this->setup_editorcfg = $editorcfg->setup;
  802. }
  803. // ****************************************************************
  804. // Final processing of the $this->setup TypoScript Template array
  805. // Basically: This is unsetting/setting of certain reserved keys.
  806. // ****************************************************************
  807. // 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!
  808. unset($this->setup['resources']);
  809. unset($this->setup['resources.']);
  810. $this->setup['resources'] = implode(',', t3lib_div::trimExplode(',', $this->resources, 1));
  811. unset($this->setup['sitetitle']);
  812. unset($this->setup['sitetitle.']);
  813. $this->setup['sitetitle'] = $this->sitetitle;
  814. // Unsetting some vars...
  815. unset($this->setup['types.']);
  816. unset($this->setup['types']);
  817. if (is_array($this->setup)) {
  818. foreach ($this->setup as $key => $value) {
  819. if ($value == 'PAGE') {
  820. // Set the typeNum of the current page object:
  821. if (isset($this->setup[$key . '.']['typeNum'])) {
  822. $typeNum = $this->setup[$key . '.']['typeNum'];
  823. $this->setup['types.'][$typeNum] = $key;
  824. // If there is no type 0 yet and typeNum was not set, we use the current object as the default
  825. } elseif (!isset($this->setup['types.'][0]) || !$this->setup['types.'][0]) {
  826. $this->setup['types.'][0] = $key;
  827. }
  828. }
  829. }
  830. }
  831. unset($this->setup['styles.']);
  832. unset($this->setup['temp.']);
  833. unset($constants);
  834. // Storing the conditions found/matched information:
  835. $this->sections = $config->sections;
  836. $this->sectionsMatch = $config->sectionsMatch;
  837. }
  838. /**
  839. * Searching TypoScript code text (for constants, config (Setup) and editorcfg)
  840. * for include instructions and does the inclusion of external TypoScript files
  841. * if needed.
  842. *
  843. * @return void
  844. * @see t3lib_TSparser, generateConfig()
  845. */
  846. public function processIncludes() {
  847. $files = array();
  848. foreach ($this->constants as &$value) {
  849. $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
  850. $files = array_merge($files, $includeData['files']);
  851. $value = $includeData['typoscript'];
  852. }
  853. foreach ($this->config as &$value) {
  854. $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
  855. $files = array_merge($files, $includeData['files']);
  856. $value = $includeData['typoscript'];
  857. }
  858. foreach ($this->editorcfg as &$value) {
  859. $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
  860. $files = array_merge($files, $includeData['files']);
  861. $value = $includeData['typoscript'];
  862. }
  863. if (count($files)) {
  864. $files = array_unique($files);
  865. foreach ($files as $file) {
  866. $this->rowSum[] = array($file, filemtime($file));
  867. }
  868. }
  869. }
  870. /**
  871. * 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!
  872. *
  873. * @param array Constants array, default input.
  874. * @return array Constants array, modified
  875. * @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...)
  876. */
  877. function mergeConstantsFromPageTSconfig($constArray) {
  878. $TSdataArray = array();
  879. $TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
  880. for ($a = 0; $a <= $this->outermostRootlineIndexWithTemplate; $a++) {
  881. $TSdataArray[] = $this->absoluteRootLine[$a]['TSconfig'];
  882. }
  883. // Parsing the user TS (or getting from cache)
  884. $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
  885. $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
  886. $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
  887. $parseObj->parse($userTS);
  888. if (is_array($parseObj->setup['TSFE.']['constants.'])) {
  889. $constArray = t3lib_div::array_merge_recursive_overrule($constArray, $parseObj->setup['TSFE.']['constants.']);
  890. }
  891. return $constArray;
  892. }
  893. /**
  894. * This flattens a hierarchical TypoScript array to $this->flatSetup
  895. *
  896. * @param array TypoScript array
  897. * @param string Prefix to the object path. Used for recursive calls to this function.
  898. * @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.
  899. * @return void
  900. * @see generateConfig()
  901. */
  902. function flattenSetup($setupArray, $prefix, $resourceFlag) {
  903. if (is_array($setupArray)) {
  904. foreach ($setupArray as $key => $val) {
  905. if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
  906. if (is_array($val)) {
  907. $this->flattenSetup($val, $prefix . $key, ($key == 'file.'));
  908. } elseif ($resourceFlag) {
  909. $this->flatSetup[$prefix . $key] = $this->getFileName($val);
  910. } else {
  911. $this->flatSetup[$prefix . $key] = $val;
  912. }
  913. }
  914. }
  915. }
  916. }
  917. /**
  918. * Substitutes the constants from $this->flatSetup in the text string $all
  919. *
  920. * @param string TypoScript code text string
  921. * @return string The processed string with all constants found in $this->flatSetup as key/value pairs substituted.
  922. * @see generateConfig(), flattenSetup()
  923. */
  924. function substituteConstants($all) {
  925. if ($this->tt_track) {
  926. $GLOBALS['TT']->setTSlogMessage('Constants to substitute: ' . count($this->flatSetup));
  927. }
  928. $noChange = FALSE;
  929. // recursive substitution of constants (up to 10 nested levels)
  930. for ($i = 0; $i < 10 && !$noChange; $i++) {
  931. $old_all = $all;
  932. $all = preg_replace_callback('/\{\$(.[^}]*)\}/', array($this, 'substituteConstantsCallBack'), $all);
  933. if ($old_all == $all) {
  934. $noChange = TRUE;
  935. }
  936. }
  937. return $all;
  938. }
  939. /**
  940. * Call back method for preg_replace_callback in substituteConstants
  941. *
  942. * @param array Regular expression matches
  943. * @return string Replacement
  944. * @see substituteConstants()
  945. */
  946. function substituteConstantsCallBack($matches) {
  947. // replace {$CONST} if found in $this->flatSetup, else leave unchanged
  948. return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
  949. }
  950. /*******************************************************************
  951. *
  952. * Various API functions, used from elsewhere in the frontend classes
  953. *
  954. *******************************************************************/
  955. /**
  956. * Implementation of the "optionSplit" feature in TypoScript (used eg. for MENU objects)
  957. * 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.
  958. * The concept is known as "optionSplit" and is rather advanced to handle but quite powerful, in particular for creating menus in TYPO3.
  959. *
  960. * @param array A TypoScript array
  961. * @param integer The number of items for which to generated individual TypoScript arrays
  962. * @return array The individualized TypoScript array.
  963. * @see tslib_cObj::IMGTEXT(), tslib_menu::procesItemStates()
  964. */
  965. function splitConfArray($conf, $splitCount) {
  966. // Initialize variables:
  967. $splitCount = intval($splitCount);
  968. $conf2 = array();
  969. if ($splitCount && is_array($conf)) {
  970. // Initialize output to carry at least the keys:
  971. for ($aKey = 0; $aKey < $splitCount; $aKey++) {
  972. $conf2[$aKey] = array();
  973. }
  974. // Recursive processing of array keys:
  975. foreach ($conf as $cKey => $val) {
  976. if (is_array($val)) {
  977. $tempConf = $this->splitConfArray($val, $splitCount);
  978. foreach ($tempConf as $aKey => $val) {
  979. $conf2[$aKey][$cKey] = $val;
  980. }
  981. } else {
  982. // Splitting of all values on this level of the TypoScript object tree:
  983. if (!strstr($val, '|*|') && !strstr($val, '||')) {
  984. for ($aKey = 0; $aKey < $splitCount; $aKey++) {
  985. $conf2[$aKey][$cKey] = $val;
  986. }
  987. } else {
  988. $main = explode('|*|', $val);
  989. $mainCount = count($main);
  990. $lastC = 0;
  991. $middleC = 0;
  992. $firstC = 0;
  993. if ($main[0]) {
  994. $first = explode('||', $main[0]);
  995. $firstC = count($first);
  996. }
  997. if ($main[1]) {
  998. $middle = explode('||', $main[1]);
  999. $middleC = count($middle);
  1000. }
  1001. if ($main[2]) {
  1002. $last = explode('||', $main[2]);
  1003. $lastC = count($last);
  1004. $value = $last[0];
  1005. }
  1006. for ($aKey = 0; $aKey < $splitCount; $aKey++) {
  1007. if ($firstC && isset($first[$aKey])) {
  1008. $value = $first[$aKey];
  1009. } elseif ($middleC) {
  1010. $value = $middle[($aKey - $firstC) % $middleC];
  1011. }
  1012. if ($lastC && $lastC >= ($splitCount - $aKey)) {
  1013. $value = $last[$lastC - ($splitCount - $aKey)];
  1014. }
  1015. $conf2[$aKey][$cKey] = trim($value);
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. return $conf2;
  1022. }
  1023. /**
  1024. * Returns the reference to a 'resource' in TypoScript.
  1025. * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list
  1026. *
  1027. * @param string TypoScript "resource" data type value.
  1028. * @return string Resulting filename, if any.
  1029. */
  1030. functi

Large files files are truncated, but you can click here to view the full file