2009-11-06 14:35:00 +00:00
< ? php
/**
2011-09-16 14:19:56 +00:00
* Smarty Internal Plugin Compile While
* Compiles the { while } tag
*
2014-06-06 02:40:04 +00:00
* @ package Smarty
2011-09-16 14:19:56 +00:00
* @ subpackage Compiler
2014-06-06 02:40:04 +00:00
* @ author Uwe Tews
2011-09-16 14:19:56 +00:00
*/
2010-08-17 15:39:51 +00:00
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Smarty Internal Plugin Compile While Class
*
2014-06-06 02:40:04 +00:00
* @ package Smarty
2011-09-16 14:19:56 +00:00
* @ subpackage Compiler
*/
2013-07-14 22:15:45 +00:00
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
{
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Compiles code for the { while } tag
*
2013-07-14 22:15:45 +00:00
* @ param array $args array with attributes from parser
* @ param object $compiler compiler object
* @ param array $parameter array with compilation parameter
2014-06-06 02:40:04 +00:00
*
2011-09-16 14:19:56 +00:00
* @ return string compiled code
*/
2010-11-11 21:34:36 +00:00
public function compile ( $args , $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 , 'while' , $compiler -> nocache );
2009-11-06 14:35:00 +00:00
2014-06-06 02:40:04 +00:00
if ( ! array_key_exists ( " if condition " , $parameter )) {
2011-11-01 20:27:53 +00:00
$compiler -> trigger_template_error ( " missing while condition " , $compiler -> lex -> taglineno );
}
2009-11-06 14:35:00 +00:00
// maybe nocache because of nocache variables
2011-09-16 14:19:56 +00:00
$compiler -> nocache = $compiler -> nocache | $compiler -> tag_nocache ;
2010-11-11 21:34:36 +00:00
if ( is_array ( $parameter [ 'if condition' ])) {
2011-09-16 14:19:56 +00:00
if ( $compiler -> nocache ) {
$_nocache = ',true' ;
// create nocache var to make it know for further compiling
if ( is_array ( $parameter [ 'if condition' ][ 'var' ])) {
2015-01-06 01:18:58 +01:00
$compiler -> template -> tpl_vars [ trim ( $parameter [ 'if condition' ][ 'var' ][ 'var' ], " ' " )] = new Smarty_Variable ( null , true );
2011-09-16 14:19:56 +00:00
} else {
2015-01-06 01:18:58 +01:00
$compiler -> template -> tpl_vars [ trim ( $parameter [ 'if condition' ][ 'var' ], " ' " )] = new Smarty_Variable ( null , true );
2011-09-16 14:19:56 +00:00
}
} else {
$_nocache = '' ;
}
2010-11-24 19:38:45 +00:00
if ( is_array ( $parameter [ 'if condition' ][ 'var' ])) {
2011-09-16 14:19:56 +00:00
$_output = " <?php if (!isset( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ][ 'var' ] . " ]) || !is_array( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ][ 'var' ] . " ]->value)) \$ _smarty_tpl->createLocalArrayVariable( " . $parameter [ 'if condition' ][ 'var' ][ 'var' ] . " $_nocache ); \n " ;
2013-07-14 22:15:45 +00:00
$_output .= " while ( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ][ 'var' ] . " ]->value " . $parameter [ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] . " = " . $parameter [ 'if condition' ][ 'value' ] . " ) { ?> " ;
2010-11-24 19:38:45 +00:00
} else {
2011-09-16 14:19:56 +00:00
$_output = " <?php if (!isset( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ] . " ])) \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ] . " ] = new Smarty_Variable(null { $_nocache } ); " ;
2013-07-14 22:15:45 +00:00
$_output .= " while ( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ] . " ]->value = " . $parameter [ 'if condition' ][ 'value' ] . " ) { ?> " ;
2011-09-16 14:19:56 +00:00
}
2013-07-14 22:15:45 +00:00
2009-11-06 14:35:00 +00:00
return $_output ;
} else {
2013-07-14 22:15:45 +00:00
return " <?php while ( { $parameter [ 'if condition' ] } ) { ?> " ;
2011-09-16 14:19:56 +00:00
}
}
}
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Smarty Internal Plugin Compile Whileclose Class
*
2014-06-06 02:40:04 +00:00
* @ package Smarty
2011-09-16 14:19:56 +00:00
* @ subpackage Compiler
*/
2013-07-14 22:15:45 +00:00
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
{
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Compiles code for the { / while } tag
*
2013-07-14 22:15:45 +00:00
* @ param array $args array with attributes from parser
* @ param object $compiler compiler object
2014-06-06 02:40:04 +00:00
*
2011-09-16 14:19:56 +00:00
* @ return string compiled code
*/
2009-11-06 14:35:00 +00:00
public function compile ( $args , $compiler )
{
2010-08-17 15:39:51 +00:00
// must endblock be nocache?
2011-09-16 14:19:56 +00:00
if ( $compiler -> nocache ) {
$compiler -> tag_nocache = true ;
2009-11-06 14:35:00 +00:00
}
2011-09-16 14:19:56 +00:00
$compiler -> nocache = $this -> closeTag ( $compiler , array ( 'while' ));
2013-07-14 22:15:45 +00:00
2009-11-06 14:35:00 +00:00
return " <?php }?> " ;
2011-09-16 14:19:56 +00:00
}
}