IP/libs/sysplugins/smarty_internal_compile_while.php

103 lines
3.8 KiB
PHP
Raw Normal View History

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