Revision history for CalcInfo


Revision [19369]

Last edited on 2008-01-28 00:15:26 by JfDelesse [Modified links pointing to docs server]

No Differences

Revision [17593]

Edited on 2007-10-02 16:12:57 by JfDelesse [Modified links pointing to docs server]
Additions:
$otherpat='([0-9\.*\(\)\-+\/=]+)';
Deletions:
$otherpat='([0-9\.*\-+\/=]+)';


Revision [17515]

Edited on 2007-09-23 12:10:14 by JfDelesse [Modified links pointing to docs server]
Additions:
$otherpat='([0-9\.*\-+\/=]+)';
Deletions:
$otherpat='([0-9*\-+\/=]+)';


Revision [17508]

Edited on 2007-09-22 18:01:52 by JfDelesse [Modified links pointing to docs server]
Additions:
===This action allows you to put calculations (with variables or not) and write out the result.===
Deletions:
===This action allows you to write calculations (with variables or not) and write out the result.===


Revision [17507]

Edited on 2007-09-22 18:00:54 by JfDelesse [Modified links pointing to docs server]
Additions:
===This action allows you to write calculations (with variables or not) and write out the result.===
- The variables are keys in an associative array named calcvar (//i.e. calcvar['total']//)
- The function calls are forgotten.
- It makes your wiki page a spreadsheet.
- It allows displaying not hard-coded numerical values (such the number of seconds in a day), preventing errors...
- It allows modification of values in a page without recalculation by-hand of a global result (if you add an item //green: 12// in the list)
- You can easily add an operator (currently -*/+) by adding a char in the regexp line 16.
- You could authorize the call of specific functions (such ln, exp,...) by matching them (a little bit more difficult)
- You could define options in order to set the precision of the result by example.
Deletions:
This action allows you to write calculations (with variables) and write out the result.
-~the used variables are keys in an associative array named calcvar (//i.e. calcvar['total']//)
-~it allows giving not hard-coded numerical values
- You can easily add a lot of operators by adding a char in the regexp line 16.
- You could authorize the call of specific functions (such ln, exp,...) by matching them


Revision [17506]

Edited on 2007-09-22 17:43:53 by JfDelesse [Modified links pointing to docs server]
Additions:
==Features==
- Secure
-~the used variables are keys in an associative array named calcvar (//i.e. calcvar['total']//)
- Powerful
-~it allows giving not hard-coded numerical values
==Restrictions==
- Variables names are necessary alphabetics (see line 14).
- You can't (because of security) call functions (see line 28).
- A few operators are allowed (see line 16).

==Improvements==
- You can easily add a lot of operators by adding a char in the regexp line 16.
- You could authorize the call of specific functions (such ln, exp,...) by matching them
Deletions:
==Restriction==
- Variables names are necessary alphabetics.
- You can't (because of security) call functions.
- A few operators are allowed (see line
// print ($allpattern);


Revision [17505]

Edited on 2007-09-22 17:32:21 by JfDelesse [Modified links pointing to docs server]
Additions:
==Restriction==
- Variables names are necessary alphabetics.
- You can't (because of security) call functions.
- A few operators are allowed (see line


Revision [17504]

Edited on 2007-09-22 17:28:38 by JfDelesse [Modified links pointing to docs server]
Additions:
*Author:Jean-françois Delesse (jfdelesse@free.fr)
}
Deletions:
*



Revision [17503]

Edited on 2007-09-22 17:20:20 by JfDelesse [Modified links pointing to docs server]
Additions:
- **total+taxes**: **{{calc total+total*18.6/100.0}}**
- **total+taxes**: **13.046**
Deletions:
- **total+taxes**: **{{calc total+total*18.6/100}}**


Revision [17502]

Edited on 2007-09-22 17:17:36 by JfDelesse [Modified links pointing to docs server]
Additions:
- **total+taxes**: **{{calc total+total*18.6/100}}**


Revision [17501]

Edited on 2007-09-22 17:07:35 by JfDelesse [Modified links pointing to docs server]
Additions:
Because:
- Several expressions separated by a semicolon can appear in a **calc** action,
- only those that aren't assignations (not containing the equal sign) are displayed.


Revision [17500]

Edited on 2007-09-22 17:01:28 by JfDelesse [Modified links pointing to docs server]
Additions:
==Basic usage==
==With variables usage==
{{calc total=0}}
- red: {{calc q=2;total+=q;q}}
- blue: {{calc q=3;total+=q;q}}
- yellow: {{calc q=6;total+=q;q}}
- **total**: **{{calc total}}**
You will obtain:
- red: 2
- blue: 3
- yellow: 6
- **total**: **11**
==Code==


Revision [17499]

Edited on 2007-09-22 16:44:01 by JfDelesse [Modified links pointing to docs server]
Additions:
By typing:
1 day ={{calc 24*60*60}} seconds
you will obtain:
1 day =86400 seconds


Revision [17498]

Edited on 2007-09-22 16:26:07 by JfDelesse [Modified links pointing to docs server]
Additions:
%%(php;1)
Deletions:
%%(php;10)


Revision [17497]

Edited on 2007-09-22 16:25:30 by JfDelesse [Modified links pointing to docs server]
Additions:
%%(php;10)
Deletions:
%%(php;10;calc.php)


Revision [17496]

Edited on 2007-09-22 16:24:10 by JfDelesse [Modified links pointing to docs server]
Additions:
%%(php;10;calc.php)
Deletions:
%%(php;1;calc.php)


Revision [17495]

Edited on 2007-09-22 16:23:41 by JfDelesse [Modified links pointing to docs server]
Additions:
Save this as actions/calc.php
%%(php;1;calc.php)
Deletions:
%%(php)


Revision [17494]

Edited on 2007-09-22 16:19:14 by JfDelesse [Modified links pointing to docs server]
Additions:
This action allows you to write calculations (with variables) and write out the result.
/*
if (!function_exists('strtonum'))
{
$calcvar=array();

function strtonum($str)
{
static $calcvar;
$pattern = '/([^;])+/';
$varpat='([a-zA-Z]+\s*\(*)';
$varpattern="/$varpat/";
$otherpat='([0-9*\-+\/=]+)';
$allpattern="/$varpat|$otherpat/";
// print ($allpattern);
preg_match_all($pattern,$str,$blocks);
foreach ($blocks[0] as $k=>$block)
{
$affichage=true;
$blockstr="";
preg_match_all($allpattern,$block,$out,PREG_SET_ORDER);
foreach ($out as $k2=>$token)
{
if ($token[1]!="")
{
$token[1]=preg_replace('/\s*\(*/','',$token[1]);
$tokstr='$calcvar[\''.$token[1].'\']';
}
if ($token[2]!="")
{
$tokstr=$token[2];
if (!(strpos($tokstr,"=")===false))
{
$affichage=false;
}
}
$blockstr.=$tokstr;
}
if(!empty($blockstr))
{
$blockstr="$blockstr;";
$blockstr=eval("return ".$blockstr);
if ($affichage)
$outstr.=($outstr!=""?";":"").$blockstr ;
}
}
return $outstr;
}
}
if (is_array($vars))
{
print strtonum($vars['wikka_vars']);

}
?>
Deletions:
Allow
/**


Revision [17493]

The oldest known version of this page was created on 2007-09-22 16:16:07 by JfDelesse [Modified links pointing to docs server]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki