PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/eztemplate/classes/eztemplatecompiler.php

https://github.com/aurelienRT1/ezpublish
PHP | 3357 lines | 3130 code | 53 blank | 174 comment | 55 complexity | 719270ac1b739ddefeca5ba57668cdfd MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0

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

  1. <?php
  2. //
  3. // Definition of eZTemplateCompiler class
  4. //
  5. // Created on: <06-Dec-2002 14:17:10 amos>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \file
  31. */
  32. /*!
  33. \class eZTemplateCompiler eztemplatecompiler.php
  34. \brief Creates compiled PHP code from templates to speed up template usage.
  35. Various optimizations that can be done are:
  36. Data:
  37. - Is constant, generate static data
  38. - Is variable, generate direct variable extraction
  39. - Has operators
  40. - Has attributes
  41. Attributes:
  42. - Is constant, generate static data
  43. Operators:
  44. - Supports input
  45. - Supports output
  46. - Supports parameters
  47. - Generates static data (true, false)
  48. - Custom PHP code
  49. - Modifies template variables, if possible name which ones. Allows
  50. for caching of variables in the script.
  51. Functions:
  52. - Supports parameters
  53. - Supports children (set? no, section? yes)
  54. - Generates static data (ldelim,rdelim)
  55. - Children usage, no result(set-block) | copy(let,default) | dynamic(conditional, repeated etc.)
  56. - Children tree, requires original tree | allows custom processing
  57. - Custom PHP code
  58. - Deflate/transform tree, create new non-nested tree (let, default)
  59. - Modifies template variables, if possible name which ones. Allows
  60. for caching of variables in the script.
  61. */
  62. class eZTemplateCompiler
  63. {
  64. const CODE_DATE = 1074699607;
  65. /*!
  66. \static
  67. Returns the prefix for file names
  68. */
  69. static function TemplatePrefix()
  70. {
  71. $templatePrefix = '';
  72. $ini = eZINI::instance();
  73. if ( $ini->variable( 'TemplateSettings', 'TemplateCompression' ) == 'enabled' )
  74. {
  75. $templatePrefix = 'compress.zlib://';
  76. }
  77. return $templatePrefix;
  78. }
  79. /*!
  80. \static
  81. Sets/unsets various compiler settings. To set a setting add a key in the \a $settingsMap
  82. with the wanted value, to unset it use \c null as the value.
  83. The following values can be set.
  84. - compile - boolean, whether to compile templates or not
  85. - comments - boolean, whether to include comments in templates
  86. - accumulators - boolean, whether to include debug accumulators in templates
  87. - timingpoints - boolean, whether to include debug timingpoints in templates
  88. - fallbackresource - boolean, whether to include the fallback resource code
  89. - nodeplacement - boolean, whether to include information on placement of all nodes
  90. - execution - boolean, whether to execute the compiled templates or not
  91. - generate - boolean, whether to always generate the compiled files, or only when template is changed
  92. - compilation-directory - string, where to place compiled files, the path will be relative from the
  93. eZ Publish directory and not the var/cache directory.
  94. */
  95. static function setSettings( $settingsMap )
  96. {
  97. $existingMap = array();
  98. if ( isset( $GLOBALS['eZTemplateCompilerSettings'] ) )
  99. {
  100. $existingMap = $GLOBALS['eZTemplateCompilerSettings'];
  101. }
  102. $GLOBALS['eZTemplateCompilerSettings'] = array_merge( $existingMap, $settingsMap );
  103. }
  104. /*!
  105. \static
  106. \return true if template compiling is enabled.
  107. \note To change this setting edit settings/site.ini and locate the group TemplateSettings and the entry TemplateCompile.
  108. */
  109. static function isCompilationEnabled()
  110. {
  111. if ( isset( $GLOBALS['eZSiteBasics'] ) )
  112. {
  113. $siteBasics = $GLOBALS['eZSiteBasics'];
  114. if ( isset( $siteBasics['no-cache-adviced'] ) and
  115. $siteBasics['no-cache-adviced'] )
  116. {
  117. return false;
  118. }
  119. }
  120. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['compile'] ) and
  121. $GLOBALS['eZTemplateCompilerSettings']['compile'] !== null )
  122. {
  123. return $GLOBALS['eZTemplateCompilerSettings']['compile'];
  124. }
  125. $ini = eZINI::instance();
  126. $compilationEnabled = $ini->variable( 'TemplateSettings', 'TemplateCompile' ) == 'enabled';
  127. return $compilationEnabled;
  128. }
  129. /*!
  130. \static
  131. \return true if template compilation should include comments.
  132. */
  133. static function isCommentsEnabled()
  134. {
  135. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['comments'] ) and
  136. $GLOBALS['eZTemplateCompilerSettings']['comments'] !== null )
  137. {
  138. return $GLOBALS['eZTemplateCompilerSettings']['comments'];
  139. }
  140. $ini = eZINI::instance();
  141. $commentsEnabled = $ini->variable( 'TemplateSettings', 'CompileComments' ) == 'enabled';
  142. return $commentsEnabled;
  143. }
  144. /*!
  145. \static
  146. \return true if template compilation should run in development mode.
  147. When in development mode the system will perform additional checks, e.g. for
  148. modification time of compiled file vs original source file.
  149. This mode is quite useful for development since it requires less
  150. clear-cache calls but has additional file checks and should be turned off
  151. for live sites.
  152. */
  153. static function isDevelopmentModeEnabled()
  154. {
  155. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['development_mode'] ) and
  156. $GLOBALS['eZTemplateCompilerSettings']['development_mode'] !== null )
  157. {
  158. return $GLOBALS['eZTemplateCompilerSettings']['development_mode'];
  159. }
  160. $ini = eZINI::instance();
  161. $developmentModeEnabled = $ini->variable( 'TemplateSettings', 'DevelopmentMode' ) == 'enabled';
  162. return $developmentModeEnabled;
  163. }
  164. /*!
  165. \static
  166. \return true if template compilation should include debug accumulators.
  167. */
  168. static function isAccumulatorsEnabled()
  169. {
  170. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['accumulators'] ) and
  171. $GLOBALS['eZTemplateCompilerSettings']['accumulators'] !== null )
  172. {
  173. return $GLOBALS['eZTemplateCompilerSettings']['accumulators'];
  174. }
  175. $ini = eZINI::instance();
  176. $enabled = $ini->variable( 'TemplateSettings', 'CompileAccumulators' ) == 'enabled';
  177. return $enabled;
  178. }
  179. /*!
  180. \static
  181. \return true if template compilation should include debug timing points.
  182. */
  183. static function isTimingPointsEnabled()
  184. {
  185. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['timingpoints'] ) and
  186. $GLOBALS['eZTemplateCompilerSettings']['timingpoints'] !== null )
  187. {
  188. return $GLOBALS['eZTemplateCompilerSettings']['timingpoints'];
  189. }
  190. $ini = eZINI::instance();
  191. $enabled = $ini->variable( 'TemplateSettings', 'CompileTimingPoints' ) == 'enabled';
  192. return $enabled;
  193. }
  194. /*!
  195. \static
  196. \return true if resource fallback code should be included.
  197. */
  198. static function isFallbackResourceCodeEnabled()
  199. {
  200. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['fallbackresource'] ) and
  201. $GLOBALS['eZTemplateCompilerSettings']['fallbackresource'] !== null )
  202. {
  203. return $GLOBALS['eZTemplateCompilerSettings']['fallbackresource'];
  204. }
  205. $ini = eZINI::instance();
  206. $enabled = $ini->variable( 'TemplateSettings', 'CompileResourceFallback' ) == 'enabled';
  207. return $enabled;
  208. }
  209. /*!
  210. \static
  211. \return true if template compilation should include comments.
  212. */
  213. static function isNodePlacementEnabled()
  214. {
  215. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['nodeplacement'] ) and
  216. $GLOBALS['eZTemplateCompilerSettings']['nodeplacement'] !== null )
  217. {
  218. return $GLOBALS['eZTemplateCompilerSettings']['nodeplacement'];
  219. }
  220. $ini = eZINI::instance();
  221. $nodePlacementEnabled = $ini->variable( 'TemplateSettings', 'CompileNodePlacements' ) == 'enabled';
  222. return $nodePlacementEnabled;
  223. }
  224. /*!
  225. \static
  226. \return true if the compiled template execution is enabled.
  227. */
  228. static function isExecutionEnabled()
  229. {
  230. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['execution'] ) and
  231. $GLOBALS['eZTemplateCompilerSettings']['execution'] !== null )
  232. {
  233. return $GLOBALS['eZTemplateCompilerSettings']['execution'];
  234. }
  235. $ini = eZINI::instance();
  236. $execution = $ini->variable( 'TemplateSettings', 'CompileExecution' ) == 'enabled';
  237. return $execution;
  238. }
  239. /*!
  240. \static
  241. \return true if template compilation should always be run even if a sufficient compilation already exists.
  242. */
  243. static function alwaysGenerate()
  244. {
  245. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['generate'] ) and
  246. $GLOBALS['eZTemplateCompilerSettings']['generate'] !== null )
  247. {
  248. return $GLOBALS['eZTemplateCompilerSettings']['generate'];
  249. }
  250. $ini = eZINI::instance();
  251. $alwaysGenerate = $ini->variable( 'TemplateSettings', 'CompileAlwaysGenerate' ) == 'enabled';
  252. return $alwaysGenerate;
  253. }
  254. /*!
  255. \static
  256. \return true if template node tree named \a $treeName should be included the compiled template.
  257. */
  258. static function isTreeEnabled( $treeName )
  259. {
  260. $ini = eZINI::instance();
  261. $treeList = $ini->variable( 'TemplateSettings', 'CompileIncludeNodeTree' );
  262. return in_array( $treeName, $treeList );
  263. }
  264. /*!
  265. \static
  266. \return the directory for compiled templates.
  267. */
  268. static function compilationDirectory()
  269. {
  270. if ( isset( $GLOBALS['eZTemplateCompilerSettings']['compilation-directory'] ) and
  271. $GLOBALS['eZTemplateCompilerSettings']['compilation-directory'] !== null )
  272. {
  273. return $GLOBALS['eZTemplateCompilerSettings']['compilation-directory'];
  274. }
  275. $compilationDirectory =& $GLOBALS['eZTemplateCompilerDirectory'];
  276. if ( !isset( $compilationDirectory ) )
  277. {
  278. $ini = eZINI::instance();
  279. $shareTemplates = $ini->hasVariable( 'TemplateSettings', 'ShareCompiledTemplates' ) ?
  280. $ini->variable( 'TemplateSettings', 'ShareCompiledTemplates' ) == 'enabled' :
  281. false;
  282. if ( $shareTemplates &&
  283. $ini->hasVariable( 'TemplateSettings', 'SharedCompiledTemplatesDir' ) &&
  284. trim( $ini->variable( 'TemplateSettings', 'SharedCompiledTemplatesDir' ) ) != '' )
  285. {
  286. $compilationDirectory = eZDir::path( array( $ini->variable( 'TemplateSettings', 'SharedCompiledTemplatesDir' ) ) );
  287. }
  288. else
  289. {
  290. $compilationDirectory = eZDir::path( array( eZSys::cacheDirectory(), 'template/compiled' ) );
  291. }
  292. }
  293. return $compilationDirectory;
  294. }
  295. /*!
  296. Creates the name for the compiled template and returns it.
  297. The name conists of original filename with the md5 of the key and charset appended.
  298. */
  299. static function compilationFilename( $key, $resourceData )
  300. {
  301. $internalCharset = eZTextCodec::internalCharset();
  302. $templateFilepath = $resourceData['template-filename'];
  303. $extraName = '';
  304. if ( preg_match( "#^.+/(.*)\.tpl$#", $templateFilepath, $matches ) )
  305. $extraName = $matches[1] . '-';
  306. else if ( preg_match( "#^(.*)\.tpl$#", $templateFilepath, $matches ) )
  307. $extraName = $matches[1] . '-';
  308. $accessText = false;
  309. if ( isset( $GLOBALS['eZCurrentAccess']['name'] ) )
  310. $accessText = '-' . $GLOBALS['eZCurrentAccess']['name'];
  311. $locale = eZLocale::instance();
  312. $language = $locale->localeFullCode();
  313. $http = eZHTTPTool::instance();
  314. $useFullUrlText = $http->UseFullUrl ? 'full' : 'relative';
  315. $pageLayoutVariable = "";
  316. if ( isset( $GLOBALS['eZCustomPageLayout'] ) )
  317. $pageLayoutVariable = $GLOBALS['eZCustomPageLayout'];
  318. $ini = eZINI::instance();
  319. $shareTemplates = $ini->hasVariable( 'TemplateSettings', 'ShareCompiledTemplates' ) ?
  320. $ini->variable( 'TemplateSettings', 'ShareCompiledTemplates' ) == 'enabled' :
  321. false;
  322. if ( $shareTemplates )
  323. $cacheFileKey = $key . '-' . $language;
  324. else
  325. $cacheFileKey = $key . '-' . $internalCharset . '-' . $language . '-' . $useFullUrlText . $accessText . "-" . $pageLayoutVariable . '-' . eZSys::indexFile();
  326. $cacheFileName = $extraName . md5( $cacheFileKey ) . '.php';
  327. return $cacheFileName;
  328. }
  329. /*!
  330. \static
  331. \return true if the compiled template with the key \a $key exists.
  332. A compiled template is found usable when it exists and has a timestamp
  333. higher or equal to \a $timestamp.
  334. */
  335. static function hasCompiledTemplate( $key, $timestamp, &$resourceData )
  336. {
  337. if ( !eZTemplateCompiler::isCompilationEnabled() )
  338. return false;
  339. if ( eZTemplateCompiler::alwaysGenerate() )
  340. return false;
  341. $cacheFileName = eZTemplateCompiler::compilationFilename( $key, $resourceData );
  342. $php = new eZPHPCreator( eZTemplateCompiler::compilationDirectory(), $cacheFileName, eZTemplateCompiler::TemplatePrefix() );
  343. $canRestore = $php->canRestore( $timestamp );
  344. $uri = false;
  345. if ( $canRestore )
  346. eZDebugSetting::writeDebug( 'eztemplate-compile', "Cache hit for uri '$uri' with key '$key'", 'eZTemplateCompiler::hasCompiledTemplate' );
  347. else
  348. eZDebugSetting::writeDebug( 'eztemplate-compile', "Cache miss for uri '$uri' with key '$key'", 'eZTemplateCompiler::hasCompiledTemplate' );
  349. return $canRestore;
  350. }
  351. /*!
  352. Tries to execute the compiled template and returns \c true if succsesful.
  353. Returns \c false if caching is disabled or the compiled template could not be executed.
  354. */
  355. static function executeCompilation( $tpl, &$textElements, $key, &$resourceData,
  356. $rootNamespace, $currentNamespace )
  357. {
  358. if ( !eZTemplateCompiler::isCompilationEnabled() )
  359. return false;
  360. if ( !eZTemplateCompiler::isExecutionEnabled() )
  361. return false;
  362. $cacheFileName = eZTemplateCompiler::compilationFilename( $key, $resourceData );
  363. $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
  364. $directory = eZTemplateCompiler::compilationDirectory();
  365. $phpScript = eZDir::path( array( $directory, $cacheFileName ) );
  366. if ( file_exists( $phpScript ) )
  367. {
  368. $text = false;
  369. $helperStatus = eZTemplateCompiler::executeCompilationHelper( $phpScript, $text,
  370. $tpl, $key, $resourceData,
  371. $rootNamespace, $currentNamespace );
  372. if ( $helperStatus )
  373. {
  374. $textElements[] = $text;
  375. return true;
  376. }
  377. else
  378. eZDebug::writeError( "Failed executing compiled template '$phpScript'", 'eZTemplateCompiler::executeCompilation' );
  379. }
  380. else
  381. eZDebug::writeError( "Unknown compiled template '$phpScript'", 'eZTemplateCompiler::executeCompilation' );
  382. return false;
  383. }
  384. /*!
  385. Helper function for executeCompilation. Will execute the script \a $phpScript and
  386. set the result text in \a $text.
  387. The parameters \a $tpl, \a $resourceData, \a $rootNamespace and \a $currentNamespace
  388. are passed to the executed template compilation script.
  389. \return true if a text result was created.
  390. */
  391. static function executeCompilationHelper( $phpScript, &$text,
  392. $tpl, $key, &$resourceData,
  393. $rootNamespace, $currentNamespace )
  394. {
  395. $vars =& $tpl->Variables;
  396. /* We use $setArray to detect if execution failed, and not $text,
  397. * because an empty template does not return any $text and this is not
  398. * an error. */
  399. $setArray = null;
  400. $namespaceStack = array();
  401. $tpl->createLocalVariablesList();
  402. include( eZTemplateCompiler::TemplatePrefix() . $phpScript );
  403. $tpl->unsetLocalVariables();
  404. $tpl->destroyLocalVariablesList();
  405. if ( $setArray !== null )
  406. {
  407. return true;
  408. }
  409. return false;
  410. }
  411. /*!
  412. \static
  413. Generates the cache which will be used for handling optimized processing using the key \a $key.
  414. \note Each call to this will set the PHP time limit to 30
  415. \return false if the cache does not exist.
  416. */
  417. static function compileTemplate( $tpl, $key, &$resourceData )
  418. {
  419. if ( !eZTemplateCompiler::isCompilationEnabled() )
  420. return false;
  421. $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
  422. $cacheFileName = eZTemplateCompiler::compilationFilename( $key, $resourceData );
  423. $resourceData['uniqid'] = md5( $resourceData['template-filename']. uniqid( "ezp". getmypid(), true ) );
  424. // Time limit #1:
  425. // We reset the time limit to 30 seconds to ensure that templates
  426. // have enough time to compile
  427. // However if time limit is unlimited (0) we leave it be
  428. // Time limit will also be reset after subtemplates are compiled
  429. $maxExecutionTime = ini_get( 'max_execution_time' );
  430. if ( $maxExecutionTime != 0 && $maxExecutionTime < 30 )
  431. {
  432. @set_time_limit( 30 );
  433. }
  434. $rootNode =& $resourceData['root-node'];
  435. if ( !$rootNode )
  436. return false;
  437. $GLOBALS['eZTemplateCompilerResourceCache'][$resourceData['template-filename']] =& $resourceData;
  438. $useComments = eZTemplateCompiler::isCommentsEnabled();
  439. if ( !$resourceData['test-compile'] )
  440. {
  441. eZTemplateCompiler::createCommonCompileTemplate();
  442. }
  443. /* Check if we need to disable the generation of spacing for the compiled templates */
  444. $ini = eZINI::instance();
  445. $spacing = 'disabled';
  446. if ( $ini->variable( 'TemplateSettings', 'UseFormatting' ) == 'enabled' )
  447. {
  448. $spacing = 'enabled';
  449. }
  450. $php = new eZPHPCreator( eZTemplateCompiler::compilationDirectory(), $cacheFileName,
  451. eZTemplateCompiler::TemplatePrefix(), array( 'spacing' => $spacing ) );
  452. $php->addComment( 'URI: ' . $resourceData['uri'] );
  453. $php->addComment( 'Filename: ' . $resourceData['template-filename'] );
  454. $php->addComment( 'Timestamp: ' . $resourceData['time-stamp'] . ' (' . date( 'D M j G:i:s T Y', $resourceData['time-stamp'] ) . ')' );
  455. $php->addCodePiece("\$oldSetArray_{$resourceData['uniqid']} = isset( \$setArray ) ? \$setArray : array();\n".
  456. "\$setArray = array();\n");
  457. // Code to decrement include level of the templates
  458. $php->addCodePiece( "\$tpl->Level++;\n" );
  459. $php->addCodePiece( "if ( \$tpl->Level > $tpl->MaxLevel )\n".
  460. "{\n".
  461. "\$text = \$tpl->MaxLevelWarning;".
  462. "\$tpl->Level--;\n".
  463. "return;\n".
  464. "}\n" );
  465. if ( $resourceData['locales'] && count( $resourceData['locales'] ) )
  466. {
  467. $php->addComment( 'Locales: ' . join( ', ', $resourceData['locales'] ) );
  468. $php->addCodePiece(
  469. '$locales = array( "'. join( '", "', $resourceData['locales'] ) . "\" );\n".
  470. '$oldLocale_'. $resourceData['uniqid']. ' = setlocale( LC_CTYPE, null );'. "\n".
  471. '$currentLocale_'. $resourceData['uniqid']. ' = setlocale( LC_CTYPE, $locales );'. "\n"
  472. );
  473. }
  474. // $php->addCodePiece( "print( \"" . $resourceData['template-filename'] . " ($cacheFileName)<br/>\n\" );" );
  475. if ( $useComments )
  476. {
  477. $templateFilename = $resourceData['template-filename'];
  478. if ( file_exists( $templateFilename ) )
  479. {
  480. $fd = fopen( $templateFilename, 'rb' );
  481. if ( $fd )
  482. {
  483. $templateText = fread( $fd, filesize( $templateFilename ) );
  484. $php->addComment( "Original code:\n" . $templateText );
  485. fclose( $fd );
  486. }
  487. }
  488. }
  489. $php->addVariable( 'eZTemplateCompilerCodeDate', eZTemplateCompiler::CODE_DATE );
  490. $php->addCodePiece( "if ( !defined( 'EZ_TEMPLATE_COMPILER_COMMON_CODE' ) )\n" );
  491. $php->addInclude( eZTemplateCompiler::compilationDirectory() . '/common.php', eZPHPCreator::INCLUDE_ONCE_STATEMENT, array( 'spacing' => 4 ) );
  492. $php->addSpace();
  493. if ( eZTemplateCompiler::isAccumulatorsEnabled() )
  494. {
  495. $php->addCodePiece( "eZDebug::accumulatorStart( 'template_compiled_execution', 'template_total', 'Template compiled execution', true );\n" );
  496. }
  497. if ( eZTemplateCompiler::isTimingPointsEnabled() )
  498. {
  499. $php->addCodePiece( "eZDebug::addTimingPoint( 'Script start $cacheFileName' );\n" );
  500. }
  501. // $php->addCodePiece( "if ( !isset( \$vars ) )\n \$vars =& \$tpl->Variables;\n" );
  502. // $php->addSpace();
  503. $parameters = array();
  504. $textName = eZTemplateCompiler::currentTextName( $parameters );
  505. // $php->addCodePiece( "if ( !isset( \$$textName ) )\n \$$textName = '';\n" );
  506. // $php->addSpace();
  507. // $variableStats = array();
  508. // eZTemplateCompiler::prepareVariableStatistics( $tpl, $resourceData, $variableStats );
  509. // eZTemplateCompiler::calculateVariableStatistics( $tpl, $rootNode, $resourceData, $variableStats );
  510. // print_r( $variableStats );
  511. $transformedTree = array();
  512. eZTemplateCompiler::processNodeTransformation( $useComments, $php, $tpl, $rootNode, $resourceData, $transformedTree );
  513. if ( $ini->variable( 'TemplateSettings', 'TemplateOptimization' ) == 'enabled' )
  514. {
  515. /* Retrieve class information for the attribute lookup table */
  516. if ( isset( $resourceData['handler']->Keys ) and isset( $resourceData['handler']->Keys['class'] ) ) {
  517. $resourceData['class-info'] = eZTemplateOptimizer::fetchClassDeclaration( $resourceData['handler']->Keys['class'] );
  518. }
  519. /* Run the optimizations */
  520. eZTemplateOptimizer::optimize( $useComments, $php, $tpl, $transformedTree, $resourceData );
  521. }
  522. $staticTree = array();
  523. eZTemplateCompiler::processStaticOptimizations( $useComments, $php, $tpl, $transformedTree, $resourceData, $staticTree );
  524. $combinedTree = array();
  525. eZTemplateCompiler::processNodeCombining( $useComments, $php, $tpl, $staticTree, $resourceData, $combinedTree );
  526. $finalTree = $combinedTree;
  527. if ( !eZTemplateCompiler::isNodePlacementEnabled() )
  528. eZTemplateCompiler::processRemoveNodePlacement( $finalTree );
  529. eZTemplateCompiler::generatePHPCode( $useComments, $php, $tpl, $finalTree, $resourceData );
  530. if ( eZTemplateCompiler::isTreeEnabled( 'final' ) )
  531. $php->addVariable( 'finalTree', $finalTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
  532. if ( eZTemplateCompiler::isTreeEnabled( 'combined' ) )
  533. $php->addVariable( 'combinedTree', $combinedTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
  534. if ( eZTemplateCompiler::isTreeEnabled( 'static' ) )
  535. $php->addVariable( 'staticTree', $staticTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
  536. if ( eZTemplateCompiler::isTreeEnabled( 'transformed' ) )
  537. $php->addVariable( 'transformedTree', $transformedTree, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
  538. if ( eZTemplateCompiler::isTreeEnabled( 'original' ) )
  539. $php->addVariable( 'originalTree', $rootNode, eZPHPCreator::VARIABLE_ASSIGNMENT, array( 'full-tree' => true ) );
  540. if ( eZTemplateCompiler::isTimingPointsEnabled() )
  541. $php->addCodePiece( "eZDebug::addTimingPoint( 'Script end $cacheFileName' );\n" );
  542. if ( eZTemplateCompiler::isAccumulatorsEnabled() )
  543. $php->addCodePiece( "eZDebug::accumulatorStop( 'template_compiled_execution', true );\n" );
  544. if ( $resourceData['locales'] && count( $resourceData['locales'] ) )
  545. {
  546. $php->addCodePiece(
  547. 'setlocale( LC_CTYPE, $oldLocale_'. $resourceData['uniqid']. ' );'. "\n"
  548. );
  549. }
  550. $php->addCodePiece('$setArray = $oldSetArray_'. $resourceData['uniqid']. ";\n");
  551. // Code to decrement include level of the templates
  552. $php->addCodePiece("\$tpl->Level--;\n" );
  553. /*
  554. // dump names of all defined PHP variables
  555. $php->addCodePiece( "echo \"defined vars in $resourceData[uri]:<br/><pre>\\n\";\n" );
  556. $php->addCodePiece( 'foreach ( array_keys( get_defined_vars() ) as $var_name ) echo "- $var_name\n";' );
  557. // dump tpl vars
  558. $php->addCodePiece( 'echo "\n-----------------------------------------------------------\nvars: ";' );
  559. $php->addCodePiece( 'var_dump( $vars );' );
  560. $php->addCodePiece( 'echo "</pre><hr/>\n";' );
  561. */
  562. if ( !$resourceData['test-compile'] )
  563. {
  564. $php->store( true );
  565. }
  566. return true;
  567. }
  568. static function prepareVariableStatistics( $tpl, &$resourceData, &$stats )
  569. {
  570. // $path = $resourceData['template-filename'];
  571. // $info =& $GLOBALS['eZTemplateCompileVariableInfo'][$path];
  572. if ( isset( $resourceData['variable-info'] ) )
  573. {
  574. }
  575. }
  576. static function calculateVariableStatistics( $tpl, &$node, &$resourceData, &$stats )
  577. {
  578. $nodeType = $node[0];
  579. if ( $nodeType == eZTemplate::NODE_ROOT )
  580. {
  581. $children = $node[1];
  582. $namespace = '';
  583. if ( $children )
  584. {
  585. eZTemplateCompiler::calculateVariableStatisticsChildren( $tpl, $children, $resourceData, $namespace, $stats );
  586. }
  587. }
  588. else
  589. $tpl->error( 'calculateVariableStatistics', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
  590. }
  591. static function calculateVariableStatisticsChildren( $tpl, &$nodeChildren, &$resourceData, $namespace, &$stats )
  592. {
  593. foreach ( $nodeChildren as $node )
  594. {
  595. if ( !isset( $node[0] ) )
  596. continue;
  597. $nodeType = $node[0];
  598. if ( $nodeType == eZTemplate::NODE_ROOT )
  599. {
  600. $children = $node[1];
  601. if ( $children )
  602. {
  603. eZTemplateCompiler::calculateVariableStatisticsChildren( $tpl, $children, $resourceData, $namespace, $stats );
  604. }
  605. }
  606. else if ( $nodeType == eZTemplate::NODE_TEXT )
  607. {
  608. $text = $node[2];
  609. $placement = $node[3];
  610. }
  611. else if ( $nodeType == eZTemplate::NODE_VARIABLE )
  612. {
  613. $variableData = $node[2];
  614. $variablePlacement = $node[3];
  615. $variableParameters = false;
  616. eZTemplateCompiler::calculateVariableNodeStatistics( $tpl, $variableData, $variablePlacement, $resourceData, $namespace, $stats );
  617. }
  618. else if ( $nodeType == eZTemplate::NODE_FUNCTION )
  619. {
  620. $functionChildren = $node[1];
  621. $functionName = $node[2];
  622. $functionParameters = $node[3];
  623. $functionPlacement = $node[4];
  624. if ( !isset( $tpl->Functions[$functionName] ) )
  625. continue;
  626. if ( is_array( $tpl->Functions[$functionName] ) )
  627. {
  628. $tpl->loadAndRegisterOperators( $tpl->Functions[$functionName] );
  629. }
  630. $functionObject =& $tpl->Functions[$functionName];
  631. if ( is_object( $functionObject ) )
  632. {
  633. $hasTransformationSupport = false;
  634. $transformChildren = true;
  635. if ( method_exists( $functionObject, 'functionTemplateStatistics' ) )
  636. {
  637. $functionObject->functionTemplateStatistics( $functionName, $node, $tpl, $resourceData, $namespace, $stats );
  638. }
  639. }
  640. else if ( $resourceData['test-compile'] )
  641. {
  642. $tpl->warning( '', "Operator '$operatorName' is not registered.", $functionPlacement );
  643. }
  644. }
  645. }
  646. }
  647. static function calculateVariableNodeStatistics( $tpl, $variableData, $variablePlacement, &$resourceData, $namespace, &$stats )
  648. {
  649. if ( !is_array( $variableData ) )
  650. return false;
  651. foreach ( $variableData as $variableItem )
  652. {
  653. $variableItemType = $variableItem[0];
  654. $variableItemData = $variableItem[1];
  655. $variableItemPlacement = $variableItem[2];
  656. if ( $variableItemType == eZTemplate::TYPE_STRING or
  657. $variableItemType == eZTemplate::TYPE_IDENTIFIER )
  658. {
  659. }
  660. else if ( $variableItemType == eZTemplate::TYPE_NUMERIC )
  661. {
  662. }
  663. else if ( $variableItemType == eZTemplate::TYPE_ARRAY )
  664. {
  665. }
  666. else if ( $variableItemType == eZTemplate::TYPE_BOOLEAN )
  667. {
  668. }
  669. else if ( $variableItemType == eZTemplate::TYPE_VARIABLE )
  670. {
  671. $variableNamespace = $variableItemData[0];
  672. $variableNamespaceScope = $variableItemData[1];
  673. $variableName = $variableItemData[2];
  674. if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_GLOBAL )
  675. $newNamespace = $variableNamespace;
  676. else if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_LOCAL )
  677. $newNamespace = $variableNamespace;
  678. else if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_RELATIVE )
  679. $newNamespace = $tpl->mergeNamespace( $namespace, $variableNamespace );
  680. else
  681. $newNamespace = false;
  682. eZTemplateCompiler::setVariableStatistics( $stats, $newNamespace, $variableName, array( 'is_accessed' => true ) );
  683. }
  684. else if ( $variableItemType == eZTemplate::TYPE_ATTRIBUTE )
  685. {
  686. eZTemplateCompiler::calculateVariableNodeStatistics( $tpl, $variableItemData, $variableItemPlacement, $resourceData, $namespace, $stats );
  687. }
  688. else if ( $variableItemType == eZTemplate::TYPE_OPERATOR )
  689. {
  690. $operatorName = $variableItemData[0];
  691. if ( !isset( $tpl->Operators[$operatorName] ) )
  692. continue;
  693. if ( is_array( $tpl->Operators[$operatorName] ) )
  694. {
  695. $tpl->loadAndRegisterOperators( $tpl->Operators[$operatorName] );
  696. }
  697. $operator =& $tpl->Operators[$operatorName];
  698. if ( is_object( $operator ) )
  699. {
  700. $hasStats = false;
  701. if ( method_exists( $operator, 'operatorTemplateHints' ) )
  702. {
  703. $hints = $operator->operatorTemplateHints();
  704. if ( isset( $hints[$operatorName] ) )
  705. {
  706. $operatorHints = $hints[$operatorName];
  707. $hasParameters = false;
  708. if ( isset( $operatorHints['parameters'] ) )
  709. $hasParameters = $operatorHints['parameters'];
  710. if ( $hasParameters === true )
  711. {
  712. $parameters = $variableItemData;
  713. $count = count( $parameters ) - 1;
  714. for ( $i = 0; $i < $count; ++$i )
  715. {
  716. $parameter =& $parameters[$i + 1];
  717. $parameterData = $parameter[1];
  718. $parameterPlacement = $parameter[2];
  719. eZTemplateCompiler::calculateVariableNodeStatistics( $tpl, $parameter, $parameterPlacement,
  720. $resourceData, $namespace, $stats );
  721. }
  722. }
  723. else if ( is_integer( $hasParameters ) )
  724. {
  725. $parameters = $variableItemData;
  726. $count = min( count( $parameters ) - 1, $hasParameters );
  727. for ( $i = 0; $i < $count; ++$i )
  728. {
  729. $parameter =& $parameters[$i + 1];
  730. $parameterData = $parameter[1];
  731. $parameterPlacement = $parameter[2];
  732. eZTemplateCompiler::calculateVariableNodeStatistics( $tpl, $parameter, $parameterPlacement,
  733. $resourceData, $namespace, $stats );
  734. }
  735. }
  736. $hasStats = true;
  737. }
  738. }
  739. if ( !$hasStats and method_exists( $operator, 'operatorTemplateStatistics' ) )
  740. {
  741. $hasStats = $operator->operatorTemplateStatistics( $operatorName, $variableItem, $variablePlacement, $tpl, $resourceData, $namespace, $stats );
  742. }
  743. if ( !$hasStats and method_exists( $operator, 'namedParameterList' ) )
  744. {
  745. $namedParameterList = $operator->namedParameterList();
  746. if ( method_exists( $operator, 'namedParameterPerOperator' ) and
  747. $operator->namedParameterPerOperator() )
  748. {
  749. $namedParameterList = $namedParameterList[$operatorName];
  750. }
  751. $operatorParameters = array_slice( $variableItemData, 1 );
  752. $count = 0;
  753. foreach ( $namedParameterList as $parameterName => $parameterDefinition )
  754. {
  755. $operatorParameter = $operatorParameters[$count];
  756. eZTemplateCompiler::calculateVariableNodeStatistics( $tpl, $operatorParameter, $variablePlacement, $resourceData, $namespace, $stats );
  757. ++$count;
  758. }
  759. $hasStats = true;
  760. }
  761. }
  762. else if ( $resourceData['test-compile'] )
  763. {
  764. $tpl->warning( '', "Operator '$operatorName' is not registered." );
  765. }
  766. }
  767. else if ( $variableItemType == eZTemplate::TYPE_VOID )
  768. {
  769. $tpl->warning( 'TemplateCompiler::calculateOperatorStatistics', "Void datatype should not be used, ignoring it" );
  770. }
  771. else
  772. {
  773. $tpl->warning( 'TemplateCompiler::calculateOperatorStatistics', "Unknown data type $variableItemType, ignoring it" );
  774. }
  775. }
  776. return true;
  777. }
  778. static function setVariableStatistics( &$stats, $namespace, $variableName, $changes )
  779. {
  780. if ( isset( $stats['variables'][$namespace][$variableName] ) )
  781. {
  782. $variableStats =& $stats['variables'][$namespace][$variableName];
  783. }
  784. else
  785. {
  786. $variableStats = array( 'is_accessed' => false,
  787. 'is_created' => false,
  788. 'is_modified' => false,
  789. 'is_removed' => false,
  790. 'is_local' => false,
  791. 'is_input' => false,
  792. 'namespace' => $namespace,
  793. 'namespace_scope' => false,
  794. 'type' => false );
  795. $stats['variables'][$namespace][$variableName] =& $variableStats;
  796. }
  797. if ( isset( $changes['invalid_access'] ) and $changes['invalid_access'] !== false )
  798. $variableStats['invalid_access'] = $changes['invalid_access'];
  799. if ( isset( $changes['is_accessed'] ) and $changes['is_accessed'] !== false )
  800. $variableStats['is_accessed'] = $changes['is_accessed'];
  801. if ( isset( $changes['is_created'] ) and $changes['is_created'] !== false )
  802. $variableStats['is_created'] = $changes['is_created'];
  803. if ( isset( $changes['is_modified'] ) and $changes['is_modified'] !== false )
  804. $variableStats['is_modified'] = $changes['is_modified'];
  805. if ( isset( $changes['is_removed'] ) and $changes['is_removed'] !== false )
  806. $variableStats['is_removed'] = $changes['is_removed'];
  807. if ( isset( $changes['is_local'] ) and $changes['is_local'] !== false )
  808. $variableStats['is_local'] = $changes['is_local'];
  809. if ( isset( $changes['is_input'] ) and $changes['is_input'] !== false )
  810. $variableStats['is_input'] = $changes['is_input'];
  811. if ( isset( $changes['namespace'] ) )
  812. $variableStats['namespace'] = $changes['namespace'];
  813. if ( isset( $changes['namespace_scope'] ) )
  814. $variableStats['namespace_scope'] = $changes['namespace_scope'];
  815. if ( isset( $changes['type'] ) )
  816. $variableStats['type'] = $changes['type'];
  817. }
  818. /*!
  819. Iterates over the template node tree and tries to combine multiple static siblings
  820. into one element. The original tree is specified in \a $node and the new
  821. combined tree will be present in \a $newNode.
  822. \sa processNodeCombiningChildren
  823. */
  824. static function processNodeCombining( $useComments, $php, $tpl, &$node, &$resourceData, &$newNode )
  825. {
  826. $nodeType = $node[0];
  827. if ( $nodeType == eZTemplate::NODE_ROOT )
  828. {
  829. $children = $node[1];
  830. $newNode[0] = $nodeType;
  831. $newNode[1] = false;
  832. if ( $children )
  833. {
  834. eZTemplateCompiler::processNodeCombiningChildren( $useComments, $php, $tpl, $children, $resourceData, $newNode );
  835. }
  836. }
  837. else
  838. $tpl->error( 'processNodeCombining', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
  839. }
  840. /*!
  841. Does node combining on the children \a $nodeChildren.
  842. \sa processNodeCombining
  843. */
  844. static function processNodeCombiningChildren( $useComments, $php, $tpl, &$nodeChildren, &$resourceData, &$parentNode )
  845. {
  846. $newNodeChildren = array();
  847. $lastNode = false;
  848. foreach ( $nodeChildren as $node )
  849. {
  850. $newNode = false;
  851. if ( !isset( $node[0] ) )
  852. continue;
  853. $nodeType = $node[0];
  854. if ( $nodeType == eZTemplate::NODE_ROOT )
  855. {
  856. $children = $node[1];
  857. $newNode = array( $nodeType,
  858. false );
  859. if ( $children )
  860. {
  861. eZTemplateCompiler::processNodeCombiningChildren( $useComments, $php, $tpl, $children, $resourceData, $newNode );
  862. }
  863. }
  864. else if ( $nodeType == eZTemplate::NODE_TEXT )
  865. {
  866. $text = $node[2];
  867. $placement = $node[3];
  868. $newNode = array( $nodeType,
  869. false,
  870. $text,
  871. $placement );
  872. eZTemplateCompiler::combineStaticNodes( $tpl, $resourceData, $lastNode, $newNode );
  873. }
  874. else if ( $nodeType == eZTemplate::NODE_VARIABLE )
  875. {
  876. $variableCustom = $node[1];
  877. $variableData = $node[2];
  878. $variablePlacement = $node[3];
  879. $variableParameters = false;
  880. $dataInspection = eZTemplateCompiler::inspectVariableData( $tpl,
  881. $variableData, $variablePlacement,
  882. $resourceData );
  883. $newNode = $node;
  884. $newNode[1] = $variableCustom;
  885. unset( $dataInspection );
  886. eZTemplateCompiler::combineStaticNodes( $tpl, $resourceData, $lastNode, $newNode );
  887. }
  888. else if ( $nodeType == eZTemplate::NODE_FUNCTION )
  889. {
  890. $functionChildren = $node[1];
  891. $functionName = $node[2];
  892. $functionParameters = $node[3];
  893. $functionPlacement = $node[4];
  894. $newNode = array( $nodeType,
  895. false,
  896. $functionName,
  897. $functionParameters,
  898. $functionPlacement );
  899. if ( isset( $node[5] ) )
  900. $newNode[5] = $node[5];
  901. if ( is_array( $functionChildren ) )
  902. {
  903. eZTemplateCompiler::processNodeCombiningChildren( $useComments, $php, $tpl,
  904. $functionChildren, $resourceData, $newNode );
  905. }
  906. }
  907. else
  908. $newNode = $node;
  909. if ( $lastNode != false )
  910. {
  911. $newNodeChildren[] = $lastNode;
  912. $lastNode = false;
  913. }
  914. if ( $newNode != false )
  915. $lastNode = $newNode;
  916. }
  917. if ( $lastNode != false )
  918. {
  919. $newNodeChildren[] = $lastNode;
  920. $lastNode = false;
  921. }
  922. $parentNode[1] = $newNodeChildren;
  923. }
  924. /*!
  925. Tries to combine the node \a $lastNode and the node \a $newNode
  926. into one new text node. If possible the new node is created in \a $newNode
  927. and \a $lastNode will be set to \c false.
  928. Combining nodes only works for text nodes and variable nodes without
  929. variable lookup, attributes and operators.
  930. */
  931. static function combineStaticNodes( $tpl, &$resourceData, &$lastNode, &$newNode )
  932. {
  933. if ( $lastNode == false or
  934. $newNode == false )
  935. return false;
  936. $lastNodeType = $lastNode[0];
  937. $newNodeType = $newNode[0];
  938. if ( !in_array( $lastNodeType, array( eZTemplate::NODE_TEXT,
  939. eZTemplate::NODE_VARIABLE ) ) or
  940. !in_array( $newNodeType, array( eZTemplate::NODE_TEXT,
  941. eZTemplate::NODE_VARIABLE ) ) )
  942. return false;
  943. if ( $lastNodeType == eZTemplate::NODE_VARIABLE )
  944. {
  945. if ( is_array( $lastNode[1] ) )
  946. return false;
  947. $lastDataInspection = eZTemplateCompiler::inspectVariableData( $tpl,
  948. $lastNode[2], $lastNode[3],
  949. $resourceData );
  950. if ( !$lastDataInspection['is-constant'] or
  951. $lastDataInspection['is-variable'] or
  952. $lastDataInspection['has-attributes'] or
  953. $lastDataInspection['has-operators'] )
  954. return false;
  955. if ( isset( $lastNode[4] ) and
  956. isset( $lastNode[4]['text-result'] ) and
  957. !$lastNode[4]['text-result'] )
  958. return false;
  959. }
  960. if ( $newNodeType == eZTemplate::NODE_VARIABLE )
  961. {
  962. if ( is_array( $newNode[1] ) )
  963. return false;
  964. $newDataInspection = eZTemplateCompiler::inspectVariableData( $tpl,
  965. $newNode[2], $newNode[3],
  966. $resourceData );
  967. if ( !$newDataInspection['is-constant'] or
  968. $newDataInspection['is-variable'] or
  969. $newDataInspection['has-attributes'] or
  970. $newDataInspection['has-operators'] )
  971. return false;
  972. if ( isset( $newNode[4] ) and
  973. isset( $newNode[4]['text-result'] ) and
  974. !$newNode[4]['text-result'] )
  975. return false;
  976. if ( isset( $newNode[1] ) and
  977. $newNode[1] !== false )
  978. return false;
  979. }
  980. $textElements = array();
  981. $lastNodeData = eZTemplateCompiler::staticNodeData( $lastNode );
  982. $newNodeData = eZTemplateCompiler::staticNodeData( $newNode );
  983. $tpl->appendElementText( $textElements, $lastNodeData, false, false );
  984. $tpl->appendElementText( $textElements, $newNodeData, false, false );
  985. $newData = implode( '', $textElements );
  986. $newPlacement = $lastNode[3];
  987. if ( !is_array( $newPlacement ) )
  988. {
  989. $newPlacement = $newNode[3];
  990. }
  991. else
  992. {
  993. $newPlacement[1][0] = $newNode[3][1][0]; // Line end
  994. $newPlacement[1][1] = $newNode[3][1][1]; // Column end
  995. $newPlacement[1][2] = $newNode[3][1][2]; // Position end
  996. }
  997. $lastNode = false;
  998. $newNode = array( eZTemplate::NODE_TEXT,
  999. false,
  1000. $newData,
  1001. $newPlacement );
  1002. }
  1003. /*!
  1004. \return the static data for the node \a $node or \c false if
  1005. no data could be fetched.
  1006. Will only return data from text nodes and variables nodes
  1007. without variable lookup, attribute lookup or operators.
  1008. */
  1009. static function staticNodeData( $node )
  1010. {
  1011. $nodeType = $node[0];
  1012. if ( $nodeType == eZTemplate::NODE_TEXT )
  1013. {
  1014. return $node[2];
  1015. }
  1016. else if ( $nodeType == eZTemplate::NODE_VARIABLE )
  1017. {
  1018. $data = $node[2];
  1019. if ( is_array( $data ) and
  1020. count( $data ) > 0 )
  1021. {
  1022. $dataType = $data[0][0];
  1023. if ( $dataType == eZTemplate::TYPE_STRING or
  1024. $dataType == eZTemplate::TYPE_NUMERIC or
  1025. $dataType == eZTemplate::TYPE_IDENTIFIER or
  1026. $dataType == eZTemplate::TYPE_ARRAY or
  1027. $dataType == eZTemplate::TYPE_BOOLEAN )
  1028. {
  1029. return $data[0][1];
  1030. }
  1031. }
  1032. }
  1033. return null;
  1034. }
  1035. /*!
  1036. Iterates over the items in the tree \a $node and tries to extract static data
  1037. from operators which supports it.
  1038. */
  1039. static function processStaticOptimizations( $useComments, $php, $tpl, &$node, &$resourceData, &$newNode )
  1040. {
  1041. $nodeType = $node[0];
  1042. if ( $nodeType == eZTemplate::NODE_ROOT )
  1043. {
  1044. $children = $node[1];
  1045. $newNode[0] = $nodeType;
  1046. $newNode[1] = false;
  1047. if ( $children )
  1048. {
  1049. $newNode[1] = array();
  1050. foreach ( $children as $child )
  1051. {
  1052. $newChild = array();
  1053. eZTemplateCompiler::processStaticOptimizations( $useComments, $php, $tpl, $child, $resourceData, $newChild );
  1054. $newNode[1][] = $newChild;
  1055. }
  1056. }
  1057. }
  1058. else if ( $nodeType == eZTemplate::NODE_TEXT )
  1059. {
  1060. $text = $node[2];
  1061. $placement = $node[3];
  1062. $newNode[0] = $nodeType;
  1063. $newNode[1] = false;
  1064. $newNode[2] = $text;
  1065. $newNode[3] = $placement;
  1066. }
  1067. else if ( $nodeType == eZTemplate::NODE_VARIABLE )
  1068. {
  1069. $variableCustom = $node[1];
  1070. $variableData = $node[2];
  1071. $variablePlacement = $node[3];
  1072. $dataInspection = eZTemplateCompiler::inspectVariableData( $tpl,

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