init
[garradin.git] / include / libs / template_lite / internal / compile.parse_is_expr.php
1 <?php
2 /**
3 * Template Lite compile IS exprenssion in IF tag - template internal module
4 *
5 * Type: template
6 * Name: compile_parse_is_expr
7 */
8
9 function compile_parse_is_expr($is_arg, $_args, &$object)
10 {
11 $expr_end = 0;
12 $negate_expr = false;
13
14 if (($first_arg = array_shift($_args)) == 'not') {
15 $negate_expr = true;
16 $expr_type = array_shift($_args);
17 }
18 else
19 {
20 $expr_type = $first_arg;
21 }
22
23 switch ($expr_type) {
24 case 'even':
25 if (isset($_args[$expr_end]) && $_args[$expr_end] == 'by')
26 {
27 $expr_end++;
28 $expr_arg = $_args[$expr_end++];
29 $expr = "!(1 & ($is_arg / " . $object->_parse_variable($expr_arg) . "))";
30 }
31 else
32 {
33 $expr = "!(1 & $is_arg)";
34 }
35 break;
36
37 case 'odd':
38 if (isset($_args[$expr_end]) && $_args[$expr_end] == 'by')
39 {
40 $expr_end++;
41 $expr_arg = $_args[$expr_end++];
42 $expr = "(1 & ($is_arg / " . $object->_parse_variable($expr_arg) . "))";
43 }
44 else
45 {
46 $expr = "(1 & $is_arg)";
47 }
48 break;
49
50 case 'div':
51 if (@$_args[$expr_end] == 'by')
52 {
53 $expr_end++;
54 $expr_arg = $_args[$expr_end++];
55 $expr = "!($is_arg % " . $object->_parse_variable($expr_arg) . ")";
56 }
57 else
58 {
59 throw new Template_Exception("expecting 'by' after 'div'", $object);
60 }
61 break;
62
63 default:
64 throw new Template_Exception("unknown 'is' expression - '$expr_type'", $object);
65 break;
66 }
67
68 if ($negate_expr) {
69 $expr = "!($expr)";
70 }
71
72 array_splice($_args, 0, $expr_end, $expr);
73
74 return $_args;
75 }
76
77 ?>