diff --git a/change_log.txt b/change_log.txt index b68efbf4..46548c0d 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,9 @@  ===== 3.1.28-dev===== (xx.xx.2015) + 12.07.2015 + - optimize {extends} compilation + 10.07.2015 - - bugfix force file: resource in demo resource.extendsall.php + - bugfix force file: resource in demo resource.extendsall.php 08.07.2015 - bugfix convert each word of class names to ucfirst in in compiler. (forum topic 25588) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8f96d053..c94bfe40 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/26'; + const SMARTY_VERSION = '3.1.28-dev/27'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php index 2b541f2e..b4e2bbf2 100644 --- a/libs/sysplugins/smarty_internal_compile_extends.php +++ b/libs/sysplugins/smarty_internal_compile_extends.php @@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $required_attributes = array('file'); + /** * Attribute definition: Overwrites base class. * @@ -52,32 +53,39 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase } $name = $_attr['file']; - /** @var Smarty_Internal_Template $_smarty_tpl - * used in evaluated code - */ - $_smarty_tpl = $compiler->template; - eval("\$tpl_name = $name;"); - // create template object - $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template); + if ($compiler->has_variable_string || !((substr_count($name, '"') == 2 || substr_count($name, "'") == 2)) || + substr_count($name, '(') != 0 || substr_count($name, '$_smarty_tpl->') != 0 + ) { + /** @var Smarty_Internal_Template $_smarty_tpl + * used in evaluated code + */ + $_smarty_tpl = $compiler->template; + eval("\$tpl_name = {$name};"); + } else { + $tpl_name = trim($name, '\'"'); + } + // create source object + $_source = Smarty_Template_Source::load(null, $compiler->smarty, $tpl_name); // check for recursion - $uid = $_template->source->uid; + $uid = $_source->uid; if (isset($compiler->extends_uid[$uid])) { - $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1); + $compiler->trigger_template_error("illegal recursive call of \"{$_source->filepath}\"", $compiler->lex->line - + 1); } $compiler->extends_uid[$uid] = true; - if (empty($_template->source->components)) { - array_unshift($compiler->sources, $_template->source); + if (empty($_source->components)) { + array_unshift($compiler->sources, $_source); } else { - foreach ($_template->source->components as $source) { + foreach ($_source->components as $source) { array_unshift($compiler->sources, $source); $uid = $source->uid; if (isset($compiler->extends_uid[$uid])) { - $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1); + $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - + 1); } $compiler->extends_uid[$uid] = true; } } - unset ($_template); $compiler->inheritance_child = true; $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); return '';