Source for file function.math.php
Documentation is available at function.math.php
* Smarty {math} function plugin
* Purpose: handle math computations in template<br>
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
// be sure equation parameter is present
if (empty($params['equation'])) {
$equation = $params['equation'];
// make sure parenthesis are balanced
// match all vars in equation, make sure all are passed
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
foreach($match[2] as $curr_var) {
$smarty->trigger_error("math: parameter $curr_var not passed as argument");
foreach($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
eval ("\$smarty_math_result = ". $equation. ";");
if (empty($params['format'])) {
if (empty($params['assign'])) {
return $smarty_math_result;
$smarty->assign($params['assign'],$smarty_math_result);
if (empty($params['assign'])){
printf($params['format'],$smarty_math_result);
$smarty->assign($params['assign'],sprintf($params['format'],$smarty_math_result));
/* vim: set expandtab: */
|