From 580c44ff06a4c1fb495da5a3cde62053d8e6c372 Mon Sep 17 00:00:00 2001 From: mohrt Date: Tue, 27 Nov 2001 22:47:50 +0000 Subject: [PATCH] fixed bugs and added assign attribute to several functions --- NEWS | 6 +++++ Smarty.addons.php | 55 ++++++++++++++++++++++++++++++------------- Smarty.class.php | 6 ++++- docs.sgml | 2 +- libs/Smarty.class.php | 6 ++++- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index efb90524..20d4b8f2 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ + - added assign attribute to insert function (Monte) + - added assign attribute to fetch function (Monte) + - fixed bug with fetch testing for file with http address (Monte) + - added assign attribute to math function (Monte) + - added assign attribute to counter function (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 49221465..5af26f08 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -526,7 +526,7 @@ function smarty_func_html_select_time() Function: smarty_func_math Purpose: allow math computations in template \*======================================================================*/ -function smarty_func_math($args, $smarty_obj) { +function smarty_func_math($args, &$smarty_obj) { // be sure equation parameter is present if (empty($args["equation"])) { $smarty_obj->_trigger_error_msg("math: missing equation parameter"); @@ -554,7 +554,7 @@ function smarty_func_math($args, $smarty_obj) { } foreach($args as $key => $val) { - if ($key != "equation" && $key != "format") { + if ($key != "equation" && $key != "format" && $key != "assign") { // make sure value is not empty if (strlen($val)==0) { $smarty_obj->_trigger_error_msg("math: parameter $key is empty"); @@ -570,10 +570,19 @@ function smarty_func_math($args, $smarty_obj) { eval("\$smarty_math_result = ".$equation.";"); - if (empty($args["format"])) - echo $smarty_math_result; - else - printf($args["format"],$smarty_math_result); + 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)); + } + } } /*======================================================================*\ @@ -600,13 +609,21 @@ 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; + } } - readfile($file); + + if(!empty($assign)) { + ob_start(); + readfile($file); + $smarty_obj->assign($assign,ob_get_contents()); + ob_end_clean(); + } else { + readfile($file); + } } /*======================================================================*\ @@ -660,15 +677,16 @@ function smarty_mod_count_paragraphs($string,$include_spaces=false) { Function: smarty_func_counter Purpose: print out a counter value \*======================================================================*/ -function smarty_func_counter() { +function smarty_func_counter($args, &$smarty_obj) { static $count = array(); static $skipval = array(); static $dir = array(); static $id = "default"; static $printval = array(); + static $assign = ""; - extract(func_get_arg(0)); + extract($args); if (!isset($id)) $id = "default"; @@ -682,15 +700,20 @@ function smarty_func_counter() { $printval[$id]=true; else $printval[$id]=$print; + + 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 (!isset($skipval)) + elseif (empty($skipval[$id])) $skipval[$id] = 1; - + if (isset($direction)) $dir[$id] = $direction; elseif (!isset($dir[$id])) @@ -700,7 +723,7 @@ function smarty_func_counter() { $count[$id] -= $skipval[$id]; else $count[$id] += $skipval[$id]; - + return true; } diff --git a/Smarty.class.php b/Smarty.class.php index 971e235b..0462eb94 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1024,7 +1024,11 @@ function _run_insert_handler($args) 'depth' => $this->_inclusion_depth, 'exec_time' => $this->_get_microtime() - $debug_start_time); } - return $content; + if(!empty($args["assign"])) { + $this->assign($args["assign"],$content); + } else { + return $content; + } } } diff --git a/docs.sgml b/docs.sgml index 8126a67b..14772113 100644 --- a/docs.sgml +++ b/docs.sgml @@ -3149,7 +3149,7 @@ The value of $name is Bob. print boolean No - false + true Whether or not to print the value diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 971e235b..0462eb94 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1024,7 +1024,11 @@ function _run_insert_handler($args) 'depth' => $this->_inclusion_depth, 'exec_time' => $this->_get_microtime() - $debug_start_time); } - return $content; + if(!empty($args["assign"])) { + $this->assign($args["assign"],$content); + } else { + return $content; + } } }