Changeset 1424902
- Timestamp:
- 05/26/2016 05:48:14 PM (10 years ago)
- Location:
- woocommerce-basic-ordernumbers
- Files:
-
- 3 edited
- 14 copied
-
tags/1.3.4 (copied) (copied from woocommerce-basic-ordernumbers/trunk)
-
tags/1.3.4/assets/css/opentools-updatecheck.css (copied) (copied from woocommerce-basic-ordernumbers/trunk/assets/css/opentools-updatecheck.css)
-
tags/1.3.4/assets/js/opentools-updatecheck.js (copied) (copied from woocommerce-basic-ordernumbers/trunk/assets/js/opentools-updatecheck.js)
-
tags/1.3.4/library/css/index.html (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/css/index.html)
-
tags/1.3.4/library/css/ordernumber.css (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/css/ordernumber.css)
-
tags/1.3.4/library/images/index.html (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/images/index.html)
-
tags/1.3.4/library/index.html (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/index.html)
-
tags/1.3.4/library/js/index.html (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/js/index.html)
-
tags/1.3.4/library/js/ordernumber.js (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/js/ordernumber.js)
-
tags/1.3.4/library/ordernumber_helper.php (copied) (copied from woocommerce-basic-ordernumbers/trunk/library/ordernumber_helper.php) (9 diffs)
-
tags/1.3.4/ordernumber_helper_woocommerce.php (copied) (copied from woocommerce-basic-ordernumbers/trunk/ordernumber_helper_woocommerce.php) (2 diffs)
-
tags/1.3.4/ordernumbers_woocommerce_basic.php (copied) (copied from woocommerce-basic-ordernumbers/trunk/ordernumbers_woocommerce_basic.php)
-
tags/1.3.4/readme.txt (copied) (copied from woocommerce-basic-ordernumbers/trunk/readme.txt) (2 diffs)
-
tags/1.3.4/woocommerce-basic-ordernumbers.php (copied) (copied from woocommerce-basic-ordernumbers/trunk/woocommerce-basic-ordernumbers.php)
-
trunk/library/ordernumber_helper.php (modified) (9 diffs)
-
trunk/ordernumber_helper_woocommerce.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-basic-ordernumbers/tags/1.3.4/library/ordernumber_helper.php
r1355159 r1424902 17 17 class OrdernumberHelper { 18 18 static $_version = "0.1"; 19 protected $ _callbacks = array();19 protected $callbacks = array(); 20 20 public $_styles = array( 21 21 'counter-table-class' => "table-striped", … … 104 104 public function __($string) { 105 105 if (isset($this->callbacks["translate"])) { 106 return $this->callbacks["translate"]($string);106 return call_user_func_array($this->callbacks['translate'], func_get_args()); 107 107 } else { 108 108 return $string; … … 143 143 public function urlPath($type, $file) { 144 144 if (isset($this->callbacks['urlPath'])) { 145 return $this->callbacks['urlPath']($type, $file);145 return call_user_func_array($this->callbacks['urlPath'], func_get_args()); 146 146 } else { 147 147 throw new Exception('No callback defined for urlPath(type, file)!'); … … 151 151 protected function replacementsCallback ($func, &$reps, $details, $nrtype) { 152 152 if (isset($this->callbacks[$func])) { 153 return $this->callbacks[$func]($reps, $details, $nrtype);153 return call_user_func_array($this->callbacks[$func], array(&$reps, $details, $nrtype)); 154 154 } 155 155 } … … 157 157 protected function getCounter($type, $countername, $default) { 158 158 if (isset($this->callbacks['getCounter'])) { 159 return $this->callbacks['getCounter']($type, $countername, $default);159 return call_user_func_array($this->callbacks['getCounter'], func_get_args()); 160 160 } else { 161 161 throw new Exception('No callback defined for getCounter(type, countername, default)!'); … … 165 165 protected function setCounter($type, $countername, $value) { 166 166 if (isset($this->callbacks['getCounter'])) { 167 return $this->callbacks['getCounter']($type, $countername, $value);167 return call_user_func_array($this->callbacks['setCounter'], func_get_args()); 168 168 } else { 169 169 throw new Exception('No callback defined for setCounter(type, countername, value)!'); … … 172 172 173 173 public function getAllCounters($type) { 174 if (isset($this->callbacks['get Counter'])) {175 return $this->callbacks['getCounter']($type);174 if (isset($this->callbacks['getAllCounters'])) { 175 return call_user_func_array($this->callbacks['getAllCounters'], func_get_args()); 176 176 } else { 177 177 throw new Exception ('No callback defined for getAllCounters(type)!'); … … 227 227 return self::randomString ($alphabet, $len); 228 228 } 229 230 public function getDateTime($utime) { 231 $time = new DateTime(); 232 $time->setTimestamp($utime); 233 return $time; 234 } 229 235 230 236 public function setupDateTimeReplacements (&$reps, $details, $nrtype) { 231 237 $utime = microtime(true); 232 $reps["[year]"] = date ("Y", $utime); 233 $reps["[year2]"] = date ("y", $utime); 234 $reps["[month]"] = date("m", $utime); 235 $reps["[day]"] = date("d", $utime); 236 $reps["[hour]"] = date("H", $utime); 237 $reps["[hour12]"] = date("h", $utime); 238 $reps["[ampm]"] = date("a", $utime); 239 $reps["[minute]"] = date("i", $utime); 240 $reps["[second]"] = date("s", $utime); 238 $time = $this->getDateTime($utime); 239 $reps["[year]"] = $time->format ("Y"); 240 $reps["[year2]"] = $time->format ("y"); 241 $reps["[month]"] = $time->format("m"); 242 $reps["[day]"] = $time->format("d"); 243 $reps["[hour]"] = $time->format("H"); 244 $reps["[hour12]"] = $time->format("h"); 245 $reps["[ampm]"] = $time->format("a"); 246 $reps["[minute]"] = $time->format("i"); 247 $reps["[second]"] = $time->format("s"); 241 248 $milliseconds = (int)(1000*($utime - (int)$utime)); 242 249 $millisecondsstring = sprintf('%03d', $milliseconds); … … 404 411 $ctrsettings = $this->extractCounterSettings ($format, $type, $ctrsettings); 405 412 406 // JFactory::getApplication()->enqueueMessage("<pre>Replacements for $type:".print_r($reps,1)."</pre>", 'error');407 413 // Increment the counter only if the format contains a placeholder for it! 408 414 if (strpos($ctrsettings["${type}_format"], "#") !== false) { -
woocommerce-basic-ordernumbers/tags/1.3.4/ordernumber_helper_woocommerce.php
r1355159 r1424902 12 12 if (!class_exists( 'OrdernumberHelper' )) 13 13 require_once (dirname(__FILE__) . '/library/ordernumber_helper.php'); 14 15 /** 16 * Returns the timezone string for a site, even if it's set to a UTC offset 17 * 18 * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155 19 * 20 * @return string valid PHP timezone string 21 */ 22 function wp_get_timezone_string() { 23 // if site timezone string exists, return it 24 if ( $timezone = get_option( 'timezone_string' ) ) 25 return $timezone; 26 27 // get UTC offset, if it isn't set then return UTC 28 if ( 0 === ( $utc_offset = get_option( 'gmt_offset', 0 ) ) ) 29 return 'UTC'; 30 31 // adjust UTC offset from hours to seconds 32 $utc_offset *= 3600; 33 34 // attempt to guess the timezone string from the UTC offset 35 if ( $timezone = timezone_name_from_abbr( '', $utc_offset, 0 ) ) { 36 return $timezone; 37 } 38 39 // last try, guess timezone string manually 40 $is_dst = date( 'I' ); 41 42 foreach ( timezone_abbreviations_list() as $abbr ) { 43 foreach ( $abbr as $city ) { 44 if ( $city['dst'] == $is_dst && $city['offset'] == $utc_offset ) 45 return $city['timezone_id']; 46 } 47 } 48 49 // fallback to UTC 50 return 'UTC'; 51 } 14 52 15 53 class OrdernumberHelperWooCommerce extends OrdernumberHelper { … … 32 70 return $helper; 33 71 } 72 73 public function getDateTime($utime) { 74 $time = new DateTime(); 75 $time->setTimestamp($utime); 76 $time->setTimezone(new DateTimeZone(wp_get_timezone_string())); 77 return $time; 78 } 79 34 80 35 81 /** -
woocommerce-basic-ordernumbers/tags/1.3.4/readme.txt
r1401707 r1424902 5 5 Requires at least: 4.0 6 6 Tested up to: 4.5 7 Stable tag: 1.3. 37 Stable tag: 1.3.4 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl.html … … 79 79 == Changelog == 80 80 81 = 1.3.4 = 82 * Fix all time variables to use the timezone configured for WordPress 83 81 84 = 1.3.3 = 82 85 * Fix issue with order tracking (which assumed order IDs were entered) -
woocommerce-basic-ordernumbers/trunk/library/ordernumber_helper.php
r1355159 r1424902 17 17 class OrdernumberHelper { 18 18 static $_version = "0.1"; 19 protected $ _callbacks = array();19 protected $callbacks = array(); 20 20 public $_styles = array( 21 21 'counter-table-class' => "table-striped", … … 104 104 public function __($string) { 105 105 if (isset($this->callbacks["translate"])) { 106 return $this->callbacks["translate"]($string);106 return call_user_func_array($this->callbacks['translate'], func_get_args()); 107 107 } else { 108 108 return $string; … … 143 143 public function urlPath($type, $file) { 144 144 if (isset($this->callbacks['urlPath'])) { 145 return $this->callbacks['urlPath']($type, $file);145 return call_user_func_array($this->callbacks['urlPath'], func_get_args()); 146 146 } else { 147 147 throw new Exception('No callback defined for urlPath(type, file)!'); … … 151 151 protected function replacementsCallback ($func, &$reps, $details, $nrtype) { 152 152 if (isset($this->callbacks[$func])) { 153 return $this->callbacks[$func]($reps, $details, $nrtype);153 return call_user_func_array($this->callbacks[$func], array(&$reps, $details, $nrtype)); 154 154 } 155 155 } … … 157 157 protected function getCounter($type, $countername, $default) { 158 158 if (isset($this->callbacks['getCounter'])) { 159 return $this->callbacks['getCounter']($type, $countername, $default);159 return call_user_func_array($this->callbacks['getCounter'], func_get_args()); 160 160 } else { 161 161 throw new Exception('No callback defined for getCounter(type, countername, default)!'); … … 165 165 protected function setCounter($type, $countername, $value) { 166 166 if (isset($this->callbacks['getCounter'])) { 167 return $this->callbacks['getCounter']($type, $countername, $value);167 return call_user_func_array($this->callbacks['setCounter'], func_get_args()); 168 168 } else { 169 169 throw new Exception('No callback defined for setCounter(type, countername, value)!'); … … 172 172 173 173 public function getAllCounters($type) { 174 if (isset($this->callbacks['get Counter'])) {175 return $this->callbacks['getCounter']($type);174 if (isset($this->callbacks['getAllCounters'])) { 175 return call_user_func_array($this->callbacks['getAllCounters'], func_get_args()); 176 176 } else { 177 177 throw new Exception ('No callback defined for getAllCounters(type)!'); … … 227 227 return self::randomString ($alphabet, $len); 228 228 } 229 230 public function getDateTime($utime) { 231 $time = new DateTime(); 232 $time->setTimestamp($utime); 233 return $time; 234 } 229 235 230 236 public function setupDateTimeReplacements (&$reps, $details, $nrtype) { 231 237 $utime = microtime(true); 232 $reps["[year]"] = date ("Y", $utime); 233 $reps["[year2]"] = date ("y", $utime); 234 $reps["[month]"] = date("m", $utime); 235 $reps["[day]"] = date("d", $utime); 236 $reps["[hour]"] = date("H", $utime); 237 $reps["[hour12]"] = date("h", $utime); 238 $reps["[ampm]"] = date("a", $utime); 239 $reps["[minute]"] = date("i", $utime); 240 $reps["[second]"] = date("s", $utime); 238 $time = $this->getDateTime($utime); 239 $reps["[year]"] = $time->format ("Y"); 240 $reps["[year2]"] = $time->format ("y"); 241 $reps["[month]"] = $time->format("m"); 242 $reps["[day]"] = $time->format("d"); 243 $reps["[hour]"] = $time->format("H"); 244 $reps["[hour12]"] = $time->format("h"); 245 $reps["[ampm]"] = $time->format("a"); 246 $reps["[minute]"] = $time->format("i"); 247 $reps["[second]"] = $time->format("s"); 241 248 $milliseconds = (int)(1000*($utime - (int)$utime)); 242 249 $millisecondsstring = sprintf('%03d', $milliseconds); … … 404 411 $ctrsettings = $this->extractCounterSettings ($format, $type, $ctrsettings); 405 412 406 // JFactory::getApplication()->enqueueMessage("<pre>Replacements for $type:".print_r($reps,1)."</pre>", 'error');407 413 // Increment the counter only if the format contains a placeholder for it! 408 414 if (strpos($ctrsettings["${type}_format"], "#") !== false) { -
woocommerce-basic-ordernumbers/trunk/ordernumber_helper_woocommerce.php
r1355159 r1424902 12 12 if (!class_exists( 'OrdernumberHelper' )) 13 13 require_once (dirname(__FILE__) . '/library/ordernumber_helper.php'); 14 15 /** 16 * Returns the timezone string for a site, even if it's set to a UTC offset 17 * 18 * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155 19 * 20 * @return string valid PHP timezone string 21 */ 22 function wp_get_timezone_string() { 23 // if site timezone string exists, return it 24 if ( $timezone = get_option( 'timezone_string' ) ) 25 return $timezone; 26 27 // get UTC offset, if it isn't set then return UTC 28 if ( 0 === ( $utc_offset = get_option( 'gmt_offset', 0 ) ) ) 29 return 'UTC'; 30 31 // adjust UTC offset from hours to seconds 32 $utc_offset *= 3600; 33 34 // attempt to guess the timezone string from the UTC offset 35 if ( $timezone = timezone_name_from_abbr( '', $utc_offset, 0 ) ) { 36 return $timezone; 37 } 38 39 // last try, guess timezone string manually 40 $is_dst = date( 'I' ); 41 42 foreach ( timezone_abbreviations_list() as $abbr ) { 43 foreach ( $abbr as $city ) { 44 if ( $city['dst'] == $is_dst && $city['offset'] == $utc_offset ) 45 return $city['timezone_id']; 46 } 47 } 48 49 // fallback to UTC 50 return 'UTC'; 51 } 14 52 15 53 class OrdernumberHelperWooCommerce extends OrdernumberHelper { … … 32 70 return $helper; 33 71 } 72 73 public function getDateTime($utime) { 74 $time = new DateTime(); 75 $time->setTimestamp($utime); 76 $time->setTimezone(new DateTimeZone(wp_get_timezone_string())); 77 return $time; 78 } 79 34 80 35 81 /** -
woocommerce-basic-ordernumbers/trunk/readme.txt
r1401707 r1424902 5 5 Requires at least: 4.0 6 6 Tested up to: 4.5 7 Stable tag: 1.3. 37 Stable tag: 1.3.4 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl.html … … 79 79 == Changelog == 80 80 81 = 1.3.4 = 82 * Fix all time variables to use the timezone configured for WordPress 83 81 84 = 1.3.3 = 82 85 * Fix issue with order tracking (which assumed order IDs were entered)
Note: See TracChangeset
for help on using the changeset viewer.