Version 1.14a

This commit is contained in:
nemunaire 2020-11-15 16:12:32 +01:00
commit dc48225dc9
1094 changed files with 189052 additions and 13889 deletions

View file

@ -1,8 +1,10 @@
<?php
/**
* Smarty plugin
*
* This plugin is only for Smarty2 BC
* @package Smarty
* @subpackage plugins
* @subpackage PluginsFunction
*/
@ -15,15 +17,16 @@
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
* @param array $params parameters
* @param object $smarty Smarty object
* @param object $template template object
* @return string|null
*/
function smarty_function_math($params, &$smarty)
function smarty_function_math($params, $smarty, $template)
{
// be sure equation parameter is present
if (empty($params['equation'])) {
$smarty->trigger_error("math: missing equation parameter");
throw new Exception ("math: missing equation parameter");
return;
}
@ -31,7 +34,7 @@ function smarty_function_math($params, &$smarty)
// make sure parenthesis are balanced
if (substr_count($equation,"(") != substr_count($equation,")")) {
$smarty->trigger_error("math: unbalanced parenthesis");
throw new Exception ("math: unbalanced parenthesis");
return;
}
@ -42,7 +45,7 @@ function smarty_function_math($params, &$smarty)
foreach($match[1] as $curr_var) {
if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
$smarty->trigger_error("math: function call $curr_var not allowed");
throw new Exception ("math: function call $curr_var not allowed");
return;
}
}
@ -51,11 +54,11 @@ function smarty_function_math($params, &$smarty)
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val)==0) {
$smarty->trigger_error("math: parameter $key is empty");
throw new Exception ("math: parameter $key is empty");
return;
}
if (!is_numeric($val)) {
$smarty->trigger_error("math: parameter $key: is not numeric");
throw new Exception ("math: parameter $key: is not numeric");
return;
}
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
@ -68,17 +71,14 @@ function smarty_function_math($params, &$smarty)
if (empty($params['assign'])) {
return $smarty_math_result;
} else {
$smarty->assign($params['assign'],$smarty_math_result);
$template->assign($params['assign'],$smarty_math_result);
}
} else {
if (empty($params['assign'])){
printf($params['format'],$smarty_math_result);
} else {
$smarty->assign($params['assign'],sprintf($params['format'],$smarty_math_result));
$template->assign($params['assign'],sprintf($params['format'],$smarty_math_result));
}
}
}
/* vim: set expandtab: */
?>