- bugfix on template functions called nocache calling other template functions

This commit is contained in:
uwe.tews@googlemail.com
2011-09-28 15:56:01 +00:00
parent d9ba05407a
commit bc2d519c38
5 changed files with 30 additions and 1 deletions

View File

@@ -1,4 +1,7 @@
===== trunk =====
28.09.2011
- bugfix on template functions called nocache calling other template functions
27.09.2011
- bugfix possible warning "attempt to modify property of non-object" in {section} (issue #34)
- added chaining to Smarty_Internal_Data so $smarty->assign('a',1)->assign('b',2); is possible now

View File

@@ -57,6 +57,9 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
$_assign = $_attr['assign'];
}
$_name = $_attr['name'];
if ($compiler->compiles_template_function) {
$compiler->called_functions[] = trim($_name, "'\"");
}
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
// set flag (compiled code of {function} must be included in cache file
if ($compiler->nocache || $compiler->tag_nocache) {

View File

@@ -61,6 +61,8 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase {
$this->openTag($compiler, 'function', $save);
$_name = trim($_attr['name'], "'\"");
unset($_attr['name']);
// set flag that we are compiling a template function
$compiler->compiles_template_function = true;
$compiler->template->properties['function'][$_name]['parameter'] = array();
$_smarty_tpl = $compiler->template;
foreach ($_attr as $_key => $_data) {
@@ -141,12 +143,16 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
. $compiler->parser->current_buffer->to_smarty_php();
$compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code;
$compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions;
$compiler->called_functions = array();
$compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name];
$compiler->has_code = false;
$output = true;
} else {
$output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}}?>\n";
}
// reset flag that we are compiling a template function
$compiler->compiles_template_function = false;
// restore old compiler status
$compiler->parser->current_buffer = $saved_data[1];
$compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2];

View File

@@ -360,7 +360,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// copy code of {function} tags called in nocache mode
foreach ($this->smarty->template_functions as $name => $function_data) {
if (isset($function_data['called_nocache'])) {
unset($function_data['called_nocache'], $this->smarty->template_functions[$name]['called_nocache']);
foreach ($function_data['called_functions'] as $func_name) {
$this->smarty->template_functions[$func_name]['called_nocache'] = true;
}
}
}
foreach ($this->smarty->template_functions as $name => $function_data) {
if (isset($function_data['called_nocache'])) {
unset($function_data['called_nocache'], $function_data['called_functions'], $this->smarty->template_functions[$name]['called_nocache']);
$this->properties['function'][$name] = $function_data;
}
}

View File

@@ -97,6 +97,16 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @var bool
*/
public $write_compiled_code = true;
/**
* flag if currently a template function is compiled
* @var bool
*/
public $compiles_template_function = false;
/**
* called subfuntions from template function
* @var array
*/
public $called_functions = array();
/**
* flags for used modifier plugins
* @var array