Completed
Push — 1.2 ( 261ddf...fd7ca1 )
by David
15:45 queued 09:58
created
lib/Dwoo/Smarty/Adapter.php 3 patches
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!defined('DIR_SEP')) {
4
-    define('DIR_SEP', DIRECTORY_SEPARATOR);
4
+	define('DIR_SEP', DIRECTORY_SEPARATOR);
5 5
 }
6 6
 
7 7
 if (!defined('SMARTY_PHP_PASSTHRU')) {
8
-    define('SMARTY_PHP_PASSTHRU',   0);
9
-    define('SMARTY_PHP_QUOTE',      1);
10
-    define('SMARTY_PHP_REMOVE',     2);
11
-    define('SMARTY_PHP_ALLOW',      3);
8
+	define('SMARTY_PHP_PASSTHRU',   0);
9
+	define('SMARTY_PHP_QUOTE',      1);
10
+	define('SMARTY_PHP_REMOVE',     2);
11
+	define('SMARTY_PHP_ALLOW',      3);
12 12
 }
13 13
 
14 14
 /**
@@ -30,499 +30,499 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class Dwoo_Smarty__Adapter extends Dwoo_Core
32 32
 {
33
-    // magic get/set/call functions that handle unsupported features
34
-    public function __set($p, $v)
35
-    {
36
-        if ($p === 'scope') {
37
-            $this->scope = $v;
38
-
39
-            return;
40
-        }
41
-        if ($p === 'data') {
42
-            $this->data = $v;
43
-
44
-            return;
45
-        }
46
-        if (array_key_exists($p, $this->compat['properties']) !== false) {
47
-            if ($this->show_compat_errors) {
48
-                $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);
49
-            }
50
-            $this->compat['properties'][$p] = $v;
51
-        } else {
52
-            if ($this->show_compat_errors) {
53
-                $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);
54
-            }
55
-        }
56
-    }
57
-
58
-    public function __get($p)
59
-    {
60
-        if (array_key_exists($p, $this->compat['properties']) !== false) {
61
-            if ($this->show_compat_errors) {
62
-                $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);
63
-            }
64
-
65
-            return $this->compat['properties'][$p];
66
-        } else {
67
-            if ($this->show_compat_errors) {
68
-                $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);
69
-            }
70
-        }
71
-    }
72
-
73
-    public function __call($m, $a)
74
-    {
75
-        if (method_exists($this->dataProvider, $m)) {
76
-            call_user_func_array(array($this->dataProvider, $m), $a);
77
-        } elseif ($this->show_compat_errors) {
78
-            if (array_search($m, $this->compat['methods']) !== false) {
79
-                $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);
80
-            } else {
81
-                $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);
82
-            }
83
-        }
84
-    }
85
-
86
-    // list of unsupported properties and methods
87
-    protected $compat = array(
88
-        'methods' => array(
89
-            'register_resource', 'unregister_resource', 'load_filter', 'clear_compiled_tpl',
90
-            'clear_config', 'get_config_vars', 'config_load',
91
-        ),
92
-        'properties' => array(
93
-            'cache_handler_func' => null,
94
-            'debugging' => false,
95
-            'error_reporting' => null,
96
-            'debugging_ctrl' => 'NONE',
97
-            'request_vars_order' => 'EGPCS',
98
-            'request_use_auto_globals' => true,
99
-            'use_sub_dirs' => false,
100
-            'autoload_filters' => array(),
101
-            'default_template_handler_func' => '',
102
-            'debug_tpl' => '',
103
-            'cache_modified_check' => false,
104
-            'default_modifiers' => array(),
105
-            'default_resource_type' => 'file',
106
-            'config_overwrite' => true,
107
-            'config_booleanize' => true,
108
-            'config_read_hidden' => false,
109
-            'config_fix_newlines' => true,
110
-            'config_class' => 'Config_File',
111
-        ),
112
-    );
113
-
114
-    // security vars
115
-    public $security = false;
116
-    public $trusted_dir = array();
117
-    public $secure_dir = array();
118
-    public $php_handling = SMARTY_PHP_PASSTHRU;
119
-    public $security_settings = array(
120
-        'PHP_HANDLING' => false,
121
-        'IF_FUNCS' => array(
122
-            'list', 'empty', 'count', 'sizeof',
123
-            'in_array', 'is_array',
124
-        ),
125
-        'INCLUDE_ANY' => false,
126
-        'PHP_TAGS' => false,
127
-        'MODIFIER_FUNCS' => array(),
128
-        'ALLOW_CONSTANTS' => false,
129
-    );
130
-
131
-    // paths
132
-    public $template_dir = 'templates';
133
-    public $compile_dir = 'templates_c';
134
-    public $config_dir = 'configs';
135
-    public $cache_dir = 'cache';
136
-    public $plugins_dir = array();
137
-
138
-    // misc options
139
-    public $left_delimiter = '{';
140
-    public $right_delimiter = '}';
141
-    public $compile_check = true;
142
-    public $force_compile = false;
143
-    public $caching = 0;
144
-    public $cache_lifetime = 3600;
145
-    public $compile_id = null;
146
-    public $compiler_file = null;
147
-    public $compiler_class = null;
148
-
149
-    // dwoo/smarty compat layer
150
-    public $show_compat_errors = false;
151
-    protected $dataProvider;
152
-    protected $_filters = array('pre' => array(), 'post' => array(), 'output' => array());
153
-    protected static $tplCache = array();
154
-    protected $compiler = null;
155
-
156
-    public function __construct()
157
-    {
158
-        parent::__construct();
159
-        $this->charset = 'iso-8859-1';
160
-        $this->dataProvider = new Dwoo_Data();
161
-        $this->compiler = new Dwoo_Compiler();
162
-    }
163
-
164
-    public function display($filename, $cacheId = null, $compileId = null)
165
-    {
166
-        $this->fetch($filename, $cacheId, $compileId, true);
167
-    }
168
-
169
-    public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
170
-    {
171
-        $this->setCacheDir($this->cache_dir);
172
-        $this->setCompileDir($this->compile_dir);
173
-
174
-        if ($this->security) {
175
-            $policy = new Dwoo_Security_Policy();
176
-            $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
177
-
178
-            $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
179
-            if ($this->security_settings['PHP_TAGS']) {
180
-                $phpTags = SMARTY_PHP_ALLOW;
181
-            }
182
-            switch ($phpTags) {
183
-                case SMARTY_PHP_ALLOW:
184
-                case SMARTY_PHP_PASSTHRU:
185
-                    $phpTags = Dwoo_Security_Policy::PHP_ALLOW;
186
-                    break;
187
-                case SMARTY_PHP_QUOTE:
188
-                    $phpTags = Dwoo_Security_Policy::PHP_ENCODE;
189
-                    break;
190
-                case SMARTY_PHP_REMOVE:
191
-                default:
192
-                    $phpTags = Dwoo_Security_Policy::PHP_REMOVE;
193
-                    break;
194
-            }
195
-            $policy->setPhpHandling($phpTags);
196
-
197
-            $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
198
-
199
-            if ($this->security_settings['INCLUDE_ANY']) {
200
-                $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
201
-            } else {
202
-                $policy->allowDirectory($this->secure_dir);
203
-            }
204
-
205
-            $this->setSecurityPolicy($policy);
206
-        }
207
-
208
-        if (!empty($this->plugins_dir)) {
209
-            foreach ($this->plugins_dir as $dir) {
210
-                $this->getLoader()->addDirectory(rtrim($dir, '\\/'));
211
-            }
212
-        }
213
-
214
-        $tpl = $this->makeTemplate($filename, $cacheId, $compileId);
215
-        if ($this->force_compile) {
216
-            $tpl->forceCompilation();
217
-        }
218
-
219
-        if ($this->caching > 0) {
220
-            $this->cacheTime = $this->cache_lifetime;
221
-        } else {
222
-            $this->cacheTime = 0;
223
-        }
224
-
225
-        if ($this->compiler_class !== null) {
226
-            if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
227
-                include $this->compiler_file;
228
-            }
229
-            $this->compiler = new $this->compiler_class();
230
-        } else {
231
-            $this->compiler->addPreProcessor('smarty_compat', true);
232
-            $this->compiler->setLooseOpeningHandling(true);
233
-        }
234
-
235
-        $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
236
-
237
-        return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
238
-    }
239
-
240
-    public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
241
-    {
242
-        if ($_compiler === null) {
243
-            $_compiler = $this->compiler;
244
-        }
245
-
246
-        return parent::get($_tpl, $data, $_compiler, $_output);
247
-    }
248
-
249
-    public function register_function($name, $callback, $cacheable = true, $cache_attrs = null)
250
-    {
251
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) {
252
-            throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
253
-        }
254
-        $this->plugins[$name] = array('type' => self::SMARTY_FUNCTION, 'callback' => $callback);
255
-    }
256
-
257
-    public function unregister_function($name)
258
-    {
259
-        unset($this->plugins[$name]);
260
-    }
261
-
262
-    public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
263
-    {
264
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
265
-            throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
266
-        }
267
-        $this->plugins[$name] = array('type' => self::SMARTY_BLOCK, 'callback' => $callback);
268
-    }
269
-
270
-    public function unregister_block($name)
271
-    {
272
-        unset($this->plugins[$name]);
273
-    }
274
-
275
-    public function register_modifier($name, $callback)
276
-    {
277
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) {
278
-            throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
279
-        }
280
-        $this->plugins[$name] = array('type' => self::SMARTY_MODIFIER, 'callback' => $callback);
281
-    }
282
-
283
-    public function unregister_modifier($name)
284
-    {
285
-        unset($this->plugins[$name]);
286
-    }
287
-
288
-    public function register_prefilter($callback)
289
-    {
290
-        $processor = new Dwoo_SmartyProcessorAdapter($this->compiler);
291
-        $processor->registerCallback($callback);
292
-        $this->_filters['pre'][] = $processor;
293
-        $this->compiler->addPreProcessor($processor);
294
-    }
295
-
296
-    public function unregister_prefilter($callback)
297
-    {
298
-        foreach ($this->_filters['pre'] as $index => $processor) {
299
-            if ($processor->callback === $callback) {
300
-                $this->compiler->removePostProcessor($processor);
301
-                unset($this->_filters['pre'][$index]);
302
-            }
303
-        }
304
-    }
305
-
306
-    public function register_postfilter($callback)
307
-    {
308
-        $processor = new Dwoo_SmartyProcessorAdapter($this->compiler);
309
-        $processor->registerCallback($callback);
310
-        $this->_filters['post'][] = $processor;
311
-        $this->compiler->addPostProcessor($processor);
312
-    }
313
-
314
-    public function unregister_postfilter($callback)
315
-    {
316
-        foreach ($this->_filters['post'] as $index => $processor) {
317
-            if ($processor->callback === $callback) {
318
-                $this->compiler->removePostProcessor($processor);
319
-                unset($this->_filters['post'][$index]);
320
-            }
321
-        }
322
-    }
323
-
324
-    public function register_outputfilter($callback)
325
-    {
326
-        $filter = new Dwoo_SmartyFilterAdapter($this);
327
-        $filter->registerCallback($callback);
328
-        $this->_filters['output'][] = $filter;
329
-        $this->addFilter($filter);
330
-    }
331
-
332
-    public function unregister_outputfilter($callback)
333
-    {
334
-        foreach ($this->_filters['output'] as $index => $filter) {
335
-            if ($filter->callback === $callback) {
336
-                $this->removeOutputFilter($filter);
337
-                unset($this->_filters['output'][$index]);
338
-            }
339
-        }
340
-    }
341
-
342
-    public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array())
343
-    {
344
-        settype($allowed, 'array');
345
-        settype($block_methods, 'array');
346
-        settype($smarty_args, 'boolean');
347
-
348
-        if (!empty($allowed) && $this->show_compat_errors) {
349
-            $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);
350
-        }
351
-
352
-        if ($smarty_args) {
353
-            $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);
354
-        }
355
-
356
-        if (!empty($block_methods)) {
357
-            $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);
358
-        }
359
-
360
-        $this->dataProvider->assign($object, $object_impl);
361
-    }
362
-
363
-    public function unregister_object($object)
364
-    {
365
-        $this->dataProvider->clear($object);
366
-    }
367
-
368
-    public function get_registered_object($name)
369
-    {
370
-        $data = $this->dataProvider->getData();
371
-        if (isset($data[$name]) && is_object($data[$name])) {
372
-            return $data[$name];
373
-        } else {
374
-            trigger_error('Dwoo_Compiler: object "'.$name.'" was not registered or is not an object', E_USER_ERROR);
375
-        }
376
-    }
377
-
378
-    public function template_exists($filename)
379
-    {
380
-        if (!is_array($this->template_dir)) {
381
-            return file_exists($this->template_dir.DIRECTORY_SEPARATOR.$filename);
382
-        } else {
383
-            foreach ($this->template_dir as $tpl_dir) {
384
-                if (file_exists($tpl_dir.DIRECTORY_SEPARATOR.$filename)) {
385
-                    return true;
386
-                }
387
-            }
388
-
389
-            return false;
390
-        }
391
-    }
392
-
393
-    public function is_cached($tpl, $cacheId = null, $compileId = null)
394
-    {
395
-        return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId));
396
-    }
397
-
398
-    public function append_by_ref($var, &$value, $merge = false)
399
-    {
400
-        $this->dataProvider->appendByRef($var, $value, $merge);
401
-    }
402
-
403
-    public function assign_by_ref($name, &$val)
404
-    {
405
-        $this->dataProvider->assignByRef($name, $val);
406
-    }
407
-
408
-    public function clear_assign($var)
409
-    {
410
-        $this->dataProvider->clear($var);
411
-    }
412
-
413
-    public function clear_all_assign()
414
-    {
415
-        $this->dataProvider->clear();
416
-    }
417
-
418
-    public function get_template_vars($name = null)
419
-    {
420
-        if ($this->show_compat_errors) {
421
-            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);
422
-        }
423
-
424
-        $data = $this->dataProvider->getData();
425
-        if ($name === null) {
426
-            return $data;
427
-        } elseif (isset($data[$name])) {
428
-            return $data[$name];
429
-        }
430
-
431
-        return null;
432
-    }
433
-
434
-    public function clear_all_cache($olderThan = 0)
435
-    {
436
-        $this->clearCache($olderThan);
437
-    }
438
-
439
-    public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0)
440
-    {
441
-        $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
442
-    }
443
-
444
-    public function trigger_error($error_msg, $error_type = E_USER_WARNING)
445
-    {
446
-        $this->triggerError($error_msg, $error_type);
447
-    }
448
-
449
-    protected function initGlobals()
450
-    {
451
-        parent::initGlobals();
452
-        $this->globals['ldelim'] = '{';
453
-        $this->globals['rdelim'] = '}';
454
-    }
455
-
456
-    protected function makeTemplate($file, $cacheId, $compileId)
457
-    {
458
-        if ($compileId === null) {
459
-            $compileId = $this->compile_id;
460
-        }
461
-
462
-        $hash = bin2hex(md5($file.$cacheId.$compileId, true));
463
-        if (!isset(self::$tplCache[$hash])) {
464
-            // abs path
465
-            if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
466
-                self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId);
467
-            } elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
468
-                self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId, $this->template_dir);
469
-            } else {
470
-                throw new Exception('Unable to load "'.$file.'", check the template_dir');
471
-            }
472
-        }
473
-
474
-        return self::$tplCache[$hash];
475
-    }
476
-
477
-    public function triggerError($message, $level = E_USER_NOTICE)
478
-    {
479
-        if (is_object($this->template)) {
480
-            return parent::triggerError($message, $level);
481
-        }
482
-        trigger_error('Dwoo error : '.$message, $level);
483
-    }
33
+	// magic get/set/call functions that handle unsupported features
34
+	public function __set($p, $v)
35
+	{
36
+		if ($p === 'scope') {
37
+			$this->scope = $v;
38
+
39
+			return;
40
+		}
41
+		if ($p === 'data') {
42
+			$this->data = $v;
43
+
44
+			return;
45
+		}
46
+		if (array_key_exists($p, $this->compat['properties']) !== false) {
47
+			if ($this->show_compat_errors) {
48
+				$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);
49
+			}
50
+			$this->compat['properties'][$p] = $v;
51
+		} else {
52
+			if ($this->show_compat_errors) {
53
+				$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);
54
+			}
55
+		}
56
+	}
57
+
58
+	public function __get($p)
59
+	{
60
+		if (array_key_exists($p, $this->compat['properties']) !== false) {
61
+			if ($this->show_compat_errors) {
62
+				$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);
63
+			}
64
+
65
+			return $this->compat['properties'][$p];
66
+		} else {
67
+			if ($this->show_compat_errors) {
68
+				$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);
69
+			}
70
+		}
71
+	}
72
+
73
+	public function __call($m, $a)
74
+	{
75
+		if (method_exists($this->dataProvider, $m)) {
76
+			call_user_func_array(array($this->dataProvider, $m), $a);
77
+		} elseif ($this->show_compat_errors) {
78
+			if (array_search($m, $this->compat['methods']) !== false) {
79
+				$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);
80
+			} else {
81
+				$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);
82
+			}
83
+		}
84
+	}
85
+
86
+	// list of unsupported properties and methods
87
+	protected $compat = array(
88
+		'methods' => array(
89
+			'register_resource', 'unregister_resource', 'load_filter', 'clear_compiled_tpl',
90
+			'clear_config', 'get_config_vars', 'config_load',
91
+		),
92
+		'properties' => array(
93
+			'cache_handler_func' => null,
94
+			'debugging' => false,
95
+			'error_reporting' => null,
96
+			'debugging_ctrl' => 'NONE',
97
+			'request_vars_order' => 'EGPCS',
98
+			'request_use_auto_globals' => true,
99
+			'use_sub_dirs' => false,
100
+			'autoload_filters' => array(),
101
+			'default_template_handler_func' => '',
102
+			'debug_tpl' => '',
103
+			'cache_modified_check' => false,
104
+			'default_modifiers' => array(),
105
+			'default_resource_type' => 'file',
106
+			'config_overwrite' => true,
107
+			'config_booleanize' => true,
108
+			'config_read_hidden' => false,
109
+			'config_fix_newlines' => true,
110
+			'config_class' => 'Config_File',
111
+		),
112
+	);
113
+
114
+	// security vars
115
+	public $security = false;
116
+	public $trusted_dir = array();
117
+	public $secure_dir = array();
118
+	public $php_handling = SMARTY_PHP_PASSTHRU;
119
+	public $security_settings = array(
120
+		'PHP_HANDLING' => false,
121
+		'IF_FUNCS' => array(
122
+			'list', 'empty', 'count', 'sizeof',
123
+			'in_array', 'is_array',
124
+		),
125
+		'INCLUDE_ANY' => false,
126
+		'PHP_TAGS' => false,
127
+		'MODIFIER_FUNCS' => array(),
128
+		'ALLOW_CONSTANTS' => false,
129
+	);
130
+
131
+	// paths
132
+	public $template_dir = 'templates';
133
+	public $compile_dir = 'templates_c';
134
+	public $config_dir = 'configs';
135
+	public $cache_dir = 'cache';
136
+	public $plugins_dir = array();
137
+
138
+	// misc options
139
+	public $left_delimiter = '{';
140
+	public $right_delimiter = '}';
141
+	public $compile_check = true;
142
+	public $force_compile = false;
143
+	public $caching = 0;
144
+	public $cache_lifetime = 3600;
145
+	public $compile_id = null;
146
+	public $compiler_file = null;
147
+	public $compiler_class = null;
148
+
149
+	// dwoo/smarty compat layer
150
+	public $show_compat_errors = false;
151
+	protected $dataProvider;
152
+	protected $_filters = array('pre' => array(), 'post' => array(), 'output' => array());
153
+	protected static $tplCache = array();
154
+	protected $compiler = null;
155
+
156
+	public function __construct()
157
+	{
158
+		parent::__construct();
159
+		$this->charset = 'iso-8859-1';
160
+		$this->dataProvider = new Dwoo_Data();
161
+		$this->compiler = new Dwoo_Compiler();
162
+	}
163
+
164
+	public function display($filename, $cacheId = null, $compileId = null)
165
+	{
166
+		$this->fetch($filename, $cacheId, $compileId, true);
167
+	}
168
+
169
+	public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
170
+	{
171
+		$this->setCacheDir($this->cache_dir);
172
+		$this->setCompileDir($this->compile_dir);
173
+
174
+		if ($this->security) {
175
+			$policy = new Dwoo_Security_Policy();
176
+			$policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
177
+
178
+			$phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
179
+			if ($this->security_settings['PHP_TAGS']) {
180
+				$phpTags = SMARTY_PHP_ALLOW;
181
+			}
182
+			switch ($phpTags) {
183
+				case SMARTY_PHP_ALLOW:
184
+				case SMARTY_PHP_PASSTHRU:
185
+					$phpTags = Dwoo_Security_Policy::PHP_ALLOW;
186
+					break;
187
+				case SMARTY_PHP_QUOTE:
188
+					$phpTags = Dwoo_Security_Policy::PHP_ENCODE;
189
+					break;
190
+				case SMARTY_PHP_REMOVE:
191
+				default:
192
+					$phpTags = Dwoo_Security_Policy::PHP_REMOVE;
193
+					break;
194
+			}
195
+			$policy->setPhpHandling($phpTags);
196
+
197
+			$policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
198
+
199
+			if ($this->security_settings['INCLUDE_ANY']) {
200
+				$policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
201
+			} else {
202
+				$policy->allowDirectory($this->secure_dir);
203
+			}
204
+
205
+			$this->setSecurityPolicy($policy);
206
+		}
207
+
208
+		if (!empty($this->plugins_dir)) {
209
+			foreach ($this->plugins_dir as $dir) {
210
+				$this->getLoader()->addDirectory(rtrim($dir, '\\/'));
211
+			}
212
+		}
213
+
214
+		$tpl = $this->makeTemplate($filename, $cacheId, $compileId);
215
+		if ($this->force_compile) {
216
+			$tpl->forceCompilation();
217
+		}
218
+
219
+		if ($this->caching > 0) {
220
+			$this->cacheTime = $this->cache_lifetime;
221
+		} else {
222
+			$this->cacheTime = 0;
223
+		}
224
+
225
+		if ($this->compiler_class !== null) {
226
+			if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
227
+				include $this->compiler_file;
228
+			}
229
+			$this->compiler = new $this->compiler_class();
230
+		} else {
231
+			$this->compiler->addPreProcessor('smarty_compat', true);
232
+			$this->compiler->setLooseOpeningHandling(true);
233
+		}
234
+
235
+		$this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
236
+
237
+		return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
238
+	}
239
+
240
+	public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
241
+	{
242
+		if ($_compiler === null) {
243
+			$_compiler = $this->compiler;
244
+		}
245
+
246
+		return parent::get($_tpl, $data, $_compiler, $_output);
247
+	}
248
+
249
+	public function register_function($name, $callback, $cacheable = true, $cache_attrs = null)
250
+	{
251
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) {
252
+			throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
253
+		}
254
+		$this->plugins[$name] = array('type' => self::SMARTY_FUNCTION, 'callback' => $callback);
255
+	}
256
+
257
+	public function unregister_function($name)
258
+	{
259
+		unset($this->plugins[$name]);
260
+	}
261
+
262
+	public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
263
+	{
264
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
265
+			throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
266
+		}
267
+		$this->plugins[$name] = array('type' => self::SMARTY_BLOCK, 'callback' => $callback);
268
+	}
269
+
270
+	public function unregister_block($name)
271
+	{
272
+		unset($this->plugins[$name]);
273
+	}
274
+
275
+	public function register_modifier($name, $callback)
276
+	{
277
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) {
278
+			throw new Dwoo_Exception('Multiple plugins of different types can not share the same name');
279
+		}
280
+		$this->plugins[$name] = array('type' => self::SMARTY_MODIFIER, 'callback' => $callback);
281
+	}
282
+
283
+	public function unregister_modifier($name)
284
+	{
285
+		unset($this->plugins[$name]);
286
+	}
287
+
288
+	public function register_prefilter($callback)
289
+	{
290
+		$processor = new Dwoo_SmartyProcessorAdapter($this->compiler);
291
+		$processor->registerCallback($callback);
292
+		$this->_filters['pre'][] = $processor;
293
+		$this->compiler->addPreProcessor($processor);
294
+	}
295
+
296
+	public function unregister_prefilter($callback)
297
+	{
298
+		foreach ($this->_filters['pre'] as $index => $processor) {
299
+			if ($processor->callback === $callback) {
300
+				$this->compiler->removePostProcessor($processor);
301
+				unset($this->_filters['pre'][$index]);
302
+			}
303
+		}
304
+	}
305
+
306
+	public function register_postfilter($callback)
307
+	{
308
+		$processor = new Dwoo_SmartyProcessorAdapter($this->compiler);
309
+		$processor->registerCallback($callback);
310
+		$this->_filters['post'][] = $processor;
311
+		$this->compiler->addPostProcessor($processor);
312
+	}
313
+
314
+	public function unregister_postfilter($callback)
315
+	{
316
+		foreach ($this->_filters['post'] as $index => $processor) {
317
+			if ($processor->callback === $callback) {
318
+				$this->compiler->removePostProcessor($processor);
319
+				unset($this->_filters['post'][$index]);
320
+			}
321
+		}
322
+	}
323
+
324
+	public function register_outputfilter($callback)
325
+	{
326
+		$filter = new Dwoo_SmartyFilterAdapter($this);
327
+		$filter->registerCallback($callback);
328
+		$this->_filters['output'][] = $filter;
329
+		$this->addFilter($filter);
330
+	}
331
+
332
+	public function unregister_outputfilter($callback)
333
+	{
334
+		foreach ($this->_filters['output'] as $index => $filter) {
335
+			if ($filter->callback === $callback) {
336
+				$this->removeOutputFilter($filter);
337
+				unset($this->_filters['output'][$index]);
338
+			}
339
+		}
340
+	}
341
+
342
+	public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array())
343
+	{
344
+		settype($allowed, 'array');
345
+		settype($block_methods, 'array');
346
+		settype($smarty_args, 'boolean');
347
+
348
+		if (!empty($allowed) && $this->show_compat_errors) {
349
+			$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);
350
+		}
351
+
352
+		if ($smarty_args) {
353
+			$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);
354
+		}
355
+
356
+		if (!empty($block_methods)) {
357
+			$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);
358
+		}
359
+
360
+		$this->dataProvider->assign($object, $object_impl);
361
+	}
362
+
363
+	public function unregister_object($object)
364
+	{
365
+		$this->dataProvider->clear($object);
366
+	}
367
+
368
+	public function get_registered_object($name)
369
+	{
370
+		$data = $this->dataProvider->getData();
371
+		if (isset($data[$name]) && is_object($data[$name])) {
372
+			return $data[$name];
373
+		} else {
374
+			trigger_error('Dwoo_Compiler: object "'.$name.'" was not registered or is not an object', E_USER_ERROR);
375
+		}
376
+	}
377
+
378
+	public function template_exists($filename)
379
+	{
380
+		if (!is_array($this->template_dir)) {
381
+			return file_exists($this->template_dir.DIRECTORY_SEPARATOR.$filename);
382
+		} else {
383
+			foreach ($this->template_dir as $tpl_dir) {
384
+				if (file_exists($tpl_dir.DIRECTORY_SEPARATOR.$filename)) {
385
+					return true;
386
+				}
387
+			}
388
+
389
+			return false;
390
+		}
391
+	}
392
+
393
+	public function is_cached($tpl, $cacheId = null, $compileId = null)
394
+	{
395
+		return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId));
396
+	}
397
+
398
+	public function append_by_ref($var, &$value, $merge = false)
399
+	{
400
+		$this->dataProvider->appendByRef($var, $value, $merge);
401
+	}
402
+
403
+	public function assign_by_ref($name, &$val)
404
+	{
405
+		$this->dataProvider->assignByRef($name, $val);
406
+	}
407
+
408
+	public function clear_assign($var)
409
+	{
410
+		$this->dataProvider->clear($var);
411
+	}
412
+
413
+	public function clear_all_assign()
414
+	{
415
+		$this->dataProvider->clear();
416
+	}
417
+
418
+	public function get_template_vars($name = null)
419
+	{
420
+		if ($this->show_compat_errors) {
421
+			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);
422
+		}
423
+
424
+		$data = $this->dataProvider->getData();
425
+		if ($name === null) {
426
+			return $data;
427
+		} elseif (isset($data[$name])) {
428
+			return $data[$name];
429
+		}
430
+
431
+		return null;
432
+	}
433
+
434
+	public function clear_all_cache($olderThan = 0)
435
+	{
436
+		$this->clearCache($olderThan);
437
+	}
438
+
439
+	public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0)
440
+	{
441
+		$this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
442
+	}
443
+
444
+	public function trigger_error($error_msg, $error_type = E_USER_WARNING)
445
+	{
446
+		$this->triggerError($error_msg, $error_type);
447
+	}
448
+
449
+	protected function initGlobals()
450
+	{
451
+		parent::initGlobals();
452
+		$this->globals['ldelim'] = '{';
453
+		$this->globals['rdelim'] = '}';
454
+	}
455
+
456
+	protected function makeTemplate($file, $cacheId, $compileId)
457
+	{
458
+		if ($compileId === null) {
459
+			$compileId = $this->compile_id;
460
+		}
461
+
462
+		$hash = bin2hex(md5($file.$cacheId.$compileId, true));
463
+		if (!isset(self::$tplCache[$hash])) {
464
+			// abs path
465
+			if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
466
+				self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId);
467
+			} elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
468
+				self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId, $this->template_dir);
469
+			} else {
470
+				throw new Exception('Unable to load "'.$file.'", check the template_dir');
471
+			}
472
+		}
473
+
474
+		return self::$tplCache[$hash];
475
+	}
476
+
477
+	public function triggerError($message, $level = E_USER_NOTICE)
478
+	{
479
+		if (is_object($this->template)) {
480
+			return parent::triggerError($message, $level);
481
+		}
482
+		trigger_error('Dwoo error : '.$message, $level);
483
+	}
484 484
 }
485 485
 
486 486
 class Dwoo_Smarty_Filter_Adapter extends Dwoo_Filter
487 487
 {
488
-    public $callback;
488
+	public $callback;
489 489
 
490
-    public function process($input)
491
-    {
492
-        return call_user_func($this->callback, $input);
493
-    }
490
+	public function process($input)
491
+	{
492
+		return call_user_func($this->callback, $input);
493
+	}
494 494
 
495
-    public function registerCallback($callback)
496
-    {
497
-        $this->callback = $callback;
498
-    }
495
+	public function registerCallback($callback)
496
+	{
497
+		$this->callback = $callback;
498
+	}
499 499
 }
500 500
 
501 501
 class Dwoo_Smarty_Processor_Adapter extends Dwoo_Processor
502 502
 {
503
-    public $callback;
503
+	public $callback;
504 504
 
505
-    public function process($input)
506
-    {
507
-        return call_user_func($this->callback, $input);
508
-    }
505
+	public function process($input)
506
+	{
507
+		return call_user_func($this->callback, $input);
508
+	}
509 509
 
510
-    public function registerCallback($callback)
511
-    {
512
-        $this->callback = $callback;
513
-    }
510
+	public function registerCallback($callback)
511
+	{
512
+		$this->callback = $callback;
513
+	}
514 514
 }
515 515
 
516 516
 // cloaks the adapter if possible with the smarty name to fool type-hinted plugins
517 517
 if (class_exists('Smarty') === false) {
518
-    interface Smarty
519
-    {
520
-    }
521
-    class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter implements Smarty
522
-    {
523
-    }
518
+	interface Smarty
519
+	{
520
+	}
521
+	class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter implements Smarty
522
+	{
523
+	}
524 524
 } else {
525
-    class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter
526
-    {
527
-    }
525
+	class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter
526
+	{
527
+	}
528 528
 }
Please login to merge, or discard this patch.
Switch Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -180,17 +180,17 @@
 block discarded – undo
180 180
                 $phpTags = SMARTY_PHP_ALLOW;
181 181
             }
182 182
             switch ($phpTags) {
183
-                case SMARTY_PHP_ALLOW:
184
-                case SMARTY_PHP_PASSTHRU:
185
-                    $phpTags = Dwoo_Security_Policy::PHP_ALLOW;
186
-                    break;
187
-                case SMARTY_PHP_QUOTE:
188
-                    $phpTags = Dwoo_Security_Policy::PHP_ENCODE;
189
-                    break;
190
-                case SMARTY_PHP_REMOVE:
191
-                default:
192
-                    $phpTags = Dwoo_Security_Policy::PHP_REMOVE;
193
-                    break;
183
+            case SMARTY_PHP_ALLOW:
184
+            case SMARTY_PHP_PASSTHRU:
185
+                $phpTags = Dwoo_Security_Policy::PHP_ALLOW;
186
+                break;
187
+            case SMARTY_PHP_QUOTE:
188
+                $phpTags = Dwoo_Security_Policy::PHP_ENCODE;
189
+                break;
190
+            case SMARTY_PHP_REMOVE:
191
+            default:
192
+                $phpTags = Dwoo_Security_Policy::PHP_REMOVE;
193
+                break;
194 194
             }
195 195
             $policy->setPhpHandling($phpTags);
196 196
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
5 5
 }
6 6
 
7 7
 if (!defined('SMARTY_PHP_PASSTHRU')) {
8
-    define('SMARTY_PHP_PASSTHRU',   0);
9
-    define('SMARTY_PHP_QUOTE',      1);
10
-    define('SMARTY_PHP_REMOVE',     2);
11
-    define('SMARTY_PHP_ALLOW',      3);
8
+    define('SMARTY_PHP_PASSTHRU', 0);
9
+    define('SMARTY_PHP_QUOTE', 1);
10
+    define('SMARTY_PHP_REMOVE', 2);
11
+    define('SMARTY_PHP_ALLOW', 3);
12 12
 }
13 13
 
14 14
 /**
Please login to merge, or discard this patch.
lib/Dwoo/Security/Policy.php 1 patch
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Security_Policy
21 21
 {
22
-    /**#@+
22
+	/**#@+
23 23
      * php handling constants, defaults to PHP_REMOVE
24 24
      *
25 25
      * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template
@@ -28,296 +28,296 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @var int
30 30
      */
