Refactoring of code base - modularized code, introduced configuration, started working on a PDO based DB connector
This commit is contained in:
@@ -21,7 +21,7 @@ class RainTPL{
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $tpl_dir = "tpl/";
|
||||
static $tpl_dir = 'tpl/';
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ class RainTPL{
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $cache_dir = "tmp/";
|
||||
static $cache_dir = 'tmp/';
|
||||
|
||||
|
||||
/**
|
||||
@@ -81,10 +81,10 @@ class RainTPL{
|
||||
*
|
||||
*/
|
||||
static $check_template_update = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PHP tags <? ?>
|
||||
* PHP tags <? ?>
|
||||
* True: php tags are enabled into the template
|
||||
* False: php tags are disabled into the template and rendered as html
|
||||
*
|
||||
@@ -92,7 +92,7 @@ class RainTPL{
|
||||
*/
|
||||
static $php_enabled = false;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Debug mode flag.
|
||||
* True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated.
|
||||
@@ -257,9 +257,9 @@ class RainTPL{
|
||||
|
||||
$tpl_basename = basename( $tpl_name ); // template basename
|
||||
$tpl_basedir = strpos($tpl_name,"/") ? dirname($tpl_name) . '/' : null; // template basedirectory
|
||||
$tpl_dir = self::$tpl_dir . $tpl_basedir; // template directory
|
||||
$tpl_dir = PATH . self::$tpl_dir . $tpl_basedir; // template directory
|
||||
$this->tpl['tpl_filename'] = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext; // template filename
|
||||
$temp_compiled_filename = self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . serialize(self::$config_name_sum));
|
||||
$temp_compiled_filename = PATH . self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . serialize(self::$config_name_sum));
|
||||
$this->tpl['compiled_filename'] = $temp_compiled_filename . '.rtpl.php'; // cache filename
|
||||
$this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.rtpl.php'; // static cache filename
|
||||
|
||||
@@ -271,7 +271,7 @@ class RainTPL{
|
||||
|
||||
// file doesn't exsist, or the template was updated, Rain will compile the template
|
||||
if( !file_exists( $this->tpl['compiled_filename'] ) || ( self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime( $this->tpl['tpl_filename'] ) ) ){
|
||||
$this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], self::$cache_dir, $this->tpl['compiled_filename'] );
|
||||
$this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], PATH . self::$cache_dir, $this->tpl['compiled_filename'] );
|
||||
return true;
|
||||
}
|
||||
$this->tpl['checked'] = true;
|
||||
@@ -285,7 +285,7 @@ class RainTPL{
|
||||
*/
|
||||
protected function xml_reSubstitution($capture) {
|
||||
return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and write the compiled template file
|
||||
@@ -304,11 +304,11 @@ class RainTPL{
|
||||
$template_code = str_replace( array("<?","?>"), array("<?","?>"), $template_code );
|
||||
|
||||
//xml re-substitution
|
||||
$template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
|
||||
$template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code );
|
||||
|
||||
//compile template
|
||||
$template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir );
|
||||
|
||||
|
||||
|
||||
// fix the php-eating-newline-after-closing-tag-problem
|
||||
$template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled );
|
||||
@@ -413,7 +413,7 @@ class RainTPL{
|
||||
|
||||
// if the cache is active
|
||||
if( isset($code[ 2 ]) ){
|
||||
|
||||
|
||||
//dynamic include
|
||||
$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
|
||||
'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' .
|
||||
@@ -426,7 +426,7 @@ class RainTPL{
|
||||
'} ?>';
|
||||
}
|
||||
else{
|
||||
|
||||
|
||||
//dynamic include
|
||||
$compiled_code .= '<?php $tpl = new '.get_class($this).';' .
|
||||
'$tpl_dir_temp = self::$tpl_dir;' .
|
||||
@@ -434,8 +434,8 @@ class RainTPL{
|
||||
( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ).
|
||||
'$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'.
|
||||
'?>';
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -548,7 +548,7 @@ class RainTPL{
|
||||
else
|
||||
// parse the function
|
||||
$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 );
|
||||
|
||||
|
||||
//if code
|
||||
$compiled_code .= "<?php echo $parsed_function; ?>";
|
||||
}
|
||||
@@ -582,8 +582,8 @@ class RainTPL{
|
||||
}
|
||||
return $compiled_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reduce a path, eg. www/library/../filepath//file => www/filepath/file
|
||||
* @param type $path
|
||||
@@ -611,8 +611,8 @@ class RainTPL{
|
||||
|
||||
if( self::$path_replace ){
|
||||
|
||||
$tpl_dir = self::$base_url . self::$tpl_dir . $tpl_basedir;
|
||||
|
||||
$tpl_dir = self::$base_url . PATH . self::$tpl_dir . $tpl_basedir;
|
||||
|
||||
// reduce the path
|
||||
$path = $this->reduce_path($tpl_dir);
|
||||
|
||||
@@ -683,7 +683,7 @@ class RainTPL{
|
||||
$this->function_check( $tag );
|
||||
|
||||
$extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level );
|
||||
|
||||
|
||||
|
||||
// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
|
||||
$is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var );
|
||||
@@ -712,7 +712,7 @@ class RainTPL{
|
||||
|
||||
//if there's a function
|
||||
if( $function_var ){
|
||||
|
||||
|
||||
// check if there's a function or a static method and separate, function by parameters
|
||||
$function_var = str_replace("::", "@double_dot@", $function_var );
|
||||
|
||||
@@ -786,7 +786,7 @@ class RainTPL{
|
||||
|
||||
// check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value
|
||||
$is_init_variable = preg_match( "/^[a-z_A-Z\.\[\](\-\>)]*=[^=]*$/", $extra_var );
|
||||
|
||||
|
||||
//function associate to variable
|
||||
$function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null;
|
||||
|
||||
@@ -805,16 +805,16 @@ class RainTPL{
|
||||
|
||||
//transform .$variable in ["$variable"] and .variable in ["variable"]
|
||||
$variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path );
|
||||
|
||||
|
||||
// if is an assignment also assign the variable to $this->var['value']
|
||||
if( $is_init_variable )
|
||||
$extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var;
|
||||
|
||||
|
||||
|
||||
|
||||
//if there's a function
|
||||
if( $function_var ){
|
||||
|
||||
|
||||
// check if there's a function or a static method and separate, function by parameters
|
||||
$function_var = str_replace("::", "@double_dot@", $function_var );
|
||||
|
||||
@@ -855,13 +855,13 @@ class RainTPL{
|
||||
$php_var = '$' . $var_name . $variable_path;
|
||||
}else
|
||||
$php_var = '$' . $var_name . $variable_path;
|
||||
|
||||
|
||||
// compile the variable for php
|
||||
if( isset( $function ) )
|
||||
$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter;
|
||||
else
|
||||
$php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter;
|
||||
|
||||
|
||||
$html = str_replace( $tag, $php_var, $html );
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user