Completed
Branch 1.2 (e91c8b)
by David
04:07
created
lib/Dwoo/Adapters/CodeIgniter/libraries/Dwootemplate.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
      *
90 90
      * @param string $sTemplate
91 91
      * @param boolean $return
92
-     * @return mixed
92
+     * @return null|string
93 93
      */
94 94
     public function display($sTemplate, $return = FALSE) {
95 95
         // Start benchmark
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -20,153 +20,153 @@
 block discarded – undo
20 20
  * @uses the dwoo package from http://dwoo.org
21 21
  */
22 22
 class Dwootemplate extends Dwoo_Core {
23
-    protected $dwoo_data = array();
24
-
25
-    /**
26
-     * Constructor for the DwooTemplate engine
27
-     *
28
-     */
29
-    public function __construct() {
30
-        // Call parents constructor
31
-        parent::__construct();
32
-
33
-        // Set the config settings
34
-        $this->initialize();
35
-
36
-        // Assign some defaults to dwoo
37
-        $CI                         = get_instance();
38
-        $this->dwoo_data            = new Dwoo_Data();
39
-        $this->dwoo_data->js_files  = array();
40
-        $this->dwoo_data->css_files = array();
41
-        $this->dwoo_data->CI        = $CI;
42
-        $this->dwoo_data->site_url  = $CI->config->site_url(); // so we can get the full path to CI easily
43
-        $this->dwoo_data->uniqid    = uniqid();
44
-        $this->dwoo_data->timestamp = mktime();
45
-
46
-        log_message('debug', "Dwoo Template Class Initialized");
47
-    }
48
-
49
-
50
-    /**
51
-     * Assign data to dwoo data object
52
-     *
53
-     * @param string $key
54
-     * @param mixed $value
55
-     */
56
-    public function assign($key, $value) {
57
-        $this->dwoo_data->$key = $value;
58
-    }
59
-
60
-
61
-    /**
62
-     * Add Javascript files to template
63
-     *
64
-     * @param string $js
65
-     */
66
-    public function add_js($js) {
67
-        $current   = $this->dwoo_data->js_files;
68
-        $current[] = $js;
69
-        $this->dwoo_data->js_files = $current;
70
-    }
71
-
72
-
73
-    /**
74
-     * Add Css stylesheets to template
75
-     *
76
-     * @param string $css
77
-     */
78
-    public function add_css($css) {
79
-        $current   = $this->dwoo_data->css_files;
80
-        $current[] = $css;
81
-        $this->dwoo_data->css_files = $current;
82
-    }
83
-
84
-
85
-    /**
86
-     * Display or return the compiled template
87
-     * Since we assign the results to the standard CI output module
88
-     * you can also use the helper from CI in your templates!!
89
-     *
90
-     * @param string $sTemplate
91
-     * @param boolean $return
92
-     * @return mixed
93
-     */
94
-    public function display($sTemplate, $return = FALSE) {
95
-        // Start benchmark
96
-        $CI = get_instance();
97
-        $CI->benchmark->mark('dwoo_parse_start');
98
-
99
-        // Check if file exists
100
-        if ( !file_exists($this->template_dir . $sTemplate ) ) {
101
-            $message = sprintf('Template file \'%s\' not found.', $sTemplate);
102
-            show_error($message);
103
-            log_message('error', $message);
104
-        }
105
-
106
-        // Create new template
107
-        $tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
108
-
109
-        // render the template
110
-        $template = $this->get($tpl, $this->dwoo_data);
111
-
112
-        // Finish benchmark
113
-        $CI->benchmark->mark('dwoo_parse_end');
114
-
115
-        // Return results or not ?
116
-        if ($return == FALSE) {
117
-            $CI->output->final_output = $template;
118
-        } else {
119
-            return $template;
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * Toggle Codeigniter profiler on/off
126
-     *
127
-     */
128
-    public function enable_profiler($toggle = TRUE) {
129
-        $CI = get_instance();
130
-        $CI->output->enable_profiler($toggle);
131
-    }
132
-
133
-
134
-    /**
135
-     * Set http header
136
-     *
137
-     * @example $this->output->set_header("HTTP/1.1 200 OK");
138
-     * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
139
-     * @param string $header
140
-     */
141
-    public function set_header($header) {
142
-        $CI = get_instance();
143
-        $CI->output->set_header($header);
144
-    }
145
-
146
-
147
-    /**
148
-     * Set status header
149
-     *
150
-     * @example $this->output->set_status_header('401');
151
-     * @example // Sets the header as: Unauthorized
152
-     * @param string $header
153
-     */
154
-    public function set_status_header($header) {
155
-        $CI = get_instance();
156
-        $CI->output->set_status_header($header);
157
-    }
158
-
159
-
160
-    /**
161
-     * Assign the dwootemplate config items to the instance
162
-     *
163
-     */
164
-    private function initialize() {
165
-        $CI = get_instance();
166
-        $CI->config->load('dwootemplate', TRUE);
167
-        $config = $CI->config->item('dwootemplate');
168
-        foreach ($config as $key => $val) {
169
-                $this->$key = $val;
170
-        }
171
-    }
23
+	protected $dwoo_data = array();
24
+
25
+	/**
26
+	 * Constructor for the DwooTemplate engine
27
+	 *
28
+	 */
29
+	public function __construct() {
30
+		// Call parents constructor
31
+		parent::__construct();
32
+
33
+		// Set the config settings
34
+		$this->initialize();
35
+
36
+		// Assign some defaults to dwoo
37
+		$CI                         = get_instance();
38
+		$this->dwoo_data            = new Dwoo_Data();
39
+		$this->dwoo_data->js_files  = array();
40
+		$this->dwoo_data->css_files = array();
41
+		$this->dwoo_data->CI        = $CI;
42
+		$this->dwoo_data->site_url  = $CI->config->site_url(); // so we can get the full path to CI easily
43
+		$this->dwoo_data->uniqid    = uniqid();
44
+		$this->dwoo_data->timestamp = mktime();
45
+
46
+		log_message('debug', "Dwoo Template Class Initialized");
47
+	}
48
+
49
+
50
+	/**
51
+	 * Assign data to dwoo data object
52
+	 *
53
+	 * @param string $key
54
+	 * @param mixed $value
55
+	 */
56
+	public function assign($key, $value) {
57
+		$this->dwoo_data->$key = $value;
58
+	}
59
+
60
+
61
+	/**
62
+	 * Add Javascript files to template
63
+	 *
64
+	 * @param string $js
65
+	 */
66
+	public function add_js($js) {
67
+		$current   = $this->dwoo_data->js_files;
68
+		$current[] = $js;
69
+		$this->dwoo_data->js_files = $current;
70
+	}
71
+
72
+
73
+	/**
74
+	 * Add Css stylesheets to template
75
+	 *
76
+	 * @param string $css
77
+	 */
78
+	public function add_css($css) {
79
+		$current   = $this->dwoo_data->css_files;
80
+		$current[] = $css;
81
+		$this->dwoo_data->css_files = $current;
82
+	}
83
+
84
+
85
+	/**
86
+	 * Display or return the compiled template
87
+	 * Since we assign the results to the standard CI output module
88
+	 * you can also use the helper from CI in your templates!!
89
+	 *
90
+	 * @param string $sTemplate
91
+	 * @param boolean $return
92
+	 * @return mixed
93
+	 */
94
+	public function display($sTemplate, $return = FALSE) {
95
+		// Start benchmark
96
+		$CI = get_instance();
97
+		$CI->benchmark->mark('dwoo_parse_start');
98
+
99
+		// Check if file exists
100
+		if ( !file_exists($this->template_dir . $sTemplate ) ) {
101
+			$message = sprintf('Template file \'%s\' not found.', $sTemplate);
102
+			show_error($message);
103
+			log_message('error', $message);
104
+		}
105
+
106
+		// Create new template
107
+		$tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
108
+
109
+		// render the template
110
+		$template = $this->get($tpl, $this->dwoo_data);
111
+
112
+		// Finish benchmark
113
+		$CI->benchmark->mark('dwoo_parse_end');
114
+
115
+		// Return results or not ?
116
+		if ($return == FALSE) {
117
+			$CI->output->final_output = $template;
118
+		} else {
119
+			return $template;
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * Toggle Codeigniter profiler on/off
126
+	 *
127
+	 */
128
+	public function enable_profiler($toggle = TRUE) {
129
+		$CI = get_instance();
130
+		$CI->output->enable_profiler($toggle);
131
+	}
132
+
133
+
134
+	/**
135
+	 * Set http header
136
+	 *
137
+	 * @example $this->output->set_header("HTTP/1.1 200 OK");
138
+	 * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
139
+	 * @param string $header
140
+	 */
141
+	public function set_header($header) {
142
+		$CI = get_instance();
143
+		$CI->output->set_header($header);
144
+	}
145
+
146
+
147
+	/**
148
+	 * Set status header
149
+	 *
150
+	 * @example $this->output->set_status_header('401');
151
+	 * @example // Sets the header as: Unauthorized
152
+	 * @param string $header
153
+	 */
154
+	public function set_status_header($header) {
155
+		$CI = get_instance();
156
+		$CI->output->set_status_header($header);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Assign the dwootemplate config items to the instance
162
+	 *
163
+	 */
164
+	private function initialize() {
165
+		$CI = get_instance();
166
+		$CI->config->load('dwootemplate', TRUE);
167
+		$config = $CI->config->item('dwootemplate');
168
+		foreach ($config as $key => $val) {
169
+				$this->$key = $val;
170
+		}
171
+	}
172 172
 }
173 173
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,14 +97,14 @@
 block discarded – undo
97 97
         $CI->benchmark->mark('dwoo_parse_start');
98 98
 
99 99
         // Check if file exists
100
-        if ( !file_exists($this->template_dir . $sTemplate ) ) {
100
+        if (!file_exists($this->template_dir.$sTemplate)) {
101 101
             $message = sprintf('Template file \'%s\' not found.', $sTemplate);
102 102
             show_error($message);
103 103
             log_message('error', $message);
104 104
         }
105 105
 
106 106
         // Create new template
107
-        $tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
107
+        $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate);
108 108
 
109 109
         // render the template
110 110
         $template = $this->get($tpl, $this->dwoo_data);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
1
+<?php if (!defined('BASEPATH')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 
3 5
 require "dwoo/dwooAutoload.php";
4 6
 
Please login to merge, or discard this patch.
lib/Dwoo/Adapters/ZendFramework/PluginProxy.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
 	/**
29 29
 	 * Dwoo_Adapters_ZendFramework_PluginProxy's constructor.
30 30
 	 *
31
-	 * @param Zend_View_Interface $view
31
+	 * @param Dwoo_Adapters_ZendFramework_View $view
32 32
 	 */
33 33
 	public function __construct(Zend_View_Interface $view) {
34 34
 		$this->view = $view;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
 	 * @return string
60 60
 	 */
61 61
 	public function getCode($name, $params) {
62
-		return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($params).')';
62
+		return '$this->getPluginProxy()->view->'.$name.'('.Dwoo_Compiler::implode_r($params).')';
63 63
 	}
64 64
 
65 65
 	/**
Please login to merge, or discard this patch.
lib/Dwoo/Data.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,6 @@
 block discarded – undo
66 66
 	 * merges the given array(s) with the current data with array_merge
67 67
 	 *
68 68
 	 * @param array $data the array to merge
69
-	 * @param array $data2 $data3 ... other arrays to merge, optional, etc.
70 69
 	 */
71 70
 	public function mergeData(array $data)
72 71
 	{
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,8 +45,9 @@  discard block
 block discarded – undo
45 45
 		if ($name === null) {
46 46
 			$this->data = array();
47 47
 		} elseif (is_array($name)) {
48
-			foreach ($name as $index)
49
-				unset($this->data[$index]);
48
+			foreach ($name as $index) {
49
+							unset($this->data[$index]);
50
+			}
50 51
 		} else {
51 52
 			unset($this->data[$name]);
52 53
 		}
@@ -90,8 +91,9 @@  discard block
 block discarded – undo
90 91
 	{
91 92
 		if (is_array($name)) {
92 93
 			reset($name);
93
-			while (list($k,$v) = each($name))
94
-				$this->data[$k] = $v;
94
+			while (list($k,$v) = each($name)) {
95
+							$this->data[$k] = $v;
96
+			}
95 97
 		} else {
96 98
 			$this->data[$name] = $val;
97 99
 		}
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	{
93 93
 		if (is_array($name)) {
94 94
 			reset($name);
95
-			while (list($k,$v) = each($name))
95
+			while (list($k, $v) = each($name))
96 96
 				$this->data[$k] = $v;
97 97
 		} else {
98 98
 			$this->data[$name] = $val;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 */
120 120
 	public function assignByRef($name, &$val)
121 121
 	{
122
-		$this->data[$name] =& $val;
122
+		$this->data[$name] = & $val;
123 123
 	}
124 124
 
125 125
 	/**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				}
141 141
 
142 142
 				if ($merge === true && is_array($val)) {
143
-					$this->data[$key] = $val + $this->data[$key];
143
+					$this->data[$key] = $val+$this->data[$key];
144 144
 				} else {
145 145
 					$this->data[$key][] = $val;
146 146
 				}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			}
154 154
 
155 155
 			if ($merge === true && is_array($val)) {
156
-				$this->data[$name] = $val + $this->data[$name];
156
+				$this->data[$name] = $val+$this->data[$name];
157 157
 			} else {
158 158
 				$this->data[$name][] = $val;
159 159
 			}
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 
177 177
    		if ($merge === true && is_array($val)) {
178 178
    			foreach ($val as $key => &$value) {
179
-   				$this->data[$name][$key] =& $value;
179
+   				$this->data[$name][$key] = & $value;
180 180
    			}
181 181
    		} else {
182
-   			$this->data[$name][] =& $val;
182
+   			$this->data[$name][] = & $val;
183 183
    		}
184 184
    	}
185 185
    	
Please login to merge, or discard this patch.
lib/Dwoo/ICompiler.php 1 patch
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	/**
25 25
 	 * compiles the provided string down to php code
26 26
 	 *
27
-	 * @param string $templateStr the template to compile
27
+	 * @param string $template the template to compile
28 28
 	 * @return string a compiled php code string
29 29
 	 */
30 30
 	public function compile(Dwoo_Core $dwoo, Dwoo_ITemplate $template);
@@ -34,6 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @see Dwoo_Core::addPlugin
36 36
 	 * @param array $customPlugins an array of custom plugins
37
+	 * @return void
37 38
 	 */
38 39
 	public function setCustomPlugins(array $customPlugins);
39 40
 
@@ -44,6 +45,7 @@  discard block
 block discarded – undo
44 45
 	 * set it on the Dwoo object as it will be passed onto the compiler automatically
45 46
 	 *
46 47
 	 * @param Dwoo_Security_Policy $policy the security policy object
48
+	 * @return void
47 49
 	 */
48 50
 	public function setSecurityPolicy(Dwoo_Security_Policy $policy = null);
49 51
 }
Please login to merge, or discard this patch.
lib/Dwoo/Loader.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -42,6 +42,9 @@
 block discarded – undo
42 42
 
43 43
 	protected $corePluginDir;
44 44
 
45
+	/**
46
+	 * @param string $cacheDir
47
+	 */
45 48
 	public function __construct($cacheDir)
46 49
 	{
47 50
 		$this->corePluginDir = DWOO_DIRECTORY . 'plugins';
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -44,14 +44,14 @@  discard block
 block discarded – undo
44 44
 
45 45
 	public function __construct($cacheDir)
46 46
 	{
47
-		$this->corePluginDir = DWOO_DIRECTORY . 'plugins';
48
-		$this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
47
+		$this->corePluginDir = DWOO_DIRECTORY.'plugins';
48
+		$this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
49 49
 
50 50
 		// include class paths or rebuild paths if the cache file isn't there
51 51
 		$cacheFile = $this->cacheDir.'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php';
52 52
 		if (file_exists($cacheFile)) {
53 53
 			$classpath = file_get_contents($cacheFile);
54
-			$this->classPath = unserialize($classpath) + $this->classPath;
54
+			$this->classPath = unserialize($classpath)+$this->classPath;
55 55
 		} else {
56 56
 			$this->rebuildClassPathCache($this->corePluginDir, $cacheFile);
57 57
 		}
@@ -65,25 +65,25 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	protected function rebuildClassPathCache($path, $cacheFile)
67 67
 	{
68
-		if ($cacheFile!==false) {
68
+		if ($cacheFile !== false) {
69 69
 			$tmp = $this->classPath;
70 70
 			$this->classPath = array();
71 71
 		}
72 72
 
73 73
 		// iterates over all files/folders
74
-		$list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*');
74
+		$list = glob(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'*');
75 75
 		if (is_array($list)) {
76 76
 			foreach ($list as $f) {
77 77
 				if (is_dir($f)) {
78 78
 					$this->rebuildClassPathCache($f, false);
79 79
 				} else {
80
-					$this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f;
80
+					$this->classPath[str_replace(array('function.', 'block.', 'modifier.', 'outputfilter.', 'filter.', 'prefilter.', 'postfilter.', 'pre.', 'post.', 'output.', 'shared.', 'helper.'), '', basename($f, '.php'))] = $f;
81 81
 				}
82 82
 			}
83 83
 		}
84 84
 
85 85
 		// save in file if it's the first call (not recursed)
86
-		if ($cacheFile!==false) {
86
+		if ($cacheFile !== false) {
87 87
 			if (!file_put_contents($cacheFile, serialize($this->classPath))) {
88 88
 				throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
89 89
 			}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			!(include $this->classPath[$class]))
110 110
 		{
111 111
 			if ($forceRehash) {
112
-				$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php');
112
+				$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir.'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php');
113 113
 				foreach ($this->paths as $path=>$file) {
114 114
 					$this->rebuildClassPathCache($path, $file);
115 115
 				}
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 		if (!$pluginDir) {
143 143
 			throw new Dwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory);
144 144
 		}
145
-		$cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo_Core::RELEASE_TAG.'.php';
145
+		$cacheFile = $this->cacheDir.'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo_Core::RELEASE_TAG.'.php';
146 146
 		$this->paths[$pluginDir] = $cacheFile;
147 147
 		if (file_exists($cacheFile)) {
148 148
 			$classpath = file_get_contents($cacheFile);
149
-			$this->classPath = unserialize($classpath) + $this->classPath;
149
+			$this->classPath = unserialize($classpath)+$this->classPath;
150 150
 		} else {
151 151
 			$this->rebuildClassPathCache($pluginDir, $cacheFile);
152 152
 		}
Please login to merge, or discard this patch.
lib/Dwoo/Template/String.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -278,7 +278,7 @@
 block discarded – undo
278 278
 	 *
279 279
 	 * @param Dwoo_Core $dwoo the dwoo instance that requests it
280 280
 	 * @param string $output the template output
281
-	 * @return mixed full path of the cached file or false upon failure
281
+	 * @return false|string full path of the cached file or false upon failure
282 282
 	 */
283 283
 	public function cache(Dwoo_Core $dwoo, $output)
284 284
 	{
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		if (isset(self::$cache['cached'][$this->cacheId]) === true && file_exists($cachedFile)) {
268 268
 			// already checked, return cache file
269 269
 			return $cachedFile;
270
-		} elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === -1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME'] - $cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($dwoo))) {
270
+		} elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === -1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME']-$cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($dwoo))) {
271 271
 			// cache is still valid and can be loaded
272 272
 			self::$cache['cached'][$this->cacheId] = true;
273 273
 			return $cachedFile;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		// thanks for his help on avoiding concurency issues
294 294
 		$temp = tempnam($cacheDir, 'temp');
295 295
 		if (!($file = @fopen($temp, 'wb'))) {
296
-			$temp = $cacheDir . uniqid('temp');
296
+			$temp = $cacheDir.uniqid('temp');
297 297
 			if (!($file = @fopen($temp, 'wb'))) {
298 298
 				trigger_error('Error writing temporary file \''.$temp.'\'', E_USER_WARNING);
299 299
 				return false;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	{
330 330
 		$cachedFile = $this->getCacheFilename($dwoo);
331 331
 
332
-		return !file_exists($cachedFile) || (filectime($cachedFile) < (time() - $olderThan) && unlink($cachedFile));
332
+		return !file_exists($cachedFile) || (filectime($cachedFile) < (time()-$olderThan) && unlink($cachedFile));
333 333
 	}
334 334
 
335 335
 	/**
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
 	protected function getCompiledFilename(Dwoo_Core $dwoo)
427 427
 	{
428 428
 		// no compile id was provided, set default
429
-		if ($this->compileId===null) {
429
+		if ($this->compileId === null) {
430 430
 			$this->compileId = $this->name;
431 431
 		}
432
-		return $dwoo->getCompileDir() . $this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
432
+		return $dwoo->getCompileDir().$this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
433 433
 	}
434 434
 
435 435
 	/**
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
 			// force compiled id generation
454 454
 			$this->getCompiledFilename($dwoo);
455 455
 
456
-			$this->cacheId = str_replace('../', '__', $this->compileId . strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
456
+			$this->cacheId = str_replace('../', '__', $this->compileId.strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
457 457
 		}
458
-		return $dwoo->getCacheDir() . $this->cacheId.'.html';
458
+		return $dwoo->getCacheDir().$this->cacheId.'.html';
459 459
 	}
460 460
 
461 461
 	/**
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 			$path = strtr(str_replace($baseDir, '', $path), '\\', '/');
505 505
 			$folders = explode('/', trim($path, '/'));
506 506
 			foreach ($folders as $folder) {
507
-				$baseDir .= $folder . DIRECTORY_SEPARATOR;
507
+				$baseDir .= $folder.DIRECTORY_SEPARATOR;
508 508
 				if (!chmod($baseDir, $chmod))
509 509
 				{
510 510
 					throw new Exception("Unable to chmod ".
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/dynamic.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -53,6 +53,10 @@
 block discarded – undo
53 53
 		return $output;
54 54
 	}
55 55
 
56
+	/**
57
+	 * @param string $dynamicId
58
+	 * @param string $compiledFile
59
+	 */
56 60
 	public static function unescape($output, $dynamicId, $compiledFile)
57 61
 	{
58 62
 		$output = preg_replace_callback('/<dwoo:dynamic_('.$dynamicId.')>(.+?)<\/dwoo:dynamic_'.$dynamicId.'>/s', array('self', 'unescapePhp'), $output, -1, $count);
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,23 +32,23 @@
 block discarded – undo
32 32
 			return $content;
33 33
 		} catch (Dwoo_Compilation_Exception $e) {
34 34
 		}
35
-		$output = Dwoo_Compiler::PHP_OPEN .
35
+		$output = Dwoo_Compiler::PHP_OPEN.
36 36
 			'if($doCache) {'."\n\t".
37 37
 				'echo \'<dwoo:dynamic_\'.$dynamicId.\'>'.
38
-				str_replace('\'', '\\\'', $content) .
38
+				str_replace('\'', '\\\'', $content).
39 39
 				'</dwoo:dynamic_\'.$dynamicId.\'>\';'.
40 40
 			"\n} else {\n\t";
41
-				if(substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
41
+				if (substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
42 42
 					$output .= substr($content, strlen(Dwoo_Compiler::PHP_OPEN));
43 43
 				} else {
44
-					$output .= Dwoo_Compiler::PHP_CLOSE . $content;
44
+					$output .= Dwoo_Compiler::PHP_CLOSE.$content;
45 45
 				}
46
-				if(substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
46
+				if (substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
47 47
 					$output = substr($output, 0, -strlen(Dwoo_Compiler::PHP_CLOSE));
48 48
 				} else {
49 49
 					$output .= Dwoo_Compiler::PHP_OPEN;
50 50
 				}
51
-			$output .= "\n}". Dwoo_Compiler::PHP_CLOSE;
51
+			$output .= "\n}".Dwoo_Compiler::PHP_CLOSE;
52 52
 
53 53
 		return $output;
54 54
 	}
Please login to merge, or discard this patch.
lib/Dwoo/Template/File.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * @return boolean True cache file existance and it's modification time
108 108
 	 */
109 109
 	protected function isValidCompiledFile($file) {
110
-		return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file);
110
+		return parent::isValidCompiledFile($file) && (int) $this->getUid() <= filemtime($file);
111 111
 	}
112 112
 
113 113
 	/**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 			foreach ($this->includePath as $path) {
146 146
 				$path = rtrim($path, DIRECTORY_SEPARATOR);
147 147
 				if (file_exists($path.DIRECTORY_SEPARATOR.$this->file) === true) {
148
-					$this->resolvedPath = $path . DIRECTORY_SEPARATOR . $this->file;
148
+					$this->resolvedPath = $path.DIRECTORY_SEPARATOR.$this->file;
149 149
 					return $this->resolvedPath;
150 150
 				}
151 151
 			}
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
 	protected function getCompiledFilename(Dwoo_Core $dwoo)
251 251
 	{
252 252
 		// no compile id was provided, set default
253
-		if ($this->compileId===null) {
253
+		if ($this->compileId === null) {
254 254
 			$this->compileId = str_replace('../', '__', strtr($this->getResourceIdentifier(), '\\:', '/-'));
255 255
 		}
256
-		return $dwoo->getCompileDir() . $this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
256
+		return $dwoo->getCompileDir().$this->compileId.'.d'.Dwoo_Core::RELEASE_TAG.'.php';
257 257
 	}
258 258
 
259 259
 	/**
Please login to merge, or discard this patch.
lib/Dwoo/Core.php 4 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1538,8 +1538,9 @@
 block discarded – undo
1538 1538
                 array_pop($this->scopeTree);
1539 1539
                 $this->scope =& $this->data;
1540 1540
                 $cnt = count($this->scopeTree);
1541
-                for ($i=0;$i<$cnt;$i++)
1542
-                    $this->scope =& $this->scope[$this->scopeTree[$i]];
1541
+                for ($i=0;$i<$cnt;$i++) {
1542
+                                    $this->scope =& $this->scope[$this->scopeTree[$i]];
1543
+                }
1543 1544
             } elseif ($bit === '__' || $bit === '_root') {
1544 1545
                 $this->scope =& $this->data;
1545 1546
                 $this->scopeTree = array();
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1484,7 +1484,7 @@
 block discarded – undo
1484 1484
      *
1485 1485
      * @param mixed $value the value to assign
1486 1486
      * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1487
-     * @return bool true if assigned correctly or false if a problem occured while parsing the var string
1487
+     * @return null|false true if assigned correctly or false if a problem occured while parsing the var string
1488 1488
      */
1489 1489
     public function assignInScope($value, $scope)
1490 1490
     {
Please login to merge, or discard this patch.
Indentation   +1413 added lines, -1413 removed lines patch added patch discarded remove patch
@@ -33,23 +33,23 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class Dwoo_Core
35 35
 {
36
-    /**
37
-     * current version number
38
-     *
39
-     * @var string
40
-     */
41
-    const VERSION = '1.2.3';
36
+	/**
37
+	 * current version number
38
+	 *
39
+	 * @var string
40
+	 */
41
+	const VERSION = '1.2.3';
42 42
 
43
-    /**
44
-     * unique number of this dwoo release
45
-     *
46
-     * this can be used by templates classes to check whether the compiled template
47
-     * has been compiled before this release or not, so that old templates are
48
-     * recompiled automatically when Dwoo is updated
49
-     */
50
-    const RELEASE_TAG = 17;
43
+	/**
44
+	 * unique number of this dwoo release
45
+	 *
46
+	 * this can be used by templates classes to check whether the compiled template
47
+	 * has been compiled before this release or not, so that old templates are
48
+	 * recompiled automatically when Dwoo is updated
49
+	 */
50
+	const RELEASE_TAG = 17;
51 51
 
52
-    /**#@+
52
+	/**#@+
53 53
      * constants that represents all plugin types
54 54
      *
55 55
      * these are bitwise-operation-safe values to allow multiple types
@@ -57,251 +57,251 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @var int
59 59
      */
60
-    const CLASS_PLUGIN = 1;
61
-    const FUNC_PLUGIN = 2;
62
-    const NATIVE_PLUGIN = 4;
63
-    const BLOCK_PLUGIN = 8;
64
-    const COMPILABLE_PLUGIN = 16;
65
-    const CUSTOM_PLUGIN = 32;
66
-    const SMARTY_MODIFIER = 64;
67
-    const SMARTY_BLOCK = 128;
68
-    const SMARTY_FUNCTION = 256;
69
-    const PROXY_PLUGIN = 512;
70
-    const TEMPLATE_PLUGIN = 1024;
71
-    /**#@-*/
72
-
73
-    /**
74
-     * character set of the template, used by string manipulation plugins
75
-     *
76
-     * it must be lowercase, but setCharset() will take care of that
77
-     *
78
-     * @see setCharset
79
-     * @see getCharset
80
-     * @var string
81
-     */
82
-    protected $charset = 'utf-8';
60
+	const CLASS_PLUGIN = 1;
61
+	const FUNC_PLUGIN = 2;
62
+	const NATIVE_PLUGIN = 4;
63
+	const BLOCK_PLUGIN = 8;
64
+	const COMPILABLE_PLUGIN = 16;
65
+	const CUSTOM_PLUGIN = 32;
66
+	const SMARTY_MODIFIER = 64;
67
+	const SMARTY_BLOCK = 128;
68
+	const SMARTY_FUNCTION = 256;
69
+	const PROXY_PLUGIN = 512;
70
+	const TEMPLATE_PLUGIN = 1024;
71
+	/**#@-*/
83 72
 
84
-    /**
85
-     * global variables that are accessible through $dwoo.* in the templates
86
-     *
87
-     * default values include:
88
-     *
89
-     * $dwoo.version - current version number
90
-     * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org
91
-     * $dwoo.now - the current time
92
-     * $dwoo.template - the current template filename
93
-     * $dwoo.charset - the character set used by the template
94
-     *
95
-     * on top of that, foreach and other plugins can store special values in there,
96
-     * see their documentation for more details.
97
-     *
98
-     * @private
99
-     * @var array
100
-     */
101
-    public $globals;
73
+	/**
74
+	 * character set of the template, used by string manipulation plugins
75
+	 *
76
+	 * it must be lowercase, but setCharset() will take care of that
77
+	 *
78
+	 * @see setCharset
79
+	 * @see getCharset
80
+	 * @var string
81
+	 */
82
+	protected $charset = 'utf-8';
102 83
 
103
-    /**
104
-     * directory where the compiled templates are stored
105
-     *
106
-     * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)
107
-     *
108
-     * @var string
109
-     */
110
-    protected $compileDir;
84
+	/**
85
+	 * global variables that are accessible through $dwoo.* in the templates
86
+	 *
87
+	 * default values include:
88
+	 *
89
+	 * $dwoo.version - current version number
90
+	 * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org
91
+	 * $dwoo.now - the current time
92
+	 * $dwoo.template - the current template filename
93
+	 * $dwoo.charset - the character set used by the template
94
+	 *
95
+	 * on top of that, foreach and other plugins can store special values in there,
96
+	 * see their documentation for more details.
97
+	 *
98
+	 * @private
99
+	 * @var array
100
+	 */
101
+	public $globals;
111 102
 
112
-    /**
113
-     * directory where the cached templates are stored
114
-     *
115
-     * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)
116
-     *
117
-     * @var string
118
-     */
119
-    protected $cacheDir;
103
+	/**
104
+	 * directory where the compiled templates are stored
105
+	 *
106
+	 * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)
107
+	 *
108
+	 * @var string
109
+	 */
110
+	protected $compileDir;
120 111
 
121
-    /**
122
-     * defines how long (in seconds) the cached files must remain valid
123
-     *
124
-     * can be overriden on a per-template basis
125
-     *
126
-     * -1 = never delete
127
-     * 0 = disabled
128
-     * >0 = duration in seconds
129
-     *
130
-     * @var int
131
-     */
132
-    protected $cacheTime = 0;
112
+	/**
113
+	 * directory where the cached templates are stored
114
+	 *
115
+	 * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)
116
+	 *
117
+	 * @var string
118
+	 */
119
+	protected $cacheDir;
133 120
 
134
-    /**
135
-     * security policy object
136
-     *
137
-     * @var Dwoo_Security_Policy
138
-     */
139
-    protected $securityPolicy = null;
121
+	/**
122
+	 * defines how long (in seconds) the cached files must remain valid
123
+	 *
124
+	 * can be overriden on a per-template basis
125
+	 *
126
+	 * -1 = never delete
127
+	 * 0 = disabled
128
+	 * >0 = duration in seconds
129
+	 *
130
+	 * @var int
131
+	 */
132
+	protected $cacheTime = 0;
140 133
 
141
-    /**
142
-     * stores the custom plugins callbacks
143
-     *
144
-     * @see addPlugin
145
-     * @see removePlugin
146
-     * @var array
147
-     */
148
-    protected $plugins = array();
134
+	/**
135
+	 * security policy object
136
+	 *
137
+	 * @var Dwoo_Security_Policy
138
+	 */
139
+	protected $securityPolicy = null;
149 140
 
150
-    /**
151
-     * stores the filter callbacks
152
-     *
153
-     * @see addFilter
154
-     * @see removeFilter
155
-     * @var array
156
-     */
157
-    protected $filters = array();
141
+	/**
142
+	 * stores the custom plugins callbacks
143
+	 *
144
+	 * @see addPlugin
145
+	 * @see removePlugin
146
+	 * @var array
147
+	 */
148
+	protected $plugins = array();
158 149
 
159
-    /**
160
-     * stores the resource types and associated
161
-     * classes / compiler classes
162
-     *
163
-     * @var array
164
-     */
165
-    protected $resources = array
166
-    (
167
-        'file'      =>  array
168
-        (
169
-            'class'     =>  'Dwoo_Template_File',
170
-            'compiler'  =>  null
171
-        ),
172
-        'string'    =>  array
173
-        (
174
-            'class'     =>  'Dwoo_Template_String',
175
-            'compiler'  =>  null
176
-        )
177
-    );
178
-
179
-    /**
180
-     * the dwoo loader object used to load plugins by this dwoo instance
181
-     *
182
-     * @var Dwoo_ILoader
183
-     */
184
-    protected $loader = null;
150
+	/**
151
+	 * stores the filter callbacks
152
+	 *
153
+	 * @see addFilter
154
+	 * @see removeFilter
155
+	 * @var array
156
+	 */
157
+	protected $filters = array();
185 158
 
186
-    /**
187
-     * currently rendered template, set to null when not-rendering
188
-     *
189
-     * @var Dwoo_ITemplate
190
-     */
191
-    protected $template = null;
159
+	/**
160
+	 * stores the resource types and associated
161
+	 * classes / compiler classes
162
+	 *
163
+	 * @var array
164
+	 */
165
+	protected $resources = array
166
+	(
167
+		'file'      =>  array
168
+		(
169
+			'class'     =>  'Dwoo_Template_File',
170
+			'compiler'  =>  null
171
+		),
172
+		'string'    =>  array
173
+		(
174
+			'class'     =>  'Dwoo_Template_String',
175
+			'compiler'  =>  null
176
+		)
177
+	);
192 178
 
193
-    /**
194
-     * stores the instances of the class plugins during template runtime
195
-     *
196
-     * @var array
197
-     */
198
-    protected $runtimePlugins;
179
+	/**
180
+	 * the dwoo loader object used to load plugins by this dwoo instance
181
+	 *
182
+	 * @var Dwoo_ILoader
183
+	 */
184
+	protected $loader = null;
199 185
 
200
-    /**
201
-     * stores the returned values during template runtime
202
-     *
203
-     * @var array
204
-     */
205
-    protected $returnData;
186
+	/**
187
+	 * currently rendered template, set to null when not-rendering
188
+	 *
189
+	 * @var Dwoo_ITemplate
190
+	 */
191
+	protected $template = null;
206 192
 
207
-    /**
208
-     * stores the data during template runtime
209
-     *
210
-     * @var array
211
-     * @private
212
-     */
213
-    public $data;
193
+	/**
194
+	 * stores the instances of the class plugins during template runtime
195
+	 *
196
+	 * @var array
197
+	 */
198
+	protected $runtimePlugins;
214 199
 
215
-    /**
216
-     * stores the current scope during template runtime
217
-     *
218
-     * this should ideally not be accessed directly from outside template code
219
-     *
220
-     * @var mixed
221
-     * @private
222
-     */
223
-    public $scope;
200
+	/**
201
+	 * stores the returned values during template runtime
202
+	 *
203
+	 * @var array
204
+	 */
205
+	protected $returnData;
224 206
 
225
-    /**
226
-     * stores the scope tree during template runtime
227
-     *
228
-     * @var array
229
-     */
230
-    protected $scopeTree;
207
+	/**
208
+	 * stores the data during template runtime
209
+	 *
210
+	 * @var array
211
+	 * @private
212
+	 */
213
+	public $data;
231 214
 
232
-    /**
233
-     * stores the block plugins stack during template runtime
234
-     *
235
-     * @var array
236
-     */
237
-    protected $stack;
215
+	/**
216
+	 * stores the current scope during template runtime
217
+	 *
218
+	 * this should ideally not be accessed directly from outside template code
219
+	 *
220
+	 * @var mixed
221
+	 * @private
222
+	 */
223
+	public $scope;
238 224
 
239
-    /**
240
-     * stores the current block plugin at the top of the stack during template runtime
241
-     *
242
-     * @var Dwoo_Block_Plugin
243
-     */
244
-    protected $curBlock;
225
+	/**
226
+	 * stores the scope tree during template runtime
227
+	 *
228
+	 * @var array
229
+	 */
230
+	protected $scopeTree;
245 231
 
246
-    /**
247
-     * stores the output buffer during template runtime
248
-     *
249
-     * @var string
250
-     */
251
-    protected $buffer;
232
+	/**
233
+	 * stores the block plugins stack during template runtime
234
+	 *
235
+	 * @var array
236
+	 */
237
+	protected $stack;
252 238
 
253
-    /**
254
-     * stores plugin proxy
255
-     *
256
-     * @var Dwoo_IPluginProxy
257
-     */
258
-    protected $pluginProxy;
239
+	/**
240
+	 * stores the current block plugin at the top of the stack during template runtime
241
+	 *
242
+	 * @var Dwoo_Block_Plugin
243
+	 */
244
+	protected $curBlock;
259 245
 
260
-    /**
261
-     * constructor, sets the cache and compile dir to the default values if not provided
262
-     *
263
-     * @param string $compileDir path to the compiled directory, defaults to lib/compiled
264
-     * @param string $cacheDir path to the cache directory, defaults to lib/cache
265
-     */
266
-    public function __construct($compileDir = null, $cacheDir = null)
267
-    {
268
-        if ($compileDir !== null) {
269
-            $this->setCompileDir($compileDir);
270
-        }
271
-        if ($cacheDir !== null) {
272
-            $this->setCacheDir($cacheDir);
273
-        }
274
-        $this->initGlobals();
275
-    }
276
-
277
-    /**
278
-     * resets some runtime variables to allow a cloned object to be used to render sub-templates
279
-     */
280
-    public function __clone()
281
-    {
282
-        $this->template = null;
283
-        unset($this->data);
284
-        unset($this->returnData);
285
-    }
286
-
287
-    /**
288
-     * outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true)
289
-     *
290
-     * @see get
291
-     * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or
292
-     *                   a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster,
293
-     *                   especially if you render a template multiple times
294
-     * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're
295
-     *                    rendering the template from cache, it can be left null
296
-     * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default
297
-     *                                Dwoo_Compiler will be used.
298
-     * @return string nothing or the template output if $output is true
246
+	/**
247
+	 * stores the output buffer during template runtime
248
+	 *
249
+	 * @var string
250
+	 */
251
+	protected $buffer;
252
+
253
+	/**
254
+	 * stores plugin proxy
255
+	 *
256
+	 * @var Dwoo_IPluginProxy
257
+	 */
258
+	protected $pluginProxy;
259
+
260
+	/**
261
+	 * constructor, sets the cache and compile dir to the default values if not provided
262
+	 *
263
+	 * @param string $compileDir path to the compiled directory, defaults to lib/compiled
264
+	 * @param string $cacheDir path to the cache directory, defaults to lib/cache
265
+	 */
266
+	public function __construct($compileDir = null, $cacheDir = null)
267
+	{
268
+		if ($compileDir !== null) {
269
+			$this->setCompileDir($compileDir);
270
+		}
271
+		if ($cacheDir !== null) {
272
+			$this->setCacheDir($cacheDir);
273
+		}
274
+		$this->initGlobals();
275
+	}
276
+
277
+	/**
278
+	 * resets some runtime variables to allow a cloned object to be used to render sub-templates
279
+	 */
280
+	public function __clone()
281
+	{
282
+		$this->template = null;
283
+		unset($this->data);
284
+		unset($this->returnData);
285
+	}
286
+
287
+	/**
288
+	 * outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true)
289
+	 *
290
+	 * @see get
291
+	 * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or
292
+	 *                   a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster,
293
+	 *                   especially if you render a template multiple times
294
+	 * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're
295
+	 *                    rendering the template from cache, it can be left null
296
+	 * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default
297
+	 *                                Dwoo_Compiler will be used.
298
+	 * @return string nothing or the template output if $output is true
299 299
 	 * @deprecated 1.2.3. will be deleted in 1.3.0.
300
-     */
301
-    public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null)
302
-    {
303
-        return $this->get($tpl, $data, $compiler, true);
304
-    }
300
+	 */
301
+	public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null)
302
+	{
303
+		return $this->get($tpl, $data, $compiler, true);
304
+	}
305 305
 
306 306
 	/**
307 307
 	 * returns the given template rendered using the provided data and optional compiler
@@ -316,156 +316,156 @@  discard block
 block discarded – undo
316 316
 	 *                                Dwoo_Compiler will be used.
317 317
 	 * @param bool $_output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true)
318 318
 	 */
319
-    public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
320
-    {
321
-        // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one
322
-        if ($this->template instanceof Dwoo_ITemplate) {
323
-            $clone = clone $this;
324
-            return $clone->get($_tpl, $data, $_compiler, $_output);
325
-        }
326
-
327
-        // auto-create template if required
328
-        if ($_tpl instanceof Dwoo_ITemplate) {
329
-            // valid, skip
330
-        } elseif (is_string($_tpl) && file_exists($_tpl)) {
331
-            $_tpl = new Dwoo_Template_File($_tpl);
332
-        } else {
333
-            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);
334
-        }
335
-
336
-        // save the current template, enters render mode at the same time
337
-        // if another rendering is requested it will be proxied to a new Dwoo_Core(instance
338
-        $this->template = $_tpl;
339
-
340
-        // load data
341
-        if ($data instanceof Dwoo_IDataProvider) {
342
-            $this->data = $data->getData();
343
-        } elseif (is_array($data)) {
344
-            $this->data = $data;
345
-        } elseif ($data instanceof ArrayAccess) {
346
-            $this->data = $data;
347
-        } else {
348
-            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);
349
-        }
350
-
351
-        $this->globals['template'] = $_tpl->getName();
352
-        $this->initRuntimeVars($_tpl);
353
-
354
-        // try to get cached template
355
-        $file = $_tpl->getCachedTemplate($this);
356
-        $doCache = $file === true;
357
-        $cacheLoaded = is_string($file);
358
-
359
-        if ($cacheLoaded === true) {
360
-            // cache is present, run it
361
-            if ($_output === true) {
362
-                include $file;
363
-                $this->template = null;
364
-            } else {
365
-                ob_start();
366
-                include $file;
367
-                $this->template = null;
368
-                return ob_get_clean();
369
-            }
370
-        } else {
319
+	public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
320
+	{
321
+		// a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one
322
+		if ($this->template instanceof Dwoo_ITemplate) {
323
+			$clone = clone $this;
324
+			return $clone->get($_tpl, $data, $_compiler, $_output);
325
+		}
326
+
327
+		// auto-create template if required
328
+		if ($_tpl instanceof Dwoo_ITemplate) {
329
+			// valid, skip
330
+		} elseif (is_string($_tpl) && file_exists($_tpl)) {
331
+			$_tpl = new Dwoo_Template_File($_tpl);
332
+		} else {
333
+			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);
334
+		}
335
+
336
+		// save the current template, enters render mode at the same time
337
+		// if another rendering is requested it will be proxied to a new Dwoo_Core(instance
338
+		$this->template = $_tpl;
339
+
340
+		// load data
341
+		if ($data instanceof Dwoo_IDataProvider) {
342
+			$this->data = $data->getData();
343
+		} elseif (is_array($data)) {
344
+			$this->data = $data;
345
+		} elseif ($data instanceof ArrayAccess) {
346
+			$this->data = $data;
347
+		} else {
348
+			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);
349
+		}
350
+
351
+		$this->globals['template'] = $_tpl->getName();
352
+		$this->initRuntimeVars($_tpl);
353
+
354
+		// try to get cached template
355
+		$file = $_tpl->getCachedTemplate($this);
356
+		$doCache = $file === true;
357
+		$cacheLoaded = is_string($file);
358
+
359
+		if ($cacheLoaded === true) {
360
+			// cache is present, run it
361
+			if ($_output === true) {
362
+				include $file;
363
+				$this->template = null;
364
+			} else {
365
+				ob_start();
366
+				include $file;
367
+				$this->template = null;
368
+				return ob_get_clean();
369
+			}
370
+		} else {
371 371
 			$dynamicId = uniqid();
372 372
 
373
-            // render template
374
-            $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
375
-            $out = include $compiledTemplate;
376
-
377
-            // template returned false so it needs to be recompiled
378
-            if ($out === false) {
379
-                $_tpl->forceCompilation();
380
-                $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
381
-                $out = include $compiledTemplate;
382
-            }
383
-
384
-            if ($doCache === true) {
385
-
386
-                $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out);
387
-                if (!class_exists('Dwoo_plugin_dynamic')) {
388
-                    $this->getLoader()->loadPlugin('dynamic');
389
-                }
390
-                $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate);
391
-            }
392
-
393
-            // process filters
394
-            foreach ($this->filters as $filter) {
395
-                if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) {
396
-                    $out = call_user_func($filter, $out);
397
-                } else {
398
-                    $out = call_user_func($filter, $this, $out);
399
-                }
400
-            }
401
-
402
-            if ($doCache === true) {
403
-                // building cache
404
-                $file = $_tpl->cache($this, $out);
405
-
406
-                // run it from the cache to be sure dynamics are rendered
407
-                if ($_output === true) {
408
-                    include $file;
409
-                    // exit render mode
410
-                    $this->template = null;
411
-                } else {
412
-                    ob_start();
413
-                    include $file;
414
-                    // exit render mode
415
-                    $this->template = null;
416
-                    return ob_get_clean();
417
-                }
418
-            } else {
419
-                // no need to build cache
420
-                // exit render mode
421
-                $this->template = null;
422
-                // output
423
-                if ($_output === true) {
424
-                    echo $out;
425
-                }
426
-                return $out;
427
-            }
428
-        }
429
-
430
-        return '';
431
-    }
432
-
433
-    /**
434
-     * re-initializes the globals array before each template run
435
-     *
436
-     * this method is only callede once when the Dwoo object is created
437
-     */
438
-    protected function initGlobals()
439
-    {
440
-        $this->globals = array
441
-        (
442
-            'version'   =>  self::VERSION,
443
-            'ad'        =>  '<a href="http://dwoo.org/">Powered by Dwoo</a>',
444
-            'now'       =>  $_SERVER['REQUEST_TIME'],
445
-            'charset'   =>  $this->charset,
446
-        );
447
-    }
448
-
449
-    /**
450
-     * re-initializes the runtime variables before each template run
451
-     *
452
-     * override this method to inject data in the globals array if needed, this
453
-     * method is called before each template execution
454
-     *
455
-     * @param Dwoo_ITemplate $tpl the template that is going to be rendered
456
-     */
457
-    protected function initRuntimeVars(Dwoo_ITemplate $tpl)
458
-    {
459
-        $this->runtimePlugins = array();
460
-        $this->scope =& $this->data;
461
-        $this->scopeTree = array();
462
-        $this->stack = array();
463
-        $this->curBlock = null;
464
-        $this->buffer = '';
465
-        $this->returnData = array();
466
-    }
467
-
468
-    /*
373
+			// render template
374
+			$compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
375
+			$out = include $compiledTemplate;
376
+
377
+			// template returned false so it needs to be recompiled
378
+			if ($out === false) {
379
+				$_tpl->forceCompilation();
380
+				$compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler);
381
+				$out = include $compiledTemplate;
382
+			}
383
+
384
+			if ($doCache === true) {
385
+
386
+				$out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out);
387
+				if (!class_exists('Dwoo_plugin_dynamic')) {
388
+					$this->getLoader()->loadPlugin('dynamic');
389
+				}
390
+				$out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate);
391
+			}
392
+
393
+			// process filters
394
+			foreach ($this->filters as $filter) {
395
+				if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) {
396
+					$out = call_user_func($filter, $out);
397
+				} else {
398
+					$out = call_user_func($filter, $this, $out);
399
+				}
400
+			}
401
+
402
+			if ($doCache === true) {
403
+				// building cache
404
+				$file = $_tpl->cache($this, $out);
405
+
406
+				// run it from the cache to be sure dynamics are rendered
407
+				if ($_output === true) {
408
+					include $file;
409
+					// exit render mode
410
+					$this->template = null;
411
+				} else {
412
+					ob_start();
413
+					include $file;
414
+					// exit render mode
415
+					$this->template = null;
416
+					return ob_get_clean();
417
+				}
418
+			} else {
419
+				// no need to build cache
420
+				// exit render mode
421
+				$this->template = null;
422
+				// output
423
+				if ($_output === true) {
424
+					echo $out;
425
+				}
426
+				return $out;
427
+			}
428
+		}
429
+
430
+		return '';
431
+	}
432
+
433
+	/**
434
+	 * re-initializes the globals array before each template run
435
+	 *
436
+	 * this method is only callede once when the Dwoo object is created
437
+	 */
438
+	protected function initGlobals()
439
+	{
440
+		$this->globals = array
441
+		(
442
+			'version'   =>  self::VERSION,
443
+			'ad'        =>  '<a href="http://dwoo.org/">Powered by Dwoo</a>',
444
+			'now'       =>  $_SERVER['REQUEST_TIME'],
445
+			'charset'   =>  $this->charset,
446
+		);
447
+	}
448
+
449
+	/**
450
+	 * re-initializes the runtime variables before each template run
451
+	 *
452
+	 * override this method to inject data in the globals array if needed, this
453
+	 * method is called before each template execution
454
+	 *
455
+	 * @param Dwoo_ITemplate $tpl the template that is going to be rendered
456
+	 */
457
+	protected function initRuntimeVars(Dwoo_ITemplate $tpl)
458
+	{
459
+		$this->runtimePlugins = array();
460
+		$this->scope =& $this->data;
461
+		$this->scopeTree = array();
462
+		$this->stack = array();
463
+		$this->curBlock = null;
464
+		$this->buffer = '';
465
+		$this->returnData = array();
466
+	}
467
+
468
+	/*
469 469
      * --------- settings functions ---------
470 470
      */
471 471
 
@@ -478,16 +478,16 @@  discard block
 block discarded – undo
478 478
 	 * @param bool     $compilable if set to true, the plugin is assumed to be compilable
479 479
 	 * @throws Dwoo_Exception
480 480
 	 */
481
-    public function addPlugin($name, $callback, $compilable = false)
482
-    {
483
-        $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0;
484
-        if (is_array($callback)) {
485
-            if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) {
486
-                $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]));
487
-            } else {
488
-                $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]);
489
-            }
490
-        } elseif(is_string($callback)) {
481
+	public function addPlugin($name, $callback, $compilable = false)
482
+	{
483
+		$compilable = $compilable ? self::COMPILABLE_PLUGIN : 0;
484
+		if (is_array($callback)) {
485
+			if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) {
486
+				$this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]));
487
+			} else {
488
+				$this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]);
489
+			}
490
+		} elseif(is_string($callback)) {
491 491
 			if (class_exists($callback)) {
492 492
 				if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) {
493 493
 					$this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback);
@@ -502,21 +502,21 @@  discard block
 block discarded – undo
502 502
 		} elseif($callback instanceof \Closure) {
503 503
 			$this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback);
504 504
 		} else {
505
-            throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
506
-        }
507
-    }
505
+			throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
506
+		}
507
+	}
508 508
 
