Skip to content

Commit

Permalink
See changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
leigeber committed Nov 13, 2013
1 parent db87e8e commit fe62c6e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# 1.4.0

2013-11-13

- FIX: Resolved issue with 0 value handling of boolean checks
- UPDATE: Updated plugin to reflect EE 2.6+ global style ee()

# 1.3.1

2013-07-04

- If a round value is set with no decimal value the decimal setting defaults to 0
- UPDATED: If a round value is set with no decimal value the decimal setting defaults to 0

# 1.3.0

2013-05-08

- Added DevDemon Updater compatability
- ADDED: Added DevDemon Updater compatability

# 1.2.0

2013-01-13

- Resolved issue with deimal padding and rounding
- FIXED: Resolved issue with decimal padding and rounding

# 1.1.0

2013-01-04

- Plugin now strips non-numeric characters out of passed parameters
- UPDATED: Plugin now strips non-numeric characters out of passed parameters
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ExpressionEngine Math Plugin 1.3.1
ExpressionEngine Math Plugin 1.4.0
====

Use Math to execute PHP supported math formulas in ExpressionEngine.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schema_version": "1.0",
"name" : "math",
"label": "Math",
"version": "1.3.1",
"version": "1.4.0",
"types": ["plugin"],
"paths": {
"system": [
Expand Down
60 changes: 29 additions & 31 deletions system/expressionengine/third_party/math/pi.math.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');

$plugin_info = array (
'pi_name' => 'Math',
'pi_version' => '1.3.1',
'pi_author' => 'Michael Leigeber',
'pi_version' => '1.4.0',
'pi_author' => 'Caddis',
'pi_author_url' => 'http://www.caddis.co',
'pi_description' => 'Use Math to execute PHP supported math formulas.',
'pi_usage' => Math::usage()
Expand All @@ -15,24 +15,22 @@ class Math {

public function __construct()
{
$this->EE =& get_instance();

// Get formula
$formula = $this->EE->TMPL->fetch_param('formula');
$formula = ee()->TMPL->fetch_param('formula');

$error = false;
$result = '';

if ($formula)
if ($formula !== false)
{
// Convert html entities to math characters
$formula = html_entity_decode($formula);

// Replace parameters
$params = $this->EE->TMPL->fetch_param('params');
$numeric_error = $this->EE->TMPL->fetch_param('numeric_error', 'Invalid input');
$params = ee()->TMPL->fetch_param('params');
$numeric_error = ee()->TMPL->fetch_param('numeric_error', 'Invalid input');

if ($params)
if ($params !== false)
{
$params = explode('|', $params);
$i = 1;
Expand All @@ -57,18 +55,18 @@ public function __construct()
}
}

if (! $error)
if ($error !== true)
{
// Evaluate math
@eval("\$result = $formula;");

// Get settings
$round = $this->EE->TMPL->fetch_param('round', false);
$decimals = $this->EE->TMPL->fetch_param('decimals', false);
$decimal_point = $this->EE->TMPL->fetch_param('dec_point', '.');
$thousands_seperator = $this->EE->TMPL->fetch_param('thousands_seperator', ',');
$absolute = $this->EE->TMPL->fetch_param('absolute');
$trailing_zeros = $this->EE->TMPL->fetch_param('trailing_zeros', false);
$round = ee()->TMPL->fetch_param('round');
$decimals = ee()->TMPL->fetch_param('decimals');
$decimal_point = ee()->TMPL->fetch_param('dec_point', '.');
$thousands_seperator = ee()->TMPL->fetch_param('thousands_seperator', ',');
$absolute = ee()->TMPL->fetch_param('absolute');
$trailing_zeros = ee()->TMPL->fetch_param('trailing_zeros');

$decimal_digits = 0;

Expand All @@ -79,7 +77,7 @@ public function __construct()
}

// Rounding
if ($decimals !== false || $round !== false)
if ($decimals !== false or $round !== false)
{
$dec = ($decimals !== false) ? $decimals : 0;
$mult = pow(10, $dec);
Expand All @@ -105,25 +103,25 @@ public function __construct()
// Format response
if ($decimals !== false)
{
$result = number_format((int)$parts[0], 0, $decimal_point, $thousands_seperator);
$result = number_format((int) $parts[0], 0, $decimal_point, $thousands_seperator);

if ($decimals > 0)
{
if ($decimal_digits < $decimals && $trailing_zeros)
if ($decimal_digits < $decimals and $trailing_zeros)
{
$result .= '.' . str_pad($decimal_value, $decimals, 0);
}
else
{
$result .= $decimal_value ? '.' . $decimal_value : '';
$result .= $decimal_value ? ('.' . $decimal_value) : '';
}
}
}
else
{
$decimals = $decimal_digits;

$result = number_format((float)$result, $decimals, $decimal_point, $thousands_seperator);
$result = number_format((float) $result, $decimals, $decimal_point, $thousands_seperator);
}
}
}
Expand All @@ -137,15 +135,15 @@ public static function usage()
?>
Parameters:

formula = '(5 * 2) / [1]' // math formula (required) supports the following operators as well as bitwise + - * / % ++ -- < > <= => != <> ==
params = '{var}|{var2}' // pipe delimited list of numeric parameters to be replaced into formula, recommended due to use of PHP eval (default: null)
decimals = '2' // sets the number of decimal points (default: "0")
decimal_point = '.' // sets the separator for the decimal point (default: ".")
thousands_seperator = ',' // sets the thousands separator; (default: ",")
absolute = 'yes' // return the absolute number of the result (defaults: "no")
round = 'up|down|ceil' // whether to round the result up or down, where up is standard rounding (defaults: no rounding)
numeric_error = 'Error' // message returned when non-numeric parameters are provided (default: "Invalid input")
trailing_zeros = 'yes' // include trailing 0 decimal places (defaults: "no")
formula = '(5 * 2) / [1]' // math formula (required) supports the following operators as well as bitwise + - * / % ++ -- < > <= => != <> ==
params = '{var}|{var2}' // pipe delimited list of numeric parameters to be replaced into formula, recommended due to use of PHP eval (default: null)
decimals = '2' // sets the number of decimal points (default: "0")
decimal_point = '.' // sets the separator for the decimal point (default: ".")
thousands_seperator = ',' // sets the thousands separator; (default: ",")
absolute = 'yes' // return the absolute number of the result (defaults: "no")
round = 'up|down|ceil' // whether to round the result up or down, where up is standard rounding (defaults: no rounding)
numeric_error = 'Error' // message returned when non-numeric parameters are provided (default: "Invalid input")
trailing_zeros = 'yes' // include trailing 0 decimal places (defaults: "no")

Usage:

Expand Down

0 comments on commit fe62c6e

Please sign in to comment.