mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-05 04:04:10 +02:00
- bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
This commit is contained in:
@@ -39,13 +39,13 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
}
|
||||
|
||||
if (is_array($parameter[ 'if condition' ])) {
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
} else {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
} else {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||
}
|
||||
$compiler->setNocacheInVariable($var);
|
||||
}
|
||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||
@@ -59,7 +59,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
||||
$_output = $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
}
|
||||
$_output .= "<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
|
||||
$_output .= "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] : '') . ") {?>";
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php if ({$parameter['if condition']}) {?>";
|
||||
@@ -123,15 +125,16 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
}
|
||||
|
||||
$assignCode = '';
|
||||
$var = '';
|
||||
if (is_array($parameter[ 'if condition' ])) {
|
||||
$condition_by_assign = true;
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
} else {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
} else {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||
}
|
||||
$compiler->setNocacheInVariable($var);
|
||||
}
|
||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||
@@ -154,8 +157,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
if ($condition_by_assign) {
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
||||
return $compiler->appendCode($_output,
|
||||
"<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
|
||||
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||
'') . ") {?>");
|
||||
} else {
|
||||
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
||||
return "<?php } elseif ({$parameter['if condition']}) {?>";
|
||||
@@ -165,8 +170,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
$_output = $compiler->appendCode($_output, $assignCode);
|
||||
return $compiler->appendCode($_output,
|
||||
"<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
|
||||
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||
'') . ") {?>");
|
||||
} else {
|
||||
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user