mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +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:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.31-dev ===== (xx.xx.xx)
|
===== 3.1.31-dev ===== (xx.xx.xx)
|
||||||
|
15.09.2016
|
||||||
|
- 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
|
||||||
|
|
||||||
11.09.2016
|
11.09.2016
|
||||||
- improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288
|
- improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288
|
||||||
- improvement move often used code snippets into methods
|
- improvement move often used code snippets into methods
|
||||||
|
@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.31-dev/18';
|
const SMARTY_VERSION = '3.1.31-dev/19';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -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' ])) {
|
||||||
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||||
|
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||||
|
} else {
|
||||||
|
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||||
|
}
|
||||||
if ($compiler->nocache) {
|
if ($compiler->nocache) {
|
||||||
// create nocache var to make it know for further compiling
|
// 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);
|
$compiler->setNocacheInVariable($var);
|
||||||
}
|
}
|
||||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
$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' ];
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
||||||
$_output = $assignCompiler->compile($assignAttr, $compiler, array());
|
$_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;
|
return $_output;
|
||||||
} else {
|
} else {
|
||||||
return "<?php if ({$parameter['if condition']}) {?>";
|
return "<?php if ({$parameter['if condition']}) {?>";
|
||||||
@@ -123,15 +125,16 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$assignCode = '';
|
$assignCode = '';
|
||||||
|
$var = '';
|
||||||
if (is_array($parameter[ 'if condition' ])) {
|
if (is_array($parameter[ 'if condition' ])) {
|
||||||
$condition_by_assign = true;
|
$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) {
|
if ($compiler->nocache) {
|
||||||
// create nocache var to make it know for further compiling
|
// 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);
|
$compiler->setNocacheInVariable($var);
|
||||||
}
|
}
|
||||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||||
@@ -154,8 +157,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
|||||||
if ($condition_by_assign) {
|
if ($condition_by_assign) {
|
||||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||||
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
||||||
return $compiler->appendCode($_output,
|
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||||
"<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
|
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||||
|
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||||
|
'') . ") {?>");
|
||||||
} else {
|
} else {
|
||||||
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
||||||
return "<?php } elseif ({$parameter['if condition']}) {?>";
|
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));
|
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||||
if ($condition_by_assign) {
|
if ($condition_by_assign) {
|
||||||
$_output = $compiler->appendCode($_output, $assignCode);
|
$_output = $compiler->appendCode($_output, $assignCode);
|
||||||
return $compiler->appendCode($_output,
|
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||||
"<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
|
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||||
|
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||||
|
'') . ") {?>");
|
||||||
} else {
|
} else {
|
||||||
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,6 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
|||||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||||
if (is_array($parameter[ 'if condition' ])) {
|
if (is_array($parameter[ 'if condition' ])) {
|
||||||
if ($compiler->nocache) {
|
if ($compiler->nocache) {
|
||||||
$_nocache = ',true';
|
|
||||||
// create nocache var to make it know for further compiling
|
// create nocache var to make it know for further compiling
|
||||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||||
@@ -49,20 +48,19 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
|||||||
$var = $parameter[ 'if condition' ][ 'var' ];
|
$var = $parameter[ 'if condition' ][ 'var' ];
|
||||||
}
|
}
|
||||||
$compiler->setNocacheInVariable($var);
|
$compiler->setNocacheInVariable($var);
|
||||||
} else {
|
|
||||||
$_nocache = '';
|
|
||||||
}
|
}
|
||||||
|
$prefixVar = $compiler->getNewPrefixVariable();
|
||||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||||
$assignAttr = array();
|
$assignAttr = array();
|
||||||
$assignAttr[][ 'value' ] = $parameter[ 'if condition' ][ 'value' ];
|
$assignAttr[][ 'value' ] = "{$prefixVar}";
|
||||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||||
$_output = "<?php while (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
|
$_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
|
||||||
$_output .= $assignCompiler->compile($assignAttr, $compiler,
|
$_output .= $assignCompiler->compile($assignAttr, $compiler,
|
||||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
|
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
|
||||||
} else {
|
} else {
|
||||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
||||||
$_output = "<?php while (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
|
$_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
|
||||||
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user