Updated to Smarty 2.6.26 (June 18th, 2009), we should update to Smarty 3.x (current...
[mirrors/Kyberia-bloodline.git] / wwwroot / smarty / libs / plugins / function.math.php
index 544f5c6a8a0b719cc06dcd3827d8e4a576b13991..bb78dac22c0be41c9148a2a36634089be3f74dcc 100644 (file)
@@ -14,6 +14,7 @@
  * Purpose:  handle math computations in template<br>
  * @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
@@ -26,7 +27,8 @@ function smarty_function_math($params, &$smarty)
         return;
     }
 
-    $equation = $params['equation'];
+    // strip out backticks, not necessary for math
+    $equation = str_replace('`','',$params['equation']);
 
     // make sure parenthesis are balanced
     if (substr_count($equation,"(") != substr_count($equation,")")) {
@@ -38,7 +40,7 @@ function smarty_function_math($params, &$smarty)
     preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]+)!",$equation, $match);
     $allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
                            'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
-
+    
     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");
@@ -57,7 +59,7 @@ function smarty_function_math($params, &$smarty)
                 $smarty->trigger_error("math: parameter $key: is not numeric");
                 return;
             }
-            $equation = preg_replace("/\b$key\b/",$val, $equation);
+            $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
         }
     }
 
This page took 0.116677 seconds and 4 git commands to generate.