31
-    const PHP_ENCODE = 1;
32
-    const PHP_REMOVE = 2;
33
-    const PHP_ALLOW = 3;
34
-    /**#@-*/
31
+	const PHP_ENCODE = 1;
32
+	const PHP_REMOVE = 2;
33
+	const PHP_ALLOW = 3;
34
+	/**#@-*/
35 35
 
36
-    /**#@+
36
+	/**#@+
37 37
      * constant handling constants, defaults to CONST_DISALLOW
38 38
      *
39 39
      * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template
40 40
      * CONST_ALLOW : allow {$dwoo.const.*} calls
41 41
      */
42
-    const CONST_DISALLOW = false;
43
-    const CONST_ALLOW = true;
44
-    /**#@-*/
42
+	const CONST_DISALLOW = false;
43
+	const CONST_ALLOW = true;
44
+	/**#@-*/
45 45
 
46
-    /**
47
-     * php functions that are allowed to be used within the template.
48
-     *
49
-     * @var array
50
-     */
51
-    protected $allowedPhpFunctions = array(
52
-        'str_repeat' => true,
53
-        'number_format' => true,
54
-        'htmlentities' => true,
55
-        'htmlspecialchars' => true,
56
-        'long2ip' => true,
57
-        'strlen' => true,
58
-        'list' => true,
59
-        'empty' => true,
60
-        'count' => true,
61
-        'sizeof' => true,
62
-        'in_array' => true,
63
-        'is_array' => true,
64
-    );
46
+	/**
47
+	 * php functions that are allowed to be used within the template.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $allowedPhpFunctions = array(
52
+		'str_repeat' => true,
53
+		'number_format' => true,
54
+		'htmlentities' => true,
55
+		'htmlspecialchars' => true,
56
+		'long2ip' => true,
57
+		'strlen' => true,
58
+		'list' => true,
59
+		'empty' => true,
60
+		'count' => true,
61
+		'sizeof' => true,
62
+		'in_array' => true,
63
+		'is_array' => true,
64
+	);
65 65
 
66
-    /**
67
-     * methods that are allowed to be used within the template.
68
-     *
69
-     * @var array
70
-     */
71
-    protected $allowedMethods = array();
66
+	/**
67
+	 * methods that are allowed to be used within the template.
68
+	 *
69
+	 * @var array
70
+	 */
71
+	protected $allowedMethods = array();
72 72
 
73
-    /**
74
-     * paths that are safe to use with include or other file-access plugins.
75
-     *
76
-     * @var array
77
-     */
78
-    protected $allowedDirectories = array();
73
+	/**
74
+	 * paths that are safe to use with include or other file-access plugins.
75
+	 *
76
+	 * @var array
77
+	 */
78
+	protected $allowedDirectories = array();
79 79
 
80
-    /**
81
-     * stores the php handling level.
82
-     *
83
-     * defaults to Dwoo_Security_Policy::PHP_REMOVE
84
-     *
85
-     * @var int
86
-     */
87
-    protected $phpHandling = self::PHP_REMOVE;
80
+	/**
81
+	 * stores the php handling level.
82
+	 *
83
+	 * defaults to Dwoo_Security_Policy::PHP_REMOVE
84
+	 *
85
+	 * @var int
86
+	 */
87
+	protected $phpHandling = self::PHP_REMOVE;
88 88
 
89
-    /**
90
-     * stores the constant handling level.
91
-     *
92
-     * defaults to Dwoo_Security_Policy::CONST_DISALLOW
93
-     *
94
-     * @var bool
95
-     */
96
-    protected $constHandling = self::CONST_DISALLOW;
89
+	/**
90
+	 * stores the constant handling level.
91
+	 *
92
+	 * defaults to Dwoo_Security_Policy::CONST_DISALLOW
93
+	 *
94
+	 * @var bool
95
+	 */
96
+	protected $constHandling = self::CONST_DISALLOW;
97 97
 
98
-    /**
99
-     * adds a php function to the allowed list.
100
-     *
101
-     * @param mixed $func function name or array of function names
102
-     */
103
-    public function allowPhpFunction($func)
104
-    {
105
-        if (is_array($func)) {
106
-            foreach ($func as $fname) {
107
-                $this->allowedPhpFunctions[strtolower($fname)] = true;
108
-            }
109
-        } else {
110
-            $this->allowedPhpFunctions[strtolower($func)] = true;
111
-        }
112
-    }
98
+	/**
99
+	 * adds a php function to the allowed list.
100
+	 *
101
+	 * @param mixed $func function name or array of function names
102
+	 */
103
+	public function allowPhpFunction($func)
104
+	{
105
+		if (is_array($func)) {
106
+			foreach ($func as $fname) {
107
+				$this->allowedPhpFunctions[strtolower($fname)] = true;
108
+			}
109
+		} else {
110
+			$this->allowedPhpFunctions[strtolower($func)] = true;
111
+		}
112
+	}
113 113
 
114
-    /**
115
-     * removes a php function from the allowed list.
116
-     *
117
-     * @param mixed $func function name or array of function names
118
-     */
119
-    public function disallowPhpFunction($func)
120
-    {
121
-        if (is_array($func)) {
122
-            foreach ($func as $fname) {
123
-                unset($this->allowedPhpFunctions[strtolower($fname)]);
124
-            }
125
-        } else {
126
-            unset($this->allowedPhpFunctions[strtolower($func)]);
127
-        }
128
-    }
114
+	/**
115
+	 * removes a php function from the allowed list.
116
+	 *
117
+	 * @param mixed $func function name or array of function names
118
+	 */
119
+	public function disallowPhpFunction($func)
120
+	{
121
+		if (is_array($func)) {
122
+			foreach ($func as $fname) {
123
+				unset($this->allowedPhpFunctions[strtolower($fname)]);
124
+			}
125
+		} else {
126
+			unset($this->allowedPhpFunctions[strtolower($func)]);
127
+		}
128
+	}
129 129
 
130
-    /**
131
-     * returns the list of php functions allowed to run, note that the function names
132
-     * are stored in the array keys and not values.
133
-     *
134
-     * @return array
135
-     */
136
-    public function getAllowedPhpFunctions()
137
-    {
138
-        return $this->allowedPhpFunctions;
139
-    }
130
+	/**
131
+	 * returns the list of php functions allowed to run, note that the function names
132
+	 * are stored in the array keys and not values.
133
+	 *
134
+	 * @return array
135
+	 */
136
+	public function getAllowedPhpFunctions()
137
+	{
138
+		return $this->allowedPhpFunctions;
139
+	}
140 140
 
141
-    /**
142
-     * adds a class method to the allowed list, this must be used for
143
-     * both static and non static method by providing the class name
144
-     * and method name to use.
145
-     *
146
-     * @param mixed  $class  class name or array of array('class', 'method') couples
147
-     * @param string $method method name
148
-     */
149
-    public function allowMethod($class, $method = null)
150
-    {
151
-        if (is_array($class)) {
152
-            foreach ($class as $elem) {
153
-                $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true;
154
-            }
155
-        } else {
156
-            $this->allowedMethods[strtolower($class)][strtolower($method)] = true;
157
-        }
158
-    }
141
+	/**
142
+	 * adds a class method to the allowed list, this must be used for
143
+	 * both static and non static method by providing the class name
144
+	 * and method name to use.
145
+	 *
146
+	 * @param mixed  $class  class name or array of array('class', 'method') couples
147
+	 * @param string $method method name
148
+	 */
149
+	public function allowMethod($class, $method = null)
150
+	{
151
+		if (is_array($class)) {
152
+			foreach ($class as $elem) {
153
+				$this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true;
154
+			}
155
+		} else {
156
+			$this->allowedMethods[strtolower($class)][strtolower($method)] = true;
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * removes a class method from the allowed list.
162
-     *
163
-     * @param mixed  $class  class name or array of array('class', 'method') couples
164
-     * @param string $method method name
165
-     */
166
-    public function disallowMethod($class, $method = null)
167
-    {
168
-        if (is_array($class)) {
169
-            foreach ($class as $elem) {
170
-                unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]);
171
-            }
172
-        } else {
173
-            unset($this->allowedMethods[strtolower($class)][strtolower($method)]);
174
-        }
175
-    }
160
+	/**
161
+	 * removes a class method from the allowed list.
162
+	 *
163
+	 * @param mixed  $class  class name or array of array('class', 'method') couples
164
+	 * @param string $method method name
165
+	 */
166
+	public function disallowMethod($class, $method = null)
167
+	{
168
+		if (is_array($class)) {
169
+			foreach ($class as $elem) {
170
+				unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]);
171
+			}
172
+		} else {
173
+			unset($this->allowedMethods[strtolower($class)][strtolower($method)]);
174
+		}
175
+	}
176 176
 
177
-    /**
178
-     * returns the list of class methods allowed to run, note that the class names
179
-     * and method names are stored in the array keys and not values.
180
-     *
181
-     * @return array
182
-     */
183
-    public function getAllowedMethods()
184
-    {
185
-        return $this->allowedMethods;
186
-    }
177
+	/**
178
+	 * returns the list of class methods allowed to run, note that the class names
179
+	 * and method names are stored in the array keys and not values.
180
+	 *
181
+	 * @return array
182
+	 */
183
+	public function getAllowedMethods()
184
+	{
185
+		return $this->allowedMethods;
186
+	}
187 187
 
188
-    /**
189
-     * adds a directory to the safelist for includes and other file-access plugins.
190
-     *
191
-     * note that all the includePath directories you provide to the Dwoo_Template_File class
192
-     * are automatically marked as safe
193
-     *
194
-     * @param mixed $path a path name or an array of paths
195
-     */
196
-    public function allowDirectory($path)
197
-    {
198
-        if (is_array($path)) {
199
-            foreach ($path as $dir) {
200
-                $this->allowedDirectories[realpath($dir)] = true;
201
-            }
202
-        } else {
203
-            $this->allowedDirectories[realpath($path)] = true;
204
-        }
205
-    }
188
+	/**
189
+	 * adds a directory to the safelist for includes and other file-access plugins.
190
+	 *
191
+	 * note that all the includePath directories you provide to the Dwoo_Template_File class
192
+	 * are automatically marked as safe
193
+	 *
194
+	 * @param mixed $path a path name or an array of paths
195
+	 */
196
+	public function allowDirectory($path)
197
+	{
198
+		if (is_array($path)) {
199
+			foreach ($path as $dir) {
200
+				$this->allowedDirectories[realpath($dir)] = true;
201
+			}
202
+		} else {
203
+			$this->allowedDirectories[realpath($path)] = true;
204
+		}
205
+	}
206 206
 
207
-    /**
208
-     * removes a directory from the safelist.
209
-     *
210
-     * @param mixed $path a path name or an array of paths
211
-     */
212
-    public function disallowDirectory($path)
213
-    {
214
-        if (is_array($path)) {
215
-            foreach ($path as $dir) {
216
-                unset($this->allowedDirectories[realpath($dir)]);
217
-            }
218
-        } else {
219
-            unset($this->allowedDirectories[realpath($path)]);
220
-        }
221
-    }
207
+	/**
208
+	 * removes a directory from the safelist.
209
+	 *
210
+	 * @param mixed $path a path name or an array of paths
211
+	 */
212
+	public function disallowDirectory($path)
213
+	{
214
+		if (is_array($path)) {
215
+			foreach ($path as $dir) {
216
+				unset($this->allowedDirectories[realpath($dir)]);
217
+			}
218
+		} else {
219
+			unset($this->allowedDirectories[realpath($path)]);
220
+		}
221
+	}
222 222
 
223
-    /**
224
-     * returns the list of safe paths, note that the paths are stored in the array
225
-     * keys and not values.
226
-     *
227
-     * @return array
228
-     */
229
-    public function getAllowedDirectories()
230
-    {
231
-        return $this->allowedDirectories;
232
-    }
223
+	/**
224
+	 * returns the list of safe paths, note that the paths are stored in the array
225
+	 * keys and not values.
226
+	 *
227
+	 * @return array
228
+	 */
229
+	public function getAllowedDirectories()
230
+	{
231
+		return $this->allowedDirectories;
232
+	}
233 233
 
234
-    /**
235
-     * sets the php handling level, defaults to REMOVE.
236
-     *
237
-     * @param int $level one of the Dwoo_Security_Policy::PHP_* constants
238
-     */
239
-    public function setPhpHandling($level = self::PHP_REMOVE)
240
-    {
241
-        $this->phpHandling = $level;
242
-    }
234
+	/**
235
+	 * sets the php handling level, defaults to REMOVE.
236
+	 *
237
+	 * @param int $level one of the Dwoo_Security_Policy::PHP_* constants
238
+	 */
239
+	public function setPhpHandling($level = self::PHP_REMOVE)
240
+	{
241
+		$this->phpHandling = $level;
242
+	}
243 243
 
244
-    /**
245
-     * returns the php handling level.
246
-     *
247
-     * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
248
-     */
249
-    public function getPhpHandling()
250
-    {
251
-        return $this->phpHandling;
252
-    }
244
+	/**
245
+	 * returns the php handling level.
246
+	 *
247
+	 * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
248
+	 */
249
+	public function getPhpHandling()
250
+	{
251
+		return $this->phpHandling;
252
+	}
253 253
 
254
-    /**
255
-     * sets the constant handling level, defaults to CONST_DISALLOW.
256
-     *
257
-     * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
258
-     */
259
-    public function setConstantHandling($level = self::CONST_DISALLOW)
260
-    {
261
-        $this->constHandling = $level;
262
-    }
254
+	/**
255
+	 * sets the constant handling level, defaults to CONST_DISALLOW.
256
+	 *
257
+	 * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
258
+	 */
259
+	public function setConstantHandling($level = self::CONST_DISALLOW)
260
+	{
261
+		$this->constHandling = $level;
262
+	}
263 263
 
264
-    /**
265
-     * returns the constant handling level.
266
-     *
267
-     * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
268
-     */
269
-    public function getConstantHandling()
270
-    {
271
-        return $this->constHandling;
272
-    }
264
+	/**
265
+	 * returns the constant handling level.
266
+	 *
267
+	 * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
268
+	 */
269
+	public function getConstantHandling()
270
+	{
271
+		return $this->constHandling;
272
+	}
273 273
 
274
-    /**
275
-     * this is used at run time to check whether method calls are allowed or not.
276
-     *
277
-     * @param Dwoo_Core $dwoo   dwoo instance that calls this
278
-     * @param object    $obj    any object on which the method must be called
279
-     * @param string    $method lowercased method name
280
-     * @param array     $args   arguments array
281
-     *
282
-     * @return mixed result of method call or unll + E_USER_NOTICE if not allowed
283
-     */
284
-    public function callMethod(Dwoo_Core $dwoo, $obj, $method, $args)
285
-    {
286
-        foreach ($this->allowedMethods as $class => $methods) {
287
-            if (!isset($methods[$method])) {
288
-                continue;
289
-            }
290
-            if ($obj instanceof $class) {
291
-                return call_user_func_array(array($obj, $method), $args);
292
-            }
293
-        }
294
-        $dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()');
274
+	/**
275
+	 * this is used at run time to check whether method calls are allowed or not.
276
+	 *
277
+	 * @param Dwoo_Core $dwoo   dwoo instance that calls this
278
+	 * @param object    $obj    any object on which the method must be called
279
+	 * @param string    $method lowercased method name
280
+	 * @param array     $args   arguments array
281
+	 *
282
+	 * @return mixed result of method call or unll + E_USER_NOTICE if not allowed
283
+	 */
284
+	public function callMethod(Dwoo_Core $dwoo, $obj, $method, $args)
285
+	{
286
+		foreach ($this->allowedMethods as $class => $methods) {
287
+			if (!isset($methods[$method])) {
288
+				continue;
289
+			}
290
+			if ($obj instanceof $class) {
291
+				return call_user_func_array(array($obj, $method), $args);
292
+			}
293
+		}
294
+		$dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()');
295 295
 
296
-        return null;
297
-    }
296
+		return null;
297
+	}
298 298
 
299
-    /**
300
-     * this is used at compile time to check whether static method calls are allowed or not.
301
-     *
302
-     * @param mixed  $class  lowercased class name or array('class', 'method') couple
303
-     * @param string $method lowercased method name
304
-     *
305
-     * @return bool
306
-     */
307
-    public function isMethodAllowed($class, $method = null)
308
-    {
309
-        if (is_array($class)) {
310
-            list($class, $method) = $class;
311
-        }
312
-        foreach ($this->allowedMethods as $allowedClass => $methods) {
313
-            if (!isset($methods[$method])) {
314
-                continue;
315
-            }
316
-            if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) {
317
-                return true;
318
-            }
319
-        }
299
+	/**
300
+	 * this is used at compile time to check whether static method calls are allowed or not.
301
+	 *
302
+	 * @param mixed  $class  lowercased class name or array('class', 'method') couple
303
+	 * @param string $method lowercased method name
304
+	 *
305
+	 * @return bool
306
+	 */
307
+	public function isMethodAllowed($class, $method = null)
308
+	{
309
+		if (is_array($class)) {
310
+			list($class, $method) = $class;
311
+		}
312
+		foreach ($this->allowedMethods as $allowedClass => $methods) {
313
+			if (!isset($methods[$method])) {
314
+				continue;
315
+			}
316
+			if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) {
317
+				return true;
318
+			}
319
+		}
320 320
 
321
-        return false;
322
-    }
321
+		return false;
322
+	}
323 323
 }
Please login to merge, or discard this patch.
lib/Dwoo/ITemplate.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -19,140 +19,140 @@
 block discarded – undo
19 19
  */
20 20
 interface Dwoo_ITemplate
