diff options
Diffstat (limited to 'inc/rain.tpl.class.php')
-rw-r--r-- | inc/rain.tpl.class.php | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/inc/rain.tpl.class.php b/inc/rain.tpl.class.php index ea83b2c1..6522c798 100644 --- a/inc/rain.tpl.class.php +++ b/inc/rain.tpl.class.php | |||
@@ -81,18 +81,18 @@ class RainTPL{ | |||
81 | * | 81 | * |
82 | */ | 82 | */ |
83 | static $check_template_update = true; | 83 | static $check_template_update = true; |
84 | 84 | ||
85 | 85 | ||
86 | /** | 86 | /** |
87 | * PHP tags <? ?> | 87 | * PHP tags <? ?> |
88 | * True: php tags are enabled into the template | 88 | * True: php tags are enabled into the template |
89 | * False: php tags are disabled into the template and rendered as html | 89 | * False: php tags are disabled into the template and rendered as html |
90 | * | 90 | * |
91 | * @var bool | 91 | * @var bool |
92 | */ | 92 | */ |
93 | static $php_enabled = false; | 93 | static $php_enabled = true; |
94 | |||
94 | 95 | ||
95 | |||
96 | /** | 96 | /** |
97 | * Debug mode flag. | 97 | * Debug mode flag. |
98 | * True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated. | 98 | * True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated. |
@@ -285,7 +285,7 @@ class RainTPL{ | |||
285 | */ | 285 | */ |
286 | protected function xml_reSubstitution($capture) { | 286 | protected function xml_reSubstitution($capture) { |
287 | return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>"; | 287 | return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>"; |
288 | } | 288 | } |
289 | 289 | ||
290 | /** | 290 | /** |
291 | * Compile and write the compiled template file | 291 | * Compile and write the compiled template file |
@@ -304,11 +304,11 @@ class RainTPL{ | |||
304 | $template_code = str_replace( array("<?","?>"), array("<?","?>"), $template_code ); | 304 | $template_code = str_replace( array("<?","?>"), array("<?","?>"), $template_code ); |
305 | 305 | ||
306 | //xml re-substitution | 306 | //xml re-substitution |
307 | $template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code ); | 307 | $template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code ); |
308 | 308 | ||
309 | //compile template | 309 | //compile template |
310 | $template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir ); | 310 | $template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir ); |
311 | 311 | ||
312 | 312 | ||
313 | // fix the php-eating-newline-after-closing-tag-problem | 313 | // fix the php-eating-newline-after-closing-tag-problem |
314 | $template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled ); | 314 | $template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled ); |
@@ -413,7 +413,7 @@ class RainTPL{ | |||
413 | 413 | ||
414 | // if the cache is active | 414 | // if the cache is active |
415 | if( isset($code[ 2 ]) ){ | 415 | if( isset($code[ 2 ]) ){ |
416 | 416 | ||
417 | //dynamic include | 417 | //dynamic include |
418 | $compiled_code .= '<?php $tpl = new '.get_class($this).';' . | 418 | $compiled_code .= '<?php $tpl = new '.get_class($this).';' . |
419 | 'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' . | 419 | 'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' . |
@@ -426,7 +426,7 @@ class RainTPL{ | |||
426 | '} ?>'; | 426 | '} ?>'; |
427 | } | 427 | } |
428 | else{ | 428 | else{ |
429 | 429 | ||
430 | //dynamic include | 430 | //dynamic include |
431 | $compiled_code .= '<?php $tpl = new '.get_class($this).';' . | 431 | $compiled_code .= '<?php $tpl = new '.get_class($this).';' . |
432 | '$tpl_dir_temp = self::$tpl_dir;' . | 432 | '$tpl_dir_temp = self::$tpl_dir;' . |
@@ -434,8 +434,8 @@ class RainTPL{ | |||
434 | ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ). | 434 | ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ). |
435 | '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'. | 435 | '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'. |
436 | '?>'; | 436 | '?>'; |
437 | 437 | ||
438 | 438 | ||
439 | } | 439 | } |
440 | 440 | ||
441 | } | 441 | } |
@@ -548,7 +548,7 @@ class RainTPL{ | |||
548 | else | 548 | else |
549 | // parse the function | 549 | // parse the function |
550 | $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 ); | 550 | $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 ); |
551 | 551 | ||
552 | //if code | 552 | //if code |
553 | $compiled_code .= "<?php echo $parsed_function; ?>"; | 553 | $compiled_code .= "<?php echo $parsed_function; ?>"; |
554 | } | 554 | } |
@@ -582,8 +582,8 @@ class RainTPL{ | |||
582 | } | 582 | } |
583 | return $compiled_code; | 583 | return $compiled_code; |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | /** | 587 | /** |
588 | * Reduce a path, eg. www/library/../filepath//file => www/filepath/file | 588 | * Reduce a path, eg. www/library/../filepath//file => www/filepath/file |
589 | * @param type $path | 589 | * @param type $path |
@@ -612,7 +612,7 @@ class RainTPL{ | |||
612 | if( self::$path_replace ){ | 612 | if( self::$path_replace ){ |
613 | 613 | ||
614 | $tpl_dir = self::$base_url . self::$tpl_dir . $tpl_basedir; | 614 | $tpl_dir = self::$base_url . self::$tpl_dir . $tpl_basedir; |
615 | 615 | ||
616 | // reduce the path | 616 | // reduce the path |
617 | $path = $this->reduce_path($tpl_dir); | 617 | $path = $this->reduce_path($tpl_dir); |
618 | 618 | ||
@@ -683,7 +683,7 @@ class RainTPL{ | |||
683 | $this->function_check( $tag ); | 683 | $this->function_check( $tag ); |
684 | 684 | ||
685 | $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level ); | 685 | $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level ); |
686 | 686 | ||
687 | 687 | ||
688 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value | 688 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value |
689 | $is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var ); | 689 | $is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var ); |
@@ -712,7 +712,7 @@ class RainTPL{ | |||
712 | 712 | ||
713 | //if there's a function | 713 | //if there's a function |
714 | if( $function_var ){ | 714 | if( $function_var ){ |
715 | 715 | ||
716 | // check if there's a function or a static method and separate, function by parameters | 716 | // check if there's a function or a static method and separate, function by parameters |
717 | $function_var = str_replace("::", "@double_dot@", $function_var ); | 717 | $function_var = str_replace("::", "@double_dot@", $function_var ); |
718 | 718 | ||
@@ -786,7 +786,7 @@ class RainTPL{ | |||
786 | 786 | ||
787 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value | 787 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value |
788 | $is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var ); | 788 | $is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var ); |
789 | 789 | ||
790 | //function associate to variable | 790 | //function associate to variable |
791 | $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null; | 791 | $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null; |
792 | 792 | ||
@@ -805,16 +805,16 @@ class RainTPL{ | |||
805 | 805 | ||
806 | //transform .$variable in ["$variable"] and .variable in ["variable"] | 806 | //transform .$variable in ["$variable"] and .variable in ["variable"] |
807 | $variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path ); | 807 | $variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path ); |
808 | 808 | ||
809 | // if is an assignment also assign the variable to $this->var['value'] | 809 | // if is an assignment also assign the variable to $this->var['value'] |
810 | if( $is_init_variable ) | 810 | if( $is_init_variable ) |
811 | $extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var; | 811 | $extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var; |
812 | 812 | ||
813 | 813 | ||
814 | 814 | ||
815 | //if there's a function | 815 | //if there's a function |
816 | if( $function_var ){ | 816 | if( $function_var ){ |
817 | 817 | ||
818 | // check if there's a function or a static method and separate, function by parameters | 818 | // check if there's a function or a static method and separate, function by parameters |
819 | $function_var = str_replace("::", "@double_dot@", $function_var ); | 819 | $function_var = str_replace("::", "@double_dot@", $function_var ); |
820 | 820 | ||
@@ -855,13 +855,13 @@ class RainTPL{ | |||
855 | $php_var = '$' . $var_name . $variable_path; | 855 | $php_var = '$' . $var_name . $variable_path; |
856 | }else | 856 | }else |
857 | $php_var = '$' . $var_name . $variable_path; | 857 | $php_var = '$' . $var_name . $variable_path; |
858 | 858 | ||
859 | // compile the variable for php | 859 | // compile the variable for php |
860 | if( isset( $function ) ) | 860 | if( isset( $function ) ) |
861 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter; | 861 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter; |
862 | else | 862 | else |
863 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter; | 863 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter; |
864 | 864 | ||
865 | $html = str_replace( $tag, $php_var, $html ); | 865 | $html = str_replace( $tag, $php_var, $html ); |
866 | 866 | ||
867 | 867 | ||