aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/libs/plugins/function.math.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-10-30 12:12:07 +0100
committerMario Vavti <mario@mariovavti.com>2018-10-30 12:12:07 +0100
commit2192ea6fdf21a00ccf44d626a01b756d194d6cbe (patch)
tree153d4b4ffb2bf40edf8aae66b82a274dac37c208 /vendor/smarty/smarty/libs/plugins/function.math.php
parent0f19627407ccd373afe1ce2d2347ea240f3195c1 (diff)
downloadvolse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.tar.gz
volse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.tar.bz2
volse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.zip
update html_to_markdown, smarty and sabredav libs via composer
Diffstat (limited to 'vendor/smarty/smarty/libs/plugins/function.math.php')
-rw-r--r--vendor/smarty/smarty/libs/plugins/function.math.php49
1 files changed, 26 insertions, 23 deletions
diff --git a/vendor/smarty/smarty/libs/plugins/function.math.php b/vendor/smarty/smarty/libs/plugins/function.math.php
index 396ad085e..7348d9649 100644
--- a/vendor/smarty/smarty/libs/plugins/function.math.php
+++ b/vendor/smarty/smarty/libs/plugins/function.math.php
@@ -6,16 +6,15 @@
* @package Smarty
* @subpackage PluginsFunction
*/
-
/**
* Smarty {math} function plugin
* Type: function
* Name: math
* Purpose: handle math computations in template
*
- * @link http://www.smarty.net/manual/en/language.function.math.php {math}
+ * @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
- * @author Monte Ohrt <monte at ohrt dot com>
+ * @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
@@ -25,66 +24,71 @@
function smarty_function_math($params, $template)
{
static $_allowed_funcs =
- array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
- 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true,
- 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
+ array(
+ 'int' => true,
+ 'abs' => true,
+ 'ceil' => true,
+ 'cos' => true,
+ 'exp' => true,
+ 'floor' => true,
+ 'log' => true,
+ 'log10' => true,
+ 'max' => true,
+ 'min' => true,
+ 'pi' => true,
+ 'pow' => true,
+ 'rand' => true,
+ 'round' => true,
+ 'sin' => true,
+ 'sqrt' => true,
+ 'srand' => true,
+ 'tan' => true
+ );
// be sure equation parameter is present
if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING);
-
return;
}
-
$equation = $params[ 'equation' ];
-
// make sure parenthesis are balanced
if (substr_count($equation, '(') !== substr_count($equation, ')')) {
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
-
return;
}
-
// disallow backticks
if (strpos($equation, '`') !== false) {
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
-
return;
}
-
// also disallow dollar signs
if (strpos($equation, '$') !== false) {
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
-
return;
}
-
foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
// make sure value is not empty
if (strlen($val) === 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
-
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
-
return;
}
}
}
-
// match all vars in equation, make sure all are passed
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
-
foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
- trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
-
+ trigger_error(
+ "math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'",
+ E_USER_WARNING
+ );
return;
}
}
-
foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
@@ -92,7 +96,6 @@ function smarty_function_math($params, $template)
}
$smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";");
-
if (empty($params[ 'format' ])) {
if (empty($params[ 'assign' ])) {
return $smarty_math_result;