Code

Updated smarty to 1.0.9
[gosa.git] / gosa-core / include / smarty / plugins / function.math.php
index bb78dac22c0be41c9148a2a36634089be3f74dcc..cd90020a43d0850363041444f9fa19e736fadc01 100644 (file)
@@ -1,11 +1,12 @@
 <?php
 /**
  * Smarty plugin
+ *
+ * This plugin is only for Smarty2 BC
  * @package Smarty
- * @subpackage plugins
+ * @subpackage PluginsFunction
  */
 
-
 /**
  * Smarty {math} function plugin
  *
  * @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 $template template object
+ * @return string|null
  */
-function smarty_function_math($params, &$smarty)
+function smarty_function_math($params, $template)
 {
     // be sure equation parameter is present
     if (empty($params['equation'])) {
-        $smarty->trigger_error("math: missing equation parameter");
+        trigger_error("math: missing equation parameter",E_USER_WARNING);
         return;
     }
 
-    // strip out backticks, not necessary for math
-    $equation = str_replace('`','',$params['equation']);
+    $equation = $params['equation'];
 
     // make sure parenthesis are balanced
     if (substr_count($equation,"(") != substr_count($equation,")")) {
-        $smarty->trigger_error("math: unbalanced parenthesis");
+        trigger_error("math: unbalanced parenthesis",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][a-zA-Z0-9_]+)!",$equation, $match);
+    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");
+            trigger_error("math: function call $curr_var not allowed",E_USER_WARNING);
             return;
         }
     }
@@ -52,34 +52,32 @@ 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");
+                trigger_error("math: parameter $key is empty",E_USER_WARNING);
                 return;
             }
             if (!is_numeric($val)) {
-                $smarty->trigger_error("math: parameter $key: is not numeric");
+                trigger_error("math: parameter $key: is not numeric",E_USER_WARNING);
                 return;
             }
             $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
         }
     }
-
+    $smarty_math_result = null;
     eval("\$smarty_math_result = ".$equation.";");
 
     if (empty($params['format'])) {
         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: */
-
-?>
+?>
\ No newline at end of file