diff --git a/change_log.txt b/change_log.txt index 2b659965..133a5b81 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,6 @@ +10/05/2010 +- bugfix on {foreach} and {for} optimizations of 27/04/2010 + 09/05/2010 - update of template and config file parser because of minor parser generator bugs diff --git a/libs/sysplugins/smarty_internal_compile_for.php b/libs/sysplugins/smarty_internal_compile_for.php index a85a52f3..a848a6f4 100644 --- a/libs/sysplugins/smarty_internal_compile_for.php +++ b/libs/sysplugins/smarty_internal_compile_for.php @@ -43,9 +43,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); - $this->_open_tag('for', array('for', $this->compiler->nocache)); - // maybe nocache because of nocache variables - $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; + $local_vars = array(); $output = "tpl_vars[$_statement[var]] = new Smarty_Variable;"; $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n"; $compiler->local_var[$_statement['var']] = true; + $local_vars[] = $_statement['var']; } $output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[varloop]]->value$_attr[loop]){\n"; } else { $_statement = $_attr['start']; $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;"; $compiler->local_var[$_statement['var']] = true; + $local_vars[] = $_statement['var']; if (isset($_attr['step'])) { $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];"; } else { @@ -74,7 +74,11 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase { $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->first = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == 1;"; $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->last = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == \$_smarty_tpl->tpl_vars[$_statement[var]]->total;"; } - $output .= "?>"; + $output .= "?>"; + + $this->_open_tag('for', array('for', $this->compiler->nocache, $local_vars)); + // maybe nocache because of nocache variables + $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; // return compiled code return $output; } @@ -97,8 +101,8 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); - list($_open_tag, $nocache) = $this->_close_tag(array('for')); - $this->_open_tag('forelse', array('forelse', $nocache)); + list($_open_tag, $nocache, $local_vars) = $this->_close_tag(array('for')); + $this->_open_tag('forelse', array('forelse', $nocache, $local_vars)); return ""; } } @@ -124,7 +128,11 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase { $this->compiler->tag_nocache = true; } - list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('for', 'forelse')); + list($_open_tag, $this->compiler->nocache, $local_vars) = $this->_close_tag(array('for', 'forelse')); + + foreach ($local_vars as $var) { + unset($compiler->local_var[$var]); + } if ($_open_tag == 'forelse') return ""; else diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index aac39f64..bfc084da 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -28,10 +28,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); - $this->_open_tag('foreach', array('foreach', $this->compiler->nocache)); - // maybe nocache because of nocache variables - $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; - $from = $_attr['from']; $item = $_attr['item']; @@ -41,6 +37,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { $key = null; } + $this->_open_tag('foreach', array('foreach', $this->compiler->nocache, $item, $key)); + // maybe nocache because of nocache variables + $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; + if (isset($_attr['name'])) { $name = $_attr['name']; $has_name = true; @@ -153,8 +153,8 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); - list($_open_tag, $nocache) = $this->_close_tag(array('foreach')); - $this->_open_tag('foreachelse', array('foreachelse', $nocache)); + list($_open_tag, $nocache, $item, $key) = $this->_close_tag(array('foreach')); + $this->_open_tag('foreachelse', array('foreachelse', $nocache, $item, $key)); return ""; } @@ -181,7 +181,11 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase { $this->compiler->tag_nocache = true; } - list($_open_tag, $this->compiler->nocache) = $this->_close_tag(array('foreach', 'foreachelse')); + list($_open_tag, $this->compiler->nocache, $item, $key) = $this->_close_tag(array('foreach', 'foreachelse')); + unset($compiler->local_var[$item]); + if ($key != null) { + unset($compiler->local_var[$key]); + } if ($_open_tag == 'foreachelse') return "";