Completed
Branch master (6977c2)
by El
04:23
created
lib/i18n.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -77,7 +77,6 @@  discard block
 block discarded – undo
77 77
      * @access public
78 78
      * @static
79 79
      * @param  string $messageId
80
-     * @param  mixed $args one or multiple parameters injected into placeholders
81 80
      * @return string
82 81
      */
83 82
     public static function _($messageId)
@@ -91,7 +90,6 @@  discard block
 block discarded – undo
91 90
      * @access public
92 91
      * @static
93 92
      * @param  string $messageId
94
-     * @param  mixed $args one or multiple parameters injected into placeholders
95 93
      * @return string
96 94
      */
97 95
     public static function translate($messageId)
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         {
113 113
             $number = (int) $args[1];
114 114
             $key = self::_getPluralForm($number);
115
-            $max = count(self::$_translations[$messageId]) - 1;
115
+            $max = count(self::$_translations[$messageId])-1;
116 116
             if ($key > $max) $key = $max;
117 117
 
118 118
             $args[0] = self::$_translations[$messageId][$key];
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
             case 'zh':
307 307
                 return ($n > 1 ? 1 : 0);
308 308
             case 'pl':
309
-                return ($n == 1 ? 0 : $n%10 >= 2 && $n %10 <=4 && ($n%100 < 10 || $n%100 >= 20) ? 1 : 2);
309
+                return ($n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
310 310
             // en, de
311 311
             default:
312 312
                 return ($n != 1 ? 1 : 0);
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
     protected static function _matchLanguage($a, $b) {
387 387
         $a = explode('-', $a);
388 388
         $b = explode('-', $b);
389
-        for ($i=0, $n=min(count($a), count($b)); $i<$n; $i++)
389
+        for ($i = 0, $n = min(count($a), count($b)); $i < $n; $i++)
390 390
         {
391 391
             if ($a[$i] !== $b[$i]) break;
392 392
         }
Please login to merge, or discard this patch.
Braces   +23 added lines, -12 removed lines patch added patch discarded remove patch
@@ -96,8 +96,12 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public static function translate($messageId)
98 98
     {
99
-        if (empty($messageId)) return $messageId;
100
-        if (count(self::$_translations) === 0) self::loadTranslations();
99
+        if (empty($messageId)) {
100
+            return $messageId;
101
+        }
102
+        if (count(self::$_translations) === 0) {
103
+            self::loadTranslations();
104
+        }
101 105
         $messages = $messageId;
102 106
         if (is_array($messageId))
103 107
         {
@@ -113,12 +117,13 @@  discard block
 block discarded – undo
113 117
             $number = (int) $args[1];
114 118
             $key = self::_getPluralForm($number);
115 119
             $max = count(self::$_translations[$messageId]) - 1;
116
-            if ($key > $max) $key = $max;
120
+            if ($key > $max) {
121
+                $key = $max;
122
+            }
117 123
 
118 124
             $args[0] = self::$_translations[$messageId][$key];
119 125
             $args[1] = $number;
120
-        }
121
-        else
126
+        } else
122 127
         {
123 128
             $args[0] = self::$_translations[$messageId];
124 129
         }
@@ -208,8 +213,7 @@  discard block
 block discarded – undo
208 213
                     if (!isset($match[2]))
209 214
                     {
210 215
                         $match[2] = '1.0';
211
-                    }
212
-                    else
216
+                    } else
213 217
                     {
214 218
                         $match[2] = (string) floatval($match[2]);
215 219
                     }
@@ -254,7 +258,9 @@  discard block
 block discarded – undo
254 258
         {
255 259
             self::$_languageLabels = json_decode(file_get_contents($file), true);
256 260
         }
257
-        if (count($languages) == 0) return self::$_languageLabels;
261
+        if (count($languages) == 0) {
262
+            return self::$_languageLabels;
263
+        }
258 264
         return array_intersect_key(self::$_languageLabels, array_flip($languages));
259 265
     }
260 266
 
@@ -268,8 +274,9 @@  discard block
 block discarded – undo
268 274
      */
269 275
     public static function setLanguageFallback($lang)
270 276
     {
271
-        if (in_array($lang, self::getAvailableLanguages()))
272
-            self::$_languageFallback = $lang;
277
+        if (in_array($lang, self::getAvailableLanguages())) {
278
+                    self::$_languageFallback = $lang;
279
+        }
273 280
     }
274 281
 
275 282
     /**
@@ -330,7 +337,9 @@  discard block
 block discarded – undo
330 337
         foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues)
331 338
         {
332 339
             $acceptedQuality = floatval($acceptedQuality);
333
-            if ($acceptedQuality === 0.0) continue;
340
+            if ($acceptedQuality === 0.0) {
341
+                continue;
342
+            }
334 343
             foreach ($availableLanguages as $availableValue)
335 344
             {
336 345
                 $availableQuality = 1.0;
@@ -388,7 +397,9 @@  discard block
 block discarded – undo
388 397
         $b = explode('-', $b);
389 398
         for ($i=0, $n=min(count($a), count($b)); $i<$n; $i++)
390 399
         {
391
-            if ($a[$i] !== $b[$i]) break;
400
+            if ($a[$i] !== $b[$i]) {
401
+                break;
402
+            }
392 403
         }
393 404
         return $i === 0 ? 0 : (float) $i / count($a);
394 405
     }
Please login to merge, or discard this patch.
lib/persistence.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
      * @access public
46 46
      * @static
47 47
      * @param  string $filename
48
-     * @return void
48
+     * @return string
49 49
      */
50 50
     public static function getPath($filename = null)
51 51
     {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public static function getPath($filename = null)
51 51
     {
52
-        if(strlen($filename)) {
52
+        if (strlen($filename)) {
53 53
             return self::$_path . DIRECTORY_SEPARATOR . $filename;
54 54
         } else {
55 55
             return self::$_path;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             $writtenBytes = @file_put_contents(
93 93
                 $file,
94 94
                 'Allow from none' . PHP_EOL .
95
-                'Deny from all'. PHP_EOL,
95
+                'Deny from all' . PHP_EOL,
96 96
                 LOCK_EX
97 97
             );
98 98
             if ($writtenBytes === false || $writtenBytes < 30) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,9 +81,10 @@
 block discarded – undo
81 81
     protected static function _initialize()
82 82
     {
83 83
         // Create storage directory if it does not exist.
84
-        if (!is_dir(self::$_path))
85
-            if (!@mkdir(self::$_path))
84
+        if (!is_dir(self::$_path)) {
85
+                    if (!@mkdir(self::$_path))
86 86
                 throw new Exception('unable to create directory ' . self::$_path, 10);
87
+        }
87 88
 
88 89
         // Create .htaccess file if it does not exist.
89 90
         $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
Please login to merge, or discard this patch.
lib/RainTPL.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * eg. 	$t->assign('name','mickey');
175 175
 	 *
176 176
 	 * @access public
177
-	 * @param  mixed $variable_name Name of template variable or associative array name/value
177
+	 * @param  string $variable Name of template variable or associative array name/value
178 178
 	 * @param  mixed $value value assigned to this variable. Not set if variable_name is an associative array
179 179
 	 */
180 180
 	public function assign( $variable, $value = null ){
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @access public
254 254
 	 * @param  string $tpl_name Name of template (set the same of draw)
255
-	 * @param  int $expiration_time Set after how many seconds the cache expire and must be regenerated
255
+	 * @param  int $expire_time Set after how many seconds the cache expire and must be regenerated
256 256
 	 * @param  string $cache_id Suffix to be used when writing file to cache (optional)
257 257
 	 * @return string it return the HTML or null if the cache must be recreated
258 258
 	 */
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @access protected
300 300
 	 * @param  string $tpl_name template name to check
301 301
 	 * @throws RainTpl_NotFoundException
302
-	 * @return bool return true if the template has changed
302
+	 * @return boolean|null return true if the template has changed
303 303
 	 */
304 304
 	protected function check_template( $tpl_name ){
305 305
 
@@ -1168,8 +1168,6 @@  discard block
 block discarded – undo
1168 1168
  * alias for i18n::translate()
1169 1169
  *
1170 1170
  * @access public
1171
- * @param  string $messageId
1172
- * @param  mixed $args one or multiple parameters injected into placeholders
1173 1171
  * @return string
1174 1172
  */
1175 1173
 function t() {
Please login to merge, or discard this patch.
Indentation   +976 added lines, -976 removed lines patch added patch discarded remove patch
@@ -14,1046 +14,1046 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class RainTPL{
16 16
 
17
-	// -------------------------
18
-	// 	CONFIGURATION
19
-	// -------------------------
20
-
21
-		/**
22
-		 * Template directory
23
-		 *
24
-		 * @var string
25
-		 */
26
-		static $tpl_dir = 'tpl/';
27
-
28
-
29
-		/**
30
-		 * Cache directory
31
-		 *
32
-		 * Is the directory where RainTPL will compile the template and save the cache
33
-		 *
34
-		 * @var string
35
-		 */
36
-		static $cache_dir = 'tmp/';
37
-
38
-
39
-		/**
40
-		 * Template base URL
41
-		 *
42
-		 * RainTPL will add this URL to the relative paths of element selected in $path_replace_list.
43
-		 *
44
-		 * @var string
45
-		 */
46
-		static $base_url = null;
47
-
48
-
49
-		/**
50
-		 * Template extension
51
-		 *
52
-		 * @var string
53
-		 */
54
-		static $tpl_ext = "html";
55
-
56
-
57
-		/**
58
-		 * Should the path be replaced
59
-		 *
60
-		 * Path replace is a cool features that replace all relative paths of images (&lt;img src="..."&gt;), stylesheet (&lt;link href="..."&gt;), script (&lt;script src="..."&gt;) and link (&lt;a href="..."&gt;)
61
-		 * Set true to enable the path replace.
62
-		 *
63
-		 * @var boolean
64
-		 */
65
-		static $path_replace = true;
66
-
67
-
68
-		/**
69
-		 * You can set what the path_replace method will replace.
70
-		 * Avaible options: a, img, link, script, input
71
-		 *
72
-		 * @var array
73
-		 */
74
-		static $path_replace_list = array( 'a', 'img', 'link', 'script', 'input' );
75
-
76
-
77
-		/**
78
-		 * You can define in the black list what string are disabled into the template tags
79
-		 *
80
-		 * @var array
81
-		 */
82
-		static $black_list = array( '\$this', 'raintpl::', 'self::', '_SESSION', '_SERVER', '_ENV',  'eval', 'exec', 'unlink', 'rmdir' );
83
-
84
-
85
-		/**
86
-		 * Check template
87
-		 *
88
-		 * true: checks template update time, if changed it compile them
89
-		 * false: loads the compiled template. Set false if server doesn't have write permission for cache_directory.
90
-		 *
91
-		 * @var bool
92
-		 */
93
-		static $check_template_update = true;
94
-
95
-
96
-		/**
97
-		 * PHP tags <? ?>
98
-		 *
99
-		 * True: php tags are enabled into the template
100
-		 * False: php tags are disabled into the template and rendered as html
101
-		 *
102
-		 * @var bool
103
-		 */
104
-		static $php_enabled = false;
105
-
106
-
107
-		/**
108
-		 * Debug mode flag
109
-		 *
110
-		 * True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated.
111
-		 * False: exception is thrown on found error.
112
-		 *
113
-		 * @var bool
114
-		 */
115
-		static $debug = false;
116
-
117
-	// -------------------------
118
-
119
-
120
-	// -------------------------
121
-	// 	RAINTPL VARIABLES
122
-	// -------------------------
123
-
124
-		/**
125
-		 * Is the array where RainTPL keep the variables assigned
126
-		 *
127
-		 * @var array
128
-		 */
129
-		public $var = array();
130
-
131
-		/**
132
-		 * variables to keep the template directories and info
133
-		 *
134
-		 * @var array
135
-		 */
136
-		protected $tpl = array();		//
137
-
138
-		/**
139
-		 * static cache enabled / disabled
140
-		 *
141
-		 * @var bool
142
-		 */
143
-		protected $cache = false;
144
-
145
-		/**
146
-		 * identify only one cache
147
-		 *
148
-		 * @var string
149
-		 */
150
-		protected $cache_id = '';
151
-
152
-		/**
153
-		 * takes all the config to create the md5 of the file
154
-		 *
155
-		 * @var array the file
156
-		 */
157
-		protected static $config_name_sum = array();
158
-
159
-	// -------------------------
160
-
161
-
162
-
163
-	/**
164
-	 * default cache expire time = hour
165
-	 *
166
-	 * @const int
167
-	 */
168
-	const CACHE_EXPIRE_TIME = 3600;
169
-
170
-
171
-
172
-	/**
173
-	 * Assign variable
174
-	 * eg. 	$t->assign('name','mickey');
175
-	 *
176
-	 * @access public
177
-	 * @param  mixed $variable_name Name of template variable or associative array name/value
178
-	 * @param  mixed $value value assigned to this variable. Not set if variable_name is an associative array
179
-	 */
180
-	public function assign( $variable, $value = null ){
181
-		if( is_array( $variable ) )
182
-			$this->var += $variable;
183
-		else
184
-			$this->var[ $variable ] = $value;
185
-	}
186
-
187
-
188
-
189
-	/**
190
-	 * Draw the template
191
-	 * eg. 	$html = $tpl->draw( 'demo', TRUE ); // return template in string
192
-	 * or 	$tpl->draw( $tpl_name ); // echo the template
193
-	 *
194
-	 * @access public
195
-	 * @param  string $tpl_name  template to load
196
-	 * @param  boolean $return_string  true=return a string, false=echo the template
197
-	 * @return string
198
-	 */
199
-	public function draw( $tpl_name, $return_string = false ){
200
-
201
-		try {
202
-			// compile the template if necessary and set the template filepath
203
-			$this->check_template( $tpl_name );
204
-		} catch (RainTpl_Exception $e) {
205
-			$output = $this->printDebug($e);
206
-			die($output);
207
-		}
208
-
209
-		// Cache is off and, return_string is false
210
-		// Rain just echo the template
211
-
212
-		if( !$this->cache && !$return_string ){
213
-			extract( $this->var );
214
-			include $this->tpl['compiled_filename'];
215
-			unset( $this->tpl );
216
-		}
217
-
218
-
219
-		// cache or return_string are enabled
220
-		// rain get the output buffer to save the output in the cache or to return it as string
221
-
222
-		else{
223
-
224
-			//----------------------
225
-			// get the output buffer
226
-			//----------------------
227
-				ob_start();
228
-				extract( $this->var );
229
-				include $this->tpl['compiled_filename'];
230
-				$raintpl_contents = ob_get_clean();
231
-			//----------------------
232
-
233
-
234
-			// save the output in the cache
235
-			if( $this->cache )
236
-				file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents );
237
-
238
-			// free memory
239
-			unset( $this->tpl );
240
-
241
-			// return or print the template
242
-			if( $return_string ) return $raintpl_contents; else echo $raintpl_contents;
243
-
244
-		}
245
-
246
-	}
247
-
248
-
249
-
250
-	/**
251
-	 * If exists a valid cache for this template it returns the cache
252
-	 *
253
-	 * @access public
254
-	 * @param  string $tpl_name Name of template (set the same of draw)
255
-	 * @param  int $expiration_time Set after how many seconds the cache expire and must be regenerated
256
-	 * @param  string $cache_id Suffix to be used when writing file to cache (optional)
257
-	 * @return string it return the HTML or null if the cache must be recreated
258
-	 */
259
-	public function cache( $tpl_name, $expire_time = self::CACHE_EXPIRE_TIME, $cache_id = '' ){
260
-
261
-		// set the cache_id
262
-		$this->cache_id = $cache_id;
263
-
264
-		if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) )
265
-			return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 );
266
-		else{
267
-			//delete the cache of the selected template
268
-			if (file_exists($this->tpl['cache_filename']))
269
-			unlink($this->tpl['cache_filename'] );
270
-			$this->cache = true;
271
-		}
272
-	}
273
-
274
-
275
-
276
-	/**
277
-	 * Configure the settings of RainTPL
278
-	 *
279
-	 * @access public
280
-	 * @static
281
-	 * @param  array|string $setting array of settings or setting name
282
-	 * @param  mixed $value content to set in the setting (optional)
283
-	 */
284
-	public static function configure( $setting, $value = null ){
285
-		if( is_array( $setting ) )
286
-			foreach( $setting as $key => $value )
287
-				self::configure( $key, $value );
288
-		else if( property_exists( __CLASS__, $setting ) ){
289
-			self::$$setting = $value;
290
-			self::$config_name_sum[ $setting ] = $value; // take trace of all config
291
-		}
292
-	}
293
-
294
-
295
-
296
-	/**
297
-	 * Check if has to compile the template
298
-	 *
299
-	 * @access protected
300
-	 * @param  string $tpl_name template name to check
301
-	 * @throws RainTpl_NotFoundException
302
-	 * @return bool return true if the template has changed
303
-	 */
304
-	protected function check_template( $tpl_name ){
305
-
306
-		if( !isset($this->tpl['checked']) ){
307
-
308
-			$tpl_basename					   = basename( $tpl_name );														// template basename
309
-			$tpl_basedir						= strpos($tpl_name,"/") ? dirname($tpl_name) . '/' : null;						// template basedirectory
310
-			$tpl_dir							= PATH . self::$tpl_dir . $tpl_basedir;								// template directory
311
-			$this->tpl['tpl_filename']		  = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;	// template filename
312
-			$temp_compiled_filename			 = PATH . self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . serialize(self::$config_name_sum));
313
-			$this->tpl['compiled_filename']	 = $temp_compiled_filename . '.rtpl.php';	// cache filename
314
-			$this->tpl['cache_filename']		= $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';	// static cache filename
315
-
316
-			// if the template doesn't exsist throw an error
317
-			if( self::$check_template_update && !file_exists( $this->tpl['tpl_filename'] ) ){
318
-				$e = new RainTpl_NotFoundException( 'Template '. $tpl_basename .' not found!' );
319
-				throw $e->setTemplateFile($this->tpl['tpl_filename']);
320
-			}
321
-
322
-			// file doesn't exsist, or the template was updated, Rain will compile the template
323
-			if( !file_exists( $this->tpl['compiled_filename'] ) || ( self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime( $this->tpl['tpl_filename'] ) ) ){
324
-				$this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename'] );
325
-				return true;
326
-			}
327
-			$this->tpl['checked'] = true;
328
-		}
329
-	}
330
-
331
-
332
-
333
-	/**
334
-	 * execute stripslaches() on the xml block. Invoqued by preg_replace_callback function below
335
-	 *
336
-	 * @access protected
337
-	 * @param string $capture
338
-	 * @return string
339
-	 */
340
-	protected function xml_reSubstitution($capture) {
341
-			return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>";
342
-	}
343
-
344
-
345
-
346
-	/**
347
-	 * Compile and write the compiled template file
348
-	 *
349
-	 * @access protected
350
-	 * @param  string $tpl_basename
351
-	 * @param  string $tpl_basedir
352
-	 * @param  string $tpl_filename
353
-	 * @param  string $cache_dir
354
-	 * @param  string $compiled_filename
355
-	 * @throws RainTpl_Exception
356
-	 * @return void
357
-	 */
358
-	protected function compileFile( $tpl_basename, $tpl_basedir, $tpl_filename, $cache_dir, $compiled_filename ){
359
-
360
-		//read template file
361
-		$this->tpl['source'] = $template_code = file_get_contents( $tpl_filename );
362
-
363
-		//xml substitution
364
-		$template_code = preg_replace( "/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code );
365
-
366
-		//disable php tag
367
-		if( !self::$php_enabled )
368
-			$template_code = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $template_code );
369
-
370
-		//xml re-substitution
371
-		$template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
372
-
373
-		//compile template
374
-		$template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir );
375
-
376
-
377
-		// fix the php-eating-newline-after-closing-tag-problem
378
-		$template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled );
379
-
380
-		// create directories
381
-		if( !is_dir( $cache_dir ) )
382
-			mkdir( $cache_dir, 0755, true );
383
-
384
-		if( !is_writable( $cache_dir ) )
385
-			throw new RainTpl_Exception ('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
386
-
387
-		//write compiled file
388
-		file_put_contents( $compiled_filename, $template_compiled );
389
-	}
390
-
391
-
392
-
393
-	/**
394
-	 * Compile template
395
-	 *
396
-	 * @access protected
397
-	 * @param  string $template_code
398
-	 * @param  string $tpl_basedir
399
-	 * @return string
400
-	 */
401
-	protected function compileTemplate( $template_code, $tpl_basedir ){
402
-
403
-		//tag list
404
-		$tag_regexp = array( 'loop'		 => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})',
405
-							 'loop_close'   => '(\{\/loop\})',
406
-							 'if'		   => '(\{if(?: condition){0,1}="[^"]*"\})',
407
-							 'elseif'	   => '(\{elseif(?: condition){0,1}="[^"]*"\})',
408
-							 'else'		 => '(\{else\})',
409
-							 'if_close'	 => '(\{\/if\})',
410
-							 'function'	 => '(\{function="[^"]*"\})',
411
-							 'noparse'	  => '(\{noparse\})',
412
-							 'noparse_close'=> '(\{\/noparse\})',
413
-							 'ignore'	   => '(\{ignore\}|\{\*)',
414
-							 'ignore_close'	=> '(\{\/ignore\}|\*\})',
415
-							 'include'	  => '(\{include="[^"]*"(?: cache="[^"]*")?\})',
416
-							 'template_info'=> '(\{\$template_info\})',
417
-							 'function'		=> '(\{function="(\w*?)(?:.*?)"\})'
418
-							);
419
-
420
-		$tag_regexp = "/" . join( "|", $tag_regexp ) . "/";
421
-
422
-		//split the code with the tags regexp
423
-		$template_code = preg_split ( $tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
424
-
425
-		//path replace (src of img, background and href of link)
426
-		$template_code = $this->path_replace( $template_code, $tpl_basedir );
427
-
428
-		//compile the code
429
-		$compiled_code = $this->compileCode( $template_code );
430
-
431
-		//return the compiled code
432
-		return $compiled_code;
433
-
434
-	}
17
+    // -------------------------
18
+    // 	CONFIGURATION
19
+    // -------------------------
20
+
21
+        /**
22
+         * Template directory
23
+         *
24
+         * @var string
25
+         */
26
+        static $tpl_dir = 'tpl/';
27
+
28
+
29
+        /**
30
+         * Cache directory
31
+         *
32
+         * Is the directory where RainTPL will compile the template and save the cache
33
+         *
34
+         * @var string
35
+         */
36
+        static $cache_dir = 'tmp/';
37
+
38
+
39
+        /**
40
+         * Template base URL
41
+         *
42
+         * RainTPL will add this URL to the relative paths of element selected in $path_replace_list.
43
+         *
44
+         * @var string
45
+         */
46
+        static $base_url = null;
47
+
48
+
49
+        /**
50
+         * Template extension
51
+         *
52
+         * @var string
53
+         */
54
+        static $tpl_ext = "html";
55
+
56
+
57
+        /**
58
+         * Should the path be replaced
59
+         *
60
+         * Path replace is a cool features that replace all relative paths of images (&lt;img src="..."&gt;), stylesheet (&lt;link href="..."&gt;), script (&lt;script src="..."&gt;) and link (&lt;a href="..."&gt;)
61
+         * Set true to enable the path replace.
62
+         *
63
+         * @var boolean
64
+         */
65
+        static $path_replace = true;
66
+
67
+
68
+        /**
69
+         * You can set what the path_replace method will replace.
70
+         * Avaible options: a, img, link, script, input
71
+         *
72
+         * @var array
73
+         */
74
+        static $path_replace_list = array( 'a', 'img', 'link', 'script', 'input' );
75
+
76
+
77
+        /**
78
+         * You can define in the black list what string are disabled into the template tags
79
+         *
80
+         * @var array
81
+         */
82
+        static $black_list = array( '\$this', 'raintpl::', 'self::', '_SESSION', '_SERVER', '_ENV',  'eval', 'exec', 'unlink', 'rmdir' );
83
+
84
+
85
+        /**
86
+         * Check template
87
+         *
88
+         * true: checks template update time, if changed it compile them
89
+         * false: loads the compiled template. Set false if server doesn't have write permission for cache_directory.
90
+         *
91
+         * @var bool
92
+         */
93
+        static $check_template_update = true;
94
+
95
+
96
+        /**
97
+         * PHP tags <? ?>
98
+         *
99
+         * True: php tags are enabled into the template
100
+         * False: php tags are disabled into the template and rendered as html
101
+         *
102
+         * @var bool
103
+         */
104
+        static $php_enabled = false;
105
+
106
+
107
+        /**
108
+         * Debug mode flag
109
+         *
110
+         * True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated.
111
+         * False: exception is thrown on found error.
112
+         *
113
+         * @var bool
114
+         */
115
+        static $debug = false;
116
+
117
+    // -------------------------
118
+
119
+
120
+    // -------------------------
121
+    // 	RAINTPL VARIABLES
122
+    // -------------------------
123
+
124
+        /**
125
+         * Is the array where RainTPL keep the variables assigned
126
+         *
127
+         * @var array
128
+         */
129
+        public $var = array();
130
+
131
+        /**
132
+         * variables to keep the template directories and info
133
+         *
134
+         * @var array
135
+         */
136
+        protected $tpl = array();		//
137
+
138
+        /**
139
+         * static cache enabled / disabled
140
+         *
141
+         * @var bool
142
+         */
143
+        protected $cache = false;
144
+
145
+        /**
146
+         * identify only one cache
147
+         *
148
+         * @var string
149
+         */
150
+        protected $cache_id = '';
151
+
152
+        /**
153
+         * takes all the config to create the md5 of the file
154
+         *
155
+         * @var array the file
156
+         */
157
+        protected static $config_name_sum = array();
158
+
159
+    // -------------------------
160
+
161
+
162
+
163
+    /**
164
+     * default cache expire time = hour
165
+     *
166
+     * @const int
167
+     */
168
+    const CACHE_EXPIRE_TIME = 3600;
169
+
170
+
171
+
172
+    /**
173
+     * Assign variable
174
+     * eg. 	$t->assign('name','mickey');
175
+     *
176
+     * @access public
177
+     * @param  mixed $variable_name Name of template variable or associative array name/value
178
+     * @param  mixed $value value assigned to this variable. Not set if variable_name is an associative array
179
+     */
180
+    public function assign( $variable, $value = null ){
181
+        if( is_array( $variable ) )
182
+            $this->var += $variable;
183
+        else
184
+            $this->var[ $variable ] = $value;
185
+    }
186
+
187
+
188
+
189
+    /**
190
+     * Draw the template
191
+     * eg. 	$html = $tpl->draw( 'demo', TRUE ); // return template in string
192
+     * or 	$tpl->draw( $tpl_name ); // echo the template
193
+     *
194
+     * @access public
195
+     * @param  string $tpl_name  template to load
196
+     * @param  boolean $return_string  true=return a string, false=echo the template
197
+     * @return string
198
+     */
199
+    public function draw( $tpl_name, $return_string = false ){
200
+
201
+        try {
202
+            // compile the template if necessary and set the template filepath
203
+            $this->check_template( $tpl_name );
204
+        } catch (RainTpl_Exception $e) {
205
+            $output = $this->printDebug($e);
206
+            die($output);
207
+        }
208
+
209
+        // Cache is off and, return_string is false
210
+        // Rain just echo the template
211
+
212
+        if( !$this->cache && !$return_string ){
213
+            extract( $this->var );
214
+            include $this->tpl['compiled_filename'];
215
+            unset( $this->tpl );
216
+        }
217
+
218
+
219
+        // cache or return_string are enabled
220
+        // rain get the output buffer to save the output in the cache or to return it as string
221
+
222
+        else{
223
+
224
+            //----------------------
225
+            // get the output buffer
226
+            //----------------------
227
+                ob_start();
228
+                extract( $this->var );
229
+                include $this->tpl['compiled_filename'];
230
+                $raintpl_contents = ob_get_clean();
231
+            //----------------------
232
+
233
+
234
+            // save the output in the cache
235
+            if( $this->cache )
236
+                file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents );
237
+
238
+            // free memory
239
+            unset( $this->tpl );
240
+
241
+            // return or print the template
242
+            if( $return_string ) return $raintpl_contents; else echo $raintpl_contents;
243
+
244
+        }
245
+
246
+    }
247
+
248
+
249
+
250
+    /**
251
+     * If exists a valid cache for this template it returns the cache
252
+     *
253
+     * @access public
254
+     * @param  string $tpl_name Name of template (set the same of draw)
255
+     * @param  int $expiration_time Set after how many seconds the cache expire and must be regenerated
256
+     * @param  string $cache_id Suffix to be used when writing file to cache (optional)
257
+     * @return string it return the HTML or null if the cache must be recreated
258
+     */
259
+    public function cache( $tpl_name, $expire_time = self::CACHE_EXPIRE_TIME, $cache_id = '' ){
260
+
261
+        // set the cache_id
262
+        $this->cache_id = $cache_id;
263
+
264
+        if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) )
265
+            return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 );
266
+        else{
267
+            //delete the cache of the selected template
268
+            if (file_exists($this->tpl['cache_filename']))
269
+            unlink($this->tpl['cache_filename'] );
270
+            $this->cache = true;
271
+        }
272
+    }
273
+
274
+
275
+
276
+    /**
277
+     * Configure the settings of RainTPL
278
+     *
279
+     * @access public
280
+     * @static
281
+     * @param  array|string $setting array of settings or setting name
282
+     * @param  mixed $value content to set in the setting (optional)
283
+     */
284
+    public static function configure( $setting, $value = null ){
285
+        if( is_array( $setting ) )
286
+            foreach( $setting as $key => $value )
287
+                self::configure( $key, $value );
288
+        else if( property_exists( __CLASS__, $setting ) ){
289
+            self::$$setting = $value;
290
+            self::$config_name_sum[ $setting ] = $value; // take trace of all config
291
+        }
292
+    }
293
+
294
+
295
+
296
+    /**
297
+     * Check if has to compile the template
298
+     *
299
+     * @access protected
300
+     * @param  string $tpl_name template name to check
301
+     * @throws RainTpl_NotFoundException
302
+     * @return bool return true if the template has changed
303
+     */
304
+    protected function check_template( $tpl_name ){
305
+
306
+        if( !isset($this->tpl['checked']) ){
307
+
308
+            $tpl_basename					   = basename( $tpl_name );														// template basename
309
+            $tpl_basedir						= strpos($tpl_name,"/") ? dirname($tpl_name) . '/' : null;						// template basedirectory
310
+            $tpl_dir							= PATH . self::$tpl_dir . $tpl_basedir;								// template directory
311
+            $this->tpl['tpl_filename']		  = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;	// template filename
312
+            $temp_compiled_filename			 = PATH . self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . serialize(self::$config_name_sum));
313
+            $this->tpl['compiled_filename']	 = $temp_compiled_filename . '.rtpl.php';	// cache filename
314
+            $this->tpl['cache_filename']		= $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';	// static cache filename
315
+
316
+            // if the template doesn't exsist throw an error
317
+            if( self::$check_template_update && !file_exists( $this->tpl['tpl_filename'] ) ){
318
+                $e = new RainTpl_NotFoundException( 'Template '. $tpl_basename .' not found!' );
319
+                throw $e->setTemplateFile($this->tpl['tpl_filename']);
320
+            }
321
+
322
+            // file doesn't exsist, or the template was updated, Rain will compile the template
323
+            if( !file_exists( $this->tpl['compiled_filename'] ) || ( self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime( $this->tpl['tpl_filename'] ) ) ){
324
+                $this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename'] );
325
+                return true;
326
+            }
327
+            $this->tpl['checked'] = true;
328
+        }
329
+    }
330
+
331
+
332
+
333
+    /**
334
+     * execute stripslaches() on the xml block. Invoqued by preg_replace_callback function below
335
+     *
336
+     * @access protected
337
+     * @param string $capture
338
+     * @return string
339
+     */
340
+    protected function xml_reSubstitution($capture) {
341
+            return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>";
342
+    }
343
+
344
+
345
+
346
+    /**
347
+     * Compile and write the compiled template file
348
+     *
349
+     * @access protected
350
+     * @param  string $tpl_basename
351
+     * @param  string $tpl_basedir
352
+     * @param  string $tpl_filename
353
+     * @param  string $cache_dir
354
+     * @param  string $compiled_filename
355
+     * @throws RainTpl_Exception
356
+     * @return void
357
+     */
358
+    protected function compileFile( $tpl_basename, $tpl_basedir, $tpl_filename, $cache_dir, $compiled_filename ){
359
+
360
+        //read template file
361
+        $this->tpl['source'] = $template_code = file_get_contents( $tpl_filename );
362
+
363
+        //xml substitution
364
+        $template_code = preg_replace( "/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code );
365
+
366
+        //disable php tag
367
+        if( !self::$php_enabled )
368
+            $template_code = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $template_code );
369
+
370
+        //xml re-substitution
371
+        $template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
372
+
373
+        //compile template
374
+        $template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir );
375
+
376
+
377
+        // fix the php-eating-newline-after-closing-tag-problem
378
+        $template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled );
379
+
380
+        // create directories
381
+        if( !is_dir( $cache_dir ) )
382
+            mkdir( $cache_dir, 0755, true );
383
+
384
+        if( !is_writable( $cache_dir ) )
385
+            throw new RainTpl_Exception ('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
386
+
387
+        //write compiled file
388
+        file_put_contents( $compiled_filename, $template_compiled );
389
+    }
390
+
391
+
392
+
393
+    /**
394
+     * Compile template
395
+     *
396
+     * @access protected
397
+     * @param  string $template_code
398
+     * @param  string $tpl_basedir
399
+     * @return string
400
+     */
401
+    protected function compileTemplate( $template_code, $tpl_basedir ){
402
+
403
+        //tag list
404
+        $tag_regexp = array( 'loop'		 => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})',
405
+                                'loop_close'   => '(\{\/loop\})',
406
+                                'if'		   => '(\{if(?: condition){0,1}="[^"]*"\})',
407
+                                'elseif'	   => '(\{elseif(?: condition){0,1}="[^"]*"\})',
408
+                                'else'		 => '(\{else\})',
409
+                                'if_close'	 => '(\{\/if\})',
410
+                                'function'	 => '(\{function="[^"]*"\})',
411
+                                'noparse'	  => '(\{noparse\})',
412
+                                'noparse_close'=> '(\{\/noparse\})',
413
+                                'ignore'	   => '(\{ignore\}|\{\*)',
414
+                                'ignore_close'	=> '(\{\/ignore\}|\*\})',
415
+                                'include'	  => '(\{include="[^"]*"(?: cache="[^"]*")?\})',
416
+                                'template_info'=> '(\{\$template_info\})',
417
+                                'function'		=> '(\{function="(\w*?)(?:.*?)"\})'
418
+                            );
419
+
420
+        $tag_regexp = "/" . join( "|", $tag_regexp ) . "/";
421
+
422
+        //split the code with the tags regexp
423
+        $template_code = preg_split ( $tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
424
+
425
+        //path replace (src of img, background and href of link)
426
+        $template_code = $this->path_replace( $template_code, $tpl_basedir );
427
+
428
+        //compile the code
429
+        $compiled_code = $this->compileCode( $template_code );
430
+
431
+        //return the compiled code
432
+        return $compiled_code;
433
+
434
+    }
435 435
 
