Changeset 1549928
- Timestamp:
- 12/08/2016 10:30:22 PM (9 years ago)
- Location:
- shipping-by-rules-for-woocommerce
- Files:
-
- 4 edited
- 13 copied
-
tags/1.2.6 (copied) (copied from shipping-by-rules-for-woocommerce/trunk)
-
tags/1.2.6/LICENSE.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/LICENSE.txt)
-
tags/1.2.6/assets (copied) (copied from shipping-by-rules-for-woocommerce/trunk/assets)
-
tags/1.2.6/assets/js/opentools-updatecheck.js (copied) (copied from shipping-by-rules-for-woocommerce/trunk/assets/js/opentools-updatecheck.js)
-
tags/1.2.6/includes (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes)
-
tags/1.2.6/includes/rules-shipping-method.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules-shipping-method.php)
-
tags/1.2.6/includes/rules-shipping-post-type.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules-shipping-post-type.php)
-
tags/1.2.6/includes/rules_shipping_framework_woocommerce.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php) (1 diff)
-
tags/1.2.6/includes/rules_shipping_framework_woocommerce_advanced.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce_advanced.php)
-
tags/1.2.6/library (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library)
-
tags/1.2.6/library/rules_shipping_framework.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php) (9 diffs)
-
tags/1.2.6/readme.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/readme.txt) (2 diffs)
-
tags/1.2.6/woocommerce-shipping-by-rules.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php) (3 diffs)
-
trunk/includes/rules_shipping_framework_woocommerce.php (modified) (1 diff)
-
trunk/library/rules_shipping_framework.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/woocommerce-shipping-by-rules.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipping-by-rules-for-woocommerce/tags/1.2.6/includes/rules_shipping_framework_woocommerce.php
r1485122 r1549928 50 50 } 51 51 52 public function print Warning($message) {52 public function printMessage($message, $type) { 53 53 // Keep track of warning messages, so we don't print them twice: 54 global $printed_warnings; 55 if (!isset($printed_warnings)) 56 $printed_warnings = array(); 57 if (!in_array($message, $printed_warnings)) { 58 wc_add_notice( $message, 'error'); 59 $printed_warnings[] = $message; 60 } 61 } 62 63 /** @tag public-api 64 * @function debug() 65 * Print a debug message (untranslated) in the system-specific way. 66 * @param $message the debug message to be printed 67 */ 68 public function debug($message) { 69 if ( true === WP_DEBUG ) { 70 if ( is_array( $message ) || is_object( $message ) ) { 71 error_log( print_r( $message, true ) ); 72 } else { 73 error_log( $message ); 74 } 54 global $printed_messages; 55 if (!isset($printed_messages)) 56 $printed_messages = array(); 57 if ($type == "debug") { 58 if ( true === WP_DEBUG ) { 59 if ( is_array( $message ) || is_object( $message ) ) { 60 error_log( print_r( $message, true ) ); 61 } else { 62 error_log( $message ); 63 } 64 } 65 } elseif (!in_array($message, $printed_messages)) { 66 switch ($type) { 67 case 'error': 68 case 'warning': 69 wc_add_notice( $message, 'error'); break; 70 case 'message': 71 wc_add_notice( $message, 'success'); break; 72 case 'notice': 73 default: 74 wc_add_notice( $message, 'notice'); break; 75 } 76 $printed_messages[] = $message; 75 77 } 76 78 } -
shipping-by-rules-for-woocommerce/tags/1.2.6/library/rules_shipping_framework.php
r1485122 r1549928 172 172 } 173 173 174 /** @tag system-specific 175 * @function printWarning() 176 * Print a warning in the system-specific way. 177 * @param $message the warning message to be printed (already properly translated) 178 */ 179 protected function printWarning($message) { 180 echo($message); 174 /** @tag public-api 175 * @tag system-specific 176 * @function message() 177 * Print a message (to be translated) with given type in the system-specific way. 178 * @param $message the message to be printed 179 * @param $type the type of message (one of "error", "warning", "message"/"notice" or "debug") 180 * @param $args optional arguments to be inserted into the translated message in sprintf-style 181 */ 182 public function message($message, $type) { 183 $args = func_get_args(); 184 // Remove the $type from the args passed to __ 185 unset($args[1]); 186 $msg = call_user_func_array(array($this, "__"), $args); 187 $this->printMessage($msg, $type); 188 } 189 190 /** @tag public-api 191 * @tag system-specific 192 * @function error() 193 * Print an error message (to be translated) in the system-specific way. 194 * @param $message the error message to be printed 195 * @param $args optional arguments to be inserted into the translated message in sprintf-style 196 */ 197 public function error($message) { 198 $args = func_get_args(); 199 array_splice($args, 1, 0, 'error'); // insert msg type in second position 200 call_user_func_array(array($this, "message"), $args); 181 201 } 182 202 … … 190 210 public function warning($message) { 191 211 $args = func_get_args(); 192 $msg = call_user_func_array(array($this, "__"), $args);193 $this->printWarning($msg);212 array_splice($args, 1, 0, 'warning'); // insert msg type in second position 213 call_user_func_array(array($this, "message"), $args); 194 214 } 195 215 196 216 /** @tag public-api 217 * @tag system-specific 218 * @function notice() 219 * Print a message (to be translated) in the system-specific way. 220 * @param $message the message to be printed 221 * @param $args optional arguments to be inserted into the translated message in sprintf-style 222 */ 223 public function notice($message) { 224 $args = func_get_args(); 225 array_splice($args, 1, 0, 'notice'); // insert msg type in second position 226 call_user_func_array(array($this, "message"), $args); 227 } 228 229 /** @tag public-api 230 * @tag system-specific 197 231 * @function debug() 198 * Print a debug message (untranslated) in the system-specific way. 199 * @param $message the debug message to be printed 232 * Print a debug message in the system-specific way. 233 * @param $message the message to be printed 234 * @param $args optional arguments to be inserted into the translated message in sprintf-style 200 235 */ 201 236 public function debug($message) { 237 $args = func_get_args(); 238 array_splice($args, 1, 0, 'debug'); // insert msg type in second position 239 call_user_func_array(array($this, "message"), $args); 240 } 241 242 /** @tag system-specific 243 * @function printMessage() 244 * Print a message of given type in the system-specific way. 245 * @param $message the message to be printed (already properly translated) 246 * @param $type the type of message (one of "error", "warning", "message"/"notice" or "debug") 247 */ 248 protected function printMessage($message, $type) { 249 echo($message); 202 250 } 203 251 … … 417 465 break; 418 466 } 467 // Handle messages (error, warning, message/notice, debug: 468 foreach ($r->messages as $k=>$msgs) { 469 foreach ($msgs as $msg) { 470 $this->message($msg, $k); 471 } 472 } 419 473 } 420 474 if (!is_null($result["rule"])) { … … 594 648 var $ruleinfo = 0; 595 649 var $includes_tax = 0; 650 var $messages = array('error' => array(), 'warning' => array(), 'notice' => array(), 'debug' => array()); 596 651 597 652 function __construct ($framework, $rule, $countries, $ruleinfo) { … … 625 680 case 'extrashippingmultiplier': $this->shipping = $value; $this->ruletype = 'modifiers_multiply'; break; // modifiers are also stored in the shipping member! 626 681 case 'comment': break; // Completely ignore all comments! 682 case 'error': $this->messages['error'][] = $value; break; 683 case 'warning': $this->messages['warning'][] = $value; break; 684 case 'notice': 685 case 'message': $this->messages['notice'][] = $value; break; 686 case 'debug': $this->messages['debug'][] = $value; break; 627 687 case 'condition': $this->conditions[] = $value; break; 628 688 default: $this->framework->warning('OTSHIPMENT_RULES_UNKNOWN_VARIABLE', $var, $rulepart); … … 647 707 if (!isset($rulepart) || $rulepart==='') return; 648 708 649 650 709 // Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression! 651 if (preg_match('/^\s*(name|variable|definition )\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) {710 if (preg_match('/^\s*(name|variable|definition|error|warning|message|notice|debug)\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) { 652 711 $this->handleAssignment ($matches[1], $matches[3], $rulepart); 653 712 return; … … 1028 1087 } 1029 1088 1030 protected function calculateShipping ($vals, $products, $cartvals_callback) {1089 protected function calculateShipping($vals, $products, $cartvals_callback) { 1031 1090 return $this->evaluateTerm($this->shipping, $vals, $products, $cartvals_callback); 1091 } 1092 1093 protected function stringReplaceVariables($str, $vals) { 1094 // Evaluate the rule name as a translatable string with variables inserted: 1095 // Replace all {variable} tags in the name by the variables from $vals 1096 $matches = array(); 1097 preg_match_all('/{([A-Za-z0-9_]+)}/', $str, $matches); 1098 1099 foreach ($matches[1] as $m) { 1100 $val = $this->evaluateVariable($m, $vals); 1101 if ($val !== null) { 1102 $str = str_replace("{".$m."}", $val, $str); 1103 } 1104 } 1105 return $str; 1106 1032 1107 } 1033 1108 … … 1054 1129 // All conditions match 1055 1130 $this->match = True; 1131 foreach ($this->messages as $k=>$msgs) { 1132 foreach ($msgs as $i=>$m) { 1133 $this->messages[$k][$i] = $this->stringReplaceVariables($m, $vals); 1134 } 1135 } 1056 1136 // Calculate the value (i.e. shipping cost or modifier) 1057 1137 $this->value = $this->calculateShipping($vals, $products, $cartvals_callback); 1058 // Evaluate the rule name as a translatable string with variables inserted:1059 // Replace all {variable} tags in the name by the variables from $vals1060 $matches = array();1061 $name = $this->framework->__($this->name);1062 preg_match_all('/{([A-Za-z0-9_]+)}/', $name, $matches);1063 1138 1064 foreach ($matches[1] as $m) { 1065 $val = $this->evaluateVariable($m, $vals); 1066 if ($val !== null) { 1067 $name = str_replace("{".$m."}", $val, $name); 1068 } 1069 } 1070 $this->rulename = $name; 1139 $this->rulename = $this->stringReplaceVariables($this->framework->__($this->name), $vals); 1071 1140 } 1072 1141 … … 1153 1222 1154 1223 // Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression! 1155 if (preg_match('/^\s*(name|variable|definition )\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) {1224 if (preg_match('/^\s*(name|variable|definition|error|warning|message|notice|debug)\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) { 1156 1225 $this->handleAssignment ($matches[1], $matches[3], $rulepart); 1157 1226 return; -
shipping-by-rules-for-woocommerce/tags/1.2.6/readme.txt
r1485122 r1549928 3 3 Tags: WooCommerce, Shipment, Shipping, Rules shipping 4 4 Requires at least: 4.0 5 Tested up to: 4. 56 Stable tag: 1.2. 55 Tested up to: 4.7 6 Stable tag: 1.2.6 7 7 License: GPLv3 or later 8 8 License URI: http://www.gnu.org/licenses/gpl.html … … 70 70 == Changelog == 71 71 72 = 1.2.6 = 73 * Add message functionality (Error=..., Warning=..., Message=... rule parts) 74 72 75 = 1.2.5 = 73 76 * Add variables username, first_name, last_name, email -
shipping-by-rules-for-woocommerce/tags/1.2.6/woocommerce-shipping-by-rules.php
r1485122 r1549928 4 4 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html 5 5 * Description: Define Shipping cost by very general and flexible (text-based) rules. 6 * Version: 1.2. 56 * Version: 1.2.6 7 7 * Author: Open Tools, Reinhold Kainhofer 8 8 * Author URI: http://open-tools.net … … 11 11 * License: GPL2+ 12 12 * WC requires at least: 2.2 13 * WC tested up to: 2. 613 * WC tested up to: 2.7 14 14 15 15 … … 49 49 * @var string $version Plugin version number. 50 50 */ 51 public $version = '1.2. 5';51 public $version = '1.2.6'; 52 52 53 53 -
shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php
r1485122 r1549928 50 50 } 51 51 52 public function print Warning($message) {52 public function printMessage($message, $type) { 53 53 // Keep track of warning messages, so we don't print them twice: 54 global $printed_warnings; 55 if (!isset($printed_warnings)) 56 $printed_warnings = array(); 57 if (!in_array($message, $printed_warnings)) { 58 wc_add_notice( $message, 'error'); 59 $printed_warnings[] = $message; 60 } 61 } 62 63 /** @tag public-api 64 * @function debug() 65 * Print a debug message (untranslated) in the system-specific way. 66 * @param $message the debug message to be printed 67 */ 68 public function debug($message) { 69 if ( true === WP_DEBUG ) { 70 if ( is_array( $message ) || is_object( $message ) ) { 71 error_log( print_r( $message, true ) ); 72 } else { 73 error_log( $message ); 74 } 54 global $printed_messages; 55 if (!isset($printed_messages)) 56 $printed_messages = array(); 57 if ($type == "debug") { 58 if ( true === WP_DEBUG ) { 59 if ( is_array( $message ) || is_object( $message ) ) { 60 error_log( print_r( $message, true ) ); 61 } else { 62 error_log( $message ); 63 } 64 } 65 } elseif (!in_array($message, $printed_messages)) { 66 switch ($type) { 67 case 'error': 68 case 'warning': 69 wc_add_notice( $message, 'error'); break; 70 case 'message': 71 wc_add_notice( $message, 'success'); break; 72 case 'notice': 73 default: 74 wc_add_notice( $message, 'notice'); break; 75 } 76 $printed_messages[] = $message; 75 77 } 76 78 } -
shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php
r1485122 r1549928 172 172 } 173 173 174 /** @tag system-specific 175 * @function printWarning() 176 * Print a warning in the system-specific way. 177 * @param $message the warning message to be printed (already properly translated) 178 */ 179 protected function printWarning($message) { 180 echo($message); 174 /** @tag public-api 175 * @tag system-specific 176 * @function message() 177 * Print a message (to be translated) with given type in the system-specific way. 178 * @param $message the message to be printed 179 * @param $type the type of message (one of "error", "warning", "message"/"notice" or "debug") 180 * @param $args optional arguments to be inserted into the translated message in sprintf-style 181 */ 182 public function message($message, $type) { 183 $args = func_get_args(); 184 // Remove the $type from the args passed to __ 185 unset($args[1]); 186 $msg = call_user_func_array(array($this, "__"), $args); 187 $this->printMessage($msg, $type); 188 } 189 190 /** @tag public-api 191 * @tag system-specific 192 * @function error() 193 * Print an error message (to be translated) in the system-specific way. 194 * @param $message the error message to be printed 195 * @param $args optional arguments to be inserted into the translated message in sprintf-style 196 */ 197 public function error($message) { 198 $args = func_get_args(); 199 array_splice($args, 1, 0, 'error'); // insert msg type in second position 200 call_user_func_array(array($this, "message"), $args); 181 201 } 182 202 … … 190 210 public function warning($message) { 191 211 $args = func_get_args(); 192 $msg = call_user_func_array(array($this, "__"), $args);193 $this->printWarning($msg);212 array_splice($args, 1, 0, 'warning'); // insert msg type in second position 213 call_user_func_array(array($this, "message"), $args); 194 214 } 195 215 196 216 /** @tag public-api 217 * @tag system-specific 218 * @function notice() 219 * Print a message (to be translated) in the system-specific way. 220 * @param $message the message to be printed 221 * @param $args optional arguments to be inserted into the translated message in sprintf-style 222 */ 223 public function notice($message) { 224 $args = func_get_args(); 225 array_splice($args, 1, 0, 'notice'); // insert msg type in second position 226 call_user_func_array(array($this, "message"), $args); 227 } 228 229 /** @tag public-api 230 * @tag system-specific 197 231 * @function debug() 198 * Print a debug message (untranslated) in the system-specific way. 199 * @param $message the debug message to be printed 232 * Print a debug message in the system-specific way. 233 * @param $message the message to be printed 234 * @param $args optional arguments to be inserted into the translated message in sprintf-style 200 235 */ 201 236 public function debug($message) { 237 $args = func_get_args(); 238 array_splice($args, 1, 0, 'debug'); // insert msg type in second position 239 call_user_func_array(array($this, "message"), $args); 240 } 241 242 /** @tag system-specific 243 * @function printMessage() 244 * Print a message of given type in the system-specific way. 245 * @param $message the message to be printed (already properly translated) 246 * @param $type the type of message (one of "error", "warning", "message"/"notice" or "debug") 247 */ 248 protected function printMessage($message, $type) { 249 echo($message); 202 250 } 203 251 … … 417 465 break; 418 466 } 467 // Handle messages (error, warning, message/notice, debug: 468 foreach ($r->messages as $k=>$msgs) { 469 foreach ($msgs as $msg) { 470 $this->message($msg, $k); 471 } 472 } 419 473 } 420 474 if (!is_null($result["rule"])) { … … 594 648 var $ruleinfo = 0; 595 649 var $includes_tax = 0; 650 var $messages = array('error' => array(), 'warning' => array(), 'notice' => array(), 'debug' => array()); 596 651 597 652 function __construct ($framework, $rule, $countries, $ruleinfo) { … … 625 680 case 'extrashippingmultiplier': $this->shipping = $value; $this->ruletype = 'modifiers_multiply'; break; // modifiers are also stored in the shipping member! 626 681 case 'comment': break; // Completely ignore all comments! 682 case 'error': $this->messages['error'][] = $value; break; 683 case 'warning': $this->messages['warning'][] = $value; break; 684 case 'notice': 685 case 'message': $this->messages['notice'][] = $value; break; 686 case 'debug': $this->messages['debug'][] = $value; break; 627 687 case 'condition': $this->conditions[] = $value; break; 628 688 default: $this->framework->warning('OTSHIPMENT_RULES_UNKNOWN_VARIABLE', $var, $rulepart); … … 647 707 if (!isset($rulepart) || $rulepart==='') return; 648 708 649 650 709 // Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression! 651 if (preg_match('/^\s*(name|variable|definition )\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) {710 if (preg_match('/^\s*(name|variable|definition|error|warning|message|notice|debug)\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) { 652 711 $this->handleAssignment ($matches[1], $matches[3], $rulepart); 653 712 return; … … 1028 1087 } 1029 1088 1030 protected function calculateShipping ($vals, $products, $cartvals_callback) {1089 protected function calculateShipping($vals, $products, $cartvals_callback) { 1031 1090 return $this->evaluateTerm($this->shipping, $vals, $products, $cartvals_callback); 1091 } 1092 1093 protected function stringReplaceVariables($str, $vals) { 1094 // Evaluate the rule name as a translatable string with variables inserted: 1095 // Replace all {variable} tags in the name by the variables from $vals 1096 $matches = array(); 1097 preg_match_all('/{([A-Za-z0-9_]+)}/', $str, $matches); 1098 1099 foreach ($matches[1] as $m) { 1100 $val = $this->evaluateVariable($m, $vals); 1101 if ($val !== null) { 1102 $str = str_replace("{".$m."}", $val, $str); 1103 } 1104 } 1105 return $str; 1106 1032 1107 } 1033 1108 … … 1054 1129 // All conditions match 1055 1130 $this->match = True; 1131 foreach ($this->messages as $k=>$msgs) { 1132 foreach ($msgs as $i=>$m) { 1133 $this->messages[$k][$i] = $this->stringReplaceVariables($m, $vals); 1134 } 1135 } 1056 1136 // Calculate the value (i.e. shipping cost or modifier) 1057 1137 $this->value = $this->calculateShipping($vals, $products, $cartvals_callback); 1058 // Evaluate the rule name as a translatable string with variables inserted:1059 // Replace all {variable} tags in the name by the variables from $vals1060 $matches = array();1061 $name = $this->framework->__($this->name);1062 preg_match_all('/{([A-Za-z0-9_]+)}/', $name, $matches);1063 1138 1064 foreach ($matches[1] as $m) { 1065 $val = $this->evaluateVariable($m, $vals); 1066 if ($val !== null) { 1067 $name = str_replace("{".$m."}", $val, $name); 1068 } 1069 } 1070 $this->rulename = $name; 1139 $this->rulename = $this->stringReplaceVariables($this->framework->__($this->name), $vals); 1071 1140 } 1072 1141 … … 1153 1222 1154 1223 // Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression! 1155 if (preg_match('/^\s*(name|variable|definition )\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) {1224 if (preg_match('/^\s*(name|variable|definition|error|warning|message|notice|debug)\s*=\s*(["\']?)(.*)\2\s*$/i', $rulepart, $matches)) { 1156 1225 $this->handleAssignment ($matches[1], $matches[3], $rulepart); 1157 1226 return; -
shipping-by-rules-for-woocommerce/trunk/readme.txt
r1485122 r1549928 3 3 Tags: WooCommerce, Shipment, Shipping, Rules shipping 4 4 Requires at least: 4.0 5 Tested up to: 4. 56 Stable tag: 1.2. 55 Tested up to: 4.7 6 Stable tag: 1.2.6 7 7 License: GPLv3 or later 8 8 License URI: http://www.gnu.org/licenses/gpl.html … … 70 70 == Changelog == 71 71 72 = 1.2.6 = 73 * Add message functionality (Error=..., Warning=..., Message=... rule parts) 74 72 75 = 1.2.5 = 73 76 * Add variables username, first_name, last_name, email -
shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php
r1485122 r1549928 4 4 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html 5 5 * Description: Define Shipping cost by very general and flexible (text-based) rules. 6 * Version: 1.2. 56 * Version: 1.2.6 7 7 * Author: Open Tools, Reinhold Kainhofer 8 8 * Author URI: http://open-tools.net … … 11 11 * License: GPL2+ 12 12 * WC requires at least: 2.2 13 * WC tested up to: 2. 613 * WC tested up to: 2.7 14 14 15 15 … … 49 49 * @var string $version Plugin version number. 50 50 */ 51 public $version = '1.2. 5';51 public $version = '1.2.6'; 52 52 53 53
Note: See TracChangeset
for help on using the changeset viewer.