Skip to content

Commit

Permalink
Add support for ExpressionEngine 3
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ Draper committed Oct 26, 2015
1 parent 2ac6123 commit 3b63960
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 72 deletions.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#------------------------------------
# Tools
#------------------------------------

.bundle
.idea/
.komodotools
.project
.settings/
.tern-project
.tmproj
.vscode/
*.esproj
*.komodoproject
*.sublime-*
browserstack.js
codekit-config.json
mixture.json
prepros.json


#------------------------------------
# System
#------------------------------------

.cache
.DS_Store
.tmp
*.diff
*.err
*.lock
*.log
*.orig
*.rej
*.swo
*.swp
*.vi
error_log
Thumbs.db


#------------------------------------
# Gitkeep
#------------------------------------

!.gitkeep
36 changes: 0 additions & 36 deletions CHANGELOG.md

This file was deleted.

14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Math 1.4.1
## Math 1.5.0

Math allows you to execute many PHP math functions in your ExpressionEngine templates without needing to enable PHP parsing.

Expand Down Expand Up @@ -90,6 +90,18 @@ Message returned when non-numeric parameters are provided (default: "Invalid inp

Include trailing 0 decimal places (defaults: "no")

## Installation

### EE 2

DevDemon Updater is fully supported, or for manual installs, copy `system/expressionengine/third_party/math` to your third_party system directory.

### EE 3

1. Copy `system/expressionengine/third_party/math` to `system/user/addons`
2. Go to your control panel and navigate to the Add-On Manager
3. Locate Math in the Third Part Add-Ons section and click install

## License

Copyright 2014 Caddis Interactive, LLC
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.4.1",
"version": "1.5.0",
"types": ["plugin"],
"paths": {
"system": [
Expand Down
20 changes: 20 additions & 0 deletions system/expressionengine/third_party/math/addon.setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

if (! defined('MATH_AUTHOR')) {
define('MATH_AUTHOR', 'Caddis');
define('MATH_AUTHOR_URL', 'https://www.caddis.co');
define('MATH_DESC', 'Use Math to execute PHP supported math formulas.');
define('MATH_DOCS_URL', 'https://github.com/caddis/math');
define('MATH_NAME', 'Math');
define('MATH_VER', '1.5.0');
}

return array(
'author' => MATH_AUTHOR,
'author_url' => MATH_AUTHOR_URL,
'description' => MATH_DESC,
'docs_url' => MATH_DOCS_URL,
'name' => MATH_NAME,
'namespace' => 'Caddis\Resizer',
'version' => MATH_VER
);
44 changes: 10 additions & 34 deletions system/expressionengine/third_party/math/pi.math.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');

include_once(PATH_THIRD . 'math/addon.setup.php');

$plugin_info = array (
'pi_name' => 'Math',
'pi_version' => '1.4.1',
'pi_author' => 'Caddis',
'pi_author_url' => 'http://www.caddis.co',
'pi_description' => 'Use Math to execute PHP supported math formulas.',
'pi_author' => MATH_AUTHOR,
'pi_author_url' => MATH_AUTHOR_URL,
'pi_description' => MATH_DESC,
'pi_name' => MATH_NAME,
'pi_version' => MATH_VER,
'pi_usage' => Math::usage()
);

Expand Down Expand Up @@ -83,7 +85,7 @@ public function __construct()
break;
default:
$result = intval($result * $mult) / $mult;
}
}
}

$parts = explode('.', $result);
Expand Down Expand Up @@ -115,32 +117,6 @@ public function __construct()

public static function usage()
{
ob_start();
?>
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")

Usage:

{exp:math formula="10 - 12" absolute="yes"} outputs 2
{exp:math formula="((4 * 5) / 2)" decimals="2"} outputs 10.00
{exp:math formula="([1] + 1) / [2]" params="{total_results}|2" round="down"} outputs 5 where {total_results} is 10
{exp:math formula="2/3" decimals="2" round="up"} outputs 0.67
<?php
$buffer = ob_get_contents();

ob_end_clean();

return $buffer;
return 'See docs and examples at https://github.com/caddis/math';
}
}
?>
}

0 comments on commit 3b63960

Please sign in to comment.