mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- bugfix template objects must be cached on $smarty->fetch('foo.tpl) calls incase the template is fetched
multiple times (forum topic 25909)
This commit is contained in:
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/50';
|
const SMARTY_VERSION = '3.1.30-dev/51';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
@@ -1046,23 +1046,23 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
} else {
|
} else {
|
||||||
$data = null;
|
$data = null;
|
||||||
}
|
}
|
||||||
if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId =
|
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
||||||
$this->_getTemplateId($template, $cache_id, $compile_id) ])
|
$tpl = null;
|
||||||
) {
|
if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId ])) {
|
||||||
$tpl = $do_clone ? clone $this->_cache[ 'isCached' ][ $_templateId ] :
|
$tpl = $do_clone ? clone $this->_cache[ 'isCached' ][ $_templateId ] :
|
||||||
$this->_cache[ 'isCached' ][ $_templateId ];
|
$this->_cache[ 'isCached' ][ $_templateId ];
|
||||||
$tpl->parent = $parent;
|
$template->tpl_vars = $template->config_vars = array();
|
||||||
$tpl->tpl_vars = array();
|
} else if (!$do_clone && isset($this->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||||
$tpl->config_vars = array();
|
$tpl = clone $this->_cache[ 'tplObjects' ][ $_templateId ];
|
||||||
} else {
|
} else {
|
||||||
/* @var Smarty_Internal_Template $tpl */
|
/* @var Smarty_Internal_Template $tpl */
|
||||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id, null, null);
|
$tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
|
||||||
|
$tpl->templateId = $_templateId;
|
||||||
}
|
}
|
||||||
if ($do_clone) {
|
if ($do_clone) {
|
||||||
$tpl->smarty = clone $tpl->smarty;
|
$tpl->smarty = clone $tpl->smarty;
|
||||||
} elseif ($parent === null) {
|
|
||||||
$tpl->parent = $this;
|
|
||||||
}
|
}
|
||||||
|
$tpl->parent = $parent ? $parent : $this;
|
||||||
// fill data if present
|
// fill data if present
|
||||||
if (!empty($data) && is_array($data)) {
|
if (!empty($data) && is_array($data)) {
|
||||||
// set up variable values
|
// set up variable values
|
||||||
|
@@ -155,14 +155,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$isCacheTpl =
|
$isCacheTpl =
|
||||||
$this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
$this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
||||||
if ($isCacheTpl) {
|
if ($isCacheTpl) {
|
||||||
if (!isset($this->cached)) {
|
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id ||
|
||||||
|
$this->cached->compile_id !== $this->compile_id
|
||||||
|
) {
|
||||||
$this->loadCached();
|
$this->loadCached();
|
||||||
}
|
}
|
||||||
$this->cached->render($this, $no_output_filter);
|
$this->cached->render($this, $no_output_filter);
|
||||||
} elseif ($this->source->handler->uncompiled) {
|
} elseif ($this->source->handler->uncompiled) {
|
||||||
$this->source->render($this);
|
$this->source->render($this);
|
||||||
} else {
|
} else {
|
||||||
if (!isset($this->compiled)) {
|
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
||||||
$this->loadCompiled();
|
$this->loadCompiled();
|
||||||
}
|
}
|
||||||
$this->compiled->render($this);
|
$this->compiled->render($this);
|
||||||
|
@@ -148,23 +148,24 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
private function _execute($template, $cache_id, $compile_id, $parent, $function)
|
private function _execute($template, $cache_id, $compile_id, $parent, $function)
|
||||||
{
|
{
|
||||||
$smarty = $this->_objType == 1 ? $this : $this->smarty;
|
$smarty = $this->_objType == 1 ? $this : $this->smarty;
|
||||||
|
$saveVars = true;
|
||||||
if ($template === null) {
|
if ($template === null) {
|
||||||
if ($this->_objType != 2) {
|
if ($this->_objType != 2) {
|
||||||
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
||||||
} else {
|
} else {
|
||||||
$template = clone $this;
|
$template = $this;
|
||||||
}
|
}
|
||||||
} elseif (is_object($template)) {
|
} elseif (is_object($template)) {
|
||||||
if (!isset($template->_objType) || $template->_objType != 2) {
|
if (!isset($template->_objType) || $template->_objType != 2) {
|
||||||
throw new SmartyException($function . '():Template object expected');
|
throw new SmartyException($function . '():Template object expected');
|
||||||
} else {
|
|
||||||
/* @var Smarty_Internal_Template $template */
|
|
||||||
$template = clone $template;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// get template object
|
// get template object
|
||||||
/* @var Smarty_Internal_Template $template */
|
/* @var Smarty_Internal_Template $template */
|
||||||
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
$saveVars = false;
|
||||||
|
|
||||||
|
$template =
|
||||||
|
$smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
||||||
if ($this->_objType == 1) {
|
if ($this->_objType == 1) {
|
||||||
// set caching in template object
|
// set caching in template object
|
||||||
$template->caching = $this->caching;
|
$template->caching = $this->caching;
|
||||||
@@ -187,12 +188,28 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($saveVars) {
|
||||||
|
$savedTplVars = $template->tpl_vars;
|
||||||
|
$savedConfigVars = $template->config_vars;
|
||||||
|
}
|
||||||
ob_start();
|
ob_start();
|
||||||
$template->_mergeVars();
|
$template->_mergeVars();
|
||||||
if (!empty(Smarty::$global_tpl_vars)) {
|
if (!empty(Smarty::$global_tpl_vars)) {
|
||||||
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
|
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
|
||||||
}
|
}
|
||||||
$result = $template->render(false, $function);
|
$result = $template->render(false, $function);
|
||||||
|
unset($template->ext->_inheritance);
|
||||||
|
$template->tpl_function = array();
|
||||||
|
if ($saveVars) {
|
||||||
|
$template->tpl_vars = $savedTplVars;
|
||||||
|
$template->config_vars = $savedConfigVars;
|
||||||
|
} else {
|
||||||
|
if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) {
|
||||||
|
$template->parent = null;
|
||||||
|
$template->tpl_vars = $template->config_vars = array();
|
||||||
|
$smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($_smarty_old_error_level)) {
|
if (isset($_smarty_old_error_level)) {
|
||||||
error_reporting($_smarty_old_error_level);
|
error_reporting($_smarty_old_error_level);
|
||||||
|
Reference in New Issue
Block a user