From aaa7b8f245314bf1ecc87c0d7a24ad889ce434fc Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Thu, 17 Dec 2009 16:58:44 +0000 Subject: [PATCH] - bugfix of parent/global variable update at included/merged subtemplates - encode final template filepath into filename of compiled and cached files --- change_log.txt | 4 +++ .../smarty_internal_cacheresource_file.php | 2 +- .../smarty_internal_compile_include.php | 35 +++++++++---------- .../smarty_internal_resource_extends.php | 2 +- .../smarty_internal_resource_file.php | 2 +- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/change_log.txt b/change_log.txt index b72bc2db..7fa53ec2 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +12/17/2009 +- bugfix of parent/global variable update at included/merged subtemplates +- encode final template filepath into filename of compiled and cached files + 12/16/2009 - update of changelog - added {include file='foo.tpl' inline} inline option to merge compiled code of aubtemplate into the calling template diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index aee72653..f3a1329c 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -27,7 +27,7 @@ class Smarty_Internal_CacheResource_File { */ public function getCachedFilepath($template) { - return $this->buildCachedFilepath ($template->resource_name, $template->cache_id, $template->compile_id); + return $this->buildCachedFilepath ($template->getTemplateFilepath(), $template->cache_id, $template->compile_id); } /** diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 093e9d3c..c0a8fd92 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -52,12 +52,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { } else { $tpl->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler); if ($resource_type == 'file') { - $must_compile = true; // subtemplate no longer existing + $must_compile = true; // subtemplate no longer existing break; } $mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name); } -// If ($mtime != $_file_to_check[1]) { + // If ($mtime != $_file_to_check[1]) { If ($mtime > $_file_to_check[1]) { $must_compile = true; break; @@ -100,7 +100,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { $_parent_scope = SMARTY_GLOBAL_SCOPE; } } - $_caching= 'null'; + $_caching = 'null'; // default for included templates if ($this->compiler->template->caching && !$this->compiler->nocache) { $_caching = 9999; @@ -115,8 +115,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { $this->compiler->tag_nocache = true; $_caching = SMARTY_CACHING_LIFETIME_CURRENT; } else { - $_cache_lifetime = 'null'; - } + $_cache_lifetime = 'null'; + } if (isset($_attr['nocache'])) { if ($_attr['nocache'] == 'true') { $this->compiler->tag_nocache = true; @@ -132,7 +132,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { } } // create template object - $_output = "smarty->template_class} ($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id, \$_smarty_tpl->compile_id, $_caching, $_cache_lifetime);"; + $_output = "smarty->template_class}($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id, \$_smarty_tpl->compile_id, $_caching, $_cache_lifetime);"; // delete {include} standard attributes unset($_attr['file'], $_attr['assign'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']); // remaining attributes must be assigned as smarty variable @@ -148,22 +148,21 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { } // was there an assign attribute if (isset($_assign)) { - $_output .= "\$_smarty_tpl->assign($_assign,\$_template->getRenderedTemplate()); ?>"; + $_output .= "\$_smarty_tpl->assign($_assign,\$_template->getRenderedTemplate());?>"; } else { if ($has_compiled_template && !($compiler->template->caching && ($this->compiler->tag_nocache || $this->compiler->nocache))) { - $_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; - $_output .= $compiled_tpl . "getTemplateFilepath() . "\" */ ?>"; - $_output .= ""; + $_output .= "\$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; + $_output .= $compiled_tpl; + $_output .= "updateParentVariables($_parent_scope);?>"; + $_output .= "getTemplateFilepath() . "\" */ ?>"; + $_output .= ""; } else { - $_output .= " echo \$_template->getRenderedTemplate(); ?>"; + $_output .= " echo \$_template->getRenderedTemplate();?>"; + $_output .= "updateParentVariables($_parent_scope);?>"; } } - if ($_parent_scope != SMARTY_LOCAL_SCOPE) { - $_output .= "updateParentVariables($_parent_scope); ?>"; - } - $_output .= ""; + $_output .= ""; return $_output; - } -} - + } +} ?> diff --git a/libs/sysplugins/smarty_internal_resource_extends.php b/libs/sysplugins/smarty_internal_resource_extends.php index 92ccf610..81f0e78b 100644 --- a/libs/sysplugins/smarty_internal_resource_extends.php +++ b/libs/sysplugins/smarty_internal_resource_extends.php @@ -166,7 +166,7 @@ class Smarty_Internal_Resource_Extends { { $_compile_id = isset($template->compile_id) ? preg_replace('![^\w\|]+!', '_', $template->compile_id) : null; $_files = explode('|', $template->resource_name); - $_filepath = (string)abs(crc32($template->resource_name)); + $_filepath = (string)abs(crc32($template->getTemplateFilepath())); // if use_sub_dirs, break file into directories if ($template->smarty->use_sub_dirs) { $_filepath = substr($_filepath, 0, 2) . DS diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index eafc4268..db876e5e 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -113,7 +113,7 @@ class Smarty_Internal_Resource_File { { $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!','_',$_template->compile_id) : null; // $_filepath = md5($_template->resource_name); - $_filepath = (string)abs(crc32($_template->resource_name)); + $_filepath = (string)abs(crc32($_template->getTemplateFilepath())); // if use_sub_dirs, break file into directories if ($_template->smarty->use_sub_dirs) { $_filepath = substr($_filepath, 0, 2) . DS