Code

Updated smarty to 1.0.9
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_break.php
1 <?php\r
2 \r
3 /**\r
4  * Smarty Internal Plugin Compile Break\r
5  * \r
6  * Compiles the {break} tag\r
7  * \r
8  * @package Smarty\r
9  * @subpackage Compiler\r
10  * @author Uwe Tews \r
11  */\r
12 /**\r
13  * Smarty Internal Plugin Compile Break Class\r
14  */\r
15 class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase {\r
16         // attribute definitions\r
17     public $optional_attributes = array('levels'); \r
18     public $shorttag_order = array('levels');\r
19 \r
20 \r
21     /**\r
22      * Compiles code for the {break} tag\r
23      * \r
24      * @param array $args array with attributes from parser\r
25      * @param object $compiler compiler object\r
26      * @param array $parameter array with compilation parameter\r
27      * @return string compiled code\r
28      */\r
29     public function compile($args, $compiler, $parameter)\r
30     {    \r
31         $this->compiler = $compiler;\r
32         $this->smarty = $compiler->smarty;\r
33         // check and get attributes\r
34         $_attr = $this->_get_attributes($args);\r
35 \r
36         if ($_attr['nocache'] === true) {\r
37                 $this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);\r
38         }\r
39 \r
40         if (isset($_attr['levels'])) {\r
41             if (!is_numeric($_attr['levels'])) {\r
42                 $this->compiler->trigger_template_error('level attribute must be a numeric constant', $this->compiler->lex->taglineno);\r
43             } \r
44             $_levels = $_attr['levels'];\r
45         } else {\r
46             $_levels = 1;\r
47         } \r
48         $level_count = $_levels;\r
49         $stack_count = count($compiler->_tag_stack) - 1;\r
50         while ($level_count > 0 && $stack_count >= 0) {\r
51             if (in_array($compiler->_tag_stack[$stack_count][0], array('for', 'foreach', 'while', 'section'))) {\r
52                 $level_count--;\r
53             } \r
54             $stack_count--;\r
55         } \r
56         if ($level_count != 0) {\r
57             $this->compiler->trigger_template_error("cannot break {$_levels} level(s)", $this->compiler->lex->taglineno);\r
58         } \r
59         // this tag does not return compiled code\r
60         $this->compiler->has_code = true;\r
61         return "<?php break {$_levels}?>";\r
62     } \r
63\r
64 \r
65 ?>