509
-    /**
510
-     * removes a custom plugin
511
-     *
512
-     * @param string $name the plugin name
513
-     */
514
-    public function removePlugin($name)
515
-    {
516
-        if (isset($this->plugins[$name])) {
517
-            unset($this->plugins[$name]);
518
-        }
519
-    }
509
+	/**
510
+	 * removes a custom plugin
511
+	 *
512
+	 * @param string $name the plugin name
513
+	 */
514
+	public function removePlugin($name)
515
+	{
516
+		if (isset($this->plugins[$name])) {
517
+			unset($this->plugins[$name]);
518
+		}
519
+	}
520 520
 
521 521
 	/**
522 522
 	 * adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this instance
@@ -524,58 +524,58 @@  discard block
 block discarded – undo
524 524
 	 * @param bool  $autoload if true, the first parameter must be a filter name from one of the plugin directories
525 525
 	 * @throws Dwoo_Exception
526 526
 	 */
527
-    public function addFilter($callback, $autoload = false)
528
-    {
529
-        if ($autoload) {
530
-            $class = 'Dwoo_Filter_'.$callback;
531
-
532
-            if (!class_exists($class) && !function_exists($class)) {
533
-                try {
534
-                    $this->getLoader()->loadPlugin($callback);
535
-                } catch (Dwoo_Exception $e) {
536
-                    if (strstr($callback, 'Dwoo_Filter_')) {
537
-                        throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"');
538
-                    } else {
539
-                        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"');
540
-                    }
541
-                }
542
-            }
543
-
544
-            if (class_exists($class)) {
545
-                $callback = array(new $class($this), 'process');
546
-            } elseif (function_exists($class)) {
547
-                $callback = $class;
548
-            } else {
549
-                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"');
550
-            }
551
-
552
-            $this->filters[] = $callback;
553
-        } else {
554
-            $this->filters[] = $callback;
555
-        }
556
-    }
557
-
558
-    /**
559
-     * removes a filter
560
-     *
561
-     * @param mixed $callback callback or filter name if it was autoloaded
562
-     */
563
-    public function removeFilter($callback)
564
-    {
565
-        if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) {
566
-            unset($this->filters[$index]);
567
-        } elseif (($index = array_search($callback, $this->filters, true)) !== false) {
568
-            unset($this->filters[$index]);
569
-        } else  {
570
-            $class = 'Dwoo_Filter_' . $callback;
571
-            foreach ($this->filters as $index=>$filter) {
572
-                if (is_array($filter) && $filter[0] instanceof $class) {
573
-                    unset($this->filters[$index]);
574
-                    break;
575
-                }
576
-            }
577
-        }
578
-    }
527
+	public function addFilter($callback, $autoload = false)
528
+	{
529
+		if ($autoload) {
530
+			$class = 'Dwoo_Filter_'.$callback;
531
+
532
+			if (!class_exists($class) && !function_exists($class)) {
533
+				try {
534
+					$this->getLoader()->loadPlugin($callback);
535
+				} catch (Dwoo_Exception $e) {
536
+					if (strstr($callback, 'Dwoo_Filter_')) {
537
+						throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"');
538
+					} else {
539
+						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"');
540
+					}
541
+				}
542
+			}
543
+
544
+			if (class_exists($class)) {
545
+				$callback = array(new $class($this), 'process');
546
+			} elseif (function_exists($class)) {
547
+				$callback = $class;
548
+			} else {
549
+				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"');
550
+			}
551
+
552
+			$this->filters[] = $callback;
553
+		} else {
554
+			$this->filters[] = $callback;
555
+		}
556
+	}
557
+
558
+	/**
559
+	 * removes a filter
560
+	 *
561
+	 * @param mixed $callback callback or filter name if it was autoloaded
562
+	 */
563
+	public function removeFilter($callback)
564
+	{
565
+		if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) {
566
+			unset($this->filters[$index]);
567
+		} elseif (($index = array_search($callback, $this->filters, true)) !== false) {
568
+			unset($this->filters[$index]);
569
+		} else  {
570
+			$class = 'Dwoo_Filter_' . $callback;
571
+			foreach ($this->filters as $index=>$filter) {
572
+				if (is_array($filter) && $filter[0] instanceof $class) {
573
+					unset($this->filters[$index]);
574
+					break;
575
+				}
576
+			}
577
+		}
578
+	}
579 579
 
