/[cvs]/nfo/php/libs/net.php.smarty/plugins/function.math.php
ViewVC logotype

Diff of /nfo/php/libs/net.php.smarty/plugins/function.math.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cvsjoko, Wed Oct 9 00:53:36 2002 UTC revision 1.2 by joko, Wed Jun 16 21:58:17 2004 UTC
# Line 1  Line 1 
1  <?php  <?php
2    /**
 /*  
3   * Smarty plugin   * Smarty plugin
4   * -------------------------------------------------------------   * @package Smarty
5   * Type:     function   * @subpackage plugins
6   * Name:     math   */
7   * Purpose:  handle math computations in template  
8   * -------------------------------------------------------------  
9    /**
10     * Smarty {math} function plugin
11     *
12     * Type:     function<br>
13     * Name:     math<br>
14     * Purpose:  handle math computations in template<br>
15     * @link http://smarty.php.net/manual/en/language.function.math.php {math}
16     *          (Smarty online manual)
17     * @param array
18     * @param Smarty
19     * @return string
20   */   */
21  function smarty_function_math($params, &$smarty)  function smarty_function_math($params, &$smarty)
22  {  {
# Line 25  function smarty_function_math($params, & Line 35  function smarty_function_math($params, &
35      }      }
36    
37      // match all vars in equation, make sure all are passed      // match all vars in equation, make sure all are passed
38      preg_match_all("![a-zA-Z][a-zA-Z0-9]*!",$equation, $match);      preg_match_all("!\!(0x)([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match);
39      $allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',      $allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
40                             'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');                             'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
41        foreach($match[2] as $curr_var) {
     foreach($match[0] as $curr_var) {  
42          if (!in_array($curr_var,array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {          if (!in_array($curr_var,array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
43              $smarty->trigger_error("math: parameter $curr_var not passed as argument");              $smarty->trigger_error("math: parameter $curr_var not passed as argument");
44              return;              return;
# Line 55  function smarty_function_math($params, & Line 64  function smarty_function_math($params, &
64    
65      if (empty($params['format'])) {      if (empty($params['format'])) {
66          if (empty($params['assign'])) {          if (empty($params['assign'])) {
67              echo $smarty_math_result;              return $smarty_math_result;
68          } else {          } else {
69              $smarty->assign($params['assign'],$smarty_math_result);              $smarty->assign($params['assign'],$smarty_math_result);
70          }          }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed