fixed bug with nested calls to fetch() when caching enabled

This commit is contained in:
messju
2003-04-14 07:31:42 +00:00
parent 61b1b4134f
commit 238655b2fa

View File

@@ -1065,6 +1065,8 @@ class Smarty
*/ */
function fetch($tpl_file, $cache_id = null, $compile_id = null, $display = false) function fetch($tpl_file, $cache_id = null, $compile_id = null, $display = false)
{ {
static $_cache_info = array();
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE); $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
if($this->security && !in_array($this->template_dir, $this->secure_dir)) { if($this->security && !in_array($this->template_dir, $this->secure_dir)) {
@@ -1095,11 +1097,9 @@ class Smarty
$this->_inclusion_depth = 0; $this->_inclusion_depth = 0;
if ($this->caching) { if ($this->caching) {
if(!empty($this->_cache_info)) { // save old cache_info, initialize cache_info
// nested call, init cache_info array_push($_cache_info, $this->_cache_info);
$_cache_info = $this->_cache_info;
$this->_cache_info = array(); $this->_cache_info = array();
}
if ($this->_read_cache_file($tpl_file, $cache_id, $compile_id, $_smarty_results)) { if ($this->_read_cache_file($tpl_file, $cache_id, $compile_id, $_smarty_results)) {
if (@count($this->_cache_info['insert_tags'])) { if (@count($this->_cache_info['insert_tags'])) {
$this->_load_plugins($this->_cache_info['insert_tags']); $this->_load_plugins($this->_cache_info['insert_tags']);
@@ -1127,9 +1127,13 @@ class Smarty
echo $_smarty_results; echo $_smarty_results;
} }
error_reporting($_smarty_old_error_level); error_reporting($_smarty_old_error_level);
// restore initial cache_info
$this->_cache_info = array_pop($_cache_info);
return true; return true;
} else { } else {
error_reporting($_smarty_old_error_level); error_reporting($_smarty_old_error_level);
// restore initial cache_info
$this->_cache_info = array_pop($_cache_info);
return $_smarty_results; return $_smarty_results;
} }
} else { } else {
@@ -1138,10 +1142,6 @@ class Smarty
header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT'); header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');
} }
} }
if(isset($_cache_info)) {
// restore cache_info
$this->_cache_info = $_cache_info;
}
} }
if (count($this->autoload_filters)) { if (count($this->autoload_filters)) {
@@ -1174,6 +1174,8 @@ class Smarty
if ($this->caching) { if ($this->caching) {
$this->_write_cache_file($tpl_file, $cache_id, $compile_id, $_smarty_results); $this->_write_cache_file($tpl_file, $cache_id, $compile_id, $_smarty_results);
$_smarty_results = $this->_process_cached_inserts($_smarty_results); $_smarty_results = $this->_process_cached_inserts($_smarty_results);
// restore initial cache_info
$this->_cache_info = array_pop($_cache_info);
} }
if ($display) { if ($display) {