580 580
 	/**
581 581
 	 * adds a resource or overrides a default one
@@ -584,274 +584,274 @@  discard block
 block discarded – undo
584 584
 	 * @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance used to compile this resource, if none is provided. by default it will produce a Dwoo_Compiler object
585 585
 	 * @throws Dwoo_Exception
586 586
 	 */
587
-    public function addResource($name, $class, $compilerFactory = null)
588
-    {
589
-        if (strlen($name) < 2) {
590
-            throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');
591
-        }
587
+	public function addResource($name, $class, $compilerFactory = null)
588
+	{
589
+		if (strlen($name) < 2) {
590
+			throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths');
591
+		}
592 592
 
593
-        if (!class_exists($class)) {
594
-            throw new Dwoo_Exception('Resource class does not exist');
595
-        }
593
+		if (!class_exists($class)) {
594
+			throw new Dwoo_Exception('Resource class does not exist');
595
+		}
596 596
 
597
-        $interfaces = class_implements($class);
598
-        if (in_array('Dwoo_ITemplate', $interfaces) === false) {
599
-            throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate');
600
-        }
597
+		$interfaces = class_implements($class);
598
+		if (in_array('Dwoo_ITemplate', $interfaces) === false) {
599
+			throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate');
600
+		}
601 601
 
602
-        $this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory);
603
-    }
602
+		$this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory);
603
+	}
604 604
 