436 436
 
437 437
 
438
-	/**
439
-	 * Compile the code
440
-	 *
441
-	 * @access protected
442
-	 * @param  string $parsed_code
443
-	 * @throws RainTpl_SyntaxException
444
-	 * @return string
445
-	 */
446
-	protected function compileCode( $parsed_code ){
438
+    /**
439
+     * Compile the code
440
+     *
441
+     * @access protected
442
+     * @param  string $parsed_code
443
+     * @throws RainTpl_SyntaxException
444
+     * @return string
445
+     */
446
+    protected function compileCode( $parsed_code ){
447 447
 
448
-		//variables initialization
449
-		$compiled_code = $open_if = $comment_is_open = $ignore_is_open = null;
450
-		$loop_level = 0;
448
+        //variables initialization
449
+        $compiled_code = $open_if = $comment_is_open = $ignore_is_open = null;
450
+        $loop_level = 0;
451 451
 
452
-		//read all parsed code
453
-		while( $html = array_shift( $parsed_code ) ){
452
+        //read all parsed code
453
+        while( $html = array_shift( $parsed_code ) ){
454 454
 
455
-			//close ignore tag
456
-			if( !$comment_is_open && ( strpos( $html, '{/ignore}' ) !== FALSE || strpos( $html, '*}' ) !== FALSE ) )
457
-				$ignore_is_open = false;
455
+            //close ignore tag
456
+            if( !$comment_is_open && ( strpos( $html, '{/ignore}' ) !== FALSE || strpos( $html, '*}' ) !== FALSE ) )
457
+                $ignore_is_open = false;
458 458
 
459
-			//code between tag ignore id deleted
460
-			elseif( $ignore_is_open ){
461
-				//ignore the code
462
-			}
459
+            //code between tag ignore id deleted
460
+            elseif( $ignore_is_open ){
461
+                //ignore the code
462
+            }
463 463
 
464
-			//close no parse tag
465
-			elseif( strpos( $html, '{/noparse}' ) !== FALSE )
466
-				$comment_is_open = false;
464
+            //close no parse tag
465
+            elseif( strpos( $html, '{/noparse}' ) !== FALSE )
466
+                $comment_is_open = false;
467 467
 
468
-			//code between tag noparse is not compiled
469
-			elseif( $comment_is_open )
470
-				$compiled_code .= $html;
468
+            //code between tag noparse is not compiled
469
+            elseif( $comment_is_open )
470
+                $compiled_code .= $html;
471 471
 
472
-			//ignore
473
-			elseif( strpos( $html, '{ignore}' ) !== FALSE || strpos( $html, '{*' ) !== FALSE )
474
-				$ignore_is_open = true;
472
+            //ignore
473
+            elseif( strpos( $html, '{ignore}' ) !== FALSE || strpos( $html, '{*' ) !== FALSE )
474
+                $ignore_is_open = true;
475 475
 
476
-			//noparse
477
-			elseif( strpos( $html, '{noparse}' ) !== FALSE )
478
-				$comment_is_open = true;
476
+            //noparse
477
+            elseif( strpos( $html, '{noparse}' ) !== FALSE )
478
+                $comment_is_open = true;
479 479
 
480
-			//include tag
481
-			elseif( preg_match( '/\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\}/', $html, $code ) ){
480
+            //include tag
481
+            elseif( preg_match( '/\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\}/', $html, $code ) ){
482 482
 
483
-				//variables substitution
484
-				$include_var = $this->var_replace( $code[ 1 ], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".' , $php_right_delimiter = '."', $loop_level );
483
+                //variables substitution
484
+                $include_var = $this->var_replace( $code[ 1 ], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".' , $php_right_delimiter = '."', $loop_level );
485 485
 
486
-				// if the cache is active
487
-				if( isset($code[ 2 ]) ){
486
+                // if the cache is active
487
+                if( isset($code[ 2 ]) ){
488 488
 
489
-					//dynamic include
490
-					$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
491
-								 'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' .
492
-								 '	echo $cache;' .
493
-								 'else{' .
494
-								 '	$tpl_dir_temp = self::$tpl_dir;' .
495
-								 '	$tpl->assign( $this->var );' .
496
-									( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
497
-								 '	$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
498
-								 '} ?>';
499
-				}
500
-				else{
489
+                    //dynamic include
490
+                    $compiled_code .= '<?php $tpl = new '.get_class($this).';' .
491
+                                    'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' .
492
+                                    '	echo $cache;' .
493
+                                    'else{' .
494
+                                    '	$tpl_dir_temp = self::$tpl_dir;' .
495
+                                    '	$tpl->assign( $this->var );' .
496
+                                    ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
497
+                                    '	$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
498
+                                    '} ?>';
499
+                }
500
+                else{
501 501
 
502
-					//dynamic include
503
-					$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
504
-									  '$tpl_dir_temp = self::$tpl_dir;' .
505
-									  '$tpl->assign( $this->var );' .
506
-									  ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
507
-									  '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
508
-									  '?>';
502
+                    //dynamic include
503
+                    $compiled_code .= '<?php $tpl = new '.get_class($this).';' .
504
+                                        '$tpl_dir_temp = self::$tpl_dir;' .
505
+                                        '$tpl->assign( $this->var );' .
506
+                                        ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
507
+                                        '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
508
+                                        '?>';
509 509
 
510 510
 
511
-				}
511
+                }
512 512
 
513
-			}
513
+            }
514 514
 
515
-			//loop
516
-			elseif( preg_match( '/\{loop(?: name){0,1}="\${0,1}([^"]*)"\}/', $html, $code ) ){
515
+            //loop
516
+            elseif( preg_match( '/\{loop(?: name){0,1}="\${0,1}([^"]*)"\}/', $html, $code ) ){
517 517
 
518
-				//increase the loop counter
519
-				$loop_level++;
518
+                //increase the loop counter
519
+                $loop_level++;
520 520
 
521
-				//replace the variable in the loop
522
-				$var = $this->var_replace( '$' . $code[ 1 ], $tag_left_delimiter=null, $tag_right_delimiter=null, $php_left_delimiter=null, $php_right_delimiter=null, $loop_level-1 );
521
+                //replace the variable in the loop
522
+                $var = $this->var_replace( '$' . $code[ 1 ], $tag_left_delimiter=null, $tag_right_delimiter=null, $php_left_delimiter=null, $php_right_delimiter=null, $loop_level-1 );
523 523
 
524
-				//loop variables
525
-				$counter = "\$counter$loop_level";	   // count iteration
526
-				$key = "\$key$loop_level";			   // key
527
-				$value = "\$value$loop_level";		   // value
524
+                //loop variables
525
+                $counter = "\$counter$loop_level";	   // count iteration
526
+                $key = "\$key$loop_level";			   // key
527
+                $value = "\$value$loop_level";		   // value
528 528
 
529
-				//loop code
530
-				$compiled_code .=  "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>";
529
+                //loop code
530
+                $compiled_code .=  "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>";
531 531
 
532
-			}
532
+            }
533 533
 
534
-			//close loop tag
535
-			elseif( strpos( $html, '{/loop}' ) !== FALSE ) {
534
+            //close loop tag
535
+            elseif( strpos( $html, '{/loop}' ) !== FALSE ) {
536 536
 
537
-				//iterator
538
-				$counter = "\$counter$loop_level";
537
+                //iterator
538
+                $counter = "\$counter$loop_level";
539 539
 
540
-				//decrease the loop counter
541
-				$loop_level--;
540
+                //decrease the loop counter
541
+                $loop_level--;
542 542
 
543
-				//close loop code
544
-				$compiled_code .=  "<?php } ?>";
543
+                //close loop code
544
+                $compiled_code .=  "<?php } ?>";
545 545
 
546
-			}
546
+            }
547 547
 
548
-			//if
549
-			elseif( preg_match( '/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
548
+            //if
549
+            elseif( preg_match( '/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
550 550
 
551
-				//increase open if counter (for intendation)
552
-				$open_if++;
551
+                //increase open if counter (for intendation)
552
+                $open_if++;
553 553
 
554
-				//tag
555
-				$tag = $code[ 0 ];
554
+                //tag
555
+                $tag = $code[ 0 ];
556 556
 
557
-				//condition attribute
558
-				$condition = $code[ 1 ];
557
+                //condition attribute
558
+                $condition = $code[ 1 ];
559 559
 
560
-				// check if there's any function disabled by black_list
561
-				$this->function_check( $tag );
560
+                // check if there's any function disabled by black_list
561
+                $this->function_check( $tag );
562 562
 
563
-				//variable substitution into condition (no delimiter into the condition)
564
-				$parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
563
+                //variable substitution into condition (no delimiter into the condition)
564
+                $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
565 565
 
566
-				//if code
567
-				$compiled_code .=   "<?php if( $parsed_condition ){ ?>";
566
+                //if code
567
+                $compiled_code .=   "<?php if( $parsed_condition ){ ?>";
568 568
 
569
-			}
569
+            }
570 570
 
571
-			//elseif
572
-			elseif( preg_match( '/\{elseif(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
571
+            //elseif
572
+            elseif( preg_match( '/\{elseif(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
573 573
 
574
-				//tag
575
-				$tag = $code[ 0 ];
574
+                //tag
575
+                $tag = $code[ 0 ];
576 576
 
577
-				//condition attribute
578
-				$condition = $code[ 1 ];
577
+                //condition attribute
578
+                $condition = $code[ 1 ];
579 579
 
580
-				//variable substitution into condition (no delimiter into the condition)
581
-				$parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
580
+                //variable substitution into condition (no delimiter into the condition)
581
+                $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
582 582
 
583
-				//elseif code
584
-				$compiled_code .=   "<?php }elseif( $parsed_condition ){ ?>";
585
-			}
583
+                //elseif code
584
+                $compiled_code .=   "<?php }elseif( $parsed_condition ){ ?>";
585
+            }
586 586
 
587
-			//else
588
-			elseif( strpos( $html, '{else}' ) !== FALSE ) {
587
+            //else
588
+            elseif( strpos( $html, '{else}' ) !== FALSE ) {
589 589
 
590
-				//else code
591
-				$compiled_code .=   '<?php }else{ ?>';
590
+                //else code
591
+                $compiled_code .=   '<?php }else{ ?>';
592 592
 
593
-			}
593
+            }
594 594
 
595
-			//close if tag
596
-			elseif( strpos( $html, '{/if}' ) !== FALSE ) {
595
+            //close if tag
596
+            elseif( strpos( $html, '{/if}' ) !== FALSE ) {
597 597
 
598
-				//decrease if counter
599
-				$open_if--;
598
+                //decrease if counter
599
+                $open_if--;
600 600
 
601
-				// close if code
602
-				$compiled_code .=   '<?php } ?>';
601
+                // close if code
602
+                $compiled_code .=   '<?php } ?>';
603 603
 
604
-			}
604
+            }
605 605
 
606
-			//function
607
-			elseif( preg_match( '/\{function="(\w*)(.*?)"\}/', $html, $code ) ){
606
+            //function
607
+            elseif( preg_match( '/\{function="(\w*)(.*?)"\}/', $html, $code ) ){
608 608
 
609
-				//tag
610
-				$tag = $code[ 0 ];
609
+                //tag
610
+                $tag = $code[ 0 ];
611 611
 
612
-				//function
613
-				$function = $code[ 1 ];
612
+                //function
613
+                $function = $code[ 1 ];
614 614
 
615
-				// check if there's any function disabled by black_list
616
-				$this->function_check( $tag );
615
+                // check if there's any function disabled by black_list
616
+                $this->function_check( $tag );
617 617
 
618
-				if( empty( $code[ 2 ] ) )
619
-					$parsed_function = $function . "()";
620
-				else
621
-					// parse the function
622
-					$parsed_function = $function . $this->var_replace( $code[ 2 ], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
618
+                if( empty( $code[ 2 ] ) )
619
+                    $parsed_function = $function . "()";
620
+                else
621
+                    // parse the function
622
+                    $parsed_function = $function . $this->var_replace( $code[ 2 ], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
623 623
 
624
-				//if code
625
-				$compiled_code .=   "<?php echo $parsed_function; ?>";
626
-			}
624
+                //if code
625
+                $compiled_code .=   "<?php echo $parsed_function; ?>";
626
+            }
627 627
 
628
-			// show all vars
629
-			elseif ( strpos( $html, '{$template_info}' ) !== FALSE ) {
628
+            // show all vars
629
+            elseif ( strpos( $html, '{$template_info}' ) !== FALSE ) {
630 630
 
631
-				//tag
632
-				$tag  = '{$template_info}';
631
+                //tag
632
+                $tag  = '{$template_info}';
633 633
 
634
-				//if code
635
-				$compiled_code .=   '<?php echo "<pre>"; print_r( $this->var ); echo "</pre>"; ?>';
636
-			}
634
+                //if code
635
+                $compiled_code .=   '<?php echo "<pre>"; print_r( $this->var ); echo "</pre>"; ?>';
636
+            }
637 637
 
638 638
 
639
-			//all html code
640
-			else{
639
+            //all html code
640
+            else{
641 641
 
642
-				//variables substitution (es. {$title})
643
-				$html = $this->var_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
644
-				//const substitution (es. {#CONST#})
645
-				$html = $this->const_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
646
-				//functions substitution (es. {"string"|functions})
647
-				$compiled_code .= $this->func_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
648
-			}
649
-		}
642
+                //variables substitution (es. {$title})
643
+                $html = $this->var_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
644
+                //const substitution (es. {#CONST#})
645
+                $html = $this->const_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
646
+                //functions substitution (es. {"string"|functions})
647
+                $compiled_code .= $this->func_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
648
+            }
649
+        }
650 650
 
651
-		if( $open_if > 0 ) {
652
-			$e = new RainTpl_SyntaxException('Error! You need to close an {if} tag in ' . $this->tpl['tpl_filename'] . ' template');
653
-			throw $e->setTemplateFile($this->tpl['tpl_filename']);
654
-		}
655
-		return $compiled_code;
656
-	}
651
+        if( $open_if > 0 ) {
652
+            $e = new RainTpl_SyntaxException('Error! You need to close an {if} tag in ' . $this->tpl['tpl_filename'] . ' template');
653
+            throw $e->setTemplateFile($this->tpl['tpl_filename']);
654
+        }
655
+        return $compiled_code;
656
+    }
657 657
 
658 658
 
659 659
 
660
-	/**
661
-	 * Reduce a path
662
-	 *
663
-	 * eg. www/library/../filepath//file => www/filepath/file
664
-	 *
665
-	 * @param string $path
666
-	 * @return string
667
-	 */
668
-	protected function reduce_path( $path ){
669
-		$path = str_replace( "://", "@not_replace@", $path );
670
-		$path = str_replace( "//", "/", $path );
671
-		$path = str_replace( "@not_replace@", "://", $path );
672
-		return preg_replace('/\w+\/\.\.\//', '', $path );
673
-	}
660
+    /**
661
+     * Reduce a path
662
+     *
663
+     * eg. www/library/../filepath//file => www/filepath/file
664
+     *
665
+     * @param string $path
666
+     * @return string
667
+     */
668
+    protected function reduce_path( $path ){
669
+        $path = str_replace( "://", "@not_replace@", $path );
670
+        $path = str_replace( "//", "/", $path );
671
+        $path = str_replace( "@not_replace@", "://", $path );
672
+        return preg_replace('/\w+\/\.\.\//', '', $path );
673
+    }
674 674
 
675 675
 
676 676
 
677
-	/**
678
-	 * replace the path of image src, link href and a href
679
-	 *
680
-	 * url => template_dir/url
681
-	 * url# => url
682
-	 * http://url => http://url
683
-	 *
684
-	 * @access protected
685
-	 * @param  string $html
686
-	 * @param  string $tpl_basedir
687
-	 * @return string html substitution
688
-	 */
689
-	protected function path_replace( $html, $tpl_basedir ){
677
+    /**
678
+     * replace the path of image src, link href and a href
679
+     *
680
+     * url => template_dir/url
681
+     * url# => url
682
+     * http://url => http://url
683
+     *
684
+     * @access protected
685
+     * @param  string $html
686
+     * @param  string $tpl_basedir
687
+     * @return string html substitution
688
+     */
689
+    protected function path_replace( $html, $tpl_basedir ){
690 690
 
691
-		if( self::$path_replace ){
691
+        if( self::$path_replace ){
692 692
 
693
-			$tpl_dir = self::$base_url . PATH . self::$tpl_dir . $tpl_basedir;
693
+            $tpl_dir = self::$base_url . PATH . self::$tpl_dir . $tpl_basedir;
694 694
 
695
-			// reduce the path
696
-			$path = $this->reduce_path($tpl_dir);
695
+            // reduce the path
696
+            $path = $this->reduce_path($tpl_dir);
697 697
 
698
-			$exp = $sub = array();
698
+            $exp = $sub = array();
699 699
 
700
-			if( in_array( "img", self::$path_replace_list ) ){
701
-				$exp = array( '/<img(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<img(.*?)src=(?:")([^"]+?)#(?:")/i', '/<img(.*?)src="(.*?)"/', '/<img(.*?)src=(?:\@)([^"]+?)(?:\@)/i' );
702
-				$sub = array( '<img$1src=@$2://$3@', '<img$1src=@$2@', '<img$1src="' . $path . '$2"', '<img$1src="$2"' );
703
-			}
700
+            if( in_array( "img", self::$path_replace_list ) ){
701
+                $exp = array( '/<img(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<img(.*?)src=(?:")([^"]+?)#(?:")/i', '/<img(.*?)src="(.*?)"/', '/<img(.*?)src=(?:\@)([^"]+?)(?:\@)/i' );
702
+                $sub = array( '<img$1src=@$2://$3@', '<img$1src=@$2@', '<img$1src="' . $path . '$2"', '<img$1src="$2"' );
703
+            }
704 704
 
705
-			if( in_array( "script", self::$path_replace_list ) ){
706
-				$exp = array_merge( $exp , array( '/<script(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<script(.*?)src=(?:")([^"]+?)#(?:")/i', '/<script(.*?)src="(.*?)"/', '/<script(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
707
-				$sub = array_merge( $sub , array( '<script$1src=@$2://$3@', '<script$1src=@$2@', '<script$1src="' . $path . '$2"', '<script$1src="$2"' ) );
708
-			}
705
+            if( in_array( "script", self::$path_replace_list ) ){
706
+                $exp = array_merge( $exp , array( '/<script(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<script(.*?)src=(?:")([^"]+?)#(?:")/i', '/<script(.*?)src="(.*?)"/', '/<script(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
707
+                $sub = array_merge( $sub , array( '<script$1src=@$2://$3@', '<script$1src=@$2@', '<script$1src="' . $path . '$2"', '<script$1src="$2"' ) );
708
+            }
709 709
 
710
-			if( in_array( "link", self::$path_replace_list ) ){
711
-				$exp = array_merge( $exp , array( '/<link(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ) );
712
-				$sub = array_merge( $sub , array( '<link$1href=@$2://$3@', '<link$1href=@$2@' , '<link$1href="' . $path . '$2"', '<link$1href="$2"' ) );
713
-			}
710
+            if( in_array( "link", self::$path_replace_list ) ){
711
+                $exp = array_merge( $exp , array( '/<link(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ) );
712
+                $sub = array_merge( $sub , array( '<link$1href=@$2://$3@', '<link$1href=@$2@' , '<link$1href="' . $path . '$2"', '<link$1href="$2"' ) );
713
+            }
714 714
 
715
-			if( in_array( "a", self::$path_replace_list ) ){
716
-				$exp = array_merge( $exp , array( '/<a(.*?)href=(?:")(http\:\/\/|https\:\/\/|javascript:)([^"]+?)(?:")/i', '/<a(.*?)href="(.*?)"/', '/<a(.*?)href=(?:\@)([^"]+?)(?:\@)/i'  ) );
717
-				$sub = array_merge( $sub , array( '<a$1href=@$2$3@', '<a$1href="' . self::$base_url . '$2"', '<a$1href="$2"' ) );
718
-			}
715
+            if( in_array( "a", self::$path_replace_list ) ){
716
+                $exp = array_merge( $exp , array( '/<a(.*?)href=(?:")(http\:\/\/|https\:\/\/|javascript:)([^"]+?)(?:")/i', '/<a(.*?)href="(.*?)"/', '/<a(.*?)href=(?:\@)([^"]+?)(?:\@)/i'  ) );
717
+                $sub = array_merge( $sub , array( '<a$1href=@$2$3@', '<a$1href="' . self::$base_url . '$2"', '<a$1href="$2"' ) );
718
+            }
719 719
 
720
-			if( in_array( "input", self::$path_replace_list ) ){
721
-				$exp = array_merge( $exp , array( '/<input(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<input(.*?)src=(?:")([^"]+?)#(?:")/i', '/<input(.*?)src="(.*?)"/', '/<input(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
722
-				$sub = array_merge( $sub , array( '<input$1src=@$2://$3@', '<input$1src=@$2@', '<input$1src="' . $path . '$2"', '<input$1src="$2"' ) );
723
-			}
720
+            if( in_array( "input", self::$path_replace_list ) ){
721
+                $exp = array_merge( $exp , array( '/<input(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<input(.*?)src=(?:")([^"]+?)#(?:")/i', '/<input(.*?)src="(.*?)"/', '/<input(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
722
+                $sub = array_merge( $sub , array( '<input$1src=@$2://$3@', '<input$1src=@$2@', '<input$1src="' . $path . '$2"', '<input$1src="$2"' ) );
723
+            }
724 724
 
725
-			return preg_replace( $exp, $sub, $html );
725
+            return preg_replace( $exp, $sub, $html );
726 726
 
727
-		}
728
-		else
729
-			return $html;
727
+        }
728
+        else
729
+            return $html;
730 730
 
731
-	}
731
+    }
732 732
 
733 733
 
734 734
 
735
-	/**
736
-	 * replace constants
737
-	 *
738
-	 * @access public
739
-	 * @param  string $html
740
-	 * @param  string $tag_left_delimiter
741
-	 * @param  string $tag_right_delimiter
742
-	 * @param  string $php_left_delimiter (optional)
743
-	 * @param  string $php_right_delimiter (optional)
744
-	 * @param  string $loop_level (optional)
745
-	 * @param  string $echo (optional)
746
-	 * @return string
747
-	 */
748
-	public function const_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
749
-		// const
750
-		return preg_replace( '/\{\#(\w+)\#{0,1}\}/', $php_left_delimiter . ( $echo ? " echo " : null ) . '\\1' . $php_right_delimiter, $html );
751
-	}
735
+    /**
736
+     * replace constants
737
+     *
738
+     * @access public
739
+     * @param  string $html
740
+     * @param  string $tag_left_delimiter
741
+     * @param  string $tag_right_delimiter
742
+     * @param  string $php_left_delimiter (optional)
743
+     * @param  string $php_right_delimiter (optional)
744
+     * @param  string $loop_level (optional)
745
+     * @param  string $echo (optional)
746
+     * @return string
747
+     */
748
+    public function const_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
749
+        // const
750
+        return preg_replace( '/\{\#(\w+)\#{0,1}\}/', $php_left_delimiter . ( $echo ? " echo " : null ) . '\\1' . $php_right_delimiter, $html );
751
+    }
752 752
 
753 753
 
754 754
 
755
-	/**
756
-	 * replace functions/modifiers on constants and strings
757
-	 *
758
-	 * @access public
759
-	 * @param  string $html
760
-	 * @param  string $tag_left_delimiter
761
-	 * @param  string $tag_right_delimiter
762
-	 * @param  string $php_left_delimiter (optional)
763
-	 * @param  string $php_right_delimiter (optional)
764
-	 * @param  string $loop_level (optional)
765
-	 * @param  string $echo (optional)
766
-	 * @return string
767
-	 */
768
-	public function func_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
755
+    /**
756
+     * replace functions/modifiers on constants and strings
757
+     *
758
+     * @access public
759
+     * @param  string $html
760
+     * @param  string $tag_left_delimiter
761
+     * @param  string $tag_right_delimiter
762
+     * @param  string $php_left_delimiter (optional)
763
+     * @param  string $php_right_delimiter (optional)
764
+     * @param  string $loop_level (optional)
765
+     * @param  string $echo (optional)
766
+     * @return string
767
+     */
768
+    public function func_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
769 769
 
770
-		preg_match_all( '/' . '\{\#{0,1}(\"{0,1}.*?\"{0,1})(\|\w.*?)\#{0,1}\}' . '/', $html, $matches );
770
+        preg_match_all( '/' . '\{\#{0,1}(\"{0,1}.*?\"{0,1})(\|\w.*?)\#{0,1}\}' . '/', $html, $matches );
771 771
 
772
-		for( $i=0, $n=count($matches[0]); $i<$n; $i++ ){
772
+        for( $i=0, $n=count($matches[0]); $i<$n; $i++ ){
773 773
 
774
-			//complete tag ex: {$news.title|substr:0,100}
775
-			$tag = $matches[ 0 ][ $i ];
774
+            //complete tag ex: {$news.title|substr:0,100}
775
+            $tag = $matches[ 0 ][ $i ];
776 776
 
777
-			//variable name ex: news.title
778
-			$var = $matches[ 1 ][ $i ];
777
+            //variable name ex: news.title
778
+            $var = $matches[ 1 ][ $i ];
779 779
 
780
-			//function and parameters associate to the variable ex: substr:0,100
781
-			$extra_var = $matches[ 2 ][ $i ];
780
+            //function and parameters associate to the variable ex: substr:0,100
781
+            $extra_var = $matches[ 2 ][ $i ];
782 782
 
783
-			// check if there's any function disabled by black_list
784
-			$this->function_check( $tag );
783
+            // check if there's any function disabled by black_list
784
+            $this->function_check( $tag );
785 785
 
786
-			$extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
786
+            $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
787 787
 
788 788
 
789
-			// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
790
-			$is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var );
789
+            // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
790
+            $is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var );
791 791
 
792
-			//function associate to variable
793
-			$function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
792
+            //function associate to variable
793
+            $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
794 794
 
795
-			//variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
796
-			$temp = preg_split( "/\.|\[|\-\>/", $var );
795
+            //variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
796
+            $temp = preg_split( "/\.|\[|\-\>/", $var );
797 797
 
798
-			//variable name
799
-			$var_name = $temp[ 0 ];
798
+            //variable name
799
+            $var_name = $temp[ 0 ];
800 800
 
801
-			//variable path
802
-			$variable_path = substr( $var, strlen( $var_name ) );
801
+            //variable path
802
+            $variable_path = substr( $var, strlen( $var_name ) );
803 803
 
804
-			//parentesis transform [ e ] in [" e in "]
805
-			$variable_path = str_replace( '[', '["', $variable_path );
806
-			$variable_path = str_replace( ']', '"]', $variable_path );
804
+            //parentesis transform [ e ] in [" e in "]
805
+            $variable_path = str_replace( '[', '["', $variable_path );
806
+            $variable_path = str_replace( ']', '"]', $variable_path );
807 807
 
808
-			//transform .$variable in ["$variable"]
809
-			$variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path );
808
+            //transform .$variable in ["$variable"]
809
+            $variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path );
810 810
 
811
-			//transform [variable] in ["variable"]
812
-			$variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path );
811
+            //transform [variable] in ["variable"]
812
+            $variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path );
813 813
 
814
-			//if there's a function
815
-			if( $function_var ){
814
+            //if there's a function
815
+            if( $function_var ){
816 816
 
817
-				// check if there's a function or a static method and separate, function by parameters
818
-				$function_var = str_replace("::", "@double_dot@", $function_var );
817
+                // check if there's a function or a static method and separate, function by parameters
818
+                $function_var = str_replace("::", "@double_dot@", $function_var );
819 819
 
820
-				// get the position of the first :
821
-				if( $dot_position = strpos( $function_var, ":" ) ){
820
+                // get the position of the first :
821
+                if( $dot_position = strpos( $function_var, ":" ) ){
822 822
 
823
-					// get the function and the parameters
824
-					$function = substr( $function_var, 0, $dot_position );
825
-					$params = substr( $function_var, $dot_position+1 );
823
+                    // get the function and the parameters
824
+                    $function = substr( $function_var, 0, $dot_position );
825
+                    $params = substr( $function_var, $dot_position+1 );
826 826
 
827
-				}
828
-				else{
827
+                }
828
+                else{
829 829
 
830
-					//get the function
831
-					$function = str_replace( "@double_dot@", "::", $function_var );
832
-					$params = null;
830
+                    //get the function
831
+                    $function = str_replace( "@double_dot@", "::", $function_var );
832
+                    $params = null;
833 833
 
834
-				}
834
+                }
835 835
 
836
-				// replace back the @double_dot@ with ::
837
-				$function = str_replace( "@double_dot@", "::", $function );
838
-				$params = str_replace( "@double_dot@", "::", $params );
836
+                // replace back the @double_dot@ with ::
837
+                $function = str_replace( "@double_dot@", "::", $function );
838
+                $params = str_replace( "@double_dot@", "::", $params );
839 839
 
840 840
 
841
-			}
842
-			else
843
-				$function = $params = null;
841
+            }
842
+            else
843
+                $function = $params = null;
844 844
 
845
-			$php_var = $var_name . $variable_path;
845
+            $php_var = $var_name . $variable_path;
846 846
 
847
-			// compile the variable for php
848
-			if( isset( $function ) ){
849
-				if( $php_var )
850
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
851
-				else
852
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter;
853
-			}
854
-			else
855
-				$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
847
+            // compile the variable for php
848
+            if( isset( $function ) ){
849
+                if( $php_var )
850
+                    $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
851
+                else
852
+                    $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter;
853
+            }
854
+            else
855
+                $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
856 856
 
857
-			$html = str_replace( $tag, $php_var, $html );
857
+            $html = str_replace( $tag, $php_var, $html );
858 858
 
859
-		}
859
+        }
860 860
 
861
-		return $html;
861
+        return $html;
862 862
 
863
-	}
863
+    }
864 864
 
865 865
 
866 866
 
867
-	/**
868
-	 * replace variables
869
-	 *
870
-	 * @access public
871
-	 * @param  string $html
872
-	 * @param  string $tag_left_delimiter
873
-	 * @param  string $tag_right_delimiter
874
-	 * @param  string $php_left_delimiter (optional)
875
-	 * @param  string $php_right_delimiter (optional)
876
-	 * @param  string $loop_level (optional)
877
-	 * @param  string $echo (optional)
878
-	 * @return string
879
-	 */
880
-	public function var_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
867
+    /**
868
+     * replace variables
869
+     *
870
+     * @access public
871
+     * @param  string $html
872
+     * @param  string $tag_left_delimiter
873
+     * @param  string $tag_right_delimiter
874
+     * @param  string $php_left_delimiter (optional)
875
+     * @param  string $php_right_delimiter (optional)
876
+     * @param  string $loop_level (optional)
877
+     * @param  string $echo (optional)
878
+     * @return string
879
+     */
880
+    public function var_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
881 881
 
882
-		//all variables
883
-		if( preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ) ){
882
+        //all variables
883
+        if( preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ) ){
884 884
 
885
-			for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ )
886
-				$parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]);
885
+            for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ )
886
+                $parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]);
887 887
 
888
-			foreach( $parsed as $tag => $array ){
888
+            foreach( $parsed as $tag => $array ){
889 889
 
890
-				//variable name ex: news.title
891
-				$var = $array['var'];
890
+                //variable name ex: news.title
891
+                $var = $array['var'];
892 892
 
893
-				//function and parameters associate to the variable ex: substr:0,100
894
-				$extra_var = $array['extra_var'];
893
+                //function and parameters associate to the variable ex: substr:0,100
894
+                $extra_var = $array['extra_var'];
895 895
 
896
-				// check if there's any function disabled by black_list
897
-				$this->function_check( $tag );
896
+                // check if there's any function disabled by black_list
897
+                $this->function_check( $tag );
898 898
 
899
-				$extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
899
+                $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
900 900
 
901
-				// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
902
-				$is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var );
901
+                // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
902
+                $is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var );
903 903
 
904
-				//function associate to variable
905
-				$function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
904
+                //function associate to variable
905
+                $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
906 906
 
907
-				//variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
908
-				$temp = preg_split( "/\.|\[|\-\>/", $var );
907
+                //variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
908
+                $temp = preg_split( "/\.|\[|\-\>/", $var );
909 909
 
910
-				//variable name
911
-				$var_name = $temp[ 0 ];
910
+                //variable name
911
+                $var_name = $temp[ 0 ];
912 912
 
913
-				//variable path
914
-				$variable_path = substr( $var, strlen( $var_name ) );
913
+                //variable path
914
+                $variable_path = substr( $var, strlen( $var_name ) );
915 915
 
916
-				//parentesis transform [ e ] in [" e in "]
917
-				$variable_path = str_replace( '[', '["', $variable_path );
918
-				$variable_path = str_replace( ']', '"]', $variable_path );
916
+                //parentesis transform [ e ] in [" e in "]
917
+                $variable_path = str_replace( '[', '["', $variable_path );
918
+                $variable_path = str_replace( ']', '"]', $variable_path );
919 919
 
920
-				//transform .$variable in ["$variable"] and .variable in ["variable"]
921
-				$variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path );
920
+                //transform .$variable in ["$variable"] and .variable in ["variable"]
921
+                $variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path );
922 922
 
923
-				// if is an assignment also assign the variable to $this->var['value']
924
-				if( $is_init_variable )
925
-					$extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
923
+                // if is an assignment also assign the variable to $this->var['value']
924
+                if( $is_init_variable )
925
+                    $extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
926 926
 
927 927
 
928 928
 
929
-				//if there's a function
930
-				if( $function_var ){
929
+                //if there's a function
930
+                if( $function_var ){
931 931
 
932
-					// check if there's a function or a static method and separate, function by parameters
933
-					$function_var = str_replace("::", "@double_dot@", $function_var );
932
+                    // check if there's a function or a static method and separate, function by parameters
933
+                    $function_var = str_replace("::", "@double_dot@", $function_var );
934 934
 
935 935
 
936
-					// get the position of the first :
937
-					if( $dot_position = strpos( $function_var, ":" ) ){
936
+                    // get the position of the first :
937
+                    if( $dot_position = strpos( $function_var, ":" ) ){
938 938
 
939
-						// get the function and the parameters
940
-						$function = substr( $function_var, 0, $dot_position );
941
-						$params = substr( $function_var, $dot_position+1 );
939
+                        // get the function and the parameters
940
+                        $function = substr( $function_var, 0, $dot_position );
941
+                        $params = substr( $function_var, $dot_position+1 );
942 942
 
943
-					}
944
-					else{
943
+                    }
944
+                    else{
945 945
 
946
-						//get the function
947
-						$function = str_replace( "@double_dot@", "::", $function_var );
948
-						$params = null;
946
+                        //get the function
947
+                        $function = str_replace( "@double_dot@", "::", $function_var );
948
+                        $params = null;
949 949
 
950
-					}
950
+                    }
951 951
 
952
-					// replace back the @double_dot@ with ::
953
-					$function = str_replace( "@double_dot@", "::", $function );
954
-					$params = str_replace( "@double_dot@", "::", $params );
955
-				}
956
-				else
957
-					$function = $params = null;
952
+                    // replace back the @double_dot@ with ::
953
+                    $function = str_replace( "@double_dot@", "::", $function );
954
+                    $params = str_replace( "@double_dot@", "::", $params );
955
+                }
956
+                else
957
+                    $function = $params = null;
958 958
 
959
-				//if it is inside a loop
960
-				if( $loop_level ){
961
-					//verify the variable name
962
-					if( $var_name == 'key' )
963
-							$php_var = '$key' . $loop_level;
964
-					elseif( $var_name == 'value' )
965
-							$php_var = '$value' . $loop_level . $variable_path;
966
-					elseif( $var_name == 'counter' )
967
-							$php_var = '$counter' . $loop_level;
968
-					else
969
-							$php_var = '$' . $var_name . $variable_path;
970
-				}else
971
-					$php_var = '$' . $var_name . $variable_path;
972
-
973
-				// compile the variable for php
974
-				if( isset( $function ) )
975
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
976
-				else
977
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
978
-
979
-				$html = str_replace( $tag, $php_var, $html );
980
-
981
-
982
-			}
983
-		}
984
-
985
-		return $html;
986
-	}
987
-
988
-
989
-
990
-	/**
991
-	 * Check if function is in black list (sandbox)
992
-	 *
993
-	 * @access protected
994
-	 * @param  string $code
995
-	 * @throws RainTpl_SyntaxException
996
-	 * @return void
997
-	 */
998
-	protected function function_check( $code ){
999
-
1000
-		$preg = '#(\W|\s)' . implode( '(\W|\s)|(\W|\s)', self::$black_list ) . '(\W|\s)#';
1001
-
1002
-		// check if the function is in the black list (or not in white list)
1003
-		if( count(self::$black_list) && preg_match( $preg, $code, $match ) ){
1004
-
1005
-			// find the line of the error
1006
-			$line = 0;
1007
-			$rows=explode("\n",$this->tpl['source']);
1008
-			while( !strpos($rows[$line],$code) )
1009
-				$line++;
1010
-
1011
-			// stop the execution of the script
1012
-			$e = new RainTpl_SyntaxException('Unallowed syntax in ' . $this->tpl['tpl_filename'] . ' template');
1013
-			throw $e->setTemplateFile($this->tpl['tpl_filename'])
1014
-				->setTag($code)
1015
-				->setTemplateLine($line);
1016
-		}
1017
-
1018
-	}
1019
-
1020
-
1021
-
1022
-	/**
1023
-	 * Prints debug info about exception or passes it further if debug is disabled.
1024
-	 *
1025
-	 * @access protected
1026
-	 * @param  RainTpl_Exception $e
1027
-	 * @return string
1028
-	 */
1029
-	protected function printDebug(RainTpl_Exception $e){
1030
-		if (!self::$debug) {
1031
-			throw $e;
1032
-		}
1033
-		$output = sprintf('<h2>Exception: %s</h2><h3>%s</h3><p>template: %s</p>',
1034
-			get_class($e),
1035
-			$e->getMessage(),
1036
-			$e->getTemplateFile()
1037
-		);
1038
-		if ($e instanceof RainTpl_SyntaxException) {
1039
-			if (null != $e->getTemplateLine()) {
1040
-				$output .= '<p>line: ' . $e->getTemplateLine() . '</p>';
1041
-			}
1042
-			if (null != $e->getTag()) {
1043
-				$output .= '<p>in tag: ' . htmlspecialchars($e->getTag()) . '</p>';
1044
-			}
1045
-			if (null != $e->getTemplateLine() && null != $e->getTag()) {
1046
-				$rows=explode("\n",  htmlspecialchars($this->tpl['source']));
1047
-				$rows[$e->getTemplateLine()] = '<font color=red>' . $rows[$e->getTemplateLine()] . '</font>';
1048
-				$output .= '<h3>template code</h3>' . implode('<br />', $rows) . '</pre>';
1049
-			}
1050
-		}
1051
-		$output .= sprintf('<h3>trace</h3><p>In %s on line %d</p><pre>%s</pre>',
1052
-			$e->getFile(), $e->getLine(),
1053
-			nl2br(htmlspecialchars($e->getTraceAsString()))
1054
-		);
1055
-		return $output;
1056
-	}
959
+                //if it is inside a loop
960
+                if( $loop_level ){
961
+                    //verify the variable name
962
+                    if( $var_name == 'key' )
963
+                            $php_var = '$key' . $loop_level;
964
+                    elseif( $var_name == 'value' )
965
+                            $php_var = '$value' . $loop_level . $variable_path;
966
+                    elseif( $var_name == 'counter' )
967
+                            $php_var = '$counter' . $loop_level;
968
+                    else
969
+                            $php_var = '$' . $var_name . $variable_path;
970
+                }else
971
+                    $php_var = '$' . $var_name . $variable_path;
972
+
973
+                // compile the variable for php
974
+                if( isset( $function ) )
975
+                    $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
976
+                else
977
+                    $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
978
+
979
+                $html = str_replace( $tag, $php_var, $html );
980
+
981
+
982
+            }
983
+        }
984
+
985
+        return $html;
986
+    }
987
+
988
+
989
+
990
+    /**
991
+     * Check if function is in black list (sandbox)
992
+     *
993
+     * @access protected
994
+     * @param  string $code
995
+     * @throws RainTpl_SyntaxException
996
+     * @return void
997
+     */
998
+    protected function function_check( $code ){
999
+
1000
+        $preg = '#(\W|\s)' . implode( '(\W|\s)|(\W|\s)', self::$black_list ) . '(\W|\s)#';
1001
+
1002
+        // check if the function is in the black list (or not in white list)
1003
+        if( count(self::$black_list) && preg_match( $preg, $code, $match ) ){
1004
+
1005
+            // find the line of the error
1006
+            $line = 0;
1007
+            $rows=explode("\n",$this->tpl['source']);
1008
+            while( !strpos($rows[$line],$code) )
1009
+                $line++;
1010
+
1011
+            // stop the execution of the script
1012
+            $e = new RainTpl_SyntaxException('Unallowed syntax in ' . $this->tpl['tpl_filename'] . ' template');
1013
+            throw $e->setTemplateFile($this->tpl['tpl_filename'])
1014
+                ->setTag($code)
1015
+                ->setTemplateLine($line);
1016
+        }
1017
+
1018
+    }
1019
+
1020
+
1021
+
1022
+    /**
1023
+     * Prints debug info about exception or passes it further if debug is disabled.
1024
+     *
1025
+     * @access protected
1026
+     * @param  RainTpl_Exception $e
1027
+     * @return string
1028
+     */
1029
+    protected function printDebug(RainTpl_Exception $e){
1030
+        if (!self::$debug) {
1031
+            throw $e;
1032
+        }
1033
+        $output = sprintf('<h2>Exception: %s</h2><h3>%s</h3><p>template: %s</p>',
1034
+            get_class($e),
1035
+            $e->getMessage(),
1036
+            $e->getTemplateFile()
1037
+        );
1038
+        if ($e instanceof RainTpl_SyntaxException) {
1039
+            if (null != $e->getTemplateLine()) {
1040
+                $output .= '<p>line: ' . $e->getTemplateLine() . '</p>';
1041
+            }
1042
+            if (null != $e->getTag()) {
1043
+                $output .= '<p>in tag: ' . htmlspecialchars($e->getTag()) . '</p>';
1044
+            }
1045
+            if (null != $e->getTemplateLine() && null != $e->getTag()) {
1046
+                $rows=explode("\n",  htmlspecialchars($this->tpl['source']));
1047
+                $rows[$e->getTemplateLine()] = '<font color=red>' . $rows[$e->getTemplateLine()] . '</font>';
1048
+                $output .= '<h3>template code</h3>' . implode('<br />', $rows) . '</pre>';
1049
+            }
1050
+        }
1051
+        $output .= sprintf('<h3>trace</h3><p>In %s on line %d</p><pre>%s</pre>',
1052
+            $e->getFile(), $e->getLine(),
1053
+            nl2br(htmlspecialchars($e->getTraceAsString()))
1054
+        );
1055
+        return $output;
1056
+    }
1057 1057
 }
