@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | use Dwoo\Smarty\Processor\Adapter as ProcessorAdapter; |
27 | 27 | |
28 | 28 | if (!defined('DIR_SEP')) { |
29 | - define('DIR_SEP', DIRECTORY_SEPARATOR); |
|
29 | + define('DIR_SEP', DIRECTORY_SEPARATOR); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if (!defined('SMARTY_PHP_PASSTHRU')) { |
33 | - define('SMARTY_PHP_PASSTHRU', 0); |
|
34 | - define('SMARTY_PHP_QUOTE', 1); |
|
35 | - define('SMARTY_PHP_REMOVE', 2); |
|
36 | - define('SMARTY_PHP_ALLOW', 3); |
|
33 | + define('SMARTY_PHP_PASSTHRU', 0); |
|
34 | + define('SMARTY_PHP_QUOTE', 1); |
|
35 | + define('SMARTY_PHP_REMOVE', 2); |
|
36 | + define('SMARTY_PHP_ALLOW', 3); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,656 +43,656 @@ discard block |
||
43 | 43 | */ |
44 | 44 | class Adapter extends Core |
45 | 45 | { |
46 | - /** |
|
47 | - * Magic get/set/call functions that handle unsupported features |
|
48 | - * |
|
49 | - * @param string $p |
|
50 | - * @param string $v |
|
51 | - */ |
|
52 | - public function __set($p, $v) |
|
53 | - { |
|
54 | - if ($p === 'scope') { |
|
55 | - $this->scope = $v; |
|
56 | - |
|
57 | - return; |
|
58 | - } |
|
59 | - if ($p === 'data') { |
|
60 | - $this->data = $v; |
|
61 | - |
|
62 | - return; |
|
63 | - } |
|
64 | - if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
65 | - if ($this->show_compat_errors) { |
|
66 | - $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
67 | - } |
|
68 | - $this->compat['properties'][$p] = $v; |
|
69 | - } else { |
|
70 | - if ($this->show_compat_errors) { |
|
71 | - $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param $p |
|
78 | - * |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public function __get($p) |
|
82 | - { |
|
83 | - if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
84 | - if ($this->show_compat_errors) { |
|
85 | - $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
86 | - } |
|
87 | - |
|
88 | - return $this->compat['properties'][$p]; |
|
89 | - } else { |
|
90 | - if ($this->show_compat_errors) { |
|
91 | - $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $m |
|
98 | - * @param array $a |
|
99 | - * |
|
100 | - * @return mixed|void |
|
101 | - */ |
|
102 | - public function __call($m, $a) |
|
103 | - { |
|
104 | - if (method_exists($this->dataProvider, $m)) { |
|
105 | - call_user_func_array( |
|
106 | - array( |
|
107 | - $this->dataProvider, |
|
108 | - $m |
|
109 | - ), $a |
|
110 | - ); |
|
111 | - } elseif ($this->show_compat_errors) { |
|
112 | - if (array_search($m, $this->compat['methods']) !== false) { |
|
113 | - $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
114 | - } else { |
|
115 | - $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * List of unsupported properties and methods |
|
122 | - */ |
|
123 | - protected $compat = array( |
|
124 | - 'methods' => array( |
|
125 | - 'register_resource', |
|
126 | - 'unregister_resource', |
|
127 | - 'load_filter', |
|
128 | - 'clear_compiled_tpl', |
|
129 | - 'clear_config', |
|
130 | - 'get_config_vars', |
|
131 | - 'config_load', |
|
132 | - ), |
|
133 | - 'properties' => array( |
|
134 | - 'cache_handler_func' => null, |
|
135 | - 'debugging' => false, |
|
136 | - 'error_reporting' => null, |
|
137 | - 'debugging_ctrl' => 'NONE', |
|
138 | - 'request_vars_order' => 'EGPCS', |
|
139 | - 'request_use_auto_globals' => true, |
|
140 | - 'use_sub_dirs' => false, |
|
141 | - 'autoload_filters' => array(), |
|
142 | - 'default_template_handler_func' => '', |
|
143 | - 'debug_tpl' => '', |
|
144 | - 'cache_modified_check' => false, |
|
145 | - 'default_modifiers' => array(), |
|
146 | - 'default_resource_type' => 'file', |
|
147 | - 'config_overwrite' => true, |
|
148 | - 'config_booleanize' => true, |
|
149 | - 'config_read_hidden' => false, |
|
150 | - 'config_fix_newlines' => true, |
|
151 | - 'config_class' => 'Config_File', |
|
152 | - ), |
|
153 | - ); |
|
154 | - |
|
155 | - /** |
|
156 | - * Security vars |
|
157 | - */ |
|
158 | - public $security = false; |
|
159 | - public $trusted_dir = array(); |
|
160 | - public $secure_dir = array(); |
|
161 | - public $php_handling = SMARTY_PHP_PASSTHRU; |
|
162 | - public $security_settings = array( |
|
163 | - 'PHP_HANDLING' => false, |
|
164 | - 'IF_FUNCS' => array( |
|
165 | - 'list', |
|
166 | - 'empty', |
|
167 | - 'count', |
|
168 | - 'sizeof', |
|
169 | - 'in_array', |
|
170 | - 'is_array', |
|
171 | - ), |
|
172 | - 'INCLUDE_ANY' => false, |
|
173 | - 'PHP_TAGS' => false, |
|
174 | - 'MODIFIER_FUNCS' => array(), |
|
175 | - 'ALLOW_CONSTANTS' => false, |
|
176 | - ); |
|
177 | - |
|
178 | - /** |
|
179 | - * Paths |
|
180 | - */ |
|
181 | - public $template_dir = 'templates'; |
|
182 | - public $compile_dir = 'templates_c'; |
|
183 | - public $config_dir = 'configs'; |
|
184 | - public $cache_dir = 'cache'; |
|
185 | - public $plugins_dir = array(); |
|
186 | - |
|
187 | - /** |
|
188 | - * Misc options |
|
189 | - */ |
|
190 | - public $left_delimiter = '{'; |
|
191 | - public $right_delimiter = '}'; |
|
192 | - public $compile_check = true; |
|
193 | - public $force_compile = false; |
|
194 | - public $caching = 0; |
|
195 | - public $cache_lifetime = 3600; |
|
196 | - public $compile_id = null; |
|
197 | - public $compiler_file = null; |
|
198 | - public $compiler_class = null; |
|
199 | - |
|
200 | - /** |
|
201 | - * Dwoo/Smarty compat layer |
|
202 | - */ |
|
203 | - public $show_compat_errors = false; |
|
204 | - protected $dataProvider; |
|
205 | - protected $_filters = array( |
|
206 | - 'pre' => array(), |
|
207 | - 'post' => array(), |
|
208 | - 'output' => array() |
|
209 | - ); |
|
210 | - protected static $tplCache = array(); |
|
211 | - protected $compiler = null; |
|
212 | - |
|
213 | - /** |
|
214 | - * Adapter constructor. |
|
215 | - */ |
|
216 | - public function __construct() |
|
217 | - { |
|
218 | - parent::__construct(); |
|
219 | - $this->charset = 'iso-8859-1'; |
|
220 | - $this->dataProvider = new Data(); |
|
221 | - $this->compiler = new Compiler(); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param $filename |
|
226 | - * @param null $cacheId |
|
227 | - * @param null $compileId |
|
228 | - */ |
|
229 | - public function display($filename, $cacheId = null, $compileId = null) |
|
230 | - { |
|
231 | - $this->fetch($filename, $cacheId, $compileId, true); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @param $filename |
|
236 | - * @param null $cacheId |
|
237 | - * @param null $compileId |
|
238 | - * @param bool $display |
|
239 | - * |
|
240 | - * @return string|void |
|
241 | - */ |
|
242 | - public function fetch($filename, $cacheId = null, $compileId = null, $display = false) |
|
243 | - { |
|
244 | - $this->setCacheDir($this->cache_dir); |
|
245 | - $this->setCompileDir($this->compile_dir); |
|
246 | - |
|
247 | - if ($this->security) { |
|
248 | - $policy = new SecurityPolicy(); |
|
249 | - $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS'])); |
|
250 | - |
|
251 | - $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling; |
|
252 | - if ($this->security_settings['PHP_TAGS']) { |
|
253 | - $phpTags = SMARTY_PHP_ALLOW; |
|
254 | - } |
|
255 | - switch ($phpTags) { |
|
256 | - case SMARTY_PHP_ALLOW: |
|
257 | - case SMARTY_PHP_PASSTHRU: |
|
258 | - $phpTags = SecurityPolicy::PHP_ALLOW; |
|
259 | - break; |
|
260 | - case SMARTY_PHP_QUOTE: |
|
261 | - $phpTags = SecurityPolicy::PHP_ENCODE; |
|
262 | - break; |
|
263 | - case SMARTY_PHP_REMOVE: |
|
264 | - default: |
|
265 | - $phpTags = SecurityPolicy::PHP_REMOVE; |
|
266 | - break; |
|
267 | - } |
|
268 | - $policy->setPhpHandling($phpTags); |
|
269 | - |
|
270 | - $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']); |
|
271 | - |
|
272 | - if ($this->security_settings['INCLUDE_ANY']) { |
|
273 | - $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__)); |
|
274 | - } else { |
|
275 | - $policy->allowDirectory($this->secure_dir); |
|
276 | - } |
|
277 | - |
|
278 | - $this->setSecurityPolicy($policy); |
|
279 | - } |
|
280 | - |
|
281 | - if (!empty($this->plugins_dir)) { |
|
282 | - foreach ($this->plugins_dir as $dir) { |
|
283 | - $this->getLoader()->addDirectory(rtrim($dir, '\\/')); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - $tpl = $this->makeTemplate($filename, $cacheId, $compileId); |
|
288 | - if ($this->force_compile) { |
|
289 | - $tpl->forceCompilation(); |
|
290 | - } |
|
291 | - |
|
292 | - if ($this->caching > 0) { |
|
293 | - $this->cacheTime = $this->cache_lifetime; |
|
294 | - } else { |
|
295 | - $this->cacheTime = 0; |
|
296 | - } |
|
297 | - |
|
298 | - if ($this->compiler_class !== null) { |
|
299 | - if ($this->compiler_file !== null && !class_exists($this->compiler_class)) { |
|
300 | - include $this->compiler_file; |
|
301 | - } |
|
302 | - $this->compiler = new $this->compiler_class(); |
|
303 | - } else { |
|
304 | - $this->compiler->addPreProcessor('PluginSmartyCompatible', true); |
|
305 | - $this->compiler->setLooseOpeningHandling(true); |
|
306 | - } |
|
307 | - |
|
308 | - $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter); |
|
309 | - |
|
310 | - return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true); |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @param mixed $_tpl |
|
315 | - * @param array $data |
|
316 | - * @param null $_compiler |
|
317 | - * @param bool $_output |
|
318 | - * |
|
319 | - * @return string|void |
|
320 | - */ |
|
321 | - public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
322 | - { |
|
323 | - if ($_compiler === null) { |
|
324 | - $_compiler = $this->compiler; |
|
325 | - } |
|
326 | - |
|
327 | - return parent::get($_tpl, $data, $_compiler, $_output); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param $name |
|
332 | - * @param $callback |
|
333 | - * @param bool $cacheable |
|
334 | - * @param null $cache_attrs |
|
335 | - * |
|
336 | - * @throws Exception |
|
337 | - */ |
|
338 | - public function register_function($name, $callback, $cacheable = true, $cache_attrs = null) |
|
339 | - { |
|
340 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) { |
|
341 | - throw new Exception('Multiple plugins of different types can not share the same name'); |
|
342 | - } |
|
343 | - $this->plugins[$name] = array( |
|
344 | - 'type' => self::SMARTY_FUNCTION, |
|
345 | - 'callback' => $callback |
|
346 | - ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * @param $name |
|
351 | - */ |
|
352 | - public function unregister_function($name) |
|
353 | - { |
|
354 | - unset($this->plugins[$name]); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * @param $name |
|
359 | - * @param $callback |
|
360 | - * @param bool $cacheable |
|
361 | - * @param null $cache_attrs |
|
362 | - * |
|
363 | - * @throws Exception |
|
364 | - */ |
|
365 | - public function register_block($name, $callback, $cacheable = true, $cache_attrs = null) |
|
366 | - { |
|
367 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) { |
|
368 | - throw new Exception('Multiple plugins of different types can not share the same name'); |
|
369 | - } |
|
370 | - $this->plugins[$name] = array( |
|
371 | - 'type' => self::SMARTY_BLOCK, |
|
372 | - 'callback' => $callback |
|
373 | - ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @param $name |
|
378 | - */ |
|
379 | - public function unregister_block($name) |
|
380 | - { |
|
381 | - unset($this->plugins[$name]); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * @param $name |
|
386 | - * @param $callback |
|
387 | - * |
|
388 | - * @throws Exception |
|
389 | - */ |
|
390 | - public function register_modifier($name, $callback) |
|
391 | - { |
|
392 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) { |
|
393 | - throw new Exception('Multiple plugins of different types can not share the same name'); |
|
394 | - } |
|
395 | - $this->plugins[$name] = array( |
|
396 | - 'type' => self::SMARTY_MODIFIER, |
|
397 | - 'callback' => $callback |
|
398 | - ); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * @param $name |
|
403 | - */ |
|
404 | - public function unregister_modifier($name) |
|
405 | - { |
|
406 | - unset($this->plugins[$name]); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * @param $callback |
|
411 | - */ |
|
412 | - public function register_prefilter($callback) |
|
413 | - { |
|
414 | - $processor = new ProcessorAdapter($this->compiler); |
|
415 | - $processor->registerCallback($callback); |
|
416 | - $this->_filters['pre'][] = $processor; |
|
417 | - $this->compiler->addPreProcessor($processor); |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * @param $callback |
|
422 | - */ |
|
423 | - public function unregister_prefilter($callback) |
|
424 | - { |
|
425 | - foreach ($this->_filters['pre'] as $index => $processor) { |
|
426 | - if ($processor->callback === $callback) { |
|
427 | - $this->compiler->removePostProcessor($processor); |
|
428 | - unset($this->_filters['pre'][$index]); |
|
429 | - } |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param $callback |
|
435 | - */ |
|
436 | - public function register_postfilter($callback) |
|
437 | - { |
|
438 | - $processor = new ProcessorAdapter($this->compiler); |
|
439 | - $processor->registerCallback($callback); |
|
440 | - $this->_filters['post'][] = $processor; |
|
441 | - $this->compiler->addPostProcessor($processor); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * @param $callback |
|
446 | - */ |
|
447 | - public function unregister_postfilter($callback) |
|
448 | - { |
|
449 | - foreach ($this->_filters['post'] as $index => $processor) { |
|
450 | - if ($processor->callback === $callback) { |
|
451 | - $this->compiler->removePostProcessor($processor); |
|
452 | - unset($this->_filters['post'][$index]); |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @param $callback |
|
459 | - */ |
|
460 | - public function register_outputfilter($callback) |
|
461 | - { |
|
462 | - $filter = new FilterAdapter($this); |
|
463 | - $filter->registerCallback($callback); |
|
464 | - $this->_filters['output'][] = $filter; |
|
465 | - $this->addFilter($filter); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * @param $callback |
|
470 | - */ |
|
471 | - public function unregister_outputfilter($callback) |
|
472 | - { |
|
473 | - foreach ($this->_filters['output'] as $index => $filter) { |
|
474 | - if ($filter->callback === $callback) { |
|
475 | - $this->removeOutputFilter($filter); |
|
476 | - unset($this->_filters['output'][$index]); |
|
477 | - } |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @param $object |
|
483 | - * @param $object_impl |
|
484 | - * @param array $allowed |
|
485 | - * @param bool $smarty_args |
|
486 | - * @param array $block_methods |
|
487 | - */ |
|
488 | - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array()) |
|
489 | - { |
|
490 | - settype($allowed, 'array'); |
|
491 | - settype($block_methods, 'array'); |
|
492 | - settype($smarty_args, 'boolean'); |
|
493 | - |
|
494 | - if (!empty($allowed) && $this->show_compat_errors) { |
|
495 | - $this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE); |
|
496 | - } |
|
497 | - |
|
498 | - if ($smarty_args) { |
|
499 | - $this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE); |
|
500 | - } |
|
501 | - |
|
502 | - if (!empty($block_methods)) { |
|
503 | - $this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE); |
|
504 | - } |
|
505 | - |
|
506 | - $this->dataProvider->assign($object, $object_impl); |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * @param $object |
|
511 | - */ |
|
512 | - public function unregister_object($object) |
|
513 | - { |
|
514 | - $this->dataProvider->clear($object); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * @param $name |
|
519 | - * |
|
520 | - * @return mixed |
|
521 | - */ |
|
522 | - public function get_registered_object($name) |
|
523 | - { |
|
524 | - $data = $this->dataProvider->getData(); |
|
525 | - if (isset($data[$name]) && is_object($data[$name])) { |
|
526 | - return $data[$name]; |
|
527 | - } else { |
|
528 | - trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR); |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @param $filename |
|
534 | - * |
|
535 | - * @return bool |
|
536 | - */ |
|
537 | - public function template_exists($filename) |
|
538 | - { |
|
539 | - if (!is_array($this->template_dir)) { |
|
540 | - return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename); |
|
541 | - } else { |
|
542 | - foreach ($this->template_dir as $tpl_dir) { |
|
543 | - if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) { |
|
544 | - return true; |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - return false; |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * @param $tpl |
|
554 | - * @param null $cacheId |
|
555 | - * @param null $compileId |
|
556 | - * |
|
557 | - * @return bool |
|
558 | - */ |
|
559 | - public function is_cached($tpl, $cacheId = null, $compileId = null) |
|
560 | - { |
|
561 | - return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId)); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @param $var |
|
566 | - * @param $value |
|
567 | - * @param bool $merge |
|
568 | - */ |
|
569 | - public function append_by_ref($var, &$value, $merge = false) |
|
570 | - { |
|
571 | - $this->dataProvider->appendByRef($var, $value, $merge); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * @param $name |
|
576 | - * @param $val |
|
577 | - */ |
|
578 | - public function assign_by_ref($name, &$val) |
|
579 | - { |
|
580 | - $this->dataProvider->assignByRef($name, $val); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * @param $var |
|
585 | - */ |
|
586 | - public function clear_assign($var) |
|
587 | - { |
|
588 | - $this->dataProvider->clear($var); |
|
589 | - } |
|
590 | - |
|
591 | - /** |
|
592 | - * |
|
593 | - */ |
|
594 | - public function clear_all_assign() |
|
595 | - { |
|
596 | - $this->dataProvider->clear(); |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * @param null $name |
|
601 | - * |
|
602 | - * @return array|null |
|
603 | - */ |
|
604 | - public function get_template_vars($name = null) |
|
605 | - { |
|
606 | - if ($this->show_compat_errors) { |
|
607 | - trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE); |
|
608 | - } |
|
609 | - |
|
610 | - $data = $this->dataProvider->getData(); |
|
611 | - if ($name === null) { |
|
612 | - return $data; |
|
613 | - } elseif (isset($data[$name])) { |
|
614 | - return $data[$name]; |
|
615 | - } |
|
616 | - |
|
617 | - return null; |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * @param int $olderThan |
|
622 | - */ |
|
623 | - public function clear_all_cache($olderThan = 0) |
|
624 | - { |
|
625 | - $this->clearCache($olderThan); |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * @param $template |
|
630 | - * @param null $cacheId |
|
631 | - * @param null $compileId |
|
632 | - * @param int $olderThan |
|
633 | - */ |
|
634 | - public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0) |
|
635 | - { |
|
636 | - $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan); |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * @param $error_msg |
|
641 | - * @param int $error_type |
|
642 | - */ |
|
643 | - public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
644 | - { |
|
645 | - $this->triggerError($error_msg, $error_type); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * |
|
650 | - */ |
|
651 | - protected function initGlobals() |
|
652 | - { |
|
653 | - parent::initGlobals(); |
|
654 | - $this->globals['ldelim'] = '{'; |
|
655 | - $this->globals['rdelim'] = '}'; |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * @param $file |
|
660 | - * @param $cacheId |
|
661 | - * @param $compileId |
|
662 | - * |
|
663 | - * @return mixed |
|
664 | - * @throws Exception |
|
665 | - */ |
|
666 | - protected function makeTemplate($file, $cacheId, $compileId) |
|
667 | - { |
|
668 | - if ($compileId === null) { |
|
669 | - $compileId = $this->compile_id; |
|
670 | - } |
|
671 | - |
|
672 | - $hash = bin2hex(md5($file . $cacheId . $compileId, true)); |
|
673 | - if (!isset(self::$tplCache[$hash])) { |
|
674 | - // abs path |
|
675 | - if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') { |
|
676 | - self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId); |
|
677 | - } elseif (is_string($this->template_dir) || is_array($this->template_dir)) { |
|
678 | - self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir); |
|
679 | - } else { |
|
680 | - throw new Exception('Unable to load "' . $file . '", check the template_dir'); |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - return self::$tplCache[$hash]; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * @param string $message |
|
689 | - * @param int $level |
|
690 | - */ |
|
691 | - public function triggerError($message, $level = E_USER_NOTICE) |
|
692 | - { |
|
693 | - if (is_object($this->template)) { |
|
694 | - parent::triggerError($message, $level); |
|
695 | - } |
|
696 | - trigger_error('Dwoo error : ' . $message, $level); |
|
697 | - } |
|
46 | + /** |
|
47 | + * Magic get/set/call functions that handle unsupported features |
|
48 | + * |
|
49 | + * @param string $p |
|
50 | + * @param string $v |
|
51 | + */ |
|
52 | + public function __set($p, $v) |
|
53 | + { |
|
54 | + if ($p === 'scope') { |
|
55 | + $this->scope = $v; |
|
56 | + |
|
57 | + return; |
|
58 | + } |
|
59 | + if ($p === 'data') { |
|
60 | + $this->data = $v; |
|
61 | + |
|
62 | + return; |
|
63 | + } |
|
64 | + if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
65 | + if ($this->show_compat_errors) { |
|
66 | + $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
67 | + } |
|
68 | + $this->compat['properties'][$p] = $v; |
|
69 | + } else { |
|
70 | + if ($this->show_compat_errors) { |
|
71 | + $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param $p |
|
78 | + * |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public function __get($p) |
|
82 | + { |
|
83 | + if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
84 | + if ($this->show_compat_errors) { |
|
85 | + $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
86 | + } |
|
87 | + |
|
88 | + return $this->compat['properties'][$p]; |
|
89 | + } else { |
|
90 | + if ($this->show_compat_errors) { |
|
91 | + $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $m |
|
98 | + * @param array $a |
|
99 | + * |
|
100 | + * @return mixed|void |
|
101 | + */ |
|
102 | + public function __call($m, $a) |
|
103 | + { |
|
104 | + if (method_exists($this->dataProvider, $m)) { |
|
105 | + call_user_func_array( |
|
106 | + array( |
|
107 | + $this->dataProvider, |
|
108 | + $m |
|
109 | + ), $a |
|
110 | + ); |
|
111 | + } elseif ($this->show_compat_errors) { |
|
112 | + if (array_search($m, $this->compat['methods']) !== false) { |
|
113 | + $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
114 | + } else { |
|
115 | + $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * List of unsupported properties and methods |
|
122 | + */ |
|
123 | + protected $compat = array( |
|
124 | + 'methods' => array( |
|
125 | + 'register_resource', |
|
126 | + 'unregister_resource', |
|
127 | + 'load_filter', |
|
128 | + 'clear_compiled_tpl', |
|
129 | + 'clear_config', |
|
130 | + 'get_config_vars', |
|
131 | + 'config_load', |
|
132 | + ), |
|
133 | + 'properties' => array( |
|
134 | + 'cache_handler_func' => null, |
|
135 | + 'debugging' => false, |
|
136 | + 'error_reporting' => null, |
|
137 | + 'debugging_ctrl' => 'NONE', |
|
138 | + 'request_vars_order' => 'EGPCS', |
|
139 | + 'request_use_auto_globals' => true, |
|
140 | + 'use_sub_dirs' => false, |
|
141 | + 'autoload_filters' => array(), |
|
142 | + 'default_template_handler_func' => '', |
|
143 | + 'debug_tpl' => '', |
|
144 | + 'cache_modified_check' => false, |
|
145 | + 'default_modifiers' => array(), |
|
146 | + 'default_resource_type' => 'file', |
|
147 | + 'config_overwrite' => true, |
|
148 | + 'config_booleanize' => true, |
|
149 | + 'config_read_hidden' => false, |
|
150 | + 'config_fix_newlines' => true, |
|
151 | + 'config_class' => 'Config_File', |
|
152 | + ), |
|
153 | + ); |
|
154 | + |
|
155 | + /** |
|
156 | + * Security vars |
|
157 | + */ |
|
158 | + public $security = false; |
|
159 | + public $trusted_dir = array(); |
|
160 | + public $secure_dir = array(); |
|
161 | + public $php_handling = SMARTY_PHP_PASSTHRU; |
|
162 | + public $security_settings = array( |
|
163 | + 'PHP_HANDLING' => false, |
|
164 | + 'IF_FUNCS' => array( |
|
165 | + 'list', |
|
166 | + 'empty', |
|
167 | + 'count', |
|
168 | + 'sizeof', |
|
169 | + 'in_array', |
|
170 | + 'is_array', |
|
171 | + ), |
|
172 | + 'INCLUDE_ANY' => false, |
|
173 | + 'PHP_TAGS' => false, |
|
174 | + 'MODIFIER_FUNCS' => array(), |
|
175 | + 'ALLOW_CONSTANTS' => false, |
|
176 | + ); |
|
177 | + |
|
178 | + /** |
|
179 | + * Paths |
|
180 | + */ |
|
181 | + public $template_dir = 'templates'; |
|
182 | + public $compile_dir = 'templates_c'; |
|
183 | + public $config_dir = 'configs'; |
|
184 | + public $cache_dir = 'cache'; |
|
185 | + public $plugins_dir = array(); |
|
186 | + |
|
187 | + /** |
|
188 | + * Misc options |
|
189 | + */ |
|
190 | + public $left_delimiter = '{'; |
|
191 | + public $right_delimiter = '}'; |
|
192 | + public $compile_check = true; |
|
193 | + public $force_compile = false; |
|
194 | + public $caching = 0; |
|
195 | + public $cache_lifetime = 3600; |
|
196 | + public $compile_id = null; |
|
197 | + public $compiler_file = null; |
|
198 | + public $compiler_class = null; |
|
199 | + |
|
200 | + /** |
|
201 | + * Dwoo/Smarty compat layer |
|
202 | + */ |
|
203 | + public $show_compat_errors = false; |
|
204 | + protected $dataProvider; |
|
205 | + protected $_filters = array( |
|
206 | + 'pre' => array(), |
|
207 | + 'post' => array(), |
|
208 | + 'output' => array() |
|
209 | + ); |
|
210 | + protected static $tplCache = array(); |
|
211 | + protected $compiler = null; |
|
212 | + |
|
213 | + /** |
|
214 | + * Adapter constructor. |
|
215 | + */ |
|
216 | + public function __construct() |
|
217 | + { |
|
218 | + parent::__construct(); |
|
219 | + $this->charset = 'iso-8859-1'; |
|
220 | + $this->dataProvider = new Data(); |
|
221 | + $this->compiler = new Compiler(); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param $filename |
|
226 | + * @param null $cacheId |
|
227 | + * @param null $compileId |
|
228 | + */ |
|
229 | + public function display($filename, $cacheId = null, $compileId = null) |
|
230 | + { |
|
231 | + $this->fetch($filename, $cacheId, $compileId, true); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @param $filename |
|
236 | + * @param null $cacheId |
|
237 | + * @param null $compileId |
|
238 | + * @param bool $display |
|
239 | + * |
|
240 | + * @return string|void |
|
241 | + */ |
|
242 | + public function fetch($filename, $cacheId = null, $compileId = null, $display = false) |
|
243 | + { |
|
244 | + $this->setCacheDir($this->cache_dir); |
|
245 | + $this->setCompileDir($this->compile_dir); |
|
246 | + |
|
247 | + if ($this->security) { |
|
248 | + $policy = new SecurityPolicy(); |
|
249 | + $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS'])); |
|
250 | + |
|
251 | + $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling; |
|
252 | + if ($this->security_settings['PHP_TAGS']) { |
|
253 | + $phpTags = SMARTY_PHP_ALLOW; |
|
254 | + } |
|
255 | + switch ($phpTags) { |
|
256 | + case SMARTY_PHP_ALLOW: |
|
257 | + case SMARTY_PHP_PASSTHRU: |
|
258 | + $phpTags = SecurityPolicy::PHP_ALLOW; |
|
259 | + break; |
|
260 | + case SMARTY_PHP_QUOTE: |
|
261 | + $phpTags = SecurityPolicy::PHP_ENCODE; |
|
262 | + break; |
|
263 | + case SMARTY_PHP_REMOVE: |
|
264 | + default: |
|
265 | + $phpTags = SecurityPolicy::PHP_REMOVE; |
|
266 | + break; |
|
267 | + } |
|
268 | + $policy->setPhpHandling($phpTags); |
|
269 | + |
|
270 | + $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']); |
|
271 | + |
|
272 | + if ($this->security_settings['INCLUDE_ANY']) { |
|
273 | + $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__)); |
|
274 | + } else { |
|
275 | + $policy->allowDirectory($this->secure_dir); |
|
276 | + } |
|
277 | + |
|
278 | + $this->setSecurityPolicy($policy); |
|
279 | + } |
|
280 | + |
|
281 | + if (!empty($this->plugins_dir)) { |
|
282 | + foreach ($this->plugins_dir as $dir) { |
|
283 | + $this->getLoader()->addDirectory(rtrim($dir, '\\/')); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + $tpl = $this->makeTemplate($filename, $cacheId, $compileId); |
|
288 | + if ($this->force_compile) { |
|
289 | + $tpl->forceCompilation(); |
|
290 | + } |
|
291 | + |
|
292 | + if ($this->caching > 0) { |
|
293 | + $this->cacheTime = $this->cache_lifetime; |
|
294 | + } else { |
|
295 | + $this->cacheTime = 0; |
|
296 | + } |
|
297 | + |
|
298 | + if ($this->compiler_class !== null) { |
|
299 | + if ($this->compiler_file !== null && !class_exists($this->compiler_class)) { |
|
300 | + include $this->compiler_file; |
|
301 | + } |
|
302 | + $this->compiler = new $this->compiler_class(); |
|
303 | + } else { |
|
304 | + $this->compiler->addPreProcessor('PluginSmartyCompatible', true); |
|
305 | + $this->compiler->setLooseOpeningHandling(true); |
|
306 | + } |
|
307 | + |
|
308 | + $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter); |
|
309 | + |
|
310 | + return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true); |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @param mixed $_tpl |
|
315 | + * @param array $data |
|
316 | + * @param null $_compiler |
|
317 | + * @param bool $_output |
|
318 | + * |
|
319 | + * @return string|void |
|
320 | + */ |
|
321 | + public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
322 | + { |
|
323 | + if ($_compiler === null) { |
|
324 | + $_compiler = $this->compiler; |
|
325 | + } |
|
326 | + |
|
327 | + return parent::get($_tpl, $data, $_compiler, $_output); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param $name |
|
332 | + * @param $callback |
|
333 | + * @param bool $cacheable |
|
334 | + * @param null $cache_attrs |
|
335 | + * |
|
336 | + * @throws Exception |
|
337 | + */ |
|
338 | + public function register_function($name, $callback, $cacheable = true, $cache_attrs = null) |
|
339 | + { |
|
340 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) { |
|
341 | + throw new Exception('Multiple plugins of different types can not share the same name'); |
|
342 | + } |
|
343 | + $this->plugins[$name] = array( |
|
344 | + 'type' => self::SMARTY_FUNCTION, |
|
345 | + 'callback' => $callback |
|
346 | + ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * @param $name |
|
351 | + */ |
|
352 | + public function unregister_function($name) |
|
353 | + { |
|
354 | + unset($this->plugins[$name]); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * @param $name |
|
359 | + * @param $callback |
|
360 | + * @param bool $cacheable |
|
361 | + * @param null $cache_attrs |
|
362 | + * |
|
363 | + * @throws Exception |
|
364 | + */ |
|
365 | + public function register_block($name, $callback, $cacheable = true, $cache_attrs = null) |
|
366 | + { |
|
367 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) { |
|
368 | + throw new Exception('Multiple plugins of different types can not share the same name'); |
|
369 | + } |
|
370 | + $this->plugins[$name] = array( |
|
371 | + 'type' => self::SMARTY_BLOCK, |
|
372 | + 'callback' => $callback |
|
373 | + ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @param $name |
|
378 | + */ |
|
379 | + public function unregister_block($name) |
|
380 | + { |
|
381 | + unset($this->plugins[$name]); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * @param $name |
|
386 | + * @param $callback |
|
387 | + * |
|
388 | + * @throws Exception |
|
389 | + */ |
|
390 | + public function register_modifier($name, $callback) |
|
391 | + { |
|
392 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) { |
|
393 | + throw new Exception('Multiple plugins of different types can not share the same name'); |
|
394 | + } |
|
395 | + $this->plugins[$name] = array( |
|
396 | + 'type' => self::SMARTY_MODIFIER, |
|
397 | + 'callback' => $callback |
|
398 | + ); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * @param $name |
|
403 | + */ |
|
404 | + public function unregister_modifier($name) |
|
405 | + { |
|
406 | + unset($this->plugins[$name]); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * @param $callback |
|
411 | + */ |
|
412 | + public function register_prefilter($callback) |
|
413 | + { |
|
414 | + $processor = new ProcessorAdapter($this->compiler); |
|
415 | + $processor->registerCallback($callback); |
|
416 | + $this->_filters['pre'][] = $processor; |
|
417 | + $this->compiler->addPreProcessor($processor); |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * @param $callback |
|
422 | + */ |
|
423 | + public function unregister_prefilter($callback) |
|
424 | + { |
|
425 | + foreach ($this->_filters['pre'] as $index => $processor) { |
|
426 | + if ($processor->callback === $callback) { |
|
427 | + $this->compiler->removePostProcessor($processor); |
|
428 | + unset($this->_filters['pre'][$index]); |
|
429 | + } |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param $callback |
|
435 | + */ |
|
436 | + public function register_postfilter($callback) |
|
437 | + { |
|
438 | + $processor = new ProcessorAdapter($this->compiler); |
|
439 | + $processor->registerCallback($callback); |
|
440 | + $this->_filters['post'][] = $processor; |
|
441 | + $this->compiler->addPostProcessor($processor); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * @param $callback |
|
446 | + */ |
|
447 | + public function unregister_postfilter($callback) |
|
448 | + { |
|
449 | + foreach ($this->_filters['post'] as $index => $processor) { |
|
450 | + if ($processor->callback === $callback) { |
|
451 | + $this->compiler->removePostProcessor($processor); |
|
452 | + unset($this->_filters['post'][$index]); |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @param $callback |
|
459 | + */ |
|
460 | + public function register_outputfilter($callback) |
|
461 | + { |
|
462 | + $filter = new FilterAdapter($this); |
|
463 | + $filter->registerCallback($callback); |
|
464 | + $this->_filters['output'][] = $filter; |
|
465 | + $this->addFilter($filter); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * @param $callback |
|
470 | + */ |
|
471 | + public function unregister_outputfilter($callback) |
|
472 | + { |
|
473 | + foreach ($this->_filters['output'] as $index => $filter) { |
|
474 | + if ($filter->callback === $callback) { |
|
475 | + $this->removeOutputFilter($filter); |
|
476 | + unset($this->_filters['output'][$index]); |
|
477 | + } |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @param $object |
|
483 | + * @param $object_impl |
|
484 | + * @param array $allowed |
|
485 | + * @param bool $smarty_args |
|
486 | + * @param array $block_methods |
|
487 | + */ |
|
488 | + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array()) |
|
489 | + { |
|
490 | + settype($allowed, 'array'); |
|
491 | + settype($block_methods, 'array'); |
|
492 | + settype($smarty_args, 'boolean'); |
|
493 | + |
|
494 | + if (!empty($allowed) && $this->show_compat_errors) { |
|
495 | + $this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE); |
|
496 | + } |
|
497 | + |
|
498 | + if ($smarty_args) { |
|
499 | + $this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE); |
|
500 | + } |
|
501 | + |
|
502 | + if (!empty($block_methods)) { |
|
503 | + $this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE); |
|
504 | + } |
|
505 | + |
|
506 | + $this->dataProvider->assign($object, $object_impl); |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * @param $object |
|
511 | + */ |
|
512 | + public function unregister_object($object) |
|
513 | + { |
|
514 | + $this->dataProvider->clear($object); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * @param $name |
|
519 | + * |
|
520 | + * @return mixed |
|
521 | + */ |
|
522 | + public function get_registered_object($name) |
|
523 | + { |
|
524 | + $data = $this->dataProvider->getData(); |
|
525 | + if (isset($data[$name]) && is_object($data[$name])) { |
|
526 | + return $data[$name]; |
|
527 | + } else { |
|
528 | + trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR); |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @param $filename |
|
534 | + * |
|
535 | + * @return bool |
|
536 | + */ |
|
537 | + public function template_exists($filename) |
|
538 | + { |
|
539 | + if (!is_array($this->template_dir)) { |
|
540 | + return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename); |
|
541 | + } else { |
|
542 | + foreach ($this->template_dir as $tpl_dir) { |
|
543 | + if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) { |
|
544 | + return true; |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + return false; |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * @param $tpl |
|
554 | + * @param null $cacheId |
|
555 | + * @param null $compileId |
|
556 | + * |
|
557 | + * @return bool |
|
558 | + */ |
|
559 | + public function is_cached($tpl, $cacheId = null, $compileId = null) |
|
560 | + { |
|
561 | + return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId)); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @param $var |
|
566 | + * @param $value |
|
567 | + * @param bool $merge |
|
568 | + */ |
|
569 | + public function append_by_ref($var, &$value, $merge = false) |
|
570 | + { |
|
571 | + $this->dataProvider->appendByRef($var, $value, $merge); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * @param $name |
|
576 | + * @param $val |
|
577 | + */ |
|
578 | + public function assign_by_ref($name, &$val) |
|
579 | + { |
|
580 | + $this->dataProvider->assignByRef($name, $val); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * @param $var |
|
585 | + */ |
|
586 | + public function clear_assign($var) |
|
587 | + { |
|
588 | + $this->dataProvider->clear($var); |
|
589 | + } |
|
590 | + |
|
591 | + /** |
|
592 | + * |
|
593 | + */ |
|
594 | + public function clear_all_assign() |
|
595 | + { |
|
596 | + $this->dataProvider->clear(); |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * @param null $name |
|
601 | + * |
|
602 | + * @return array|null |
|
603 | + */ |
|
604 | + public function get_template_vars($name = null) |
|
605 | + { |
|
606 | + if ($this->show_compat_errors) { |
|
607 | + trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE); |
|
608 | + } |
|
609 | + |
|
610 | + $data = $this->dataProvider->getData(); |
|
611 | + if ($name === null) { |
|
612 | + return $data; |
|
613 | + } elseif (isset($data[$name])) { |
|
614 | + return $data[$name]; |
|
615 | + } |
|
616 | + |
|
617 | + return null; |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * @param int $olderThan |
|
622 | + */ |
|
623 | + public function clear_all_cache($olderThan = 0) |
|
624 | + { |
|
625 | + $this->clearCache($olderThan); |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * @param $template |
|
630 | + * @param null $cacheId |
|
631 | + * @param null $compileId |
|
632 | + * @param int $olderThan |
|
633 | + */ |
|
634 | + public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0) |
|
635 | + { |
|
636 | + $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan); |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * @param $error_msg |
|
641 | + * @param int $error_type |
|
642 | + */ |
|
643 | + public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
644 | + { |
|
645 | + $this->triggerError($error_msg, $error_type); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * |
|
650 | + */ |
|
651 | + protected function initGlobals() |
|
652 | + { |
|
653 | + parent::initGlobals(); |
|
654 | + $this->globals['ldelim'] = '{'; |
|
655 | + $this->globals['rdelim'] = '}'; |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * @param $file |
|
660 | + * @param $cacheId |
|
661 | + * @param $compileId |
|
662 | + * |
|
663 | + * @return mixed |
|
664 | + * @throws Exception |
|
665 | + */ |
|
666 | + protected function makeTemplate($file, $cacheId, $compileId) |
|
667 | + { |
|
668 | + if ($compileId === null) { |
|
669 | + $compileId = $this->compile_id; |
|
670 | + } |
|
671 | + |
|
672 | + $hash = bin2hex(md5($file . $cacheId . $compileId, true)); |
|
673 | + if (!isset(self::$tplCache[$hash])) { |
|
674 | + // abs path |
|
675 | + if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') { |
|
676 | + self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId); |
|
677 | + } elseif (is_string($this->template_dir) || is_array($this->template_dir)) { |
|
678 | + self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir); |
|
679 | + } else { |
|
680 | + throw new Exception('Unable to load "' . $file . '", check the template_dir'); |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + return self::$tplCache[$hash]; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * @param string $message |
|
689 | + * @param int $level |
|
690 | + */ |
|
691 | + public function triggerError($message, $level = E_USER_NOTICE) |
|
692 | + { |
|
693 | + if (is_object($this->template)) { |
|
694 | + parent::triggerError($message, $level); |
|
695 | + } |
|
696 | + trigger_error('Dwoo error : ' . $message, $level); |
|
697 | + } |
|
698 | 698 | } |
@@ -23,23 +23,23 @@ |
||
23 | 23 | */ |
24 | 24 | class Adapter extends Filter |
25 | 25 | { |
26 | - public $callback; |
|
26 | + public $callback; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $input |
|
30 | - * |
|
31 | - * @return mixed |
|
32 | - */ |
|
33 | - public function process($input) |
|
34 | - { |
|
35 | - return call_user_func($this->callback, $input); |
|
36 | - } |
|
28 | + /** |
|
29 | + * @param string $input |
|
30 | + * |
|
31 | + * @return mixed |
|
32 | + */ |
|
33 | + public function process($input) |
|
34 | + { |
|
35 | + return call_user_func($this->callback, $input); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param $callback |
|
40 | - */ |
|
41 | - public function registerCallback($callback) |
|
42 | - { |
|
43 | - $this->callback = $callback; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param $callback |
|
40 | + */ |
|
41 | + public function registerCallback($callback) |
|
42 | + { |
|
43 | + $this->callback = $callback; |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -23,23 +23,23 @@ |
||
23 | 23 | */ |
24 | 24 | class Adapter extends Processor |
25 | 25 | { |
26 | - public $callback; |
|
26 | + public $callback; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $input |
|
30 | - * |
|
31 | - * @return mixed |
|
32 | - */ |
|
33 | - public function process($input) |
|
34 | - { |
|
35 | - return call_user_func($this->callback, $input); |
|
36 | - } |
|
28 | + /** |
|
29 | + * @param string $input |
|
30 | + * |
|
31 | + * @return mixed |
|
32 | + */ |
|
33 | + public function process($input) |
|
34 | + { |
|
35 | + return call_user_func($this->callback, $input); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param $callback |
|
40 | - */ |
|
41 | - public function registerCallback($callback) |
|
42 | - { |
|
43 | - $this->callback = $callback; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param $callback |
|
40 | + */ |
|
41 | + public function registerCallback($callback) |
|
42 | + { |
|
43 | + $this->callback = $callback; |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -23,52 +23,52 @@ |
||
23 | 23 | */ |
24 | 24 | interface IPluginProxy |
25 | 25 | { |
26 | - /** |
|
27 | - * Returns true or false to say whether the given plugin is handled by this proxy or not. |
|
28 | - * |
|
29 | - * @param string $name the plugin name |
|
30 | - * |
|
31 | - * @return bool true if the plugin is known and usable, otherwise false |
|
32 | - */ |
|
33 | - public function handles($name); |
|
26 | + /** |
|
27 | + * Returns true or false to say whether the given plugin is handled by this proxy or not. |
|
28 | + * |
|
29 | + * @param string $name the plugin name |
|
30 | + * |
|
31 | + * @return bool true if the plugin is known and usable, otherwise false |
|
32 | + */ |
|
33 | + public function handles($name); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns the code (as a string) to call the plugin |
|
37 | - * (this will be executed at runtime inside the Dwoo class). |
|
38 | - * |
|
39 | - * @param string $name the plugin name |
|
40 | - * @param array $params a parameter array, array key "*" is the rest array |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function getCode($name, $params); |
|
35 | + /** |
|
36 | + * Returns the code (as a string) to call the plugin |
|
37 | + * (this will be executed at runtime inside the Dwoo class). |
|
38 | + * |
|
39 | + * @param string $name the plugin name |
|
40 | + * @param array $params a parameter array, array key "*" is the rest array |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function getCode($name, $params); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns a callback to the plugin, this is used with the reflection API to |
|
48 | - * find out about the plugin's parameter names etc. |
|
49 | - * should you need a rest array without the possibility to edit the |
|
50 | - * plugin's code, you can provide a callback to some |
|
51 | - * other function with the correct parameter signature, i.e. : |
|
52 | - * <code> |
|
53 | - * return array($this, "callbackHelper"); |
|
54 | - * // and callbackHelper would be as such: |
|
55 | - * public function callbackHelper(array $rest=array()){} |
|
56 | - * </code> |
|
57 | - * |
|
58 | - * @param string $name the plugin name |
|
59 | - * |
|
60 | - * @return callback |
|
61 | - */ |
|
62 | - public function getCallback($name); |
|
46 | + /** |
|
47 | + * Returns a callback to the plugin, this is used with the reflection API to |
|
48 | + * find out about the plugin's parameter names etc. |
|
49 | + * should you need a rest array without the possibility to edit the |
|
50 | + * plugin's code, you can provide a callback to some |
|
51 | + * other function with the correct parameter signature, i.e. : |
|
52 | + * <code> |
|
53 | + * return array($this, "callbackHelper"); |
|
54 | + * // and callbackHelper would be as such: |
|
55 | + * public function callbackHelper(array $rest=array()){} |
|
56 | + * </code> |
|
57 | + * |
|
58 | + * @param string $name the plugin name |
|
59 | + * |
|
60 | + * @return callback |
|
61 | + */ |
|
62 | + public function getCallback($name); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns some code that will check if the plugin is loaded and if not load it |
|
66 | - * this is optional, if your plugins are autoloaded or whatever, just return an |
|
67 | - * empty string. |
|
68 | - * |
|
69 | - * @param string $name the plugin name |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getLoader($name); |
|
64 | + /** |
|
65 | + * Returns some code that will check if the plugin is loaded and if not load it |
|
66 | + * this is optional, if your plugins are autoloaded or whatever, just return an |
|
67 | + * empty string. |
|
68 | + * |
|
69 | + * @param string $name the plugin name |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getLoader($name); |
|
74 | 74 | } |
@@ -23,30 +23,30 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class Filter |
25 | 25 | { |
26 | - /** |
|
27 | - * The dwoo instance that runs this filter. |
|
28 | - * |
|
29 | - * @var Core |
|
30 | - */ |
|
31 | - protected $dwoo; |
|
26 | + /** |
|
27 | + * The dwoo instance that runs this filter. |
|
28 | + * |
|
29 | + * @var Core |
|
30 | + */ |
|
31 | + protected $dwoo; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
35 | - * the dwoo instance yourself if you need it. |
|
36 | - * |
|
37 | - * @param Core $dwoo the dwoo instance that runs this plugin |
|
38 | - */ |
|
39 | - public function __construct(Core $dwoo) |
|
40 | - { |
|
41 | - $this->dwoo = $dwoo; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
35 | + * the dwoo instance yourself if you need it. |
|
36 | + * |
|
37 | + * @param Core $dwoo the dwoo instance that runs this plugin |
|
38 | + */ |
|
39 | + public function __construct(Core $dwoo) |
|
40 | + { |
|
41 | + $this->dwoo = $dwoo; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Processes the input and returns it filtered. |
|
46 | - * |
|
47 | - * @param string $input the template to process |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function process($input); |
|
44 | + /** |
|
45 | + * Processes the input and returns it filtered. |
|
46 | + * |
|
47 | + * @param string $input the template to process |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function process($input); |
|
52 | 52 | } |
@@ -23,15 +23,15 @@ |
||
23 | 23 | */ |
24 | 24 | interface ILoader |
25 | 25 | { |
26 | - /** |
|
27 | - * Loads a plugin file. |
|
28 | - * the second parameter is used to avoid permanent rehashing when using php functions, |
|
29 | - * however this means that if you have add a plugin that overrides a php function you have |
|
30 | - * to delete the classpath.cache file(s) by hand to force a rehash of the plugins |
|
31 | - * |
|
32 | - * @param string $class the plugin name, without the `Plugin` prefix |
|
33 | - * @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it |
|
34 | - * has just been added, defaults to true |
|
35 | - */ |
|
36 | - public function loadPlugin($class, $forceRehash = true); |
|
26 | + /** |
|
27 | + * Loads a plugin file. |
|
28 | + * the second parameter is used to avoid permanent rehashing when using php functions, |
|
29 | + * however this means that if you have add a plugin that overrides a php function you have |
|
30 | + * to delete the classpath.cache file(s) by hand to force a rehash of the plugins |
|
31 | + * |
|
32 | + * @param string $class the plugin name, without the `Plugin` prefix |
|
33 | + * @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it |
|
34 | + * has just been added, defaults to true |
|
35 | + */ |
|
36 | + public function loadPlugin($class, $forceRehash = true); |
|
37 | 37 | } |
@@ -26,6 +26,6 @@ |
||
26 | 26 | */ |
27 | 27 | interface ICompilable |
28 | 28 | { |
29 | - // this replaces the process function |
|
30 | - //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
29 | + // this replaces the process function |
|
30 | + //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
31 | 31 | } |
@@ -23,30 +23,30 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class Processor |
25 | 25 | { |
26 | - /** |
|
27 | - * The compiler instance that runs this processor. |
|
28 | - * |
|
29 | - * @var Core |
|
30 | - */ |
|
31 | - protected $compiler; |
|
26 | + /** |
|
27 | + * The compiler instance that runs this processor. |
|
28 | + * |
|
29 | + * @var Core |
|
30 | + */ |
|
31 | + protected $compiler; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
35 | - * the dwoo instance yourself if you need it. |
|
36 | - * |
|
37 | - * @param Compiler $compiler the compiler class |
|
38 | - */ |
|
39 | - public function __construct(Compiler $compiler) |
|
40 | - { |
|
41 | - $this->compiler = $compiler; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
35 | + * the dwoo instance yourself if you need it. |
|
36 | + * |
|
37 | + * @param Compiler $compiler the compiler class |
|
38 | + */ |
|
39 | + public function __construct(Compiler $compiler) |
|
40 | + { |
|
41 | + $this->compiler = $compiler; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Processes the input and returns it filtered. |
|
46 | - * |
|
47 | - * @param string $input the template to process |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function process($input); |
|
44 | + /** |
|
45 | + * Processes the input and returns it filtered. |
|
46 | + * |
|
47 | + * @param string $input the template to process |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function process($input); |
|
52 | 52 | } |
@@ -25,81 +25,81 @@ |
||
25 | 25 | */ |
26 | 26 | abstract class Plugin |
27 | 27 | { |
28 | - /** |
|
29 | - * The dwoo instance that runs this plugin. |
|
30 | - * |
|
31 | - * @var Core |
|
32 | - */ |
|
33 | - protected $core; |
|
28 | + /** |
|
29 | + * The dwoo instance that runs this plugin. |
|
30 | + * |
|
31 | + * @var Core |
|
32 | + */ |
|
33 | + protected $core; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor, if you override it, call parent::__construct($core); or assign |
|
37 | - * the dwoo instance yourself if you need it. |
|
38 | - * |
|
39 | - * @param Core $core the dwoo instance that runs this plugin |
|
40 | - */ |
|
41 | - public function __construct(Core $core) |
|
42 | - { |
|
43 | - $this->core = $core; |
|
44 | - } |
|
35 | + /** |
|
36 | + * Constructor, if you override it, call parent::__construct($core); or assign |
|
37 | + * the dwoo instance yourself if you need it. |
|
38 | + * |
|
39 | + * @param Core $core the dwoo instance that runs this plugin |
|
40 | + */ |
|
41 | + public function __construct(Core $core) |
|
42 | + { |
|
43 | + $this->core = $core; |
|
44 | + } |
|
45 | 45 | |
46 | - // plugins should always implement : |
|
47 | - // public function process($arg, $arg, ...) |
|
48 | - // or for block plugins : |
|
49 | - // public function init($arg, $arg, ...) |
|
46 | + // plugins should always implement : |
|
47 | + // public function process($arg, $arg, ...) |
|
48 | + // or for block plugins : |
|
49 | + // public function init($arg, $arg, ...) |
|
50 | 50 | |
51 | - // this could be enforced with : |
|
52 | - // abstract public function process(...); |
|
53 | - // if my feature request gets enough interest one day |
|
54 | - // see => http://bugs.php.net/bug.php?id=44043 |
|
51 | + // this could be enforced with : |
|
52 | + // abstract public function process(...); |
|
53 | + // if my feature request gets enough interest one day |
|
54 | + // see => http://bugs.php.net/bug.php?id=44043 |
|
55 | 55 | |
56 | - /** |
|
57 | - * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
58 | - * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
59 | - * $p = $compiler->getCompiledParams($params); |
|
60 | - * // get only the rest array as attributes |
|
61 | - * $attributes = Plugin::paramsToAttributes($p['*']); |
|
62 | - * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
63 | - * $attributes = Plugin::paramsToAttributes($p); |
|
64 | - * |
|
65 | - * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
66 | - * inclusion in a php string |
|
67 | - * @param string $delim the string delimiter you want to use (defaults to ') |
|
68 | - * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
69 | - * escaping behavior) |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
74 | - { |
|
75 | - if (isset($params['*'])) { |
|
76 | - $params = array_merge($params, $params['*']); |
|
77 | - unset($params['*']); |
|
78 | - } |
|
56 | + /** |
|
57 | + * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
58 | + * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
59 | + * $p = $compiler->getCompiledParams($params); |
|
60 | + * // get only the rest array as attributes |
|
61 | + * $attributes = Plugin::paramsToAttributes($p['*']); |
|
62 | + * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
63 | + * $attributes = Plugin::paramsToAttributes($p); |
|
64 | + * |
|
65 | + * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
66 | + * inclusion in a php string |
|
67 | + * @param string $delim the string delimiter you want to use (defaults to ') |
|
68 | + * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
69 | + * escaping behavior) |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
74 | + { |
|
75 | + if (isset($params['*'])) { |
|
76 | + $params = array_merge($params, $params['*']); |
|
77 | + unset($params['*']); |
|
78 | + } |
|
79 | 79 | |
80 | - $out = ''; |
|
81 | - foreach ($params as $attr => $val) { |
|
82 | - $out .= ' ' . $attr . '='; |
|
83 | - if (trim($val, '"\'') == '' || $val == 'null') { |
|
84 | - $out .= str_replace($delim, '\\' . $delim, '""'); |
|
85 | - } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
86 | - $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
87 | - } else { |
|
88 | - if (!$compiler) { |
|
89 | - // disable double encoding since it can not be determined if it was encoded |
|
90 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
91 | - } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
92 | - // escape if auto escaping is disabled, or there was no variable in the string |
|
93 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
94 | - } else { |
|
95 | - // print as is |
|
96 | - $escapedVal = '.' . $val . '.'; |
|
97 | - } |
|
80 | + $out = ''; |
|
81 | + foreach ($params as $attr => $val) { |
|
82 | + $out .= ' ' . $attr . '='; |
|
83 | + if (trim($val, '"\'') == '' || $val == 'null') { |
|
84 | + $out .= str_replace($delim, '\\' . $delim, '""'); |
|
85 | + } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
86 | + $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
87 | + } else { |
|
88 | + if (!$compiler) { |
|
89 | + // disable double encoding since it can not be determined if it was encoded |
|
90 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
91 | + } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
92 | + // escape if auto escaping is disabled, or there was no variable in the string |
|
93 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
94 | + } else { |
|
95 | + // print as is |
|
96 | + $escapedVal = '.' . $val . '.'; |
|
97 | + } |
|
98 | 98 | |
99 | - $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
100 | - } |
|
101 | - } |
|
99 | + $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - return ltrim($out); |
|
104 | - } |
|
103 | + return ltrim($out); |
|
104 | + } |
|
105 | 105 | } |