21 21
 {
22
-    /**
23
-     * returns the cache duration for this template.
24
-     *
25
-     * defaults to null if it was not provided
26
-     *
27
-     * @return int|null
28
-     */
29
-    public function getCacheTime();
22
+	/**
23
+	 * returns the cache duration for this template.
24
+	 *
25
+	 * defaults to null if it was not provided
26
+	 *
27
+	 * @return int|null
28
+	 */
29
+	public function getCacheTime();
30 30
 
31
-    /**
32
-     * sets the cache duration for this template.
33
-     *
34
-     * can be used to set it after the object is created if you did not provide
35
-     * it in the constructor
36
-     *
37
-     * @param int $seconds duration of the cache validity for this template, if
38
-     *                     null it defaults to the Dwoo instance's cache time. 0 = disable and
39
-     *                     -1 = infinite cache
40
-     */
41
-    public function setCacheTime($seconds = null);
31
+	/**
32
+	 * sets the cache duration for this template.
33
+	 *
34
+	 * can be used to set it after the object is created if you did not provide
35
+	 * it in the constructor
36
+	 *
37
+	 * @param int $seconds duration of the cache validity for this template, if
38
+	 *                     null it defaults to the Dwoo instance's cache time. 0 = disable and
39
+	 *                     -1 = infinite cache
40
+	 */
41
+	public function setCacheTime($seconds = null);
42 42
 
43
-    /**
44
-     * returns the cached template output file name, true if it's cache-able but not cached
45
-     * or false if it's not cached.
46
-     *
47
-     * @param Dwoo_Core $dwoo the dwoo instance that requests it
48
-     *
49
-     * @return string|bool
50
-     */
51
-    public function getCachedTemplate(Dwoo_Core $dwoo);
43
+	/**
44
+	 * returns the cached template output file name, true if it's cache-able but not cached
45
+	 * or false if it's not cached.
46
+	 *
47
+	 * @param Dwoo_Core $dwoo the dwoo instance that requests it
48
+	 *
49
+	 * @return string|bool
50
+	 */
51
+	public function getCachedTemplate(Dwoo_Core $dwoo);
52 52
 
53
-    /**
54
-     * caches the provided output into the cache file.
55
-     *
56
-     * @param Dwoo_Core $dwoo   the dwoo instance that requests it
57
-     * @param string    $output the template output
58
-     *
59
-     * @return mixed full path of the cached file or false upon failure
60
-     */
61
-    public function cache(Dwoo_Core $dwoo, $output);
53
+	/**
54
+	 * caches the provided output into the cache file.
55
+	 *
56
+	 * @param Dwoo_Core $dwoo   the dwoo instance that requests it
57
+	 * @param string    $output the template output
58
+	 *
59
+	 * @return mixed full path of the cached file or false upon failure
60
+	 */
61
+	public function cache(Dwoo_Core $dwoo, $output);
62 62
 
63
-    /**
64
-     * clears the cached template if it's older than the given time.
65
-     *
66
-     * @param Dwoo_Core $dwoo      the dwoo instance that was used to cache that template
67
-     * @param int       $olderThan minimum time (in seconds) required for the cache to be cleared
68
-     *
69
-     * @return bool true if the cache was not present or if it was deleted, false if it remains there
70
-     */
71
-    public function clearCache(Dwoo_Core $dwoo, $olderThan = -1);
63
+	/**
64
+	 * clears the cached template if it's older than the given time.
65
+	 *
66
+	 * @param Dwoo_Core $dwoo      the dwoo instance that was used to cache that template
67
+	 * @param int       $olderThan minimum time (in seconds) required for the cache to be cleared
68
+	 *
69
+	 * @return bool true if the cache was not present or if it was deleted, false if it remains there
70
+	 */
71
+	public function clearCache(Dwoo_Core $dwoo, $olderThan = -1);
72 72
 
73
-    /**
74
-     * returns the compiled template file name.
75
-     *
76
-     * @param Dwoo_Core      $dwoo     the dwoo instance that requests it
77
-     * @param Dwoo_ICompiler $compiler the compiler that must be used
78
-     *
79
-     * @return string
80
-     */
81
-    public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler = null);
73
+	/**
74
+	 * returns the compiled template file name.
75
+	 *
76
+	 * @param Dwoo_Core      $dwoo     the dwoo instance that requests it
77
+	 * @param Dwoo_ICompiler $compiler the compiler that must be used
78
+	 *
79
+	 * @return string
80
+	 */
81
+	public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler = null);
82 82
 
83
-    /**
84
-     * returns the template name.
85
-     *
86
-     * @return string
87
-     */
88
-    public function getName();
83
+	/**
84
+	 * returns the template name.
85
+	 *
86
+	 * @return string
87
+	 */
88
+	public function getName();
89 89
 
90
-    /**
91
-     * returns the resource name for this template class.
92
-     *
93
-     * @return string
94
-     */
95
-    public function getResourceName();
90
+	/**
91
+	 * returns the resource name for this template class.
92
+	 *
93
+	 * @return string
94
+	 */
95
+	public function getResourceName();
96 96
 
97
-    /**
98
-     * returns the resource identifier for this template or false if it has no identifier.
99
-     *
100
-     * @return string|false
101
-     */
102
-    public function getResourceIdentifier();
97
+	/**
98
+	 * returns the resource identifier for this template or false if it has no identifier.
99
+	 *
100
+	 * @return string|false
101
+	 */
102
+	public function getResourceIdentifier();
103 103
 
104
-    /**
105
-     * returns the template source of this template.
106
-     *
107
-     * @return string
108
-     */
109
-    public function getSource();
104
+	/**
105
+	 * returns the template source of this template.
106
+	 *
107
+	 * @return string
108
+	 */
109
+	public function getSource();
110 110
 
111
-    /**
112
-     * returns an unique string identifying the current version of this template,
113
-     * for example a timestamp of the last modified date or a hash of the template source.
114
-     *
115
-     * @return string
116
-     */
117
-    public function getUid();
111
+	/**
112
+	 * returns an unique string identifying the current version of this template,
113
+	 * for example a timestamp of the last modified date or a hash of the template source.
114
+	 *
115
+	 * @return string
116
+	 */
117
+	public function getUid();
118 118
 
119
-    /**
120
-     * returns the compiler used by this template, if it was just compiled, or null.
121
-     *
122
-     * @return Dwoo_ICompiler
123
-     */
124
-    public function getCompiler();
119
+	/**
120
+	 * returns the compiler used by this template, if it was just compiled, or null.
121
+	 *
122
+	 * @return Dwoo_ICompiler
123
+	 */
124
+	public function getCompiler();
125 125
 
126
-    /**
127
-     * returns some php code that will check if this template has been modified or not.
128
-     *
129
-     * if the function returns null, the template will be instanciated and then the Uid checked
130
-     *
131
-     * @return string
132
-     */
133
-    public function getIsModifiedCode();
126
+	/**
127
+	 * returns some php code that will check if this template has been modified or not.
128
+	 *
129
+	 * if the function returns null, the template will be instanciated and then the Uid checked
130
+	 *
131
+	 * @return string
132
+	 */
133
+	public function getIsModifiedCode();
134 134
 
135
-    /**
136
-     * returns a new template object from the given resource identifier, null if no include is
137
-     * possible (resource not found), or false if include is not permitted by this resource type.
138
-     *
139
-     * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the
140
-     * necessary permission checks if required, if the security policy prevents the template
141
-     * generation it should throw a new Dwoo_Security_Exception with a relevant message
142
-     *
143
-     * @param mixed          $resourceId     the resource identifier
144
-     * @param int            $cacheTime      duration of the cache validity for this template,
145
-     *                                       if null it defaults to the Dwoo instance that will
146
-     *                                       render this template
147
-     * @param string         $cacheId        the unique cache identifier of this page or anything else that
148
-     *                                       makes this template's content unique, if null it defaults
149
-     *                                       to the current url
150
-     * @param string         $compileId      the unique compiled identifier, which is used to distinguish this
151
-     *                                       template from others, if null it defaults to the filename+bits of the path
152
-     * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
153
-     *                                       an include, extends or any other plugin)
154
-     *
155
-     * @return Dwoo_ITemplate|null|false
156
-     */
157
-    public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null);
135
+	/**
136
+	 * returns a new template object from the given resource identifier, null if no include is
137
+	 * possible (resource not found), or false if include is not permitted by this resource type.
138
+	 *
139
+	 * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the
140
+	 * necessary permission checks if required, if the security policy prevents the template
141
+	 * generation it should throw a new Dwoo_Security_Exception with a relevant message
142
+	 *
143
+	 * @param mixed          $resourceId     the resource identifier
144
+	 * @param int            $cacheTime      duration of the cache validity for this template,
145
+	 *                                       if null it defaults to the Dwoo instance that will
146
+	 *                                       render this template
147
+	 * @param string         $cacheId        the unique cache identifier of this page or anything else that
148
+	 *                                       makes this template's content unique, if null it defaults
149
+	 *                                       to the current url
150
+	 * @param string         $compileId      the unique compiled identifier, which is used to distinguish this
151
+	 *                                       template from others, if null it defaults to the filename+bits of the path
152
+	 * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
153
+	 *                                       an include, extends or any other plugin)
154
+	 *
155
+	 * @return Dwoo_ITemplate|null|false
156
+	 */
157
+	public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null);
158 158
 }
Please login to merge, or discard this patch.
lib/Dwoo/Template/File.php 1 patch
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -19,267 +19,267 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Template_File extends Dwoo_Template_String
21 21
 {
22
-    /**
23
-     * template filename.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $file;
22
+	/**
23
+	 * template filename.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $file;
28 28
 
29
-    /**
30
-     * include path(s) to look into to find this template.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $includePath = null;
29
+	/**
30
+	 * include path(s) to look into to find this template.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $includePath = null;
35 35
 
36
-    /**
37
-     * resolved path cache when looking for a file in multiple include paths.
38
-     *
39
-     * this is reset when the include path is changed
40
-     *
41
-     * @var string
42
-     */
43
-    protected $resolvedPath = null;
36
+	/**
37
+	 * resolved path cache when looking for a file in multiple include paths.
38
+	 *
39
+	 * this is reset when the include path is changed
40
+	 *
41
+	 * @var string
42
+	 */
43
+	protected $resolvedPath = null;
44 44
 
45
-    /**
46
-     * creates a template from a file.
47
-     *
48
-     * @param string $file        the path to the template file, make sure it exists
49
-     * @param int    $cacheTime   duration of the cache validity for this template,
50
-     *                            if null it defaults to the Dwoo instance that will
51
-     *                            render this template
52
-     * @param string $cacheId     the unique cache identifier of this page or anything else that
53
-     *                            makes this template's content unique, if null it defaults
54
-     *                            to the current url
55
-     * @param string $compileId   the unique compiled identifier, which is used to distinguish this
56
-     *                            template from others, if null it defaults to the filename+bits of the path
57
-     * @param mixed  $includePath a string for a single path to look into for the given file, or an array of paths
58
-     */
59
-    public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = null)
60
-    {
61
-        $this->file = $file;
62
-        $this->name = basename($file);
63
-        $this->cacheTime = $cacheTime;
45
+	/**
46
+	 * creates a template from a file.
47
+	 *
48
+	 * @param string $file        the path to the template file, make sure it exists
49
+	 * @param int    $cacheTime   duration of the cache validity for this template,
50
+	 *                            if null it defaults to the Dwoo instance that will
51
+	 *                            render this template
52
+	 * @param string $cacheId     the unique cache identifier of this page or anything else that
53
+	 *                            makes this template's content unique, if null it defaults
54
+	 *                            to the current url
55
+	 * @param string $compileId   the unique compiled identifier, which is used to distinguish this
56
+	 *                            template from others, if null it defaults to the filename+bits of the path
57
+	 * @param mixed  $includePath a string for a single path to look into for the given file, or an array of paths
58
+	 */
59
+	public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = null)
60
+	{
61
+		$this->file = $file;
62
+		$this->name = basename($file);
63
+		$this->cacheTime = $cacheTime;
64 64
 
65
-        if ($compileId !== null) {
66
-            $this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
67
-        }
65
+		if ($compileId !== null) {
66
+			$this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
67
+		}
68 68
 
69
-        if ($cacheId !== null) {
70
-            $this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
71
-        }
69
+		if ($cacheId !== null) {
70
+			$this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
71
+		}
72 72
 
73
-        if (is_string($includePath)) {
74
-            $this->includePath = array($includePath);
75
-        } elseif (is_array($includePath)) {
76
-            $this->includePath = $includePath;
77
-        }
78
-    }
73
+		if (is_string($includePath)) {
74
+			$this->includePath = array($includePath);
75
+		} elseif (is_array($includePath)) {
76
+			$this->includePath = $includePath;
77
+		}
78
+	}
79 79
 
80
-    /**
81
-     * sets the include path(s) to where the given template filename must be looked up.
82
-     *
83
-     * @param mixed $paths the path to look into, can be string for a single path or an array of paths
84
-     */
85
-    public function setIncludePath($paths)
86
-    {
87
-        if (is_array($paths) === false) {
88
-            $paths = array($paths);
89
-        }
80
+	/**
81
+	 * sets the include path(s) to where the given template filename must be looked up.
82
+	 *
83
+	 * @param mixed $paths the path to look into, can be string for a single path or an array of paths
84
+	 */
85
+	public function setIncludePath($paths)
86
+	{
87
+		if (is_array($paths) === false) {
88
+			$paths = array($paths);
89
+		}
90 90
 
91
-        $this->includePath = $paths;
92
-        $this->resolvedPath = null;
93
-    }
91
+		$this->includePath = $paths;
92
+		$this->resolvedPath = null;
93
+	}
94 94
 
95
-    /**
96
-     * return the current include path(s).
97
-     *
98
-     * @return array
99
-     */
100
-    public function getIncludePath()
101
-    {
102
-        return $this->includePath;
103
-    }
95
+	/**
96
+	 * return the current include path(s).
97
+	 *
98
+	 * @return array
99
+	 */
100
+	public function getIncludePath()
101
+	{
102
+		return $this->includePath;
103
+	}
104 104
 
105
-    /**
106
-     * Checks if compiled file is valid (exists and it's the modification is greater or
107
-     * equal to the modification time of the template file).
108
-     *
109
-     * @param string file
110
-     *
111
-     * @return bool True cache file existance and it's modification time
112
-     */
113
-    protected function isValidCompiledFile($file)
114
-    {
115
-        return parent::isValidCompiledFile($file) && (int) $this->getUid() <= filemtime($file);
116
-    }
105
+	/**
106
+	 * Checks if compiled file is valid (exists and it's the modification is greater or
107
+	 * equal to the modification time of the template file).
108
+	 *
109
+	 * @param string file
110
+	 *
111
+	 * @return bool True cache file existance and it's modification time
112
+	 */
113
+	protected function isValidCompiledFile($file)
114
+	{
115
+		return parent::isValidCompiledFile($file) && (int) $this->getUid() <= filemtime($file);
116
+	}
117 117
 
118
-    /**
119
-     * returns the template source of this template.
120
-     *
121
-     * @return string
122
-     */
123
-    public function getSource()
124
-    {
125
-        return file_get_contents($this->getResourceIdentifier());
126
-    }
118
+	/**
119
+	 * returns the template source of this template.
120
+	 *
121
+	 * @return string
122
+	 */
123
+	public function getSource()
124
+	{
125
+		return file_get_contents($this->getResourceIdentifier());
126
+	}
127 127
 
128
-    /**
129
-     * returns the resource name for this template class.
130
-     *
131
-     * @return string
132
-     */
133
-    public function getResourceName()
134
-    {
135
-        return 'file';
136
-    }
128
+	/**
129
+	 * returns the resource name for this template class.
130
+	 *
131
+	 * @return string
132
+	 */
133
+	public function getResourceName()
134
+	{
135
+		return 'file';
136
+	}
137 137
 
138
-    /**
139
-     * returns this template's source filename.
140
-     *
141
-     * @return string
142
-     *
143
-     * @throws Dwoo_Exception
144
-     */
145
-    public function getResourceIdentifier()
146
-    {
147
-        if ($this->resolvedPath !== null) {
148
-            return $this->resolvedPath;
149
-        } elseif ($this->includePath === null) {
150
-            return $this->file;
151
-        } else {
152
-            foreach ($this->includePath as $path) {
153
-                $path = rtrim($path, DIRECTORY_SEPARATOR);
154
-                if (file_exists($path.DIRECTORY_SEPARATOR.$this->file) === true) {
155
-                    $this->resolvedPath = $path.DIRECTORY_SEPARATOR.$this->file;
138
+	/**
139
+	 * returns this template's source filename.
140
+	 *
141
+	 * @return string
142
+	 *
143
+	 * @throws Dwoo_Exception
144
+	 */
145
+	public function getResourceIdentifier()
146
+	{
147
+		if ($this->resolvedPath !== null) {
148
+			return $this->resolvedPath;
149
+		} elseif ($this->includePath === null) {
150
+			return $this->file;
151
+		} else {
152
+			foreach ($this->includePath as $path) {
153
+				$path = rtrim($path, DIRECTORY_SEPARATOR);
154
+				if (file_exists($path.DIRECTORY_SEPARATOR.$this->file) === true) {
155
+					$this->resolvedPath = $path.DIRECTORY_SEPARATOR.$this->file;
156 156
 
157
-                    return $this->resolvedPath;
158
-                }
159
-            }
157
+					return $this->resolvedPath;
158
+				}
159
+			}
160 160
 
161
-            throw new Dwoo_Exception('Template "'.$this->file.'" could not be found in any of your include path(s)');
162
-        }
163
-    }
161
+			throw new Dwoo_Exception('Template "'.$this->file.'" could not be found in any of your include path(s)');
162
+		}
163
+	}
164 164
 
165
-    /**
166
-     * returns an unique value identifying the current version of this template,
167
-     * in this case it's the unix timestamp of the last modification.
168
-     *
169
-     * @return string
170
-     */
171
-    public function getUid()
172
-    {
173
-        return (string) filemtime($this->getResourceIdentifier());
174
-    }
165
+	/**
166
+	 * returns an unique value identifying the current version of this template,
167
+	 * in this case it's the unix timestamp of the last modification.
168
+	 *
169
+	 * @return string
170
+	 */
171
+	public function getUid()
172
+	{
173
+		return (string) filemtime($this->getResourceIdentifier());
174
+	}
175 175
 
176
-    /**
177
-     * returns a new template object from the given include name, null if no include is
178
-     * possible (resource not found), or false if include is not permitted by this resource type.
179
-     *
180
-     * @param Dwoo_Core      $dwoo           the dwoo instance requiring it
181
-     * @param mixed          $resourceId     the filename (relative to this template's dir) of the template to include
182
-     * @param int            $cacheTime      duration of the cache validity for this template,
183
-     *                                       if null it defaults to the Dwoo instance that will
184
-     *                                       render this template
185
-     * @param string         $cacheId        the unique cache identifier of this page or anything else that
186
-     *                                       makes this template's content unique, if null it defaults
187
-     *                                       to the current url
188
-     * @param string         $compileId      the unique compiled identifier, which is used to distinguish this
189
-     *                                       template from others, if null it defaults to the filename+bits of the path
190
-     * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
191
-     *                                       an include, extends or any other plugin)
192
-     *
193
-     * @return Dwoo_Template_File|null
194
-     *
195
-     * @throws Dwoo_Exception
196
-     * @throws Dwoo_Security_Exception
197
-     */
198
-    public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
199
-    {
200
-        if (DIRECTORY_SEPARATOR === '\\') {
201
-            $resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array('\\t', '\\n', '\\r', '\\f', '\\v'), $resourceId);
202
-        }
203
-        $resourceId = strtr($resourceId, '\\', '/');
176
+	/**
177
+	 * returns a new template object from the given include name, null if no include is
178
+	 * possible (resource not found), or false if include is not permitted by this resource type.
179
+	 *
180
+	 * @param Dwoo_Core      $dwoo           the dwoo instance requiring it
181
+	 * @param mixed          $resourceId     the filename (relative to this template's dir) of the template to include
182
+	 * @param int            $cacheTime      duration of the cache validity for this template,
183
+	 *                                       if null it defaults to the Dwoo instance that will
184
+	 *                                       render this template
185
+	 * @param string         $cacheId        the unique cache identifier of this page or anything else that
186
+	 *                                       makes this template's content unique, if null it defaults
187
+	 *                                       to the current url
188
+	 * @param string         $compileId      the unique compiled identifier, which is used to distinguish this
189
+	 *                                       template from others, if null it defaults to the filename+bits of the path
190
+	 * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
191
+	 *                                       an include, extends or any other plugin)
192
+	 *
193
+	 * @return Dwoo_Template_File|null
194
+	 *
195
+	 * @throws Dwoo_Exception
196
+	 * @throws Dwoo_Security_Exception
197
+	 */
198
+	public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
199
+	{
200
+		if (DIRECTORY_SEPARATOR === '\\') {
201
+			$resourceId = str_replace(array("\t", "\n", "\r", "\f", "\v"), array('\\t', '\\n', '\\r', '\\f', '\\v'), $resourceId);
202
+		}
203
+		$resourceId = strtr($resourceId, '\\', '/');
204 204
 
205
-        $includePath = null;
205
+		$includePath = null;
206 206
 
207
-        if (file_exists($resourceId) === false) {
208
-            if ($parentTemplate === null) {
209
-                $parentTemplate = $dwoo->getTemplate();
210
-            }
211
-            if ($parentTemplate instanceof self) {
212
-                if ($includePath = $parentTemplate->getIncludePath()) {
213
-                    if (strstr($resourceId, '../')) {
214
-                        throw new Dwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');
215
-                    }
216
-                } else {
217
-                    $resourceId = dirname($parentTemplate->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;
218
-                    if (file_exists($resourceId) === false) {
219
-                        return null;
220
-                    }
221
-                }
222
-            } else {
223
-                return null;
224
-            }
225
-        }
207
+		if (file_exists($resourceId) === false) {
208
+			if ($parentTemplate === null) {
209
+				$parentTemplate = $dwoo->getTemplate();
210
+			}
211
+			if ($parentTemplate instanceof self) {
212
+				if ($includePath = $parentTemplate->getIncludePath()) {
213
+					if (strstr($resourceId, '../')) {
214
+						throw new Dwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');
215
+					}
216
+				} else {
217
+					$resourceId = dirname($parentTemplate->getResourceIdentifier()).DIRECTORY_SEPARATOR.$resourceId;
218
+					if (file_exists($resourceId) === false) {
219
+						return null;
220
+					}
221
+				}
222
+			} else {
223
+				return null;
224
+			}
225
+		}
226 226
 
227
-        if ($policy = $dwoo->getSecurityPolicy()) {
228
-            while (true) {
229
-                if (preg_match('{^([a-z]+?)://}i', $resourceId)) {
230
-                    throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$resourceId.'</em>.');
231
-                }
227
+		if ($policy = $dwoo->getSecurityPolicy()) {
228
+			while (true) {
229
+				if (preg_match('{^([a-z]+?)://}i', $resourceId)) {
230
+					throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$resourceId.'</em>.');
231
+				}
232 232
 
233
-                if ($includePath) {
234
-                    break;
235
-                }
233
+				if ($includePath) {
234
+					break;
235
+				}
236 236
 
237
-                $resourceId = realpath($resourceId);
238
-                $dirs = $policy->getAllowedDirectories();
239
-                foreach ($dirs as $dir => $dummy) {
240
-                    if (strpos($resourceId, $dir) === 0) {
241
-                        break 2;
242
-                    }
243
-                }
244
-                throw new Dwoo_Security_Exception('The security policy prevents you to read <em>'.$resourceId.'</em>');
245
-            }
246
-        }
237
+				$resourceId = realpath($resourceId);
238
+				$dirs = $policy->getAllowedDirectories();
239
+				foreach ($dirs as $dir => $dummy) {
240
+					if (strpos($resourceId, $dir) === 0) {
241
+						break 2;
242
+					}
243
+				}
244
+				throw new Dwoo_Security_Exception('The security policy prevents you to read <em>'.$resourceId.'</em>');
245
+			}
246
+		}
247 247
 
248
-        $class = 'Dwoo_Template_File';
249
-        if ($parentTemplate) {
250
-            $class = get_class($parentTemplate);
251
-        }
248
+		$class = 'Dwoo_Template_File';
249
+		if ($parentTemplate) {
250
+			$class = get_class($parentTemplate);
251
+		}
252 252
 
253
-        return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath);
254
-    }
253
+		return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath);
254
+	}
255 255
 
256
-    /**
257
-     * returns the full compiled file name and assigns a default value to it if
258
-     * required.
259
-     *
260
-     * @param Dwoo_Core $dwoo the dwoo instance that requests the file name
261
-     *
262
-     * @return string the full path to the compiled file
263
-     */
264
-    protected function getCompiledFilename(Dwoo_Core $dwoo)
265
-    {
266
-        // no compile id was provided, set default
267
-        if ($this->compileId === null) {
268
-            $this->compileId = str_replace('../', '__', strtr($this->getResourceIdentifier(), '\\:', '/-'));
269
-        }
256
+	/**
257
+	 * returns the full compiled file name and assigns a default value to it if
258
+	 * required.
259
+	 *
260
+	 * @param Dwoo_Core $dwoo the dwoo instance that requests the file name
261
+	 *
262
+	 * @return string the full path to the compiled file
263
+	 */
264
+	protected function getCompiledFilename(Dwoo_Core $dwoo)
265
+	{
266
+		// no compile id was provided, set default
267
+		if ($this->compileId === null) {
268
+			$this->compileId = str_replace('../', '__', strtr($this->getResourceIdentifier(), '\\:', '/-'));
269
+		}
270 270
 
271
-        return $dwoo->getCompileDir().$this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
272
-    }
271
+		return $dwoo->getCompileDir().$this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
272
+	}
273 273
 
274
-    /**
275
-     * returns some php code that will check if this template has been modified or not.
276
-     *
277
-     * if the function returns null, the template will be instanciated and then the Uid checked
278
-     *
279
-     * @return string
280
-     */
281
-    public function getIsModifiedCode()
282
-    {
283
-        return '"'.$this->getUid().'" == filemtime('.var_export($this->getResourceIdentifier(), true).')';
284
-    }
274
+	/**
275
+	 * returns some php code that will check if this template has been modified or not.
276
+	 *
277
+	 * if the function returns null, the template will be instanciated and then the Uid checked
278
+	 *
279
+	 * @return string
280
+	 */
281
+	public function getIsModifiedCode()
282
+	{
283
+		return '"'.$this->getUid().'" == filemtime('.var_export($this->getResourceIdentifier(), true).')';
284
+	}
285 285
 }