1058 1058
 
1059 1059
 
@@ -1062,32 +1062,32 @@  discard block
 block discarded – undo
1062 1062
  * Basic Rain tpl exception.
1063 1063
  */
1064 1064
 class RainTpl_Exception extends Exception{
1065
-	/**
1066
-	 * Path of template file with error.
1067
-	 */
1068
-	protected $templateFile = '';
1069
-
1070
-	/**
1071
-	 * Returns path of template file with error.
1072
-	 *
1073
-	 * @return string
1074
-	 */
1075
-	public function getTemplateFile()
1076
-	{
1077
-		return $this->templateFile;
1078
-	}
1079
-
1080
-	/**
1081
-	 * Sets path of template file with error.
1082
-	 *
1083
-	 * @param string $templateFile
1084
-	 * @return RainTpl_Exception
1085
-	 */
1086
-	public function setTemplateFile($templateFile)
1087
-	{
1088
-		$this->templateFile = (string) $templateFile;
1089
-		return $this;
1090
-	}
1065
+    /**
1066
+     * Path of template file with error.
1067
+     */
1068
+    protected $templateFile = '';
1069
+
1070
+    /**
1071
+     * Returns path of template file with error.
1072
+     *
1073
+     * @return string
1074
+     */
1075
+    public function getTemplateFile()
1076
+    {
1077
+        return $this->templateFile;
1078
+    }
1079
+
1080
+    /**
1081
+     * Sets path of template file with error.
1082
+     *
1083
+     * @param string $templateFile
1084
+     * @return RainTpl_Exception
1085
+     */
1086
+    public function setTemplateFile($templateFile)
1087
+    {
1088
+        $this->templateFile = (string) $templateFile;
1089
+        return $this;
1090
+    }
1091 1091
 }
