fusionpbx/resources/templates/engine/smarty/sysplugins/smarty_internal_compile_whi...

101 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2013-11-09 21:02:56 +01:00
<?php
/**
* Smarty Internal Plugin Compile While
* Compiles the {while} tag
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage Compiler
2018-11-07 08:18:14 +01:00
* @author Uwe Tews
2013-11-09 21:02:56 +01:00
*/
/**
* Smarty Internal Plugin Compile While Class
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {while} tag
*
2018-11-07 08:18:14 +01:00
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
2013-11-09 21:02:56 +01:00
* @return string compiled code
2018-11-07 08:18:14 +01:00
* @throws \SmartyCompilerException
2013-11-09 21:02:56 +01:00
*/
2018-11-07 08:18:14 +01:00
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
2013-11-09 21:02:56 +01:00
{
2018-11-07 08:18:14 +01:00
$compiler->loopNesting++;
2013-11-09 21:02:56 +01:00
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache);
2018-11-07 08:18:14 +01:00
if (!array_key_exists('if condition', $parameter)) {
$compiler->trigger_template_error('missing while condition', null, true);
2013-11-09 21:02:56 +01:00
}
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
2018-11-07 08:18:14 +01:00
if (is_array($parameter[ 'if condition' ])) {
2013-11-09 21:02:56 +01:00
if ($compiler->nocache) {
// create nocache var to make it know for further compiling
2018-11-07 08:18:14 +01:00
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
2013-11-09 21:02:56 +01:00
} else {
2018-11-07 08:18:14 +01:00
$var = $parameter[ 'if condition' ][ 'var' ];
2013-11-09 21:02:56 +01:00
}
2018-11-07 08:18:14 +01:00
$compiler->setNocacheInVariable($var);
2013-11-09 21:02:56 +01:00
}
2018-11-07 08:18:14 +01:00
$prefixVar = $compiler->getNewPrefixVariable();
$assignCompiler = new Smarty_Internal_Compile_Assign();
$assignAttr = array();
$assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile(
$assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
2013-11-09 21:02:56 +01:00
} else {
2018-11-07 08:18:14 +01:00
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
2013-11-09 21:02:56 +01:00
}
return $_output;
} else {
2018-11-07 08:18:14 +01:00
return "<?php\n while ({$parameter['if condition']}) {?>";
2013-11-09 21:02:56 +01:00
}
}
}
/**
* Smarty Internal Plugin Compile Whileclose Class
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/while} tag
*
2018-11-07 08:18:14 +01:00
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
2013-11-09 21:02:56 +01:00
* @return string compiled code
*/
2018-11-07 08:18:14 +01:00
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
2013-11-09 21:02:56 +01:00
{
2018-11-07 08:18:14 +01:00
$compiler->loopNesting--;
2013-11-09 21:02:56 +01:00
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
$compiler->nocache = $this->closeTag($compiler, array('while'));
2018-11-07 08:18:14 +01:00
return "<?php }?>\n";
2013-11-09 21:02:56 +01:00
}
}