Please login to merge, or discard this patch.
lib/Dwoo/Core.php 4 patches
Indentation   +1705 added lines, -1705 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!defined('DWOO_DIRECTORY')) {
4
-    define('DWOO_DIRECTORY', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
4
+	define('DWOO_DIRECTORY', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
5 5
 }
6 6
 
7 7
 /**
@@ -32,1708 +32,1708 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Dwoo_Core
34 34
 {
35
-    /**
36
-     * Current version number.
37
-     *
38
-     * @var string
39
-     */
40
-    const VERSION = '1.2.3';
41
-
42
-    /**
43
-     * Unique number of this dwoo release.
44
-     * this can be used by templates classes to check whether the compiled template
45
-     * has been compiled before this release or not, so that old templates are
46
-     * recompiled automatically when Dwoo is updated
47
-     */
48
-    const RELEASE_TAG = 17;
49
-
50
-    /**
51
-     * Constants that represents all plugin types
52
-     * these are bitwise-operation-safe values to allow multiple types
53
-     * on a single plugin
54
-     *
55
-     * @var int
56
-     */
57
-    const CLASS_PLUGIN      = 1;
58
-    const FUNC_PLUGIN       = 2;
59
-    const NATIVE_PLUGIN     = 4;
60
-    const BLOCK_PLUGIN      = 8;
61
-    const COMPILABLE_PLUGIN = 16;
62
-    const CUSTOM_PLUGIN     = 32;
63
-    const SMARTY_MODIFIER   = 64;
64
-    const SMARTY_BLOCK      = 128;
65
-    const SMARTY_FUNCTION   = 256;
66
-    const PROXY_PLUGIN      = 512;
67
-    const TEMPLATE_PLUGIN   = 1024;
68
-
69
-    /**
70
-     * Character set of the template, used by string manipulation plugins.
71
-     * it must be lowercase, but setCharset() will take care of that
72
-     *
73
-     * @see setCharset
74
-     * @see getCharset
75
-     * @var string
76
-     */
77
-    protected $charset = 'utf-8';
78
-
79
-    /**
80
-     * Global variables that are accessible through $dwoo.* in the templates.
81
-     * default values include:
82
-     * $dwoo.version - current version number
83
-     * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org
84
-     * $dwoo.now - the current time
85
-     * $dwoo.template - the current template filename
86
-     * $dwoo.charset - the character set used by the template
87
-     * on top of that, foreach and other plugins can store special values in there,
88
-     * see their documentation for more details.
89
-     *
90
-     * @var array
91
-     */
92
-    public $globals;
93
-
94
-    /**
95
-     * Directory where the compiled templates are stored.
96
-     * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)
97
-     *
98
-     * @var string
99
-     */
100
-    protected $compileDir;
101
-
102
-    /**
103
-     * Directory where the cached templates are stored.
104
-     * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)
105
-     *
106
-     * @var string
107
-     */
108
-    protected $cacheDir;
109
-
110
-    /**
111
-     * Defines how long (in seconds) the cached files must remain valid.
112
-     * can be overriden on a per-template basis
113
-     * -1 = never delete
114
-     * 0 = disabled
115
-     * >0 = duration in seconds
116
-     *
117
-     * @var int
118
-     */
119
-    protected $cacheTime = 0;
120
-
121
-    /**
122
-     * Security policy object.
123
-     *
124
-     * @var Dwoo_Security_Policy
125
-     */
126
-    protected $securityPolicy = null;
127
-
128
-    /**
129
-     * Stores the custom plugins callbacks.
130
-     *
131
-     * @see addPlugin
132
-     * @see removePlugin
133
-     * @var array
134
-     */
135
-    protected $plugins = array();
136
-
137
-    /**
138
-     * Stores the filter callbacks.
139
-     *
140
-     * @see addFilter
141
-     * @see removeFilter
142
-     * @var array
143
-     */
144
-    protected $filters = array();
145
-
146
-    /**
147
-     * Stores the resource types and associated
148
-     * classes / compiler classes.
149
-     *
150
-     * @var array
151
-     */
152
-    protected $resources = array(
153
-        'file'   => array(
154
-            'class'    => 'Dwoo_Template_File',
155
-            'compiler' => null,
156
-        ),
157
-        'string' => array(
158
-            'class'    => 'Dwoo_Template_String',
159
-            'compiler' => null,
160
-        ),
161
-    );
162
-
163
-    /**
164
-     * The dwoo loader object used to load plugins by this dwoo instance.
165
-     *
166
-     * @var Dwoo_ILoader
167
-     */
168
-    protected $loader = null;
169
-
170
-    /**
171
-     * Currently rendered template, set to null when not-rendering.
172
-     *
173
-     * @var Dwoo_ITemplate
174
-     */
175
-    protected $template = null;
176
-
177
-    /**
178
-     * Stores the instances of the class plugins during template runtime.
179
-     *
180
-     * @var array
181
-     */
182
-    protected $runtimePlugins;
183
-
184
-    /**
185
-     * Stores the returned values during template runtime.
186
-     *
187
-     * @var array
188
-     */
189
-    protected $returnData;
190
-
191
-    /**
192
-     * Stores the data during template runtime.
193
-     *
194
-     * @var array
195
-     */
196
-    public $data;
197
-
198
-    /**
199
-     * Stores the current scope during template runtime.
200
-     * this should ideally not be accessed directly from outside template code
201
-     *
202
-     * @var mixed
203
-     */
204
-    public $scope;
205
-
206
-    /**
207
-     * Stores the scope tree during template runtime.
208
-     *
209
-     * @var array
210
-     */
211
-    protected $scopeTree;
212
-
213
-    /**
214
-     * Stores the block plugins stack during template runtime.
215
-     *
216
-     * @var array
217
-     */
218
-    protected $stack;
219
-
220
-    /**
221
-     * Stores the current block plugin at the top of the stack during template runtime.
222
-     *
223
-     * @var Dwoo_Block_Plugin
224
-     */
225
-    protected $curBlock;
226
-
227
-    /**
228
-     * Stores the output buffer during template runtime.
229
-     *
230
-     * @var string
231
-     */
232
-    protected $buffer;
233
-
234
-    /**
235
-     * Stores plugin proxy.
236
-     *
237
-     * @var Dwoo_IPluginProxy
238
-     */
239
-    protected $pluginProxy;
240
-
241
-    /**
242
-     * Constructor, sets the cache and compile dir to the default values if not provided.
243
-     *
244
-     * @param string $compileDir path to the compiled directory, defaults to lib/compiled
245
-     * @param string $cacheDir   path to the cache directory, defaults to lib/cache
246
-     */
247
-    public function __construct($compileDir = null, $cacheDir = null)
248
-    {
249
-        if ($compileDir !== null) {
250
-            $this->setCompileDir($compileDir);
251
-        }
252
-        if ($cacheDir !== null) {
253
-            $this->setCacheDir($cacheDir);
254
-        }
255
-        $this->initGlobals();
256
-    }
257
-
258
-    /**
259
-     * Resets some runtime variables to allow a cloned object to be used to render sub-templates.
260
-     *
261
-     * @return void
262
-     */
263
-    public function __clone()
264
-    {
265
-        $this->template = null;
266
-        unset($this->data);
267
-        unset($this->returnData);
268
-    }
269
-
270
-    /**
271
-     * Autputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true).
272
-     *
273
-     * @param mixed          $tpl      template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a
274
-     *                                 valid path to a template, or a template as a string it is recommended to provide
275
-     *                                 a Dwoo_ITemplate as it will probably make things faster, especially if you
276
-     *                                 render a template multiple times
277
-     * @param mixed          $data     the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or
278
-     *                                 an associative array. if you're rendering the template from cache, it can be
279
-     *                                 left null
280
-     * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default
281
-     *                                 Dwoo_Compiler will be used
282
-     *
283
-     * @return     string nothing or the template output if $output is true
284
-     * @deprecated 1.2.3. will be deleted in 1.3.0
285
-     */
286
-    public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null)
287
-    {
288
-        return $this->get($tpl, $data, $compiler, true);
289
-    }
290
-
291
-    /**
292
-     * Returns the given template rendered using the provided data and optional compiler.
293
-     *
294
-     * @param mixed          $_tpl      template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a
295
-     *                                  valid path to a template, or a template as a string it is recommended to
296
-     *                                  provide a Dwoo_ITemplate as it will probably make things faster, especially if
297
-     *                                  you render a template multiple times
298
-     * @param mixed          $data      the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or
299
-     *                                  an associative array. if you're rendering the template from cache, it can be
300
-     *                                  left null
301
-     * @param Dwoo_ICompiler $_compiler the compiler that must be used to compile the template, if left empty a default
302
-     *                                  Dwoo_Compiler will be used
303
-     * @param bool           $_output   flag that defines whether the function returns the output of the template
304
-     *                                  (false, default) or echoes it directly (true)
305
-     *
306
-     * @return string|void or the template output if $output is false
307
-     * @throws Dwoo_Exception
308
-     */
309
-    public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
310
-    {
311
-        // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one
312
-        if ($this->template instanceof Dwoo_ITemplate) {
313
-            $clone = clone $this;
314
-
315
-            return $clone->get($_tpl, $data, $_compiler, $_output);
316
-        }
317
-
318
-        // auto-create template if required
319
-        if ($_tpl instanceof Dwoo_ITemplate) {
320
-            // valid, skip
321
-        } elseif (is_string($_tpl) && file_exists($_tpl)) {
322
-            $_tpl = new Dwoo_Template_File($_tpl);
323
-        } else {
324
-            throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE);
325
-        }
326
-
327
-        // save the current template, enters render mode at the same time
328
-        // if another rendering is requested it will be proxied to a new Dwoo_Core(instance
329
-        $this->template = $_tpl;
330
-
331
-        // load data
332
-        if ($data instanceof Dwoo_IDataProvider) {
333
-            $this->data = $data->getData();
334
-        } elseif (is_array($data)) {
335
-            $this->data = $data;
336
-        } elseif ($data instanceof ArrayAccess) {
337
-            $this->data = $data;
338
-        } else {
339
-            throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE);
340
-        }
341
-
342
-        $this->globals['template'] = $_tpl->getName();
343
-        $this->initRuntimeVars($_tpl);
344
-
345
-        // try to get cached template
346
-        $file        = $_tpl->getCachedTemplate($this);
347
-        $doCache     = $file === true;
348
-        $cacheLoaded = is_string($file);
349
-
350
-        if ($cacheLoaded === true) {
351
-            // cache is present, run it
352
-            if ($_output === true) {
353
-                include $file;
354
-                $this->template = null;
355
-            } else {
356
-                ob_start();
357
-                include $file;
358
-                $this->template = null;
359
-
360
-                return ob_get_clean();
361
-            }
362
-        } else {
363
-            $dynamicId = uniqid();
364
-
365
-            // render template
366
-            $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
367
-            $out              = include $compiledTemplate;
368
-
369
-            // template returned false so it needs to be recompiled
370
-            if ($out === false) {
371
-                $_tpl->forceCompilation();
372
-                $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
373
-                $out              = include $compiledTemplate;
374
-            }
375
-
376
-            if ($doCache === true) {
377
-                $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*' . $dynamicId . '*/ echo \'$1\'; ?>', $out);
378
-                if (!class_exists('Dwoo_plugin_dynamic')) {
379
-                    $this->getLoader()->loadPlugin('dynamic');
380
-                }
381
-                $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate);
382
-            }
383
-
384
-            // process filters
385
-            foreach ($this->filters as $filter) {
386
-                if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) {
387
-                    $out = call_user_func($filter, $out);
388
-                } else {
389
-                    $out = call_user_func($filter, $this, $out);
390
-                }
391
-            }
392
-
393
-            if ($doCache === true) {
394
-                // building cache
395
-                $file = $_tpl->cache($this, $out);
396
-
397
-                // run it from the cache to be sure dynamics are rendered
398
-                if ($_output === true) {
399
-                    include $file;
400
-                    // exit render mode
401
-                    $this->template = null;
402
-                } else {
403
-                    ob_start();
404
-                    include $file;
405
-                    // exit render mode
406
-                    $this->template = null;
407
-
408
-                    return ob_get_clean();
409
-                }
410
-            } else {
411
-                // no need to build cache
412
-                // exit render mode
413
-                $this->template = null;
414
-                // output
415
-                if ($_output === true) {
416
-                    echo $out;
417
-                }
418
-
419
-                return $out;
420
-            }
421
-        }
422
-
423
-        return '';
424
-    }
425
-
426
-    /**
427
-     * Re-initializes the globals array before each template run.
428
-     * this method is only callede once when the Dwoo object is created
429
-     *
430
-     * @return void
431
-     */
432
-    protected function initGlobals()
433
-    {
434
-        $this->globals = array(
435
-            'version' => self::VERSION,
436
-            'ad'      => '<a href="http://dwoo.org/">Powered by Dwoo</a>',
437
-            'now'     => $_SERVER['REQUEST_TIME'],
438
-            'charset' => $this->charset,
439
-        );
440
-    }
441
-
442
-    /**
443
-     * Re-initializes the runtime variables before each template run.
444
-     * override this method to inject data in the globals array if needed, this
445
-     * method is called before each template execution
446
-     *
447
-     * @param Dwoo_ITemplate $tpl the template that is going to be rendered
448
-     *
449
-     * @return void
450
-     */
451
-    protected function initRuntimeVars(Dwoo_ITemplate $tpl)
452
-    {
453
-        $this->runtimePlugins = array();
454
-        $this->scope          = &$this->data;
455
-        $this->scopeTree      = array();
456
-        $this->stack          = array();
457
-        $this->curBlock       = null;
458
-        $this->buffer         = '';
459
-        $this->returnData     = array();
460
-    }
461
-
462
-    /**
463
-     * Adds a custom plugin that is not in one of the plugin directories.
464
-     *
465
-     * @param string   $name       the plugin name to be used in the templates
466
-     * @param callback $callback   the plugin callback, either a function name,
467
-     *                             a class name or an array containing an object
468
-     *                             or class name and a method name
469
-     * @param bool     $compilable if set to true, the plugin is assumed to be compilable
470
-     *
471
-     * @return void
472
-     * @throws Dwoo_Exception
473
-     */
474
-    public function addPlugin($name, $callback, $compilable = false)
475
-    {
476
-        $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0;
477
-        if (is_array($callback)) {
478
-            if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) {
479
-                $this->plugins[$name] = array(
480
-                    'type'     => self::BLOCK_PLUGIN | $compilable,
481
-                    'callback' => $callback,
482
-                    'class'    => (is_object($callback[0]) ? get_class($callback[0]) : $callback[0])
483
-                );
484
-            } else {
485
-                $this->plugins[$name] = array(
486
-                    'type'     => self::CLASS_PLUGIN | $compilable,
487
-                    'callback' => $callback,
488
-                    'class'    => (is_object($callback[0]) ? get_class($callback[0]) : $callback[0]),
489
-                    'function' => $callback[1]
490
-                );
491
-            }
492
-        } elseif (is_string($callback)) {
493
-            if (class_exists($callback)) {
494
-                if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) {
495
-                    $this->plugins[$name] = array(
496
-                        'type'     => self::BLOCK_PLUGIN | $compilable,
497
-                        'callback' => $callback,
498
-                        'class'    => $callback
499
-                    );
500
-                } else {
501
-                    $this->plugins[$name] = array(
502
-                        'type'     => self::CLASS_PLUGIN | $compilable,
503
-                        'callback' => $callback,
504
-                        'class'    => $callback,
505
-                        'function' => ($compilable ? 'compile' : 'process')
506
-                    );
507
-                }
508
-            } elseif (function_exists($callback)) {
509
-                $this->plugins[$name] = array(
510
-                    'type'     => self::FUNC_PLUGIN | $compilable,
511
-                    'callback' => $callback
512
-                );
513
-            } else {
514
-                throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
515
-            }
516
-        } elseif ($callback instanceof \Closure) {
517
-            $this->plugins[$name] = array(
518
-                'type'     => self::FUNC_PLUGIN | $compilable,
519
-                'callback' => $callback
520
-            );
521
-        } else {
522
-            throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
523
-        }
524
-    }
525
-
526
-    /**
527
-     * Removes a custom plugin.
528
-     *
529
-     * @param string $name the plugin name
530
-     *
531
-     * @return void
532
-     */
533
-    public function removePlugin($name)
534
-    {
535
-        if (isset($this->plugins[$name])) {
536
-            unset($this->plugins[$name]);
537
-        }
538
-    }
539
-
540
-    /**
541
-     * Adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this
542
-     * instance.
543
-     *
544
-     * @param mixed $callback a callback or a filter name if it is autoloaded from a plugin directory
545
-     * @param bool  $autoload if true, the first parameter must be a filter name from one of the plugin directories
546
-     *
547
-     * @return void
548
-     * @throws Dwoo_Exception
549
-     */
550
-    public function addFilter($callback, $autoload = false)
551
-    {
552
-        if ($autoload) {
553
-            $class = 'Dwoo_Filter_' . $callback;
554
-
555
-            if (!class_exists($class) && !function_exists($class)) {
556
-                try {
557
-                    $this->getLoader()->loadPlugin($callback);
558
-                }
559
-                catch (Dwoo_Exception $e) {
560
-                    if (strstr($callback, 'Dwoo_Filter_')) {
561
-                        throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', the "Dwoo_Filter_" prefix should not be used, please only use "' . str_replace('Dwoo_Filter_', '', $callback) . '"');
562
-                    } else {
563
-                        throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
564
-                    }
565
-                }
566
-            }
567
-
568
-            if (class_exists($class)) {
569
-                $callback = array(
570
-                    new $class($this),
571
-                    'process'
572
-                );
573
-            } elseif (function_exists($class)) {
574
-                $callback = $class;
575
-            } else {
576
-                throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
577
-            }
578
-
579
-            $this->filters[] = $callback;
580
-        } else {
581
-            $this->filters[] = $callback;
582
-        }
583
-    }
584
-
585
-    /**
586
-     * Removes a filter.
587
-     *
588
-     * @param mixed $callback callback or filter name if it was autoloaded
589
-     *
590
-     * @return void
591
-     */
592
-    public function removeFilter($callback)
593
-    {
594
-        if (($index = array_search('Dwoo_Filter_' . $callback, $this->filters, true)) !== false) {
595
-            unset($this->filters[$index]);
596
-        } elseif (($index = array_search($callback, $this->filters, true)) !== false) {
597
-            unset($this->filters[$index]);
598
-        } else {
599
-            $class = 'Dwoo_Filter_' . $callback;
600
-            foreach ($this->filters as $index => $filter) {
601
-                if (is_array($filter) && $filter[0] instanceof $class) {
602
-                    unset($this->filters[$index]);
603
-                    break;
604
-                }
605
-            }
606
-        }
607
-    }
608
-
609
-    /**
610
-     * Adds a resource or overrides a default one.
611
-     *
612
-     * @param string   $name            the resource name
613
-     * @param string   $class           the resource class (which must implement Dwoo_ITemplate)
614
-     * @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance
615
-     *                                  used to compile this resource, if none is provided. by default it will produce
616
-     *                                  a Dwoo_Compiler object
617
-     *
618
-     * @return void
619
-     * @throws Dwoo_Exception
620
-     */
621
-    public function addResource($name, $class, $compilerFactory = null)
622
-    {
623
-        if (strlen($name) < 2) {
624
-            throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');
625
-        }
626
-
627
-        if (!class_exists($class)) {
628
-            throw new Dwoo_Exception('Resource class does not exist');
629
-        }
630
-
631
-        $interfaces = class_implements($class);
632
-        if (in_array('Dwoo_ITemplate', $interfaces) === false) {
633
-            throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate');
634
-        }
635
-
636
-        $this->resources[$name] = array(
637
-            'class'    => $class,
638
-            'compiler' => $compilerFactory
639
-        );
640
-    }
641
-
642
-    /**
643
-     * Removes a custom resource.
644
-     *
645
-     * @param string $name the resource name
646
-     *
647
-     * @return void
648
-     */
649
-    public function removeResource($name)
650
-    {
651
-        unset($this->resources[$name]);
652
-        if ($name === 'file') {
653
-            $this->resources['file'] = array(
654
-                'class'    => 'Dwoo_Template_File',
655
-                'compiler' => null
656
-            );
657
-        }
658
-    }
659
-
660
-    /**
661
-     * Sets the loader object to use to load plugins.
662
-     *
663
-     * @param Dwoo_ILoader $loader loader
664
-     *
665
-     * @return void
666
-     */
667
-    public function setLoader(Dwoo_ILoader $loader)
668
-    {
669
-        $this->loader = $loader;
670
-    }
671
-
672
-    /**
673
-     * Returns the current loader object or a default one if none is currently found.
674
-     *
675
-     * @return Dwoo_ILoader|Dwoo_Loader
676
-     */
677
-    public function getLoader()
678
-    {
679
-        if ($this->loader === null) {
680
-            $this->loader = new Dwoo_Loader($this->getCompileDir());
681
-        }
682
-
683
-        return $this->loader;
684
-    }
685
-
686
-    /**
687
-     * Returns the custom plugins loaded.
688
-     * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance
689
-     *
690
-     * @return array
691
-     */
692
-    public function getCustomPlugins()
693
-    {
694
-        return $this->plugins;
695
-    }
696
-
697
-    /**
698
-     * Returns the cache directory with a trailing DIRECTORY_SEPARATOR.
699
-     *
700
-     * @return string
701
-     */
702
-    public function getCacheDir()
703
-    {
704
-        if ($this->cacheDir === null) {
705
-            $this->setCacheDir(DWOO_DIRECTORY . 'cache' . DIRECTORY_SEPARATOR);
706
-        }
707
-
708
-        return $this->cacheDir;
709
-    }
710
-
711
-    /**
712
-     * Sets the cache directory and automatically appends a DIRECTORY_SEPARATOR.
713
-     *
714
-     * @param string $dir the cache directory
715
-     *
716
-     * @return void
717
-     * @throws Dwoo_Exception
718
-     */
719
-    public function setCacheDir($dir)
720
-    {
721
-        $this->cacheDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
722
-        if (is_writable($this->cacheDir) === false) {
723
-            throw new Dwoo_Exception('The cache directory must be writable, chmod "' . $this->cacheDir . '" to make it writable');
724
-        }
725
-    }
726
-
727
-    /**
728
-     * Returns the compile directory with a trailing DIRECTORY_SEPARATOR.
729
-     *
730
-     * @return string
731
-     */
732
-    public function getCompileDir()
733
-    {
734
-        if ($this->compileDir === null) {
735
-            $this->setCompileDir(DWOO_DIRECTORY . 'compiled' . DIRECTORY_SEPARATOR);
736
-        }
737
-
738
-        return $this->compileDir;
739
-    }
740
-
741
-    /**
742
-     * Sets the compile directory and automatically appends a DIRECTORY_SEPARATOR.
743
-     *
744
-     * @param string $dir the compile directory
745
-     *
746
-     * @return void
747
-     * @throws Dwoo_Exception
748
-     */
749
-    public function setCompileDir($dir)
750
-    {
751
-        $this->compileDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
752
-        if (is_writable($this->compileDir) === false) {
753
-            throw new Dwoo_Exception('The compile directory must be writable, chmod "' . $this->compileDir . '" to make it writable');
754
-        }
755
-    }
756
-
757
-    /**
758
-     * Returns the default cache time that is used with templates that do not have a cache time set.
759
-     *
760
-     * @return int the duration in seconds
761
-     */
762
-    public function getCacheTime()
763
-    {
764
-        return $this->cacheTime;
765
-    }
766
-
767
-    /**
768
-     * Sets the default cache time to use with templates that do not have a cache time set.
769
-     *
770
-     * @param int $seconds the duration in seconds
771
-     *
772
-     * @return void
773
-     */
774
-    public function setCacheTime($seconds)
775
-    {
776
-        $this->cacheTime = (int)$seconds;
777
-    }
778
-
779
-    /**
780
-     * Returns the character set used by the string manipulation plugins.
781
-     * the charset is automatically lowercased
782
-     *
783
-     * @return string
784
-     */
785
-    public function getCharset()
786
-    {
787
-        return $this->charset;
788
-    }
789
-
790
-    /**
791
-     * Sets the character set used by the string manipulation plugins.
792
-     * the charset will be automatically lowercased
793
-     *
794
-     * @param string $charset the character set
795
-     *
796
-     * @return void
797
-     */
798
-    public function setCharset($charset)
799
-    {
800
-        $this->charset = strtolower((string)$charset);
801
-    }
802
-
803
-    /**
804
-     * Returns the current template being rendered, when applicable, or null.
805
-     *
806
-     * @return Dwoo_ITemplate|null
807
-     */
808
-    public function getTemplate()
809
-    {
810
-        return $this->template;
811
-    }
812
-
813
-    /**
814
-     * Sets the current template being rendered.
815
-     *
816
-     * @param Dwoo_ITemplate $tpl template object
817
-     *
818
-     * @return void
819
-     */
820
-    public function setTemplate(Dwoo_ITemplate $tpl)
821
-    {
822
-        $this->template = $tpl;
823
-    }
824
-
825
-    /**
826
-     * Sets the default compiler factory function for the given resource name.
827
-     * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs
828
-     *
829
-     * @param string   $resourceName    the resource name (i.e. file, string)
830
-     * @param callback $compilerFactory the compiler factory callback
831
-     *
832
-     * @return void
833
-     */
834
-    public function setDefaultCompilerFactory($resourceName, $compilerFactory)
835
-    {
836
-        $this->resources[$resourceName]['compiler'] = $compilerFactory;
837
-    }
838
-
839
-    /**
840
-     * Returns the default compiler factory function for the given resource name.
841
-     *
842
-     * @param string $resourceName the resource name
843
-     *
844
-     * @return callback the compiler factory callback
845
-     */
846
-    public function getDefaultCompilerFactory($resourceName)
847
-    {
848
-        return $this->resources[$resourceName]['compiler'];
849
-    }
850
-
851
-    /**
852
-     * Sets the security policy object to enforce some php security settings.
853
-     * use this if untrusted persons can modify templates
854
-     *
855
-     * @param Dwoo_Security_Policy $policy the security policy object
856
-     *
857
-     * @return void
858
-     */
859
-    public function setSecurityPolicy(Dwoo_Security_Policy $policy = null)
860
-    {
861
-        $this->securityPolicy = $policy;
862
-    }
863
-
864
-    /**
865
-     * Returns the current security policy object or null by default.
866
-     *
867
-     * @return Dwoo_Security_Policy|null the security policy object if any
868
-     */
869
-    public function getSecurityPolicy()
870
-    {
871
-        return $this->securityPolicy;
872
-    }
873
-
874
-    /**
875
-     * Sets the object that must be used as a plugin proxy when plugin can't be found
876
-     * by dwoo's loader.
877
-     *
878
-     * @param Dwoo_IPluginProxy $pluginProxy the proxy object
879
-     *
880
-     * @return void
881
-     */
882
-    public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy)
883
-    {
884
-        $this->pluginProxy = $pluginProxy;
885
-    }
886
-
887
-    /**
888
-     * Returns the current plugin proxy object or null by default.
889
-     *
890
-     * @return Dwoo_IPluginProxy
891
-     */
892
-    public function getPluginProxy()
893
-    {
894
-        return $this->pluginProxy;
895
-    }
896
-
897
-    /**
898
-     * Checks whether the given template is cached or not.
899
-     *
900
-     * @param Dwoo_ITemplate $tpl the template object
901
-     *
902
-     * @return bool
903
-     */
904
-    public function isCached(Dwoo_ITemplate $tpl)
905
-    {
906
-        return is_string($tpl->getCachedTemplate($this));
907
-    }
908
-
909
-    /**
910
-     * Clear templates inside the compiled directory.
911
-     *
912
-     * @return int
913
-     */
914
-    public function clearCompiled()
915
-    {
916
-        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getCompileDir()), \RecursiveIteratorIterator::SELF_FIRST);
917
-        $count    = 0;
918
-        foreach ($iterator as $file) {
919
-            if ($file->isFile()) {
920
-                $count += unlink($file->__toString()) ? 1 : 0;
921
-            }
922
-        }
923
-
924
-        return $count;
925
-    }
926
-
927
-    /**
928
-     * Clears the cached templates if they are older than the given time.
929
-     *
930
-     * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared
931
-     *
932
-     * @return int the amount of templates cleared
933
-     */
934
-    public function clearCache($olderThan = - 1)
935
-    {
936
-        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getCacheDir()), \RecursiveIteratorIterator::SELF_FIRST);
937
-        $expired  = time() - $olderThan;
938
-        $count    = 0;
939
-        foreach ($iterator as $file) {
940
-            if ($file->isFile() && $file->getCTime() < $expired) {
941
-                $count += unlink((string)$file) ? 1 : 0;
942
-            }
943
-        }
944
-
945
-        return $count;
946
-    }
947
-
948
-    /**
949
-     * Fetches a template object of the given resource.
950
-     *
951
-     * @param string         $resourceName   the resource name (i.e. file, string)
952
-     * @param string         $resourceId     the resource identifier (i.e. file path)
953
-     * @param int            $cacheTime      the cache time setting for this resource
954
-     * @param string         $cacheId        the unique cache identifier
955
-     * @param string         $compileId      the unique compiler identifier
956
-     * @param Dwoo_ITemplate $parentTemplate the parent template
957
-     *
958
-     * @return Dwoo_ITemplate
959
-     * @throws Dwoo_Exception
960
-     */
961
-    public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
962
-    {
963
-        if (isset($this->resources[$resourceName])) {
964
-            // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe
965
-            return call_user_func(array(
966
-                $this->resources[$resourceName]['class'],
967
-                'templateFactory'
968
-            ), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate);
969
-        }
970
-
971
-        throw new Dwoo_Exception('Unknown resource type : ' . $resourceName);
972
-    }
973
-
974
-    /**
975
-     * Checks if the input is an array or arrayaccess object, optionally it can also check if it's
976
-     * empty.
977
-     *
978
-     * @param mixed $value        the variable to check
979
-     * @param bool  $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty,
980
-     *                            and return true only if it's not empty
981
-     *
982
-     * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's
983
-     *                  not an array|arrayaccess (or 0 if $checkIsEmpty is true)
984
-     */
985
-    public function isArray($value, $checkIsEmpty = false)
986
-    {
987
-        if (is_array($value) === true || $value instanceof ArrayAccess) {
988
-            if ($checkIsEmpty === false) {
989
-                return true;
990
-            }
991
-
992
-            return $this->count($value);
993
-        }
994
-
995
-        return false;
996
-    }
997
-
998
-    /**
999
-     * Checks if the input is an array or a traversable object, optionally it can also check if it's
1000
-     * empty.
1001
-     *
1002
-     * @param mixed $value        the variable to check
1003
-     * @param bool  $checkIsEmpty if true, the function will also check if the array|traversable is empty,
1004
-     *                            and return true only if it's not empty
1005
-     *
1006
-     * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's
1007
-     *                  not an array|traversable (or 0 if $checkIsEmpty is true)
1008
-     */
1009
-    public function isTraversable($value, $checkIsEmpty = false)
1010
-    {
1011
-        if (is_array($value) === true) {
1012
-            if ($checkIsEmpty === false) {
1013
-                return true;
1014
-            } else {
1015
-                return count($value) > 0;
1016
-            }
1017
-        } elseif ($value instanceof Traversable) {
1018
-            if ($checkIsEmpty === false) {
1019
-                return true;
1020
-            } else {
1021
-                return $this->count($value);
1022
-            }
1023
-        }
1024
-
1025
-        return false;
1026
-    }
1027
-
1028
-    /**
1029
-     * Counts an array or arrayaccess/traversable object.
1030
-     *
1031
-     * @param mixed $value the value to count
1032
-     *
1033
-     * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't,
1034
-     *                  and 0 for empty elements
1035
-     */
1036
-    public function count($value)
1037
-    {
1038
-        if (is_array($value) === true || $value instanceof Countable) {
1039
-            return count($value);
1040
-        } elseif ($value instanceof ArrayAccess) {
1041
-            if ($value->offsetExists(0)) {
1042
-                return true;
1043
-            }
1044
-        } elseif ($value instanceof Iterator) {
1045
-            $value->rewind();
1046
-            if ($value->valid()) {
1047
-                return true;
1048
-            }
1049
-        } elseif ($value instanceof Traversable) {
1050
-            foreach ($value as $dummy) {
1051
-                return true;
1052
-            }
1053
-        }
1054
-
1055
-        return 0;
1056
-    }
1057
-
1058
-    /**
1059
-     * Triggers a dwoo error.
1060
-     *
1061
-     * @param string $message the error message
1062
-     * @param int    $level   the error level, one of the PHP's E_* constants
1063
-     *
1064
-     * @return void
1065
-     */
1066
-    public function triggerError($message, $level = E_USER_NOTICE)
1067
-    {
1068
-        if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
1069
-            $tplIdentifier = $this->template->getResourceName();
1070
-        }
1071
-        trigger_error('Dwoo error (in ' . $tplIdentifier . ') : ' . $message, $level);
1072
-    }
1073
-
1074
-    /**
1075
-     * Adds a block to the block stack.
1076
-     *
1077
-     * @param string $blockName the block name (without Dwoo_Plugin_ prefix)
1078
-     * @param array  $args      the arguments to be passed to the block's init() function
1079
-     *
1080
-     * @return Dwoo_Block_Plugin the newly created block
1081
-     */
1082
-    public function addStack($blockName, array $args = array())
1083
-    {
1084
-        if (isset($this->plugins[$blockName])) {
1085
-            $class = $this->plugins[$blockName]['class'];
1086
-        } else {
1087
-            $class = 'Dwoo_Plugin_' . $blockName;
1088
-        }
1089
-
1090
-        if ($this->curBlock !== null) {
1091
-            $this->curBlock->buffer(ob_get_contents());
1092
-            ob_clean();
1093
-        } else {
1094
-            $this->buffer .= ob_get_contents();
1095
-            ob_clean();
1096
-        }
1097
-
1098
-        $block = new $class($this);
1099
-
1100
-        $cnt = count($args);
1101
-        if ($cnt === 0) {
1102
-            $block->init();
1103
-        } elseif ($cnt === 1) {
1104
-            $block->init($args[0]);
1105
-        } elseif ($cnt === 2) {
1106
-            $block->init($args[0], $args[1]);
1107
-        } elseif ($cnt === 3) {
1108
-            $block->init($args[0], $args[1], $args[2]);
1109
-        } elseif ($cnt === 4) {
1110
-            $block->init($args[0], $args[1], $args[2], $args[3]);
1111
-        } else {
1112
-            call_user_func_array(array(
1113
-                $block,
1114
-                'init'
1115
-            ), $args);
1116
-        }
1117
-
1118
-        $this->stack[] = $this->curBlock = $block;
1119
-
1120
-        return $block;
1121
-    }
1122
-
1123
-    /**
1124
-     * Removes the plugin at the top of the block stack.
1125
-     * Calls the block buffer() function, followed by a call to end() and finally a call to process()
1126
-     *
1127
-     * @return void
1128
-     */
1129
-    public function delStack()
1130
-    {
1131
-        $args = func_get_args();
1132
-
1133
-        $this->curBlock->buffer(ob_get_contents());
1134
-        ob_clean();
1135
-
1136
-        $cnt = count($args);
1137
-        if ($cnt === 0) {
1138
-            $this->curBlock->end();
1139
-        } elseif ($cnt === 1) {
1140
-            $this->curBlock->end($args[0]);
1141
-        } elseif ($cnt === 2) {
1142
-            $this->curBlock->end($args[0], $args[1]);
1143
-        } elseif ($cnt === 3) {
1144
-            $this->curBlock->end($args[0], $args[1], $args[2]);
1145
-        } elseif ($cnt === 4) {
1146
-            $this->curBlock->end($args[0], $args[1], $args[2], $args[3]);
1147
-        } else {
1148
-            call_user_func_array(array(
1149
-                $this->curBlock,
1150
-                'end'
1151
-            ), $args);
1152
-        }
1153
-
1154
-        $tmp = array_pop($this->stack);
1155
-
1156
-        if (count($this->stack) > 0) {
1157
-            $this->curBlock = end($this->stack);
1158
-            $this->curBlock->buffer($tmp->process());
1159
-        } else {
1160
-            if ($this->buffer !== '') {
1161
-                echo $this->buffer;
1162
-                $this->buffer = '';
1163
-            }
1164
-            $this->curBlock = null;
1165
-            echo $tmp->process();
1166
-        }
1167
-
1168
-        unset($tmp);
1169
-    }
1170
-
1171
-    /**
1172
-     * Returns the parent block of the given block.
1173
-     *
1174
-     * @param Dwoo_Block_Plugin $block the block class plugin
1175
-     *
1176
-     * @return Dwoo_Block_Plugin|false if the given block isn't in the stack
1177
-     */
1178
-    public function getParentBlock(Dwoo_Block_Plugin $block)
1179
-    {
1180
-        $index = array_search($block, $this->stack, true);
1181
-        if ($index !== false && $index > 0) {
1182
-            return $this->stack[$index - 1];
1183
-        }
1184
-
1185
-        return false;
1186
-    }
1187
-
1188
-    /**
1189
-     * Finds the closest block of the given type, starting at the top of the stack.
1190
-     *
1191
-     * @param string $type the type of plugin you want to find
1192
-     *
1193
-     * @return Dwoo_Block_Plugin|false if no plugin of such type is in the stack
1194
-     */
1195
-    public function findBlock($type)
1196
-    {
1197
-        if (isset($this->plugins[$type])) {
1198
-            $type = $this->plugins[$type]['class'];
1199
-        } else {
1200
-            $type = 'Dwoo_Plugin_' . str_replace('Dwoo_Plugin_', '', $type);
1201
-        }
1202
-
1203
-        $keys = array_keys($this->stack);
1204
-        while (($key = array_pop($keys)) !== false) {
1205
-            if ($this->stack[$key] instanceof $type) {
1206
-                return $this->stack[$key];
1207
-            }
1208
-        }
1209
-
1210
-        return false;
1211
-    }
1212
-
1213
-    /**
1214
-     * Returns a Dwoo_Plugin of the given class.
1215
-     * this is so a single instance of every class plugin is created at each template run,
1216
-     * allowing class plugins to have "per-template-run" static variables
1217
-     *
1218
-     * @param string $class the class name
1219
-     *
1220
-     * @return mixed an object of the given class
1221
-     */
1222
-    public function getObjectPlugin($class)
1223
-    {
1224
-        if (isset($this->runtimePlugins[$class])) {
1225
-            return $this->runtimePlugins[$class];
1226
-        }
1227
-
1228
-        return $this->runtimePlugins[$class] = new $class($this);
1229
-    }
1230
-
1231
-    /**
1232
-     * Calls the process() method of the given class-plugin name.
1233
-     *
1234
-     * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix)
1235
-     * @param array  $params   an array of parameters to send to the process() method
1236
-     *
1237
-     * @return string the process() return value
1238
-     */
1239
-    public function classCall($plugName, array $params = array())
1240
-    {
1241
-        $class = 'Dwoo_Plugin_' . $plugName;
1242
-
1243
-        $plugin = $this->getObjectPlugin($class);
1244
-
1245
-        $cnt = count($params);
1246
-        if ($cnt === 0) {
1247
-            return $plugin->process();
1248
-        } elseif ($cnt === 1) {
1249
-            return $plugin->process($params[0]);
1250
-        } elseif ($cnt === 2) {
1251
-            return $plugin->process($params[0], $params[1]);
1252
-        } elseif ($cnt === 3) {
1253
-            return $plugin->process($params[0], $params[1], $params[2]);
1254
-        } elseif ($cnt === 4) {
1255
-            return $plugin->process($params[0], $params[1], $params[2], $params[3]);
1256
-        } else {
1257
-            return call_user_func_array(array(
1258
-                $plugin,
1259
-                'process'
1260
-            ), $params);
1261
-        }
1262
-    }
1263
-
1264
-    /**
1265
-     * Calls a php function.
1266
-     *
1267
-     * @param string $callback the function to call
1268
-     * @param array  $params   an array of parameters to send to the function
1269
-     *
1270
-     * @return mixed the return value of the called function
1271
-     */
1272
-    public function arrayMap($callback, array $params)
1273
-    {
1274
-        if ($params[0] === $this) {
1275
-            $addThis = true;
1276
-            array_shift($params);
1277
-        }
1278
-        if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) {
1279
-            if (empty($params[0])) {
1280
-                return $params[0];
1281
-            }
1282
-
1283
-            // array map
1284
-            $out = array();
1285
-            $cnt = count($params);
1286
-
1287
-            if (isset($addThis)) {
1288
-                array_unshift($params, $this);
1289
-                $items = $params[1];
1290
-                $keys  = array_keys($items);
1291
-
1292
-                if (is_string($callback) === false) {
1293
-                    while (($i = array_shift($keys)) !== null) {
1294
-                        $out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1295
-                    }
1296
-                } elseif ($cnt === 1) {
1297
-                    while (($i = array_shift($keys)) !== null) {
1298
-                        $out[] = $callback($this, $items[$i]);
1299
-                    }
1300
-                } elseif ($cnt === 2) {
1301
-                    while (($i = array_shift($keys)) !== null) {
1302
-                        $out[] = $callback($this, $items[$i], $params[2]);
1303
-                    }
1304
-                } elseif ($cnt === 3) {
1305
-                    while (($i = array_shift($keys)) !== null) {
1306
-                        $out[] = $callback($this, $items[$i], $params[2], $params[3]);
1307
-                    }
1308
-                } else {
1309
-                    while (($i = array_shift($keys)) !== null) {
1310
-                        $out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1311
-                    }
1312
-                }
1313
-            } else {
1314
-                $items = $params[0];
1315
-                $keys  = array_keys($items);
1316
-
1317
-                if (is_string($callback) === false) {
1318
-                    while (($i = array_shift($keys)) !== null) {
1319
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1320
-                    }
1321
-                } elseif ($cnt === 1) {
1322
-                    while (($i = array_shift($keys)) !== null) {
1323
-                        $out[] = $callback($items[$i]);
1324
-                    }
1325
-                } elseif ($cnt === 2) {
1326
-                    while (($i = array_shift($keys)) !== null) {
1327
-                        $out[] = $callback($items[$i], $params[1]);
1328
-                    }
1329
-                } elseif ($cnt === 3) {
1330
-                    while (($i = array_shift($keys)) !== null) {
1331
-                        $out[] = $callback($items[$i], $params[1], $params[2]);
1332
-                    }
1333
-                } elseif ($cnt === 4) {
1334
-                    while (($i = array_shift($keys)) !== null) {
1335
-                        $out[] = $callback($items[$i], $params[1], $params[2], $params[3]);
1336
-                    }
1337
-                } else {
1338
-                    while (($i = array_shift($keys)) !== null) {
1339
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1340
-                    }
1341
-                }
1342
-            }
1343
-
1344
-            return $out;
1345
-        } else {
1346
-            return $params[0];
1347
-        }
1348
-    }
1349
-
1350
-    /**
1351
-     * Reads a variable into the given data array.
1352
-     *
1353
-     * @param string $varstr   the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1354
-     * @param mixed  $data     the data array or object to read from
1355
-     * @param bool   $safeRead if true, the function will check whether the index exists to prevent any notices from
1356
-     *                         being output
1357
-     *
1358
-     * @return mixed
1359
-     */
1360
-    public function readVarInto($varstr, $data, $safeRead = false)
1361
-    {
1362
-        if ($data === null) {
1363
-            return null;
1364
-        }
1365
-
1366
-        if (is_array($varstr) === false) {
1367
-            preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1368
-        } else {
1369
-            $m = $varstr;
1370
-        }
1371
-        unset($varstr);
1372
-
1373
-        while (list($k, $sep) = each($m[1])) {
1374
-            if ($sep === '.' || $sep === '[' || $sep === '') {
1375
-                // strip enclosing quotes if present
1376
-                $m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]);
1377
-
1378
-                if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) {
1379
-                    $data = $data[$m[2][$k]];
1380
-                } else {
1381
-                    return null;
1382
-                }
1383
-            } else {
1384
-                if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) {
1385
-                    $data = $data->$m[2][$k];
1386
-                } else {
1387
-                    return null;
1388
-                }
1389
-            }
1390
-        }
1391
-
1392
-        return $data;
1393
-    }
1394
-
1395
-    /**
1396
-     * Reads a variable into the parent scope.
1397
-     *
1398
-     * @param int    $parentLevels the amount of parent levels to go from the current scope
1399
-     * @param string $varstr       the variable string, using dwoo variable syntax (i.e.
1400
-     *                             "var.subvar[subsubvar]->property")
1401
-     *
1402
-     * @return mixed
1403
-     */
1404
-    public function readParentVar($parentLevels, $varstr = null)
1405
-    {
1406
-        $tree = $this->scopeTree;
1407
-        $cur  = $this->data;
1408
-
1409
-        while ($parentLevels -- !== 0) {
1410
-            array_pop($tree);
1411
-        }
1412
-
1413
-        while (($i = array_shift($tree)) !== null) {
1414
-            if (is_object($cur)) {
1415
-                $cur = $cur->$i;
1416
-            } else {
1417
-                $cur = $cur[$i];
1418
-            }
1419
-        }
1420
-
1421
-        if ($varstr !== null) {
1422
-            return $this->readVarInto($varstr, $cur);
1423
-        } else {
1424
-            return $cur;
1425
-        }
1426
-    }
1427
-
1428
-    /**
1429
-     * Reads a variable into the current scope.
1430
-     *
1431
-     * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1432
-     *
1433
-     * @return mixed
1434
-     */
1435
-    public function readVar($varstr)
1436
-    {
1437
-        if (is_array($varstr) === true) {
1438
-            $m = $varstr;
1439
-            unset($varstr);
1440
-        } else {
1441
-            if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) {
1442
-                if ($varstr === 'dwoo') {
1443
-                    return $this->globals;
1444
-                } elseif ($varstr === '__' || $varstr === '_root') {
1445
-                    return $this->data;
1446
-                } elseif ($varstr === '_' || $varstr === '_parent') {
1447
-                    $varstr = '.' . $varstr;
1448
-                    $tree   = $this->scopeTree;
1449
-                    $cur    = $this->data;
1450
-                    array_pop($tree);
1451
-
1452
-                    while (($i = array_shift($tree)) !== null) {
1453
-                        if (is_object($cur)) {
1454
-                            $cur = $cur->$i;
1455
-                        } else {
1456
-                            $cur = $cur[$i];
1457
-                        }
1458
-                    }
1459
-
1460
-                    return $cur;
1461
-                }
1462
-
1463
-                $cur = $this->scope;
1464
-
1465
-                if (isset($cur[$varstr])) {
1466
-                    return $cur[$varstr];
1467
-                } else {
1468
-                    return null;
1469
-                }
1470
-            }
1471
-
1472
-            if (substr($varstr, 0, 1) === '.') {
1473
-                $varstr = 'dwoo' . $varstr;
1474
-            }
1475
-
1476
-            preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1477
-        }
1478
-
1479
-        $i = $m[2][0];
1480
-        if ($i === 'dwoo') {
1481
-            $cur = $this->globals;
1482
-            array_shift($m[2]);
1483
-            array_shift($m[1]);
1484
-            switch ($m[2][0]) {
1485
-                case 'get':
1486
-                    $cur = $_GET;
1487
-                    break;
1488
-                case 'post':
1489
-                    $cur = $_POST;
1490
-                    break;
1491
-                case 'session':
1492
-                    $cur = $_SESSION;
1493
-                    break;
1494
-                case 'cookies':
1495
-                case 'cookie':
1496
-                    $cur = $_COOKIE;
1497
-                    break;
1498
-                case 'server':
1499
-                    $cur = $_SERVER;
1500
-                    break;
1501
-                case 'env':
1502
-                    $cur = $_ENV;
1503
-                    break;
1504
-                case 'request':
1505
-                    $cur = $_REQUEST;
1506
-                    break;
1507
-                case 'const':
1508
-                    array_shift($m[2]);
1509
-                    if (defined($m[2][0])) {
1510
-                        return constant($m[2][0]);
1511
-                    } else {
1512
-                        return null;
1513
-                    }
1514
-            }
1515
-            if ($cur !== $this->globals) {
1516
-                array_shift($m[2]);
1517
-                array_shift($m[1]);
1518
-            }
1519
-        } elseif ($i === '__' || $i === '_root') {
1520
-            $cur = $this->data;
1521
-            array_shift($m[2]);
1522
-            array_shift($m[1]);
1523
-        } elseif ($i === '_' || $i === '_parent') {
1524
-            $tree = $this->scopeTree;
1525
-            $cur  = $this->data;
1526
-
1527
-            while (true) {
1528
-                array_pop($tree);
1529
-                array_shift($m[2]);
1530
-                array_shift($m[1]);
1531
-                if (current($m[2]) === '_' || current($m[2]) === '_parent') {
1532
-                    continue;
1533
-                }
1534
-
1535
-                while (($i = array_shift($tree)) !== null) {
1536
-                    if (is_object($cur)) {
1537
-                        $cur = $cur->$i;
1538
-                    } else {
1539
-                        $cur = $cur[$i];
1540
-                    }
1541
-                }
1542
-                break;
1543
-            }
1544
-        } else {
1545
-            $cur = $this->scope;
1546
-        }
1547
-
1548
-        while (list($k, $sep) = each($m[1])) {
1549
-            if ($sep === '.' || $sep === '[' || $sep === '') {
1550
-                if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) {
1551
-                    $cur = $cur[$m[2][$k]];
1552
-                } else {
1553
-                    return null;
1554
-                }
1555
-            } elseif ($sep === '->') {
1556
-                if (is_object($cur)) {
1557
-                    $cur = $cur->$m[2][$k];
1558
-                } else {
1559
-                    return null;
1560
-                }
1561
-            } else {
1562
-                return null;
1563
-            }
1564
-        }
1565
-
1566
-        return $cur;
1567
-    }
1568
-
1569
-    /**
1570
-     * Assign the value to the given variable.
1571
-     *
1572
-     * @param mixed  $value the value to assign
1573
-     * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1574
-     *
1575
-     * @return bool true if assigned correctly or false if a problem occured while parsing the var string
1576
-     */
1577
-    public function assignInScope($value, $scope)
1578
-    {
1579
-        $tree = &$this->scopeTree;
1580
-        $data = &$this->data;
1581
-
1582
-        if (!is_string($scope)) {
1583
-            $this->triggerError('Assignments must be done into strings, (' . gettype($scope) . ') ' . var_export($scope, true) . ' given', E_USER_ERROR);
1584
-        }
1585
-        if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
1586
-            $this->scope[$scope] = $value;
1587
-        } else {
1588
-            // TODO handle _root/_parent scopes ?
1589
-            preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m);
1590
-
1591
-            $cur  = &$this->scope;
1592
-            $last = array(
1593
-                array_pop($m[1]),
1594
-                array_pop($m[2])
1595
-            );
1596
-
1597
-            while (list($k, $sep) = each($m[1])) {
1598
-                if ($sep === '.' || $sep === '[' || $sep === '') {
1599
-                    if (is_array($cur) === false) {
1600
-                        $cur = array();
1601
-                    }
1602
-                    $cur = &$cur[$m[2][$k]];
1603
-                } elseif ($sep === '->') {
1604
-                    if (is_object($cur) === false) {
1605
-                        $cur = new stdClass();
1606
-                    }
1607
-                    $cur = &$cur->$m[2][$k];
1608
-                } else {
1609
-                    return false;
1610
-                }
1611
-            }
1612
-
1613
-            if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') {
1614
-                if (is_array($cur) === false) {
1615
-                    $cur = array();
1616
-                }
1617
-                $cur[$last[1]] = $value;
1618
-            } elseif ($last[0] === '->') {
1619
-                if (is_object($cur) === false) {
1620
-                    $cur = new stdClass();
1621
-                }
1622
-                $cur->$last[1] = $value;
1623
-            }
1624
-        }
1625
-
1626
-        return false;
1627
-    }
1628
-
1629
-    /**
1630
-     * Sets the scope to the given scope string or array.
1631
-     *
1632
-     * @param mixed $scope    a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1633
-     * @param bool  $absolute if true, the scope is set from the top level scope and not from the current scope
1634
-     *
1635
-     * @return array the current scope tree
1636
-     */
1637
-    public function setScope($scope, $absolute = false)
1638
-    {
1639
-        $old = $this->scopeTree;
1640
-
1641
-        if (is_string($scope) === true) {
1642
-            $scope = explode('.', $scope);
1643
-        }
1644
-
1645
-        if ($absolute === true) {
1646
-            $this->scope     = &$this->data;
1647
-            $this->scopeTree = array();
1648
-        }
1649
-
1650
-        while (($bit = array_shift($scope)) !== null) {
1651
-            if ($bit === '_' || $bit === '_parent') {
1652
-                array_pop($this->scopeTree);
1653
-                $this->scope = &$this->data;
1654
-                $cnt         = count($this->scopeTree);
1655
-                for ($i = 0; $i < $cnt; ++ $i) {
1656
-                    $this->scope = &$this->scope[$this->scopeTree[$i]];
1657
-                }
1658
-            } elseif ($bit === '__' || $bit === '_root') {
1659
-                $this->scope     = &$this->data;
1660
-                $this->scopeTree = array();
1661
-            } elseif (isset($this->scope[$bit])) {
1662
-                if ($this->scope instanceof ArrayAccess) {
1663
-                    $tmp         = $this->scope[$bit];
1664
-                    $this->scope = &$tmp;
1665
-                } else {
1666
-                    $this->scope = &$this->scope[$bit];
1667
-                }
1668
-                $this->scopeTree[] = $bit;
1669
-            } else {
1670
-                unset($this->scope);
1671
-                $this->scope = null;
1672
-            }
1673
-        }
1674
-
1675
-        return $old;
1676
-    }
1677
-
1678
-    /**
1679
-     * Returns the entire data array.
1680
-     *
1681
-     * @return array
1682
-     */
1683
-    public function getData()
1684
-    {
1685
-        return $this->data;
1686
-    }
1687
-
1688
-    /**
1689
-     * Sets a return value for the currently running template.
1690
-     *
1691
-     * @param string $name  var name
1692
-     * @param mixed  $value var value
1693
-     *
1694
-     * @return void
1695
-     */
1696
-    public function setReturnValue($name, $value)
1697
-    {
1698
-        $this->returnData[$name] = $value;
1699
-    }
1700
-
1701
-    /**
1702
-     * Retrieves the return values set by the template.
1703
-     *
1704
-     * @return array
1705
-     */
1706
-    public function getReturnValues()
1707
-    {
1708
-        return $this->returnData;
1709
-    }
1710
-
1711
-    /**
1712
-     * Returns a reference to the current scope.
1713
-     *
1714
-     * @return mixed
1715
-     */
1716
-    public function &getScope()
1717
-    {
1718
-        return $this->scope;
1719
-    }
1720
-
1721
-    /**
1722
-     * Redirects all calls to unexisting to plugin proxy.
1723
-     *
1724
-     * @param string $method the method name
1725
-     * @param array  $args   array of arguments
1726
-     *
1727
-     * @return mixed
1728
-     * @throws Dwoo_Exception
1729
-     */
1730
-    public function __call($method, $args)
1731
-    {
1732
-        $proxy = $this->getPluginProxy();
1733
-        if (!$proxy) {
1734
-            throw new Dwoo_Exception('Call to undefined method ' . __CLASS__ . '::' . $method . '()');
1735
-        }
1736
-
1737
-        return call_user_func_array($proxy->getCallback($method), $args);
1738
-    }
35
+	/**
36
+	 * Current version number.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	const VERSION = '1.2.3';
41
+
42
+	/**
43
+	 * Unique number of this dwoo release.
44
+	 * this can be used by templates classes to check whether the compiled template
45
+	 * has been compiled before this release or not, so that old templates are
46
+	 * recompiled automatically when Dwoo is updated
47
+	 */
48
+	const RELEASE_TAG = 17;
49
+
50
+	/**
51
+	 * Constants that represents all plugin types
52
+	 * these are bitwise-operation-safe values to allow multiple types
53
+	 * on a single plugin
54
+	 *
55
+	 * @var int
56
+	 */
57
+	const CLASS_PLUGIN      = 1;
58
+	const FUNC_PLUGIN       = 2;
59
+	const NATIVE_PLUGIN     = 4;
60
+	const BLOCK_PLUGIN      = 8;
61
+	const COMPILABLE_PLUGIN = 16;
62
+	const CUSTOM_PLUGIN     = 32;
63
+	const SMARTY_MODIFIER   = 64;
64
+	const SMARTY_BLOCK      = 128;
65
+	const SMARTY_FUNCTION   = 256;
66
+	const PROXY_PLUGIN      = 512;
67
+	const TEMPLATE_PLUGIN   = 1024;
68
+
69
+	/**
70
+	 * Character set of the template, used by string manipulation plugins.
71
+	 * it must be lowercase, but setCharset() will take care of that
72
+	 *
73
+	 * @see setCharset
74
+	 * @see getCharset
75
+	 * @var string
76
+	 */
77
+	protected $charset = 'utf-8';
78
+
79
+	/**
80
+	 * Global variables that are accessible through $dwoo.* in the templates.
81
+	 * default values include:
82
+	 * $dwoo.version - current version number
83
+	 * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org
84
+	 * $dwoo.now - the current time
85
+	 * $dwoo.template - the current template filename
86
+	 * $dwoo.charset - the character set used by the template
87
+	 * on top of that, foreach and other plugins can store special values in there,
88
+	 * see their documentation for more details.
89
+	 *
90
+	 * @var array
91
+	 */
92
+	public $globals;
93
+
94
+	/**
95
+	 * Directory where the compiled templates are stored.
96
+	 * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)
97
+	 *
98
+	 * @var string
99
+	 */
100
+	protected $compileDir;
101
+
102
+	/**
103
+	 * Directory where the cached templates are stored.
104
+	 * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $cacheDir;
109
+
110
+	/**
111
+	 * Defines how long (in seconds) the cached files must remain valid.
112
+	 * can be overriden on a per-template basis
113
+	 * -1 = never delete
114
+	 * 0 = disabled
115
+	 * >0 = duration in seconds
116
+	 *
117
+	 * @var int
118
+	 */
119
+	protected $cacheTime = 0;
120
+
121
+	/**
122
+	 * Security policy object.
123
+	 *
124
+	 * @var Dwoo_Security_Policy
125
+	 */
126
+	protected $securityPolicy = null;
127
+
128
+	/**
129
+	 * Stores the custom plugins callbacks.
130
+	 *
131
+	 * @see addPlugin
132
+	 * @see removePlugin
133
+	 * @var array
134
+	 */
135
+	protected $plugins = array();
136
+
137
+	/**
138
+	 * Stores the filter callbacks.
139
+	 *
140
+	 * @see addFilter
141
+	 * @see removeFilter
142
+	 * @var array
143
+	 */
144
+	protected $filters = array();
145
+
146
+	/**
147
+	 * Stores the resource types and associated
148
+	 * classes / compiler classes.
149
+	 *
150
+	 * @var array
151
+	 */
152
+	protected $resources = array(
153
+		'file'   => array(
154
+			'class'    => 'Dwoo_Template_File',
155
+			'compiler' => null,
156
+		),
157
+		'string' => array(
158
+			'class'    => 'Dwoo_Template_String',
159
+			'compiler' => null,
160
+		),
161
+	);
162
+
163
+	/**
164
+	 * The dwoo loader object used to load plugins by this dwoo instance.
165
+	 *
166
+	 * @var Dwoo_ILoader
167
+	 */
168
+	protected $loader = null;
169
+
170
+	/**
171
+	 * Currently rendered template, set to null when not-rendering.
172
+	 *
173
+	 * @var Dwoo_ITemplate
174
+	 */
175
+	protected $template = null;
176
+
177
+	/**
178
+	 * Stores the instances of the class plugins during template runtime.
179
+	 *
180
+	 * @var array
181
+	 */
182
+	protected $runtimePlugins;
183
+
184
+	/**
185
+	 * Stores the returned values during template runtime.
186
+	 *
187
+	 * @var array
188
+	 */
189
+	protected $returnData;
190
+
191
+	/**
192
+	 * Stores the data during template runtime.
193
+	 *
194
+	 * @var array
195
+	 */
196
+	public $data;
197
+
198
+	/**
199
+	 * Stores the current scope during template runtime.
200
+	 * this should ideally not be accessed directly from outside template code
201
+	 *
202
+	 * @var mixed
203
+	 */
204
+	public $scope;
205
+
206
+	/**
207
+	 * Stores the scope tree during template runtime.
208
+	 *
209
+	 * @var array
210
+	 */
211
+	protected $scopeTree;
212
+
213
+	/**
214
+	 * Stores the block plugins stack during template runtime.
215
+	 *
216
+	 * @var array
217
+	 */
218
+	protected $stack;
219
+
220
+	/**
221
+	 * Stores the current block plugin at the top of the stack during template runtime.
222
+	 *
223
+	 * @var Dwoo_Block_Plugin
224
+	 */
225
+	protected $curBlock;
226
+
227
+	/**
228
+	 * Stores the output buffer during template runtime.
229
+	 *
230
+	 * @var string
231
+	 */
232
+	protected $buffer;
233
+
234
+	/**
235
+	 * Stores plugin proxy.
236
+	 *
237
+	 * @var Dwoo_IPluginProxy
238
+	 */
239
+	protected $pluginProxy;
240
+
241
+	/**
242
+	 * Constructor, sets the cache and compile dir to the default values if not provided.
243
+	 *
244
+	 * @param string $compileDir path to the compiled directory, defaults to lib/compiled
245
+	 * @param string $cacheDir   path to the cache directory, defaults to lib/cache
246
+	 */
247
+	public function __construct($compileDir = null, $cacheDir = null)
248
+	{
249
+		if ($compileDir !== null) {
250
+			$this->setCompileDir($compileDir);
251
+		}
252
+		if ($cacheDir !== null) {
253
+			$this->setCacheDir($cacheDir);
254
+		}
255
+		$this->initGlobals();
256
+	}
257
+
258
+	/**
259
+	 * Resets some runtime variables to allow a cloned object to be used to render sub-templates.
260
+	 *
261
+	 * @return void
262
+	 */
263
+	public function __clone()
264
+	{
265
+		$this->template = null;
266
+		unset($this->data);
267
+		unset($this->returnData);
268
+	}
269
+
270
+	/**
271
+	 * Autputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true).
272
+	 *
273
+	 * @param mixed          $tpl      template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a
274
+	 *                                 valid path to a template, or a template as a string it is recommended to provide
275
+	 *                                 a Dwoo_ITemplate as it will probably make things faster, especially if you
276
+	 *                                 render a template multiple times
277
+	 * @param mixed          $data     the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or
278
+	 *                                 an associative array. if you're rendering the template from cache, it can be
279
+	 *                                 left null
280
+	 * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default
281
+	 *                                 Dwoo_Compiler will be used
282
+	 *
283
+	 * @return     string nothing or the template output if $output is true
284
+	 * @deprecated 1.2.3. will be deleted in 1.3.0
285
+	 */
286
+	public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null)
287
+	{
288
+		return $this->get($tpl, $data, $compiler, true);
289
+	}
290
+
291
+	/**
292
+	 * Returns the given template rendered using the provided data and optional compiler.
293
+	 *
294
+	 * @param mixed          $_tpl      template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a
295
+	 *                                  valid path to a template, or a template as a string it is recommended to
296
+	 *                                  provide a Dwoo_ITemplate as it will probably make things faster, especially if
297
+	 *                                  you render a template multiple times
298
+	 * @param mixed          $data      the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or
299
+	 *                                  an associative array. if you're rendering the template from cache, it can be
300
+	 *                                  left null
301
+	 * @param Dwoo_ICompiler $_compiler the compiler that must be used to compile the template, if left empty a default
302
+	 *                                  Dwoo_Compiler will be used
303
+	 * @param bool           $_output   flag that defines whether the function returns the output of the template
304
+	 *                                  (false, default) or echoes it directly (true)
305
+	 *
306
+	 * @return string|void or the template output if $output is false
307
+	 * @throws Dwoo_Exception
308
+	 */
309
+	public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
310
+	{
311
+		// a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one
312
+		if ($this->template instanceof Dwoo_ITemplate) {
313
+			$clone = clone $this;
314
+
315
+			return $clone->get($_tpl, $data, $_compiler, $_output);
316
+		}
317
+
318
+		// auto-create template if required
319
+		if ($_tpl instanceof Dwoo_ITemplate) {
320
+			// valid, skip
321
+		} elseif (is_string($_tpl) && file_exists($_tpl)) {
322
+			$_tpl = new Dwoo_Template_File($_tpl);
323
+		} else {
324
+			throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE);
325
+		}
326
+
327
+		// save the current template, enters render mode at the same time
328
+		// if another rendering is requested it will be proxied to a new Dwoo_Core(instance
329
+		$this->template = $_tpl;
330
+
331
+		// load data
332
+		if ($data instanceof Dwoo_IDataProvider) {
333
+			$this->data = $data->getData();
334
+		} elseif (is_array($data)) {
335
+			$this->data = $data;
336
+		} elseif ($data instanceof ArrayAccess) {
337
+			$this->data = $data;
338
+		} else {
339
+			throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE);
340
+		}
341
+
342
+		$this->globals['template'] = $_tpl->getName();
343
+		$this->initRuntimeVars($_tpl);
344
+
345
+		// try to get cached template
346
+		$file        = $_tpl->getCachedTemplate($this);
347
+		$doCache     = $file === true;
348
+		$cacheLoaded = is_string($file);
349
+
350
+		if ($cacheLoaded === true) {
351
+			// cache is present, run it
352
+			if ($_output === true) {
353
+				include $file;
354
+				$this->template = null;
355
+			} else {
356
+				ob_start();
357
+				include $file;
358
+				$this->template = null;
359
+
360
+				return ob_get_clean();
361
+			}
362
+		} else {
363
+			$dynamicId = uniqid();
364
+
365
+			// render template
366
+			$compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
367
+			$out              = include $compiledTemplate;
368
+
369
+			// template returned false so it needs to be recompiled
370
+			if ($out === false) {
371
+				$_tpl->forceCompilation();
372
+				$compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
373
+				$out              = include $compiledTemplate;
374
+			}
375
+
376
+			if ($doCache === true) {
377
+				$out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*' . $dynamicId . '*/ echo \'$1\'; ?>', $out);
378
+				if (!class_exists('Dwoo_plugin_dynamic')) {
379
+					$this->getLoader()->loadPlugin('dynamic');
380
+				}
381
+				$out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate);
382
+			}
383
+
384
+			// process filters
385
+			foreach ($this->filters as $filter) {
386
+				if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) {
387
+					$out = call_user_func($filter, $out);
388
+				} else {
389
+					$out = call_user_func($filter, $this, $out);
390
+				}
391
+			}
392
+
393
+			if ($doCache === true) {
394
+				// building cache
395
+				$file = $_tpl->cache($this, $out);
396
+
397
+				// run it from the cache to be sure dynamics are rendered
398
+				if ($_output === true) {
399
+					include $file;
400
+					// exit render mode
401
+					$this->template = null;
402
+				} else {
403
+					ob_start();
404
+					include $file;
405
+					// exit render mode
406
+					$this->template = null;
407
+
408
+					return ob_get_clean();
409
+				}
410
+			} else {
411
+				// no need to build cache
412
+				// exit render mode
413
+				$this->template = null;
414
+				// output
415
+				if ($_output === true) {
416
+					echo $out;
417
+				}
418
+
419
+				return $out;
420
+			}
421
+		}
422
+
423
+		return '';
424
+	}
425
+
426
+	/**
427
+	 * Re-initializes the globals array before each template run.
428
+	 * this method is only callede once when the Dwoo object is created
429
+	 *
430
+	 * @return void
431
+	 */
432
+	protected function initGlobals()
433
+	{
434
+		$this->globals = array(
435
+			'version' => self::VERSION,
436
+			'ad'      => '<a href="http://dwoo.org/">Powered by Dwoo</a>',
437
+			'now'     => $_SERVER['REQUEST_TIME'],
438
+			'charset' => $this->charset,
439
+		);
440
+	}
441
+
442
+	/**
443
+	 * Re-initializes the runtime variables before each template run.
444
+	 * override this method to inject data in the globals array if needed, this
445
+	 * method is called before each template execution
446
+	 *
447
+	 * @param Dwoo_ITemplate $tpl the template that is going to be rendered
448
+	 *
449
+	 * @return void
450
+	 */
451
+	protected function initRuntimeVars(Dwoo_ITemplate $tpl)
452
+	{
453
+		$this->runtimePlugins = array();
454
+		$this->scope          = &$this->data;
455
+		$this->scopeTree      = array();
456
+		$this->stack          = array();
457
+		$this->curBlock       = null;
458
+		$this->buffer         = '';
459
+		$this->returnData     = array();
460
+	}
461
+
462
+	/**
463
+	 * Adds a custom plugin that is not in one of the plugin directories.
464
+	 *
465
+	 * @param string   $name       the plugin name to be used in the templates
466
+	 * @param callback $callback   the plugin callback, either a function name,
467
+	 *                             a class name or an array containing an object
468
+	 *                             or class name and a method name
469
+	 * @param bool     $compilable if set to true, the plugin is assumed to be compilable
470
+	 *
471
+	 * @return void
472
+	 * @throws Dwoo_Exception
473
+	 */
474
+	public function addPlugin($name, $callback, $compilable = false)
475
+	{
476
+		$compilable = $compilable ? self::COMPILABLE_PLUGIN : 0;
477
+		if (is_array($callback)) {
478
+			if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) {
479
+				$this->plugins[$name] = array(
480
+					'type'     => self::BLOCK_PLUGIN | $compilable,
481
+					'callback' => $callback,
482
+					'class'    => (is_object($callback[0]) ? get_class($callback[0]) : $callback[0])
483
+				);
484
+			} else {
485
+				$this->plugins[$name] = array(
486
+					'type'     => self::CLASS_PLUGIN | $compilable,
487
+					'callback' => $callback,
488
+					'class'    => (is_object($callback[0]) ? get_class($callback[0]) : $callback[0]),
489
+					'function' => $callback[1]
490
+				);
491
+			}
492
+		} elseif (is_string($callback)) {
493
+			if (class_exists($callback)) {
494
+				if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) {
495
+					$this->plugins[$name] = array(
496
+						'type'     => self::BLOCK_PLUGIN | $compilable,
497
+						'callback' => $callback,
498
+						'class'    => $callback
499
+					);
500
+				} else {
501
+					$this->plugins[$name] = array(
502
+						'type'     => self::CLASS_PLUGIN | $compilable,
503
+						'callback' => $callback,
504
+						'class'    => $callback,
505
+						'function' => ($compilable ? 'compile' : 'process')
506
+					);
507
+				}
508
+			} elseif (function_exists($callback)) {
509
+				$this->plugins[$name] = array(
510
+					'type'     => self::FUNC_PLUGIN | $compilable,
511
+					'callback' => $callback
512
+				);
513
+			} else {
514
+				throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
515
+			}
516
+		} elseif ($callback instanceof \Closure) {
517
+			$this->plugins[$name] = array(
518
+				'type'     => self::FUNC_PLUGIN | $compilable,
519
+				'callback' => $callback
520
+			);
521
+		} else {
522
+			throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
523
+		}
524
+	}
525
+
526
+	/**
527
+	 * Removes a custom plugin.
528
+	 *
529
+	 * @param string $name the plugin name
530
+	 *
531
+	 * @return void
532
+	 */
533
+	public function removePlugin($name)
534
+	{
535
+		if (isset($this->plugins[$name])) {
536
+			unset($this->plugins[$name]);
537
+		}
538
+	}
539
+
540
+	/**
541
+	 * Adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this
542
+	 * instance.
543
+	 *
544
+	 * @param mixed $callback a callback or a filter name if it is autoloaded from a plugin directory
545
+	 * @param bool  $autoload if true, the first parameter must be a filter name from one of the plugin directories
546
+	 *
547
+	 * @return void
548
+	 * @throws Dwoo_Exception
549
+	 */
550
+	public function addFilter($callback, $autoload = false)
551
+	{
552
+		if ($autoload) {
553
+			$class = 'Dwoo_Filter_' . $callback;
554
+
555
+			if (!class_exists($class) && !function_exists($class)) {
556
+				try {
557
+					$this->getLoader()->loadPlugin($callback);
558
+				}
559
+				catch (Dwoo_Exception $e) {
560
+					if (strstr($callback, 'Dwoo_Filter_')) {
561
+						throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', the "Dwoo_Filter_" prefix should not be used, please only use "' . str_replace('Dwoo_Filter_', '', $callback) . '"');
562
+					} else {
563
+						throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
564
+					}
565
+				}
566
+			}
567
+
568
+			if (class_exists($class)) {
569
+				$callback = array(
570
+					new $class($this),
571
+					'process'
572
+				);
573
+			} elseif (function_exists($class)) {
574
+				$callback = $class;
575
+			} else {
576
+				throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
577
+			}
578
+
579
+			$this->filters[] = $callback;
580
+		} else {
581
+			$this->filters[] = $callback;
582
+		}
583
+	}
584
+
585
+	/**
586
+	 * Removes a filter.
587
+	 *
588
+	 * @param mixed $callback callback or filter name if it was autoloaded
589
+	 *
590
+	 * @return void
591
+	 */
592
+	public function removeFilter($callback)
593
+	{
594
+		if (($index = array_search('Dwoo_Filter_' . $callback, $this->filters, true)) !== false) {
595
+			unset($this->filters[$index]);
596
+		} elseif (($index = array_search($callback, $this->filters, true)) !== false) {
597
+			unset($this->filters[$index]);
598
+		} else {
599
+			$class = 'Dwoo_Filter_' . $callback;
600
+			foreach ($this->filters as $index => $filter) {
601
+				if (is_array($filter) && $filter[0] instanceof $class) {
602
+					unset($this->filters[$index]);
603
+					break;
604
+				}
605
+			}
606
+		}
607
+	}
608
+
609
+	/**
610
+	 * Adds a resource or overrides a default one.
611
+	 *
612
+	 * @param string   $name            the resource name
613
+	 * @param string   $class           the resource class (which must implement Dwoo_ITemplate)
614
+	 * @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance
615
+	 *                                  used to compile this resource, if none is provided. by default it will produce
616
+	 *                                  a Dwoo_Compiler object
617
+	 *
618
+	 * @return void
619
+	 * @throws Dwoo_Exception
620
+	 */
621
+	public function addResource($name, $class, $compilerFactory = null)
622
+	{
623
+		if (strlen($name) < 2) {
624
+			throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');
625
+		}
626
+
627
+		if (!class_exists($class)) {
628
+			throw new Dwoo_Exception('Resource class does not exist');
629
+		}
630
+
631
+		$interfaces = class_implements($class);
632
+		if (in_array('Dwoo_ITemplate', $interfaces) === false) {
633
+			throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate');
634
+		}
635
+
636
+		$this->resources[$name] = array(
637
+			'class'    => $class,
638
+			'compiler' => $compilerFactory
639
+		);
640
+	}
641
+
642
+	/**
643
+	 * Removes a custom resource.
644
+	 *
645
+	 * @param string $name the resource name
646
+	 *
647
+	 * @return void
648
+	 */
649
+	public function removeResource($name)
650
+	{
651
+		unset($this->resources[$name]);
652
+		if ($name === 'file') {
653
+			$this->resources['file'] = array(
654
+				'class'    => 'Dwoo_Template_File',
655
+				'compiler' => null
656
+			);
657
+		}
658
+	}
659
+
660
+	/**
661
+	 * Sets the loader object to use to load plugins.
662
+	 *
663
+	 * @param Dwoo_ILoader $loader loader
664
+	 *
665
+	 * @return void
666
+	 */
667
+	public function setLoader(Dwoo_ILoader $loader)
668
+	{
669
+		$this->loader = $loader;
670
+	}
671
+
672
+	/**
673
+	 * Returns the current loader object or a default one if none is currently found.
674
+	 *
675
+	 * @return Dwoo_ILoader|Dwoo_Loader
676
+	 */
677
+	public function getLoader()
678
+	{
679
+		if ($this->loader === null) {
680
+			$this->loader = new Dwoo_Loader($this->getCompileDir());
681
+		}
682
+
683
+		return $this->loader;
684
+	}
685
+
686
+	/**
687
+	 * Returns the custom plugins loaded.
688
+	 * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance
689
+	 *
690
+	 * @return array
691
+	 */
692
+	public function getCustomPlugins()
693
+	{
694
+		return $this->plugins;
695
+	}
696
+
697
+	/**
698
+	 * Returns the cache directory with a trailing DIRECTORY_SEPARATOR.
699
+	 *
700
+	 * @return string
701
+	 */
702
+	public function getCacheDir()
703
+	{
704
+		if ($this->cacheDir === null) {
705
+			$this->setCacheDir(DWOO_DIRECTORY . 'cache' . DIRECTORY_SEPARATOR);
706
+		}
707
+
708
+		return $this->cacheDir;
709
+	}
710
+
711
+	/**
712
+	 * Sets the cache directory and automatically appends a DIRECTORY_SEPARATOR.
713
+	 *
714
+	 * @param string $dir the cache directory
715
+	 *
716
+	 * @return void
717
+	 * @throws Dwoo_Exception
718
+	 */
719
+	public function setCacheDir($dir)
720
+	{
721
+		$this->cacheDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
722
+		if (is_writable($this->cacheDir) === false) {
723
+			throw new Dwoo_Exception('The cache directory must be writable, chmod "' . $this->cacheDir . '" to make it writable');
724
+		}
725
+	}
726
+
727
+	/**
728
+	 * Returns the compile directory with a trailing DIRECTORY_SEPARATOR.
729
+	 *
730
+	 * @return string
731
+	 */
732
+	public function getCompileDir()
733
+	{
734
+		if ($this->compileDir === null) {
735
+			$this->setCompileDir(DWOO_DIRECTORY . 'compiled' . DIRECTORY_SEPARATOR);
736
+		}
737
+
738
+		return $this->compileDir;
739
+	}
740
+
741
+	/**
742
+	 * Sets the compile directory and automatically appends a DIRECTORY_SEPARATOR.
743
+	 *
744
+	 * @param string $dir the compile directory
745
+	 *
746
+	 * @return void
747
+	 * @throws Dwoo_Exception
748
+	 */
749
+	public function setCompileDir($dir)
750
+	{
751
+		$this->compileDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
752
+		if (is_writable($this->compileDir) === false) {
753
+			throw new Dwoo_Exception('The compile directory must be writable, chmod "' . $this->compileDir . '" to make it writable');
754
+		}
755
+	}
756
+
757
+	/**
758
+	 * Returns the default cache time that is used with templates that do not have a cache time set.
759
+	 *
760
+	 * @return int the duration in seconds
761
+	 */
762
+	public function getCacheTime()
763
+	{
764
+		return $this->cacheTime;
765
+	}
766
+
767
+	/**
768
+	 * Sets the default cache time to use with templates that do not have a cache time set.
769
+	 *
770
+	 * @param int $seconds the duration in seconds
771
+	 *
772
+	 * @return void
773
+	 */
774
+	public function setCacheTime($seconds)
775
+	{
776
+		$this->cacheTime = (int)$seconds;
777
+	}
778
+
779
+	/**
780
+	 * Returns the character set used by the string manipulation plugins.
781
+	 * the charset is automatically lowercased
782
+	 *
783
+	 * @return string
784
+	 */
785
+	public function getCharset()
786
+	{
787
+		return $this->charset;
788
+	}
789
+
790
+	/**
791
+	 * Sets the character set used by the string manipulation plugins.
792
+	 * the charset will be automatically lowercased
793
+	 *
794
+	 * @param string $charset the character set
795
+	 *
796
+	 * @return void
797
+	 */
798
+	public function setCharset($charset)
799
+	{
800
+		$this->charset = strtolower((string)$charset);
801
+	}
802
+
803
+	/**
804
+	 * Returns the current template being rendered, when applicable, or null.
805
+	 *
806
+	 * @return Dwoo_ITemplate|null
807
+	 */
808
+	public function getTemplate()
809
+	{
810
+		return $this->template;
811
+	}
812
+
813
+	/**
814
+	 * Sets the current template being rendered.
815
+	 *
816
+	 * @param Dwoo_ITemplate $tpl template object
817
+	 *
818
+	 * @return void
819
+	 */
820
+	public function setTemplate(Dwoo_ITemplate $tpl)
821
+	{
822
+		$this->template = $tpl;
823
+	}
824
+
825
+	/**
826
+	 * Sets the default compiler factory function for the given resource name.
827
+	 * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs
828
+	 *
829
+	 * @param string   $resourceName    the resource name (i.e. file, string)
830
+	 * @param callback $compilerFactory the compiler factory callback
831
+	 *
832
+	 * @return void
833
+	 */
834
+	public function setDefaultCompilerFactory($resourceName, $compilerFactory)
835
+	{
836
+		$this->resources[$resourceName]['compiler'] = $compilerFactory;
837
+	}
838
+
839
+	/**
840
+	 * Returns the default compiler factory function for the given resource name.
841
+	 *
842
+	 * @param string $resourceName the resource name
843
+	 *
844
+	 * @return callback the compiler factory callback
845
+	 */
846
+	public function getDefaultCompilerFactory($resourceName)
847
+	{
848
+		return $this->resources[$resourceName]['compiler'];
849
+	}
850
+
851
+	/**
852
+	 * Sets the security policy object to enforce some php security settings.
853
+	 * use this if untrusted persons can modify templates
854
+	 *
855
+	 * @param Dwoo_Security_Policy $policy the security policy object
856
+	 *
857
+	 * @return void
858
+	 */
859
+	public function setSecurityPolicy(Dwoo_Security_Policy $policy = null)
860
+	{
861
+		$this->securityPolicy = $policy;
862
+	}
863
+
864
+	/**
865
+	 * Returns the current security policy object or null by default.
866
+	 *
867
+	 * @return Dwoo_Security_Policy|null the security policy object if any
868
+	 */
869
+	public function getSecurityPolicy()
870
+	{
871
+		return $this->securityPolicy;
872
+	}
873
+
874
+	/**
875
+	 * Sets the object that must be used as a plugin proxy when plugin can't be found
876
+	 * by dwoo's loader.
877
+	 *
878
+	 * @param Dwoo_IPluginProxy $pluginProxy the proxy object
879
+	 *
880
+	 * @return void
881
+	 */
882
+	public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy)
883
+	{
884
+		$this->pluginProxy = $pluginProxy;
885
+	}
886
+
887
+	/**
888
+	 * Returns the current plugin proxy object or null by default.
889
+	 *
890
+	 * @return Dwoo_IPluginProxy
891
+	 */
892
+	public function getPluginProxy()
893
+	{
894
+		return $this->pluginProxy;
895
+	}
896
+
897
+	/**
898
+	 * Checks whether the given template is cached or not.
899
+	 *
900
+	 * @param Dwoo_ITemplate $tpl the template object
901
+	 *
902
+	 * @return bool
903
+	 */
904
+	public function isCached(Dwoo_ITemplate $tpl)
905
+	{
906
+		return is_string($tpl->getCachedTemplate($this));
907
+	}
908
+
909
+	/**
910
+	 * Clear templates inside the compiled directory.
911
+	 *
912
+	 * @return int
913
+	 */
914
+	public function clearCompiled()
915
+	{
916
+		$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getCompileDir()), \RecursiveIteratorIterator::SELF_FIRST);
917
+		$count    = 0;
918
+		foreach ($iterator as $file) {
919
+			if ($file->isFile()) {
920
+				$count += unlink($file->__toString()) ? 1 : 0;
921
+			}
922
+		}
923
+
924
+		return $count;
925
+	}
926
+
927
+	/**
928
+	 * Clears the cached templates if they are older than the given time.
929
+	 *
930
+	 * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared
931
+	 *
932
+	 * @return int the amount of templates cleared
933
+	 */
934
+	public function clearCache($olderThan = - 1)
935
+	{
936
+		$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getCacheDir()), \RecursiveIteratorIterator::SELF_FIRST);
937
+		$expired  = time() - $olderThan;
938
+		$count    = 0;
939
+		foreach ($iterator as $file) {
940
+			if ($file->isFile() && $file->getCTime() < $expired) {
941
+				$count += unlink((string)$file) ? 1 : 0;
942
+			}
943
+		}
944
+
945
+		return $count;
946
+	}
947
+
948
+	/**
949
+	 * Fetches a template object of the given resource.
950
+	 *
951
+	 * @param string         $resourceName   the resource name (i.e. file, string)
952
+	 * @param string         $resourceId     the resource identifier (i.e. file path)
953
+	 * @param int            $cacheTime      the cache time setting for this resource
954
+	 * @param string         $cacheId        the unique cache identifier
955
+	 * @param string         $compileId      the unique compiler identifier
956
+	 * @param Dwoo_ITemplate $parentTemplate the parent template
957
+	 *
958
+	 * @return Dwoo_ITemplate
959
+	 * @throws Dwoo_Exception
960
+	 */
961
+	public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
962
+	{
963
+		if (isset($this->resources[$resourceName])) {
964
+			// TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe
965
+			return call_user_func(array(
966
+				$this->resources[$resourceName]['class'],
967
+				'templateFactory'
968
+			), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate);
969
+		}
970
+
971
+		throw new Dwoo_Exception('Unknown resource type : ' . $resourceName);
972
+	}
973
+
974
+	/**
975
+	 * Checks if the input is an array or arrayaccess object, optionally it can also check if it's
976
+	 * empty.
977
+	 *
978
+	 * @param mixed $value        the variable to check
979
+	 * @param bool  $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty,
980
+	 *                            and return true only if it's not empty
981
+	 *
982
+	 * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's
983
+	 *                  not an array|arrayaccess (or 0 if $checkIsEmpty is true)
984
+	 */
985
+	public function isArray($value, $checkIsEmpty = false)
986
+	{
987
+		if (is_array($value) === true || $value instanceof ArrayAccess) {
988
+			if ($checkIsEmpty === false) {
989
+				return true;
990
+			}
991
+
992
+			return $this->count($value);
993
+		}
994
+
995
+		return false;
996
+	}
997
+
998
+	/**
999
+	 * Checks if the input is an array or a traversable object, optionally it can also check if it's
1000
+	 * empty.
1001
+	 *
1002
+	 * @param mixed $value        the variable to check
1003
+	 * @param bool  $checkIsEmpty if true, the function will also check if the array|traversable is empty,
1004
+	 *                            and return true only if it's not empty
1005
+	 *
1006
+	 * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's
1007
+	 *                  not an array|traversable (or 0 if $checkIsEmpty is true)
1008
+	 */
1009
+	public function isTraversable($value, $checkIsEmpty = false)
1010
+	{
1011
+		if (is_array($value) === true) {
1012
+			if ($checkIsEmpty === false) {
1013
+				return true;
1014
+			} else {
1015
+				return count($value) > 0;
1016
+			}
1017
+		} elseif ($value instanceof Traversable) {
1018
+			if ($checkIsEmpty === false) {
1019
+				return true;
1020
+			} else {
1021
+				return $this->count($value);
1022
+			}
1023
+		}
1024
+
1025
+		return false;
1026
+	}
1027
+
1028
+	/**
1029
+	 * Counts an array or arrayaccess/traversable object.
1030
+	 *
1031
+	 * @param mixed $value the value to count
1032
+	 *
1033
+	 * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't,
1034
+	 *                  and 0 for empty elements
1035
+	 */
1036
+	public function count($value)
1037
+	{
1038
+		if (is_array($value) === true || $value instanceof Countable) {
1039
+			return count($value);
1040
+		} elseif ($value instanceof ArrayAccess) {
1041
+			if ($value->offsetExists(0)) {
1042
+				return true;
1043
+			}
1044
+		} elseif ($value instanceof Iterator) {
1045
+			$value->rewind();
1046
+			if ($value->valid()) {
1047
+				return true;
1048
+			}
1049
+		} elseif ($value instanceof Traversable) {
1050
+			foreach ($value as $dummy) {
1051
+				return true;
1052
+			}
1053
+		}
1054
+
1055
+		return 0;
1056
+	}
1057
+
1058
+	/**
1059
+	 * Triggers a dwoo error.
1060
+	 *
1061
+	 * @param string $message the error message
1062
+	 * @param int    $level   the error level, one of the PHP's E_* constants
1063
+	 *
1064
+	 * @return void
1065
+	 */
1066
+	public function triggerError($message, $level = E_USER_NOTICE)
1067
+	{
1068
+		if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
1069
+			$tplIdentifier = $this->template->getResourceName();
1070
+		}
1071
+		trigger_error('Dwoo error (in ' . $tplIdentifier . ') : ' . $message, $level);
1072
+	}
1073
+
1074
+	/**
1075
+	 * Adds a block to the block stack.
1076
+	 *
1077
+	 * @param string $blockName the block name (without Dwoo_Plugin_ prefix)
1078
+	 * @param array  $args      the arguments to be passed to the block's init() function
1079
+	 *
1080
+	 * @return Dwoo_Block_Plugin the newly created block
1081
+	 */
1082
+	public function addStack($blockName, array $args = array())
1083
+	{
1084
+		if (isset($this->plugins[$blockName])) {
1085
+			$class = $this->plugins[$blockName]['class'];
1086
+		} else {
1087
+			$class = 'Dwoo_Plugin_' . $blockName;
1088
+		}
1089
+
1090
+		if ($this->curBlock !== null) {
1091
+			$this->curBlock->buffer(ob_get_contents());
1092
+			ob_clean();
1093
+		} else {
1094
+			$this->buffer .= ob_get_contents();
1095
+			ob_clean();
1096
+		}
1097
+
1098
+		$block = new $class($this);
1099
+
1100
+		$cnt = count($args);
1101
+		if ($cnt === 0) {
1102
+			$block->init();
1103
+		} elseif ($cnt === 1) {
1104
+			$block->init($args[0]);
1105
+		} elseif ($cnt === 2) {
1106
+			$block->init($args[0], $args[1]);
1107
+		} elseif ($cnt === 3) {
1108
+			$block->init($args[0], $args[1], $args[2]);
1109
+		} elseif ($cnt === 4) {
1110
+			$block->init($args[0], $args[1], $args[2], $args[3]);
1111
+		} else {
1112
+			call_user_func_array(array(
1113
+				$block,
1114
+				'init'
1115
+			), $args);
1116
+		}
1117
+
1118
+		$this->stack[] = $this->curBlock = $block;
1119
+
1120
+		return $block;
1121
+	}
1122
+
1123
+	/**
1124
+	 * Removes the plugin at the top of the block stack.
1125
+	 * Calls the block buffer() function, followed by a call to end() and finally a call to process()
1126
+	 *
1127
+	 * @return void
1128
+	 */
1129
+	public function delStack()
1130
+	{
1131
+		$args = func_get_args();
1132
+
1133
+		$this->curBlock->buffer(ob_get_contents());
1134
+		ob_clean();
1135
+
1136
+		$cnt = count($args);
1137
+		if ($cnt === 0) {
1138
+			$this->curBlock->end();
1139
+		} elseif ($cnt === 1) {
1140
+			$this->curBlock->end($args[0]);
1141
+		} elseif ($cnt === 2) {
1142
+			$this->curBlock->end($args[0], $args[1]);
1143
+		} elseif ($cnt === 3) {
1144
+			$this->curBlock->end($args[0], $args[1], $args[2]);
1145
+		} elseif ($cnt === 4) {
1146
+			$this->curBlock->end($args[0], $args[1], $args[2], $args[3]);
1147
+		} else {
1148
+			call_user_func_array(array(
1149
+				$this->curBlock,
1150
+				'end'
1151
+			), $args);
1152
+		}
1153
+
1154
+		$tmp = array_pop($this->stack);
1155
+
1156
+		if (count($this->stack) > 0) {
1157
+			$this->curBlock = end($this->stack);
1158
+			$this->curBlock->buffer($tmp->process());
1159
+		} else {
1160
+			if ($this->buffer !== '') {
1161
+				echo $this->buffer;
1162
+				$this->buffer = '';
1163
+			}
1164
+			$this->curBlock = null;
1165
+			echo $tmp->process();
1166
+		}
1167
+
1168
+		unset($tmp);
1169
+	}
1170
+
1171
+	/**
1172
+	 * Returns the parent block of the given block.
1173
+	 *
1174
+	 * @param Dwoo_Block_Plugin $block the block class plugin
1175
+	 *
1176
+	 * @return Dwoo_Block_Plugin|false if the given block isn't in the stack
1177
+	 */
1178
+	public function getParentBlock(Dwoo_Block_Plugin $block)
1179
+	{
1180
+		$index = array_search($block, $this->stack, true);
1181
+		if ($index !== false && $index > 0) {
1182
+			return $this->stack[$index - 1];
1183
+		}
1184
+
1185
+		return false;
1186
+	}
1187
+
1188
+	/**
1189
+	 * Finds the closest block of the given type, starting at the top of the stack.
1190
+	 *
1191
+	 * @param string $type the type of plugin you want to find
1192
+	 *
1193
+	 * @return Dwoo_Block_Plugin|false if no plugin of such type is in the stack
1194
+	 */
1195
+	public function findBlock($type)
1196
+	{
1197
+		if (isset($this->plugins[$type])) {
1198
+			$type = $this->plugins[$type]['class'];
1199
+		} else {
1200
+			$type = 'Dwoo_Plugin_' . str_replace('Dwoo_Plugin_', '', $type);
1201
+		}
1202
+
1203
+		$keys = array_keys($this->stack);
1204
+		while (($key = array_pop($keys)) !== false) {
1205
+			if ($this->stack[$key] instanceof $type) {
1206
+				return $this->stack[$key];
1207
+			}
1208
+		}
1209
+
1210
+		return false;
1211
+	}
1212
+
1213
+	/**
1214
+	 * Returns a Dwoo_Plugin of the given class.
1215
+	 * this is so a single instance of every class plugin is created at each template run,
1216
+	 * allowing class plugins to have "per-template-run" static variables
1217
+	 *
1218
+	 * @param string $class the class name
1219
+	 *
1220
+	 * @return mixed an object of the given class
1221
+	 */
1222
+	public function getObjectPlugin($class)
1223
+	{
1224
+		if (isset($this->runtimePlugins[$class])) {
1225
+			return $this->runtimePlugins[$class];
1226
+		}
1227
+
1228
+		return $this->runtimePlugins[$class] = new $class($this);
1229
+	}
1230
+
1231
+	/**
1232
+	 * Calls the process() method of the given class-plugin name.
1233
+	 *
1234
+	 * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix)
1235
+	 * @param array  $params   an array of parameters to send to the process() method
1236
+	 *
1237
+	 * @return string the process() return value
1238
+	 */
1239
+	public function classCall($plugName, array $params = array())
1240
+	{
1241
+		$class = 'Dwoo_Plugin_' . $plugName;
1242
+
1243
+		$plugin = $this->getObjectPlugin($class);
1244
+
1245
+		$cnt = count($params);
1246
+		if ($cnt === 0) {
1247
+			return $plugin->process();
1248
+		} elseif ($cnt === 1) {
1249
+			return $plugin->process($params[0]);
1250
+		} elseif ($cnt === 2) {
1251
+			return $plugin->process($params[0], $params[1]);
1252
+		} elseif ($cnt === 3) {
1253
+			return $plugin->process($params[0], $params[1], $params[2]);
1254
+		} elseif ($cnt === 4) {
1255
+			return $plugin->process($params[0], $params[1], $params[2], $params[3]);
1256
+		} else {
1257
+			return call_user_func_array(array(
1258
+				$plugin,
1259
+				'process'
1260
+			), $params);
1261
+		}
1262
+	}
1263
+
1264
+	/**
1265
+	 * Calls a php function.
1266
+	 *
1267
+	 * @param string $callback the function to call
1268
+	 * @param array  $params   an array of parameters to send to the function
1269
+	 *
1270
+	 * @return mixed the return value of the called function
1271
+	 */
1272
+	public function arrayMap($callback, array $params)
1273
+	{
1274
+		if ($params[0] === $this) {
1275
+			$addThis = true;
1276
+			array_shift($params);
1277
+		}
1278
+		if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) {
1279
+			if (empty($params[0])) {
1280
+				return $params[0];
1281
+			}
1282
+
1283
+			// array map
1284
+			$out = array();
1285
+			$cnt = count($params);
1286
+
1287
+			if (isset($addThis)) {
1288
+				array_unshift($params, $this);
1289
+				$items = $params[1];
1290
+				$keys  = array_keys($items);
1291
+
1292
+				if (is_string($callback) === false) {
1293
+					while (($i = array_shift($keys)) !== null) {
1294
+						$out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1295
+					}
1296
+				} elseif ($cnt === 1) {
1297
+					while (($i = array_shift($keys)) !== null) {
1298
+						$out[] = $callback($this, $items[$i]);
1299
+					}
1300
+				} elseif ($cnt === 2) {
1301
+					while (($i = array_shift($keys)) !== null) {
1302
+						$out[] = $callback($this, $items[$i], $params[2]);
1303
+					}
1304
+				} elseif ($cnt === 3) {
1305
+					while (($i = array_shift($keys)) !== null) {
1306
+						$out[] = $callback($this, $items[$i], $params[2], $params[3]);
1307
+					}
1308
+				} else {
1309
+					while (($i = array_shift($keys)) !== null) {
1310
+						$out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1311
+					}
1312
+				}
1313
+			} else {
1314
+				$items = $params[0];
1315
+				$keys  = array_keys($items);
1316
+
1317
+				if (is_string($callback) === false) {
1318
+					while (($i = array_shift($keys)) !== null) {
1319
+						$out[] = call_user_func_array($callback, array($items[$i]) + $params);
1320
+					}
1321
+				} elseif ($cnt === 1) {
1322
+					while (($i = array_shift($keys)) !== null) {
1323
+						$out[] = $callback($items[$i]);
1324
+					}
1325
+				} elseif ($cnt === 2) {
1326
+					while (($i = array_shift($keys)) !== null) {
1327
+						$out[] = $callback($items[$i], $params[1]);
1328
+					}
1329
+				} elseif ($cnt === 3) {
1330
+					while (($i = array_shift($keys)) !== null) {
1331
+						$out[] = $callback($items[$i], $params[1], $params[2]);
1332
+					}
1333
+				} elseif ($cnt === 4) {
1334
+					while (($i = array_shift($keys)) !== null) {
1335
+						$out[] = $callback($items[$i], $params[1], $params[2], $params[3]);
1336
+					}
1337
+				} else {
1338
+					while (($i = array_shift($keys)) !== null) {
1339
+						$out[] = call_user_func_array($callback, array($items[$i]) + $params);
1340
+					}
1341
+				}
1342
+			}
1343
+
1344
+			return $out;
1345
+		} else {
1346
+			return $params[0];
1347
+		}
1348
+	}
1349
+
1350
+	/**
1351
+	 * Reads a variable into the given data array.
1352
+	 *
1353
+	 * @param string $varstr   the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1354
+	 * @param mixed  $data     the data array or object to read from
1355
+	 * @param bool   $safeRead if true, the function will check whether the index exists to prevent any notices from
1356
+	 *                         being output
1357
+	 *
1358
+	 * @return mixed
1359
+	 */
1360
+	public function readVarInto($varstr, $data, $safeRead = false)
1361
+	{
1362
+		if ($data === null) {
1363
+			return null;
1364
+		}
1365
+
1366
+		if (is_array($varstr) === false) {
1367
+			preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1368
+		} else {
1369
+			$m = $varstr;
1370
+		}
1371
+		unset($varstr);
1372
+
1373
+		while (list($k, $sep) = each($m[1])) {
1374
+			if ($sep === '.' || $sep === '[' || $sep === '') {
1375
+				// strip enclosing quotes if present
1376
+				$m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]);
1377
+
1378
+				if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) {
1379
+					$data = $data[$m[2][$k]];
1380
+				} else {
1381
+					return null;
1382
+				}
1383
+			} else {
1384
+				if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) {
1385
+					$data = $data->$m[2][$k];
1386
+				} else {
1387
+					return null;
1388
+				}
1389
+			}
1390
+		}
1391
+
1392
+		return $data;
1393
+	}
1394
+
1395
+	/**
1396
+	 * Reads a variable into the parent scope.
1397
+	 *
1398
+	 * @param int    $parentLevels the amount of parent levels to go from the current scope
1399
+	 * @param string $varstr       the variable string, using dwoo variable syntax (i.e.
1400
+	 *                             "var.subvar[subsubvar]->property")
1401
+	 *
1402
+	 * @return mixed
1403
+	 */
1404
+	public function readParentVar($parentLevels, $varstr = null)
1405
+	{
1406
+		$tree = $this->scopeTree;
1407
+		$cur  = $this->data;
1408
+
1409
+		while ($parentLevels -- !== 0) {
1410
+			array_pop($tree);
1411
+		}
1412
+
1413
+		while (($i = array_shift($tree)) !== null) {
1414
+			if (is_object($cur)) {
1415
+				$cur = $cur->$i;
1416
+			} else {
1417
+				$cur = $cur[$i];
1418
+			}
1419
+		}
1420
+
1421
+		if ($varstr !== null) {
1422
+			return $this->readVarInto($varstr, $cur);
1423
+		} else {
1424
+			return $cur;
1425
+		}
1426
+	}
1427
+
1428
+	/**
1429
+	 * Reads a variable into the current scope.
1430
+	 *
1431
+	 * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1432
+	 *
1433
+	 * @return mixed
1434
+	 */
1435
+	public function readVar($varstr)
1436
+	{
1437
+		if (is_array($varstr) === true) {
1438
+			$m = $varstr;
1439
+			unset($varstr);
1440
+		} else {
1441
+			if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) {
1442
+				if ($varstr === 'dwoo') {
1443
+					return $this->globals;
1444
+				} elseif ($varstr === '__' || $varstr === '_root') {
1445
+					return $this->data;
1446
+				} elseif ($varstr === '_' || $varstr === '_parent') {
1447
+					$varstr = '.' . $varstr;
1448
+					$tree   = $this->scopeTree;
1449
+					$cur    = $this->data;
1450
+					array_pop($tree);
1451
+
1452
+					while (($i = array_shift($tree)) !== null) {
1453
+						if (is_object($cur)) {
1454
+							$cur = $cur->$i;
1455
+						} else {
1456
+							$cur = $cur[$i];
1457
+						}
1458
+					}
1459
+
1460
+					return $cur;
1461
+				}
1462
+
1463
+				$cur = $this->scope;
1464
+
1465
+				if (isset($cur[$varstr])) {
1466
+					return $cur[$varstr];
1467
+				} else {
1468
+					return null;
1469
+				}
1470
+			}
1471
+
1472
+			if (substr($varstr, 0, 1) === '.') {
1473
+				$varstr = 'dwoo' . $varstr;
1474
+			}
1475
+
1476
+			preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1477
+		}
1478
+
1479
+		$i = $m[2][0];
1480
+		if ($i === 'dwoo') {
1481
+			$cur = $this->globals;
1482
+			array_shift($m[2]);
1483
+			array_shift($m[1]);
1484
+			switch ($m[2][0]) {
1485
+				case 'get':
1486
+					$cur = $_GET;
1487
+					break;
1488
+				case 'post':
1489
+					$cur = $_POST;
1490
+					break;
1491
+				case 'session':
1492
+					$cur = $_SESSION;
1493
+					break;
1494
+				case 'cookies':
1495
+				case 'cookie':
1496
+					$cur = $_COOKIE;
1497
+					break;
1498
+				case 'server':
1499
+					$cur = $_SERVER;
1500
+					break;
1501
+				case 'env':
1502
+					$cur = $_ENV;
1503
+					break;
1504
+				case 'request':
1505
+					$cur = $_REQUEST;
1506
+					break;
1507
+				case 'const':
1508
+					array_shift($m[2]);
1509
+					if (defined($m[2][0])) {
1510
+						return constant($m[2][0]);
1511
+					} else {
1512
+						return null;
1513
+					}
1514
+			}
1515
+			if ($cur !== $this->globals) {
1516
+				array_shift($m[2]);
1517
+				array_shift($m[1]);
1518
+			}
1519
+		} elseif ($i === '__' || $i === '_root') {
1520
+			$cur = $this->data;
1521
+			array_shift($m[2]);
1522
+			array_shift($m[1]);
1523
+		} elseif ($i === '_' || $i === '_parent') {
1524
+			$tree = $this->scopeTree;
1525
+			$cur  = $this->data;
1526
+
1527
+			while (true) {
1528
+				array_pop($tree);
1529
+				array_shift($m[2]);
1530
+				array_shift($m[1]);
1531
+				if (current($m[2]) === '_' || current($m[2]) === '_parent') {
1532
+					continue;
1533
+				}
1534
+
1535
+				while (($i = array_shift($tree)) !== null) {
1536
+					if (is_object($cur)) {
1537
+						$cur = $cur->$i;
1538
+					} else {
1539
+						$cur = $cur[$i];
1540
+					}
1541
+				}
1542
+				break;
1543
+			}
1544
+		} else {
1545
+			$cur = $this->scope;
1546
+		}
1547
+
1548
+		while (list($k, $sep) = each($m[1])) {
1549
+			if ($sep === '.' || $sep === '[' || $sep === '') {
1550
+				if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) {
1551
+					$cur = $cur[$m[2][$k]];
1552
+				} else {
1553
+					return null;
1554
+				}
1555
+			} elseif ($sep === '->') {
1556
+				if (is_object($cur)) {
1557
+					$cur = $cur->$m[2][$k];
1558
+				} else {
1559
+					return null;
1560
+				}
1561
+			} else {
1562
+				return null;
1563
+			}
1564
+		}
1565
+
1566
+		return $cur;
1567
+	}
1568
+
1569
+	/**
1570
+	 * Assign the value to the given variable.
1571
+	 *
1572
+	 * @param mixed  $value the value to assign
1573
+	 * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1574
+	 *
1575
+	 * @return bool true if assigned correctly or false if a problem occured while parsing the var string
1576
+	 */
1577
+	public function assignInScope($value, $scope)
1578
+	{
1579
+		$tree = &$this->scopeTree;
1580
+		$data = &$this->data;
1581
+
1582
+		if (!is_string($scope)) {
1583
+			$this->triggerError('Assignments must be done into strings, (' . gettype($scope) . ') ' . var_export($scope, true) . ' given', E_USER_ERROR);
1584
+		}
1585
+		if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
1586
+			$this->scope[$scope] = $value;
1587
+		} else {
1588
+			// TODO handle _root/_parent scopes ?
1589
+			preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m);
1590
+
1591
+			$cur  = &$this->scope;
1592
+			$last = array(
1593
+				array_pop($m[1]),
1594
+				array_pop($m[2])
1595
+			);
1596
+
1597
+			while (list($k, $sep) = each($m[1])) {
1598
+				if ($sep === '.' || $sep === '[' || $sep === '') {
1599
+					if (is_array($cur) === false) {
1600
+						$cur = array();
1601
+					}
1602
+					$cur = &$cur[$m[2][$k]];
1603
+				} elseif ($sep === '->') {
1604
+					if (is_object($cur) === false) {
1605
+						$cur = new stdClass();
1606
+					}
1607
+					$cur = &$cur->$m[2][$k];
1608
+				} else {
1609
+					return false;
1610
+				}
1611
+			}
1612
+
1613
+			if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') {
1614
+				if (is_array($cur) === false) {
1615
+					$cur = array();
1616
+				}
1617
+				$cur[$last[1]] = $value;
1618
+			} elseif ($last[0] === '->') {
1619
+				if (is_object($cur) === false) {
1620
+					$cur = new stdClass();
1621
+				}
1622
+				$cur->$last[1] = $value;
1623
+			}
1624
+		}
1625
+
1626
+		return false;
1627
+	}
1628
+
1629
+	/**
1630
+	 * Sets the scope to the given scope string or array.
1631
+	 *
1632
+	 * @param mixed $scope    a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1633
+	 * @param bool  $absolute if true, the scope is set from the top level scope and not from the current scope
1634
+	 *
1635
+	 * @return array the current scope tree
1636
+	 */
1637
+	public function setScope($scope, $absolute = false)
1638
+	{
1639
+		$old = $this->scopeTree;
1640
+
1641
+		if (is_string($scope) === true) {
1642
+			$scope = explode('.', $scope);
1643
+		}
1644
+
1645
+		if ($absolute === true) {
1646
+			$this->scope     = &$this->data;
1647
+			$this->scopeTree = array();
1648
+		}
1649
+
1650
+		while (($bit = array_shift($scope)) !== null) {
1651
+			if ($bit === '_' || $bit === '_parent') {
1652
+				array_pop($this->scopeTree);
1653
+				$this->scope = &$this->data;
1654
+				$cnt         = count($this->scopeTree);
1655
+				for ($i = 0; $i < $cnt; ++ $i) {
1656
+					$this->scope = &$this->scope[$this->scopeTree[$i]];
1657
+				}
1658
+			} elseif ($bit === '__' || $bit === '_root') {
1659
+				$this->scope     = &$this->data;
1660
+				$this->scopeTree = array();
1661
+			} elseif (isset($this->scope[$bit])) {
1662
+				if ($this->scope instanceof ArrayAccess) {
1663
+					$tmp         = $this->scope[$bit];
1664
+					$this->scope = &$tmp;
1665
+				} else {
1666
+					$this->scope = &$this->scope[$bit];
1667
+				}
1668
+				$this->scopeTree[] = $bit;
1669
+			} else {
1670
+				unset($this->scope);
1671
+				$this->scope = null;
1672
+			}
1673
+		}
1674
+
1675
+		return $old;
1676
+	}
1677
+
1678
+	/**
1679
+	 * Returns the entire data array.
1680
+	 *
1681
+	 * @return array
1682
+	 */
1683
+	public function getData()
1684
+	{
1685
+		return $this->data;
1686
+	}
1687
+
1688
+	/**
1689
+	 * Sets a return value for the currently running template.
1690
+	 *
1691
+	 * @param string $name  var name
1692
+	 * @param mixed  $value var value
1693
+	 *
1694
+	 * @return void
1695
+	 */
1696
+	public function setReturnValue($name, $value)
1697
+	{
1698
+		$this->returnData[$name] = $value;
1699
+	}
1700
+
1701
+	/**
1702
+	 * Retrieves the return values set by the template.
1703
+	 *
1704
+	 * @return array
1705
+	 */
1706
+	public function getReturnValues()
1707
+	{
1708
+		return $this->returnData;
1709
+	}
1710
+
1711
+	/**
1712
+	 * Returns a reference to the current scope.
1713
+	 *
1714
+	 * @return mixed
1715
+	 */
1716
+	public function &getScope()
1717
+	{
1718
+		return $this->scope;
1719
+	}
1720
+
1721
+	/**
1722
+	 * Redirects all calls to unexisting to plugin proxy.
1723
+	 *
1724
+	 * @param string $method the method name
1725
+	 * @param array  $args   array of arguments
1726
+	 *
1727
+	 * @return mixed
1728
+	 * @throws Dwoo_Exception
1729
+	 */
1730
+	public function __call($method, $args)
1731
+	{
1732
+		$proxy = $this->getPluginProxy();
1733
+		if (!$proxy) {
1734
+			throw new Dwoo_Exception('Call to undefined method ' . __CLASS__ . '::' . $method . '()');
1735
+		}
1736
+
1737
+		return call_user_func_array($proxy->getCallback($method), $args);
1738
+	}
1739 1739
 }