605
-    /**
606
-     * removes a custom resource
607
-     *
608
-     * @param string $name the resource name
609
-     */
610
-    public function removeResource($name)
611
-    {
612
-        unset($this->resources[$name]);
613
-        if ($name==='file') {
614
-            $this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null);
615
-        }
616
-    }
617
-
618
-    /*
605
+	/**
606
+	 * removes a custom resource
607
+	 *
608
+	 * @param string $name the resource name
609
+	 */
610
+	public function removeResource($name)
611
+	{
612
+		unset($this->resources[$name]);
613
+		if ($name==='file') {
614
+			$this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null);
615
+		}
616
+	}
617
+
618
+	/*
619 619
      * --------- getters and setters ---------
620 620
      */
621 621
 
622
-    /**
623
-     * sets the loader object to use to load plugins
624
-     *
625
-     * @param Dwoo_ILoader $loader loader object
626
-     */
627
-    public function setLoader(Dwoo_ILoader $loader)
628
-    {
629
-        $this->loader = $loader;
630
-    }
622
+	/**
623
+	 * sets the loader object to use to load plugins
624
+	 *
625
+	 * @param Dwoo_ILoader $loader loader object
626
+	 */
627
+	public function setLoader(Dwoo_ILoader $loader)
628
+	{
629
+		$this->loader = $loader;
630
+	}
631 631
 
632 632
 	/**
633 633
 	 * returns the current loader object or a default one if none is currently found
634 634
 	 * @param Dwoo_ILoader
635 635
 	 * @return Dwoo_ILoader|Dwoo_Loader
636 636
 	 */
637
-    public function getLoader()
638
-    {
639
-        if ($this->loader === null) {
640
-            $this->loader = new Dwoo_Loader($this->getCompileDir());
641
-        }
637
+	public function getLoader()
638
+	{
639
+		if ($this->loader === null) {
640
+			$this->loader = new Dwoo_Loader($this->getCompileDir());
641
+		}
642 642
 
643
-        return $this->loader;
644
-    }
643
+		return $this->loader;
644
+	}
645 645
 
646
-    /**
647
-     * returns the custom plugins loaded
648
-     *
649
-     * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance
650
-     *
651
-     * @return array
652
-     */
653
-    public function getCustomPlugins()
654
-    {
655
-        return $this->plugins;
656
-    }
646
+	/**
647
+	 * returns the custom plugins loaded
648
+	 *
649
+	 * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance
650
+	 *
651
+	 * @return array
652
+	 */
653
+	public function getCustomPlugins()
654
+	{
655
+		return $this->plugins;
656
+	}
657 657
 
658
-    /**
659
-     * returns the cache directory with a trailing DIRECTORY_SEPARATOR
660
-     *
661
-     * @return string
662
-     */
663
-    public function getCacheDir()
664
-    {
665
-        if ($this->cacheDir === null) {
666
-            $this->setCacheDir(DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR);
667
-        }
658
+	/**
659
+	 * returns the cache directory with a trailing DIRECTORY_SEPARATOR
660
+	 *
661
+	 * @return string
662
+	 */
663
+	public function getCacheDir()
664
+	{
665
+		if ($this->cacheDir === null) {
666
+			$this->setCacheDir(DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR);
667
+		}
668 668
 
669
-        return $this->cacheDir;
670
-    }
669
+		return $this->cacheDir;
670
+	}
671 671
 
672 672
 	/**
673 673
 	 * sets the cache directory and automatically appends a DIRECTORY_SEPARATOR
674 674
 	 * @param string $dir the cache directory
675 675
 	 * @throws Dwoo_Exception
676 676
 	 */
677
-    public function setCacheDir($dir)
678
-    {
679
-        $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
680
-        if (is_writable($this->cacheDir) === false) {
681
-            throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable');
682
-        }
683
-    }
677
+	public function setCacheDir($dir)
678
+	{
679
+		$this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
680
+		if (is_writable($this->cacheDir) === false) {
681
+			throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable');
682
+		}
683
+	}
684 684
 
685
-    /**
686
-     * returns the compile directory with a trailing DIRECTORY_SEPARATOR
687
-     *
688
-     * @return string
689
-     */
690
-    public function getCompileDir()
691
-    {
692
-        if ($this->compileDir === null) {
693
-            $this->setCompileDir(DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR);
694
-        }
685
+	/**
686
+	 * returns the compile directory with a trailing DIRECTORY_SEPARATOR
687
+	 *
688
+	 * @return string
689
+	 */
690
+	public function getCompileDir()
691
+	{
692
+		if ($this->compileDir === null) {
693
+			$this->setCompileDir(DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR);
694
+		}
695 695
 
696
-        return $this->compileDir;
697
-    }
696
+		return $this->compileDir;
697
+	}
698 698
 
699 699
 	/**
700 700
 	 * sets the compile directory and automatically appends a DIRECTORY_SEPARATOR
701 701
 	 * @param string $dir the compile directory
702 702
 	 * @throws Dwoo_Exception
703 703
 	 */
704
-    public function setCompileDir($dir)
705
-    {
706
-        $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
707
-        if (is_writable($this->compileDir) === false) {
708
-            throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable');
709
-        }
710
-    }
711
-
712
-    /**
713
-     * returns the default cache time that is used with templates that do not have a cache time set
714
-     *
715
-     * @return int the duration in seconds
716
-     */
717
-    public function getCacheTime()
718
-    {
719
-        return $this->cacheTime;
720
-    }
704
+	public function setCompileDir($dir)
705
+	{
706
+		$this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR;
707
+		if (is_writable($this->compileDir) === false) {
708
+			throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable');
709
+		}
710
+	}
721 711
 
722
-    /**
723
-     * sets the default cache time to use with templates that do not have a cache time set
724
-     *
725
-     * @param int $seconds the duration in seconds
726
-     */
727
-    public function setCacheTime($seconds)
728
-    {
729
-        $this->cacheTime = (int) $seconds;
730
-    }
712
+	/**
713
+	 * returns the default cache time that is used with templates that do not have a cache time set
714
+	 *
715
+	 * @return int the duration in seconds
716
+	 */
717
+	public function getCacheTime()
718
+	{
719
+		return $this->cacheTime;
720
+	}
731 721
 
732
-    /**
733
-     * returns the character set used by the string manipulation plugins
734
-     *
735
-     * the charset is automatically lowercased
736
-     *
737
-     * @return string
738
-     */
739
-    public function getCharset()
740
-    {
741
-        return $this->charset;
742
-    }
722
+	/**
723
+	 * sets the default cache time to use with templates that do not have a cache time set
724
+	 *
725
+	 * @param int $seconds the duration in seconds
726
+	 */
727
+	public function setCacheTime($seconds)
728
+	{
729
+		$this->cacheTime = (int) $seconds;
730
+	}
743 731
 
744
-    /**
745
-     * sets the character set used by the string manipulation plugins
746
-     *
747
-     * the charset will be automatically lowercased
748
-     *
749
-     * @param string $charset the character set
750
-     */
751
-    public function setCharset($charset)
752
-    {
753
-        $this->charset = strtolower((string) $charset);
754
-    }
732
+	/**
733
+	 * returns the character set used by the string manipulation plugins
734
+	 *
735
+	 * the charset is automatically lowercased
736
+	 *
737
+	 * @return string
738
+	 */
739
+	public function getCharset()
740
+	{
741
+		return $this->charset;
742
+	}
755 743
 
756
-    /**
757
-     * returns the current template being rendered, when applicable, or null
758
-     *
759
-     * @return Dwoo_ITemplate|null
760
-     */
761
-    public function getTemplate()
762
-    {
763
-        return $this->template;
764
-    }
744
+	/**
745
+	 * sets the character set used by the string manipulation plugins
746
+	 *
747
+	 * the charset will be automatically lowercased
748
+	 *
749
+	 * @param string $charset the character set
750
+	 */
751
+	public function setCharset($charset)
752
+	{
753
+		$this->charset = strtolower((string) $charset);
754
+	}
765 755
 
766
-    /**
767
-     * sets the current template being rendered
768
-     *
769
-     * @param Dwoo_ITemplate $tpl template object
770
-     */
771
-    public function setTemplate(Dwoo_ITemplate $tpl)
772
-    {
773
-        $this->template = $tpl;
774
-    }
756
+	/**
757
+	 * returns the current template being rendered, when applicable, or null
758
+	 *
759
+	 * @return Dwoo_ITemplate|null
760
+	 */
761
+	public function getTemplate()
762
+	{
763
+		return $this->template;
764
+	}
775 765
 
776
-    /**
777
-     * sets the default compiler factory function for the given resource name
778
-     *
779
-     * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs
780
-     *
781
-     * @param string $resourceName the resource name (i.e. file, string)
782
-     * @param callback $compilerFactory the compiler factory callback
783
-     */
784
-    public function setDefaultCompilerFactory($resourceName, $compilerFactory)
785
-    {
786
-        $this->resources[$resourceName]['compiler'] = $compilerFactory;
787
-    }
766
+	/**
767
+	 * sets the current template being rendered
768
+	 *
769
+	 * @param Dwoo_ITemplate $tpl template object
770
+	 */
771
+	public function setTemplate(Dwoo_ITemplate $tpl)
772
+	{
773
+		$this->template = $tpl;
774
+	}
788 775
 
789
-    /**
790
-     * returns the default compiler factory function for the given resource name
791
-     *
792
-     * @param string $resourceName the resource name
793
-     * @return callback the compiler factory callback
794
-     */
795
-    public function getDefaultCompilerFactory($resourceName)
796
-    {
797
-        return $this->resources[$resourceName]['compiler'];
798
-    }
776
+	/**
777
+	 * sets the default compiler factory function for the given resource name
778
+	 *
779
+	 * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs
780
+	 *
781
+	 * @param string $resourceName the resource name (i.e. file, string)
782
+	 * @param callback $compilerFactory the compiler factory callback
783
+	 */
784
+	public function setDefaultCompilerFactory($resourceName, $compilerFactory)
785
+	{
786
+		$this->resources[$resourceName]['compiler'] = $compilerFactory;
787
+	}
799 788
 
800
-    /**
801
-     * sets the security policy object to enforce some php security settings
802
-     *
803
-     * use this if untrusted persons can modify templates
804
-     *
805
-     * @param Dwoo_Security_Policy $policy the security policy object
806
-     */
807
-    public function setSecurityPolicy(Dwoo_Security_Policy $policy = null)
808
-    {
809
-        $this->securityPolicy = $policy;
810
-    }
789
+	/**
790
+	 * returns the default compiler factory function for the given resource name
791
+	 *
792
+	 * @param string $resourceName the resource name
793
+	 * @return callback the compiler factory callback
794
+	 */
795
+	public function getDefaultCompilerFactory($resourceName)
796
+	{
797
+		return $this->resources[$resourceName]['compiler'];
798
+	}
811 799
 
812
-    /**
813
-     * returns the current security policy object or null by default
814
-     *
815
-     * @return Dwoo_Security_Policy|null the security policy object if any
816
-     */
817
-    public function getSecurityPolicy()
818
-    {
819
-        return $this->securityPolicy;
820
-    }
821
-
822
-    /**
823
-     * sets the object that must be used as a plugin proxy when plugin can't be found
824
-     * by dwoo's loader
825
-     *
826
-     * @param Dwoo_IPluginProxy $pluginProxy the proxy object
827
-     */
828
-    public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) {
829
-        $this->pluginProxy = $pluginProxy;
830
-    }
800
+	/**
801
+	 * sets the security policy object to enforce some php security settings
802
+	 *
803
+	 * use this if untrusted persons can modify templates
804
+	 *
805
+	 * @param Dwoo_Security_Policy $policy the security policy object
806
+	 */
807
+	public function setSecurityPolicy(Dwoo_Security_Policy $policy = null)
808
+	{
809
+		$this->securityPolicy = $policy;
810
+	}
811
+
812
+	/**
813
+	 * returns the current security policy object or null by default
814
+	 *
815
+	 * @return Dwoo_Security_Policy|null the security policy object if any
816
+	 */
817
+	public function getSecurityPolicy()
818
+	{
819
+		return $this->securityPolicy;
820
+	}
821
+
822
+	/**
823
+	 * sets the object that must be used as a plugin proxy when plugin can't be found
824
+	 * by dwoo's loader
825
+	 *
826
+	 * @param Dwoo_IPluginProxy $pluginProxy the proxy object
827
+	 */
828
+	public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) {
829
+		$this->pluginProxy = $pluginProxy;
830
+	}
831 831
 
832 832
 	/**
833 833
 	 * returns the current plugin proxy object or null by default
834 834
 	 * @param Dwoo_IPluginProxy|null the proxy object if any
835 835
 	 * @return Dwoo_IPluginProxy
836 836
 	 */
