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
*
* @ package Smarty
* @ subpackage Compiler
* @ author Uwe Tews
*/
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
*
* @ package Smarty
* @ subpackage Compiler
*/
2009-11-06 14:35:00 +00:00
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
2011-09-16 14:19:56 +00:00
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Compiles code for the { while } tag
*
* @ param array $args array with attributes from parser
* @ param object $compiler compiler object
* @ param array $parameter array with compilation parameter
* @ 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
2011-11-01 20:27:53 +00:00
if ( ! array_key_exists ( " if condition " , $parameter )) {
$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' ])) {
$compiler -> template -> tpl_vars [ trim ( $parameter [ 'if condition' ][ 'var' ][ 'var' ], " ' " )] = new Smarty_variable ( null , true );
} else {
$compiler -> template -> tpl_vars [ trim ( $parameter [ 'if condition' ][ 'var' ], " ' " )] = new Smarty_variable ( null , true );
}
} 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 " ;
$_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 } ); " ;
$_output .= " while ( \$ _smarty_tpl->tpl_vars[ " . $parameter [ 'if condition' ][ 'var' ] . " ]->value = " . $parameter [ 'if condition' ][ 'value' ] . " ) { ?> " ;
}
2009-11-06 14:35:00 +00:00
return $_output ;
} else {
2010-11-24 19:38: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
*
* @ package Smarty
* @ subpackage Compiler
*/
2009-11-06 14:35:00 +00:00
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase {
2011-09-16 14:19:56 +00:00
2009-11-06 14:35:00 +00:00
/**
2011-09-16 14:19:56 +00:00
* Compiles code for the { / while } tag
*
* @ param array $args array with attributes from parser
* @ param object $compiler compiler object
* @ 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' ));
2009-11-06 14:35:00 +00:00
return " <?php }?> " ;
2011-09-16 14:19:56 +00:00
}
}
2010-08-17 15:39:51 +00:00
?>