Please login to merge, or discard this patch.
Switch Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1482,35 +1482,35 @@
 block discarded – undo
1482 1482
             array_shift($m[2]);
1483 1483
             array_shift($m[1]);
1484 1484
             switch ($m[2][0]) {
1485
-                case 'get':
1486
-                    $cur = $_GET;
1487
-                    break;
1488
-                case 'post':
1489
-                    $cur = $_POST;
1490
-                    break;
1491
-                case 'session':
1492
-                    $cur = $_SESSION;
1493
-                    break;
1494
-                case 'cookies':
1495
-                case 'cookie':
1496
-                    $cur = $_COOKIE;
1497
-                    break;
1498
-                case 'server':
1499
-                    $cur = $_SERVER;
1500
-                    break;
1501
-                case 'env':
1502
-                    $cur = $_ENV;
1503
-                    break;
1504
-                case 'request':
1505
-                    $cur = $_REQUEST;
1506
-                    break;
1507
-                case 'const':
1508
-                    array_shift($m[2]);
1509
-                    if (defined($m[2][0])) {
1510
-                        return constant($m[2][0]);
1511
-                    } else {
1512
-                        return null;
1513
-                    }
1485
+            case 'get':
1486
+                $cur = $_GET;
1487
+                break;
1488
+            case 'post':
1489
+                $cur = $_POST;
1490
+                break;
1491
+            case 'session':
1492
+                $cur = $_SESSION;
1493
+                break;
1494
+            case 'cookies':
1495
+            case 'cookie':
1496
+                $cur = $_COOKIE;
1497
+                break;
1498
+            case 'server':
1499
+                $cur = $_SERVER;
1500
+                break;
1501
+            case 'env':
1502
+                $cur = $_ENV;
1503
+                break;
1504
+            case 'request':
1505
+                $cur = $_REQUEST;
1506
+                break;
1507
+            case 'const':
1508
+                array_shift($m[2]);
1509
+                if (defined($m[2][0])) {
1510
+                    return constant($m[2][0]);
1511
+                } else {
1512
+                    return null;
1513
+                }
1514 1514
             }
