2009-11-06 14:35:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Smarty Internal Plugin Compile If
|
|
|
|
* Compiles the {if} {else} {elseif} {/if} tags
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Smarty Internal Plugin Compile If Class
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Compiles code for the {if} tag
|
|
|
|
*
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
|
|
|
* @param array $parameter array with compilation parameter
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
|
|
|
* @return string compiled code
|
2015-08-06 01:19:11 +02:00
|
|
|
* @throws \SmartyCompilerException
|
2014-06-06 02:40:04 +00:00
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
|
|
|
// check and get attributes
|
2011-09-16 14:19:56 +00:00
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
$this->openTag($compiler, 'if', array(1, $compiler->nocache));
|
2010-11-11 21:34:36 +00:00
|
|
|
// must whole block be nocache ?
|
2011-09-16 14:19:56 +00:00
|
|
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
2018-08-31 16:45:09 +02:00
|
|
|
if (!isset($parameter[ 'if condition' ])) {
|
2017-11-06 01:02:56 +01:00
|
|
|
$compiler->trigger_template_error('missing if condition', null, true);
|
2011-11-01 20:27:53 +00:00
|
|
|
}
|
2016-02-09 01:27:15 +01:00
|
|
|
if (is_array($parameter[ 'if condition' ])) {
|
2016-09-15 02:56:34 +02:00
|
|
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
|
|
|
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
|
|
|
} else {
|
|
|
|
$var = $parameter[ 'if condition' ][ 'var' ];
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($compiler->nocache) {
|
|
|
|
// create nocache var to make it know for further compiling
|
2016-02-09 23:27:07 +01:00
|
|
|
$compiler->setNocacheInVariable($var);
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2016-09-15 08:36:12 +02:00
|
|
|
$prefixVar = $compiler->getNewPrefixVariable();
|
2017-11-06 01:02:56 +01:00
|
|
|
$_output = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignAttr = array();
|
2017-11-06 01:02:56 +01:00
|
|
|
$assignAttr[][ 'value' ] = $prefixVar;
|
2016-09-15 08:36:12 +02:00
|
|
|
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
2016-02-09 01:27:15 +01:00
|
|
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
2018-06-12 09:58:15 +02:00
|
|
|
$_output .= $assignCompiler->compile(
|
2018-08-31 16:45:09 +02:00
|
|
|
$assignAttr,
|
|
|
|
$compiler,
|
2018-06-12 09:58:15 +02:00
|
|
|
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
|
|
|
);
|
2010-11-24 19:38:45 +00:00
|
|
|
} else {
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
2016-09-15 08:36:12 +02:00
|
|
|
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2016-09-15 08:36:12 +02:00
|
|
|
$_output .= "<?php if ({$prefixVar}) {?>";
|
2009-11-06 14:35:00 +00:00
|
|
|
return $_output;
|
|
|
|
} else {
|
2013-07-14 22:15:45 +00:00
|
|
|
return "<?php if ({$parameter['if condition']}) {?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Smarty Internal Plugin Compile Else Class
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Compiles code for the {else} tag
|
|
|
|
*
|
2017-10-26 10:25:41 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
|
|
|
* @return string compiled code
|
2018-06-12 09:58:15 +02:00
|
|
|
*/
|
2017-10-26 10:25:41 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
|
|
|
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
2017-11-06 01:02:56 +01:00
|
|
|
return '<?php } else { ?>';
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Smarty Internal Plugin Compile ElseIf Class
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Compiles code for the {elseif} tag
|
|
|
|
*
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
|
|
|
* @param array $parameter array with compilation parameter
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
|
|
|
* @return string compiled code
|
2015-08-06 01:19:11 +02:00
|
|
|
* @throws \SmartyCompilerException
|
2014-06-06 02:40:04 +00:00
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
|
|
|
// check and get attributes
|
2011-09-16 14:19:56 +00:00
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
2018-08-31 16:45:09 +02:00
|
|
|
if (!isset($parameter[ 'if condition' ])) {
|
2017-11-06 01:02:56 +01:00
|
|
|
$compiler->trigger_template_error('missing elseif condition', null, true);
|
2011-11-01 20:27:53 +00:00
|
|
|
}
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignCode = '';
|
2016-09-15 02:56:34 +02:00
|
|
|
$var = '';
|
2016-02-09 01:27:15 +01:00
|
|
|
if (is_array($parameter[ 'if condition' ])) {
|
2011-09-16 14:19:56 +00:00
|
|
|
$condition_by_assign = true;
|
2016-09-15 02:56:34 +02:00
|
|
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
|
|
|
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
|
|
|
} else {
|
|
|
|
$var = $parameter[ 'if condition' ][ 'var' ];
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($compiler->nocache) {
|
|
|
|
// create nocache var to make it know for further compiling
|
2016-02-09 23:27:07 +01:00
|
|
|
$compiler->setNocacheInVariable($var);
|
|
|
|
}
|
2016-09-15 08:36:12 +02:00
|
|
|
$prefixVar = $compiler->getNewPrefixVariable();
|
2017-11-06 01:02:56 +01:00
|
|
|
$assignCode = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
|
|
|
$assignAttr = array();
|
2017-11-06 01:02:56 +01:00
|
|
|
$assignAttr[][ 'value' ] = $prefixVar;
|
2016-02-09 23:27:07 +01:00
|
|
|
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
|
|
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
2018-06-12 09:58:15 +02:00
|
|
|
$assignCode .= $assignCompiler->compile(
|
2018-08-31 16:45:09 +02:00
|
|
|
$assignAttr,
|
|
|
|
$compiler,
|
2018-06-12 09:58:15 +02:00
|
|
|
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
|
|
|
);
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2016-02-09 23:27:07 +01:00
|
|
|
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
2016-09-15 08:36:12 +02:00
|
|
|
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$condition_by_assign = false;
|
|
|
|
}
|
2016-02-09 23:27:07 +01:00
|
|
|
$prefixCode = $compiler->getPrefixCode();
|
|
|
|
if (empty($prefixCode)) {
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($condition_by_assign) {
|
|
|
|
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
2016-02-09 23:27:07 +01:00
|
|
|
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
2016-09-15 08:36:12 +02:00
|
|
|
return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
|
|
|
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
2013-07-14 22:15:45 +00:00
|
|
|
return "<?php } elseif ({$parameter['if condition']}) {?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
} else {
|
2016-02-09 23:27:07 +01:00
|
|
|
$_output = $compiler->appendCode("<?php } else {\n?>", $prefixCode);
|
2011-09-16 14:19:56 +00:00
|
|
|
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
|
|
|
if ($condition_by_assign) {
|
2016-02-09 23:27:07 +01:00
|
|
|
$_output = $compiler->appendCode($_output, $assignCode);
|
2016-09-15 08:36:12 +02:00
|
|
|
return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2016-02-09 23:27:07 +01:00
|
|
|
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Smarty Internal Plugin Compile Ifclose Class
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2014-06-06 02:40:04 +00:00
|
|
|
* Compiles code for the {/if} tag
|
|
|
|
*
|
2017-10-26 10:25:41 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2017-10-26 10:25:41 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
// must endblock be nocache?
|
|
|
|
if ($compiler->nocache) {
|
|
|
|
$compiler->tag_nocache = true;
|
|
|
|
}
|
|
|
|
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
|
2009-11-06 14:35:00 +00:00
|
|
|
$tmp = '';
|
2018-08-31 16:45:09 +02:00
|
|
|
for ($i = 0; $i < $nesting; $i++) {
|
2011-09-16 14:19:56 +00:00
|
|
|
$tmp .= '}';
|
|
|
|
}
|
2010-01-14 20:57:27 +00:00
|
|
|
return "<?php {$tmp}?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|