library/smarty/libs/sysplugins/smarty_internal_compile_continue.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Compile Continue
       
     4  * Compiles the {continue} tag
       
     5  *
       
     6  * @package    Smarty
       
     7  * @subpackage Compiler
       
     8  * @author     Uwe Tews
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Compile Continue Class
       
    13  *
       
    14  * @package    Smarty
       
    15  * @subpackage Compiler
       
    16  */
       
    17 class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase {
       
    18     /**
       
    19      * Attribute definition: Overwrites base class.
       
    20      *
       
    21      * @var array
       
    22      * @see Smarty_Internal_CompileBase
       
    23      */
       
    24     public $optional_attributes = array('levels');
       
    25     /**
       
    26      * Attribute definition: Overwrites base class.
       
    27      *
       
    28      * @var array
       
    29      * @see Smarty_Internal_CompileBase
       
    30      */
       
    31     public $shorttag_order = array('levels');
       
    32 
       
    33     /**
       
    34      * Compiles code for the {continue} tag
       
    35      *
       
    36      * @param  array $args array with attributes from parser
       
    37      * @param  object $compiler compiler object
       
    38      * @param  array $parameter array with compilation parameter
       
    39      *
       
    40      * @return string compiled code
       
    41      */
       
    42     public function compile($args, $compiler, $parameter) {
       
    43         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
       
    44         // check and get attributes
       
    45         $_attr = $this->getAttributes($compiler, $args);
       
    46 
       
    47         if ($_attr['nocache'] === true) {
       
    48             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
       
    49         }
       
    50 
       
    51         if (isset($_attr['levels'])) {
       
    52             if (!is_numeric($_attr['levels'])) {
       
    53                 $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
       
    54             }
       
    55             $_levels = $_attr['levels'];
       
    56         } else {
       
    57             $_levels = 1;
       
    58         }
       
    59         $level_count = $_levels;
       
    60         $stack_count = count($compiler->_tag_stack) - 1;
       
    61         while ($level_count > 0 && $stack_count >= 0) {
       
    62             if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
       
    63                 $level_count--;
       
    64             }
       
    65             $stack_count--;
       
    66         }
       
    67         if ($level_count != 0) {
       
    68             $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
       
    69         }
       
    70 
       
    71         return "<?php continue {$_levels};?>";
       
    72     }
       
    73 }