diff --git a/rules_shipping_advanced.php b/rules_shipping_advanced.php index 21bc32d3bbf8cfd398d7418b3e9d75b17bfc855d..1d68c1829304921b62b865558c5a4c67e8183ded 100644 --- a/rules_shipping_advanced.php +++ b/rules_shipping_advanced.php @@ -106,6 +106,7 @@ class plgVmShipmentRules_Shipping_Advanced extends plgVmShipmentRules_Shipping_B class ShippingRule_Advanced extends ShippingRule { var $operators = array( ".-" => 100, ".+" => 100, + " in " => 80, "^" => 70, "*" => 60, "/" => 60, "%" => 60, "+" => 50, "-" => 50, @@ -130,7 +131,10 @@ class ShippingRule_Advanced extends ShippingRule { $str_re = '/("[^"]*"|\'[^\']*\')/'; $strings = preg_split($str_re, $expression, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); // Then split all other parts of the expression at the operators - $op_re = ':\s*( OR |&&| AND |<=|=>|>=|=>|<>|!=|==|<|=|>|~|\+|-|\*|/|%|\(|\)|\^|,)\s*:'; +// TODO 1: This fails for expressions like "(1>0) OR zip in array(1,4,1080)" +// TODO 2: Better handle the spaces around in-line text operators! +// (state2 in array("TX", "WS", "MS")) OR zip in array(1,4,1080) + $op_re = ':\s*( OR |&&| AND | in |<=|=>|>=|=>|<>|!=|==|<|=|>|~|\+|-|\*|/|%|\(|\)|\^|,)\s*:'; $atoms = array(); foreach ($strings as $s) { if (preg_match($str_re, $s)) { @@ -185,7 +189,7 @@ class ShippingRule_Advanced extends ShippingRule { $atoms = $this->tokenize_expression ($rulepart); // Any of these indicate a comparison and thus a condition: - $condition_ops = array('<', '<=', '=<', '<>', '!=', '==', '>', '>=', '=>', '~', ' OR ', 'OR', 'AND', ' AND ', '&&'); + $condition_ops = array('<', '<=', '=<', '<>', '!=', '==', '>', '>=', '=>', '~', ' OR ', 'OR', 'AND', ' AND ', '&&', 'in', ' in '); $comparison_ops = array('<', '<=', '=<', '<>', '!=', '==', '>', '>=', '=>', '~'); $is_condition = false; $is_assignment = false; diff --git a/rules_shipping_base.php b/rules_shipping_base.php index e84e2f12ab35c7b0443002960e419a0976e658b0..258aae363c44434923951b0cd8e27d3151462b96 100644 --- a/rules_shipping_base.php +++ b/rules_shipping_base.php @@ -761,6 +761,7 @@ class ShippingRule { switch ($func) { case "max": return max($args); break; case "min": return min($args); break; + case "array": return $args; break; } // No known function matches => print an error, return 0 JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_EVALUATE_UNKNOWN_FUNCTION', $function, $this->rulestring), 'error'); @@ -810,7 +811,8 @@ class ShippingRule { case '&&': case 'AND': case ' AND ': $res = true; foreach ($args as $a) { $res = ($res && $a); }; break; - case 'in': $needle = array_shift($args); $res = in_array($needle, $args); break; + case 'in': + case ' in ': $res = in_array($args[0], $args[1]); break; // Comparisons: case '<':