diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index beed76d6..c0713694 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -248,7 +248,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase if (isset($_assign)) { $_output .= "ob_start();\n"; } - $_output .= "\$_smarty_tpl->_inline->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n"; + $_output .= "\$_smarty_tpl->smarty->ext->_inline->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n"; if (isset($_assign)) { $_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n"; } @@ -271,7 +271,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase if (isset($_assign)) { $_output .= "ob_start();\n"; } - $_output .= "\$_smarty_tpl->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n"; + $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n"; if (isset($_assign)) { $_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n"; } diff --git a/libs/sysplugins/smarty_internal_runtime_inline.php b/libs/sysplugins/smarty_internal_runtime_inline.php index 2eaf8512..3b49acea 100644 --- a/libs/sysplugins/smarty_internal_runtime_inline.php +++ b/libs/sysplugins/smarty_internal_runtime_inline.php @@ -1,14 +1,14 @@ setupSubtemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, - $parent_scope, $cache_tpl_obj, $uid); + $tpl = $this->setupSubTemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, + $scope, $uid); if ($parent->smarty->debugging) { $parent->smarty->_debug->start_template($tpl); $parent->smarty->_debug->start_render($tpl); @@ -45,6 +45,7 @@ class Smarty_Internal_Runtime_Inline extends Smarty_Internal_Runtime_Subtemplate if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) { $parent->cached->hashes[$tpl->compiled->nocache_hash] = true; } + $this->updateTemplateCache($tpl, $forceTplCache); } /** diff --git a/libs/sysplugins/smarty_internal_runtime_subtemplate.php b/libs/sysplugins/smarty_internal_runtime_subtemplate.php index bc859c90..f9df3324 100644 --- a/libs/sysplugins/smarty_internal_runtime_subtemplate.php +++ b/libs/sysplugins/smarty_internal_runtime_subtemplate.php @@ -1,14 +1,14 @@ setupSubtemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, - $parent_scope, $cache_tpl_obj) - ->render(); + $tpl = $this->setupSubTemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, + $scope); + $tpl->render(); + $this->updateTemplateCache($tpl, $forceTplCache); } /** @@ -43,15 +44,14 @@ class Smarty_Internal_Runtime_Subtemplate * @param integer $caching cache mode * @param integer $cache_lifetime life time of cache data * @param array $data passed parameter template variables - * @param int $parent_scope scope in which {include} should execute - * @param bool $cache_tpl_obj cache template object + * @param int $scope scope in which {include} should execute * @param string|null $uid source uid * * @return \Smarty_Internal_Template template object * @throws \SmartyException */ - public function setupSubtemplate(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching, - $cache_lifetime, $data, $parent_scope, $cache_tpl_obj, $uid = null) + public function setupSubTemplate(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching, + $cache_lifetime, $data, $scope, $uid = null) { // if there are cached template objects calculate $templateID $_templateId = isset($parent->smarty->_cache['template_objects']) ? @@ -67,7 +67,7 @@ class Smarty_Internal_Runtime_Subtemplate unset($tpl->compiled); } // get variables from calling scope - if ($parent_scope == Smarty::SCOPE_LOCAL) { + if ($scope == Smarty::SCOPE_LOCAL) { $tpl->tpl_vars = $parent->tpl_vars; $tpl->config_vars = $parent->config_vars; } @@ -89,9 +89,6 @@ class Smarty_Internal_Runtime_Subtemplate // $uid is set if template is inline if (isset($uid)) { $this->setSourceByUid($tpl, $uid); - // if template is called multiple times set flag to to cache template objects - $cache_tpl_obj = $cache_tpl_obj || (isset($tpl->compiled->includes[$tpl->template_resource]) && - $tpl->compiled->includes[$tpl->template_resource] > 1); } else { $tpl->source = null; unset($tpl->compiled); @@ -100,14 +97,6 @@ class Smarty_Internal_Runtime_Subtemplate $tpl->source = Smarty_Template_Source::load($tpl); } unset($tpl->cached); - // check if template object should be cached - if (!$tpl->source->handler->recompiled && (isset($tpl->parent->templateId) && - isset($tpl->smarty->_cache['template_objects'][$tpl->parent->templateId]) || - ($cache_tpl_obj && $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) || - $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) - ) { - $tpl->smarty->_cache['template_objects'][$tpl->_getTemplateId()] = $tpl; - } } } $tpl->caching = $caching; @@ -116,14 +105,19 @@ class Smarty_Internal_Runtime_Subtemplate $tpl->cached = $parent->cached; } // get variables from calling scope - if ($parent_scope != Smarty::SCOPE_LOCAL) { - if ($parent_scope == Smarty::SCOPE_PARENT) { + if ($scope != $tpl->scope) { + if ($tpl->scope != Smarty::SCOPE_LOCAL) { + unset($tpl->tpl_vars, $tpl->config_vars); + $tpl->tpl_vars = array(); + $tpl->config_vars = array(); + } + if ($scope == Smarty::SCOPE_PARENT) { $tpl->tpl_vars = &$parent->tpl_vars; $tpl->config_vars = &$parent->config_vars; - } elseif ($parent_scope == Smarty::SCOPE_GLOBAL) { + } elseif ($scope == Smarty::SCOPE_GLOBAL) { $tpl->tpl_vars = &Smarty::$global_tpl_vars; $tpl->config_vars = $parent->config_vars; - } elseif ($parent_scope == Smarty::SCOPE_ROOT) { + } elseif ($scope == Smarty::SCOPE_ROOT) { $ptr = $tpl->parent; while (!empty($ptr->parent)) { $ptr = $ptr->parent; @@ -134,6 +128,7 @@ class Smarty_Internal_Runtime_Subtemplate $tpl->tpl_vars = $parent->tpl_vars; $tpl->config_vars = $parent->config_vars; } + $tpl->scope = $scope; } if (!empty($data)) { @@ -144,4 +139,31 @@ class Smarty_Internal_Runtime_Subtemplate } return $tpl; } + + public function updateTemplateCache(Smarty_Internal_Template $tpl, $forceTplCache) + { + if (isset($tpl->smarty->_cache['template_objects'][$tpl->_getTemplateId()]) || + $tpl->source->handler->recompiled + ) { + return; + } + // if template is called multiple times set flag to to cache template objects + $forceTplCache = $forceTplCache || (isset($tpl->compiled->includes[$tpl->template_resource]) && + $tpl->compiled->includes[$tpl->template_resource] > 1); + // check if template object should be cached + if ((isset($tpl->parent->templateId) && + isset($tpl->smarty->_cache['template_objects'][$tpl->parent->templateId]) || + ($forceTplCache && $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) || + $tpl->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) + ) { + $tpl->parent = null; + if ($tpl->scope != Smarty::SCOPE_LOCAL) { + unset($tpl->tpl_vars, $tpl->config_vars); + $tpl->scope = Smarty::SCOPE_LOCAL; + } + $tpl->tpl_vars = array(); + $tpl->config_vars = array(); + $tpl->smarty->_cache['template_objects'][$tpl->_getTemplateId()] = $tpl; + } + } } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 37690c8b..32b65f89 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -17,12 +17,6 @@ * @property Smarty_Template_Source|Smarty_Template_Config $source * @property Smarty_Template_Compiled $compiled * @property Smarty_Template_Cached $cached - * @property Smarty_Internal_Runtime_Inheritance $_inheritance - * @property Smarty_Internal_Runtime_Subtemplate $_subtemplate - * @property Smarty_Internal_Runtime_Inline $_inline - * @property Smarty_Internal_Runtime_Tplfunc $_tplfunc - * @property Smarty_Internal_Runtime_Var $_var - * @property Smarty_Internal_Runtime_Foreach $_foreach * @method bool mustCompile() */ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase @@ -76,6 +70,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public $tpl_function = array(); + /** + * Scope in which template is rendered + * + * @var int + */ + public $scope = 0; + /** * Create template data object * Some of the global Smarty settings copied to template scope @@ -108,6 +109,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase // Template resource $this->template_resource = $template_resource; $this->source = Smarty_Template_Source::load($this); + parent::__construct(); } /** @@ -427,14 +429,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function __set($property_name, $value) { - if ($property_name[0] == '_') { - $this->$property_name = $value; - return; - } switch ($property_name) { case 'compiled': case 'cached': case 'compiler': + case 'tpl_vars': + case 'config_vars': $this->$property_name = $value; return; default: @@ -457,14 +457,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function __get($property_name) { - // object properties of runtime template extensions will start with '_' - if ($property_name[0] == '_') { - $class = 'Smarty_Internal_Runtime' . $property_name; - $class[24] = chr(ord($class[24]) & 0xDF); - if (class_exists($class)) { - return $this->$property_name = new $class(); - } - } switch ($property_name) { case 'compiled': $this->loadCompiled();