837
-    public function getPluginProxy() {
838
-        return $this->pluginProxy;
839
-    }
837
+	public function getPluginProxy() {
838
+		return $this->pluginProxy;
839
+	}
840 840
 
841
-    /*
841
+	/*
842 842
      * --------- util functions ---------
843 843
      */
844 844
 
845
-    /**
846
-     * [util function] checks whether the given template is cached or not
847
-     *
848
-     * @param Dwoo_ITemplate $tpl the template object
849
-     * @return bool
850
-     */
851
-    public function isCached(Dwoo_ITemplate $tpl)
852
-    {
853
-        return is_string($tpl->getCachedTemplate($this));
854
-    }
845
+	/**
846
+	 * [util function] checks whether the given template is cached or not
847
+	 *
848
+	 * @param Dwoo_ITemplate $tpl the template object
849
+	 * @return bool
850
+	 */
851
+	public function isCached(Dwoo_ITemplate $tpl)
852
+	{
853
+		return is_string($tpl->getCachedTemplate($this));
854
+	}
855 855
 
856 856
 	/**
857 857
 	 * Clear templates inside the compiled directory.
@@ -872,28 +872,28 @@  discard block
 block discarded – undo
872 872
 		return $count;
873 873
 	}
874 874
 
875
-    /**
876
-     * [util function] clears the cached templates if they are older than the given time
877
-     *
878
-     * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared
879
-     * @return int the amount of templates cleared
880
-     */
881
-    public function clearCache($olderThan=-1)
882
-    {
875
+	/**
876
+	 * [util function] clears the cached templates if they are older than the given time
877
+	 *
878
+	 * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared
879
+	 * @return int the amount of templates cleared
880
+	 */
881
+	public function clearCache($olderThan=-1)
882
+	{
883 883
 		$iterator = new \RecursiveIteratorIterator(
884 884
 			new \RecursiveDirectoryIterator($this->getCacheDir()),
885 885
 			\RecursiveIteratorIterator::SELF_FIRST
886 886
 		);
887
-        $expired = time() - $olderThan;
888
-        $count = 0;
887
+		$expired = time() - $olderThan;
888
+		$count = 0;
889 889
 		/** @var \SplFileInfo $file */
890
-        foreach ($iterator as $file) {
890
+		foreach ($iterator as $file) {
891 891
 			if ($file->isFile() && $file->getCTime() < $expired) {
892 892
 				$count += unlink((string) $file) ? 1 : 0;
893 893
 			}
894
-        }
895
-        return $count;
896
-    }
894
+		}
895
+		return $count;
896
+	}
897 897
 
898 898
 	/**
899 899
 	 * [util function] fetches a template object of the given resource
@@ -906,722 +906,722 @@  discard block
 block discarded – undo
906 906
 	 * @return Dwoo_ITemplate
907 907
 	 * @throws Dwoo_Exception
908 908
 	 */
909
-    public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
910
-    {
911
-        if (isset($this->resources[$resourceName])) {
912
-            // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe
913
-            return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate);
914
-        } else {
915
-            throw new Dwoo_Exception('Unknown resource type : '.$resourceName);
916
-        }
917
-    }
918
-
919
-    /**
920
-     * [util function] checks if the input is an array or arrayaccess object, optionally it can also check if it's empty
921
-     *
922
-     * @param mixed $value the variable to check
923
-     * @param bool $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty,
924
-     *                              and return true only if it's not empty
925
-     * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true)
926
-     */
927
-    public function isArray($value, $checkIsEmpty=false)
928
-    {
929
-        if (is_array($value) === true || $value instanceof ArrayAccess) {
930
-            if ($checkIsEmpty === false) {
931
-                return true;
932
-            } else {
933
-                return $this->count($value);
934
-            }
935
-        }
936
-    }
937
-
938
-    /**
939
-     * [util function] checks if the input is an array or a traversable object, optionally it can also check if it's empty
940
-     *
941
-     * @param mixed $value the variable to check
942
-     * @param bool $checkIsEmpty if true, the function will also check if the array|traversable is empty,
943
-     *                              and return true only if it's not empty
944
-     * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true)
945
-     */
946
-    public function isTraversable($value, $checkIsEmpty=false)
947
-    {
948
-        if (is_array($value) === true) {
949
-            if ($checkIsEmpty === false) {
950
-                return true;
951
-            } else {
952
-                return count($value) > 0;
953
-            }
954
-        } elseif ($value instanceof Traversable) {
955
-            if ($checkIsEmpty === false) {
956
-                return true;
957
-            } else {
958
-                return $this->count($value);
959
-            }
960
-        }
961
-        return false;
962
-    }
963
-
964
-    /**
965
-     * [util function] counts an array or arrayaccess/traversable object
966
-     * @param mixed $value
967
-     * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't, and 0 for empty elements
968
-     */
969
-    public function count($value)
970
-    {
971
-        if (is_array($value) === true || $value instanceof Countable) {
972
-            return count($value);
973
-        } elseif ($value instanceof ArrayAccess) {
974
-            if ($value->offsetExists(0)) {
975
-                return true;
976
-            }
977
-        } elseif ($value instanceof Iterator) {
978
-            $value->rewind();
979
-            if ($value->valid()) {
980
-                return true;
981
-            }
982
-        } elseif ($value instanceof Traversable) {
983
-            foreach ($value as $dummy) {
984
-                return true;
985
-            }
986
-        }
987
-        return 0;
988
-    }
989
-
990
-    /**
991
-     * [util function] triggers a dwoo error
992
-     *
993
-     * @param string $message the error message
994
-     * @param int $level the error level, one of the PHP's E_* constants
995
-     */
996
-    public function triggerError($message, $level=E_USER_NOTICE)
997
-    {
998
-        if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
999
-            $tplIdentifier = $this->template->getResourceName();
1000
-        }
1001
-        trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message, $level);
1002
-    }
1003
-
1004
-    /*
909
+	public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null)
910
+	{
911
+		if (isset($this->resources[$resourceName])) {
912
+			// TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe
913
+			return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate);
914
+		} else {
915
+			throw new Dwoo_Exception('Unknown resource type : '.$resourceName);
916
+		}
917
+	}
918
+
919
+	/**
920
+	 * [util function] checks if the input is an array or arrayaccess object, optionally it can also check if it's empty
921
+	 *
922
+	 * @param mixed $value the variable to check
923
+	 * @param bool $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty,
924
+	 *                              and return true only if it's not empty
925
+	 * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true)
926
+	 */
927
+	public function isArray($value, $checkIsEmpty=false)
928
+	{
929
+		if (is_array($value) === true || $value instanceof ArrayAccess) {
930
+			if ($checkIsEmpty === false) {
931
+				return true;
932
+			} else {
933
+				return $this->count($value);
934
+			}
935
+		}
936
+	}
937
+
938
+	/**
939
+	 * [util function] checks if the input is an array or a traversable object, optionally it can also check if it's empty
940
+	 *
941
+	 * @param mixed $value the variable to check
942
+	 * @param bool $checkIsEmpty if true, the function will also check if the array|traversable is empty,
943
+	 *                              and return true only if it's not empty
944
+	 * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true)
945
+	 */
946
+	public function isTraversable($value, $checkIsEmpty=false)
947
+	{
948
+		if (is_array($value) === true) {
949
+			if ($checkIsEmpty === false) {
950
+				return true;
951
+			} else {
952
+				return count($value) > 0;
953
+			}
954
+		} elseif ($value instanceof Traversable) {
955
+			if ($checkIsEmpty === false) {
956
+				return true;
957
+			} else {
958
+				return $this->count($value);
959
+			}
960
+		}
961
+		return false;
962
+	}
963
+
964
+	/**
965
+	 * [util function] counts an array or arrayaccess/traversable object
966
+	 * @param mixed $value
967
+	 * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't, and 0 for empty elements
968
+	 */
969
+	public function count($value)
970
+	{
971
+		if (is_array($value) === true || $value instanceof Countable) {
972
+			return count($value);
973
+		} elseif ($value instanceof ArrayAccess) {
974
+			if ($value->offsetExists(0)) {
975
+				return true;
976
+			}
977
+		} elseif ($value instanceof Iterator) {
978
+			$value->rewind();
979
+			if ($value->valid()) {
980
+				return true;
981
+			}
982
+		} elseif ($value instanceof Traversable) {
983
+			foreach ($value as $dummy) {
984
+				return true;
985
+			}
986
+		}
987
+		return 0;
988
+	}
989
+
990
+	/**
991
+	 * [util function] triggers a dwoo error
992
+	 *
993
+	 * @param string $message the error message
994
+	 * @param int $level the error level, one of the PHP's E_* constants
995
+	 */
996
+	public function triggerError($message, $level=E_USER_NOTICE)
997
+	{
998
+		if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
999
+			$tplIdentifier = $this->template->getResourceName();
1000
+		}
1001
+		trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message, $level);
1002
+	}
1003
+
1004
+	/*
1005 1005
      * --------- runtime functions ---------
1006 1006
      */
1007 1007
 
