Plugin Directory

Changeset 1424902


Ignore:
Timestamp:
05/26/2016 05:48:14 PM (10 years ago)
Author:
opentools
Message:

V1.3.4: Fix all time variables to use the WP time zone; Fix issues with callback functions in PHP 5.3

Location:
woocommerce-basic-ordernumbers
Files:
3 edited
14 copied

Legend:

Unmodified
Added
Removed
  • woocommerce-basic-ordernumbers/tags/1.3.4/library/ordernumber_helper.php

    r1355159 r1424902  
    1717class OrdernumberHelper {
    1818    static $_version = "0.1";
    19     protected $_callbacks = array();
     19    protected $callbacks = array();
    2020    public $_styles = array(
    2121        'counter-table-class' => "table-striped",
     
    104104    public function __($string) {
    105105        if (isset($this->callbacks["translate"])) {
    106             return $this->callbacks["translate"]($string);
     106            return call_user_func_array($this->callbacks['translate'], func_get_args());
    107107        } else {
    108108            return $string;
     
    143143    public function urlPath($type, $file) {
    144144        if (isset($this->callbacks['urlPath'])) {
    145             return $this->callbacks['urlPath']($type, $file);
     145            return call_user_func_array($this->callbacks['urlPath'], func_get_args());
    146146        } else {
    147147            throw new Exception('No callback defined for urlPath(type, file)!');
     
    151151    protected function replacementsCallback ($func, &$reps, $details, $nrtype) {
    152152        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));
    154154        }
    155155    }
     
    157157    protected function getCounter($type, $countername, $default) {
    158158        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());
    160160        } else {
    161161            throw new Exception('No callback defined for getCounter(type, countername, default)!');
     
    165165    protected function setCounter($type, $countername, $value) {
    166166        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());
    168168        } else {
    169169            throw new Exception('No callback defined for setCounter(type, countername, value)!');
     
    172172   
    173173    public function getAllCounters($type) {
    174         if (isset($this->callbacks['getCounter'])) {
    175             return $this->callbacks['getCounter']($type);
     174        if (isset($this->callbacks['getAllCounters'])) {
     175            return call_user_func_array($this->callbacks['getAllCounters'], func_get_args());
    176176        } else {
    177177            throw new Exception ('No callback defined for getAllCounters(type)!');
     
    227227        return self::randomString ($alphabet, $len);
    228228    }
     229   
     230    public function getDateTime($utime) {
     231        $time = new DateTime();
     232        $time->setTimestamp($utime);
     233        return $time;
     234    }
    229235
    230236    public function setupDateTimeReplacements (&$reps, $details, $nrtype) {
    231237        $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");
    241248        $milliseconds = (int)(1000*($utime - (int)$utime));
    242249        $millisecondsstring = sprintf('%03d', $milliseconds);
     
    404411        $ctrsettings = $this->extractCounterSettings ($format, $type, $ctrsettings);
    405412
    406 // JFactory::getApplication()->enqueueMessage("<pre>Replacements for $type:".print_r($reps,1)."</pre>", 'error');
    407413        // Increment the counter only if the format contains a placeholder for it!
    408414        if (strpos($ctrsettings["${type}_format"], "#") !== false) {
  • woocommerce-basic-ordernumbers/tags/1.3.4/ordernumber_helper_woocommerce.php

    r1355159 r1424902  
    1212if (!class_exists( 'OrdernumberHelper' ))
    1313    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 */
     22function 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}
    1452
    1553class OrdernumberHelperWooCommerce extends OrdernumberHelper {
     
    3270        return $helper;
    3371    }
     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
    3480   
    3581    /**
  • woocommerce-basic-ordernumbers/tags/1.3.4/readme.txt

    r1401707 r1424902  
    55Requires at least: 4.0
    66Tested up to: 4.5
    7 Stable tag: 1.3.3
     7Stable tag: 1.3.4
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl.html
     
    7979== Changelog ==
    8080
     81= 1.3.4 =
     82* Fix all time variables to use the timezone configured for WordPress
     83
    8184= 1.3.3 =
    8285* Fix issue with order tracking (which assumed order IDs were entered)
  • woocommerce-basic-ordernumbers/trunk/library/ordernumber_helper.php

    r1355159 r1424902  
    1717class OrdernumberHelper {
    1818    static $_version = "0.1";
    19     protected $_callbacks = array();
     19    protected $callbacks = array();
    2020    public $_styles = array(
    2121        'counter-table-class' => "table-striped",
     
    104104    public function __($string) {
    105105        if (isset($this->callbacks["translate"])) {
    106             return $this->callbacks["translate"]($string);
     106            return call_user_func_array($this->callbacks['translate'], func_get_args());
    107107        } else {
    108108            return $string;
     
    143143    public function urlPath($type, $file) {
    144144        if (isset($this->callbacks['urlPath'])) {
    145             return $this->callbacks['urlPath']($type, $file);
     145            return call_user_func_array($this->callbacks['urlPath'], func_get_args());
    146146        } else {
    147147            throw new Exception('No callback defined for urlPath(type, file)!');
     
    151151    protected function replacementsCallback ($func, &$reps, $details, $nrtype) {
    152152        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));
    154154        }
    155155    }
     
    157157    protected function getCounter($type, $countername, $default) {
    158158        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());
    160160        } else {
    161161            throw new Exception('No callback defined for getCounter(type, countername, default)!');
     
    165165    protected function setCounter($type, $countername, $value) {
    166166        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());
    168168        } else {
    169169            throw new Exception('No callback defined for setCounter(type, countername, value)!');
     
    172172   
    173173    public function getAllCounters($type) {
    174         if (isset($this->callbacks['getCounter'])) {
    175             return $this->callbacks['getCounter']($type);
     174        if (isset($this->callbacks['getAllCounters'])) {
     175            return call_user_func_array($this->callbacks['getAllCounters'], func_get_args());
    176176        } else {
    177177            throw new Exception ('No callback defined for getAllCounters(type)!');
     
    227227        return self::randomString ($alphabet, $len);
    228228    }
     229   
     230    public function getDateTime($utime) {
     231        $time = new DateTime();
     232        $time->setTimestamp($utime);
     233        return $time;
     234    }
    229235
    230236    public function setupDateTimeReplacements (&$reps, $details, $nrtype) {
    231237        $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");
    241248        $milliseconds = (int)(1000*($utime - (int)$utime));
    242249        $millisecondsstring = sprintf('%03d', $milliseconds);
     
    404411        $ctrsettings = $this->extractCounterSettings ($format, $type, $ctrsettings);
    405412
    406 // JFactory::getApplication()->enqueueMessage("<pre>Replacements for $type:".print_r($reps,1)."</pre>", 'error');
    407413        // Increment the counter only if the format contains a placeholder for it!
    408414        if (strpos($ctrsettings["${type}_format"], "#") !== false) {
  • woocommerce-basic-ordernumbers/trunk/ordernumber_helper_woocommerce.php

    r1355159 r1424902  
    1212if (!class_exists( 'OrdernumberHelper' ))
    1313    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 */
     22function 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}
    1452
    1553class OrdernumberHelperWooCommerce extends OrdernumberHelper {
     
    3270        return $helper;
    3371    }
     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
    3480   
    3581    /**
  • woocommerce-basic-ordernumbers/trunk/readme.txt

    r1401707 r1424902  
    55Requires at least: 4.0
    66Tested up to: 4.5
    7 Stable tag: 1.3.3
     7Stable tag: 1.3.4
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl.html
     
    7979== Changelog ==
    8080
     81= 1.3.4 =
     82* Fix all time variables to use the timezone configured for WordPress
     83
    8184= 1.3.3 =
    8285* Fix issue with order tracking (which assumed order IDs were entered)
Note: See TracChangeset for help on using the changeset viewer.