mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
implement templateId generation as method
This commit is contained in:
@@ -89,7 +89,6 @@ require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
|
|||||||
require SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
|
require SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
|
||||||
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
|
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the main Smarty class
|
* This is the main Smarty class
|
||||||
*
|
*
|
||||||
@@ -632,6 +631,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $_parserdebug = false;
|
public $_parserdebug = false;
|
||||||
|
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1287,18 +1287,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
} else {
|
} else {
|
||||||
$data = null;
|
$data = null;
|
||||||
}
|
}
|
||||||
// default to cache_id and compile_id of Smarty object
|
$_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
if ($do_clone) {
|
if ($do_clone) {
|
||||||
if (isset($this->template_objects[$_templateId])) {
|
if (isset($this->template_objects[$_templateId])) {
|
||||||
// return cached template object
|
// return cached template object
|
||||||
@@ -1309,6 +1298,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->config_vars = array();
|
$tpl->config_vars = array();
|
||||||
} else {
|
} else {
|
||||||
$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
|
$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
|
||||||
|
$tpl->templateId = $_templateId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($this->template_objects[$_templateId])) {
|
if (isset($this->template_objects[$_templateId])) {
|
||||||
@@ -1319,6 +1309,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->config_vars = array();
|
$tpl->config_vars = array();
|
||||||
} else {
|
} else {
|
||||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
|
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
|
||||||
|
$tpl->templateId = $_templateId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fill data if present
|
// fill data if present
|
||||||
@@ -1529,6 +1520,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
{
|
{
|
||||||
$this->error_reporting = $error_reporting;
|
$this->error_reporting = $error_reporting;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param boolean $escape_html
|
* @param boolean $escape_html
|
||||||
*/
|
*/
|
||||||
|
@@ -48,6 +48,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
public $cache_lifetime = 3600;
|
public $cache_lifetime = 3600;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches a rendered Smarty template
|
* fetches a rendered Smarty template
|
||||||
*
|
*
|
||||||
@@ -467,6 +468,30 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
return $dataObj;
|
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
|
* Registers plugin to be used in templates
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user