From e8a77171d3c348d905414a3184c1bf6408af8ec5 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Thu, 1 Jan 2015 22:27:45 +0100 Subject: [PATCH] implement templateId generation as method --- libs/Smarty.class.php | 20 +++++---------- .../smarty_internal_templatebase.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 0ae65ec4..3c7db90a 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -71,7 +71,7 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { /** * Try loading the Smmarty_Internal_Data class - * + * * If we fail we must load Smarty's autoloader. * Otherwise we may have a global autoloader like Composer */ @@ -89,7 +89,6 @@ require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; require SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; - /** * This is the main Smarty class * @@ -632,6 +631,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @var bool */ public $_parserdebug = false; + /**#@-*/ /** @@ -1287,18 +1287,7 @@ class Smarty extends Smarty_Internal_TemplateBase } else { $data = null; } - // default to cache_id and compile_id of Smarty object - $cache_id = $cache_id === null ? $this->cache_id : $cache_id; - $compile_id = $compile_id === null ? $this->compile_id : $compile_id; - // already in template cache? - 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); - } + $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); if ($do_clone) { if (isset($this->template_objects[$_templateId])) { // return cached template object @@ -1309,6 +1298,7 @@ class Smarty extends Smarty_Internal_TemplateBase $tpl->config_vars = array(); } else { $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id); + $tpl->templateId = $_templateId; } } else { if (isset($this->template_objects[$_templateId])) { @@ -1319,6 +1309,7 @@ class Smarty extends Smarty_Internal_TemplateBase $tpl->config_vars = array(); } else { $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); + $tpl->templateId = $_templateId; } } // fill data if present @@ -1529,6 +1520,7 @@ class Smarty extends Smarty_Internal_TemplateBase { $this->error_reporting = $error_reporting; } + /** * @param boolean $escape_html */ diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index a9f97a7a..3598faae 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -48,6 +48,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @var integer */ public $cache_lifetime = 3600; + /** * fetches a rendered Smarty template * @@ -467,6 +468,30 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data return $dataObj; } + /** + * Get unique template id + * + * @param string $template_name + * @param null|mixed $cache_id + * @param null|mixed $compile_id + * + * @return string + */ + public function getTemplateId($template_name, $cache_id = null, $compile_id = null) + { + $cache_id = isset($cache_id) ? $cache_id : $this->cache_id; + $compile_id = isset($compile_id) ? $compile_id : $this->compile_id; + if ($this->smarty->allow_ambiguous_resources) { + $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}"; + } else { + $_templateId = $this->smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}"; + } + if (isset($_templateId[150])) { + $_templateId = sha1($_templateId); + } + return $_templateId; + } + /** * Registers plugin to be used in templates *