diff --git a/NEWS b/NEWS
index 9d8d395e..6be425da 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,8 @@
- - added custom cache handling function ability (Monte)
- - added assign attribute to insert function, documented (Monte)
- - added assign attribute to fetch function, documented (Monte)
- - fixed bug with fetch testing for local file when http address (Monte)
- - added assign attribute to math function, documented (Monte)
- - added assign attribute to counter function, documented (Monte)
- - fixed bug with counter and skipval setting (Monte)
+ - added custom cache handling function ability. (Monte)
+ - added assign attribute to insert, fetch, math, and counter functions,
+ documented. (Monte)
+ - fixed bug with fetch testing for local file when http address. (Monte)
+ - fixed bug with counter and skipval setting. (Monte)
- made {config_load ...} merge globals from each config file only once per
scope, thus avoiding several problems. (Andrei)
- added {foreach ...} tag that can be used to iterate through
diff --git a/Smarty.addons.php b/Smarty.addons.php
index 5af26f08..ef61fb52 100644
--- a/Smarty.addons.php
+++ b/Smarty.addons.php
@@ -186,7 +186,7 @@ function smarty_mod_default($string, $default="")
\*======================================================================*/
function smarty_func_assign($args, &$smarty_obj)
{
- extract($args);
+ extract($args);
if (empty($var)) {
$smarty_obj->_trigger_error_msg("assign: missing 'var' parameter");
@@ -542,7 +542,7 @@ function smarty_func_math($args, &$smarty_obj) {
}
// match all vars in equation, make sure all are passed
- preg_match_all("![a-zA-Z][a-zA-Z0-9]*!",$equation,$match);
+ preg_match_all("![a-zA-Z][a-zA-Z0-9]*!",$equation, $match);
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
@@ -564,25 +564,25 @@ function smarty_func_math($args, &$smarty_obj) {
$smarty_obj->_trigger_error_msg("math: parameter $key: is not numeric");
return;
}
- $equation = preg_replace("/\b$key\b/",$val,$equation);
+ $equation = preg_replace("/\b$key\b/",$val, $equation);
}
}
eval("\$smarty_math_result = ".$equation.";");
if (empty($args["format"])) {
- if (empty($args["assign"])) {
- echo $smarty_math_result;
- } else {
- $smarty_obj->assign($args["assign"],$smarty_math_result);
- }
- } else {
- if (empty($args["assign"])){
- printf($args["format"],$smarty_math_result);
- } else {
- $smarty_obj->assign($assign,sprintf($args["format"],$smarty_math_result));
- }
- }
+ if (empty($args["assign"])) {
+ echo $smarty_math_result;
+ } else {
+ $smarty_obj->assign($args["assign"],$smarty_math_result);
+ }
+ } else {
+ if (empty($args["assign"])){
+ printf($args["format"],$smarty_math_result);
+ } else {
+ $smarty_obj->assign($assign,sprintf($args["format"],$smarty_math_result));
+ }
+ }
}
/*======================================================================*\
@@ -609,33 +609,33 @@ function smarty_func_fetch($args, &$smarty_obj) {
$smarty_obj->_trigger_error_msg("(secure mode) fetch '$file' is not allowed");
return;
}
- if (!@is_readable($file)) {
- $smarty_obj->_trigger_error_msg("fetch cannot read file '$file'");
- return;
- }
+ if (!@is_readable($file)) {
+ $smarty_obj->_trigger_error_msg("fetch cannot read file '$file'");
+ return;
+ }
}
- if(!empty($assign)) {
- ob_start();
- readfile($file);
- $smarty_obj->assign($assign,ob_get_contents());
- ob_end_clean();
- } else {
- readfile($file);
- }
+ if (!empty($assign)) {
+ ob_start();
+ readfile($file);
+ $smarty_obj->assign($assign,ob_get_contents());
+ ob_end_clean();
+ } else {
+ readfile($file);
+ }
}
/*======================================================================*\
Function: smarty_mod_count_characters
Purpose: count the number of characters in a text
\*======================================================================*/
-function smarty_mod_count_characters($string,$include_spaces=false) {
+function smarty_mod_count_characters($string, $include_spaces=false) {
if ($include_spaces)
return(strlen($string));
- return preg_match_all("/[^\s]/",$string,$match);
+ return preg_match_all("/[^\s]/",$string, $match);
}
/*======================================================================*\
@@ -656,10 +656,10 @@ function smarty_mod_count_words($string) {
Function: smarty_mod_count_sentences
Purpose: count the number of sentences in a text
\*======================================================================*/
-function smarty_mod_count_sentences($string,$include_spaces=false) {
+function smarty_mod_count_sentences($string, $include_spaces=false) {
// find periods with a word before but not after.
- return preg_match_all("/[^\s]\.(?!\w)/",$string,$match);
+ return preg_match_all("/[^\s]\.(?!\w)/",$string, $match);
}
@@ -667,7 +667,7 @@ function smarty_mod_count_sentences($string,$include_spaces=false) {
Function: smarty_mod_count_paragraphs
Purpose: count the number of sentences in a text
\*======================================================================*/
-function smarty_mod_count_paragraphs($string,$include_spaces=false) {
+function smarty_mod_count_paragraphs($string, $include_spaces=false) {
// count \r or \n characters
return count( preg_split("/[\r\n]+/",$string) );
@@ -684,7 +684,7 @@ function smarty_func_counter($args, &$smarty_obj) {
static $dir = array();
static $id = "default";
static $printval = array();
- static $assign = "";
+ static $assign = "";
extract($args);
@@ -693,37 +693,37 @@ function smarty_func_counter($args, &$smarty_obj) {
if (isset($start))
$count[$id] = $start;
- elseif (!isset($count[$id]))
+ else if (!isset($count[$id]))
$count[$id]=1;
if (!isset($print))
$printval[$id]=true;
else
$printval[$id]=$print;
-
- if(!empty($assign)) {
- $printval[$id] = false;
- $smarty_obj->assign($assign,$count[$id]);
- }
+
+ if (!empty($assign)) {
+ $printval[$id] = false;
+ $smarty_obj->assign($assign, $count[$id]);
+ }
if ($printval[$id])
echo $count[$id];
if (isset($skip))
$skipval[$id] = $skip;
- elseif (empty($skipval[$id]))
+ else if (empty($skipval[$id]))
$skipval[$id] = 1;
-
+
if (isset($direction))
$dir[$id] = $direction;
- elseif (!isset($dir[$id]))
+ else if (!isset($dir[$id]))
$dir[$id] = "up";
if ($dir[$id] == "down")
$count[$id] -= $skipval[$id];
else
$count[$id] += $skipval[$id];
-
+
return true;
}
@@ -732,22 +732,22 @@ function smarty_func_counter($args, &$smarty_obj) {
Purpose: assign debug info to the template
\*======================================================================*/
function smarty_func_assign_debug_info($args, &$smarty_obj) {
- $assigned_vars = $smarty_obj->_tpl_vars;
- ksort($assigned_vars);
- if (is_array($smarty_obj->_config[0])) {
- $config_vars = $smarty_obj->_config[0];
- ksort($config_vars);
- $smarty_obj->assign("_debug_config_keys", array_keys($config_vars));
- $smarty_obj->assign("_debug_config_vals", array_values($config_vars));
- }
-
- $included_templates = $smarty_obj->_smarty_debug_info;
-
- $smarty_obj->assign("_debug_keys", array_keys($assigned_vars));
- $smarty_obj->assign("_debug_vals", array_values($assigned_vars));
-
- $smarty_obj->assign("_debug_tpls", $included_templates);
- return true;
+ $assigned_vars = $smarty_obj->_tpl_vars;
+ ksort($assigned_vars);
+ if (is_array($smarty_obj->_config[0])) {
+ $config_vars = $smarty_obj->_config[0];
+ ksort($config_vars);
+ $smarty_obj->assign("_debug_config_keys", array_keys($config_vars));
+ $smarty_obj->assign("_debug_config_vals", array_values($config_vars));
+ }
+
+ $included_templates = $smarty_obj->_smarty_debug_info;
+
+ $smarty_obj->assign("_debug_keys", array_keys($assigned_vars));
+ $smarty_obj->assign("_debug_vals", array_values($assigned_vars));
+
+ $smarty_obj->assign("_debug_tpls", $included_templates);
+ return true;
}
/*======================================================================*\
@@ -755,26 +755,26 @@ function smarty_func_assign_debug_info($args, &$smarty_obj) {
Purpose: prints variable (or array) contents to the console
\*======================================================================*/
function smarty_mod_debug_print_var($var, $depth=0, $length=40) {
- if (is_array($var)) {
- $results = "Array (".count($var).")";
- foreach ($var as $curr_key => $curr_val) {
- $return = smarty_mod_debug_print_var($curr_val, $depth+1);
- $results .= '
\r'.str_repeat(' ', $depth*2)."$curr_key => $return";
- }
- return $results;
- } else {
- if (empty($var)) {
- return 'empty';
- }
- if (strlen($var) > $length ) {
- $results = substr($var, 0, $length-3).'...';
- } else {
- $results = $var;
- }
- $results = preg_replace("![\r\t\n]!", " ", $results);
- $results = htmlspecialchars(htmlspecialchars($results));
- return $results;
- }
+ if (is_array($var)) {
+ $results = "Array (".count($var).")";
+ foreach ($var as $curr_key => $curr_val) {
+ $return = smarty_mod_debug_print_var($curr_val, $depth+1);
+ $results .= '
\r'.str_repeat(' ', $depth*2)."$curr_key => $return";
+ }
+ return $results;
+ } else {
+ if (empty($var)) {
+ return 'empty';
+ }
+ if (strlen($var) > $length ) {
+ $results = substr($var, 0, $length-3).'...';
+ } else {
+ $results = $var;
+ }
+ $results = preg_replace("![\r\t\n]!", " ", $results);
+ $results = htmlspecialchars(htmlspecialchars($results));
+ return $results;
+ }
}
diff --git a/Smarty.class.php b/Smarty.class.php
index 0d7a88b6..9cf30eff 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -504,7 +504,7 @@ class Smarty
&& (!empty($QUERY_STRING) && strstr($QUERY_STRING, $this->_smarty_debug_id))) {
$this->debugging = true;
}
-
+
if ($this->debugging) {
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
@@ -1024,11 +1024,11 @@ function _run_insert_handler($args)
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
- if(!empty($args["assign"])) {
- $this->assign($args["assign"],$content);
- } else {
- return $content;
- }
+ if (!empty($args["assign"])) {
+ $this->assign($args["assign"],$content);
+ } else {
+ return $content;
+ }
}
}
@@ -1249,7 +1249,7 @@ function _run_insert_handler($args)
if (!empty($this->cache_handler_func)) {
// use cache_write_handler function
return $$this->cache_handler_func('write', $tpl_file, $cache_id, $compile_id, $results, $this);
- } else {
+ } else {
// use local cache file
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
$this->_write_file($cache_file, $results, true);
@@ -1268,7 +1268,7 @@ function _run_insert_handler($args)
// force compile enabled or cache lifetime is zero, always regenerate
return false;
}
-
+
if (!empty($this->cache_handler_func)) {
// use cache_read_handler function
@@ -1276,15 +1276,15 @@ function _run_insert_handler($args)
} else {
// use local file cache
-
+
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
$results = $this->_read_file($cache_file);
-
+
}
$cache_split = explode("\n",$results,2);
$cache_header = $cache_split[0];
-
+
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($cache_header, 24));
@@ -1294,7 +1294,7 @@ function _run_insert_handler($args)
// cache expired, regenerate
return false;
}
-
+
if ($this->compile_check) {
foreach ($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 0d7a88b6..9cf30eff 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -504,7 +504,7 @@ class Smarty
&& (!empty($QUERY_STRING) && strstr($QUERY_STRING, $this->_smarty_debug_id))) {
$this->debugging = true;
}
-
+
if ($this->debugging) {
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
@@ -1024,11 +1024,11 @@ function _run_insert_handler($args)
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
- if(!empty($args["assign"])) {
- $this->assign($args["assign"],$content);
- } else {
- return $content;
- }
+ if (!empty($args["assign"])) {
+ $this->assign($args["assign"],$content);
+ } else {
+ return $content;
+ }
}
}
@@ -1249,7 +1249,7 @@ function _run_insert_handler($args)
if (!empty($this->cache_handler_func)) {
// use cache_write_handler function
return $$this->cache_handler_func('write', $tpl_file, $cache_id, $compile_id, $results, $this);
- } else {
+ } else {
// use local cache file
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
$this->_write_file($cache_file, $results, true);
@@ -1268,7 +1268,7 @@ function _run_insert_handler($args)
// force compile enabled or cache lifetime is zero, always regenerate
return false;
}
-
+
if (!empty($this->cache_handler_func)) {
// use cache_read_handler function
@@ -1276,15 +1276,15 @@ function _run_insert_handler($args)
} else {
// use local file cache
-
+
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
$results = $this->_read_file($cache_file);
-
+
}
$cache_split = explode("\n",$results,2);
$cache_header = $cache_split[0];
-
+
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($cache_header, 24));
@@ -1294,7 +1294,7 @@ function _run_insert_handler($args)
// cache expired, regenerate
return false;
}
-
+
if ($this->compile_check) {
foreach ($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {