fixed bugs and added assign attribute to several functions

This commit is contained in:
mohrt
2001-11-27 22:47:50 +00:00
parent f88a78231c
commit 580c44ff06
5 changed files with 56 additions and 19 deletions

6
NEWS
View File

@@ -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 - made {config_load ...} merge globals from each config file only once per
scope, thus avoiding several problems. (Andrei) scope, thus avoiding several problems. (Andrei)
- added {foreach ...} tag that can be used to iterate through - added {foreach ...} tag that can be used to iterate through

View File

@@ -526,7 +526,7 @@ function smarty_func_html_select_time()
Function: smarty_func_math Function: smarty_func_math
Purpose: allow math computations in template 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 // be sure equation parameter is present
if (empty($args["equation"])) { if (empty($args["equation"])) {
$smarty_obj->_trigger_error_msg("math: missing equation parameter"); $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) { foreach($args as $key => $val) {
if ($key != "equation" && $key != "format") { if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty // make sure value is not empty
if (strlen($val)==0) { if (strlen($val)==0) {
$smarty_obj->_trigger_error_msg("math: parameter $key is empty"); $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.";"); eval("\$smarty_math_result = ".$equation.";");
if (empty($args["format"])) if (empty($args["format"])) {
echo $smarty_math_result; if (empty($args["assign"])) {
else echo $smarty_math_result;
printf($args["format"],$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"); $smarty_obj->_trigger_error_msg("(secure mode) fetch '$file' is not allowed");
return; return;
} }
} if (!@is_readable($file)) {
if (!@is_readable($file)) { $smarty_obj->_trigger_error_msg("fetch cannot read file '$file'");
$smarty_obj->_trigger_error_msg("fetch cannot read file '$file'"); return;
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 Function: smarty_func_counter
Purpose: print out a counter value Purpose: print out a counter value
\*======================================================================*/ \*======================================================================*/
function smarty_func_counter() { function smarty_func_counter($args, &$smarty_obj) {
static $count = array(); static $count = array();
static $skipval = array(); static $skipval = array();
static $dir = array(); static $dir = array();
static $id = "default"; static $id = "default";
static $printval = array(); static $printval = array();
static $assign = "";
extract(func_get_arg(0)); extract($args);
if (!isset($id)) if (!isset($id))
$id = "default"; $id = "default";
@@ -682,15 +700,20 @@ function smarty_func_counter() {
$printval[$id]=true; $printval[$id]=true;
else else
$printval[$id]=$print; $printval[$id]=$print;
if(!empty($assign)) {
$printval[$id] = false;
$smarty_obj->assign($assign,$count[$id]);
}
if ($printval[$id]) if ($printval[$id])
echo $count[$id]; echo $count[$id];
if (isset($skip)) if (isset($skip))
$skipval[$id] = $skip; $skipval[$id] = $skip;
elseif (!isset($skipval)) elseif (empty($skipval[$id]))
$skipval[$id] = 1; $skipval[$id] = 1;
if (isset($direction)) if (isset($direction))
$dir[$id] = $direction; $dir[$id] = $direction;
elseif (!isset($dir[$id])) elseif (!isset($dir[$id]))
@@ -700,7 +723,7 @@ function smarty_func_counter() {
$count[$id] -= $skipval[$id]; $count[$id] -= $skipval[$id];
else else
$count[$id] += $skipval[$id]; $count[$id] += $skipval[$id];
return true; return true;
} }

View File

@@ -1024,7 +1024,11 @@ function _run_insert_handler($args)
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; if(!empty($args["assign"])) {
$this->assign($args["assign"],$content);
} else {
return $content;
}
} }
} }

View File

@@ -3149,7 +3149,7 @@ The value of $name is Bob.
<entry>print</entry> <entry>print</entry>
<entry>boolean</entry> <entry>boolean</entry>
<entry>No</entry> <entry>No</entry>
<entry><emphasis>false</emphasis></entry> <entry><emphasis>true</emphasis></entry>
<entry>Whether or not to print the value</entry> <entry>Whether or not to print the value</entry>
</row> </row>
</tbody> </tbody>

View File

@@ -1024,7 +1024,11 @@ function _run_insert_handler($args)
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; if(!empty($args["assign"])) {
$this->assign($args["assign"],$content);
} else {
return $content;
}
} }
} }