1515 1515
             if ($cur !== $this->globals) {
1516 1516
                 array_shift($m[2]);
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!defined('DWOO_DIRECTORY')) {
4
-    define('DWOO_DIRECTORY', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
4
+    define('DWOO_DIRECTORY', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR);
5 5
 }
6 6
 
7 7
 /**
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
             }
375 375
 
376 376
             if ($doCache === true) {
377
-                $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*' . $dynamicId . '*/ echo \'$1\'; ?>', $out);
377
+                $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out);
378 378
                 if (!class_exists('Dwoo_plugin_dynamic')) {
379 379
                     $this->getLoader()->loadPlugin('dynamic');
380 380
                 }
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
     public function addFilter($callback, $autoload = false)
551 551
     {
552 552
         if ($autoload) {
553
-            $class = 'Dwoo_Filter_' . $callback;
553
+            $class = 'Dwoo_Filter_'.$callback;
554 554
 
555 555
             if (!class_exists($class) && !function_exists($class)) {
556 556
                 try {
@@ -558,9 +558,9 @@  discard block
 block discarded – undo
558 558
                 }
559 559
                 catch (Dwoo_Exception $e) {
560 560
                     if (strstr($callback, 'Dwoo_Filter_')) {
561
-                        throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', the "Dwoo_Filter_" prefix should not be used, please only use "' . str_replace('Dwoo_Filter_', '', $callback) . '"');
561
+                        throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"');
562 562
                     } else {
563
-                        throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
563
+                        throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
564 564
                     }
565 565
                 }
566 566
             }
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
             } elseif (function_exists($class)) {
574 574
                 $callback = $class;
575 575
             } else {
576
-                throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
576
+                throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
577 577
             }