1092 1092
 
1093 1093
 
@@ -1102,64 +1102,64 @@  discard block
 block discarded – undo
1102 1102
  * Exception thrown when syntax error occurs.
1103 1103
  */
1104 1104
 class RainTpl_SyntaxException extends RainTpl_Exception{
1105
-	/**
1106
-	 * Line in template file where error has occured.
1107
-	 *
1108
-	 * @var int | null
1109
-	 */
1110
-	protected $templateLine = null;
1111
-
1112
-	/**
1113
-	 * Tag which caused an error.
1114
-	 *
1115
-	 * @var string | null
1116
-	 */
1117
-	protected $tag = null;
1118
-
1119
-	/**
1120
-	 * Returns line in template file where error has occured
1121
-	 * or null if line is not defined.
1122
-	 *
1123
-	 * @return int | null
1124
-	 */
1125
-	public function getTemplateLine()
1126
-	{
1127
-		return $this->templateLine;
1128
-	}
1129
-
1130
-	/**
1131
-	 * Sets  line in template file where error has occured.
1132
-	 *
1133
-	 * @param int $templateLine
1134
-	 * @return RainTpl_SyntaxException
1135
-	 */
1136
-	public function setTemplateLine($templateLine)
1137
-	{
1138
-		$this->templateLine = (int) $templateLine;
1139
-		return $this;
1140
-	}
1141
-
1142
-	/**
1143
-	 * Returns tag which caused an error.
1144
-	 *
1145
-	 * @return string
1146
-	 */
1147
-	public function getTag()
1148
-	{
1149
-		return $this->tag;
1150
-	}
1151
-
1152
-	/**
1153
-	 * Sets tag which caused an error.
1154
-	 *
1155
-	 * @param string $tag
1156
-	 * @return RainTpl_SyntaxException
1157
-	 */
1158
-	public function setTag($tag)
1159
-	{
1160
-		$this->tag = (string) $tag;
1161
-		return $this;
1162
-	}
1105
+    /**
1106
+     * Line in template file where error has occured.
1107
+     *
1108
+     * @var int | null
1109
+     */
1110
+    protected $templateLine = null;
1111
+
1112
+    /**
1113
+     * Tag which caused an error.
1114
+     *
1115
+     * @var string | null
1116
+     */
1117
+    protected $tag = null;
1118
+
1119
+    /**
1120
+     * Returns line in template file where error has occured
1121
+     * or null if line is not defined.
1122
+     *
1123
+     * @return int | null
1124
+     */
1125
+    public function getTemplateLine()
1126
+    {
1127
+        return $this->templateLine;
1128
+    }
1129
+
1130
+    /**
1131
+     * Sets  line in template file where error has occured.
1132
+     *
1133
+     * @param int $templateLine
1134
+     * @return RainTpl_SyntaxException
1135
+     */
1136
+    public function setTemplateLine($templateLine)
1137
+    {
1138
+        $this->templateLine = (int) $templateLine;
1139
+        return $this;
1140
+    }
1141
+
1142
+    /**
1143
+     * Returns tag which caused an error.
1144
+     *
1145
+     * @return string
1146
+     */
1147
+    public function getTag()
1148
+    {
1149
+        return $this->tag;
1150
+    }
1151
+
1152
+    /**
1153
+     * Sets tag which caused an error.
1154
+     *
1155
+     * @param string $tag
1156
+     * @return RainTpl_SyntaxException
1157
+     */
1158
+    public function setTag($tag)
1159
+    {
1160
+        $this->tag = (string) $tag;
1161
+        return $this;
1162
+    }
1163 1163
 }
1164 1164
 
1165 1165
 /**
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
  * @return string
1174 1174
  */
1175 1175
 function t() {
1176
-	return call_user_func_array(array('i18n', 'translate'), func_get_args());
1176
+    return call_user_func_array(array('i18n', 'translate'), func_get_args());
1177 1177
 }
1178 1178
 
1179 1179
 // -- end
Please login to merge, or discard this patch.
Spacing   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * RainTPL
14 14
  */
