Completed
Push — master ( 5586cb...ad9fdf )
by El
09:08
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 ([email protected](self::$_path))
84
+        if (!is_dir(self::$_path)) {
85
+                    if ([email protected](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