578 578
 
579 579
             $this->filters[] = $callback;
@@ -591,12 +591,12 @@  discard block
 block discarded – undo
591 591
      */
592 592
     public function removeFilter($callback)
593 593
     {
594
-        if (($index = array_search('Dwoo_Filter_' . $callback, $this->filters, true)) !== false) {
594
+        if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) {
595 595
             unset($this->filters[$index]);
596 596
         } elseif (($index = array_search($callback, $this->filters, true)) !== false) {
597 597
             unset($this->filters[$index]);
598 598
         } else {
599
-            $class = 'Dwoo_Filter_' . $callback;
599
+            $class = 'Dwoo_Filter_'.$callback;
600 600
             foreach ($this->filters as $index => $filter) {
601 601
                 if (is_array($filter) && $filter[0] instanceof $class) {
602 602
                     unset($this->filters[$index]);
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
     public function getCacheDir()
703 703
     {
704 704
         if ($this->cacheDir === null) {
705
-            $this->setCacheDir(DWOO_DIRECTORY . 'cache' . DIRECTORY_SEPARATOR);
705
+            $this->setCacheDir(DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR);
706 706
         }
707 707
 
708 708
         return $this->cacheDir;
@@ -718,9 +718,9 @@  discard block
 block discarded – undo
718 718
      */
719 719
     public function setCacheDir($dir)
720 720
     {
721
-        $this->cacheDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
721
+        $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
722 722
         if (is_writable($this->cacheDir) === false) {
723
-            throw new Dwoo_Exception('The cache directory must be writable, chmod "' . $this->cacheDir . '" to make it writable');
723
+            throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable');
724 724
         }
725 725
     }
726 726
 
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
     public function getCompileDir()
733 733
     {
734 734
         if ($this->compileDir === null) {
735
-            $this->setCompileDir(DWOO_DIRECTORY . 'compiled' . DIRECTORY_SEPARATOR);
735
+            $this->setCompileDir(DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR);
736 736
         }
737 737
 
738 738
         return $this->compileDir;
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function setCompileDir($dir)
750 750
     {
751
-        $this->compileDir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
751
+        $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
752 752
         if (is_writable($this->compileDir) === false) {
753
-            throw new Dwoo_Exception('The compile directory must be writable, chmod "' . $this->compileDir . '" to make it writable');
753
+            throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable');
754 754
         }
755 755
     }
756 756
 
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
      */
774 774
     public function setCacheTime($seconds)
775 775
     {
776
-        $this->cacheTime = (int)$seconds;
776
+        $this->cacheTime = (int) $seconds;
777 777
     }
778 778
 
779 779
     /**
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
      */
798 798
     public function setCharset($charset)
799 799
     {
800
-        $this->charset = strtolower((string)$charset);
800
+        $this->charset = strtolower((string) $charset);
801 801
     }
802 802
 
803 803
     /**
@@ -934,11 +934,11 @@  discard block
 block discarded – undo
934 934
     public function clearCache($olderThan = - 1)
935 935
     {
936 936
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getCacheDir()), \RecursiveIteratorIterator::SELF_FIRST);
937
-        $expired  = time() - $olderThan;
937
+        $expired  = time()-$olderThan;
938 938
         $count    = 0;
939 939
         foreach ($iterator as $file) {
940 940
             if ($file->isFile() && $file->getCTime() < $expired) {
941
-                $count += unlink((string)$file) ? 1 : 0;
941
+                $count += unlink((string) $file) ? 1 : 0;
942 942
             }
943 943
         }
944 944
 
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
             ), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate);
969 969
         }
970 970
 
971
-        throw new Dwoo_Exception('Unknown resource type : ' . $resourceName);
971
+        throw new Dwoo_Exception('Unknown resource type : '.$resourceName);
972 972
     }
973 973
 
974 974
     /**
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
         if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
1069 1069
             $tplIdentifier = $this->template->getResourceName();
1070 1070
         }
1071
-        trigger_error('Dwoo error (in ' . $tplIdentifier . ') : ' . $message, $level);
1071
+        trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message, $level);
1072 1072
     }
1073 1073
 
1074 1074
     /**
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
         if (isset($this->plugins[$blockName])) {
1085 1085
             $class = $this->plugins[$blockName]['class'];
1086 1086
         } else {
1087
-            $class = 'Dwoo_Plugin_' . $blockName;
1087
+            $class = 'Dwoo_Plugin_'.$blockName;
1088 1088
         }
1089 1089
 
1090 1090
         if ($this->curBlock !== null) {
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
     {
1180 1180
         $index = array_search($block, $this->stack, true);
1181 1181
         if ($index !== false && $index > 0) {
1182
-            return $this->stack[$index - 1];
1182
+            return $this->stack[$index-1];
1183 1183
         }
1184 1184
 
1185 1185
         return false;
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
         if (isset($this->plugins[$type])) {
1198 1198
             $type = $this->plugins[$type]['class'];
1199 1199
         } else {
1200
-            $type = 'Dwoo_Plugin_' . str_replace('Dwoo_Plugin_', '', $type);
1200
+            $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type);
1201 1201
         }
1202 1202
 
1203 1203
         $keys = array_keys($this->stack);
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
      */
1239 1239
     public function classCall($plugName, array $params = array())
1240 1240
     {
1241
-        $class = 'Dwoo_Plugin_' . $plugName;
1241
+        $class = 'Dwoo_Plugin_'.$plugName;
1242 1242
 
1243 1243
         $plugin = $this->getObjectPlugin($class);
1244 1244
 
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 
1292 1292
                 if (is_string($callback) === false) {
1293 1293
                     while (($i = array_shift($keys)) !== null) {
1294
-                        $out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1294
+                        $out[] = call_user_func_array($callback, array(1 => $items[$i])+$params);
1295 1295
                     }
1296 1296
                 } elseif ($cnt === 1) {
1297 1297
                     while (($i = array_shift($keys)) !== null) {
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
                     }
1308 1308
                 } else {
1309 1309
                     while (($i = array_shift($keys)) !== null) {
1310
-                        $out[] = call_user_func_array($callback, array(1 => $items[$i]) + $params);
1310
+                        $out[] = call_user_func_array($callback, array(1 => $items[$i])+$params);
1311 1311
                     }
1312 1312
                 }
1313 1313
             } else {
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
 
1317 1317
                 if (is_string($callback) === false) {
1318 1318
                     while (($i = array_shift($keys)) !== null) {
1319
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1319
+                        $out[] = call_user_func_array($callback, array($items[$i])+$params);
1320 1320
                     }
1321 1321
                 } elseif ($cnt === 1) {
1322 1322
                     while (($i = array_shift($keys)) !== null) {
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
                     }
1337 1337
                 } else {
1338 1338
                     while (($i = array_shift($keys)) !== null) {
1339
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1339
+                        $out[] = call_user_func_array($callback, array($items[$i])+$params);
1340 1340
                     }
1341 1341
                 }
1342 1342
             }
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
         $tree = $this->scopeTree;
1407 1407
         $cur  = $this->data;
1408 1408
 
1409
-        while ($parentLevels -- !== 0) {
1409
+        while ($parentLevels-- !== 0) {
1410 1410
             array_pop($tree);
1411 1411
         }
1412 1412
 
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
                 } elseif ($varstr === '__' || $varstr === '_root') {
1445 1445
                     return $this->data;
1446 1446
                 } elseif ($varstr === '_' || $varstr === '_parent') {
1447
-                    $varstr = '.' . $varstr;
1447
+                    $varstr = '.'.$varstr;
1448 1448
                     $tree   = $this->scopeTree;
1449 1449
                     $cur    = $this->data;
1450 1450
                     array_pop($tree);
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
             }
1471 1471
 
1472 1472
             if (substr($varstr, 0, 1) === '.') {
1473
-                $varstr = 'dwoo' . $varstr;
1473
+                $varstr = 'dwoo'.$varstr;
1474 1474
             }
1475 1475
 
1476 1476
             preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
@@ -1580,7 +1580,7 @@  discard block
 block discarded – undo
1580 1580
         $data = &$this->data;
1581 1581
 
1582 1582
         if (!is_string($scope)) {
1583
-            $this->triggerError('Assignments must be done into strings, (' . gettype($scope) . ') ' . var_export($scope, true) . ' given', E_USER_ERROR);
1583
+            $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR);
1584 1584
         }
1585 1585
         if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
1586 1586
             $this->scope[$scope] = $value;
@@ -1731,7 +1731,7 @@  discard block
 block discarded – undo
1731 1731
     {
1732 1732
         $proxy = $this->getPluginProxy();
1733 1733
         if (!$proxy) {
1734
-            throw new Dwoo_Exception('Call to undefined method ' . __CLASS__ . '::' . $method . '()');
1734
+            throw new Dwoo_Exception('Call to undefined method '.__CLASS__.'::'.$method.'()');
1735 1735
         }
1736 1736
 
1737 1737
         return call_user_func_array($proxy->getCallback($method), $args);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -555,8 +555,7 @@
 block discarded – undo
555 555
             if (!class_exists($class) && !function_exists($class)) {
556 556
                 try {
557 557
                     $this->getLoader()->loadPlugin($callback);
558
-                }
559
-                catch (Dwoo_Exception $e) {
558
+                } catch (Dwoo_Exception $e) {
560 559
                     if (strstr($callback, 'Dwoo_Filter_')) {
561 560
                         throw new Dwoo_Exception('Wrong filter name : ' . $callback . ', the "Dwoo_Filter_" prefix should not be used, please only use "' . str_replace('Dwoo_Filter_', '', $callback) . '"');
562 561
                     } else {
Please login to merge, or discard this patch.
lib/Dwoo/Compilation/Exception.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,23 +19,23 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Compilation_Exception extends Dwoo_Exception
21 21
 {
22
-    protected $compiler;
23
-    protected $template;
22
+	protected $compiler;
23
+	protected $template;
24 24
 
25
-    public function __construct(Dwoo_Compiler $compiler, $message)
26
-    {
27
-        $this->compiler = $compiler;
28
-        $this->template = $compiler->getDwoo()->getTemplate();
29
-        parent::__construct('Compilation error at line '.$compiler->getLine().' in "'.$this->template->getResourceName().':'.$this->template->getResourceIdentifier().'" : '.$message);
30
-    }
25
+	public function __construct(Dwoo_Compiler $compiler, $message)
26
+	{
27
+		$this->compiler = $compiler;
28
+		$this->template = $compiler->getDwoo()->getTemplate();
29
+		parent::__construct('Compilation error at line '.$compiler->getLine().' in "'.$this->template->getResourceName().':'.$this->template->getResourceIdentifier().'" : '.$message);
30
+	}
31 31
 
32
-    public function getCompiler()
33
-    {
34
-        return $this->compiler;
35
-    }
32
+	public function getCompiler()
33
+	{
34
+		return $this->compiler;
35
+	}
36 36
 
37
-    public function getTemplate()
38
-    {
39
-        return $this->template;
40
-    }
37
+	public function getTemplate()
38
+	{
39
+		return $this->template;
40
+	}
41 41
 }
Please login to merge, or discard this patch.
lib/Dwoo/IPluginProxy.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -20,53 +20,53 @@
 block discarded – undo
20 20
  */
21 21
 interface Dwoo_IPluginProxy
22 22
 {
23
-    /**
24
-     * returns true or false to say whether the given plugin is handled by this proxy or not.
25
-     *
26
-     * @param string $name the plugin name
27
-     *
28
-     * @return bool true if the plugin is known and usable, otherwise false
29
-     */
30
-    public function handles($name);
23
+	/**
24
+	 * returns true or false to say whether the given plugin is handled by this proxy or not.
25
+	 *
26
+	 * @param string $name the plugin name
27
+	 *
28
+	 * @return bool true if the plugin is known and usable, otherwise false
29
+	 */
30
+	public function handles($name);
31 31
 
32
-    /**
33
-     * returns the code (as a string) to call the plugin
34
-     * (this will be executed at runtime inside the Dwoo class).
35
-     *
36
-     * @param string $name   the plugin name
37
-     * @param array  $params a parameter array, array key "*" is the rest array
38
-     *
39
-     * @return string
40
-     */
41
-    public function getCode($name, $params);
32
+	/**
33
+	 * returns the code (as a string) to call the plugin
34
+	 * (this will be executed at runtime inside the Dwoo class).
35
+	 *
36
+	 * @param string $name   the plugin name
37
+	 * @param array  $params a parameter array, array key "*" is the rest array
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function getCode($name, $params);
42 42
 
43
-    /**
44
-     * returns a callback to the plugin, this is used with the reflection API to
45
-     * find out about the plugin's parameter names etc.
46
-     *
47
-     * should you need a rest array without the possibility to edit the
48
-     * plugin's code, you can provide a callback to some
49
-     * other function with the correct parameter signature, i.e. :
50
-     * <code>
51
-     * return array($this, "callbackHelper");
52
-     * // and callbackHelper would be as such:
53
-     * public function callbackHelper(array $rest=array()){}
54
-     * </code>
55
-     *
56
-     * @param string $name the plugin name
57
-     *
58
-     * @return callback
59
-     */
60
-    public function getCallback($name);
43
+	/**
44
+	 * returns a callback to the plugin, this is used with the reflection API to
45
+	 * find out about the plugin's parameter names etc.
46
+	 *
47
+	 * should you need a rest array without the possibility to edit the
48
+	 * plugin's code, you can provide a callback to some
49
+	 * other function with the correct parameter signature, i.e. :
50
+	 * <code>
51
+	 * return array($this, "callbackHelper");
52
+	 * // and callbackHelper would be as such:
53
+	 * public function callbackHelper(array $rest=array()){}
54
+	 * </code>
55
+	 *
56
+	 * @param string $name the plugin name
57
+	 *
58
+	 * @return callback
59
+	 */
60
+	public function getCallback($name);
61 61
 
62
-    /**
63
-     * returns some code that will check if the plugin is loaded and if not load it
64
-     * this is optional, if your plugins are autoloaded or whatever, just return an
65
-     * empty string.
66
-     *
67
-     * @param string $name the plugin name
68
-     *
69
-     * @return string
70
-     */
71
-    public function getLoader($name);
62
+	/**
63
+	 * returns some code that will check if the plugin is loaded and if not load it
64
+	 * this is optional, if your plugins are autoloaded or whatever, just return an
65
+	 * empty string.
66
+	 *
67
+	 * @param string $name the plugin name
68
+	 *
69
+	 * @return string
70
+	 */
71
+	public function getLoader($name);
72 72
 }
Please login to merge, or discard this patch.
lib/Dwoo/Block/Plugin.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -22,88 +22,88 @@
 block discarded – undo
22 22
  */
23 23
 abstract class Dwoo_Block_Plugin extends Dwoo_Plugin
24 24
 {
25
-    /**
26
-     * stores the contents of the block while it runs.
27
-     *
28
-     * @var string
29
-     */
30
-    protected $buffer = '';
25
+	/**
26
+	 * stores the contents of the block while it runs.
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $buffer = '';
31 31
 
32
-    /**
33
-     * buffers input, override only if necessary.
34
-     *
35
-     * @var string the content that must be buffered
36
-     */
37
-    public function buffer($input)
38
-    {
39
-        $this->buffer .= $input;
40
-    }
32
+	/**
33
+	 * buffers input, override only if necessary.
34
+	 *
35
+	 * @var string the content that must be buffered
36
+	 */
37
+	public function buffer($input)
38
+	{
39
+		$this->buffer .= $input;
40
+	}
41 41
 
42
-    // initialization code, receives the parameters from {block param1 param2}
43
-    // public function init($arg, $arg, ...);
42
+	// initialization code, receives the parameters from {block param1 param2}
43
+	// public function init($arg, $arg, ...);
44 44
 
45
-    /**
46
-     * called when the block ends, this is most of the time followed right away by a call
47
-     * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
48
-     * block object, if required.
49
-     */
50
-    public function end()
51
-    {
52
-    }
45
+	/**
46
+	 * called when the block ends, this is most of the time followed right away by a call
47
+	 * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
48
+	 * block object, if required.
49
+	 */
50
+	public function end()
51
+	{
52
+	}
53 53
 
54
-    /**
55
-     * called when the block output is required by a parent block.
56
-     *
57
-     * this must read $this->buffer and return it processed
58
-     *
59
-     * @return string
60
-     */
61
-    public function process()
62
-    {
63
-        return $this->buffer;
64
-    }
54
+	/**
55
+	 * called when the block output is required by a parent block.
56
+	 *
57
+	 * this must read $this->buffer and return it processed
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public function process()
62
+	{
63
+		return $this->buffer;
64
+	}
65 65
 
66
-    /**
67
-     * called at compile time to define what the block should output in the compiled template code, happens when the block is declared
68
-     * basically this will replace the {block arg arg arg} tag in the template.
69
-     *
70
-     * @param Dwoo_Compiler $compiler the compiler instance that calls this function
71
-     * @param array         $params   an array containing original and compiled parameters
72
-     * @param string        $prepend  that is just meant to allow a child class to call
73
-     *                                parent::postProcessing($compiler, $params, "foo();") to add a command before the
74
-     *                                default commands are executed
75
-     * @param string        $append   that is just meant to allow a child class to call
76
-     *                                parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
77
-     *                                default commands are executed
78
-     * @param string        $type     the type is the plugin class name used
79
-     *
80
-     * @return string
81
-     */
82
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
83
-    {
84
-        return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.Dwoo_Compiler::implode_r($compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;
85
-    }
66
+	/**
67
+	 * called at compile time to define what the block should output in the compiled template code, happens when the block is declared
68
+	 * basically this will replace the {block arg arg arg} tag in the template.
69
+	 *
70
+	 * @param Dwoo_Compiler $compiler the compiler instance that calls this function
71
+	 * @param array         $params   an array containing original and compiled parameters
72
+	 * @param string        $prepend  that is just meant to allow a child class to call
73
+	 *                                parent::postProcessing($compiler, $params, "foo();") to add a command before the
74
+	 *                                default commands are executed
75
+	 * @param string        $append   that is just meant to allow a child class to call
76
+	 *                                parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
77
+	 *                                default commands are executed
78
+	 * @param string        $type     the type is the plugin class name used
79
+	 *
80
+	 * @return string
81
+	 */
82
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
83
+	{
84
+		return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.Dwoo_Compiler::implode_r($compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;
85
+	}
86 86
 
87
-    /**
88
-     * called at compile time to define what the block should output in the compiled template code, happens when the block is ended
89
-     * basically this will replace the {/block} tag in the template.
90
-     *
91
-     * @see preProcessing
92
-     *
93
-     * @param Dwoo_Compiler $compiler the compiler instance that calls this function
94
-     * @param array         $params   an array containing original and compiled parameters, see preProcessing() for more details
95
-     * @param string        $prepend  that is just meant to allow a child class to call
96
-     *                                parent::postProcessing($compiler, $params, "foo();") to add a command before the
97
-     *                                default commands are executed
98
-     * @param string        $append   that is just meant to allow a child class to call
99
-     *                                parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
100
-     *                                default commands are executed
101
-     * @param string        $content  the entire content of the block being closed
102
-     *
103
-     * @return string
104
-     */
105
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
106
-    {
107
-        return $content.Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;
108
-    }
87
+	/**
88
+	 * called at compile time to define what the block should output in the compiled template code, happens when the block is ended
89
+	 * basically this will replace the {/block} tag in the template.
90
+	 *
91
+	 * @see preProcessing
92
+	 *
93
+	 * @param Dwoo_Compiler $compiler the compiler instance that calls this function
94
+	 * @param array         $params   an array containing original and compiled parameters, see preProcessing() for more details
95
+	 * @param string        $prepend  that is just meant to allow a child class to call
96
+	 *                                parent::postProcessing($compiler, $params, "foo();") to add a command before the
97
+	 *                                default commands are executed
98
+	 * @param string        $append   that is just meant to allow a child class to call
99
+	 *                                parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
100
+	 *                                default commands are executed
101
+	 * @param string        $content  the entire content of the block being closed
102
+	 *
103
+	 * @return string
104
+	 */
105
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
106
+	{
107
+		return $content.Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
lib/Dwoo/ICompilable.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,6 +24,6 @@
 block discarded – undo
24 24
  */
25 25
 interface Dwoo_ICompilable
26 26
 {
27
-    // this replaces the process function
28
-    //public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...);
27
+	// this replaces the process function
28
+	//public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...);
29 29
 }
Please login to merge, or discard this patch.