1008
-    /**
1009
-     * [runtime function] adds a block to the block stack
1010
-     *
1011
-     * @param string $blockName the block name (without Dwoo_Plugin_ prefix)
1012
-     * @param array $args the arguments to be passed to the block's init() function
1013
-     * @return Dwoo_Block_Plugin the newly created block
1014
-     */
1015
-    public function addStack($blockName, array $args=array())
1016
-    {
1017
-        if (isset($this->plugins[$blockName])) {
1018
-            $class = $this->plugins[$blockName]['class'];
1019
-        } else {
1020
-            $class = 'Dwoo_Plugin_'.$blockName;
1021
-        }
1022
-
1023
-        if ($this->curBlock !== null) {
1024
-            $this->curBlock->buffer(ob_get_contents());
1025
-            ob_clean();
1026
-        } else {
1027
-            $this->buffer .= ob_get_contents();
1028
-            ob_clean();
1029
-        }
1030
-
1031
-        $block = new $class($this);
1032
-
1033
-        $cnt = count($args);
1034
-        if ($cnt===0) {
1035
-            $block->init();
1036
-        } elseif ($cnt===1) {
1037
-            $block->init($args[0]);
1038
-        } elseif ($cnt===2) {
1039
-            $block->init($args[0], $args[1]);
1040
-        } elseif ($cnt===3) {
1041
-            $block->init($args[0], $args[1], $args[2]);
1042
-        } elseif ($cnt===4) {
1043
-            $block->init($args[0], $args[1], $args[2], $args[3]);
1044
-        } else {
1045
-            call_user_func_array(array($block,'init'), $args);
1046
-        }
1047
-
1048
-        $this->stack[] = $this->curBlock = $block;
1049
-        return $block;
1050
-    }
1051
-
1052
-    /**
1053
-     * [runtime function] removes the plugin at the top of the block stack
1054
-     *
1055
-     * calls the block buffer() function, followed by a call to end()
1056
-     * and finally a call to process()
1057
-     */
1058
-    public function delStack()
1059
-    {
1060
-        $args = func_get_args();
1061
-
1062
-        $this->curBlock->buffer(ob_get_contents());
1063
-        ob_clean();
1064
-
1065
-        $cnt = count($args);
1066
-        if ($cnt===0) {
1067
-            $this->curBlock->end();
1068
-        } elseif ($cnt===1) {
1069
-            $this->curBlock->end($args[0]);
1070
-        } elseif ($cnt===2) {
1071
-            $this->curBlock->end($args[0], $args[1]);
1072
-        } elseif ($cnt===3) {
1073
-            $this->curBlock->end($args[0], $args[1], $args[2]);
1074
-        } elseif ($cnt===4) {
1075
-            $this->curBlock->end($args[0], $args[1], $args[2], $args[3]);
1076
-        } else {
1077
-            call_user_func_array(array($this->curBlock, 'end'), $args);
1078
-        }
1079
-
1080
-        $tmp = array_pop($this->stack);
1081
-
1082
-        if (count($this->stack) > 0) {
1083
-            $this->curBlock = end($this->stack);
1084
-            $this->curBlock->buffer($tmp->process());
1085
-        } else {
1086
-            if($this->buffer !== '') {
1087
-                echo $this->buffer;
1088
-                $this->buffer = '';
1089
-            }
1090
-            $this->curBlock = null;
1091
-            echo $tmp->process();
1092
-        }
1093
-
1094
-        unset($tmp);
1095
-    }
1096
-
1097
-    /**
1098
-     * [runtime function] returns the parent block of the given block
1099
-     *
1100
-     * @param Dwoo_Block_Plugin $block
1101
-     * @return Dwoo_Block_Plugin|false if the given block isn't in the stack
1102
-     */
1103
-    public function getParentBlock(Dwoo_Block_Plugin $block)
1104
-    {
1105
-        $index = array_search($block, $this->stack, true);
1106
-        if ($index !== false && $index > 0) {
1107
-            return $this->stack[$index-1];
1108
-        }
1109
-        return false;
1110
-    }
1111
-
1112
-    /**
1113
-     * [runtime function] finds the closest block of the given type, starting at the top of the stack
1114
-     *
1115
-     * @param string $type the type of plugin you want to find
1116
-     * @return Dwoo_Block_Plugin|false if no plugin of such type is in the stack
1117
-     */
1118
-    public function findBlock($type)
1119
-    {
1120
-        if (isset($this->plugins[$type])) {
1121
-            $type = $this->plugins[$type]['class'];
1122
-        } else {
1123
-            $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type);
1124
-        }
1125
-
1126
-        $keys = array_keys($this->stack);
1127
-        while (($key = array_pop($keys)) !== false) {
1128
-            if ($this->stack[$key] instanceof $type) {
1129
-                return $this->stack[$key];
1130
-            }
1131
-        }
1132
-        return false;
1133
-    }
1134
-
1135
-    /**
1136
-     * [runtime function] returns a Dwoo_Plugin of the given class
1137
-     *
1138
-     * this is so a single instance of every class plugin is created at each template run,
1139
-     * allowing class plugins to have "per-template-run" static variables
1140
-     *
1141
-     * @private
1142
-     * @param string $class the class name
1143
-     * @return mixed an object of the given class
1144
-     */
1145
-    public function getObjectPlugin($class)
1146
-    {
1147
-        if (isset($this->runtimePlugins[$class])) {
1148
-            return $this->runtimePlugins[$class];
1149
-        }
1150
-        return $this->runtimePlugins[$class] = new $class($this);
1151
-    }
1152
-
1153
-    /**
1154
-     * [runtime function] calls the process() method of the given class-plugin name
1155
-     *
1156
-     * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix)
1157
-     * @param array $params an array of parameters to send to the process() method
1158
-     * @return string the process() return value
1159
-     */
1160
-    public function classCall($plugName, array $params = array())
1161
-    {
1162
-        $class = 'Dwoo_Plugin_'.$plugName;
1163
-
1164
-        $plugin = $this->getObjectPlugin($class);
1165
-
1166
-        $cnt = count($params);
1167
-        if ($cnt===0) {
1168
-            return $plugin->process();
1169
-        } elseif ($cnt===1) {
1170
-            return $plugin->process($params[0]);
1171
-        } elseif ($cnt===2) {
1172
-            return $plugin->process($params[0], $params[1]);
1173
-        } elseif ($cnt===3) {
1174
-            return $plugin->process($params[0], $params[1], $params[2]);
1175
-        } elseif ($cnt===4) {
1176
-            return $plugin->process($params[0], $params[1], $params[2], $params[3]);
1177
-        } else {
1178
-            return call_user_func_array(array($plugin, 'process'), $params);
1179
-        }
1180
-    }
1181
-
1182
-    /**
1183
-     * [runtime function] calls a php function
1184
-     *
1185
-     * @param string $callback the function to call
1186
-     * @param array $params an array of parameters to send to the function
1187
-     * @return mixed the return value of the called function
1188
-     */
1189
-    public function arrayMap($callback, array $params)
1190
-    {
1191
-        if ($params[0] === $this) {
1192
-            $addThis = true;
1193
-            array_shift($params);
1194
-        }
1195
-        if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) {
1196
-            if (empty($params[0])) {
1197
-                return $params[0];
1198
-            }
1199
-
1200
-            // array map
1201
-            $out = array();
1202
-            $cnt = count($params);
1203
-
1204
-            if (isset($addThis)) {
1205
-                array_unshift($params, $this);
1206
-                $items = $params[1];
1207
-                $keys = array_keys($items);
1208
-
1209
-                if (is_string($callback) === false) {
1210
-                    while (($i = array_shift($keys)) !== null) {
1211
-                        $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1212
-                    }
1213
-                } elseif ($cnt===1) {
1214
-                    while (($i = array_shift($keys)) !== null) {
1215
-                        $out[] = $callback($this, $items[$i]);
1216
-                    }
1217
-                } elseif ($cnt===2) {
1218
-                    while (($i = array_shift($keys)) !== null) {
1219
-                        $out[] = $callback($this, $items[$i], $params[2]);
1220
-                    }
1221
-                } elseif ($cnt===3) {
1222
-                    while (($i = array_shift($keys)) !== null) {
1223
-                        $out[] = $callback($this, $items[$i], $params[2], $params[3]);
1224
-                    }
1225
-                } else {
1226
-                    while (($i = array_shift($keys)) !== null) {
1227
-                        $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1228
-                    }
1229
-                }
1230
-            } else {
1231
-                $items = $params[0];
1232
-                $keys = array_keys($items);
1233
-
1234
-                if (is_string($callback) === false) {
1235
-                    while (($i = array_shift($keys)) !== null) {
1236
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1237
-                    }
1238
-                } elseif ($cnt===1) {
1239
-                    while (($i = array_shift($keys)) !== null) {
1240
-                        $out[] = $callback($items[$i]);
1241
-                    }
1242
-                } elseif ($cnt===2) {
1243
-                    while (($i = array_shift($keys)) !== null) {
1244
-                        $out[] = $callback($items[$i], $params[1]);
1245
-                    }
1246
-                } elseif ($cnt===3) {
1247
-                    while (($i = array_shift($keys)) !== null) {
1248
-                        $out[] = $callback($items[$i], $params[1], $params[2]);
1249
-                    }
1250
-                } elseif ($cnt===4) {
1251
-                    while (($i = array_shift($keys)) !== null) {
1252
-                        $out[] = $callback($items[$i], $params[1], $params[2], $params[3]);
1253
-                    }
1254
-                } else {
1255
-                    while (($i = array_shift($keys)) !== null) {
1256
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1257
-                    }
1258
-                }
1259
-            }
1260
-            return $out;
1261
-        } else {
1262
-            return $params[0];
1263
-        }
1264
-    }
1265
-
1266
-    /**
1267
-     * [runtime function] reads a variable into the given data array
1268
-     *
1269
-     * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1270
-     * @param mixed $data the data array or object to read from
1271
-     * @param bool $safeRead if true, the function will check whether the index exists to prevent any notices from being output
1272
-     * @return mixed
1273
-     */
1274
-    public function readVarInto($varstr, $data, $safeRead = false)
1275
-    {
1276
-        if ($data === null) {
1277
-            return null;
1278
-        }
1279
-
1280
-        if (is_array($varstr) === false) {
1281
-            preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1282
-        } else {
1283
-            $m = $varstr;
1284
-        }
1285
-        unset($varstr);
1286
-
1287
-        while (list($k, $sep) = each($m[1])) {
1288
-            if ($sep === '.' || $sep === '[' || $sep === '') {
1289
-                // strip enclosing quotes if present
1290
-                $m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]);
1291
-
1292
-                if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) {
1293
-                    $data = $data[$m[2][$k]];
1294
-                } else {
1295
-                    return null;
1296
-                }
1297
-            } else {
1298
-                if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) {
1299
-                    $data = $data->$m[2][$k];
1300
-                } else {
1301
-                    return null;
1302
-                }
1303
-            }
1304
-        }
1305
-
1306
-        return $data;
1307
-    }
1308
-
1309
-    /**
1310
-     * [runtime function] reads a variable into the parent scope
1311
-     *
1312
-     * @param int $parentLevels the amount of parent levels to go from the current scope
1313
-     * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1314
-     * @return mixed
1315
-     */
1316
-    public function readParentVar($parentLevels, $varstr = null)
1317
-    {
1318
-        $tree = $this->scopeTree;
1319
-        $cur = $this->data;
1320
-
1321
-        while ($parentLevels--!==0) {
1322
-            array_pop($tree);
1323
-        }
1324
-
1325
-        while (($i = array_shift($tree)) !== null) {
1326
-            if (is_object($cur)) {
1327
-                $cur = $cur->$i;
1328
-            } else {
1329
-                $cur = $cur[$i];
1330
-            }
1331
-        }
1332
-
1333
-        if ($varstr!==null) {
1334
-            return $this->readVarInto($varstr, $cur);
1335
-        } else {
1336
-            return $cur;
1337
-        }
1338
-    }
1339
-
1340
-    /**
1341
-     * [runtime function] reads a variable into the current scope
1342
-     *
1343
-     * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1344
-     * @return mixed
1345
-     */
1346
-    public function readVar($varstr)
1347
-    {
1348
-        if (is_array($varstr)===true) {
1349
-            $m = $varstr;
1350
-            unset($varstr);
1351
-        } else {
1352
-            if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) {
1353
-                if ($varstr === 'dwoo') {
1354
-                    return $this->globals;
1355
-                } elseif ($varstr === '__' || $varstr === '_root' ) {
1356
-                    return $this->data;
1357
-                } elseif ($varstr === '_' || $varstr === '_parent') {
1358
-                    $varstr = '.'.$varstr;
1359
-                    $tree = $this->scopeTree;
1360
-                    $cur = $this->data;
1361
-                    array_pop($tree);
1362
-
1363
-                    while (($i = array_shift($tree)) !== null) {
1364
-                        if (is_object($cur)) {
1365
-                            $cur = $cur->$i;
1366
-                        } else {
1367
-                            $cur = $cur[$i];
1368
-                        }
1369
-                    }
1370
-
1371
-                    return $cur;
1372
-                }
1373
-
1374
-                $cur = $this->scope;
1375
-
1376
-                if (isset($cur[$varstr])) {
1377
-                    return $cur[$varstr];
1378
-                } else {
1379
-                    return null;
1380
-                }
1381
-            }
1382
-
1383
-            if (substr($varstr, 0, 1) === '.') {
1384
-                $varstr = 'dwoo'.$varstr;
1385
-            }
1386
-
1387
-            preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1388
-        }
1389
-
1390
-        $i = $m[2][0];
1391
-        if ($i === 'dwoo') {
1392
-            $cur = $this->globals;
1393
-            array_shift($m[2]);
1394
-            array_shift($m[1]);
1395
-            switch ($m[2][0]) {
1396
-
1397
-            case 'get':
1398
-                $cur = $_GET;
1399
-                break;
1400
-            case 'post':
1401
-                $cur = $_POST;
1402
-                break;
1403
-            case 'session':
1404
-                $cur = $_SESSION;
1405
-                break;
1406
-            case 'cookies':
1407
-            case 'cookie':
1408
-                $cur = $_COOKIE;
1409
-                break;
1410
-            case 'server':
1411
-                $cur = $_SERVER;
1412
-                break;
1413
-            case 'env':
1414
-                $cur = $_ENV;
1415
-                break;
1416
-            case 'request':
1417
-                $cur = $_REQUEST;
1418
-                break;
1419
-            case 'const':
1420
-                array_shift($m[2]);
1421
-                if (defined($m[2][0])) {
1422
-                    return constant($m[2][0]);
1423
-                } else {
1424
-                    return null;
1425
-                }
1426
-
1427
-            }
1428
-            if ($cur !== $this->globals) {
1429
-                array_shift($m[2]);
1430
-                array_shift($m[1]);
1431
-            }
1432
-        } elseif ($i === '__' || $i === '_root') {
1433
-            $cur = $this->data;
1434
-            array_shift($m[2]);
1435
-            array_shift($m[1]);
1436
-        } elseif ($i === '_' || $i === '_parent') {
1437
-            $tree = $this->scopeTree;
1438
-            $cur = $this->data;
1439
-
1440
-            while (true) {
1441
-                array_pop($tree);
1442
-                array_shift($m[2]);
1443
-                array_shift($m[1]);
1444
-                if (current($m[2]) === '_' || current($m[2]) === '_parent') {
1445
-                    continue;
1446
-                }
1447
-
1448
-                while (($i = array_shift($tree)) !== null) {
1449
-                    if (is_object($cur)) {
1450
-                        $cur = $cur->$i;
1451
-                    } else {
1452
-                        $cur = $cur[$i];
1453
-                    }
1454
-                }
1455
-                break;
1456
-            }
1457
-        } else {
1458
-            $cur = $this->scope;
1459
-        }
1460
-
1461
-        while (list($k, $sep) = each($m[1])) {
1462
-            if ($sep === '.' || $sep === '[' || $sep === '') {
1463
-                if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) {
1464
-                    $cur = $cur[$m[2][$k]];
1465
-                } else {
1466
-                    return null;
1467
-                }
1468
-            } elseif ($sep === '->') {
1469
-                if (is_object($cur)) {
1470
-                    $cur = $cur->$m[2][$k];
1471
-                } else {
1472
-                    return null;
1473
-                }
1474
-            } else {
1475
-                return null;
1476
-            }
1477
-        }
1478
-
1479
-        return $cur;
1480
-    }
1481
-
1482
-    /**
1483
-     * [runtime function] assign the value to the given variable
1484
-     *
1485
-     * @param mixed $value the value to assign
1486
-     * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1487
-     * @return bool true if assigned correctly or false if a problem occured while parsing the var string
1488
-     */
1489
-    public function assignInScope($value, $scope)
1490
-    {
1491
-        $tree =& $this->scopeTree;
1492
-        $data =& $this->data;
1493
-
1494
-        if (!is_string($scope)) {
1495
-            $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR);
1496
-        }
1497
-        if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
1498
-            $this->scope[$scope] = $value;
1499
-        } else {
1500
-            // TODO handle _root/_parent scopes ?
1501
-            preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m);
1502
-
1503
-            $cur =& $this->scope;
1504
-            $last = array(array_pop($m[1]), array_pop($m[2]));
1505
-
1506
-            while (list($k, $sep) = each($m[1])) {
1507
-                if ($sep === '.' || $sep === '[' || $sep === '') {
1508
-                    if (is_array($cur) === false) {
1509
-                        $cur = array();
1510
-                    }
1511
-                    $cur =& $cur[$m[2][$k]];
1512
-                } elseif ($sep === '->') {
1513
-                    if (is_object($cur) === false) {
1514
-                        $cur = new stdClass;
1515
-                    }
1516
-                    $cur =& $cur->$m[2][$k];
1517
-                } else {
1518
-                    return false;
1519
-                }
1520
-            }
1521
-
1522
-            if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') {
1523
-                if (is_array($cur) === false) {
1524
-                    $cur = array();
1525
-                }
1526
-                $cur[$last[1]] = $value;
1527
-            } elseif ($last[0] === '->') {
1528
-                if (is_object($cur) === false) {
1529
-                    $cur = new stdClass;
1530
-                }
1531
-                $cur->$last[1] = $value;
1532
-            } else {
1533
-                return false;
1534
-            }
1535
-        }
1536
-    }
1537
-
1538
-    /**
1539
-     * [runtime function] sets the scope to the given scope string or array
1540
-     *
1541
-     * @param mixed $scope a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1542
-     * @param bool $absolute if true, the scope is set from the top level scope and not from the current scope
1543
-     * @return array the current scope tree
1544
-     */
1545
-    public function setScope($scope, $absolute = false)
1546
-    {
1547
-        $old = $this->scopeTree;
1548
-
1549
-        if (is_string($scope)===true) {
1550
-            $scope = explode('.', $scope);
1551
-        }
1552
-
1553
-        if ($absolute===true) {
1554
-            $this->scope =& $this->data;
1555
-            $this->scopeTree = array();
1556
-        }
1557
-
1558
-        while (($bit = array_shift($scope)) !== null) {
1559
-            if ($bit === '_' || $bit === '_parent') {
1560
-                array_pop($this->scopeTree);
1561
-                $this->scope =& $this->data;
1562
-                $cnt = count($this->scopeTree);
1563
-                for ($i=0;$i<$cnt;$i++)
1564
-                    $this->scope =& $this->scope[$this->scopeTree[$i]];
1565
-            } elseif ($bit === '__' || $bit === '_root') {
1566
-                $this->scope =& $this->data;
1567
-                $this->scopeTree = array();
1568
-            } elseif (isset($this->scope[$bit])) {
1569
-                if($this->scope instanceof ArrayAccess) {
1570
-                    $tmp = $this->scope[$bit];
1571
-                    $this->scope =& $tmp;
1572
-                } else {
1573
-                    $this->scope =& $this->scope[$bit];
1574
-                }
1575
-                $this->scopeTree[] = $bit;
1576
-            } else {
1577
-                unset($this->scope);
1578
-                $this->scope = null;
1579
-            }
1580
-        }
1581
-
1582
-        return $old;
1583
-    }
1584
-
1585
-    /**
1586
-     * [runtime function] returns the entire data array
1587
-     *
1588
-     * @return array
1589
-     */
1590
-    public function getData()
1591
-    {
1592
-        return $this->data;
1593
-    }
1008
+	/**
1009
+	 * [runtime function] adds a block to the block stack
1010
+	 *
1011
+	 * @param string $blockName the block name (without Dwoo_Plugin_ prefix)
1012
+	 * @param array $args the arguments to be passed to the block's init() function
1013
+	 * @return Dwoo_Block_Plugin the newly created block
1014
+	 */
1015
+	public function addStack($blockName, array $args=array())
1016
+	{
1017
+		if (isset($this->plugins[$blockName])) {
1018
+			$class = $this->plugins[$blockName]['class'];
1019
+		} else {
1020
+			$class = 'Dwoo_Plugin_'.$blockName;
1021
+		}
1594 1022
 
1595
-    /**
1596
-     * [runtime function] sets a return value for the currently running template
1597
-     *
1598
-     * @param string $name var name
1599
-     * @param mixed $value var value
1600
-     */
1601
-    public function setReturnValue($name, $value)
1602
-    {
1603
-        $this->returnData[$name] = $value;
1604
-    }
1023
+		if ($this->curBlock !== null) {
1024
+			$this->curBlock->buffer(ob_get_contents());
1025
+			ob_clean();
1026
+		} else {
1027
+			$this->buffer .= ob_get_contents();
1028
+			ob_clean();
1029
+		}
1605 1030
 
1606
-    /**
1607
-     * [runtime function] retrieves the return values set by the template
1608
-     *
1609
-     * @return array
1610
-     */
1611
-    public function getReturnValues()
1612
-    {
1613
-        return $this->returnData;
1614
-    }
1031
+		$block = new $class($this);
1032
+
1033
+		$cnt = count($args);
1034
+		if ($cnt===0) {
1035
+			$block->init();
1036
+		} elseif ($cnt===1) {
1037
+			$block->init($args[0]);
1038
+		} elseif ($cnt===2) {
1039
+			$block->init($args[0], $args[1]);
1040
+		} elseif ($cnt===3) {
1041
+			$block->init($args[0], $args[1], $args[2]);
1042
+		} elseif ($cnt===4) {
1043
+			$block->init($args[0], $args[1], $args[2], $args[3]);
1044
+		} else {
1045
+			call_user_func_array(array($block,'init'), $args);
1046
+		}
1615 1047
 
1616
-    /**
1617
-     * [runtime function] returns a reference to the current scope
1618
-     *
1619
-     * @return &mixed
1620
-     */
1621
-    public function &getScope()
1622
-    {
1623
-        return $this->scope;
1624
-    }
1048
+		$this->stack[] = $this->curBlock = $block;
1049
+		return $block;
1050
+	}
1051
+
1052
+	/**
1053
+	 * [runtime function] removes the plugin at the top of the block stack
1054
+	 *
1055
+	 * calls the block buffer() function, followed by a call to end()
1056
+	 * and finally a call to process()
1057
+	 */
1058
+	public function delStack()
1059
+	{
1060
+		$args = func_get_args();
1061
+
1062
+		$this->curBlock->buffer(ob_get_contents());
1063
+		ob_clean();
1064
+
1065
+		$cnt = count($args);
1066
+		if ($cnt===0) {
1067
+			$this->curBlock->end();
1068
+		} elseif ($cnt===1) {
1069
+			$this->curBlock->end($args[0]);
1070
+		} elseif ($cnt===2) {
1071
+			$this->curBlock->end($args[0], $args[1]);
1072
+		} elseif ($cnt===3) {
1073
+			$this->curBlock->end($args[0], $args[1], $args[2]);
1074
+		} elseif ($cnt===4) {
1075
+			$this->curBlock->end($args[0], $args[1], $args[2], $args[3]);
1076
+		} else {
1077
+			call_user_func_array(array($this->curBlock, 'end'), $args);
1078
+		}
1079
+
1080
+		$tmp = array_pop($this->stack);
1081
+
1082
+		if (count($this->stack) > 0) {
1083
+			$this->curBlock = end($this->stack);
1084
+			$this->curBlock->buffer($tmp->process());
1085
+		} else {
1086
+			if($this->buffer !== '') {
1087
+				echo $this->buffer;
1088
+				$this->buffer = '';
1089
+			}
1090
+			$this->curBlock = null;
1091
+			echo $tmp->process();
1092
+		}
1093
+
1094
+		unset($tmp);
1095
+	}
1096
+
1097
+	/**
1098
+	 * [runtime function] returns the parent block of the given block
1099
+	 *
1100
+	 * @param Dwoo_Block_Plugin $block
1101
+	 * @return Dwoo_Block_Plugin|false if the given block isn't in the stack
1102
+	 */
1103
+	public function getParentBlock(Dwoo_Block_Plugin $block)
1104
+	{
1105
+		$index = array_search($block, $this->stack, true);
1106
+		if ($index !== false && $index > 0) {
1107
+			return $this->stack[$index-1];
1108
+		}
1109
+		return false;
1110
+	}
1111
+
1112
+	/**
1113
+	 * [runtime function] finds the closest block of the given type, starting at the top of the stack
1114
+	 *
1115
+	 * @param string $type the type of plugin you want to find
1116
+	 * @return Dwoo_Block_Plugin|false if no plugin of such type is in the stack
1117
+	 */
1118
+	public function findBlock($type)
1119
+	{
1120
+		if (isset($this->plugins[$type])) {
1121
+			$type = $this->plugins[$type]['class'];
1122
+		} else {
1123
+			$type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type);
1124
+		}
1125
+
1126
+		$keys = array_keys($this->stack);
1127
+		while (($key = array_pop($keys)) !== false) {
1128
+			if ($this->stack[$key] instanceof $type) {
1129
+				return $this->stack[$key];
1130
+			}
1131
+		}
1132
+		return false;
1133
+	}
1134
+
1135
+	/**
1136
+	 * [runtime function] returns a Dwoo_Plugin of the given class
1137
+	 *
1138
+	 * this is so a single instance of every class plugin is created at each template run,
1139
+	 * allowing class plugins to have "per-template-run" static variables
1140
+	 *
1141
+	 * @private
1142
+	 * @param string $class the class name
1143
+	 * @return mixed an object of the given class
1144
+	 */
1145
+	public function getObjectPlugin($class)
1146
+	{
1147
+		if (isset($this->runtimePlugins[$class])) {
1148
+			return $this->runtimePlugins[$class];
1149
+		}
1150
+		return $this->runtimePlugins[$class] = new $class($this);
1151
+	}
1152
+
1153
+	/**
1154
+	 * [runtime function] calls the process() method of the given class-plugin name
1155
+	 *
1156
+	 * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix)
1157
+	 * @param array $params an array of parameters to send to the process() method
1158
+	 * @return string the process() return value
1159
+	 */
1160
+	public function classCall($plugName, array $params = array())
1161
+	{
1162
+		$class = 'Dwoo_Plugin_'.$plugName;
1163
+
1164
+		$plugin = $this->getObjectPlugin($class);
1165
+
1166
+		$cnt = count($params);
1167
+		if ($cnt===0) {
1168
+			return $plugin->process();
1169
+		} elseif ($cnt===1) {
1170
+			return $plugin->process($params[0]);
1171
+		} elseif ($cnt===2) {
1172
+			return $plugin->process($params[0], $params[1]);
1173
+		} elseif ($cnt===3) {
1174
+			return $plugin->process($params[0], $params[1], $params[2]);
1175
+		} elseif ($cnt===4) {
1176
+			return $plugin->process($params[0], $params[1], $params[2], $params[3]);
1177
+		} else {
1178
+			return call_user_func_array(array($plugin, 'process'), $params);
1179
+		}
1180
+	}
1181
+
1182
+	/**
1183
+	 * [runtime function] calls a php function
1184
+	 *
1185
+	 * @param string $callback the function to call
1186
+	 * @param array $params an array of parameters to send to the function
1187
+	 * @return mixed the return value of the called function
1188
+	 */
1189
+	public function arrayMap($callback, array $params)
1190
+	{
1191
+		if ($params[0] === $this) {
1192
+			$addThis = true;
1193
+			array_shift($params);
1194
+		}
1195
+		if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) {
1196
+			if (empty($params[0])) {
1197
+				return $params[0];
1198
+			}
1199
+
1200
+			// array map
1201
+			$out = array();
1202
+			$cnt = count($params);
1203
+
1204
+			if (isset($addThis)) {
1205
+				array_unshift($params, $this);
1206
+				$items = $params[1];
1207
+				$keys = array_keys($items);
1208
+
1209
+				if (is_string($callback) === false) {
1210
+					while (($i = array_shift($keys)) !== null) {
1211
+						$out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1212
+					}
1213
+				} elseif ($cnt===1) {
1214
+					while (($i = array_shift($keys)) !== null) {
1215
+						$out[] = $callback($this, $items[$i]);
1216
+					}
1217
+				} elseif ($cnt===2) {
1218
+					while (($i = array_shift($keys)) !== null) {
1219
+						$out[] = $callback($this, $items[$i], $params[2]);
1220
+					}
1221
+				} elseif ($cnt===3) {
1222
+					while (($i = array_shift($keys)) !== null) {
1223
+						$out[] = $callback($this, $items[$i], $params[2], $params[3]);
1224
+					}
1225
+				} else {
1226
+					while (($i = array_shift($keys)) !== null) {
1227
+						$out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1228
+					}
1229
+				}
1230
+			} else {
1231
+				$items = $params[0];
1232
+				$keys = array_keys($items);
1233
+
1234
+				if (is_string($callback) === false) {
1235
+					while (($i = array_shift($keys)) !== null) {
1236
+						$out[] = call_user_func_array($callback, array($items[$i]) + $params);
1237
+					}
1238
+				} elseif ($cnt===1) {
1239
+					while (($i = array_shift($keys)) !== null) {
1240
+						$out[] = $callback($items[$i]);
1241
+					}
1242
+				} elseif ($cnt===2) {
1243
+					while (($i = array_shift($keys)) !== null) {
1244
+						$out[] = $callback($items[$i], $params[1]);
1245
+					}
1246
+				} elseif ($cnt===3) {
1247
+					while (($i = array_shift($keys)) !== null) {
1248
+						$out[] = $callback($items[$i], $params[1], $params[2]);
1249
+					}
1250
+				} elseif ($cnt===4) {
1251
+					while (($i = array_shift($keys)) !== null) {
1252
+						$out[] = $callback($items[$i], $params[1], $params[2], $params[3]);
1253
+					}
1254
+				} else {
1255
+					while (($i = array_shift($keys)) !== null) {
1256
+						$out[] = call_user_func_array($callback, array($items[$i]) + $params);
1257
+					}
1258
+				}
1259
+			}
1260
+			return $out;
1261
+		} else {
1262
+			return $params[0];
1263
+		}
1264
+	}
1265
+
1266
+	/**
1267
+	 * [runtime function] reads a variable into the given data array
1268
+	 *
1269
+	 * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1270
+	 * @param mixed $data the data array or object to read from
1271
+	 * @param bool $safeRead if true, the function will check whether the index exists to prevent any notices from being output
1272
+	 * @return mixed
1273
+	 */
1274
+	public function readVarInto($varstr, $data, $safeRead = false)
1275
+	{
1276
+		if ($data === null) {
1277
+			return null;
1278
+		}
1279
+
1280
+		if (is_array($varstr) === false) {
1281
+			preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1282
+		} else {
1283
+			$m = $varstr;
1284
+		}
1285
+		unset($varstr);
1286
+
1287
+		while (list($k, $sep) = each($m[1])) {
1288
+			if ($sep === '.' || $sep === '[' || $sep === '') {
1289
+				// strip enclosing quotes if present
1290
+				$m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]);
1291
+
1292
+				if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) {
1293
+					$data = $data[$m[2][$k]];
1294
+				} else {
1295
+					return null;
1296
+				}
1297
+			} else {
1298
+				if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) {
1299
+					$data = $data->$m[2][$k];
1300
+				} else {
1301
+					return null;
1302
+				}
1303
+			}
1304
+		}
1305
+
1306
+		return $data;
1307
+	}
1308
+
1309
+	/**
1310
+	 * [runtime function] reads a variable into the parent scope
1311
+	 *
1312
+	 * @param int $parentLevels the amount of parent levels to go from the current scope
1313
+	 * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1314
+	 * @return mixed
1315
+	 */
1316
+	public function readParentVar($parentLevels, $varstr = null)
1317
+	{
1318
+		$tree = $this->scopeTree;
1319
+		$cur = $this->data;
1320
+
1321
+		while ($parentLevels--!==0) {
1322
+			array_pop($tree);
1323
+		}
1324
+
1325
+		while (($i = array_shift($tree)) !== null) {
1326
+			if (is_object($cur)) {
1327
+				$cur = $cur->$i;
1328
+			} else {
1329
+				$cur = $cur[$i];
1330
+			}
1331
+		}
1332
+
1333
+		if ($varstr!==null) {
1334
+			return $this->readVarInto($varstr, $cur);
1335
+		} else {
1336
+			return $cur;
1337
+		}
1338
+	}
1339
+
1340
+	/**
1341
+	 * [runtime function] reads a variable into the current scope
1342
+	 *
1343
+	 * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1344
+	 * @return mixed
1345
+	 */
1346
+	public function readVar($varstr)
1347
+	{
1348
+		if (is_array($varstr)===true) {
1349
+			$m = $varstr;
1350
+			unset($varstr);
1351
+		} else {
1352
+			if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) {
1353
+				if ($varstr === 'dwoo') {
1354
+					return $this->globals;
1355
+				} elseif ($varstr === '__' || $varstr === '_root' ) {
1356
+					return $this->data;
1357
+				} elseif ($varstr === '_' || $varstr === '_parent') {
1358
+					$varstr = '.'.$varstr;
1359
+					$tree = $this->scopeTree;
1360
+					$cur = $this->data;
1361
+					array_pop($tree);
1362
+
1363
+					while (($i = array_shift($tree)) !== null) {
1364
+						if (is_object($cur)) {
1365
+							$cur = $cur->$i;
1366
+						} else {
1367
+							$cur = $cur[$i];
1368
+						}
1369
+					}
1370
+
1371
+					return $cur;
1372
+				}
1373
+
1374
+				$cur = $this->scope;
1375
+
1376
+				if (isset($cur[$varstr])) {
1377
+					return $cur[$varstr];
1378
+				} else {
1379
+					return null;
1380
+				}
1381
+			}
1382
+
1383
+			if (substr($varstr, 0, 1) === '.') {
1384
+				$varstr = 'dwoo'.$varstr;
1385
+			}
1386
+
1387
+			preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m);
1388
+		}
1389
+
1390
+		$i = $m[2][0];
1391
+		if ($i === 'dwoo') {
1392
+			$cur = $this->globals;
1393
+			array_shift($m[2]);
1394
+			array_shift($m[1]);
1395
+			switch ($m[2][0]) {
1396
+
1397
+			case 'get':
1398
+				$cur = $_GET;
1399
+				break;
1400
+			case 'post':
1401
+				$cur = $_POST;
1402
+				break;
1403
+			case 'session':
1404
+				$cur = $_SESSION;
1405
+				break;
1406
+			case 'cookies':
1407
+			case 'cookie':
1408
+				$cur = $_COOKIE;
1409
+				break;
1410
+			case 'server':
1411
+				$cur = $_SERVER;
1412
+				break;
1413
+			case 'env':
1414
+				$cur = $_ENV;
1415
+				break;
1416
+			case 'request':
1417
+				$cur = $_REQUEST;
1418
+				break;
1419
+			case 'const':
1420
+				array_shift($m[2]);
1421
+				if (defined($m[2][0])) {
1422
+					return constant($m[2][0]);
1423
+				} else {
1424
+					return null;
1425
+				}
1426
+
1427
+			}
1428
+			if ($cur !== $this->globals) {
1429
+				array_shift($m[2]);
1430
+				array_shift($m[1]);
1431
+			}
1432
+		} elseif ($i === '__' || $i === '_root') {
1433
+			$cur = $this->data;
1434
+			array_shift($m[2]);
1435
+			array_shift($m[1]);
1436
+		} elseif ($i === '_' || $i === '_parent') {
1437
+			$tree = $this->scopeTree;
1438
+			$cur = $this->data;
1439
+
1440
+			while (true) {
1441
+				array_pop($tree);
1442
+				array_shift($m[2]);
1443
+				array_shift($m[1]);
1444
+				if (current($m[2]) === '_' || current($m[2]) === '_parent') {
1445
+					continue;
1446
+				}
1447
+
1448
+				while (($i = array_shift($tree)) !== null) {
1449
+					if (is_object($cur)) {
1450
+						$cur = $cur->$i;
1451
+					} else {
1452
+						$cur = $cur[$i];
1453
+					}
1454
+				}
1455
+				break;
1456
+			}
1457
+		} else {
1458
+			$cur = $this->scope;
1459
+		}
1460
+
1461
+		while (list($k, $sep) = each($m[1])) {
1462
+			if ($sep === '.' || $sep === '[' || $sep === '') {
1463
+				if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) {
1464
+					$cur = $cur[$m[2][$k]];
1465
+				} else {
1466
+					return null;
1467
+				}
1468
+			} elseif ($sep === '->') {
1469
+				if (is_object($cur)) {
1470
+					$cur = $cur->$m[2][$k];
1471
+				} else {
1472
+					return null;
1473
+				}
1474
+			} else {
1475
+				return null;
1476
+			}
1477
+		}
1478
+
1479
+		return $cur;
1480
+	}
1481
+
1482
+	/**
1483
+	 * [runtime function] assign the value to the given variable
1484
+	 *
1485
+	 * @param mixed $value the value to assign
1486
+	 * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
1487
+	 * @return bool true if assigned correctly or false if a problem occured while parsing the var string
1488
+	 */
1489
+	public function assignInScope($value, $scope)
1490
+	{
1491
+		$tree =& $this->scopeTree;
1492
+		$data =& $this->data;
1493
+
1494
+		if (!is_string($scope)) {
1495
+			$this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR);
1496
+		}
1497
+		if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
1498
+			$this->scope[$scope] = $value;
1499
+		} else {
1500
+			// TODO handle _root/_parent scopes ?
1501
+			preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m);
1502
+
1503
+			$cur =& $this->scope;
1504
+			$last = array(array_pop($m[1]), array_pop($m[2]));
1505
+
1506
+			while (list($k, $sep) = each($m[1])) {
1507
+				if ($sep === '.' || $sep === '[' || $sep === '') {
1508
+					if (is_array($cur) === false) {
1509
+						$cur = array();
1510
+					}
1511
+					$cur =& $cur[$m[2][$k]];
1512
+				} elseif ($sep === '->') {
1513
+					if (is_object($cur) === false) {
1514
+						$cur = new stdClass;
1515
+					}
1516
+					$cur =& $cur->$m[2][$k];
1517
+				} else {
1518
+					return false;
1519
+				}
1520
+			}
1521
+
1522
+			if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') {
1523
+				if (is_array($cur) === false) {
1524
+					$cur = array();
1525
+				}
1526
+				$cur[$last[1]] = $value;
1527
+			} elseif ($last[0] === '->') {
1528
+				if (is_object($cur) === false) {
1529
+					$cur = new stdClass;
1530
+				}
1531
+				$cur->$last[1] = $value;
1532
+			} else {
1533
+				return false;
1534
+			}
1535
+		}
1536
+	}
1537
+
1538
+	/**
1539
+	 * [runtime function] sets the scope to the given scope string or array
1540
+	 *
1541
+	 * @param mixed $scope a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1542
+	 * @param bool $absolute if true, the scope is set from the top level scope and not from the current scope
1543
+	 * @return array the current scope tree
1544
+	 */
1545
+	public function setScope($scope, $absolute = false)
1546
+	{
1547
+		$old = $this->scopeTree;
1548
+
1549
+		if (is_string($scope)===true) {
1550
+			$scope = explode('.', $scope);
1551
+		}
1552
+
1553
+		if ($absolute===true) {
1554
+			$this->scope =& $this->data;
1555
+			$this->scopeTree = array();
1556
+		}
1557
+
1558
+		while (($bit = array_shift($scope)) !== null) {
1559
+			if ($bit === '_' || $bit === '_parent') {
1560
+				array_pop($this->scopeTree);
1561
+				$this->scope =& $this->data;
1562
+				$cnt = count($this->scopeTree);
1563
+				for ($i=0;$i<$cnt;$i++)
1564
+					$this->scope =& $this->scope[$this->scopeTree[$i]];
1565
+			} elseif ($bit === '__' || $bit === '_root') {
1566
+				$this->scope =& $this->data;
1567
+				$this->scopeTree = array();
1568
+			} elseif (isset($this->scope[$bit])) {
1569
+				if($this->scope instanceof ArrayAccess) {
1570
+					$tmp = $this->scope[$bit];
1571
+					$this->scope =& $tmp;
1572
+				} else {
1573
+					$this->scope =& $this->scope[$bit];
1574
+				}
1575
+				$this->scopeTree[] = $bit;
1576
+			} else {
1577
+				unset($this->scope);
1578
+				$this->scope = null;
1579
+			}
1580
+		}
1581
+
1582
+		return $old;
1583
+	}
1584
+
1585
+	/**
1586
+	 * [runtime function] returns the entire data array
1587
+	 *
1588
+	 * @return array
1589
+	 */
1590
+	public function getData()
1591
+	{
1592
+		return $this->data;
1593
+	}
1594
+
1595
+	/**
1596
+	 * [runtime function] sets a return value for the currently running template
1597
+	 *
1598
+	 * @param string $name var name
1599
+	 * @param mixed $value var value
1600
+	 */
1601
+	public function setReturnValue($name, $value)
1602
+	{
1603
+		$this->returnData[$name] = $value;
1604
+	}
1605
+
1606
+	/**
1607
+	 * [runtime function] retrieves the return values set by the template
1608
+	 *
1609
+	 * @return array
1610
+	 */
1611
+	public function getReturnValues()
1612
+	{
1613
+		return $this->returnData;
1614
+	}
1615
+
1616
+	/**
1617
+	 * [runtime function] returns a reference to the current scope
1618
+	 *
1619
+	 * @return &mixed
1620
+	 */
1621
+	public function &getScope()
1622
+	{
1623
+		return $this->scope;
1624
+	}
1625 1625
 