15
-class RainTPL{
15
+class RainTPL {
16 16
 
17 17
 	// -------------------------
18 18
 	// 	CONFIGURATION
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		 *
72 72
 		 * @var array
73 73
 		 */
74
-		static $path_replace_list = array( 'a', 'img', 'link', 'script', 'input' );
74
+		static $path_replace_list = array('a', 'img', 'link', 'script', 'input');
75 75
 
76 76
 
77 77
 		/**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		 *
80 80
 		 * @var array
81 81
 		 */
82
-		static $black_list = array( '\$this', 'raintpl::', 'self::', '_SESSION', '_SERVER', '_ENV',  'eval', 'exec', 'unlink', 'rmdir' );
82
+		static $black_list = array('\$this', 'raintpl::', 'self::', '_SESSION', '_SERVER', '_ENV', 'eval', 'exec', 'unlink', 'rmdir');
83 83
 
84 84
 
85 85
 		/**
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		 *
134 134
 		 * @var array
135 135
 		 */
136
-		protected $tpl = array();		//
136
+		protected $tpl = array(); //
137 137
 
138 138
 		/**
139 139
 		 * static cache enabled / disabled
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 * @param  mixed $variable_name Name of template variable or associative array name/value
178 178
 	 * @param  mixed $value value assigned to this variable. Not set if variable_name is an associative array
179 179
 	 */
180
-	public function assign( $variable, $value = null ){
181
-		if( is_array( $variable ) )
180
+	public function assign($variable, $value = null) {
181
+		if (is_array($variable))
182 182
 			$this->var += $variable;
183 183
 		else
184
-			$this->var[ $variable ] = $value;
184
+			$this->var[$variable] = $value;
185 185
 	}
186 186
 
187 187
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	 * @param  boolean $return_string  true=return a string, false=echo the template
197 197
 	 * @return string
198 198
 	 */
199
-	public function draw( $tpl_name, $return_string = false ){
199
+	public function draw($tpl_name, $return_string = false) {
200 200
 
201 201
 		try {
202 202
 			// compile the template if necessary and set the template filepath
203
-			$this->check_template( $tpl_name );
203
+			$this->check_template($tpl_name);
204 204
 		} catch (RainTpl_Exception $e) {
205 205
 			$output = $this->printDebug($e);
206 206
 			die($output);
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
 		// Cache is off and, return_string is false
210 210
 		// Rain just echo the template
211 211
 
212
-		if( !$this->cache && !$return_string ){
213
-			extract( $this->var );
212
+		if (!$this->cache && !$return_string) {
213
+			extract($this->var);
214 214
 			include $this->tpl['compiled_filename'];
215
-			unset( $this->tpl );
215
+			unset($this->tpl);
216 216
 		}
217 217
 
218 218
 
219 219
 		// cache or return_string are enabled
220 220
 		// rain get the output buffer to save the output in the cache or to return it as string
221 221
 
222
-		else{
222
+		else {
223 223
 
224 224
 			//----------------------
225 225
 			// get the output buffer
226 226
 			//----------------------
227 227
 				ob_start();
228
-				extract( $this->var );
228
+				extract($this->var);
229 229
 				include $this->tpl['compiled_filename'];
230 230
 				$raintpl_contents = ob_get_clean();
231 231
 			//----------------------
232 232
 
233 233
 
234 234
 			// save the output in the cache
235
-			if( $this->cache )
236
-				file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents );
235
+			if ($this->cache)
236
+				file_put_contents($this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents);
237 237
 
238 238
 			// free memory
239
-			unset( $this->tpl );
239
+			unset($this->tpl);
240 240
 
241 241
 			// return or print the template
242
-			if( $return_string ) return $raintpl_contents; else echo $raintpl_contents;
242
+			if ($return_string) return $raintpl_contents; else echo $raintpl_contents;
243 243
 
244 244
 		}
245 245
 
@@ -256,17 +256,17 @@  discard block
 block discarded – undo
256 256
 	 * @param  string $cache_id Suffix to be used when writing file to cache (optional)
257 257
 	 * @return string it return the HTML or null if the cache must be recreated
258 258
 	 */
259
-	public function cache( $tpl_name, $expire_time = self::CACHE_EXPIRE_TIME, $cache_id = '' ){
259
+	public function cache($tpl_name, $expire_time = self::CACHE_EXPIRE_TIME, $cache_id = '') {
260 260
 
261 261
 		// set the cache_id
262 262
 		$this->cache_id = $cache_id;
263 263
 
264
-		if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) )
265
-			return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 );
266
-		else{
264
+		if (!$this->check_template($tpl_name) && file_exists($this->tpl['cache_filename']) && (time()-filemtime($this->tpl['cache_filename']) < $expire_time))
265
+			return substr(file_get_contents($this->tpl['cache_filename']), 43);
266
+		else {
267 267
 			//delete the cache of the selected template
268 268
 			if (file_exists($this->tpl['cache_filename']))
269
-			unlink($this->tpl['cache_filename'] );
269
+			unlink($this->tpl['cache_filename']);
270 270
 			$this->cache = true;
271 271
 		}
272 272
 	}
@@ -281,13 +281,13 @@  discard block
 block discarded – undo
281 281
 	 * @param  array|string $setting array of settings or setting name
282 282
 	 * @param  mixed $value content to set in the setting (optional)
283 283
 	 */
284
-	public static function configure( $setting, $value = null ){
285
-		if( is_array( $setting ) )
286
-			foreach( $setting as $key => $value )
287
-				self::configure( $key, $value );
288
-		else if( property_exists( __CLASS__, $setting ) ){
284
+	public static function configure($setting, $value = null) {
285
+		if (is_array($setting))
286
+			foreach ($setting as $key => $value)
287
+				self::configure($key, $value);
288
+		else if (property_exists(__CLASS__, $setting)) {
289 289
 			self::$$setting = $value;
290
-			self::$config_name_sum[ $setting ] = $value; // take trace of all config
290
+			self::$config_name_sum[$setting] = $value; // take trace of all config
291 291
 		}
292 292
 	}
293 293
 
@@ -301,27 +301,27 @@  discard block
 block discarded – undo
301 301
 	 * @throws RainTpl_NotFoundException
302 302
 	 * @return bool return true if the template has changed
303 303
 	 */
304
-	protected function check_template( $tpl_name ){
304
+	protected function check_template($tpl_name) {
305 305
 
306
-		if( !isset($this->tpl['checked']) ){
306
+		if (!isset($this->tpl['checked'])) {
307 307
 
308
-			$tpl_basename					   = basename( $tpl_name );														// template basename
309
-			$tpl_basedir						= strpos($tpl_name,"/") ? dirname($tpl_name) . '/' : null;						// template basedirectory
310
-			$tpl_dir							= PATH . self::$tpl_dir . $tpl_basedir;								// template directory
311
-			$this->tpl['tpl_filename']		  = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext;	// template filename
312
-			$temp_compiled_filename			 = PATH . self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . serialize(self::$config_name_sum));
313
-			$this->tpl['compiled_filename']	 = $temp_compiled_filename . '.rtpl.php';	// cache filename
314
-			$this->tpl['cache_filename']		= $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php';	// static cache filename
308
+			$tpl_basename = basename($tpl_name); // template basename
309
+			$tpl_basedir = strpos($tpl_name, "/") ? dirname($tpl_name) . '/' : null; // template basedirectory
310
+			$tpl_dir = PATH . self::$tpl_dir . $tpl_basedir; // template directory
311
+			$this->tpl['tpl_filename']		  = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext; // template filename
312
+			$temp_compiled_filename = PATH . self::$cache_dir . $tpl_basename . "." . md5($tpl_dir . serialize(self::$config_name_sum));
313
+			$this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php'; // cache filename
314
+			$this->tpl['cache_filename']		= $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php'; // static cache filename
315 315
 
316 316
 			// if the template doesn't exsist throw an error
317
-			if( self::$check_template_update && !file_exists( $this->tpl['tpl_filename'] ) ){
318
-				$e = new RainTpl_NotFoundException( 'Template '. $tpl_basename .' not found!' );
317
+			if (self::$check_template_update && !file_exists($this->tpl['tpl_filename'])) {
318
+				$e = new RainTpl_NotFoundException('Template ' . $tpl_basename . ' not found!');
319 319
 				throw $e->setTemplateFile($this->tpl['tpl_filename']);
320 320
 			}
321 321
 
322 322
 			// file doesn't exsist, or the template was updated, Rain will compile the template
323
-			if( !file_exists( $this->tpl['compiled_filename'] ) || ( self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime( $this->tpl['tpl_filename'] ) ) ){
324
-				$this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename'] );
323
+			if (!file_exists($this->tpl['compiled_filename']) || (self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime($this->tpl['tpl_filename']))) {
324
+				$this->compileFile($tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename']);
325 325
 				return true;
326 326
 			}
327 327
 			$this->tpl['checked'] = true;
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	 * @return string
339 339
 	 */
340 340
 	protected function xml_reSubstitution($capture) {
341
-			return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>";
341
+			return "<?php echo '<?xml " . stripslashes($capture[1]) . " ?>'; ?>";
342 342
 	}
343 343
 
344 344
 
@@ -355,37 +355,37 @@  discard block
 block discarded – undo
355 355
 	 * @throws RainTpl_Exception
356 356
 	 * @return void
357 357
 	 */
358
-	protected function compileFile( $tpl_basename, $tpl_basedir, $tpl_filename, $cache_dir, $compiled_filename ){
358
+	protected function compileFile($tpl_basename, $tpl_basedir, $tpl_filename, $cache_dir, $compiled_filename) {
359 359
 
360 360
 		//read template file
361
-		$this->tpl['source'] = $template_code = file_get_contents( $tpl_filename );
361
+		$this->tpl['source'] = $template_code = file_get_contents($tpl_filename);
362 362
 
363 363
 		//xml substitution
364
-		$template_code = preg_replace( "/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code );
364
+		$template_code = preg_replace("/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code);
365 365
 
366 366
 		//disable php tag
367
-		if( !self::$php_enabled )
368
-			$template_code = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $template_code );
367
+		if (!self::$php_enabled)
368
+			$template_code = str_replace(array("<?", "?>"), array("&lt;?", "?&gt;"), $template_code);
369 369
 
370 370
 		//xml re-substitution
371
-		$template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
371
+		$template_code = preg_replace_callback("/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code);
372 372
 
373 373
 		//compile template
374
-		$template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir );
374
+		$template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate($template_code, $tpl_basedir);
375 375
 
376 376
 
377 377
 		// fix the php-eating-newline-after-closing-tag-problem
378
-		$template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled );
378
+		$template_compiled = str_replace("?>\n", "?>\n\n", $template_compiled);
379 379
 
380 380
 		// create directories
381
-		if( !is_dir( $cache_dir ) )
382
-			mkdir( $cache_dir, 0755, true );
381
+		if (!is_dir($cache_dir))
382
+			mkdir($cache_dir, 0755, true);
383 383
 
384
-		if( !is_writable( $cache_dir ) )
385
-			throw new RainTpl_Exception ('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
384
+		if (!is_writable($cache_dir))
385
+			throw new RainTpl_Exception('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
386 386
 
387 387
 		//write compiled file
388
-		file_put_contents( $compiled_filename, $template_compiled );
388
+		file_put_contents($compiled_filename, $template_compiled);
389 389
 	}
390 390
 
391 391
 
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $tpl_basedir
399 399
 	 * @return string
400 400
 	 */
401
-	protected function compileTemplate( $template_code, $tpl_basedir ){
401
+	protected function compileTemplate($template_code, $tpl_basedir) {
402 402
 
403 403
 		//tag list
404
-		$tag_regexp = array( 'loop'		 => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})',
404
+		$tag_regexp = array('loop'		 => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})',
405 405
 							 'loop_close'   => '(\{\/loop\})',
406 406
 							 'if'		   => '(\{if(?: condition){0,1}="[^"]*"\})',
407 407
 							 'elseif'	   => '(\{elseif(?: condition){0,1}="[^"]*"\})',
@@ -417,16 +417,16 @@  discard block
 block discarded – undo
417 417
 							 'function'		=> '(\{function="(\w*?)(?:.*?)"\})'
418 418
 							);
419 419
 
420
-		$tag_regexp = "/" . join( "|", $tag_regexp ) . "/";
420
+		$tag_regexp = "/" . join("|", $tag_regexp) . "/";
421 421
 
422 422
 		//split the code with the tags regexp
423
-		$template_code = preg_split ( $tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
423
+		$template_code = preg_split($tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
424 424
 
425 425
 		//path replace (src of img, background and href of link)
426
-		$template_code = $this->path_replace( $template_code, $tpl_basedir );
426
+		$template_code = $this->path_replace($template_code, $tpl_basedir);
427 427
 
428 428
 		//compile the code
429
-		$compiled_code = $this->compileCode( $template_code );
429
+		$compiled_code = $this->compileCode($template_code);
430 430
 
431 431
 		//return the compiled code
432 432
 		return $compiled_code;
@@ -443,68 +443,68 @@  discard block
 block discarded – undo
443 443
 	 * @throws RainTpl_SyntaxException
444 444
 	 * @return string
445 445
 	 */
446
-	protected function compileCode( $parsed_code ){
446
+	protected function compileCode($parsed_code) {
447 447
 
448 448
 		//variables initialization
449 449
 		$compiled_code = $open_if = $comment_is_open = $ignore_is_open = null;
450 450
 		$loop_level = 0;
451 451
 
452 452
 		//read all parsed code
453
-		while( $html = array_shift( $parsed_code ) ){
453
+		while ($html = array_shift($parsed_code)) {
454 454
 
455 455
 			//close ignore tag
456
-			if( !$comment_is_open && ( strpos( $html, '{/ignore}' ) !== FALSE || strpos( $html, '*}' ) !== FALSE ) )
456
+			if (!$comment_is_open && (strpos($html, '{/ignore}') !== FALSE || strpos($html, '*}') !== FALSE))
457 457
 				$ignore_is_open = false;
458 458
 
459 459
 			//code between tag ignore id deleted
460
-			elseif( $ignore_is_open ){
460
+			elseif ($ignore_is_open) {
461 461
 				//ignore the code
462 462
 			}
463 463
 
464 464
 			//close no parse tag
465
-			elseif( strpos( $html, '{/noparse}' ) !== FALSE )
465
+			elseif (strpos($html, '{/noparse}') !== FALSE)
466 466
 				$comment_is_open = false;
467 467
 
468 468
 			//code between tag noparse is not compiled
469
-			elseif( $comment_is_open )
469
+			elseif ($comment_is_open)
470 470
 				$compiled_code .= $html;
471 471
 
472 472
 			//ignore
473
-			elseif( strpos( $html, '{ignore}' ) !== FALSE || strpos( $html, '{*' ) !== FALSE )
473
+			elseif (strpos($html, '{ignore}') !== FALSE || strpos($html, '{*') !== FALSE)
474 474
 				$ignore_is_open = true;
475 475
 
476 476
 			//noparse
477
-			elseif( strpos( $html, '{noparse}' ) !== FALSE )
477
+			elseif (strpos($html, '{noparse}') !== FALSE)
478 478
 				$comment_is_open = true;
479 479
 
480 480
 			//include tag
481
-			elseif( preg_match( '/\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\}/', $html, $code ) ){
481
+			elseif (preg_match('/\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\}/', $html, $code)) {
482 482
 
483 483
 				//variables substitution
484
-				$include_var = $this->var_replace( $code[ 1 ], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".' , $php_right_delimiter = '."', $loop_level );
484
+				$include_var = $this->var_replace($code[1], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".', $php_right_delimiter = '."', $loop_level);
485 485
 
486 486
 				// if the cache is active
487
-				if( isset($code[ 2 ]) ){
487
+				if (isset($code[2])) {
488 488
 
489 489
 					//dynamic include
490
-					$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
491
-								 'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' .
490
+					$compiled_code .= '<?php $tpl = new ' . get_class($this) . ';' .
491
+								 'if( $cache = $tpl->cache( $template = basename("' . $include_var . '") ) )' .
492 492
 								 '	echo $cache;' .
493 493
 								 'else{' .
494 494
 								 '	$tpl_dir_temp = self::$tpl_dir;' .
495 495
 								 '	$tpl->assign( $this->var );' .
496
-									( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
497
-								 '	$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
496
+									(!$loop_level ? null : '$tpl->assign( "key", $key' . $loop_level . ' ); $tpl->assign( "value", $value' . $loop_level . ' );') .
497
+								 '	$tpl->draw( dirname("' . $include_var . '") . ( substr("' . $include_var . '",-1,1) != "/" ? "/" : "" ) . basename("' . $include_var . '") );' .
498 498
 								 '} ?>';
499 499
 				}
500
-				else{
500
+				else {
501 501
 
502 502
 					//dynamic include
503
-					$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
503
+					$compiled_code .= '<?php $tpl = new ' . get_class($this) . ';' .
504 504
 									  '$tpl_dir_temp = self::$tpl_dir;' .
505 505
 									  '$tpl->assign( $this->var );' .
506
-									  ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
507
-									  '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
506
+									  (!$loop_level ? null : '$tpl->assign( "key", $key' . $loop_level . ' ); $tpl->assign( "value", $value' . $loop_level . ' );') .
507
+									  '$tpl->draw( dirname("' . $include_var . '") . ( substr("' . $include_var . '",-1,1) != "/" ? "/" : "" ) . basename("' . $include_var . '") );' .
508 508
 									  '?>';
509 509
 
510 510
 
@@ -513,26 +513,26 @@  discard block
 block discarded – undo
513 513
 			}
514 514
 
515 515
 			//loop
516
-			elseif( preg_match( '/\{loop(?: name){0,1}="\${0,1}([^"]*)"\}/', $html, $code ) ){
516
+			elseif (preg_match('/\{loop(?: name){0,1}="\${0,1}([^"]*)"\}/', $html, $code)) {
517 517
 
518 518
 				//increase the loop counter
519 519
 				$loop_level++;
520 520
 
521 521
 				//replace the variable in the loop
522
-				$var = $this->var_replace( '$' . $code[ 1 ], $tag_left_delimiter=null, $tag_right_delimiter=null, $php_left_delimiter=null, $php_right_delimiter=null, $loop_level-1 );
522
+				$var = $this->var_replace('$' . $code[1], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level-1);
523 523
 
524 524
 				//loop variables
525
-				$counter = "\$counter$loop_level";	   // count iteration
526
-				$key = "\$key$loop_level";			   // key
527
-				$value = "\$value$loop_level";		   // value
525
+				$counter = "\$counter$loop_level"; // count iteration
526
+				$key = "\$key$loop_level"; // key
527
+				$value = "\$value$loop_level"; // value
528 528
 
529 529
 				//loop code
530
-				$compiled_code .=  "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>";
530
+				$compiled_code .= "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>";
531 531
 
532 532
 			}
533 533
 
534 534
 			//close loop tag
535
-			elseif( strpos( $html, '{/loop}' ) !== FALSE ) {
535
+			elseif (strpos($html, '{/loop}') !== FALSE) {
536 536
 
537 537
 				//iterator
538 538
 				$counter = "\$counter$loop_level";
@@ -541,114 +541,114 @@  discard block
 block discarded – undo
541 541
 				$loop_level--;
542 542
 
543 543
 				//close loop code
544
-				$compiled_code .=  "<?php } ?>";
544
+				$compiled_code .= "<?php } ?>";
545 545
 
546 546
 			}
547 547
 
548 548
 			//if
549
-			elseif( preg_match( '/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
549
+			elseif (preg_match('/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code)) {
550 550
 
551 551
 				//increase open if counter (for intendation)
552 552
 				$open_if++;
553 553
 
554 554
 				//tag
555
-				$tag = $code[ 0 ];
555
+				$tag = $code[0];
556 556
 
557 557
 				//condition attribute
558
-				$condition = $code[ 1 ];
558
+				$condition = $code[1];
559 559
 
560 560
 				// check if there's any function disabled by black_list
561
-				$this->function_check( $tag );
561
+				$this->function_check($tag);
562 562
 
563 563
 				//variable substitution into condition (no delimiter into the condition)
564
-				$parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
564
+				$parsed_condition = $this->var_replace($condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level);
565 565
 
566 566
 				//if code
567
-				$compiled_code .=   "<?php if( $parsed_condition ){ ?>";
567
+				$compiled_code .= "<?php if( $parsed_condition ){ ?>";
568 568
 
569 569
 			}
570 570
 
571 571
 			//elseif
572
-			elseif( preg_match( '/\{elseif(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){
572
+			elseif (preg_match('/\{elseif(?: condition){0,1}="([^"]*)"\}/', $html, $code)) {
573 573
 
574 574
 				//tag
575
-				$tag = $code[ 0 ];
575
+				$tag = $code[0];
576 576
 
577 577
 				//condition attribute
578
-				$condition = $code[ 1 ];
578
+				$condition = $code[1];
579 579
 
580 580
 				//variable substitution into condition (no delimiter into the condition)
581
-				$parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
581
+				$parsed_condition = $this->var_replace($condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level);
582 582
 
583 583
 				//elseif code
584
-				$compiled_code .=   "<?php }elseif( $parsed_condition ){ ?>";
584
+				$compiled_code .= "<?php }elseif( $parsed_condition ){ ?>";
585 585
 			}
586 586
 
587 587
 			//else
588
-			elseif( strpos( $html, '{else}' ) !== FALSE ) {
588
+			elseif (strpos($html, '{else}') !== FALSE) {
589 589
 
590 590
 				//else code
591
-				$compiled_code .=   '<?php }else{ ?>';
591
+				$compiled_code .= '<?php }else{ ?>';
592 592
 
593 593
 			}
594 594
 
595 595
 			//close if tag
596
-			elseif( strpos( $html, '{/if}' ) !== FALSE ) {
596
+			elseif (strpos($html, '{/if}') !== FALSE) {
597 597
 
598 598
 				//decrease if counter
599 599
 				$open_if--;
600 600
 
601 601
 				// close if code
602
-				$compiled_code .=   '<?php } ?>';
602
+				$compiled_code .= '<?php } ?>';
603 603
 
604 604
 			}
605 605
 
606 606
 			//function
607
-			elseif( preg_match( '/\{function="(\w*)(.*?)"\}/', $html, $code ) ){
607
+			elseif (preg_match('/\{function="(\w*)(.*?)"\}/', $html, $code)) {
608 608
 
609 609
 				//tag
610
-				$tag = $code[ 0 ];
610
+				$tag = $code[0];
611 611
 
612 612
 				//function
613
-				$function = $code[ 1 ];
613
+				$function = $code[1];
614 614
 
615 615
 				// check if there's any function disabled by black_list
616
-				$this->function_check( $tag );
616
+				$this->function_check($tag);
617 617
 
618
-				if( empty( $code[ 2 ] ) )
618
+				if (empty($code[2]))
619 619
 					$parsed_function = $function . "()";
620 620
 				else
621 621
 					// parse the function
622
-					$parsed_function = $function . $this->var_replace( $code[ 2 ], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
622
+					$parsed_function = $function . $this->var_replace($code[2], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level);
623 623
 
624 624
 				//if code
625
-				$compiled_code .=   "<?php echo $parsed_function; ?>";
625
+				$compiled_code .= "<?php echo $parsed_function; ?>";
626 626
 			}
627 627
 
628 628
 			// show all vars
629
-			elseif ( strpos( $html, '{$template_info}' ) !== FALSE ) {
629
+			elseif (strpos($html, '{$template_info}') !== FALSE) {
630 630
 
631 631
 				//tag
632
-				$tag  = '{$template_info}';
632
+				$tag = '{$template_info}';
633 633
 
634 634
 				//if code
635
-				$compiled_code .=   '<?php echo "<pre>"; print_r( $this->var ); echo "</pre>"; ?>';
635
+				$compiled_code .= '<?php echo "<pre>"; print_r( $this->var ); echo "</pre>"; ?>';
636 636
 			}
637 637
 
638 638
 
639 639
 			//all html code
640
-			else{
640
+			else {
641 641
 
642 642
 				//variables substitution (es. {$title})
643
-				$html = $this->var_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
643
+				$html = $this->var_replace($html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true);
644 644
 				//const substitution (es. {#CONST#})
645
-				$html = $this->const_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
645
+				$html = $this->const_replace($html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true);
646 646
 				//functions substitution (es. {"string"|functions})
647
-				$compiled_code .= $this->func_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true );
647
+				$compiled_code .= $this->func_replace($html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true);
648 648
 			}
649 649
 		}
650 650
 
651
-		if( $open_if > 0 ) {
651
+		if ($open_if > 0) {
652 652
 			$e = new RainTpl_SyntaxException('Error! You need to close an {if} tag in ' . $this->tpl['tpl_filename'] . ' template');
653 653
 			throw $e->setTemplateFile($this->tpl['tpl_filename']);
654 654
 		}
@@ -665,11 +665,11 @@  discard block
 block discarded – undo
665 665
 	 * @param string $path
666 666
 	 * @return string
667 667
 	 */
668
-	protected function reduce_path( $path ){
669
-		$path = str_replace( "://", "@not_replace@", $path );
670
-		$path = str_replace( "//", "/", $path );
671
-		$path = str_replace( "@not_replace@", "://", $path );
672
-		return preg_replace('/\w+\/\.\.\//', '', $path );
668
+	protected function reduce_path($path) {
669
+		$path = str_replace("://", "@not_replace@", $path);
670
+		$path = str_replace("//", "/", $path);
671
+		$path = str_replace("@not_replace@", "://", $path);
672
+		return preg_replace('/\w+\/\.\.\//', '', $path);
673 673
 	}
674 674
 
675 675
 
@@ -686,9 +686,9 @@  discard block
 block discarded – undo
686 686
 	 * @param  string $tpl_basedir
687 687
 	 * @return string html substitution
688 688
 	 */
689
-	protected function path_replace( $html, $tpl_basedir ){
689
+	protected function path_replace($html, $tpl_basedir) {
690 690
 
691
-		if( self::$path_replace ){
691
+		if (self::$path_replace) {
692 692
 
693 693
 			$tpl_dir = self::$base_url . PATH . self::$tpl_dir . $tpl_basedir;
694 694
 
@@ -697,32 +697,32 @@  discard block
 block discarded – undo
697 697
 
698 698
 			$exp = $sub = array();
699 699
 
700
-			if( in_array( "img", self::$path_replace_list ) ){
701
-				$exp = array( '/<img(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<img(.*?)src=(?:")([^"]+?)#(?:")/i', '/<img(.*?)src="(.*?)"/', '/<img(.*?)src=(?:\@)([^"]+?)(?:\@)/i' );
702
-				$sub = array( '<img$1src=@$2://$3@', '<img$1src=@$2@', '<img$1src="' . $path . '$2"', '<img$1src="$2"' );
700
+			if (in_array("img", self::$path_replace_list)) {
701
+				$exp = array('/<img(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<img(.*?)src=(?:")([^"]+?)#(?:")/i', '/<img(.*?)src="(.*?)"/', '/<img(.*?)src=(?:\@)([^"]+?)(?:\@)/i');
702
+				$sub = array('<img$1src=@$2://$3@', '<img$1src=@$2@', '<img$1src="' . $path . '$2"', '<img$1src="$2"');
703 703
 			}
704 704
 
705
-			if( in_array( "script", self::$path_replace_list ) ){
706
-				$exp = array_merge( $exp , array( '/<script(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<script(.*?)src=(?:")([^"]+?)#(?:")/i', '/<script(.*?)src="(.*?)"/', '/<script(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
707
-				$sub = array_merge( $sub , array( '<script$1src=@$2://$3@', '<script$1src=@$2@', '<script$1src="' . $path . '$2"', '<script$1src="$2"' ) );
705
+			if (in_array("script", self::$path_replace_list)) {
706
+				$exp = array_merge($exp, array('/<script(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<script(.*?)src=(?:")([^"]+?)#(?:")/i', '/<script(.*?)src="(.*?)"/', '/<script(.*?)src=(?:\@)([^"]+?)(?:\@)/i'));
707
+				$sub = array_merge($sub, array('<script$1src=@$2://$3@', '<script$1src=@$2@', '<script$1src="' . $path . '$2"', '<script$1src="$2"'));
708 708
 			}
709 709
 
710
-			if( in_array( "link", self::$path_replace_list ) ){
711
-				$exp = array_merge( $exp , array( '/<link(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ) );
712
-				$sub = array_merge( $sub , array( '<link$1href=@$2://$3@', '<link$1href=@$2@' , '<link$1href="' . $path . '$2"', '<link$1href="$2"' ) );
710
+			if (in_array("link", self::$path_replace_list)) {
711
+				$exp = array_merge($exp, array('/<link(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i'));
712
+				$sub = array_merge($sub, array('<link$1href=@$2://$3@', '<link$1href=@$2@', '<link$1href="' . $path . '$2"', '<link$1href="$2"'));
713 713
 			}
714 714
 
715
-			if( in_array( "a", self::$path_replace_list ) ){
716
-				$exp = array_merge( $exp , array( '/<a(.*?)href=(?:")(http\:\/\/|https\:\/\/|javascript:)([^"]+?)(?:")/i', '/<a(.*?)href="(.*?)"/', '/<a(.*?)href=(?:\@)([^"]+?)(?:\@)/i'  ) );
717
-				$sub = array_merge( $sub , array( '<a$1href=@$2$3@', '<a$1href="' . self::$base_url . '$2"', '<a$1href="$2"' ) );
715
+			if (in_array("a", self::$path_replace_list)) {
716
+				$exp = array_merge($exp, array('/<a(.*?)href=(?:")(http\:\/\/|https\:\/\/|javascript:)([^"]+?)(?:")/i', '/<a(.*?)href="(.*?)"/', '/<a(.*?)href=(?:\@)([^"]+?)(?:\@)/i'));
717
+				$sub = array_merge($sub, array('<a$1href=@$2$3@', '<a$1href="' . self::$base_url . '$2"', '<a$1href="$2"'));
718 718
 			}
719 719
 
720
-			if( in_array( "input", self::$path_replace_list ) ){
721
-				$exp = array_merge( $exp , array( '/<input(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<input(.*?)src=(?:")([^"]+?)#(?:")/i', '/<input(.*?)src="(.*?)"/', '/<input(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) );
722
-				$sub = array_merge( $sub , array( '<input$1src=@$2://$3@', '<input$1src=@$2@', '<input$1src="' . $path . '$2"', '<input$1src="$2"' ) );
720
+			if (in_array("input", self::$path_replace_list)) {
721
+				$exp = array_merge($exp, array('/<input(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<input(.*?)src=(?:")([^"]+?)#(?:")/i', '/<input(.*?)src="(.*?)"/', '/<input(.*?)src=(?:\@)([^"]+?)(?:\@)/i'));
722
+				$sub = array_merge($sub, array('<input$1src=@$2://$3@', '<input$1src=@$2@', '<input$1src="' . $path . '$2"', '<input$1src="$2"'));
723 723
 			}
724 724
 
725
-			return preg_replace( $exp, $sub, $html );
725
+			return preg_replace($exp, $sub, $html);
726 726
 
727 727
 		}
728 728
 		else
@@ -745,9 +745,9 @@  discard block
 block discarded – undo
745 745
 	 * @param  string $echo (optional)
746 746
 	 * @return string
747 747
 	 */
748
-	public function const_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
748
+	public function const_replace($html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null) {
749 749
 		// const
750
-		return preg_replace( '/\{\#(\w+)\#{0,1}\}/', $php_left_delimiter . ( $echo ? " echo " : null ) . '\\1' . $php_right_delimiter, $html );
750
+		return preg_replace('/\{\#(\w+)\#{0,1}\}/', $php_left_delimiter . ($echo ? " echo " : null) . '\\1' . $php_right_delimiter, $html);
751 751
 	}
752 752
 
753 753
 
@@ -765,77 +765,77 @@  discard block
 block discarded – undo
765 765
 	 * @param  string $echo (optional)
766 766
 	 * @return string
767 767
 	 */
768
-	public function func_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
768
+	public function func_replace($html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null) {
769 769
 
770
-		preg_match_all( '/' . '\{\#{0,1}(\"{0,1}.*?\"{0,1})(\|\w.*?)\#{0,1}\}' . '/', $html, $matches );
770
+		preg_match_all('/' . '\{\#{0,1}(\"{0,1}.*?\"{0,1})(\|\w.*?)\#{0,1}\}' . '/', $html, $matches);
771 771
 
772
-		for( $i=0, $n=count($matches[0]); $i<$n; $i++ ){
772
+		for ($i = 0, $n = count($matches[0]); $i < $n; $i++) {
773 773
 
774 774
 			//complete tag ex: {$news.title|substr:0,100}
775
-			$tag = $matches[ 0 ][ $i ];
775
+			$tag = $matches[0][$i];
776 776
 
777 777
 			//variable name ex: news.title
778
-			$var = $matches[ 1 ][ $i ];
778
+			$var = $matches[1][$i];
779 779
 
780 780
 			//function and parameters associate to the variable ex: substr:0,100
781
-			$extra_var = $matches[ 2 ][ $i ];
781
+			$extra_var = $matches[2][$i];
782 782
 
783 783
 			// check if there's any function disabled by black_list
784
-			$this->function_check( $tag );
784
+			$this->function_check($tag);
785 785
 
786
-			$extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
786
+			$extra_var = $this->var_replace($extra_var, null, null, null, null, $loop_level);
787 787
 
788 788
 
789 789
 			// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
790
-			$is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var );
790
+			$is_init_variable = preg_match("/^(\s*?)\=[^=](.*?)$/", $extra_var);
791 791
 
792 792
 			//function associate to variable
793
-			$function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
793
+			$function_var = ($extra_var and $extra_var[0] == '|') ? substr($extra_var, 1) : null;
794 794
 
795 795
 			//variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
796
-			$temp = preg_split( "/\.|\[|\-\>/", $var );
796
+			$temp = preg_split("/\.|\[|\-\>/", $var);
797 797
 
798 798
 			//variable name
799
-			$var_name = $temp[ 0 ];
799
+			$var_name = $temp[0];
800 800
 
801 801
 			//variable path
802
-			$variable_path = substr( $var, strlen( $var_name ) );
802
+			$variable_path = substr($var, strlen($var_name));
803 803
 
804 804
 			//parentesis transform [ e ] in [" e in "]
805
-			$variable_path = str_replace( '[', '["', $variable_path );
806
-			$variable_path = str_replace( ']', '"]', $variable_path );
805
+			$variable_path = str_replace('[', '["', $variable_path);
806
+			$variable_path = str_replace(']', '"]', $variable_path);
807 807
 
808 808
 			//transform .$variable in ["$variable"]
809
-			$variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path );
809
+			$variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path);
810 810
 
811 811
 			//transform [variable] in ["variable"]
812
-			$variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path );
812
+			$variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path);
813 813
 
814 814
 			//if there's a function
815
-			if( $function_var ){
815
+			if ($function_var) {
816 816
 
817 817
 				// check if there's a function or a static method and separate, function by parameters
818
-				$function_var = str_replace("::", "@double_dot@", $function_var );
818
+				$function_var = str_replace("::", "@double_dot@", $function_var);
819 819
 
820 820
 				// get the position of the first :
821
-				if( $dot_position = strpos( $function_var, ":" ) ){
821
+				if ($dot_position = strpos($function_var, ":")) {
822 822
 
823 823
 					// get the function and the parameters
824
-					$function = substr( $function_var, 0, $dot_position );
825
-					$params = substr( $function_var, $dot_position+1 );
824
+					$function = substr($function_var, 0, $dot_position);
825
+					$params = substr($function_var, $dot_position+1);
826 826
 
827 827
 				}
828
-				else{
828
+				else {
829 829
 
830 830
 					//get the function
831
-					$function = str_replace( "@double_dot@", "::", $function_var );
831
+					$function = str_replace("@double_dot@", "::", $function_var);
832 832
 					$params = null;
833 833
 
834 834
 				}
835 835
 
836 836
 				// replace back the @double_dot@ with ::
837
-				$function = str_replace( "@double_dot@", "::", $function );
838
-				$params = str_replace( "@double_dot@", "::", $params );
837
+				$function = str_replace("@double_dot@", "::", $function);
838
+				$params = str_replace("@double_dot@", "::", $params);
839 839
 
840 840
 
841 841
 			}
@@ -845,16 +845,16 @@  discard block
 block discarded – undo
845 845
 			$php_var = $var_name . $variable_path;
846 846
 
847 847
 			// compile the variable for php
848
-			if( isset( $function ) ){
849
-				if( $php_var )
850
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
848
+			if (isset($function)) {
849
+				if ($php_var)
850
+					$php_var = $php_left_delimiter . (!$is_init_variable && $echo ? 'echo ' : null) . ($params ? "( $function( $php_var, $params ) )" : "$function( $php_var )") . $php_right_delimiter;
851 851
 				else
852
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter;
852
+					$php_var = $php_left_delimiter . (!$is_init_variable && $echo ? 'echo ' : null) . ($params ? "( $function( $params ) )" : "$function()") . $php_right_delimiter;
853 853
 			}
854 854
 			else
855
-				$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
855
+				$php_var = $php_left_delimiter . (!$is_init_variable && $echo ? 'echo ' : null) . $php_var . $extra_var . $php_right_delimiter;
856 856
 
857
-			$html = str_replace( $tag, $php_var, $html );
857
+			$html = str_replace($tag, $php_var, $html);
858 858
 
859 859
 		}
860 860
 
@@ -877,15 +877,15 @@  discard block
 block discarded – undo
877 877
 	 * @param  string $echo (optional)
878 878
 	 * @return string
879 879
 	 */
880
-	public function var_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){
880
+	public function var_replace($html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null) {
881 881
 
882 882
 		//all variables
883
-		if( preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ) ){
883
+		if (preg_match_all('/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches)) {
884 884
 
885
-			for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ )
886
-				$parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]);
885
+			for ($parsed = array(), $i = 0, $n = count($matches[0]); $i < $n; $i++)
886
+				$parsed[$matches[0][$i]] = array('var'=>$matches[1][$i], 'extra_var'=>$matches[2][$i]);
887 887
 
888
-			foreach( $parsed as $tag => $array ){
888
+			foreach ($parsed as $tag => $array) {
889 889
 
890 890
 				//variable name ex: news.title
891 891
 				$var = $array['var'];
@@ -894,89 +894,89 @@  discard block
 block discarded – undo
894 894
 				$extra_var = $array['extra_var'];
895 895
 
896 896
 				// check if there's any function disabled by black_list
897
-				$this->function_check( $tag );
897
+				$this->function_check($tag);
898 898
 
899
-				$extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
899
+				$extra_var = $this->var_replace($extra_var, null, null, null, null, $loop_level);
900 900
 
901 901
 				// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
902
-				$is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var );
902
+				$is_init_variable = preg_match("/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var);
903 903
 
904 904
 				//function associate to variable
905
-				$function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
905
+				$function_var = ($extra_var and $extra_var[0] == '|') ? substr($extra_var, 1) : null;
906 906
 
907 907
 				//variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title)
908
-				$temp = preg_split( "/\.|\[|\-\>/", $var );
908
+				$temp = preg_split("/\.|\[|\-\>/", $var);
909 909
 
910 910
 				//variable name
911
-				$var_name = $temp[ 0 ];
911
+				$var_name = $temp[0];
912 912
 
913 913
 				//variable path
914
-				$variable_path = substr( $var, strlen( $var_name ) );
914
+				$variable_path = substr($var, strlen($var_name));
915 915
 
916 916
 				//parentesis transform [ e ] in [" e in "]
917
-				$variable_path = str_replace( '[', '["', $variable_path );
918
-				$variable_path = str_replace( ']', '"]', $variable_path );
917
+				$variable_path = str_replace('[', '["', $variable_path);
918
+				$variable_path = str_replace(']', '"]', $variable_path);
919 919
 
920 920
 				//transform .$variable in ["$variable"] and .variable in ["variable"]
921
-				$variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path );
921
+				$variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path);
922 922
 
923 923
 				// if is an assignment also assign the variable to $this->var['value']
924
-				if( $is_init_variable )
924
+				if ($is_init_variable)
925 925
 					$extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
926 926
 
927 927
 
928 928
 
929 929
 				//if there's a function
930
-				if( $function_var ){
930
+				if ($function_var) {
931 931
 
932 932
 					// check if there's a function or a static method and separate, function by parameters
933
-					$function_var = str_replace("::", "@double_dot@", $function_var );
933
+					$function_var = str_replace("::", "@double_dot@", $function_var);
934 934
 
935 935
 
936 936
 					// get the position of the first :
937
-					if( $dot_position = strpos( $function_var, ":" ) ){
937
+					if ($dot_position = strpos($function_var, ":")) {
938 938
 
939 939
 						// get the function and the parameters
940
-						$function = substr( $function_var, 0, $dot_position );
941
-						$params = substr( $function_var, $dot_position+1 );
940
+						$function = substr($function_var, 0, $dot_position);
941
+						$params = substr($function_var, $dot_position+1);
942 942
 
943 943
 					}
944
-					else{
944
+					else {
945 945
 
946 946
 						//get the function
947
-						$function = str_replace( "@double_dot@", "::", $function_var );
947
+						$function = str_replace("@double_dot@", "::", $function_var);
948 948
 						$params = null;
949 949
 
950 950
 					}
951 951
 
952 952
 					// replace back the @double_dot@ with ::
953
-					$function = str_replace( "@double_dot@", "::", $function );
954
-					$params = str_replace( "@double_dot@", "::", $params );
953
+					$function = str_replace("@double_dot@", "::", $function);
954
+					$params = str_replace("@double_dot@", "::", $params);
955 955
 				}
956 956
 				else
957 957
 					$function = $params = null;
958 958
 
959 959
 				//if it is inside a loop
960
-				if( $loop_level ){
960
+				if ($loop_level) {
961 961
 					//verify the variable name
962
-					if( $var_name == 'key' )
962
+					if ($var_name == 'key')
963 963
 							$php_var = '$key' . $loop_level;
964
-					elseif( $var_name == 'value' )
964
+					elseif ($var_name == 'value')
965 965
 							$php_var = '$value' . $loop_level . $variable_path;
966
-					elseif( $var_name == 'counter' )
966
+					elseif ($var_name == 'counter')
967 967
 							$php_var = '$counter' . $loop_level;
968 968
 					else
969 969
 							$php_var = '$' . $var_name . $variable_path;
970
-				}else
970
+				} else
971 971
 					$php_var = '$' . $var_name . $variable_path;
972 972
 
973 973
 				// compile the variable for php
974
-				if( isset( $function ) )
975
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
974
+				if (isset($function))
975
+					$php_var = $php_left_delimiter . (!$is_init_variable && $echo ? 'echo ' : null) . ($params ? "( $function( $php_var, $params ) )" : "$function( $php_var )") . $php_right_delimiter;
976 976
 				else
977
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
977
+					$php_var = $php_left_delimiter . (!$is_init_variable && $echo ? 'echo ' : null) . $php_var . $extra_var . $php_right_delimiter;
978 978
 
979
-				$html = str_replace( $tag, $php_var, $html );
979
+				$html = str_replace($tag, $php_var, $html);
980 980
 
981 981
 
982 982
 			}
@@ -995,17 +995,17 @@  discard block
 block discarded – undo
995 995
 	 * @throws RainTpl_SyntaxException
996 996
 	 * @return void
997 997
 	 */
998
-	protected function function_check( $code ){
998
+	protected function function_check($code) {
999 999
 
1000
-		$preg = '#(\W|\s)' . implode( '(\W|\s)|(\W|\s)', self::$black_list ) . '(\W|\s)#';
1000
+		$preg = '#(\W|\s)' . implode('(\W|\s)|(\W|\s)', self::$black_list) . '(\W|\s)#';
1001 1001
 
1002 1002
 		// check if the function is in the black list (or not in white list)
1003
-		if( count(self::$black_list) && preg_match( $preg, $code, $match ) ){
1003
+		if (count(self::$black_list) && preg_match($preg, $code, $match)) {
1004 1004
 
1005 1005
 			// find the line of the error
1006 1006
 			$line = 0;
1007
-			$rows=explode("\n",$this->tpl['source']);
1008
-			while( !strpos($rows[$line],$code) )
1007
+			$rows = explode("\n", $this->tpl['source']);
1008
+			while (!strpos($rows[$line], $code))
1009 1009
 				$line++;
1010 1010
 
1011 1011
 			// stop the execution of the script
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 	 * @param  RainTpl_Exception $e
1027 1027
 	 * @return string
1028 1028
 	 */
1029
-	protected function printDebug(RainTpl_Exception $e){
1029
+	protected function printDebug(RainTpl_Exception $e) {
1030 1030
 		if (!self::$debug) {
1031 1031
 			throw $e;
1032 1032
 		}
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 				$output .= '<p>in tag: ' . htmlspecialchars($e->getTag()) . '</p>';
1044 1044
 			}
1045 1045
 			if (null != $e->getTemplateLine() && null != $e->getTag()) {
1046
-				$rows=explode("\n",  htmlspecialchars($this->tpl['source']));
1046
+				$rows = explode("\n", htmlspecialchars($this->tpl['source']));
1047 1047
 				$rows[$e->getTemplateLine()] = '<font color=red>' . $rows[$e->getTemplateLine()] . '</font>';
1048 1048
 				$output .= '<h3>template code</h3>' . implode('<br />', $rows) . '</pre>';
1049 1049
 			}
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 /**
1062 1062
  * Basic Rain tpl exception.
1063 1063
  */
1064
-class RainTpl_Exception extends Exception{
1064
+class RainTpl_Exception extends Exception {
1065 1065
 	/**
1066 1066
 	 * Path of template file with error.
1067 1067
 	 */
@@ -1095,13 +1095,13 @@  discard block
 block discarded – undo
1095 1095
 /**
1096 1096
  * Exception thrown when template file does not exists.
1097 1097
  */
1098
-class RainTpl_NotFoundException extends RainTpl_Exception{
1098
+class RainTpl_NotFoundException extends RainTpl_Exception {
1099 1099
 }
1100 1100
 
1101 1101
 /**
1102 1102
  * Exception thrown when syntax error occurs.
1103 1103
  */
1104
-class RainTpl_SyntaxException extends RainTpl_Exception{
1104
+class RainTpl_SyntaxException extends RainTpl_Exception {
1105 1105
 	/**
1106 1106
 	 * Line in template file where error has occured.
1107 1107
 	 *
Please login to merge, or discard this patch.
Braces   +93 added lines, -73 removed lines patch added patch discarded remove patch
@@ -178,10 +178,11 @@  discard block
 block discarded – undo
178 178
 	 * @param  mixed $value value assigned to this variable. Not set if variable_name is an associative array
179 179
 	 */
180 180
 	public function assign( $variable, $value = null ){
181
-		if( is_array( $variable ) )
182
-			$this->var += $variable;
183
-		else
184
-			$this->var[ $variable ] = $value;
181
+		if( is_array( $variable ) ) {
182
+					$this->var += $variable;
183
+		} else {
184
+					$this->var[ $variable ] = $value;
185
+		}
185 186
 	}
186 187
 
187 188
 
@@ -232,14 +233,19 @@  discard block
 block discarded – undo
232 233
 
233 234
 
234 235
 			// save the output in the cache
235
-			if( $this->cache )
236
-				file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents );
236
+			if( $this->cache ) {
237
+							file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents );
238
+			}
237 239
 
238 240
 			// free memory
239 241
 			unset( $this->tpl );
240 242
 
241 243
 			// return or print the template
242
-			if( $return_string ) return $raintpl_contents; else echo $raintpl_contents;
244
+			if( $return_string ) {
245
+			    return $raintpl_contents;
246
+			} else {
247
+			    echo $raintpl_contents;
248
+			}
243 249
 
244 250
 		}
245 251
 
@@ -261,12 +267,13 @@  discard block
 block discarded – undo
261 267
 		// set the cache_id
262 268
 		$this->cache_id = $cache_id;
263 269
 
264
-		if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) )
265
-			return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 );
266
-		else{
270
+		if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) ) {
271
+					return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 );
272
+		} else{
267 273
 			//delete the cache of the selected template
268
-			if (file_exists($this->tpl['cache_filename']))
269
-			unlink($this->tpl['cache_filename'] );
274
+			if (file_exists($this->tpl['cache_filename'])) {
275
+						unlink($this->tpl['cache_filename'] );
276
+			}
270 277
 			$this->cache = true;
271 278
 		}
272 279
 	}
@@ -282,10 +289,10 @@  discard block
 block discarded – undo
282 289
 	 * @param  mixed $value content to set in the setting (optional)
283 290
 	 */
284 291
 	public static function configure( $setting, $value = null ){
285
-		if( is_array( $setting ) )
286
-			foreach( $setting as $key => $value )
292
+		if( is_array( $setting ) ) {
293
+					foreach( $setting as $key => $value )
287 294
 				self::configure( $key, $value );
288
-		else if( property_exists( __CLASS__, $setting ) ){
295
+		} else if( property_exists( __CLASS__, $setting ) ){
289 296
 			self::$$setting = $value;
290 297
 			self::$config_name_sum[ $setting ] = $value; // take trace of all config
291 298
 		}
@@ -364,8 +371,9 @@  discard block
 block discarded – undo
364 371
 		$template_code = preg_replace( "/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code );
365 372
 
366 373
 		//disable php tag
367
-		if( !self::$php_enabled )
368
-			$template_code = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $template_code );
374
+		if( !self::$php_enabled ) {
375
+					$template_code = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $template_code );
376
+		}
369 377
 
370 378
 		//xml re-substitution
371 379
 		$template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
@@ -378,11 +386,13 @@  discard block
 block discarded – undo
378 386
 		$template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled );
379 387
 
380 388
 		// create directories
381
-		if( !is_dir( $cache_dir ) )
382
-			mkdir( $cache_dir, 0755, true );
389
+		if( !is_dir( $cache_dir ) ) {
390
+					mkdir( $cache_dir, 0755, true );
391
+		}
383 392
 
384
-		if( !is_writable( $cache_dir ) )
385
-			throw new RainTpl_Exception ('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
393
+		if( !is_writable( $cache_dir ) ) {
394
+					throw new RainTpl_Exception ('Cache directory ' . $cache_dir . ' doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/');
395
+		}
386 396
 
387 397
 		//write compiled file
388 398
 		file_put_contents( $compiled_filename, $template_compiled );
@@ -453,8 +463,9 @@  discard block
 block discarded – undo
453 463
 		while( $html = array_shift( $parsed_code ) ){
454 464
 
455 465
 			//close ignore tag
456
-			if( !$comment_is_open && ( strpos( $html, '{/ignore}' ) !== FALSE || strpos( $html, '*}' ) !== FALSE ) )
457
-				$ignore_is_open = false;
466
+			if( !$comment_is_open && ( strpos( $html, '{/ignore}' ) !== FALSE || strpos( $html, '*}' ) !== FALSE ) ) {
467
+							$ignore_is_open = false;
468
+			}
458 469
 
459 470
 			//code between tag ignore id deleted
460 471
 			elseif( $ignore_is_open ){
@@ -462,20 +473,24 @@  discard block
 block discarded – undo
462 473
 			}
463 474
 
464 475
 			//close no parse tag
465
-			elseif( strpos( $html, '{/noparse}' ) !== FALSE )
466
-				$comment_is_open = false;
476
+			elseif( strpos( $html, '{/noparse}' ) !== FALSE ) {
477
+							$comment_is_open = false;
478
+			}
467 479
 
468 480
 			//code between tag noparse is not compiled
469
-			elseif( $comment_is_open )
470
-				$compiled_code .= $html;
481
+			elseif( $comment_is_open ) {
482
+							$compiled_code .= $html;
483
+			}
471 484
 
472 485
 			//ignore
473
-			elseif( strpos( $html, '{ignore}' ) !== FALSE || strpos( $html, '{*' ) !== FALSE )
474
-				$ignore_is_open = true;
486
+			elseif( strpos( $html, '{ignore}' ) !== FALSE || strpos( $html, '{*' ) !== FALSE ) {
487
+							$ignore_is_open = true;
488
+			}
475 489
 
476 490
 			//noparse
477
-			elseif( strpos( $html, '{noparse}' ) !== FALSE )
478
-				$comment_is_open = true;
491
+			elseif( strpos( $html, '{noparse}' ) !== FALSE ) {
492
+							$comment_is_open = true;
493
+			}
479 494
 
480 495
 			//include tag
481 496
 			elseif( preg_match( '/\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\}/', $html, $code ) ){
@@ -496,8 +511,7 @@  discard block
 block discarded – undo
496 511
 									( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
497 512
 								 '	$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
498 513
 								 '} ?>';
499
-				}
500
-				else{
514
+				} else{
501 515
 
502 516
 					//dynamic include
503 517
 					$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
@@ -615,11 +629,12 @@  discard block
 block discarded – undo
615 629
 				// check if there's any function disabled by black_list
616 630
 				$this->function_check( $tag );
617 631
 
618
-				if( empty( $code[ 2 ] ) )
619
-					$parsed_function = $function . "()";
620
-				else
621
-					// parse the function
632
+				if( empty( $code[ 2 ] ) ) {
633
+									$parsed_function = $function . "()";
634
+				} else {
635
+									// parse the function
622 636
 					$parsed_function = $function . $this->var_replace( $code[ 2 ], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level );
637
+				}
623 638
 
624 639
 				//if code
625 640
 				$compiled_code .=   "<?php echo $parsed_function; ?>";
@@ -724,9 +739,9 @@  discard block
 block discarded – undo
724 739
 
725 740
 			return preg_replace( $exp, $sub, $html );
726 741
 
742
+		} else {
743
+					return $html;
727 744
 		}
728
-		else
729
-			return $html;
730 745
 
731 746
 	}
732 747
 
@@ -824,8 +839,7 @@  discard block
 block discarded – undo
824 839
 					$function = substr( $function_var, 0, $dot_position );
825 840
 					$params = substr( $function_var, $dot_position+1 );
826 841
 
827
-				}
828
-				else{
842
+				} else{
829 843
 
830 844
 					//get the function
831 845
 					$function = str_replace( "@double_dot@", "::", $function_var );
@@ -838,21 +852,22 @@  discard block
 block discarded – undo
838 852
 				$params = str_replace( "@double_dot@", "::", $params );
839 853
 
840 854
 
855
+			} else {
856
+							$function = $params = null;
841 857
 			}
842
-			else
843
-				$function = $params = null;
844 858
 
845 859
 			$php_var = $var_name . $variable_path;
846 860
 
847 861
 			// compile the variable for php
848 862
 			if( isset( $function ) ){
849
-				if( $php_var )
850
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
851
-				else
852
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter;
863
+				if( $php_var ) {
864
+									$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
865
+				} else {
866
+									$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter;
867
+				}
868
+			} else {
869
+							$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
853 870
 			}
854
-			else
855
-				$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
856 871
 
857 872
 			$html = str_replace( $tag, $php_var, $html );
858 873
 
@@ -882,8 +897,9 @@  discard block
 block discarded – undo
882 897
 		//all variables
883 898
 		if( preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ) ){
884 899
 
885
-			for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ )
886
-				$parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]);
900
+			for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ ) {
901
+							$parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]);
902
+			}
887 903
 
888 904
 			foreach( $parsed as $tag => $array ){
889 905
 
@@ -921,8 +937,9 @@  discard block
 block discarded – undo
921 937
 				$variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path );
922 938
 
923 939
 				// if is an assignment also assign the variable to $this->var['value']
924
-				if( $is_init_variable )
925
-					$extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
940
+				if( $is_init_variable ) {
941
+									$extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
942
+				}
926 943
 
927 944
 
928 945
 
@@ -940,8 +957,7 @@  discard block
 block discarded – undo
940 957
 						$function = substr( $function_var, 0, $dot_position );
941 958
 						$params = substr( $function_var, $dot_position+1 );
942 959
 
943
-					}
944
-					else{
960
+					} else{
945 961
 
946 962
 						//get the function
947 963
 						$function = str_replace( "@double_dot@", "::", $function_var );
@@ -952,29 +968,32 @@  discard block
 block discarded – undo
952 968
 					// replace back the @double_dot@ with ::
953 969
 					$function = str_replace( "@double_dot@", "::", $function );
954 970
 					$params = str_replace( "@double_dot@", "::", $params );
971
+				} else {
972
+									$function = $params = null;
955 973
 				}
956
-				else
957
-					$function = $params = null;
958 974
 
959 975
 				//if it is inside a loop
960 976
 				if( $loop_level ){
961 977
 					//verify the variable name
962
-					if( $var_name == 'key' )
963
-							$php_var = '$key' . $loop_level;
964
-					elseif( $var_name == 'value' )
965
-							$php_var = '$value' . $loop_level . $variable_path;
966
-					elseif( $var_name == 'counter' )
967
-							$php_var = '$counter' . $loop_level;
968
-					else
969
-							$php_var = '$' . $var_name . $variable_path;
970
-				}else
971
-					$php_var = '$' . $var_name . $variable_path;
978
+					if( $var_name == 'key' ) {
979
+												$php_var = '$key' . $loop_level;
980
+					} elseif( $var_name == 'value' ) {
981
+												$php_var = '$value' . $loop_level . $variable_path;
982
+					} elseif( $var_name == 'counter' ) {
983
+												$php_var = '$counter' . $loop_level;
984
+					} else {
985
+												$php_var = '$' . $var_name . $variable_path;
986
+					}
987
+				} else {
988
+									$php_var = '$' . $var_name . $variable_path;
989
+				}
972 990
 
973 991
 				// compile the variable for php
974
-				if( isset( $function ) )
975
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
976
-				else
977
-					$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
992
+				if( isset( $function ) ) {
993
+									$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
994
+				} else {
995
+									$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
996
+				}
978 997
 
979 998
 				$html = str_replace( $tag, $php_var, $html );
980 999
 
@@ -1005,8 +1024,9 @@  discard block
 block discarded – undo
1005 1024
 			// find the line of the error
1006 1025
 			$line = 0;
1007 1026
 			$rows=explode("\n",$this->tpl['source']);
1008
-			while( !strpos($rows[$line],$code) )
1009
-				$line++;
1027
+			while( !strpos($rows[$line],$code) ) {
1028
+							$line++;
1029
+			}
1010 1030
 
1011 1031
 			// stop the execution of the script
1012 1032
 			$e = new RainTpl_SyntaxException('Unallowed syntax in ' . $this->tpl['tpl_filename'] . ' template');
Please login to merge, or discard this patch.
lib/vizhash16x16.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -175,8 +175,8 @@
 block discarded – undo
175 175
      * @access private
176 176
      * @param  resource $img
177 177
      * @param  string $direction
178
-     * @param  array $color1
179
-     * @param  array $color2
178
+     * @param  integer[] $color1
179
+     * @param  integer[] $color2
180 180
      * @return resource
181 181
      */
182 182
     private function degrade($img,$direction,$color1,$color2)
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -89,38 +89,38 @@  discard block
 block discarded – undo
89 89
         if (!function_exists('gd_info')) return '';
90 90
 
91 91
         // We hash the input string.
92
-        $hash=hash('sha1',$text.$this->salt).hash('md5',$text.$this->salt);
93
-        $hash=$hash.strrev($hash);  # more data to make graphics
92
+        $hash = hash('sha1', $text . $this->salt) . hash('md5', $text . $this->salt);
93
+        $hash = $hash . strrev($hash); # more data to make graphics
94 94
 
95 95
         // We convert the hash into an array of integers.
96
-        $this->VALUES=array();
97
-        for($i=0; $i<strlen($hash); $i=$i+2){ array_push($this->VALUES,hexdec(substr($hash,$i,2))); }
98
-        $this->VALUES_INDEX=0; // to walk the array.
96
+        $this->VALUES = array();
97
+        for ($i = 0; $i < strlen($hash); $i = $i+2) { array_push($this->VALUES, hexdec(substr($hash, $i, 2))); }
98
+        $this->VALUES_INDEX = 0; // to walk the array.
99 99
 
100 100
         // Then use these integers to drive the creation of an image.
101
-        $image = imagecreatetruecolor($this->width,$this->height);
101
+        $image = imagecreatetruecolor($this->width, $this->height);
102 102
 
103
-        $r0 = $this->getInt();$r=$r0;
104
-        $g0 = $this->getInt();$g=$g0;
105
-        $b0 = $this->getInt();$b=$b0;
103
+        $r0 = $this->getInt(); $r = $r0;
104
+        $g0 = $this->getInt(); $g = $g0;
105
+        $b0 = $this->getInt(); $b = $b0;
106 106
 
107 107
         // First, create an image with a specific gradient background.
108
-        $op='v'; if (($this->getInt()%2)==0) { $op='h'; };
109
-        $image = $this->degrade($image,$op,array($r0,$g0,$b0),array(0,0,0));
108
+        $op = 'v'; if (($this->getInt() % 2) == 0) { $op = 'h'; };
109
+        $image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
110 110
 
111
-        for($i=0; $i<7; $i=$i+1)
111
+        for ($i = 0; $i < 7; $i = $i+1)
112 112
         {
113
-            $action=$this->getInt();
114
-            $color = imagecolorallocate($image, $r,$g,$b);
115
-            $r = ($r0 + $this->getInt()/25)%256;
116
-            $g = ($g0 + $this->getInt()/25)%256;
117
-            $b = ($b0 + $this->getInt()/25)%256;
118
-            $r0=$r; $g0=$g; $b0=$b;
119
-            $this->drawshape($image,$action,$color);
113
+            $action = $this->getInt();
114
+            $color = imagecolorallocate($image, $r, $g, $b);
115
+            $r = ($r0+$this->getInt() / 25) % 256;
116
+            $g = ($g0+$this->getInt() / 25) % 256;
117
+            $b = ($b0+$this->getInt() / 25) % 256;
118
+            $r0 = $r; $g0 = $g; $b0 = $b;
119
+            $this->drawshape($image, $action, $color);
120 120
         }
121 121
 
122
-        $color = imagecolorallocate($image,$this->getInt(),$this->getInt(),$this->getInt());
123
-        $this->drawshape($image,$this->getInt(),$color);
122
+        $color = imagecolorallocate($image, $this->getInt(), $this->getInt(), $this->getInt());
123
+        $this->drawshape($image, $this->getInt(), $color);
124 124
         ob_start();
125 125
         imagepng($image);
126 126
         $imagedata = ob_get_contents();
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      */
139 139
     private function getInt()
140 140
     {
141
-        $v= $this->VALUES[$this->VALUES_INDEX];
141
+        $v = $this->VALUES[$this->VALUES_INDEX];
142 142
         $this->VALUES_INDEX++;
143 143
         $this->VALUES_INDEX %= count($this->VALUES); // Warp around the array
144 144
         return $v;
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     private function getX()
154 154
     {
155
-        return $this->width*$this->getInt()/256;
155
+        return $this->width * $this->getInt() / 256;
156 156
     }
157 157
 
158 158
     /**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     private function getY()
165 165
     {
166
-        return $this->height*$this->getInt()/256;
166
+        return $this->height * $this->getInt() / 256;
167 167
     }
168 168
 
169 169
     /**
@@ -179,22 +179,22 @@  discard block
 block discarded – undo
179 179
      * @param  array $color2
180 180
      * @return resource
181 181
      */
182
-    private function degrade($img,$direction,$color1,$color2)
182
+    private function degrade($img, $direction, $color1, $color2)
183 183
     {
184
-            if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); }
185
-            else { $size = imagesy($img); $sizeinv = imagesx($img);}
184
+            if ($direction == 'h') { $size = imagesx($img); $sizeinv = imagesy($img); }
185
+            else { $size = imagesy($img); $sizeinv = imagesx($img); }
186 186
             $diffs = array(
187
-                    (($color2[0]-$color1[0])/$size),
188
-                    (($color2[1]-$color1[1])/$size),
189
-                    (($color2[2]-$color1[2])/$size)
187
+                    (($color2[0]-$color1[0]) / $size),
188
+                    (($color2[1]-$color1[1]) / $size),
189
+                    (($color2[2]-$color1[2]) / $size)
190 190
             );
191
-            for($i=0;$i<$size;$i++)
191
+            for ($i = 0; $i < $size; $i++)
192 192
             {
193
-                    $r = $color1[0]+($diffs[0]*$i);
194
-                    $g = $color1[1]+($diffs[1]*$i);
195
-                    $b = $color1[2]+($diffs[2]*$i);
196
-                    if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); }
197
-                    else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); }
193
+                    $r = $color1[0]+($diffs[0] * $i);
194
+                    $g = $color1[1]+($diffs[1] * $i);
195
+                    $b = $color1[2]+($diffs[2] * $i);
196
+                    if ($direction == 'h') { imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b)); }
197
+                    else { imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b)); }
198 198
             }
199 199
             return $img;
200 200
     }
@@ -208,24 +208,24 @@  discard block
 block discarded – undo
208 208
      * @param  int $color
209 209
      * @return void
210 210
      */
211
-    private function drawshape($image,$action,$color)
211
+    private function drawshape($image, $action, $color)
212 212
     {
213
-        switch($action%7)
213
+        switch ($action % 7)
214 214
         {
215 215
             case 0:
216
-                ImageFilledRectangle ($image,$this->getX(),$this->getY(),$this->getX(),$this->getY(),$color);
216
+                ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
217 217
                 break;
218 218
             case 1:
219 219
             case 2:
220
-                ImageFilledEllipse ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
220
+                ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
221 221
                 break;
222 222
             case 3:
223
-                $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(),$this->getX(), $this->getY());
224
-                ImageFilledPolygon ($image, $points, 4, $color);
223
+                $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY());
224
+                ImageFilledPolygon($image, $points, 4, $color);
225 225
                 break;
226 226
             default:
227
-                $start=$this->getInt()*360/256; $end=$start+$this->getInt()*180/256;
228
-                ImageFilledArc ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(),$start,$end,$color,IMG_ARC_PIE);
227
+                $start = $this->getInt() * 360 / 256; $end = $start+$this->getInt() * 180 / 256;
228
+                ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
229 229
         }
230 230
     }
231 231
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -86,7 +86,9 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function generate($text)
88 88
     {
89
-        if (!function_exists('gd_info')) return '';
89
+        if (!function_exists('gd_info')) {
90
+            return '';
91
+        }
90 92
 
91 93
         // We hash the input string.
92 94
         $hash=hash('sha1',$text.$this->salt).hash('md5',$text.$this->salt);
@@ -181,8 +183,7 @@  discard block
 block discarded – undo
181 183
      */
182 184
     private function degrade($img,$direction,$color1,$color2)
183 185
     {
184
-            if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); }
185
-            else { $size = imagesy($img); $sizeinv = imagesx($img);}
186
+            if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); } else { $size = imagesy($img); $sizeinv = imagesx($img);}
186 187
             $diffs = array(
187 188
                     (($color2[0]-$color1[0])/$size),
188 189
                     (($color2[1]-$color1[1])/$size),
@@ -193,8 +194,7 @@  discard block
 block discarded – undo
193 194
                     $r = $color1[0]+($diffs[0]*$i);
194 195
                     $g = $color1[1]+($diffs[1]*$i);
195 196
                     $b = $color1[2]+($diffs[2]*$i);
196
-                    if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); }
197
-                    else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); }
197
+                    if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); } else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); }
198 198
             }
199 199
             return $img;
200 200
     }
Please login to merge, or discard this patch.
lib/zerobin/abstract.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * Test if a paste exists.
87 87
      *
88 88
      * @access public
89
-     * @param  string $dataid
89
+     * @param string $pasteid
90 90
      * @return bool
91 91
      */
92 92
     abstract public function exists($pasteid);
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
      * Test if a comment exists.
117 117
      *
118 118
      * @access public
119
-     * @param  string $dataid
120 119
      * @param  string $parentid
121 120
      * @param  string $commentid
121
+     * @param string $pasteid
122 122
      * @return void
123 123
      */
124 124
     abstract public function existsComment($pasteid, $parentid, $commentid);
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      *
129 129
      * @access public
130 130
      * @param  array $comments
131
-     * @param  int|string $postdate
131
+     * @param  integer $postdate
132 132
      * @return void
133 133
      */
134 134
     protected function getOpenSlot(&$comments, $postdate)
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,9 @@
 block discarded – undo
136 136
         if (array_key_exists($postdate, $comments))
137 137
         {
138 138
             $parts = explode('.', $postdate, 2);
139
-            if (!array_key_exists(1, $parts)) $parts[1] = 0;
139
+            if (!array_key_exists(1, $parts)) {
140
+                $parts[1] = 0;
141
+            }
140 142
             ++$parts[1];
141 143
             return $this->getOpenSlot($comments, implode('.', $parts));
142 144
         }
Please login to merge, or discard this patch.
lib/zerobin/data.php 3 patches
Doc Comments   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -124,8 +124,7 @@  discard block
 block discarded – undo
124 124
      * Test if a paste exists.
125 125
      *
126 126
      * @access public
127
-     * @param  string $dataid
128
-     * @return void
127
+     * @return boolean
129 128
      */
130 129
     public function exists($pasteid)
131 130
     {
@@ -197,10 +196,10 @@  discard block
 block discarded – undo
197 196
      * Test if a comment exists.
198 197
      *
199 198
      * @access public
200
-     * @param  string $dataid
201 199
      * @param  string $parentid
202 200
      * @param  string $commentid
203
-     * @return void
201
+     * @param string $pasteid
202
+     * @return boolean
204 203
      */
205 204
     public function existsComment($pasteid, $parentid, $commentid)
206 205
     {
@@ -245,7 +244,7 @@  discard block
 block discarded – undo
245 244
      * @access private
246 245
      * @static
247 246
      * @param  string $dataid
248
-     * @return void
247
+     * @return string
249 248
      */
250 249
     private static function _dataid2path($dataid)
251 250
     {
@@ -260,7 +259,7 @@  discard block
 block discarded – undo
260 259
      * @access private
261 260
      * @static
262 261
      * @param  string $dataid
263
-     * @return void
262
+     * @return string
264 263
      */
265 264
     private static function _dataid2discussionpath($dataid)
266 265
     {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             array_key_exists('dir', $options)
43 43
         ) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
44 44
         // if needed initialize the singleton
45
-        if(!(self::$_instance instanceof zerobin_data)) {
45
+        if (!(self::$_instance instanceof zerobin_data)) {
46 46
             self::$_instance = new self;
47 47
             self::_init();
48 48
         }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function read($pasteid)
76 76
     {
77
-        if(!$this->exists($pasteid)) return false;
77
+        if (!$this->exists($pasteid)) return false;
78 78
         $paste = json_decode(
79 79
             file_get_contents(self::_dataid2path($pasteid) . $pasteid)
80 80
         );
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
             $dir = dir($discdir);
112 112
             while (false !== ($filename = $dir->read()))
113 113
             {
114
-                if (is_file($discdir.$filename)) @unlink($discdir.$filename);
114
+                if (is_file($discdir . $filename)) @unlink($discdir . $filename);
115 115
             }
116 116
             $dir->close();
117 117
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             file_put_contents(
228 228
                 self::$_dir . '.htaccess',
229 229
                 'Allow from none' . PHP_EOL .
230
-                'Deny from all'. PHP_EOL
230
+                'Deny from all' . PHP_EOL
231 231
             );
232 232
         }
233 233
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      */
250 250
     private static function _dataid2path($dataid)
251 251
     {
252
-        return self::$_dir . substr($dataid,0,2) . '/' . substr($dataid,2,2) . '/';
252
+        return self::$_dir . substr($dataid, 0, 2) . '/' . substr($dataid, 2, 2) . '/';
253 253
     }
254 254
 
255 255
     /**
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
         if (
41 41
             is_array($options) &&
42 42
             array_key_exists('dir', $options)
43
-        ) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
43
+        ) {
44
+            self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
45
+        }
44 46
         // if needed initialize the singleton
45 47
         if(!(self::$_instance instanceof zerobin_data)) {
46 48
             self::$_instance = new self;
@@ -60,8 +62,12 @@  discard block
 block discarded – undo
60 62
     public function create($pasteid, $paste)
61 63
     {
62 64
         $storagedir = self::_dataid2path($pasteid);
63
-        if (is_file($storagedir . $pasteid)) return false;
64
-        if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
65
+        if (is_file($storagedir . $pasteid)) {
66
+            return false;
67
+        }
68
+        if (!is_dir($storagedir)) {
69
+            mkdir($storagedir, 0705, true);
70
+        }
65 71
         return (bool) @file_put_contents($storagedir . $pasteid, json_encode($paste));
66 72
     }
67 73
 
@@ -74,7 +80,9 @@  discard block
 block discarded – undo
74 80
      */
75 81
     public function read($pasteid)
76 82
     {
77
-        if(!$this->exists($pasteid)) return false;
83
+        if(!$this->exists($pasteid)) {
84
+            return false;
85
+        }
78 86
         $paste = json_decode(
79 87
             file_get_contents(self::_dataid2path($pasteid) . $pasteid)
80 88
         );
@@ -111,7 +119,9 @@  discard block
 block discarded – undo
111 119
             $dir = dir($discdir);
112 120
             while (false !== ($filename = $dir->read()))
113 121
             {
114
-                if (is_file($discdir.$filename)) @unlink($discdir.$filename);
122
+                if (is_file($discdir.$filename)) {
123
+                    @unlink($discdir.$filename);
124
+                }
115 125
             }
116 126
             $dir->close();
117 127
 
@@ -146,8 +156,12 @@  discard block
 block discarded – undo
146 156
     {
147 157
         $storagedir = self::_dataid2discussionpath($pasteid);
148 158
         $filename = $pasteid . '.' . $commentid . '.' . $parentid;
149
-        if (is_file($storagedir . $filename)) return false;
150
-        if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
159
+        if (is_file($storagedir . $filename)) {
160
+            return false;
161
+        }
162
+        if (!is_dir($storagedir)) {
163
+            mkdir($storagedir, 0705, true);
164
+        }
151 165
         return (bool) @file_put_contents($storagedir . $filename, json_encode($comment));
152 166
     }
153 167
 
@@ -220,7 +234,9 @@  discard block
 block discarded – undo
220 234
     private static function _init()
221 235
     {
222 236
         // Create storage directory if it does not exist.
223
-        if (!is_dir(self::$_dir)) mkdir(self::$_dir, 0705);
237
+        if (!is_dir(self::$_dir)) {
238
+            mkdir(self::$_dir, 0705);
239
+        }
224 240
         // Create .htaccess file if it does not exist.
225 241
         if (!is_file(self::$_dir . '.htaccess'))
226 242
         {
Please login to merge, or discard this patch.
lib/zerobin/db.php 4 patches
Doc Comments   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -295,8 +295,7 @@  discard block
 block discarded – undo
295 295
      * Test if a paste exists.
296 296
      *
297 297
      * @access public
298
-     * @param  string $dataid
299
-     * @return void
298
+     * @return boolean
300 299
      */
301 300
     public function exists($pasteid)
302 301
     {
@@ -373,10 +372,10 @@  discard block
 block discarded – undo
373 372
      * Test if a comment exists.
374 373
      *
375 374
      * @access public
376
-     * @param  string $dataid
377 375
      * @param  string $parentid
378 376
      * @param  string $commentid
379
-     * @return void
377
+     * @param string $pasteid
378
+     * @return boolean
380 379
      */
381 380
     public function existsComment($pasteid, $parentid, $commentid)
382 381
     {
@@ -393,7 +392,7 @@  discard block
 block discarded – undo
393 392
      * @access private
394 393
      * @static
395 394
      * @param  string $sql
396
-     * @param  array $params
395
+     * @param  string[] $params
397 396
      * @throws PDOException
398 397
      * @return array
399 398
      */
@@ -411,7 +410,7 @@  discard block
 block discarded – undo
411 410
      * @access private
412 411
      * @static
413 412
      * @param  string $sql
414
-     * @param  array $params
413
+     * @param  string[] $params
415 414
      * @param  bool $firstOnly if only the first row should be returned
416 415
      * @throws PDOException
417 416
      * @return array
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
                 break;
449 449
             case 'mssql':
450 450
                 $sql = "SELECT name FROM sysobjects "
451
-                     . "WHERE type = 'U' ORDER BY name";
451
+                        . "WHERE type = 'U' ORDER BY name";
452 452
                 break;
453 453
             case 'mysql':
454 454
                 $sql = 'SHOW TABLES';
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
                 break;
459 459
             case 'pgsql':
460 460
                 $sql = "SELECT c.relname AS table_name "
461
-                     . "FROM pg_class c, pg_user u "
462
-                     . "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
463
-                     . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
464
-                     . "AND c.relname !~ '^(pg_|sql_)' "
465
-                     . "UNION "
466
-                     . "SELECT c.relname AS table_name "
467
-                     . "FROM pg_class c "
468
-                     . "WHERE c.relkind = 'r' "
469
-                     . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
470
-                     . "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
471
-                     . "AND c.relname !~ '^pg_'";
461
+                        . "FROM pg_class c, pg_user u "
462
+                        . "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
463
+                        . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
464
+                        . "AND c.relname !~ '^(pg_|sql_)' "
465
+                        . "UNION "
466
+                        . "SELECT c.relname AS table_name "
467
+                        . "FROM pg_class c "
468
+                        . "WHERE c.relkind = 'r' "
469
+                        . "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
470
+                        . "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
471
+                        . "AND c.relname !~ '^pg_'";
472 472
                 break;
473 473
             case 'sqlite':
474 474
                 $sql = "SELECT name FROM sqlite_master WHERE type='table' "
475
-                     . "UNION ALL SELECT name FROM sqlite_temp_master "
476
-                     . "WHERE type='table' ORDER BY name";
475
+                        . "UNION ALL SELECT name FROM sqlite_temp_master "
476
+                        . "WHERE type='table' ORDER BY name";
477 477
                 break;
478 478
             default:
479 479
                 throw new Exception(
Please login to merge, or discard this patch.
Spacing   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     public static function getInstance($options = null)
64 64
     {
65 65
         // if needed initialize the singleton
66
-        if(!(self::$_instance instanceof zerobin_db)) {
66
+        if (!(self::$_instance instanceof zerobin_db)) {
67 67
             self::$_instance = new self;
68 68
         }
69 69
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         if (
153 153
             array_key_exists($pasteid, self::$_cache)
154 154
         ) {
155
-            if(false !== self::$_cache[$pasteid]) {
155
+            if (false !== self::$_cache[$pasteid]) {
156 156
                 return false;
157 157
             } else {
158 158
                 unset(self::$_cache[$pasteid]);
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
                 array($pasteid), true
224 224
             );
225 225
 
226
-            if(false !== $paste) {
226
+            if (false !== $paste) {
227 227
                 // create object
228 228
                 self::$_cache[$pasteid] = new stdClass;
229 229
                 self::$_cache[$pasteid]->data = $paste['data'];
@@ -421,8 +421,7 @@  discard block
 block discarded – undo
421 421
         $statement = self::$_db->prepare($sql);
422 422
         $statement->execute($params);
423 423
         $result = $firstOnly ?
424
-            $statement->fetch(PDO::FETCH_ASSOC) :
425
-            $statement->fetchAll(PDO::FETCH_ASSOC);
424
+            $statement->fetch(PDO::FETCH_ASSOC) : $statement->fetchAll(PDO::FETCH_ASSOC);
426 425
         $statement->closeCursor();
427 426
         return $result;
428 427
     }
@@ -438,7 +437,7 @@  discard block
 block discarded – undo
438 437
      */
439 438
     private static function _getTableQuery($type)
440 439
     {
441
-        switch($type)
440
+        switch ($type)
442 441
         {
443 442
             case 'ibm':
444 443
                 $sql = 'SELECT tabname FROM SYSCAT.TABLES ';
Please login to merge, or discard this patch.
Braces   +33 added lines, -18 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
         if (is_array($options))
71 71
         {
72 72
             // set table prefix if given
73
-            if (array_key_exists('tbl', $options)) self::$_prefix = $options['tbl'];
73
+            if (array_key_exists('tbl', $options)) {
74
+                self::$_prefix = $options['tbl'];
75
+            }
74 76
 
75 77
             // initialize the db connection with new options
76 78
             if (
@@ -121,9 +123,10 @@  discard block
 block discarded – undo
121 123
                 {
122 124
                     self::_createConfigTable();
123 125
                     // if we only needed to create the config table, the DB is older then 0.22
124
-                    if ($db_tables_exist) $db_version = '0.21';
125
-                }
126
-                else
126
+                    if ($db_tables_exist) {
127
+                        $db_version = '0.21';
128
+                    }
129
+                } else
127 130
                 {
128 131
                     $db_version = self::_getConfig('VERSION');
129 132
                 }
@@ -229,7 +232,9 @@  discard block
 block discarded – undo
229 232
                 self::$_cache[$pasteid]->data = $paste['data'];
230 233
 
231 234
                 $meta = json_decode($paste['meta']);
232
-                if (!is_object($meta)) $meta = new stdClass;
235
+                if (!is_object($meta)) {
236
+                    $meta = new stdClass;
237
+                }
233 238
 
234 239
                 // support older attachments
235 240
                 if (property_exists($meta, 'attachment'))
@@ -256,13 +261,19 @@  discard block
 block discarded – undo
256 261
                 $expire_date = (int) $paste['expiredate'];
257 262
                 if (
258 263
                     $expire_date > 0
259
-                ) self::$_cache[$pasteid]->meta->expire_date = $expire_date;
264
+                ) {
265
+                    self::$_cache[$pasteid]->meta->expire_date = $expire_date;
266
+                }
260 267
                 if (
261 268
                     $paste['opendiscussion']
262
-                ) self::$_cache[$pasteid]->meta->opendiscussion = true;
269
+                ) {
270
+                    self::$_cache[$pasteid]->meta->opendiscussion = true;
271
+                }
263 272
                 if (
264 273
                     $paste['burnafterreading']
265
-                ) self::$_cache[$pasteid]->meta->burnafterreading = true;
274
+                ) {
275
+                    self::$_cache[$pasteid]->meta->burnafterreading = true;
276
+                }
266 277
             }
267 278
         }
268 279
 
@@ -288,7 +299,9 @@  discard block
 block discarded – undo
288 299
         );
289 300
         if (
290 301
             array_key_exists($pasteid, self::$_cache)
291
-        ) unset(self::$_cache[$pasteid]);
302
+        ) {
303
+            unset(self::$_cache[$pasteid]);
304
+        }
292 305
     }
293 306
 
294 307
     /**
@@ -302,7 +315,9 @@  discard block
 block discarded – undo
302 315
     {
303 316
         if (
304 317
             !array_key_exists($pasteid, self::$_cache)
305
-        ) self::$_cache[$pasteid] = $this->read($pasteid);
318
+        ) {
319
+            self::$_cache[$pasteid] = $this->read($pasteid);
320
+        }
306 321
         return (bool) self::$_cache[$pasteid];
307 322
     }
308 323
 
@@ -359,10 +374,12 @@  discard block
 block discarded – undo
359 374
                 $comments[$i]->data = $row['data'];
360 375
                 $comments[$i]->meta = new stdClass;
361 376
                 $comments[$i]->meta->postdate = (int) $row['postdate'];
362
-                if (array_key_exists('nickname', $row))
363
-                    $comments[$i]->meta->nickname = $row['nickname'];
364
-                if (array_key_exists('vizhash', $row))
365
-                    $comments[$i]->meta->vizhash = $row['vizhash'];
377
+                if (array_key_exists('nickname', $row)) {
378
+                                    $comments[$i]->meta->nickname = $row['nickname'];
379
+                }
380
+                if (array_key_exists('vizhash', $row)) {
381
+                                    $comments[$i]->meta->vizhash = $row['vizhash'];
382
+                }
366 383
             }
367 384
             ksort($comments);
368 385
         }
@@ -515,8 +532,7 @@  discard block
 block discarded – undo
515 532
         if (self::$_type === 'mysql')
516 533
         {
517 534
             $after_key = ", PRIMARY KEY ($key)";
518
-        }
519
-        else
535
+        } else
520 536
         {
521 537
             $main_key = ' PRIMARY KEY';
522 538
         }
@@ -634,8 +650,7 @@  discard block
 block discarded – undo
634 650
                         'MODIFY COLUMN nickname BLOB, ' .
635 651
                         'MODIFY COLUMN vizhash BLOB;'
636 652
                     );
637
-                }
638
-                else
653
+                } else
639 654
                 {
640 655
                     self::$_db->exec(
641 656
                         'CREATE UNIQUE INDEX primary ON ' . self::$_prefix . 'paste(dataid);'
Please login to merge, or discard this patch.
tst/bootstrap.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
     /**
94 94
      * get example paste
95 95
      *
96
-     * @return array
96
+     * @return string
97 97
      */
98 98
     public static function getPasteAsJson($meta = array())
99 99
     {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-error_reporting( E_ALL | E_STRICT );
2
+error_reporting(E_ALL | E_STRICT);
3 3
 
4 4
 // change this, if your php files and data is outside of your webservers document root
5 5
 if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
     {
155 155
         $path .= DIRECTORY_SEPARATOR;
156 156
         $dir = dir($path);
157
-        while(false !== ($file = $dir->read())) {
158
-            if($file != '.' && $file != '..') {
159
-                if(is_dir($path . $file)) {
157
+        while (false !== ($file = $dir->read())) {
158
+            if ($file != '.' && $file != '..') {
159
+                if (is_dir($path . $file)) {
160 160
                     self::rmdir($path . $file);
161
-                } elseif(is_file($path . $file)) {
162
-                    if(!@unlink($path . $file)) {
161
+                } elseif (is_file($path . $file)) {
162
+                    if (!@unlink($path . $file)) {
163 163
                         throw new Exception('Error deleting file "' . $path . $file . '".');
164 164
                     }
165 165
                 }
166 166
             }
167 167
         }
168 168
         $dir->close();
169
-        if(!@rmdir($path)) {
169
+        if (!@rmdir($path)) {
170 170
             throw new Exception('Error deleting directory "' . $path . '".');
171 171
         }
172 172
     }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             $ini = fopen($pathToFile, 'a');
207 207
             foreach ($values as $section => $options) {
208 208
                 fwrite($ini, "[$section]" . PHP_EOL);
209
-                foreach($options as $option => $setting) {
209
+                foreach ($options as $option => $setting) {
210 210
                     if (is_null($setting)) {
211 211
                         continue;
212 212
                     } elseif (is_string($setting)) {
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -2,10 +2,18 @@  discard block
 block discarded – undo
2 2
 error_reporting( E_ALL | E_STRICT );
3 3
 
4 4
 // change this, if your php files and data is outside of your webservers document root
5
-if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
6
-if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
7
-if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
8
-if (!is_file(CONF)) copy(CONF . '.sample', CONF);
5
+if (!defined('PUBLIC_PATH')) {
6
+    define('PUBLIC_PATH', '..');
7
+}
8
+if (!defined('PATH')) {
9
+    define('PATH', '..' . DIRECTORY_SEPARATOR);
10
+}
11
+if (!defined('CONF')) {
12
+    define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
13
+}
14
+if (!is_file(CONF)) {
15
+    copy(CONF . '.sample', CONF);
16
+}
9 17
 
10 18
 require PATH . 'lib/auto.php';
11 19
 
@@ -100,8 +108,9 @@  discard block
 block discarded – undo
100 108
         $example = self::getPaste();
101 109
         // the JSON shouldn't contain the salt
102 110
         unset($example['meta']['salt']);
103
-        if (count($meta))
104
-            $example['meta'] = $meta;
111
+        if (count($meta)) {
112
+                    $example['meta'] = $meta;
113
+        }
105 114
         $example['comments'] = array();
106 115
         $example['comment_count'] = 0;
107 116
         $example['comment_offset'] = 0;
@@ -178,8 +187,9 @@  discard block
 block discarded – undo
178 187
      */
179 188
     public static function confBackup()
180 189
     {
181
-        if (!is_file(CONF . '.bak') && is_file(CONF))
182
-            rename(CONF, CONF . '.bak');
190
+        if (!is_file(CONF . '.bak') && is_file(CONF)) {
191
+                    rename(CONF, CONF . '.bak');
192
+        }
183 193
     }
184 194
 
185 195
     /**
@@ -189,8 +199,9 @@  discard block
 block discarded – undo
189 199
      */
190 200
     public static function confRestore()
191 201
     {
192
-        if (is_file(CONF . '.bak'))
193
-            rename(CONF . '.bak', CONF);
202
+        if (is_file(CONF . '.bak')) {
203
+                    rename(CONF . '.bak', CONF);
204
+        }
194 205
     }
195 206
 
196 207
     /**
Please login to merge, or discard this patch.
tst/serversalt.php 3 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -40,6 +40,11 @@
 block discarded – undo
40 40
         if (!function_exists('mcrypt_create_iv'))
41 41
         {
42 42
             if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1);
43
+
44
+            /**
45
+             * @param integer $int
46
+             * @param integer $flag
47
+             */
43 48
             function mcrypt_create_iv($int, $flag)
44 49
             {
45 50
                 $randomSalt = '';
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
     {
14 14
         /* Setup Routine */
15 15
         $this->_path = PATH . 'data';
16
-        if(!is_dir($this->_path)) mkdir($this->_path);
16
+        if (!is_dir($this->_path)) mkdir($this->_path);
17 17
         serversalt::setPath($this->_path);
18 18
 
19 19
         $this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo';
20 20
 
21 21
         $this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar';
22
-        if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath);
22
+        if (!is_dir($this->_invalidPath)) mkdir($this->_invalidPath);
23 23
         $this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
24 24
     }
25 25
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
             function mcrypt_create_iv($int, $flag)
44 44
             {
45 45
                 $randomSalt = '';
46
-                for($i = 0; $i < $int; ++$i) {
46
+                for ($i = 0; $i < $int; ++$i) {
47 47
                     $randomSalt .= base_convert(mt_rand(), 10, 16);
48 48
                 }
49 49
                 // hex2bin requires an even length, pad if necessary
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
     {
14 14
         /* Setup Routine */
15 15
         $this->_path = PATH . 'data';
16
-        if(!is_dir($this->_path)) mkdir($this->_path);
16
+        if(!is_dir($this->_path)) {
17
+            mkdir($this->_path);
18
+        }
17 19
         serversalt::setPath($this->_path);
18 20
 
19 21
         $this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo';
20 22
 
21 23
         $this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar';
22
-        if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath);
24
+        if(!is_dir($this->_invalidPath)) {
25
+            mkdir($this->_invalidPath);
26
+        }
23 27
         $this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
24 28
     }
25 29
 
@@ -39,7 +43,9 @@  discard block
 block discarded – undo
39 43
         // mcrypt mock
40 44
         if (!function_exists('mcrypt_create_iv'))
41 45
         {
42
-            if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1);
46
+            if (!defined('MCRYPT_DEV_URANDOM')) {
47
+                define('MCRYPT_DEV_URANDOM', 1);
48
+            }
43 49
             function mcrypt_create_iv($int, $flag)
44 50
             {
45 51
                 $randomSalt = '';
Please login to merge, or discard this patch.