mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 02:14:26 +02:00
fixed bugs and added assign attribute to several functions
This commit is contained in:
6
NEWS
6
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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3149,7 +3149,7 @@ The value of $name is Bob.
|
||||
<entry>print</entry>
|
||||
<entry>boolean</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>false</emphasis></entry>
|
||||
<entry><emphasis>true</emphasis></entry>
|
||||
<entry>Whether or not to print the value</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user