@@ -31,13 +31,13 @@ |
||
31 | 31 | */ |
32 | 32 | function Dwoo_Plugin_array_compile(Dwoo_Compiler $compiler, array $rest = array()) |
33 | 33 | { |
34 | - $out = array(); |
|
35 | - foreach ($rest as $key => $value) { |
|
36 | - if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
37 | - $key = "'".$key."'"; |
|
38 | - } |
|
39 | - $out[] = $key.'=>'.$value; |
|
40 | - } |
|
34 | + $out = array(); |
|
35 | + foreach ($rest as $key => $value) { |
|
36 | + if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
37 | + $key = "'".$key."'"; |
|
38 | + } |
|
39 | + $out[] = $key.'=>'.$value; |
|
40 | + } |
|
41 | 41 | |
42 | - return 'array('.implode(', ', $out).')'; |
|
42 | + return 'array('.implode(', ', $out).')'; |
|
43 | 43 | } |
@@ -31,207 +31,207 @@ |
||
31 | 31 | */ |
32 | 32 | class Dwoo_Plugin_if extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable |
33 | 33 | { |
34 | - public function init(array $rest) |
|
35 | - { |
|
36 | - } |
|
34 | + public function init(array $rest) |
|
35 | + { |
|
36 | + } |
|
37 | 37 | |
38 | - public static function replaceKeywords(array $params, array $tokens, Dwoo_Compiler $compiler) |
|
39 | - { |
|
40 | - $p = array(); |
|
38 | + public static function replaceKeywords(array $params, array $tokens, Dwoo_Compiler $compiler) |
|
39 | + { |
|
40 | + $p = array(); |
|
41 | 41 | |
42 | - reset($params); |
|
43 | - while (list($k, $v) = each($params)) { |
|
44 | - $v = (string) $v; |
|
45 | - if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
46 | - $vmod = strtolower(substr($v, 1, -1)); |
|
47 | - } else { |
|
48 | - $vmod = strtolower($v); |
|
49 | - } |
|
50 | - switch ($vmod) { |
|
42 | + reset($params); |
|
43 | + while (list($k, $v) = each($params)) { |
|
44 | + $v = (string) $v; |
|
45 | + if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
46 | + $vmod = strtolower(substr($v, 1, -1)); |
|
47 | + } else { |
|
48 | + $vmod = strtolower($v); |
|
49 | + } |
|
50 | + switch ($vmod) { |
|
51 | 51 | |
52 | - case 'and': |
|
53 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
54 | - $p[] = '&&'; |
|
55 | - } else { |
|
56 | - $p[] = $v; |
|
57 | - } |
|
58 | - break; |
|
59 | - case 'or': |
|
60 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
61 | - $p[] = '||'; |
|
62 | - } else { |
|
63 | - $p[] = $v; |
|
64 | - } |
|
65 | - break; |
|
66 | - case 'xor': |
|
67 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
68 | - $p[] = '^'; |
|
69 | - } else { |
|
70 | - $p[] = $v; |
|
71 | - } |
|
72 | - break; |
|
73 | - case 'eq': |
|
74 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
75 | - $p[] = '=='; |
|
76 | - } else { |
|
77 | - $p[] = $v; |
|
78 | - } |
|
79 | - break; |
|
80 | - case 'ne': |
|
81 | - case 'neq': |
|
82 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
83 | - $p[] = '!='; |
|
84 | - } else { |
|
85 | - $p[] = $v; |
|
86 | - } |
|
87 | - break; |
|
88 | - case 'gte': |
|
89 | - case 'ge': |
|
90 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
91 | - $p[] = '>='; |
|
92 | - } else { |
|
93 | - $p[] = $v; |
|
94 | - } |
|
95 | - break; |
|
96 | - case 'lte': |
|
97 | - case 'le': |
|
98 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
99 | - $p[] = '<='; |
|
100 | - } else { |
|
101 | - $p[] = $v; |
|
102 | - } |
|
103 | - break; |
|
104 | - case 'gt': |
|
105 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
106 | - $p[] = '>'; |
|
107 | - } else { |
|
108 | - $p[] = $v; |
|
109 | - } |
|
110 | - break; |
|
111 | - case 'lt': |
|
112 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
113 | - $p[] = '<'; |
|
114 | - } else { |
|
115 | - $p[] = $v; |
|
116 | - } |
|
117 | - break; |
|
118 | - case 'mod': |
|
119 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
120 | - $p[] = '%'; |
|
121 | - } else { |
|
122 | - $p[] = $v; |
|
123 | - } |
|
124 | - break; |
|
125 | - case 'not': |
|
126 | - if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
127 | - $p[] = '!'; |
|
128 | - } else { |
|
129 | - $p[] = $v; |
|
130 | - } |
|
131 | - break; |
|
132 | - case '<>': |
|
133 | - $p[] = '!='; |
|
134 | - break; |
|
135 | - case '==': |
|
136 | - case '!=': |
|
137 | - case '>=': |
|
138 | - case '<=': |
|
139 | - case '>': |
|
140 | - case '<': |
|
141 | - case '===': |
|
142 | - case '!==': |
|
143 | - case '%': |
|
144 | - case '!': |
|
145 | - case '^': |
|
146 | - $p[] = $vmod; |
|
147 | - break; |
|
148 | - case 'is': |
|
149 | - if ($tokens[$k] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
150 | - $p[] = $v; |
|
151 | - break; |
|
152 | - } |
|
153 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
154 | - $negate = true; |
|
155 | - next($params); |
|
156 | - } else { |
|
157 | - $negate = false; |
|
158 | - } |
|
159 | - $ptr = 1 + (int) $negate; |
|
160 | - if ($tokens[$k + $ptr] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
161 | - break; |
|
162 | - } |
|
163 | - if (!isset($params[$k + $ptr])) { |
|
164 | - $params[$k + $ptr] = ''; |
|
165 | - } else { |
|
166 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
167 | - } |
|
168 | - switch ($params[$k + $ptr]) { |
|
52 | + case 'and': |
|
53 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
54 | + $p[] = '&&'; |
|
55 | + } else { |
|
56 | + $p[] = $v; |
|
57 | + } |
|
58 | + break; |
|
59 | + case 'or': |
|
60 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
61 | + $p[] = '||'; |
|
62 | + } else { |
|
63 | + $p[] = $v; |
|
64 | + } |
|
65 | + break; |
|
66 | + case 'xor': |
|
67 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
68 | + $p[] = '^'; |
|
69 | + } else { |
|
70 | + $p[] = $v; |
|
71 | + } |
|
72 | + break; |
|
73 | + case 'eq': |
|
74 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
75 | + $p[] = '=='; |
|
76 | + } else { |
|
77 | + $p[] = $v; |
|
78 | + } |
|
79 | + break; |
|
80 | + case 'ne': |
|
81 | + case 'neq': |
|
82 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
83 | + $p[] = '!='; |
|
84 | + } else { |
|
85 | + $p[] = $v; |
|
86 | + } |
|
87 | + break; |
|
88 | + case 'gte': |
|
89 | + case 'ge': |
|
90 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
91 | + $p[] = '>='; |
|
92 | + } else { |
|
93 | + $p[] = $v; |
|
94 | + } |
|
95 | + break; |
|
96 | + case 'lte': |
|
97 | + case 'le': |
|
98 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
99 | + $p[] = '<='; |
|
100 | + } else { |
|
101 | + $p[] = $v; |
|
102 | + } |
|
103 | + break; |
|
104 | + case 'gt': |
|
105 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
106 | + $p[] = '>'; |
|
107 | + } else { |
|
108 | + $p[] = $v; |
|
109 | + } |
|
110 | + break; |
|
111 | + case 'lt': |
|
112 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
113 | + $p[] = '<'; |
|
114 | + } else { |
|
115 | + $p[] = $v; |
|
116 | + } |
|
117 | + break; |
|
118 | + case 'mod': |
|
119 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
120 | + $p[] = '%'; |
|
121 | + } else { |
|
122 | + $p[] = $v; |
|
123 | + } |
|
124 | + break; |
|
125 | + case 'not': |
|
126 | + if ($tokens[$k] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
127 | + $p[] = '!'; |
|
128 | + } else { |
|
129 | + $p[] = $v; |
|
130 | + } |
|
131 | + break; |
|
132 | + case '<>': |
|
133 | + $p[] = '!='; |
|
134 | + break; |
|
135 | + case '==': |
|
136 | + case '!=': |
|
137 | + case '>=': |
|
138 | + case '<=': |
|
139 | + case '>': |
|
140 | + case '<': |
|
141 | + case '===': |
|
142 | + case '!==': |
|
143 | + case '%': |
|
144 | + case '!': |
|
145 | + case '^': |
|
146 | + $p[] = $vmod; |
|
147 | + break; |
|
148 | + case 'is': |
|
149 | + if ($tokens[$k] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
150 | + $p[] = $v; |
|
151 | + break; |
|
152 | + } |
|
153 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
154 | + $negate = true; |
|
155 | + next($params); |
|
156 | + } else { |
|
157 | + $negate = false; |
|
158 | + } |
|
159 | + $ptr = 1 + (int) $negate; |
|
160 | + if ($tokens[$k + $ptr] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
161 | + break; |
|
162 | + } |
|
163 | + if (!isset($params[$k + $ptr])) { |
|
164 | + $params[$k + $ptr] = ''; |
|
165 | + } else { |
|
166 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
167 | + } |
|
168 | + switch ($params[$k + $ptr]) { |
|
169 | 169 | |
170 | - case 'div': |
|
171 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
172 | - $p[] = ' % '.$params[$k + $ptr + 2].' '.($negate ? '!' : '=').'== 0'; |
|
173 | - next($params); |
|
174 | - next($params); |
|
175 | - next($params); |
|
176 | - } else { |
|
177 | - throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k - 1].' is '.($negate ? 'not ' : '').'div '.$params[$k + $ptr + 1].' '.$params[$k + $ptr + 2]); |
|
178 | - } |
|
179 | - break; |
|
180 | - case 'even': |
|
181 | - $a = array_pop($p); |
|
182 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
183 | - $b = $params[$k + $ptr + 2]; |
|
184 | - $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
|
185 | - next($params); |
|
186 | - next($params); |
|
187 | - } else { |
|
188 | - $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; |
|
189 | - } |
|
190 | - next($params); |
|
191 | - break; |
|
192 | - case 'odd': |
|
193 | - $a = array_pop($p); |
|
194 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
195 | - $b = $params[$k + $ptr + 2]; |
|
196 | - $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
|
197 | - next($params); |
|
198 | - next($params); |
|
199 | - } else { |
|
200 | - $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; |
|
201 | - } |
|
202 | - next($params); |
|
203 | - break; |
|
204 | - default: |
|
205 | - throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k - 1].' is '.$params[$k + $ptr + 1]); |
|
170 | + case 'div': |
|
171 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
172 | + $p[] = ' % '.$params[$k + $ptr + 2].' '.($negate ? '!' : '=').'== 0'; |
|
173 | + next($params); |
|
174 | + next($params); |
|
175 | + next($params); |
|
176 | + } else { |
|
177 | + throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k - 1].' is '.($negate ? 'not ' : '').'div '.$params[$k + $ptr + 1].' '.$params[$k + $ptr + 2]); |
|
178 | + } |
|
179 | + break; |
|
180 | + case 'even': |
|
181 | + $a = array_pop($p); |
|
182 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
183 | + $b = $params[$k + $ptr + 2]; |
|
184 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
|
185 | + next($params); |
|
186 | + next($params); |
|
187 | + } else { |
|
188 | + $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; |
|
189 | + } |
|
190 | + next($params); |
|
191 | + break; |
|
192 | + case 'odd': |
|
193 | + $a = array_pop($p); |
|
194 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
195 | + $b = $params[$k + $ptr + 2]; |
|
196 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
|
197 | + next($params); |
|
198 | + next($params); |
|
199 | + } else { |
|
200 | + $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; |
|
201 | + } |
|
202 | + next($params); |
|
203 | + break; |
|
204 | + default: |
|
205 | + throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k - 1].' is '.$params[$k + $ptr + 1]); |
|
206 | 206 | |
207 | - } |
|
208 | - break; |
|
209 | - default: |
|
210 | - $p[] = $v; |
|
207 | + } |
|
208 | + break; |
|
209 | + default: |
|
210 | + $p[] = $v; |
|
211 | 211 | |
212 | - } |
|
213 | - } |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - return $p; |
|
216 | - } |
|
215 | + return $p; |
|
216 | + } |
|
217 | 217 | |
218 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
219 | - { |
|
220 | - return ''; |
|
221 | - } |
|
218 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
219 | + { |
|
220 | + return ''; |
|
221 | + } |
|
222 | 222 | |
223 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
224 | - { |
|
225 | - $tokens = $compiler->getParamTokens($params); |
|
226 | - $params = $compiler->getCompiledParams($params); |
|
227 | - $pre = Dwoo_Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Dwoo_Compiler::PHP_CLOSE; |
|
223 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
224 | + { |
|
225 | + $tokens = $compiler->getParamTokens($params); |
|
226 | + $params = $compiler->getCompiledParams($params); |
|
227 | + $pre = Dwoo_Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Dwoo_Compiler::PHP_CLOSE; |
|
228 | 228 | |
229 | - $post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
229 | + $post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
230 | 230 | |
231 | - if (isset($params['hasElse'])) { |
|
232 | - $post .= $params['hasElse']; |
|
233 | - } |
|
231 | + if (isset($params['hasElse'])) { |
|
232 | + $post .= $params['hasElse']; |
|
233 | + } |
|
234 | 234 | |
235 | - return $pre.$content.$post; |
|
236 | - } |
|
235 | + return $pre.$content.$post; |
|
236 | + } |
|
237 | 237 | } |
@@ -150,37 +150,37 @@ discard block |
||
150 | 150 | $p[] = $v; |
151 | 151 | break; |
152 | 152 | } |
153 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
153 | + if (isset($params[$k+1]) && strtolower(trim($params[$k+1], '"\'')) === 'not' && $tokens[$k+1] === Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
154 | 154 | $negate = true; |
155 | 155 | next($params); |
156 | 156 | } else { |
157 | 157 | $negate = false; |
158 | 158 | } |
159 | - $ptr = 1 + (int) $negate; |
|
160 | - if ($tokens[$k + $ptr] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
159 | + $ptr = 1+(int) $negate; |
|
160 | + if ($tokens[$k+$ptr] !== Dwoo_Compiler::T_UNQUOTED_STRING) { |
|
161 | 161 | break; |
162 | 162 | } |
163 | - if (!isset($params[$k + $ptr])) { |
|
164 | - $params[$k + $ptr] = ''; |
|
163 | + if (!isset($params[$k+$ptr])) { |
|
164 | + $params[$k+$ptr] = ''; |
|
165 | 165 | } else { |
166 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
166 | + $params[$k+$ptr] = trim($params[$k+$ptr], '"\''); |
|
167 | 167 | } |
168 | - switch ($params[$k + $ptr]) { |
|
168 | + switch ($params[$k+$ptr]) { |
|
169 | 169 | |
170 | 170 | case 'div': |
171 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
172 | - $p[] = ' % '.$params[$k + $ptr + 2].' '.($negate ? '!' : '=').'== 0'; |
|
171 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
172 | + $p[] = ' % '.$params[$k+$ptr+2].' '.($negate ? '!' : '=').'== 0'; |
|
173 | 173 | next($params); |
174 | 174 | next($params); |
175 | 175 | next($params); |
176 | 176 | } else { |
177 | - throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k - 1].' is '.($negate ? 'not ' : '').'div '.$params[$k + $ptr + 1].' '.$params[$k + $ptr + 2]); |
|
177 | + throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate ? 'not ' : '').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]); |
|
178 | 178 | } |
179 | 179 | break; |
180 | 180 | case 'even': |
181 | 181 | $a = array_pop($p); |
182 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
183 | - $b = $params[$k + $ptr + 2]; |
|
182 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
183 | + $b = $params[$k+$ptr+2]; |
|
184 | 184 | $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
185 | 185 | next($params); |
186 | 186 | next($params); |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | break; |
192 | 192 | case 'odd': |
193 | 193 | $a = array_pop($p); |
194 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
195 | - $b = $params[$k + $ptr + 2]; |
|
194 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
195 | + $b = $params[$k+$ptr+2]; |
|
196 | 196 | $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
197 | 197 | next($params); |
198 | 198 | next($params); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | next($params); |
203 | 203 | break; |
204 | 204 | default: |
205 | - throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k - 1].' is '.$params[$k + $ptr + 1]); |
|
205 | + throw new Dwoo_Compilation_Exception($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]); |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | break; |
@@ -19,46 +19,46 @@ |
||
19 | 19 | */ |
20 | 20 | class Dwoo_Plugin_smartyinterface extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
21 | 21 | { |
22 | - public function init($__funcname, $__functype, array $rest = array()) |
|
23 | - { |
|
24 | - } |
|
22 | + public function init($__funcname, $__functype, array $rest = array()) |
|
23 | + { |
|
24 | + } |
|
25 | 25 | |
26 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
27 | - { |
|
28 | - $params = $compiler->getCompiledParams($params); |
|
29 | - $func = $params['__funcname']; |
|
30 | - $pluginType = $params['__functype']; |
|
31 | - $params = $params['*']; |
|
26 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
27 | + { |
|
28 | + $params = $compiler->getCompiledParams($params); |
|
29 | + $func = $params['__funcname']; |
|
30 | + $pluginType = $params['__functype']; |
|
31 | + $params = $params['*']; |
|
32 | 32 | |
33 | - if ($pluginType & Dwoo_Core::CUSTOM_PLUGIN) { |
|
34 | - $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
35 | - $callback = $customPlugins[$func]['callback']; |
|
36 | - if (is_array($callback)) { |
|
37 | - if (is_object($callback[0])) { |
|
38 | - $callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'('; |
|
39 | - } else { |
|
40 | - $callback = ''.$callback[0].'::'.$callback[1].'('; |
|
41 | - } |
|
42 | - } else { |
|
43 | - $callback = $callback.'('; |
|
44 | - } |
|
45 | - } else { |
|
46 | - $callback = 'smarty_block_'.$func.'('; |
|
47 | - } |
|
33 | + if ($pluginType & Dwoo_Core::CUSTOM_PLUGIN) { |
|
34 | + $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
35 | + $callback = $customPlugins[$func]['callback']; |
|
36 | + if (is_array($callback)) { |
|
37 | + if (is_object($callback[0])) { |
|
38 | + $callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'('; |
|
39 | + } else { |
|
40 | + $callback = ''.$callback[0].'::'.$callback[1].'('; |
|
41 | + } |
|
42 | + } else { |
|
43 | + $callback = $callback.'('; |
|
44 | + } |
|
45 | + } else { |
|
46 | + $callback = 'smarty_block_'.$func.'('; |
|
47 | + } |
|
48 | 48 | |
49 | - $paramsOut = ''; |
|
50 | - foreach ($params as $i => $p) { |
|
51 | - $paramsOut .= var_export($i, true).' => '.$p.','; |
|
52 | - } |
|
49 | + $paramsOut = ''; |
|
50 | + foreach ($params as $i => $p) { |
|
51 | + $paramsOut .= var_export($i, true).' => '.$p.','; |
|
52 | + } |
|
53 | 53 | |
54 | - $curBlock = &$compiler->getCurrentBlock(); |
|
55 | - $curBlock['params']['postOut'] = Dwoo_Compiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.Dwoo_Compiler::PHP_CLOSE; |
|
54 | + $curBlock = &$compiler->getCurrentBlock(); |
|
55 | + $curBlock['params']['postOut'] = Dwoo_Compiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.Dwoo_Compiler::PHP_CLOSE; |
|
56 | 56 | |
57 | - return Dwoo_Compiler::PHP_OPEN.$prepend.' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array('.$paramsOut.'); $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.Dwoo_Compiler::PHP_CLOSE; |
|
58 | - } |
|
57 | + return Dwoo_Compiler::PHP_OPEN.$prepend.' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array('.$paramsOut.'); $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.Dwoo_Compiler::PHP_CLOSE; |
|
58 | + } |
|
59 | 59 | |
60 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
61 | - { |
|
62 | - return $content.$params['postOut']; |
|
63 | - } |
|
60 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
61 | + { |
|
62 | + return $content.$params['postOut']; |
|
63 | + } |
|
64 | 64 | } |
@@ -19,74 +19,74 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Dwoo_Plugin_section extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable |
21 | 21 | { |
22 | - public static $cnt = 0; |
|
23 | - |
|
24 | - public function init($name, $loop, $start = null, $step = null, $max = null, $show = true) |
|
25 | - { |
|
26 | - } |
|
27 | - |
|
28 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
29 | - { |
|
30 | - return ''; |
|
31 | - } |
|
32 | - |
|
33 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
34 | - { |
|
35 | - $output = Dwoo_Compiler::PHP_OPEN; |
|
36 | - $params = $compiler->getCompiledParams($params); |
|
37 | - |
|
38 | - // assigns params |
|
39 | - $loop = $params['loop']; |
|
40 | - $start = $params['start']; |
|
41 | - $max = $params['max']; |
|
42 | - $name = $params['name']; |
|
43 | - $step = $params['step']; |
|
44 | - $show = $params['show']; |
|
45 | - |
|
46 | - // gets unique id |
|
47 | - $cnt = self::$cnt++; |
|
48 | - |
|
49 | - $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n". |
|
50 | - '$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n"; |
|
51 | - |
|
52 | - if ($loop !== 'null') { |
|
53 | - $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n"; |
|
54 | - } else { |
|
55 | - $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n"; |
|
56 | - } |
|
57 | - |
|
58 | - if ($show !== 'null') { |
|
59 | - $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n"; |
|
60 | - } else { |
|
61 | - $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n"; |
|
62 | - } |
|
63 | - |
|
64 | - if ($name !== 'null') { |
|
65 | - $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n"; |
|
66 | - } else { |
|
67 | - $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n"; |
|
68 | - } |
|
69 | - |
|
70 | - if ($max !== 'null') { |
|
71 | - $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n". |
|
72 | - 'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n"; |
|
73 | - } else { |
|
74 | - $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
75 | - } |
|
76 | - |
|
77 | - if ($step !== 'null') { |
|
78 | - $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n"; |
|
79 | - } else { |
|
80 | - $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n"; |
|
81 | - } |
|
82 | - |
|
83 | - if ($start !== 'null') { |
|
84 | - $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n"; |
|
85 | - } else { |
|
86 | - $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n". |
|
87 | - 'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n". |
|
88 | - 'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n"; |
|
89 | - } |
|
22 | + public static $cnt = 0; |
|
23 | + |
|
24 | + public function init($name, $loop, $start = null, $step = null, $max = null, $show = true) |
|
25 | + { |
|
26 | + } |
|
27 | + |
|
28 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
29 | + { |
|
30 | + return ''; |
|
31 | + } |
|
32 | + |
|
33 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
34 | + { |
|
35 | + $output = Dwoo_Compiler::PHP_OPEN; |
|
36 | + $params = $compiler->getCompiledParams($params); |
|
37 | + |
|
38 | + // assigns params |
|
39 | + $loop = $params['loop']; |
|
40 | + $start = $params['start']; |
|
41 | + $max = $params['max']; |
|
42 | + $name = $params['name']; |
|
43 | + $step = $params['step']; |
|
44 | + $show = $params['show']; |
|
45 | + |
|
46 | + // gets unique id |
|
47 | + $cnt = self::$cnt++; |
|
48 | + |
|
49 | + $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n". |
|
50 | + '$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n"; |
|
51 | + |
|
52 | + if ($loop !== 'null') { |
|
53 | + $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n"; |
|
54 | + } else { |
|
55 | + $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n"; |
|
56 | + } |
|
57 | + |
|
58 | + if ($show !== 'null') { |
|
59 | + $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n"; |
|
60 | + } else { |
|
61 | + $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n"; |
|
62 | + } |
|
63 | + |
|
64 | + if ($name !== 'null') { |
|
65 | + $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n"; |
|
66 | + } else { |
|
67 | + $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n"; |
|
68 | + } |
|
69 | + |
|
70 | + if ($max !== 'null') { |
|
71 | + $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n". |
|
72 | + 'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n"; |
|
73 | + } else { |
|
74 | + $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
75 | + } |
|
76 | + |
|
77 | + if ($step !== 'null') { |
|
78 | + $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n"; |
|
79 | + } else { |
|
80 | + $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n"; |
|
81 | + } |
|
82 | + |
|
83 | + if ($start !== 'null') { |
|
84 | + $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n"; |
|
85 | + } else { |
|
86 | + $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n". |
|
87 | + 'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n". |
|
88 | + 'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n"; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | /* if ($usesAny) { |
92 | 92 | $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n("; |
@@ -100,35 +100,35 @@ discard block |
||
100 | 100 | } |
101 | 101 | */ |
102 | 102 | |
103 | - $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
104 | - if ($start === 'null' && $step === 'null' && $max === 'null') { |
|
105 | - $output .= ' $_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
106 | - } else { |
|
107 | - $output .= ' $_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n"; |
|
108 | - } |
|
109 | - $output .= ' if ($_section'.$cnt.'[\'total\'] == 0) {'."\n". |
|
110 | - ' $_section'.$cnt.'[\'show\'] = false;'."\n". |
|
111 | - ' }'."\n". |
|
112 | - '} else {'."\n". |
|
113 | - ' $_section'.$cnt.'[\'total\'] = 0;'."\n}\n"; |
|
114 | - $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
115 | - $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '. |
|
116 | - '$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '. |
|
117 | - '$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n"; |
|
118 | - $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n"; |
|
119 | - $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n"; |
|
120 | - $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n"; |
|
121 | - $output .= "\t\t".'$_section'.$cnt.'[\'first\'] = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n"; |
|
122 | - $output .= "\t\t".'$_section'.$cnt.'[\'last\'] = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n"; |
|
123 | - |
|
124 | - $output .= Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN; |
|
125 | - |
|
126 | - $output .= "\n\t}\n} ".Dwoo_Compiler::PHP_CLOSE; |
|
127 | - |
|
128 | - if (isset($params['hasElse'])) { |
|
129 | - $output .= $params['hasElse']; |
|
130 | - } |
|
131 | - |
|
132 | - return $output; |
|
133 | - } |
|
103 | + $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
104 | + if ($start === 'null' && $step === 'null' && $max === 'null') { |
|
105 | + $output .= ' $_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
106 | + } else { |
|
107 | + $output .= ' $_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n"; |
|
108 | + } |
|
109 | + $output .= ' if ($_section'.$cnt.'[\'total\'] == 0) {'."\n". |
|
110 | + ' $_section'.$cnt.'[\'show\'] = false;'."\n". |
|
111 | + ' }'."\n". |
|
112 | + '} else {'."\n". |
|
113 | + ' $_section'.$cnt.'[\'total\'] = 0;'."\n}\n"; |
|
114 | + $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
115 | + $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '. |
|
116 | + '$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '. |
|
117 | + '$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n"; |
|
118 | + $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n"; |
|
119 | + $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n"; |
|
120 | + $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n"; |
|
121 | + $output .= "\t\t".'$_section'.$cnt.'[\'first\'] = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n"; |
|
122 | + $output .= "\t\t".'$_section'.$cnt.'[\'last\'] = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n"; |
|
123 | + |
|
124 | + $output .= Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN; |
|
125 | + |
|
126 | + $output .= "\n\t}\n} ".Dwoo_Compiler::PHP_CLOSE; |
|
127 | + |
|
128 | + if (isset($params['hasElse'])) { |
|
129 | + $output .= $params['hasElse']; |
|
130 | + } |
|
131 | + |
|
132 | + return $output; |
|
133 | + } |
|
134 | 134 | } |
@@ -32,40 +32,40 @@ |
||
32 | 32 | */ |
33 | 33 | class Dwoo_Plugin_else extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
34 | 34 | { |
35 | - public function init() |
|
36 | - { |
|
37 | - } |
|
35 | + public function init() |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
40 | - { |
|
41 | - $preContent = ''; |
|
42 | - while (true) { |
|
43 | - $preContent .= $compiler->removeTopBlock(); |
|
44 | - $block = &$compiler->getCurrentBlock(); |
|
45 | - if (!$block) { |
|
46 | - throw new Dwoo_Compilation_Exception($compiler, 'An else block was found but it was not preceded by an if or other else-able construct'); |
|
47 | - } |
|
48 | - $interfaces = class_implements($block['class'], false); |
|
49 | - if (in_array('Dwoo_IElseable', $interfaces) !== false) { |
|
50 | - break; |
|
51 | - } |
|
52 | - } |
|
39 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
40 | + { |
|
41 | + $preContent = ''; |
|
42 | + while (true) { |
|
43 | + $preContent .= $compiler->removeTopBlock(); |
|
44 | + $block = &$compiler->getCurrentBlock(); |
|
45 | + if (!$block) { |
|
46 | + throw new Dwoo_Compilation_Exception($compiler, 'An else block was found but it was not preceded by an if or other else-able construct'); |
|
47 | + } |
|
48 | + $interfaces = class_implements($block['class'], false); |
|
49 | + if (in_array('Dwoo_IElseable', $interfaces) !== false) { |
|
50 | + break; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - $params['initialized'] = true; |
|
55 | - $compiler->injectBlock($type, $params); |
|
54 | + $params['initialized'] = true; |
|
55 | + $compiler->injectBlock($type, $params); |
|
56 | 56 | |
57 | - return $preContent; |
|
58 | - } |
|
57 | + return $preContent; |
|
58 | + } |
|
59 | 59 | |
60 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
61 | - { |
|
62 | - if (!isset($params['initialized'])) { |
|
63 | - return ''; |
|
64 | - } |
|
60 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
61 | + { |
|
62 | + if (!isset($params['initialized'])) { |
|
63 | + return ''; |
|
64 | + } |
|
65 | 65 | |
66 | - $block = &$compiler->getCurrentBlock(); |
|
67 | - $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
66 | + $block = &$compiler->getCurrentBlock(); |
|
67 | + $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
68 | 68 | |
69 | - return ''; |
|
70 | - } |
|
69 | + return ''; |
|
70 | + } |
|
71 | 71 | } |
@@ -37,34 +37,34 @@ |
||
37 | 37 | */ |
38 | 38 | class Dwoo_Plugin_a extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
39 | 39 | { |
40 | - public function init($href, array $rest = array()) |
|
41 | - { |
|
42 | - } |
|
40 | + public function init($href, array $rest = array()) |
|
41 | + { |
|
42 | + } |
|
43 | 43 | |
44 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
45 | - { |
|
46 | - $p = $compiler->getCompiledParams($params); |
|
44 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
45 | + { |
|
46 | + $p = $compiler->getCompiledParams($params); |
|
47 | 47 | |
48 | - $out = Dwoo_Compiler::PHP_OPEN.'echo \'<a '.self::paramsToAttributes($p, "'", $compiler); |
|
48 | + $out = Dwoo_Compiler::PHP_OPEN.'echo \'<a '.self::paramsToAttributes($p, "'", $compiler); |
|
49 | 49 | |
50 | - return $out.'>\';'.Dwoo_Compiler::PHP_CLOSE; |
|
51 | - } |
|
50 | + return $out.'>\';'.Dwoo_Compiler::PHP_CLOSE; |
|
51 | + } |
|
52 | 52 | |
53 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
54 | - { |
|
55 | - $p = $compiler->getCompiledParams($params); |
|
53 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
54 | + { |
|
55 | + $p = $compiler->getCompiledParams($params); |
|
56 | 56 | |
57 | - // no content was provided so use the url as display text |
|
58 | - if ($content == '') { |
|
59 | - // merge </a> into the href if href is a string |
|
60 | - if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') { |
|
61 | - return Dwoo_Compiler::PHP_OPEN.'echo '.substr($p['href'], 0, -1).'</a>'.substr($p['href'], -1).';'.Dwoo_Compiler::PHP_CLOSE; |
|
62 | - } |
|
63 | - // otherwise append |
|
64 | - return Dwoo_Compiler::PHP_OPEN.'echo '.$p['href'].'.\'</a>\';'.Dwoo_Compiler::PHP_CLOSE; |
|
65 | - } |
|
57 | + // no content was provided so use the url as display text |
|
58 | + if ($content == '') { |
|
59 | + // merge </a> into the href if href is a string |
|
60 | + if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') { |
|
61 | + return Dwoo_Compiler::PHP_OPEN.'echo '.substr($p['href'], 0, -1).'</a>'.substr($p['href'], -1).';'.Dwoo_Compiler::PHP_CLOSE; |
|
62 | + } |
|
63 | + // otherwise append |
|
64 | + return Dwoo_Compiler::PHP_OPEN.'echo '.$p['href'].'.\'</a>\';'.Dwoo_Compiler::PHP_CLOSE; |
|
65 | + } |
|
66 | 66 | |
67 | - // return content |
|
68 | - return $content.'</a>'; |
|
69 | - } |
|
67 | + // return content |
|
68 | + return $content.'</a>'; |
|
69 | + } |
|
70 | 70 | } |
@@ -24,137 +24,137 @@ |
||
24 | 24 | */ |
25 | 25 | class Dwoo_Plugin_for extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable |
26 | 26 | { |
27 | - public static $cnt = 0; |
|
28 | - |
|
29 | - public function init($name, $from, $to = null, $step = 1, $skip = 0) |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
34 | - { |
|
35 | - // get block params and save the current template pointer to use it in the postProcessing method |
|
36 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
37 | - $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
38 | - |
|
39 | - return ''; |
|
40 | - } |
|
41 | - |
|
42 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
43 | - { |
|
44 | - $params = $compiler->getCompiledParams($params); |
|
45 | - $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
46 | - |
|
47 | - // assigns params |
|
48 | - $from = $params['from']; |
|
49 | - $name = $params['name']; |
|
50 | - $step = $params['step']; |
|
51 | - $to = $params['to']; |
|
52 | - |
|
53 | - // evaluates which global variables have to be computed |
|
54 | - $varName = '$dwoo.for.'.trim($name, '"\'').'.'; |
|
55 | - $shortVarName = '$.for.'.trim($name, '"\'').'.'; |
|
56 | - $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
57 | - $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
58 | - $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
59 | - $usesIndex = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
60 | - $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
61 | - $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
62 | - $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
63 | - |
|
64 | - if (strpos($name, '$this->scope[') !== false) { |
|
65 | - $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
66 | - } |
|
67 | - |
|
68 | - // gets foreach id |
|
69 | - $cnt = self::$cnt++; |
|
70 | - |
|
71 | - // builds pre processing output for |
|
72 | - $out = Dwoo_Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'. |
|
73 | - "\n".'$_for'.$cnt.'_to = '.$to.';'. |
|
74 | - "\n".'$_for'.$cnt.'_step = abs('.$step.');'. |
|
75 | - "\n".'if (is_numeric($_for'.$cnt.'_from) && !is_numeric($_for'.$cnt.'_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }'. |
|
76 | - "\n".'$tmp_shows = $this->isArray($_for'.$cnt.'_from, true) || (is_numeric($_for'.$cnt.'_from) && (abs(($_for'.$cnt.'_from - $_for'.$cnt.'_to)/$_for'.$cnt.'_step) !== 0 || $_for'.$cnt.'_from == $_for'.$cnt.'_to));'; |
|
77 | - // adds for properties |
|
78 | - if ($usesAny) { |
|
79 | - $out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n("; |
|
80 | - if ($usesIndex) { |
|
81 | - $out .= "\n\t".'"index" => 0,'; |
|
82 | - } |
|
83 | - if ($usesIteration) { |
|
84 | - $out .= "\n\t".'"iteration" => 1,'; |
|
85 | - } |
|
86 | - if ($usesFirst) { |
|
87 | - $out .= "\n\t".'"first" => null,'; |
|
88 | - } |
|
89 | - if ($usesLast) { |
|
90 | - $out .= "\n\t".'"last" => null,'; |
|
91 | - } |
|
92 | - if ($usesShow) { |
|
93 | - $out .= "\n\t".'"show" => $tmp_shows,'; |
|
94 | - } |
|
95 | - if ($usesTotal) { |
|
96 | - $out .= "\n\t".'"total" => $this->isArray($_for'.$cnt.'_from) ? floor($this->count($_for'.$cnt.'_from) / $_for'.$cnt.'_step) : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),'; |
|
97 | - } |
|
98 | - $out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];'; |
|
99 | - } |
|
100 | - // checks if for must be looped |
|
101 | - $out .= "\n".'if ($tmp_shows)'."\n{"; |
|
102 | - // set from/to to correct values if an array was given |
|
103 | - $out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) { |
|
27 | + public static $cnt = 0; |
|
28 | + |
|
29 | + public function init($name, $from, $to = null, $step = 1, $skip = 0) |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
34 | + { |
|
35 | + // get block params and save the current template pointer to use it in the postProcessing method |
|
36 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
37 | + $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
38 | + |
|
39 | + return ''; |
|
40 | + } |
|
41 | + |
|
42 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
43 | + { |
|
44 | + $params = $compiler->getCompiledParams($params); |
|
45 | + $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
46 | + |
|
47 | + // assigns params |
|
48 | + $from = $params['from']; |
|
49 | + $name = $params['name']; |
|
50 | + $step = $params['step']; |
|
51 | + $to = $params['to']; |
|
52 | + |
|
53 | + // evaluates which global variables have to be computed |
|
54 | + $varName = '$dwoo.for.'.trim($name, '"\'').'.'; |
|
55 | + $shortVarName = '$.for.'.trim($name, '"\'').'.'; |
|
56 | + $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
57 | + $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
58 | + $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
59 | + $usesIndex = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
60 | + $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
61 | + $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
62 | + $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
63 | + |
|
64 | + if (strpos($name, '$this->scope[') !== false) { |
|
65 | + $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
66 | + } |
|
67 | + |
|
68 | + // gets foreach id |
|
69 | + $cnt = self::$cnt++; |
|
70 | + |
|
71 | + // builds pre processing output for |
|
72 | + $out = Dwoo_Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'. |
|
73 | + "\n".'$_for'.$cnt.'_to = '.$to.';'. |
|
74 | + "\n".'$_for'.$cnt.'_step = abs('.$step.');'. |
|
75 | + "\n".'if (is_numeric($_for'.$cnt.'_from) && !is_numeric($_for'.$cnt.'_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }'. |
|
76 | + "\n".'$tmp_shows = $this->isArray($_for'.$cnt.'_from, true) || (is_numeric($_for'.$cnt.'_from) && (abs(($_for'.$cnt.'_from - $_for'.$cnt.'_to)/$_for'.$cnt.'_step) !== 0 || $_for'.$cnt.'_from == $_for'.$cnt.'_to));'; |
|
77 | + // adds for properties |
|
78 | + if ($usesAny) { |
|
79 | + $out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n("; |
|
80 | + if ($usesIndex) { |
|
81 | + $out .= "\n\t".'"index" => 0,'; |
|
82 | + } |
|
83 | + if ($usesIteration) { |
|
84 | + $out .= "\n\t".'"iteration" => 1,'; |
|
85 | + } |
|
86 | + if ($usesFirst) { |
|
87 | + $out .= "\n\t".'"first" => null,'; |
|
88 | + } |
|
89 | + if ($usesLast) { |
|
90 | + $out .= "\n\t".'"last" => null,'; |
|
91 | + } |
|
92 | + if ($usesShow) { |
|
93 | + $out .= "\n\t".'"show" => $tmp_shows,'; |
|
94 | + } |
|
95 | + if ($usesTotal) { |
|
96 | + $out .= "\n\t".'"total" => $this->isArray($_for'.$cnt.'_from) ? floor($this->count($_for'.$cnt.'_from) / $_for'.$cnt.'_step) : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),'; |
|
97 | + } |
|
98 | + $out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];'; |
|
99 | + } |
|
100 | + // checks if for must be looped |
|
101 | + $out .= "\n".'if ($tmp_shows)'."\n{"; |
|
102 | + // set from/to to correct values if an array was given |
|
103 | + $out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) { |
|
104 | 104 | $_for'.$cnt.'_to = is_numeric($_for'.$cnt.'_to) ? $_for'.$cnt.'_to - $_for'.$cnt.'_step : $this->count($_for'.$cnt.'_from) - 1; |
105 | 105 | $_for'.$cnt.'_from = 0; |
106 | 106 | }'; |
107 | 107 | |
108 | - // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used |
|
109 | - $reverse = false; |
|
110 | - $condition = '<='; |
|
111 | - $incrementer = '+'; |
|
112 | - |
|
113 | - if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) { |
|
114 | - $from = (int) $mN1[2]; |
|
115 | - $to = (int) $mN2[2]; |
|
116 | - if ($from > $to) { |
|
117 | - $reverse = true; |
|
118 | - $condition = '>='; |
|
119 | - $incrementer = '-'; |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - // reverse from and to if needed |
|
124 | - if (!$reverse) { |
|
125 | - $out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) { |
|
108 | + // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used |
|
109 | + $reverse = false; |
|
110 | + $condition = '<='; |
|
111 | + $incrementer = '+'; |
|
112 | + |
|
113 | + if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) { |
|
114 | + $from = (int) $mN1[2]; |
|
115 | + $to = (int) $mN2[2]; |
|
116 | + if ($from > $to) { |
|
117 | + $reverse = true; |
|
118 | + $condition = '>='; |
|
119 | + $incrementer = '-'; |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + // reverse from and to if needed |
|
124 | + if (!$reverse) { |
|
125 | + $out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) { |
|
126 | 126 | $tmp = $_for'.$cnt.'_from; |
127 | 127 | $_for'.$cnt.'_from = $_for'.$cnt.'_to; |
128 | 128 | $_for'.$cnt.'_to = $tmp; |
129 | 129 | }'; |
130 | - } |
|
131 | - |
|
132 | - $out .= "\n\t".'for ($this->scope['.$name.'] = $_for'.$cnt.'_from; $this->scope['.$name.'] '.$condition.' $_for'.$cnt.'_to; $this->scope['.$name.'] '.$incrementer.'= $_for'.$cnt.'_step)'."\n\t{"; |
|
133 | - // updates properties |
|
134 | - if ($usesIndex) { |
|
135 | - $out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];'; |
|
136 | - } |
|
137 | - if ($usesFirst) { |
|
138 | - $out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);'; |
|
139 | - } |
|
140 | - if ($usesLast) { |
|
141 | - $out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);'; |
|
142 | - } |
|
143 | - $out .= "\n/* -- for start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
144 | - |
|
145 | - // build post processing output and cache it |
|
146 | - $postOut = Dwoo_Compiler::PHP_OPEN.'/* -- for end output */'; |
|
147 | - // update properties |
|
148 | - if ($usesIteration) { |
|
149 | - $postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;'; |
|
150 | - } |
|
151 | - // end loop |
|
152 | - $postOut .= "\n\t}\n}\n".Dwoo_Compiler::PHP_CLOSE; |
|
153 | - |
|
154 | - if (isset($params['hasElse'])) { |
|
155 | - $postOut .= $params['hasElse']; |
|
156 | - } |
|
157 | - |
|
158 | - return $out.$content.$postOut; |
|
159 | - } |
|
130 | + } |
|
131 | + |
|
132 | + $out .= "\n\t".'for ($this->scope['.$name.'] = $_for'.$cnt.'_from; $this->scope['.$name.'] '.$condition.' $_for'.$cnt.'_to; $this->scope['.$name.'] '.$incrementer.'= $_for'.$cnt.'_step)'."\n\t{"; |
|
133 | + // updates properties |
|
134 | + if ($usesIndex) { |
|
135 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];'; |
|
136 | + } |
|
137 | + if ($usesFirst) { |
|
138 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);'; |
|
139 | + } |
|
140 | + if ($usesLast) { |
|
141 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);'; |
|
142 | + } |
|
143 | + $out .= "\n/* -- for start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
144 | + |
|
145 | + // build post processing output and cache it |
|
146 | + $postOut = Dwoo_Compiler::PHP_OPEN.'/* -- for end output */'; |
|
147 | + // update properties |
|
148 | + if ($usesIteration) { |
|
149 | + $postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;'; |
|
150 | + } |
|
151 | + // end loop |
|
152 | + $postOut .= "\n\t}\n}\n".Dwoo_Compiler::PHP_CLOSE; |
|
153 | + |
|
154 | + if (isset($params['hasElse'])) { |
|
155 | + $postOut .= $params['hasElse']; |
|
156 | + } |
|
157 | + |
|
158 | + return $out.$content.$postOut; |
|
159 | + } |
|
160 | 160 | } |
@@ -23,30 +23,30 @@ |
||
23 | 23 | */ |
24 | 24 | class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
25 | 25 | { |
26 | - public function init($mode = 'default') |
|
27 | - { |
|
28 | - } |
|
26 | + public function init($mode = 'default') |
|
27 | + { |
|
28 | + } |
|
29 | 29 | |
30 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
31 | - { |
|
32 | - return ''; |
|
33 | - } |
|
30 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
31 | + { |
|
32 | + return ''; |
|
33 | + } |
|
34 | 34 | |
35 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
36 | - { |
|
37 | - $params = $compiler->getCompiledParams($params); |
|
35 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
36 | + { |
|
37 | + $params = $compiler->getCompiledParams($params); |
|
38 | 38 | |
39 | - $mode = trim($params['mode'], '"\''); |
|
40 | - switch ($mode) { |
|
41 | - case 'js': |
|
42 | - case 'javascript': |
|
43 | - $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content); |
|
39 | + $mode = trim($params['mode'], '"\''); |
|
40 | + switch ($mode) { |
|
41 | + case 'js': |
|
42 | + case 'javascript': |
|
43 | + $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content); |
|
44 | 44 | |
45 | - case 'default': |
|
46 | - default: |
|
47 | - } |
|
48 | - $content = preg_replace(array("/\n/", "/\r/", '/(<\?(?:php)?|<%)\s*/'), array('', '', '$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content)); |
|
45 | + case 'default': |
|
46 | + default: |
|
47 | + } |
|
48 | + $content = preg_replace(array("/\n/", "/\r/", '/(<\?(?:php)?|<%)\s*/'), array('', '', '$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content)); |
|
49 | 49 | |
50 | - return $content; |
|
51 | - } |
|
50 | + return $content; |
|
51 | + } |
|
52 | 52 | } |
@@ -38,12 +38,12 @@ |
||
38 | 38 | |
39 | 39 | $mode = trim($params['mode'], '"\''); |
40 | 40 | switch ($mode) { |
41 | - case 'js': |
|
42 | - case 'javascript': |
|
43 | - $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content); |
|
41 | + case 'js': |
|
42 | + case 'javascript': |
|
43 | + $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content); |
|
44 | 44 | |
45 | - case 'default': |
|
46 | - default: |
|
45 | + case 'default': |
|
46 | + default: |
|
47 | 47 | } |
48 | 48 | $content = preg_replace(array("/\n/", "/\r/", '/(<\?(?:php)?|<%)\s*/'), array('', '', '$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content)); |
49 | 49 |
@@ -34,134 +34,134 @@ |
||
34 | 34 | */ |
35 | 35 | class Dwoo_Plugin_foreach extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable |
36 | 36 | { |
37 | - public static $cnt = 0; |
|
38 | - |
|
39 | - public function init($from, $key = null, $item = null, $name = 'default', $implode = null) |
|
40 | - { |
|
41 | - } |
|
42 | - |
|
43 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - // get block params and save the current template pointer to use it in the postProcessing method |
|
46 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
47 | - $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
48 | - |
|
49 | - return ''; |
|
50 | - } |
|
51 | - |
|
52 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
53 | - { |
|
54 | - $params = $compiler->getCompiledParams($params); |
|
55 | - $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
56 | - |
|
57 | - // assigns params |
|
58 | - $src = $params['from']; |
|
59 | - |
|
60 | - if ($params['item'] !== 'null') { |
|
61 | - if ($params['key'] !== 'null') { |
|
62 | - $key = $params['key']; |
|
63 | - } |
|
64 | - $val = $params['item']; |
|
65 | - } elseif ($params['key'] !== 'null') { |
|
66 | - $val = $params['key']; |
|
67 | - } else { |
|
68 | - throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter missing'); |
|
69 | - } |
|
70 | - $name = $params['name']; |
|
71 | - |
|
72 | - if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
73 | - throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter must be of type string'); |
|
74 | - } |
|
75 | - if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
76 | - throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>key</em> parameter must be of type string'); |
|
77 | - } |
|
78 | - |
|
79 | - // evaluates which global variables have to be computed |
|
80 | - $varName = '$dwoo.foreach.'.trim($name, '"\'').'.'; |
|
81 | - $shortVarName = '$.foreach.'.trim($name, '"\'').'.'; |
|
82 | - $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
83 | - $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
84 | - $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
85 | - $usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
86 | - $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
87 | - $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
88 | - $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
89 | - |
|
90 | - if (strpos($name, '$this->scope[') !== false) { |
|
91 | - $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
92 | - } |
|
93 | - |
|
94 | - // override globals vars if implode is used |
|
95 | - if ($params['implode'] !== 'null') { |
|
96 | - $implode = $params['implode']; |
|
97 | - $usesAny = true; |
|
98 | - $usesLast = true; |
|
99 | - $usesIteration = true; |
|
100 | - $usesTotal = true; |
|
101 | - } |
|
102 | - |
|
103 | - // gets foreach id |
|
104 | - $cnt = self::$cnt++; |
|
105 | - |
|
106 | - // build pre content output |
|
107 | - $pre = Dwoo_Compiler::PHP_OPEN."\n".'$_fh'.$cnt.'_data = '.$src.';'; |
|
108 | - // adds foreach properties |
|
109 | - if ($usesAny) { |
|
110 | - $pre .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n("; |
|
111 | - if ($usesIndex) { |
|
112 | - $pre .= "\n\t".'"index" => 0,'; |
|
113 | - } |
|
114 | - if ($usesIteration) { |
|
115 | - $pre .= "\n\t".'"iteration" => 1,'; |
|
116 | - } |
|
117 | - if ($usesFirst) { |
|
118 | - $pre .= "\n\t".'"first" => null,'; |
|
119 | - } |
|
120 | - if ($usesLast) { |
|
121 | - $pre .= "\n\t".'"last" => null,'; |
|
122 | - } |
|
123 | - if ($usesShow) { |
|
124 | - $pre .= "\n\t".'"show" => $this->isArray($_fh'.$cnt.'_data, true),'; |
|
125 | - } |
|
126 | - if ($usesTotal) { |
|
127 | - $pre .= "\n\t".'"total" => $this->count($_fh'.$cnt.'_data),'; |
|
128 | - } |
|
129 | - $pre .= "\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];'; |
|
130 | - } |
|
131 | - // checks if foreach must be looped |
|
132 | - $pre .= "\n".'if ($this->isTraversable($_fh'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{"; |
|
133 | - // iterates over keys |
|
134 | - $pre .= "\n\t".'foreach ($_fh'.$cnt.'_data as '.(isset($key) ? '$this->scope['.$key.']=>' : '').'$this->scope['.$val.'])'."\n\t{"; |
|
135 | - // updates properties |
|
136 | - if ($usesFirst) { |
|
137 | - $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);'; |
|
138 | - } |
|
139 | - if ($usesLast) { |
|
140 | - $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);'; |
|
141 | - } |
|
142 | - $pre .= "\n/* -- foreach start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
143 | - |
|
144 | - // build post content output |
|
145 | - $post = Dwoo_Compiler::PHP_OPEN."\n"; |
|
146 | - |
|
147 | - if (isset($implode)) { |
|
148 | - $post .= '/* -- implode */'."\n".'if (!$_fh'.$cnt.'_glob["last"]) {'. |
|
149 | - "\n\t".'echo '.$implode.";\n}\n"; |
|
150 | - } |
|
151 | - $post .= '/* -- foreach end output */'; |
|
152 | - // update properties |
|
153 | - if ($usesIndex) { |
|
154 | - $post .= "\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;'; |
|
155 | - } |
|
156 | - if ($usesIteration) { |
|
157 | - $post .= "\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;'; |
|
158 | - } |
|
159 | - // end loop |
|
160 | - $post .= "\n\t}\n}".Dwoo_Compiler::PHP_CLOSE; |
|
161 | - if (isset($params['hasElse'])) { |
|
162 | - $post .= $params['hasElse']; |
|
163 | - } |
|
164 | - |
|
165 | - return $pre.$content.$post; |
|
166 | - } |
|
37 | + public static $cnt = 0; |
|
38 | + |
|
39 | + public function init($from, $key = null, $item = null, $name = 'default', $implode = null) |
|
40 | + { |
|
41 | + } |
|
42 | + |
|
43 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + // get block params and save the current template pointer to use it in the postProcessing method |
|
46 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
47 | + $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
48 | + |
|
49 | + return ''; |
|
50 | + } |
|
51 | + |
|
52 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
53 | + { |
|
54 | + $params = $compiler->getCompiledParams($params); |
|
55 | + $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
56 | + |
|
57 | + // assigns params |
|
58 | + $src = $params['from']; |
|
59 | + |
|
60 | + if ($params['item'] !== 'null') { |
|
61 | + if ($params['key'] !== 'null') { |
|
62 | + $key = $params['key']; |
|
63 | + } |
|
64 | + $val = $params['item']; |
|
65 | + } elseif ($params['key'] !== 'null') { |
|
66 | + $val = $params['key']; |
|
67 | + } else { |
|
68 | + throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter missing'); |
|
69 | + } |
|
70 | + $name = $params['name']; |
|
71 | + |
|
72 | + if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
73 | + throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter must be of type string'); |
|
74 | + } |
|
75 | + if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { |
|
76 | + throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>key</em> parameter must be of type string'); |
|
77 | + } |
|
78 | + |
|
79 | + // evaluates which global variables have to be computed |
|
80 | + $varName = '$dwoo.foreach.'.trim($name, '"\'').'.'; |
|
81 | + $shortVarName = '$.foreach.'.trim($name, '"\'').'.'; |
|
82 | + $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
83 | + $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
84 | + $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
85 | + $usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
86 | + $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
87 | + $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
88 | + $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
89 | + |
|
90 | + if (strpos($name, '$this->scope[') !== false) { |
|
91 | + $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
92 | + } |
|
93 | + |
|
94 | + // override globals vars if implode is used |
|
95 | + if ($params['implode'] !== 'null') { |
|
96 | + $implode = $params['implode']; |
|
97 | + $usesAny = true; |
|
98 | + $usesLast = true; |
|
99 | + $usesIteration = true; |
|
100 | + $usesTotal = true; |
|
101 | + } |
|
102 | + |
|
103 | + // gets foreach id |
|
104 | + $cnt = self::$cnt++; |
|
105 | + |
|
106 | + // build pre content output |
|
107 | + $pre = Dwoo_Compiler::PHP_OPEN."\n".'$_fh'.$cnt.'_data = '.$src.';'; |
|
108 | + // adds foreach properties |
|
109 | + if ($usesAny) { |
|
110 | + $pre .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n("; |
|
111 | + if ($usesIndex) { |
|
112 | + $pre .= "\n\t".'"index" => 0,'; |
|
113 | + } |
|
114 | + if ($usesIteration) { |
|
115 | + $pre .= "\n\t".'"iteration" => 1,'; |
|
116 | + } |
|
117 | + if ($usesFirst) { |
|
118 | + $pre .= "\n\t".'"first" => null,'; |
|
119 | + } |
|
120 | + if ($usesLast) { |
|
121 | + $pre .= "\n\t".'"last" => null,'; |
|
122 | + } |
|
123 | + if ($usesShow) { |
|
124 | + $pre .= "\n\t".'"show" => $this->isArray($_fh'.$cnt.'_data, true),'; |
|
125 | + } |
|
126 | + if ($usesTotal) { |
|
127 | + $pre .= "\n\t".'"total" => $this->count($_fh'.$cnt.'_data),'; |
|
128 | + } |
|
129 | + $pre .= "\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];'; |
|
130 | + } |
|
131 | + // checks if foreach must be looped |
|
132 | + $pre .= "\n".'if ($this->isTraversable($_fh'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{"; |
|
133 | + // iterates over keys |
|
134 | + $pre .= "\n\t".'foreach ($_fh'.$cnt.'_data as '.(isset($key) ? '$this->scope['.$key.']=>' : '').'$this->scope['.$val.'])'."\n\t{"; |
|
135 | + // updates properties |
|
136 | + if ($usesFirst) { |
|
137 | + $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);'; |
|
138 | + } |
|
139 | + if ($usesLast) { |
|
140 | + $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);'; |
|
141 | + } |
|
142 | + $pre .= "\n/* -- foreach start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
143 | + |
|
144 | + // build post content output |
|
145 | + $post = Dwoo_Compiler::PHP_OPEN."\n"; |
|
146 | + |
|
147 | + if (isset($implode)) { |
|
148 | + $post .= '/* -- implode */'."\n".'if (!$_fh'.$cnt.'_glob["last"]) {'. |
|
149 | + "\n\t".'echo '.$implode.";\n}\n"; |
|
150 | + } |
|
151 | + $post .= '/* -- foreach end output */'; |
|
152 | + // update properties |
|
153 | + if ($usesIndex) { |
|
154 | + $post .= "\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;'; |
|
155 | + } |
|
156 | + if ($usesIteration) { |
|
157 | + $post .= "\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;'; |
|
158 | + } |
|
159 | + // end loop |
|
160 | + $post .= "\n\t}\n}".Dwoo_Compiler::PHP_CLOSE; |
|
161 | + if (isset($params['hasElse'])) { |
|
162 | + $post .= $params['hasElse']; |
|
163 | + } |
|
164 | + |
|
165 | + return $pre.$content.$post; |
|
166 | + } |
|
167 | 167 | } |