From e1e8d2feda96b72ea7530fb022a374f6de5b7687 Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 16 Sep 2015 16:23:38 +0200 Subject: [PATCH] - update compiler by moving no longer needed properties, code optimizations and other --- change_log.txt | 3 + libs/Smarty.class.php | 2 +- .../smarty_internal_compile_block.php | 22 +- .../smarty_internal_compile_function.php | 6 +- .../smarty_internal_compile_include.php | 110 +++---- ...nternal_compile_private_foreachsection.php | 3 +- .../smarty_internal_extension_codeframe.php | 53 +--- .../smarty_internal_templatecompilerbase.php | 272 +++++++----------- libs/sysplugins/smarty_template_cached.php | 2 +- 9 files changed, 182 insertions(+), 291 deletions(-) diff --git a/change_log.txt b/change_log.txt index c5bc5173..8c807dc8 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.28-dev===== (xx.xx.2015) + 16.09.2015 + - update compiler by moving no longer needed properties, code optimizations and other + 14.09.2015 - optimize autoloader - optimize subtemplate handling diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c77d7c5e..7adfd78b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -119,7 +119,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/60'; + const SMARTY_VERSION = '3.1.28-dev/61'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index bc001236..6a3e3a30 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -165,9 +165,8 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase if ($compiler->template->compiled->has_nocache_code) { // $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; $_funcNameCaching .= '_nocache'; - $output = "template->source->type}:{$compiler->template->source->name} */\n"; - $output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; + $output = "template->source->type}:{$compiler->template->source->name} */\n"; $output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$block) {\n"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n?>\n"; @@ -176,13 +175,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $output = "template->compiled->nocache_hash}%%*/\n"; - $output .= "\n}\n}\n"; - $output .= "/*/ {$_funcName}_nocache */\n\n"; + $output .= "\n}\n"; + $output .= "/* {/block '{$_name}'} */\n\n"; $output .= "?>\n"; $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); - $compiler->parent_compiler->templateFunctionCode .= $f = + $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, @@ -190,21 +189,20 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase array($this, 'removeNocache'), $_functionCode->to_smarty_php($compiler->parser))); } - $output = "template->source->type}:{$compiler->template->source->name} */\n"; - $output .= "if (!function_exists('{$_funcName}')) {\n"; + $output = "template->source->type}:{$compiler->template->source->name} */\n"; $output .= "function {$_funcName}(\$_smarty_tpl, \$block) {?>"; $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); - $output = "\n"; $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); - $compiler->parent_compiler->templateFunctionCode .= $f = + $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser); // nocache plugins must be copied if (!empty($compiler->template->compiled->required_plugins['nocache'])) { diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index b8139fd0..f1d28dcf 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -66,8 +66,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code, $compiler->template->caching); $this->openTag($compiler, 'function', $save); - // set flag that we are compiling a template function - $compiler->compiles_template_function = true; // Init temporary context $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->template->compiled->has_nocache_code = false; @@ -107,8 +105,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $saved_data = $this->closeTag($compiler, array('function')); $_attr = $saved_data[0]; $_name = trim($_attr['name'], "'\""); - // reset flag that we are compiling a template function - $compiler->compiles_template_function = false; $compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions; $compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath; $compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid; @@ -182,7 +178,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $output .= "/*/ {$_funcName} */\n\n"; $output .= "?>\n"; $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); - $compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); + $compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); // nocache plugins must be copied if (!empty($compiler->template->compiled->required_plugins['nocache'])) { foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) { diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index c9ea0482..a78673a9 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -209,55 +209,10 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase $c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id; // we must observe different compile_id and caching $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); - $tpl_name = null; - if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) { - $compiler->smarty->allow_ambiguous_resources = true; - /* @var Smarty_Internal_Template $tpl */ - $tpl = new $compiler->smarty->template_class (trim($fullResourceName, "'"), $compiler->smarty, - $compiler->template, $compiler->template->cache_id, $c_id, - $_caching); - $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = - $tpl->source->uid; - if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { - $tpl->compiled = new Smarty_Template_Compiled(); - $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; - $tpl->loadCompiler(); - $tpl->compiler->inheritanceChild = - $tpl->compiler->inheritanceForceChild = $compiler->inheritanceForceChild; - $tpl->compiler->inheritance = $compiler->inheritance; - // save unique function name - $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] = - $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); - // make sure whole chain gets compiled - $tpl->mustCompile = true; - $tpl->compiler->suppressTemplatePropertyHeader = true; - $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] = - $tpl->compiled->nocache_hash; - // get compiled code - $compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, - $tpl->compiler->compileTemplate($tpl, - null, - $compiler->parent_compiler)); - $compiler->inheritanceParentIsChild = $tpl->compiler->inheritanceChild; - $compiler->inheritance = $tpl->compiler->inheritance; - unset($tpl->compiler); - - // remove header code - $compiled_code = - preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->compiled->nocache_hash}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", - '', $compiled_code); - if ($tpl->compiled->has_nocache_code) { - // replace nocache_hash - $compiled_code = - str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash, - $compiled_code); - $compiler->template->compiled->has_nocache_code = true; - } - $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; - $has_compiled_template = true; - unset ($tpl); - } + $has_compiled_template = + $this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash, + $c_id); } else { $has_compiled_template = true; } @@ -329,4 +284,63 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase $_output .= "?>\n"; return $_output; } + + /** + * Compile inline sub template + * + * @param \Smarty_Internal_SmartyTemplateCompiler $compiler + * @param $fullResourceName + * @param $_caching + * @param $hashResourceName + * @param $t_hash + * @param $c_id + * + * @return bool + */ + public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash, $c_id) + { + $compiler->smarty->allow_ambiguous_resources = true; + /* @var Smarty_Internal_Template $tpl */ + $tpl = new $compiler->smarty->template_class (trim($fullResourceName, "'"), $compiler->smarty, $compiler->template, + $compiler->template->cache_id, $c_id, $_caching); + $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid; + if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { + $tpl->compiled = new Smarty_Template_Compiled(); + $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; + $tpl->loadCompiler(); + $tpl->compiler->inheritanceChild = $tpl->compiler->inheritanceForceChild = $compiler->inheritanceForceChild; + $tpl->compiler->inheritance = $compiler->inheritance; + // save unique function name + $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] = + $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); + // make sure whole chain gets compiled + $tpl->mustCompile = true; + $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] = + $tpl->compiled->nocache_hash; + // get compiled code + $compiled_code = "source->type}:{$tpl->source->name}\" =============================*/\n"; + $compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n"; + $compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler); + $compiled_code .= "\n"; + $compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode); + $compiled_code .= "source->type}:{$tpl->source->name}\" =============================*/\n"; + $compiled_code .= "?>"; + $compiler->inheritanceParentIsChild = $tpl->compiler->inheritanceChild; + $compiler->inheritance = $tpl->compiler->inheritance; + unset($tpl->compiler); + if ($tpl->compiled->has_nocache_code) { + // replace nocache_hash + $compiled_code = str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash, + $compiled_code); + $compiler->template->compiled->has_nocache_code = true; + } + $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; + return true; + } else { + return false; + } + } } diff --git a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php index 2c75b389..6989223d 100644 --- a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php +++ b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php @@ -175,8 +175,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com if ($_content != '') { // run pre filter if required if ((isset($nextCompiler->smarty->autoload_filters['pre']) || - isset($nextCompiler->smarty->registered_filters['pre'])) && !$nextCompiler->suppressFilter - ) { + isset($nextCompiler->smarty->registered_filters['pre']))) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $nextCompiler->template); } $this->matchProperty($_content); diff --git a/libs/sysplugins/smarty_internal_extension_codeframe.php b/libs/sysplugins/smarty_internal_extension_codeframe.php index 09eaa04e..24e21fc2 100644 --- a/libs/sysplugins/smarty_internal_extension_codeframe.php +++ b/libs/sysplugins/smarty_internal_extension_codeframe.php @@ -23,7 +23,7 @@ class Smarty_Internal_Extension_CodeFrame * * @return string */ - public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false) + public static function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false) { // build property code $properties['has_nocache_code'] = $_template->compiled->has_nocache_code; @@ -40,10 +40,8 @@ class Smarty_Internal_Extension_CodeFrame $properties['cache_lifetime'] = $_template->cache_lifetime; } $output = "compiled->nocache_hash}%%*/\n"; $output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ");\n"; - $output .= "/*/%%SmartyHeaderCode%%*/\n"; $output .= "if (\$_valid && !is_callable('{$properties['unifunc']}')) {\n"; $output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n"; // include code for plugins @@ -77,48 +75,11 @@ class Smarty_Internal_Extension_CodeFrame } } $output .= "?>\n"; - $output = self::appendCode($output, $content); - return self::appendCode($output, ""); - } - - /** - * Create code frame of compiled template function - * - * @param \Smarty_Internal_Template $_template - * @param string $content - * - * @return string - */ - public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '') - { - $output = "compiled->nocache_hash}%%*/\n"; - $output .= "/* {$_template->source->type}:{$_template->source->name} */\n"; - $output .= "if (\$_valid && !is_callable('{$_template->compiled->unifunc}')) {\n"; - $output .= "function {$_template->compiled->unifunc} (\$_smarty_tpl) {\n"; - $output .= "?>\n" . $content; - $output .= "compiled->nocache_hash}%%*/\n"; - $output .= "}\n}\n?>"; - return $output; - } - - /** - * Append code segments and remove unneeded ?> [\n]?$/', $left) && preg_match('/^<\?php\s+/', $right)) { - $left = preg_replace('/\s*\?>[\n]?$/', "\n", $left); - $left .= preg_replace('/^<\?php\s+/', '', $right); - } else { - $left .= $right; - } - return $left; + $output .= $content; + $output .= ""; + $output .= $functions; + $output .= "[\n]?<\?php\s/', "\n", $output); } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 7ff09152..0fbf8851 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -107,7 +107,7 @@ abstract class Smarty_Internal_TemplateCompilerBase * * @var bool */ - public $inheritanceChild= false; + public $inheritanceChild = false; /** * Force all subtemplate calls to be inheritance childs @@ -186,27 +186,6 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public $forceNocache = false; - /** - * suppress Smarty header code in compiled template - * - * @var bool - */ - public $suppressHeader = false; - - /** - * suppress template property header code in compiled template - * - * @var bool - */ - public $suppressTemplatePropertyHeader = false; - - /** - * suppress pre and post filter - * - * @var bool - */ - public $suppressFilter = false; - /** * flag if compiled template file shall we written * @@ -214,13 +193,6 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public $write_compiled_code = true; - /** - * flag if currently a template function is compiled - * - * @var bool - */ - public $compiles_template_function = false; - /** * called sub functions from template function * @@ -229,11 +201,11 @@ abstract class Smarty_Internal_TemplateCompilerBase public $called_functions = array(); /** - * compiled template function code + * compiled template or block function code * * @var string */ - public $templateFunctionCode = ''; + public $blockOrFunctionCode = ''; /** * php_handling setting either from Smarty or security @@ -312,27 +284,6 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public $has_output = false; - /** - * Universal cache - * - * @var array - */ - public $cache = array(); - - /** - * Stack during {capture} compilation - * - * @var array - */ - public $_capture_stack = array(); - - /** - * Saved source resource - * - * @var \Smarty_Template_Source - */ - private $savedSource = null; - /** * Stack for {setfilter} {/setfilter} * @@ -410,16 +361,42 @@ abstract class Smarty_Internal_TemplateCompilerBase * @return bool true if compiling succeeded, false if it failed * @throws \Exception */ - public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null) + public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, + Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { - if (property_exists($template->smarty, 'plugin_search_order')) { - $this->plugin_search_order = $template->smarty->plugin_search_order; - } - // save template object in compiler class - $this->template = $template; - $this->savedSource = $this->template->source; + // get code frame of compiled template + $_compiled_code = + "source->filepath . "\" */ ?>\n" . + Smarty_Internal_Extension_CodeFrame::create($template, $this->compileTemplateSource($template, $nocache, + $parent_compiler), + $this->postFilter($this->blockOrFunctionCode) . + join('', $this->mergedSubTemplatesCode)); + return $_compiled_code; + } + /** + * Compile template source and run optional post filter + * + * @param \Smarty_Internal_Template $template + * @param null|bool $nocache flag if template must be compiled in nocache mode + * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler + * + * @return string + * @throws \Exception + */ + public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, + Smarty_Internal_TemplateCompilerBase $parent_compiler = null) + { try { + // save template object in compiler class + $this->template = $template; + if (property_exists($this->template->smarty, 'plugin_search_order')) { + $this->plugin_search_order = $this->template->smarty->plugin_search_order; + } + if ($this->smarty->debugging) { + $this->smarty->_debug->start_compile($this->template); + } if (isset($this->template->smarty->security_policy)) { $this->php_handling = $this->template->smarty->security_policy->php_handling; } else { @@ -432,20 +409,6 @@ abstract class Smarty_Internal_TemplateCompilerBase } else { $this->nocache_hash = $template->compiled->nocache_hash; } - // template header code - $template_header = ''; - if (!$this->suppressHeader) { - $template_header .= "template->source->filepath . "\" */ ?>\n"; - } - $this->smarty->_current_file = $this->template->source->filepath; - if ($this->smarty->debugging) { - $this->smarty->_debug->start_compile($this->template); - } - $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = - array($this->template->source->filepath, $this->template->source->getTimeStamp(), - $this->template->source->type); // flag for nocache sections $this->nocache = $nocache; $this->tag_nocache = false; @@ -453,85 +416,84 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->template->compiled->has_nocache_code = false; $this->has_variable_string = false; $this->prefix_code = array(); + // add file dependency + $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = + array($this->template->source->filepath, $this->template->source->getTimeStamp(), + $this->template->source->type); + $this->smarty->_current_file = $this->template->source->filepath; // get template source if (!empty($this->template->source->components)) { // we have array of inheritance templates by extends: resource - $this->sources = array_reverse($template->source->components); + $this->sources = array_reverse($this->template->source->components); $_content = ''; } else { // get template source $_content = $this->template->source->getContent(); } - if ($_content != '') { - // run pre filter if required - if ($_content != '' && ((isset($this->smarty->autoload_filters['pre']) || - isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) - ) { - $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); - } - } - // call compiler - $_compiled_code = $this->doCompile($_content, true); + + $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); + } + catch (Exception $e) { if ($this->smarty->debugging) { $this->smarty->_debug->end_compile($this->template); } - // free memory - $this->parser = null; - // restore source - $this->template->source = $this->savedSource; - $this->savedSource = null; - $this->smarty->_current_file = $this->template->source->filepath; - // return compiled code to template object - $merged_code = ''; - if (!empty($this->mergedSubTemplatesCode)) { - foreach ($this->mergedSubTemplatesCode as $code) { - $merged_code .= $code; - } - } - // run post filter if required on compiled template code - if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && - !$this->suppressFilter && $_compiled_code != '' - ) { - $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); - } - if ($this->suppressTemplatePropertyHeader) { - $_compiled_code .= $merged_code; - } else { - $_compiled_code = - $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . - $merged_code; - } - if (!empty($this->templateFunctionCode)) { - // run post filter if required on compiled template code - if ((isset($this->smarty->autoload_filters['post']) || - isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter - ) { - $_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, - $template); - } else { - $_compiled_code .= $this->templateFunctionCode; - } - } - } - catch (Exception $e) { $this->_tag_stack = array(); $this->_tag_objects = array(); - // restore source - $this->template->source = $this->savedSource; - $this->savedSource = null; - $this->smarty->_current_file = $this->template->source->filepath; // free memory $this->parent_compiler = null; $this->template = null; $this->parser = null; throw $e; } - + if ($this->smarty->debugging) { + $this->smarty->_debug->end_compile($this->template); + } $this->parent_compiler = null; $this->template = null; + $this->parser = null; return $_compiled_code; } + /** + * Optionally process compiled code by post filter + * + * @param string $code compiled code + * + * @return string + * @throws \SmartyException + */ + public function postFilter($code) + { + // run post filter if on code + if (!empty($code) && + (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) + ) { + return Smarty_Internal_Filter_Handler::runFilter('post', $code, $this->template); + } else { + return $code; + } + } + + /** + * Run optional prefilter + * + * @param string $_content template source + * + * @return string + * @throws \SmartyException + */ + public function preFilter($_content) + { + // run pre filter if required + if ($_content != '' && + ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']))) + ) { + return Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->template); + } else { + return $_content; + } + } + /** * Add code to call parent template on inheritance child templates * @@ -546,15 +508,14 @@ abstract class Smarty_Internal_TemplateCompilerBase $name = $this->extendsFileName; $this->extendsFileName = null; if (!$this->inheritanceForceChild && !$this->inheritance) { - // drop any output of child templates - array_unshift($parser->current_buffer->subtrees, - new Smarty_Internal_ParseTree_Tag($parser, "_Block = new Smarty_Internal_Runtime_Block();?>\n")); + // drop any output of child templates + array_unshift($parser->current_buffer->subtrees, new Smarty_Internal_ParseTree_Tag($parser, + "_Block = new Smarty_Internal_Runtime_Block();?>\n")); $this->inheritance = true; } - $include = new Smarty_Internal_ParseTree_Tag($parser, $this->compileTag('include', - array($name, - array('scope' => 'parent'), - array('inline' => true)))); + $include = new Smarty_Internal_ParseTree_Tag($parser, $this->compileTag('include', array($name, + array('scope' => 'parent'), + array('inline' => true)))); if (!$this->inheritanceForceChild && !$this->inheritanceParentIsChild) { $parser->current_buffer->append_subtree($parser, new Smarty_Internal_ParseTree_Tag($parser, "\n")); @@ -1177,47 +1138,6 @@ abstract class Smarty_Internal_TemplateCompilerBase str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; } - /** - * push current file and line offset on stack for tracing {block} source lines - * - * @param string $file new filename - * @param string $uid uid of file - * @param int $line line offset to source - * @param bool $debug false debug end_compile shall not be called - */ - public function pushTrace($file, $uid, $line, $debug = true) - { - if ($this->smarty->debugging && $debug) { - $this->smarty->_debug->end_compile($this->template); - } - array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, - $this->trace_line_offset)); - $this->trace_filepath = $this->smarty->_current_file = $file; - $this->trace_uid = $uid; - $this->trace_line_offset = $line; - if ($this->smarty->debugging) { - $this->smarty->_debug->start_compile($this->template); - } - } - - /** - * restore file and line offset - */ - public function popTrace() - { - if ($this->smarty->debugging) { - $this->smarty->_debug->end_compile($this->template); - } - $r = array_pop($this->trace_stack); - $this->smarty->_current_file = $r[0]; - $this->trace_filepath = $r[1]; - $this->trace_uid = $r[2]; - $this->trace_line_offset = $r[3]; - if ($this->smarty->debugging) { - $this->smarty->_debug->start_compile($this->template); - } - } - /** * display compiler error messages without dying * If parameter $args is empty it is a parser detected syntax error. diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index e2179d24..7b902b0f 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -366,7 +366,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base // don't write cache file return false; } - $content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, true); + $content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, '', true); if (!empty($_template->cached->tpl_function)) { foreach ($_template->cached->tpl_function as $funcParam) { if (is_file($funcParam['compiled_filepath'])) {