diff --git a/Smarty.class.php b/Smarty.class.php index af6ea1b4..c87109f6 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -60,8 +60,7 @@ class Smarty var $compile_dir = './templates_c'; // name of directory for compiled templates var $config_dir = './configs'; // directory where config files are located - var $global_assign = array( 'HTTP_SERVER_VARS' => - array( 'SCRIPT_NAME' ) + var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) ); // variables from the GLOBALS array // that are implicitly assigned // to all templates @@ -136,7 +135,7 @@ class Smarty var $compiler_class = 'Smarty_Compiler'; // the compiler class used by // Smarty to compile templates var $resource_funcs = array(); // what functions resource handlers are mapped to - var $prefilter_funcs = array(); // what functions templates are prefiltered through + var $prefilter_funcs = array(); // what functions templates are prefiltered through // before being compiled /**************************************************************************/ @@ -149,6 +148,7 @@ class Smarty var $_tpl_vars = array(); // where assigned template vars are kept var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + /*======================================================================*\ Function: Smarty Purpose: Constructor @@ -411,26 +411,27 @@ class Smarty Function: clear_compile_dir() Purpose: clears compiled version of specified template resource, or all compiled template files if one is not specified. - This function is for advanced use only, not normally needed. + This function is for advanced use only, not normally needed. \*======================================================================*/ - function clear_compile_dir($tpl_file=null) + function clear_compile_dir($tpl_file = null) { if (!is_dir($this->compile_dir)) return false; - if($tpl_file) { + if (isset($tpl_file)) { // remove compiled template file if it exists $tpl_file = urlencode($tpl_file).'.php'; - if(file_exists($this->compile_dir.'/'.$tpl_file)) { - unlink($this->compile_dir.'/'.$tpl_file); + if (file_exists($this->compile_dir.'/'.$tpl_file)) { + unlink($this->compile_dir.'/'.$tpl_file); } } else { // remove everything in $compile_dir $dir_handle = opendir($this->compile_dir); while ($curr_file = readdir($dir_handle)) { if ($curr_file == '.' || $curr_dir == '..' || - !is_file($this->compile_dir.'/'.$curr_file)) - { continue; } + !is_file($this->compile_dir.'/'.$curr_file)) { + continue; + } unlink($this->compile_dir.'/'.$curr_file); } closedir($dir_handle); @@ -609,7 +610,6 @@ class Smarty \*======================================================================*/ function _fetch_template_source($tpl_path, &$template_source, &$template_timestamp) { - // split tpl_path by the first colon $tpl_path_parts = explode(':', $tpl_path, 2); @@ -637,16 +637,17 @@ class Smarty return false; } break; + default: - if(isset($this->resource_funcs[$resource_type])) { + if (isset($this->resource_funcs[$resource_type])) { $funcname = $this->resource_funcs[$resource_type]; - if(function_exists($funcname)) { + if (function_exists($funcname)) { // call the function to fetch the template - $funcname($resource_name,$template_source,$template_timestamp); + $funcname($resource_name, $template_source, $template_timestamp); return true; } else { - $this->_trigger_error_msg("function: \"$funcname\" does not exist for resource type: \"$resource_type\"."); - return false; + $this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\"."); + return false; } } else { $this->_trigger_error_msg("unknown resource type: \"$resource_type\". Register this resource first."); diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 6fac6942..d4fa68db 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -56,12 +56,12 @@ class Smarty_Compiler extends Smarty { { // run template source through functions registered in prefilter_funcs - if(is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) { - foreach($this->prefilter_funcs as $curr_func) { - if(function_exists($curr_func)) { - $template_source = $curr_func($template_source); + if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) { + foreach($this->prefilter_funcs as $prefilter) { + if (function_exists($prefilter)) { + $template_source = $prefilter($template_source); } else { - $this->_trigger_error_msg("prefilter function $curr_func does not exist."); + $this->_trigger_error_msg("prefilter function $prefilter does not exist."); } } } @@ -89,8 +89,6 @@ class Smarty_Compiler extends Smarty { /* Split content by template tags to obtain non-template content. */ $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); - /* TODO: speed up the following with preg_replace and /F once we require that version of PHP */ - /* loop through text blocks */ for ($curr_tb = 0; $curr_tb < count($text_blocks); $curr_tb++) { /* match anything within */ diff --git a/docs.sgml b/docs.sgml index 2fa4af06..bbd206ab 100644 --- a/docs.sgml +++ b/docs.sgml @@ -292,8 +292,12 @@ chmod 700 cache This is a list of variables that are always implicitly assigned to the template engine. This is handy for making global variables or server variables available to all templates - without having to manually assign them. $SCRIPT_NAME is - globally assigned by default. + without having to manually assign them. Each element in the + $global_assign should be either a name of the global variable, + or a key/value pair, where the key is the name of the global + array and the value is the array of variables to be assigned + from that global array. $SCRIPT_NAME is globally assigned by + default from $HTTP_SERVER_VARS. diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index af6ea1b4..c87109f6 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -60,8 +60,7 @@ class Smarty var $compile_dir = './templates_c'; // name of directory for compiled templates var $config_dir = './configs'; // directory where config files are located - var $global_assign = array( 'HTTP_SERVER_VARS' => - array( 'SCRIPT_NAME' ) + var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) ); // variables from the GLOBALS array // that are implicitly assigned // to all templates @@ -136,7 +135,7 @@ class Smarty var $compiler_class = 'Smarty_Compiler'; // the compiler class used by // Smarty to compile templates var $resource_funcs = array(); // what functions resource handlers are mapped to - var $prefilter_funcs = array(); // what functions templates are prefiltered through + var $prefilter_funcs = array(); // what functions templates are prefiltered through // before being compiled /**************************************************************************/ @@ -149,6 +148,7 @@ class Smarty var $_tpl_vars = array(); // where assigned template vars are kept var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + /*======================================================================*\ Function: Smarty Purpose: Constructor @@ -411,26 +411,27 @@ class Smarty Function: clear_compile_dir() Purpose: clears compiled version of specified template resource, or all compiled template files if one is not specified. - This function is for advanced use only, not normally needed. + This function is for advanced use only, not normally needed. \*======================================================================*/ - function clear_compile_dir($tpl_file=null) + function clear_compile_dir($tpl_file = null) { if (!is_dir($this->compile_dir)) return false; - if($tpl_file) { + if (isset($tpl_file)) { // remove compiled template file if it exists $tpl_file = urlencode($tpl_file).'.php'; - if(file_exists($this->compile_dir.'/'.$tpl_file)) { - unlink($this->compile_dir.'/'.$tpl_file); + if (file_exists($this->compile_dir.'/'.$tpl_file)) { + unlink($this->compile_dir.'/'.$tpl_file); } } else { // remove everything in $compile_dir $dir_handle = opendir($this->compile_dir); while ($curr_file = readdir($dir_handle)) { if ($curr_file == '.' || $curr_dir == '..' || - !is_file($this->compile_dir.'/'.$curr_file)) - { continue; } + !is_file($this->compile_dir.'/'.$curr_file)) { + continue; + } unlink($this->compile_dir.'/'.$curr_file); } closedir($dir_handle); @@ -609,7 +610,6 @@ class Smarty \*======================================================================*/ function _fetch_template_source($tpl_path, &$template_source, &$template_timestamp) { - // split tpl_path by the first colon $tpl_path_parts = explode(':', $tpl_path, 2); @@ -637,16 +637,17 @@ class Smarty return false; } break; + default: - if(isset($this->resource_funcs[$resource_type])) { + if (isset($this->resource_funcs[$resource_type])) { $funcname = $this->resource_funcs[$resource_type]; - if(function_exists($funcname)) { + if (function_exists($funcname)) { // call the function to fetch the template - $funcname($resource_name,$template_source,$template_timestamp); + $funcname($resource_name, $template_source, $template_timestamp); return true; } else { - $this->_trigger_error_msg("function: \"$funcname\" does not exist for resource type: \"$resource_type\"."); - return false; + $this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\"."); + return false; } } else { $this->_trigger_error_msg("unknown resource type: \"$resource_type\". Register this resource first."); diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 6fac6942..d4fa68db 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -56,12 +56,12 @@ class Smarty_Compiler extends Smarty { { // run template source through functions registered in prefilter_funcs - if(is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) { - foreach($this->prefilter_funcs as $curr_func) { - if(function_exists($curr_func)) { - $template_source = $curr_func($template_source); + if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) { + foreach($this->prefilter_funcs as $prefilter) { + if (function_exists($prefilter)) { + $template_source = $prefilter($template_source); } else { - $this->_trigger_error_msg("prefilter function $curr_func does not exist."); + $this->_trigger_error_msg("prefilter function $prefilter does not exist."); } } } @@ -89,8 +89,6 @@ class Smarty_Compiler extends Smarty { /* Split content by template tags to obtain non-template content. */ $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); - /* TODO: speed up the following with preg_replace and /F once we require that version of PHP */ - /* loop through text blocks */ for ($curr_tb = 0; $curr_tb < count($text_blocks); $curr_tb++) { /* match anything within */