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