1626 1626
 	/**
1627 1627
 	 * Redirects all calls to unexisting to plugin proxy.
@@ -1630,11 +1630,11 @@  discard block
 block discarded – undo
1630 1630
 	 * @return mixed
1631 1631
 	 * @throws Dwoo_Exception
1632 1632
 	 */
1633
-    public function __call($method, $args) {
1634
-        $proxy = $this->getPluginProxy();
1635
-        if (!$proxy) {
1636
-            throw new Dwoo_Exception('Call to undefined method '.__CLASS__.'::'.$method.'()');
1637
-        }
1638
-        return call_user_func_array($proxy->getCallback($method), $args);
1639
-    }
1633
+	public function __call($method, $args) {
1634
+		$proxy = $this->getPluginProxy();
1635
+		if (!$proxy) {
1636
+			throw new Dwoo_Exception('Call to undefined method '.__CLASS__.'::'.$method.'()');
1637
+		}
1638
+		return call_user_func_array($proxy->getCallback($method), $args);
1639
+	}
1640 1640
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -69 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
  * main dwoo class, allows communication between the compiler, template and data classes
@@ -162,15 +162,12 @@  discard block
 block discarded – undo
162 162
      *
163 163
      * @var array
164 164
      */
165
-    protected $resources = array
166
-    (
167
-        'file'      =>  array
168
-        (
165
+    protected $resources = array(
166
+        'file'      =>  array(
169 167
             'class'     =>  'Dwoo_Template_File',
170 168
             'compiler'  =>  null
171 169
         ),
172
-        'string'    =>  array
173
-        (
170
+        'string'    =>  array(
174 171
             'class'     =>  'Dwoo_Template_String',
175 172
             'compiler'  =>  null
176 173
         )
@@ -437,8 +434,7 @@  discard block
 block discarded – undo
437 434
      */
438 435
     protected function initGlobals()
439 436
     {
440
-        $this->globals = array
441
-        (
437
+        $this->globals = array(
442 438
             'version'   =>  self::VERSION,
443 439
             'ad'        =>  '<a href="http://dwoo.org/">Powered by Dwoo</a>',
444 440
             'now'       =>  $_SERVER['REQUEST_TIME'],
@@ -457,7 +453,7 @@  discard block
 block discarded – undo
457 453
     protected function initRuntimeVars(Dwoo_ITemplate $tpl)
458 454
     {
459 455
         $this->runtimePlugins = array();
460
-        $this->scope =& $this->data;
456
+        $this->scope = & $this->data;
461 457
         $this->scopeTree = array();
462 458
         $this->stack = array();
463 459
         $this->curBlock = null;
@@ -487,7 +483,7 @@  discard block
 block discarded – undo
487 483
             } else {
488 484
                 $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]);
489 485
             }
490
-        } elseif(is_string($callback)) {
486
+        } elseif (is_string($callback)) {
491 487
 			if (class_exists($callback)) {
492 488
 				if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) {
493 489
 					$this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback);
@@ -499,7 +495,7 @@  discard block
 block discarded – undo
499 495
 			} else {
500 496
 				throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
501 497
 			}
502
-		} elseif($callback instanceof \Closure) {
498
+		} elseif ($callback instanceof \Closure) {
503 499
 			$this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback);
504 500
 		} else {
505 501
             throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists');
@@ -566,8 +562,8 @@  discard block
 block discarded – undo
566 562
             unset($this->filters[$index]);
567 563
         } elseif (($index = array_search($callback, $this->filters, true)) !== false) {
568 564
             unset($this->filters[$index]);
569
-        } else  {
570
-            $class = 'Dwoo_Filter_' . $callback;
565
+        } else {
566
+            $class = 'Dwoo_Filter_'.$callback;
571 567
             foreach ($this->filters as $index=>$filter) {
572 568
                 if (is_array($filter) && $filter[0] instanceof $class) {
573 569
                     unset($this->filters[$index]);
@@ -610,7 +606,7 @@  discard block
 block discarded – undo
610 606
     public function removeResource($name)
611 607
     {
612 608
         unset($this->resources[$name]);
613
-        if ($name==='file') {
609
+        if ($name === 'file') {
614 610
             $this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null);
615 611
         }
616 612
     }
@@ -862,7 +858,7 @@  discard block
 block discarded – undo
862 858
 			new \RecursiveDirectoryIterator($this->getCompileDir()),
863 859
 			\RecursiveIteratorIterator::SELF_FIRST
864 860
 		);
865
-		$count    = 0;
861
+		$count = 0;
866 862
 		/** @var \SplFileInfo $file */
867 863
 		foreach ($iterator as $file) {
868 864
 			if ($file->isFile()) {
@@ -878,13 +874,13 @@  discard block
 block discarded – undo
878 874
      * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared
879 875
      * @return int the amount of templates cleared
880 876
      */
881
-    public function clearCache($olderThan=-1)
877
+    public function clearCache($olderThan = -1)
882 878
     {
883 879
 		$iterator = new \RecursiveIteratorIterator(
884 880
 			new \RecursiveDirectoryIterator($this->getCacheDir()),
885 881
 			\RecursiveIteratorIterator::SELF_FIRST
886 882
 		);
887
-        $expired = time() - $olderThan;
883
+        $expired = time()-$olderThan;
888 884
         $count = 0;
889 885
 		/** @var \SplFileInfo $file */
890 886
         foreach ($iterator as $file) {
@@ -924,7 +920,7 @@  discard block
 block discarded – undo
924 920
      *                              and return true only if it's not empty
925 921
      * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true)
926 922
      */
927
-    public function isArray($value, $checkIsEmpty=false)
923
+    public function isArray($value, $checkIsEmpty = false)
928 924
     {
929 925
         if (is_array($value) === true || $value instanceof ArrayAccess) {
930 926
             if ($checkIsEmpty === false) {
@@ -943,7 +939,7 @@  discard block
 block discarded – undo
943 939
      *                              and return true only if it's not empty
944 940
      * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true)
945 941
      */
946
-    public function isTraversable($value, $checkIsEmpty=false)
942
+    public function isTraversable($value, $checkIsEmpty = false)
947 943
     {
948 944
         if (is_array($value) === true) {
949 945
             if ($checkIsEmpty === false) {
@@ -993,7 +989,7 @@  discard block
 block discarded – undo
993 989
      * @param string $message the error message
994 990
      * @param int $level the error level, one of the PHP's E_* constants
995 991
      */
996
-    public function triggerError($message, $level=E_USER_NOTICE)
992
+    public function triggerError($message, $level = E_USER_NOTICE)
997 993
     {
998 994
         if (!($tplIdentifier = $this->template->getResourceIdentifier())) {
999 995
             $tplIdentifier = $this->template->getResourceName();
@@ -1012,7 +1008,7 @@  discard block
 block discarded – undo
1012 1008
      * @param array $args the arguments to be passed to the block's init() function
1013 1009
      * @return Dwoo_Block_Plugin the newly created block
1014 1010
      */
1015
-    public function addStack($blockName, array $args=array())
1011
+    public function addStack($blockName, array $args = array())
1016 1012
     {
1017 1013
         if (isset($this->plugins[$blockName])) {
1018 1014
             $class = $this->plugins[$blockName]['class'];
@@ -1031,18 +1027,18 @@  discard block
 block discarded – undo
1031 1027
         $block = new $class($this);
1032 1028
 
1033 1029
         $cnt = count($args);
1034
-        if ($cnt===0) {
1030
+        if ($cnt === 0) {
1035 1031
             $block->init();
1036
-        } elseif ($cnt===1) {
1032
+        } elseif ($cnt === 1) {
1037 1033
             $block->init($args[0]);
1038
-        } elseif ($cnt===2) {
1034
+        } elseif ($cnt === 2) {
1039 1035
             $block->init($args[0], $args[1]);
1040
-        } elseif ($cnt===3) {
1036
+        } elseif ($cnt === 3) {
1041 1037
             $block->init($args[0], $args[1], $args[2]);
1042
-        } elseif ($cnt===4) {
1038
+        } elseif ($cnt === 4) {
1043 1039
             $block->init($args[0], $args[1], $args[2], $args[3]);
1044 1040
         } else {
1045
-            call_user_func_array(array($block,'init'), $args);
1041
+            call_user_func_array(array($block, 'init'), $args);
1046 1042
         }
1047 1043
 
1048 1044
         $this->stack[] = $this->curBlock = $block;
@@ -1063,15 +1059,15 @@  discard block
 block discarded – undo
1063 1059
         ob_clean();
1064 1060
 
1065 1061
         $cnt = count($args);
1066
-        if ($cnt===0) {
1062
+        if ($cnt === 0) {
1067 1063
             $this->curBlock->end();
1068
-        } elseif ($cnt===1) {
1064
+        } elseif ($cnt === 1) {
1069 1065
             $this->curBlock->end($args[0]);
1070
-        } elseif ($cnt===2) {
1066
+        } elseif ($cnt === 2) {
1071 1067
             $this->curBlock->end($args[0], $args[1]);
1072
-        } elseif ($cnt===3) {
1068
+        } elseif ($cnt === 3) {
1073 1069
             $this->curBlock->end($args[0], $args[1], $args[2]);
1074
-        } elseif ($cnt===4) {
1070
+        } elseif ($cnt === 4) {
1075 1071
             $this->curBlock->end($args[0], $args[1], $args[2], $args[3]);
1076 1072
         } else {
1077 1073
             call_user_func_array(array($this->curBlock, 'end'), $args);
@@ -1083,7 +1079,7 @@  discard block
 block discarded – undo
1083 1079
             $this->curBlock = end($this->stack);
1084 1080
             $this->curBlock->buffer($tmp->process());
1085 1081
         } else {
1086
-            if($this->buffer !== '') {
1082
+            if ($this->buffer !== '') {
1087 1083
                 echo $this->buffer;
1088 1084
                 $this->buffer = '';
1089 1085
             }
@@ -1164,15 +1160,15 @@  discard block
 block discarded – undo
1164 1160
         $plugin = $this->getObjectPlugin($class);
1165 1161
 
1166 1162
         $cnt = count($params);
1167
-        if ($cnt===0) {
1163
+        if ($cnt === 0) {
1168 1164
             return $plugin->process();
1169
-        } elseif ($cnt===1) {
1165
+        } elseif ($cnt === 1) {
1170 1166
             return $plugin->process($params[0]);
1171
-        } elseif ($cnt===2) {
1167
+        } elseif ($cnt === 2) {
1172 1168
             return $plugin->process($params[0], $params[1]);
1173
-        } elseif ($cnt===3) {
1169
+        } elseif ($cnt === 3) {
1174 1170
             return $plugin->process($params[0], $params[1], $params[2]);
1175
-        } elseif ($cnt===4) {
1171
+        } elseif ($cnt === 4) {
1176 1172
             return $plugin->process($params[0], $params[1], $params[2], $params[3]);
1177 1173
         } else {
1178 1174
             return call_user_func_array(array($plugin, 'process'), $params);
@@ -1208,23 +1204,23 @@  discard block
 block discarded – undo
1208 1204
 
1209 1205
                 if (is_string($callback) === false) {
1210 1206
                     while (($i = array_shift($keys)) !== null) {
1211
-                        $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1207
+                        $out[] = call_user_func_array($callback, array(1=>$items[$i])+$params);
1212 1208
                     }
1213
-                } elseif ($cnt===1) {
1209
+                } elseif ($cnt === 1) {
1214 1210
                     while (($i = array_shift($keys)) !== null) {
1215 1211
                         $out[] = $callback($this, $items[$i]);
1216 1212
                     }
1217
-                } elseif ($cnt===2) {
1213
+                } elseif ($cnt === 2) {
1218 1214
                     while (($i = array_shift($keys)) !== null) {
1219 1215
                         $out[] = $callback($this, $items[$i], $params[2]);
1220 1216
                     }
1221
-                } elseif ($cnt===3) {
1217
+                } elseif ($cnt === 3) {
1222 1218
                     while (($i = array_shift($keys)) !== null) {
1223 1219
                         $out[] = $callback($this, $items[$i], $params[2], $params[3]);
1224 1220
                     }
1225 1221
                 } else {
1226 1222
                     while (($i = array_shift($keys)) !== null) {
1227
-                        $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params);
1223
+                        $out[] = call_user_func_array($callback, array(1=>$items[$i])+$params);
1228 1224
                     }
1229 1225
                 }
1230 1226
             } else {
@@ -1233,27 +1229,27 @@  discard block
 block discarded – undo
1233 1229
 
1234 1230
                 if (is_string($callback) === false) {
1235 1231
                     while (($i = array_shift($keys)) !== null) {
1236
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1232
+                        $out[] = call_user_func_array($callback, array($items[$i])+$params);
1237 1233
                     }
1238
-                } elseif ($cnt===1) {
1234
+                } elseif ($cnt === 1) {
1239 1235
                     while (($i = array_shift($keys)) !== null) {
1240 1236
                         $out[] = $callback($items[$i]);
1241 1237
                     }
1242
-                } elseif ($cnt===2) {
1238
+                } elseif ($cnt === 2) {
1243 1239
                     while (($i = array_shift($keys)) !== null) {
1244 1240
                         $out[] = $callback($items[$i], $params[1]);
1245 1241
                     }
1246
-                } elseif ($cnt===3) {
1242
+                } elseif ($cnt === 3) {
1247 1243
                     while (($i = array_shift($keys)) !== null) {
1248 1244
                         $out[] = $callback($items[$i], $params[1], $params[2]);
1249 1245
                     }
1250
-                } elseif ($cnt===4) {
1246
+                } elseif ($cnt === 4) {
1251 1247
                     while (($i = array_shift($keys)) !== null) {
1252 1248
                         $out[] = $callback($items[$i], $params[1], $params[2], $params[3]);
1253 1249
                     }
1254 1250
                 } else {
1255 1251
                     while (($i = array_shift($keys)) !== null) {
1256
-                        $out[] = call_user_func_array($callback, array($items[$i]) + $params);
1252
+                        $out[] = call_user_func_array($callback, array($items[$i])+$params);
1257 1253
                     }
1258 1254
                 }
1259 1255
             }
@@ -1318,7 +1314,7 @@  discard block
 block discarded – undo
1318 1314
         $tree = $this->scopeTree;
1319 1315
         $cur = $this->data;
1320 1316
 
1321
-        while ($parentLevels--!==0) {
1317
+        while ($parentLevels-- !== 0) {
1322 1318
             array_pop($tree);
1323 1319
         }
1324 1320
 
@@ -1330,7 +1326,7 @@  discard block
 block discarded – undo
1330 1326
             }
1331 1327
         }
1332 1328
 
1333
-        if ($varstr!==null) {
1329
+        if ($varstr !== null) {
1334 1330
             return $this->readVarInto($varstr, $cur);
1335 1331
         } else {
1336 1332
             return $cur;
@@ -1345,14 +1341,14 @@  discard block
 block discarded – undo
1345 1341
      */
1346 1342
     public function readVar($varstr)
1347 1343
     {
1348
-        if (is_array($varstr)===true) {
1344
+        if (is_array($varstr) === true) {
1349 1345
             $m = $varstr;
1350 1346
             unset($varstr);
1351 1347
         } else {
1352 1348
             if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) {
1353 1349
                 if ($varstr === 'dwoo') {
1354 1350
                     return $this->globals;
1355
-                } elseif ($varstr === '__' || $varstr === '_root' ) {
1351
+                } elseif ($varstr === '__' || $varstr === '_root') {
1356 1352
                     return $this->data;
1357 1353
                 } elseif ($varstr === '_' || $varstr === '_parent') {
1358 1354
                     $varstr = '.'.$varstr;
@@ -1488,8 +1484,8 @@  discard block
 block discarded – undo
1488 1484
      */
1489 1485
     public function assignInScope($value, $scope)
1490 1486
     {
1491
-        $tree =& $this->scopeTree;
1492
-        $data =& $this->data;
1487
+        $tree = & $this->scopeTree;
1488
+        $data = & $this->data;
1493 1489
 
1494 1490
         if (!is_string($scope)) {
1495 1491
             $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR);
@@ -1500,7 +1496,7 @@  discard block
 block discarded – undo
1500 1496
             // TODO handle _root/_parent scopes ?
1501 1497
             preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m);
1502 1498
 
1503
-            $cur =& $this->scope;
1499
+            $cur = & $this->scope;
1504 1500
             $last = array(array_pop($m[1]), array_pop($m[2]));
1505 1501
 
1506 1502
             while (list($k, $sep) = each($m[1])) {
@@ -1508,12 +1504,12 @@  discard block
 block discarded – undo
1508 1504
                     if (is_array($cur) === false) {
1509 1505
                         $cur = array();
1510 1506
                     }
1511
-                    $cur =& $cur[$m[2][$k]];
1507
+                    $cur = & $cur[$m[2][$k]];
1512 1508
                 } elseif ($sep === '->') {
1513 1509
                     if (is_object($cur) === false) {
1514 1510
                         $cur = new stdClass;
1515 1511
                     }
1516
-                    $cur =& $cur->$m[2][$k];
1512
+                    $cur = & $cur->$m[2][$k];
1517 1513
                 } else {
1518 1514
                     return false;
1519 1515
                 }
@@ -1546,31 +1542,31 @@  discard block
 block discarded – undo
1546 1542
     {
1547 1543
         $old = $this->scopeTree;
1548 1544
 
1549
-        if (is_string($scope)===true) {
1545
+        if (is_string($scope) === true) {
1550 1546
             $scope = explode('.', $scope);
1551 1547
         }
1552 1548
 
1553
-        if ($absolute===true) {
1554
-            $this->scope =& $this->data;
1549
+        if ($absolute === true) {
1550
+            $this->scope = & $this->data;
1555 1551
             $this->scopeTree = array();
1556 1552
         }
1557 1553
 
1558 1554
         while (($bit = array_shift($scope)) !== null) {
1559 1555
             if ($bit === '_' || $bit === '_parent') {
1560 1556
                 array_pop($this->scopeTree);
1561
-                $this->scope =& $this->data;
1557
+                $this->scope = & $this->data;
1562 1558
                 $cnt = count($this->scopeTree);
1563
-                for ($i=0;$i<$cnt;$i++)
1564
-                    $this->scope =& $this->scope[$this->scopeTree[$i]];
1559
+                for ($i = 0; $i < $cnt; $i++)
1560
+                    $this->scope = & $this->scope[$this->scopeTree[$i]];
1565 1561
             } elseif ($bit === '__' || $bit === '_root') {
1566
-                $this->scope =& $this->data;
1562
+                $this->scope = & $this->data;
1567 1563
                 $this->scopeTree = array();
1568 1564
             } elseif (isset($this->scope[$bit])) {
1569
-                if($this->scope instanceof ArrayAccess) {
1565
+                if ($this->scope instanceof ArrayAccess) {
1570 1566
                     $tmp = $this->scope[$bit];
1571
-                    $this->scope =& $tmp;
1567
+                    $this->scope = & $tmp;
1572 1568
                 } else {
1573
-                    $this->scope =& $this->scope[$bit];
1569
+                    $this->scope = & $this->scope[$bit];
1574 1570
                 }
1575 1571
                 $this->scopeTree[] = $bit;
1576 1572
             } else {
Please login to merge, or discard this patch.