From 7659c6c0eaa6825391e27a09a03c3a6b0008e6f4 Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Fri, 21 Oct 2011 18:40:16 +0000 Subject: [PATCH] - add Smarty::$allow_ambiguous_resources to activate unique resource handling (Forum Topic 20128) see http://www.smarty.net/forums/viewtopic.php?t=20128 --- change_log.txt | 1 + libs/Smarty.class.php | 12 ++++++++++-- .../smarty_cacheresource_keyvaluestore.php | 6 +++++- .../smarty_internal_cacheresource_file.php | 6 +++++- libs/sysplugins/smarty_internal_template.php | 15 ++++++++++++--- libs/sysplugins/smarty_internal_utility.php | 6 +++++- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/change_log.txt b/change_log.txt index 4bc507fd..24c4462f 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,6 +2,7 @@ 21.10.2011 - bugfix apostrophe in plugins_dir path name failed (forum topic 20199) - improvement sha1() for array keys longer than 150 characters +- add Smarty::$allow_ambiguous_resources to activate unique resource handling (Forum Topic 20128) 20.10.2011 - @silenced unlink() in Smarty_Internal_Write_File since debuggers go haywire without it. diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 34ca6971..9e7dbce8 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -251,6 +251,11 @@ class Smarty extends Smarty_Internal_TemplateBase { * @var boolean */ public $use_sub_dirs = false; + /** + * allow ambiguous resources (that are made unique by the resource handler) + * @var boolean + */ + public $allow_ambiguous_resources = false; /** * caching enabled * @var boolean @@ -1172,8 +1177,11 @@ class Smarty extends Smarty_Internal_TemplateBase { $cache_id = $cache_id === null ? $this->cache_id : $cache_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id; // already in template cache? - $unique_template_name = Smarty_Resource::getUniqueTemplateName($this, $template); - $_templateId = $unique_template_name . $cache_id . $compile_id; + if ($this->allow_ambiguous_resources) { + $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id; + } else { + $_templateId = $this->joined_template_dir . '#' . $template . $cache_id . $compile_id; + } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } diff --git a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php index 7dd75f85..dff9b65a 100644 --- a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php +++ b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php @@ -178,7 +178,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource { } // remove from template cache - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + if ($smarty->allow_ambiguous_resources) { + $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + } else { + $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; + } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 17d90a17..25195412 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -154,7 +154,11 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource { // remove from template cache $tpl->source; // have the template registered before unset() - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + if ($smarty->allow_ambiguous_resources) { + $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + } else { + $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; + } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index d5d8c585..dd2ee118 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -245,8 +245,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope) { // already in template cache? - $unique_template_name = Smarty_Resource::getUniqueTemplateName($this->smarty, $template); - $_templateId = $unique_template_name . $cache_id . $compile_id; + if ($this->smarty->allow_ambiguous_resources) { + $_templateId = Smarty_Resource::getUniqueTemplateName($this->smarty, $template) . $cache_id . $compile_id; + } else { + $_templateId = $this->smarty->joined_template_dir . '#' . $template . $cache_id . $compile_id; + } + if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } @@ -625,7 +629,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { // cache template object under a unique ID // do not cache eval resources if ($this->source->type != 'eval') { - $_templateId = $this->source->unique_resource . $this->cache_id . $this->compile_id; + if ($this->smarty->allow_ambiguous_resources) { + $_templateId = $this->source->unique_resource . $this->cache_id . $this->compile_id; + } else { + $_templateId = $this->smarty->joined_template_dir . '#' . $this->template_resource . $this->cache_id . $this->compile_id; + } + if (isset($_templateId[150])) { $_templateId = sha1($_templateId); } diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 8d7b2db5..5ce1ada2 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -192,7 +192,11 @@ class Smarty_Internal_Utility { // remove from template cache $tpl->source; // have the template registered before unset() - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + if ($smarty->allow_ambiguous_resources) { + $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + } else { + $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; + } if (isset($_templateId[150])) { $_templateId = sha1($_templateId); }