Commit d9abf4ca authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 4.0.1: Handle = and html in the basic plugin's rule names; hide the...

Version 4.0.1: Handle = and html in the basic plugin's rule names; hide the quotes around rule names in the basic plugin; fix typo in the operator regexp
parent 6d5f36d9
......@@ -113,7 +113,7 @@ class ShippingRule_Advanced extends ShippingRule {
// (OR, AND, in; but make sure we don't capture parts of words, so we need to
// use lookbehind/lookahead patterns to exclude OR following another letter
// or followed by another letter) and then all arithmetic operators
$re = '/\s*("[^"]*"|\'[^\']*\'|(?<![A-Za-z0-9])(?:OR|AND|IN)(?![A-Za-z0-9])|&&|<=|=>|>=|=>|<>|!=|==|<|=|>|~|\+|-|\*|\/|%|\(|\)|\^|,)\s*/i';
$re = '/\s*("[^"]*"|\'[^\']*\'|(?<![A-Za-z0-9])(?:OR|AND|IN)(?![A-Za-z0-9])|&&|<=|=>|>=|=<|<>|!=|==|<|=|>|~|\+|-|\*|\/|%|\(|\)|\^|,)\s*/i';
$atoms = preg_split($re, $expression, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
// JFactory::getApplication()->enqueueMessage("TOKENIZING '$expression' returns: <pre>".print_r($atoms,1)."</pre>", 'error');
return $atoms;
......
<?xml version="1.0" encoding="UTF-8" ?>
<install version="1.5" type="plugin" group="vmshipment" method="upgrade">
<name>VMSHIPMENT_RULES_ADV</name>
<creationDate>2014-01-12</creationDate>
<creationDate>2014-01-14</creationDate>
<author>Reinhold Kainhofer</author>
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>4.0</version>
<version>4.0.1</version>
<description>VMSHIPMENT_RULES_ADV_DESC</description>
<files>
<filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename>
......
......@@ -787,15 +787,36 @@ class ShippingRule {
}
function tokenize_expression ($expression) {
// First, extract all strings, delimited by quotes, then all text operators
// (OR, AND, in; but make sure we don't capture parts of words, so we need to
// use lookbehind/lookahead patterns to exclude OR following another letter
// or followed by another letter) and then all arithmetic operators
$re = '/\s*("[^"]*"|\'[^\']*\'|<=|=>|>=|=<|<>|!=|==|<|=|>)\s*/i';
$atoms = preg_split($re, $expression, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
// JFactory::getApplication()->enqueueMessage("TOKENIZING '$expression' returns: <pre>".print_r($atoms,1)."</pre>", 'error');
return $atoms;
}
function parseRulePart($rulepart) {
/* In the basic version, we only split at the comparison operators and assume each term on the LHS and RHS is one variable or constant */
/* In the advanced version, all conditions and costs can be given as a full mathematical expression */
/* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */
$operators = array('<', '<=', '=', '>', '>=', '=>', '=<', '<>', '!=', '==');
$op_re='/\s*(<=|=>|>=|=>|<>|!=|==|<|=|>)\s*/';
$rulepart = trim($rulepart);
if (empty($rulepart)) return;
$atoms = preg_split ($op_re, $rulepart, -1, PREG_SPLIT_DELIM_CAPTURE);
// Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression!
if (preg_match('/^\s*(name|variable|definition)\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) {
$this->handleAssignment ($matches[1], $matches[3], $rulepart);
return;
}
// Split at all operators:
$atoms = $this->tokenize_expression ($rulepart);
/* TODO: Starting from here, the advanced plugin is different! */
$operators = array('<', '<=', '=', '>', '>=', '=>', '=<', '<>', '!=', '==');
if (count($atoms)==1) {
$this->shipping = $this->parseShippingTerm($atoms[0]);
} elseif ($atoms[1]=='=') {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment