Beispiel #1
0
function parse_time($d, $reference = null)
{
    global $Now, $Opt;
    if ($reference === null) {
        $reference = $Now;
    }
    if (!isset($Opt["dateFormatTimezoneRemover"]) && function_exists("timezone_abbreviations_list")) {
        $mytz = date_default_timezone_get();
        $x = array();
        foreach (timezone_abbreviations_list() as $tzname => $tzinfo) {
            foreach ($tzinfo as $tz) {
                if ($tz["timezone_id"] == $mytz) {
                    $x[] = preg_quote($tzname);
                }
            }
        }
        if (count($x) == 0) {
            $x[] = preg_quote(date("T", $reference));
        }
        $Opt["dateFormatTimezoneRemover"] = "/(?:\\s|\\A)(?:" . join("|", $x) . ")(?:\\s|\\z)/i";
    }
    if (@$Opt["dateFormatTimezoneRemover"]) {
        $d = preg_replace($Opt["dateFormatTimezoneRemover"], " ", $d);
    }
    $d = preg_replace('/\\butc([-+])/i', 'GMT$1', $d);
    return strtotime($d, $reference);
}
 public static function get_timezone_id()
 {
     // if site timezone string exists, return it
     if ($timezone = get_option('timezone_string')) {
         return $timezone;
     }
     // get UTC offset, if it isn't set return UTC
     if (!($utc_offset = 3600 * get_option('gmt_offset', 0))) {
         return 'UTC';
     }
     // attempt to guess the timezone string from the UTC offset
     $timezone = timezone_name_from_abbr('', $utc_offset);
     // last try, guess timezone string manually
     if (FALSE === $timezone) {
         $is_dst = date('I');
         foreach (timezone_abbreviations_list() as $abbr) {
             foreach ($abbr as $city) {
                 if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                     return $city['timezone_id'];
                 }
             }
         }
     }
     return 'UTC';
     // fallback
 }
 public static function get_local_timezone($reset = FALSE)
 {
     if ($reset) {
         self::$local_timezone = NULL;
     }
     if (!isset(self::$local_timezone)) {
         $tzstring = get_option('timezone_string');
         if (empty($tzstring)) {
             $gmt_offset = get_option('gmt_offset');
             if ($gmt_offset == 0) {
                 $tzstring = 'UTC';
             } else {
                 $gmt_offset *= HOUR_IN_SECONDS;
                 $tzstring = timezone_name_from_abbr('', $gmt_offset);
                 if (false === $tzstring) {
                     $is_dst = date('I');
                     foreach (timezone_abbreviations_list() as $abbr) {
                         foreach ($abbr as $city) {
                             if ($city['dst'] == $is_dst && $city['offset'] == $gmt_offset) {
                                 $tzstring = $city['timezone_id'];
                                 break 2;
                             }
                         }
                     }
                 }
                 if (false === $tzstring) {
                     $tzstring = 'UTC';
                 }
             }
         }
         self::$local_timezone = new DateTimeZone($tzstring);
     }
     return self::$local_timezone;
 }
Beispiel #4
0
function setTimezoneByOffset($offset)
{
    date_default_timezone_set('UTC');
    $testTimestamp = time();
    $testLocaltime = localtime($testTimestamp, true);
    $testHour = $testLocaltime['tm_hour'];
    $abbrarray = timezone_abbreviations_list();
    foreach ($abbrarray as $abbr) {
        foreach ($abbr as $city) {
            $val = false;
            if ($city['timezone_id'] != 'Factory' && '' . @$city['timezone_id'] > '') {
                if (isset($city['timezone_id'])) {
                    $val = date_default_timezone_set($city['timezone_id']);
                    if ($val) {
                        $testLocaltime = localtime($testTimestamp, true);
                        $hour = $testLocaltime['tm_hour'];
                        $testOffset = $hour - $testHour;
                        if ($testOffset == $offset || $testOffset == $offset + 24) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    date_default_timezone_set('UTC');
    return false;
}
 /**
  * Returns the timezone string for a site, even if it's set to a UTC offset
  *
  * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
  *
  * @return string valid PHP timezone string
  */
 private function determine_timezone_string()
 {
     // If site timezone string exists, return it.
     if ($timezone = get_option('timezone_string')) {
         return $timezone;
     }
     // Get UTC offset, if it isn't set then return UTC.
     if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
         return 'UTC';
     }
     // Adjust UTC offset from hours to seconds.
     $utc_offset *= HOUR_IN_SECONDS;
     // Attempt to guess the timezone string from the UTC offset.
     $timezone = timezone_name_from_abbr('', $utc_offset);
     // Last try, guess timezone string manually.
     if (false === $timezone) {
         $is_dst = date('I');
         foreach (timezone_abbreviations_list() as $abbr) {
             foreach ($abbr as $city) {
                 if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                     return $city['timezone_id'];
                 }
             }
         }
     }
     // Fallback to UTC.
     return 'UTC';
 }
 /**
  * Returns the timezone string for a site, even if it's set to a UTC offset
  *
  * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
  *
  * @return string valid PHP timezone string
  */
 private static function wp_get_timezone_string()
 {
     $blog_timezone = get_option('timezone_string');
     $blog_gmt_offset = get_option('gmt_offset', 0);
     // if site timezone string exists, return it
     if ($timezone = $blog_timezone) {
         return $timezone;
     }
     // get UTC offset, if it isn't set then return UTC
     if (0 === ($utc_offset = $blog_gmt_offset)) {
         return 'UTC';
     }
     // adjust UTC offset from hours to seconds
     $utc_offset *= 3600;
     // attempt to guess the timezone string from the UTC offset
     if ($timezone = timezone_name_from_abbr('', $utc_offset, 0)) {
         return $timezone;
     }
     // last try, guess timezone string manually
     $is_dst = date('I');
     foreach (timezone_abbreviations_list() as $abbr) {
         foreach ($abbr as $city) {
             if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                 return $city['timezone_id'];
             }
         }
     }
     // fallback to UTC
     return 'UTC';
 }
 public function validTimezone($timezone)
 {
     $validTimezones = array();
     $availableTimezones = timezone_abbreviations_list();
     foreach ($availableTimezones as $zone) {
         foreach ($zone as $item) {
             $validTimezones[$item['timezone_id']] = true;
         }
     }
     unset($validTimezones['']);
     return isset($validTimezones[$timezone]);
 }
Beispiel #8
0
 function getTimezoneByOffset($offset)
 {
     $offset *= 3600;
     // convert hour offset to seconds
     $abbrarray = timezone_abbreviations_list();
     foreach ($abbrarray as $abbr) {
         foreach ($abbr as $city) {
             if ($city['offset'] == $offset) {
                 return $city['timezone_id'];
             }
         }
     }
     return false;
 }
/**
 * Returns possible timezones as:
 * array(
 * 	'<timezone name>' => <true for DST, false otherwise>,
 * 	...
 * )
 *
 * @return array
 */
function get_timezones()
{
    $timezones = array();
    foreach (timezone_abbreviations_list() as $tz_abbreviation) {
        foreach ($tz_abbreviation as $timezone) {
            if (strlen($timezone['timezone_id']) === 0) {
                continue;
            }
            $timezones[$timezone['timezone_id']] = $timezone['dst'];
        }
    }
    ksort($timezones);
    return $timezones;
}
Beispiel #10
0
 /**
  * Timezone name
  * 
  * @param  sting  $offset
  * 
  * @return timezone name
  */
 public static function tzOffsetToName($offset)
 {
     $offset *= 3600;
     // convert hour offset to seconds
     $abbrarray = timezone_abbreviations_list();
     foreach ($abbrarray as $abbr) {
         foreach ($abbr as $city) {
             if ($city['offset'] == $offset) {
                 return $city['timezone_id'];
             }
         }
     }
     return FALSE;
 }
 /**
  * all this method does is take an incoming GMT offset value ( e.g. "+1" or "-4" ) and returns a corresponding valid DateTimeZone() timezone_string.
  * @param  string $offset GMT offset
  * @return string         timezone_string (valid for DateTimeZone)
  */
 private static function _timezone_convert_to_string_from_offset($offset)
 {
     //shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable
     $offset *= 3600;
     // convert hour offset to seconds
     $abbrarray = timezone_abbreviations_list();
     foreach ($abbrarray as $abbr) {
         foreach ($abbr as $city) {
             if ($city['offset'] === $offset && $city['dst'] === FALSE) {
                 return $city['timezone_id'];
             }
         }
     }
     return FALSE;
 }
Beispiel #12
0
 public function set_tz_by_offset($offset)
 {
     $offset = $offset * 60 * 60;
     $abbrarray = timezone_abbreviations_list();
     foreach ($abbrarray as $abbr) {
         foreach ($abbr as $city) {
             if ($city['offset'] == $offset) {
                 // remember to multiply $offset by -1 if you're getting it from js
                 date_default_timezone_set($city['timezone_id']);
                 return true;
             }
         }
     }
     date_default_timezone_set("ust");
     return false;
 }
Beispiel #13
0
function set_time_zone($time_zone)
{
    if (preg_match('/(\\+|-)([0-9]{2}):([0-9]{2})/', $time_zone, $matches)) {
        list(, $sign, $hours, $minutes) = $matches;
        $offset = ($sign == '+' ? 1 : -1) * ((int) $hours * 3600 + (int) $minutes * 60);
        if (($time_zone = timezone_name_from_abbr('', $offset, 0)) === FALSE) {
            foreach (timezone_abbreviations_list() as $abbr) {
                foreach ($abbr as $zone) {
                    if (!$zone['dst'] && $zone['offset'] == $offset) {
                        return date_default_timezone_set($zone['timezone_id']);
                    }
                }
            }
        }
    }
    return $time_zone ? date_default_timezone_set($time_zone) : FALSE;
}
Beispiel #14
0
function TSfromLocalTS($ts)
{
    $ts = (int) $ts;
    $uid = (int) sUserMgr()->getCurrentUserID();
    $user = new User($uid);
    $user_timezone = $user->properties->getValue('TIMEZONE');
    $tz = null;
    $offset = null;
    $timezoneAbbreviations = timezone_abbreviations_list();
    foreach ($timezoneAbbreviations as $timezoneAbbreviations_item) {
        foreach ($timezoneAbbreviations_item as $timezone_item) {
            if ($timezone_item['timezone_id'] == $user_timezone) {
                $tz = $timezone_item;
                $offset = $timezone_item['offset'];
            }
        }
    }
    //Windows special fallback
    if (!$tz) {
        switch ($user_timezone) {
            case 'Etc/GMT-11':
                $offset = -39600;
                break;
            case 'Etc/GMT-2':
                $offset = -7200;
                break;
            case 'Atlantic/South_Georgia':
                $offset = -7200;
                break;
            case 'GMT':
                $offset = 0;
                break;
            case 'Etc/GMT+12':
                $offset = 43200;
                break;
        }
    }
    // Save original timezone
    $currentTimeZone = date_default_timezone_get();
    // Get offset of user timezone
    date_default_timezone_set($user_timezone);
    $realOffset = date('Z', $ts);
    // Reset original timezone
    date_default_timezone_set($currentTimeZone);
    return $ts - $realOffset;
}
 public static function getTz_array()
 {
     $tz_array = array();
     foreach (timezone_abbreviations_list() as $abbr => $array) {
         foreach ($array as $id => $array2) {
             $offset = $array2['offset'];
             $timezone_id = $array2['timezone_id'];
             //$tz_byTimeZone[$timezone_id]	= format_time($offset);
             //$tz_byOffset[format_time($offset)]	= $timezone_id;
             $tz_array[$timezone_id] = array('timezone_id' => $timezone_id, 'offset' => TimezoneController::format_time($offset), 'int_offset' => round($offset / 60, 0));
         }
         //exit;
     }
     usort($tz_array, function ($a, $b) {
         return $a['offset'] - $b['offset'];
     });
     return $tz_array;
 }
Beispiel #16
0
function set_tz_by_offset($offset)
{
    global $defaultimeZone;
    $offset = $offset * 60 * 60;
    $abbrarray = timezone_abbreviations_list();
    foreach ($abbrarray as $abbr) {
        //echo $abbr."<br>";
        foreach ($abbr as $city) {
            //echo $city['offset']." $offset<br>";
            if ($city['offset'] == $offset) {
                // remember to multiply $offset by -1 if you're getting it from js
                date_default_timezone_set($city['timezone_id']);
                return true;
            }
        }
    }
    date_default_timezone_set($defaultimeZone);
    return false;
}
Beispiel #17
0
function setTimezoneByOffset($offset)
{
    $testTimestamp = time();
    date_default_timezone_set('UTC');
    $testLocaltime = localtime($testTimestamp, true);
    $testHour = $testLocaltime['tm_hour'];
    $abbrarray = timezone_abbreviations_list();
    foreach ($abbrarray as $abbr) {
        //echo $abbr."<br>";
        foreach ($abbr as $city) {
            date_default_timezone_set($city['timezone_id']);
            $testLocaltime = localtime($testTimestamp, true);
            $hour = $testLocaltime['tm_hour'];
            $testOffset = $hour - $testHour;
            if ($testOffset == $offset) {
                return true;
            }
        }
    }
    return false;
}
Beispiel #18
0
 public static function tzOffsetToName($offset, $isDst = null)
 {
     if ($isDst === null) {
         $isDst = date('I');
     }
     $zone = timezone_name_from_abbr('', $offset, $isDst);
     if ($zone === false) {
         foreach (timezone_abbreviations_list() as $abbr) {
             foreach ($abbr as $city) {
                 if ((bool) $city['dst'] === (bool) $isDst && strlen($city['timezone_id']) > 0 && $city['offset'] == $offset) {
                     $zone = $city['timezone_id'];
                     break;
                 }
             }
             if ($zone !== false) {
                 break;
             }
         }
     }
     return $zone;
 }
Beispiel #19
0
 protected function testTimezone($part)
 {
     if (self::$timeZoneList === null) {
         $idArray = array_keys(timezone_abbreviations_list());
         self::$timeZoneList = [];
         foreach ($idArray as $id) {
             if (strlen($id) > 1) {
                 // 'a' is really a timezone?
                 self::$timeZoneList[] = strtolower($id);
                 self::$timeZoneList[] = strtoupper($id);
             }
         }
         $idArray = \DateTimeZone::listIdentifiers();
         foreach ($idArray as $id) {
             self::$timeZoneList[] = strtolower($id);
             self::$timeZoneList[] = strtoupper($id);
             self::$timeZoneList[] = $id;
             // Items like 'America/Chicago' should be left as is.
         }
     }
     return in_array($part, self::$timeZoneList);
 }
/**
 * Get a timezone from a GMT offset.
 *
 * Converts a numeric offset into a valid timezone string.
 *
 * @since  3.0.0
 *
 * @param  string|float $offset
 *
 * @return null|string
 */
function simcal_get_timezone_from_gmt_offset($offset)
{
    if (is_numeric($offset)) {
        if (0 === intval($offset)) {
            return 'UTC';
        } else {
            $offset = floatval($offset) * 3600;
        }
        $timezone = timezone_name_from_abbr(null, $offset, false);
        // This is buggy and might return false:
        // @see http://php.net/manual/en/function.timezone-name-from-abbr.php#86928
        // Therefore:
        if (false == $timezone) {
            $list = timezone_abbreviations_list();
            foreach ($list as $abbr) {
                foreach ($abbr as $city) {
                    if ($offset == $city['offset']) {
                        return $city['timezone_id'];
                    }
                }
            }
        }
        return $timezone;
    }
    return null;
}
 /**
  * @param string $offset In the format of +09:00, +02:00, -04:00 etc.
  *
  * @return string
  */
 function parse_offset($offset)
 {
     //Make signed offsets unsigned for date_parse
     if (\strpos($offset, '-') !== \false) {
         $negative_offset = \true;
         $offset = \str_replace('-', '', $offset);
     } else {
         if (\strpos($offset, '+') !== \false) {
             $negative_offset = \false;
             $offset = \str_replace('+', '', $offset);
         } else {
             return \false;
         }
     }
     $parsed = \date_parse($offset);
     $offset = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
     //After date_parse is done, put the sign back
     if ($negative_offset == \true) {
         $offset = -\abs($offset);
     }
     //And then, look the offset up.
     //timezone_name_from_abbr is not used because it returns false on some(most) offsets because it's mapping function is weird.
     //That's been a bug in PHP since 2008!
     foreach (\timezone_abbreviations_list() as $zones) {
         foreach ($zones as $timezone) {
             if ($timezone['offset'] == $offset) {
                 return $timezone['timezone_id'];
             }
         }
     }
     return \false;
 }
Beispiel #22
0
<?php

date_default_timezone_set('UTC');
$timezone_abbreviations = timezone_abbreviations_list();
var_dump($timezone_abbreviations["utc"]);
echo "Done\n";
 /**
  * get_timezone_string_from_abbreviations_list
  *
  * @access public
  * @param int $gmt_offset
  * @return string
  * @throws \EE_Error
  */
 public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
 {
     $abbreviations = timezone_abbreviations_list();
     foreach ($abbreviations as $abbreviation) {
         foreach ($abbreviation as $city) {
             if ($city['offset'] === $gmt_offset && $city['dst'] === FALSE) {
                 // check if the timezone is valid but don't throw any errors if it isn't
                 if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
                     return $city['timezone_id'];
                 }
             }
         }
     }
     throw new EE_Error(sprintf(__('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso'), $gmt_offset, '<a href="http://www.php.net/manual/en/timezones.php">', '</a>'));
 }
 /**
  * This method simply gets the offset for the given valid timezone string and returns it.
  * @param  string $tz valid timezone string
  * @return int     if conversion can happen then we return the offset, if not then we return FALSE (or EE_Error)
  */
 public static function timezone_convert_to_offset_from_string($tz)
 {
     $abbreviations = timezone_abbreviations_list();
     $offset = NULL;
     foreach ($abbreviations as $abbreviation) {
         foreach ($abbreviation as $city) {
             if ($city['timezone_id'] == $tz) {
                 $offset = $city['offset'];
             }
         }
     }
     //$offset will be in seconds so let's convert to hours and make sure its an int
     return !empty($offset) ? (int) ($offset / 3600) : 0;
 }
 /**
  * An array of timezone abbreviations that the system allows.
  * Cache an array of just the abbreviation names because the
  * whole timezone_abbreviations_list is huge so we don't want
  * to get it more than necessary.
  *
  * @return array
  */
 public static function date_timezone_abbr($refresh = FALSE)
 {
     $cached = Yii::app()->getCache()->get('date_timezone_abbreviations');
     $data = isset($cached->data) ? $cached->data : array();
     if (empty($data) || $refresh) {
         $data = array_keys(timezone_abbreviations_list());
         Yii::app()->getCache()->set('date_timezone_abbreviations', $data);
     }
     return $data;
 }
 public function __construct($locale, $tz, $format)
 {
     $this->locale = $locale;
     if (preg_match('/^%([A-Z]+):(.*)$/', $format, $matches)) {
         $tz = $matches[1];
         $format = $matches[2];
     }
     $this->format = $format;
     $this->timezone = new DateTimeZone($tz);
     $date = new DateTime("", $this->timezone);
     $this->gmt_offset = $this->timezone->getOffset($date);
     $abbrev = timezone_abbreviations_list();
     $this->abbrev = $tz;
     if (!isset($abbrev[strtolower($tz)])) {
         $id = $this->timezone->getName();
         foreach ($abbrev as $key => $value) {
             if ($value['timezone_id'] == $id) {
                 $this->abbrev = $key;
                 break;
             }
         }
     }
 }
Beispiel #27
0
/**
 * Returns the difference between the server timez one and the local (users) time zone
 *
 * @param string $server
 * @param string $local
 * @return int
 */
function timezoneDiff($server, $local)
{
    if (function_exists('timezone_abbreviations_list')) {
        $timezones = timezone_abbreviations_list();
        foreach ($timezones as $key => $zones) {
            foreach ($zones as $id => $zone) {
                if (!isset($offset_server) && $zone['timezone_id'] === $server) {
                    $offset_server = (int) $zone['offset'];
                }
                if (!isset($offset_local) && $zone['timezone_id'] === $local) {
                    $offset_local = (int) $zone['offset'];
                }
                if (isset($offset_server) && isset($offset_local)) {
                    return ($offset_server - $offset_local) / 3600;
                }
            }
        }
    }
    return 0;
}
Beispiel #28
0
 /**
  * Constructor
  */
 function timezone()
 {
     // are we riding a dinosaur?
     if (!timezone::is_supported()) {
         // Standard time zones as compiled by H.M. Nautical Almanac Office, June 2004
         // http://aa.usno.navy.mil/faq/docs/world_tzones.html
         $timezones = array(-12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, +1, +2, +3, +3.5, +4, +4.5, +5, +5.5, +6, +6.5, +7, +8, +9, +9.5, +10, +10.5, +11, +11.5, +12, +13, +14);
         foreach ($timezones as $tz) {
             // Fake timezone id
             $timezone_id = 'GMT' . sprintf('%+05.1f', $tz);
             $sign = $tz >= 0 ? '+' : '';
             $label = sprintf("GMT %s%02d:%02d", $sign, $tz, abs($tz - (int) $tz) * 60);
             $this->_details[$timezone_id]['continent'] = gTxt('timezone_gmt');
             $this->_details[$timezone_id]['city'] = $label;
             $this->_details[$timezone_id]['offset'] = $tz * 3600;
             $this->_offsets[$tz * 3600] = $timezone_id;
         }
     } else {
         $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
         $server_tz = date_default_timezone_get();
         $tzlist = timezone_abbreviations_list();
         foreach ($tzlist as $abbr => $timezones) {
             foreach ($timezones as $tz) {
                 $timezone_id = $tz['timezone_id'];
                 // $timezone_ids are not unique among abbreviations
                 if ($timezone_id && !isset($this->_details[$timezone_id])) {
                     $parts = explode('/', $timezone_id);
                     if (in_array($parts[0], $continents)) {
                         if (!empty($server_tz)) {
                             if (date_default_timezone_set($timezone_id)) {
                                 $is_dst = date('I', time());
                             }
                         }
                         $this->_details[$timezone_id]['continent'] = $parts[0];
                         $this->_details[$timezone_id]['city'] = isset($parts[1]) ? $parts[1] : '';
                         $this->_details[$timezone_id]['subcity'] = isset($parts[2]) ? $parts[2] : '';
                         $this->_details[$timezone_id]['offset'] = date_offset_get(date_create()) - ($is_dst ? 3600 : 0);
                         $this->_details[$timezone_id]['dst'] = $tz['dst'];
                         $this->_details[$timezone_id]['abbr'] = strtoupper($abbr);
                         // Guesstimate a timezone key for a given GMT offset
                         $this->_offsets[$tz['offset']] = $timezone_id;
                     }
                 }
             }
         }
     }
     if (!empty($server_tz)) {
         date_default_timezone_set($server_tz);
     }
 }
Beispiel #29
0
define('ALL_SERVER', SM_RESERVED_SLOT . SM_GENERIC . SM_KICK . SM_BAN . SM_UNBAN . SM_SLAY . SM_MAP . SM_CVAR . SM_CONFIG . SM_VOTE . SM_PASSWORD . SM_RCON . SM_CHEATS . SM_CUSTOM1 . SM_CUSTOM2 . SM_CUSTOM3 . SM_CUSTOM4 . SM_CUSTOM5 . SM_CUSTOM6 . SM_ROOT);
$GLOBALS['db']->Execute("SET NAMES utf8;");
$res = $GLOBALS['db']->Execute("SELECT * FROM " . DB_PREFIX . "_settings GROUP BY `setting`, `value`");
$GLOBALS['config'] = array();
while (!$res->EOF) {
    $setting = array($res->fields['setting'] => $res->fields['value']);
    $GLOBALS['config'] = array_merge_recursive($GLOBALS['config'], $setting);
    $res->MoveNext();
}
define('SB_BANS_PER_PAGE', $GLOBALS['config']['banlist.bansperpage']);
define('MIN_PASS_LENGTH', $GLOBALS['config']['config.password.minlength']);
$dateformat = !empty($GLOBALS['config']['config.dateformat']) ? $GLOBALS['config']['config.dateformat'] : "m-d-y H:i";
if (version_compare(PHP_VERSION, "5") != -1) {
    $offset = (empty($GLOBALS['config']['config.timezone']) ? 0 : $GLOBALS['config']['config.timezone']) * 3600;
    date_default_timezone_set("GMT");
    $abbrarray = timezone_abbreviations_list();
    foreach ($abbrarray as $abbr) {
        foreach ($abbr as $city) {
            if ($city['offset'] == $offset && $city['dst'] == $GLOBALS['config']['config.summertime']) {
                date_default_timezone_set($city['timezone_id']);
                break 2;
            }
        }
    }
} else {
    if (empty($GLOBALS['config']['config.timezone'])) {
        define('SB_TIMEZONE', 0);
    } else {
        define('SB_TIMEZONE', $GLOBALS['config']['config.timezone']);
    }
}
Beispiel #30
0
/**
 *  Returns the blog timezone
 *
 * Gets timezone settings from the db. If a timezone identifier is used just turns
 * it into a DateTimeZone. If an offset is usd, it tries to find a suitable timezone.
 * If all else fails it uses UTC.
 *
 * @since 1.3.0
 *
 * @return DateTimeZone The blog timezone
*/
function eo_get_blog_timezone()
{
    $tzstring = wp_cache_get('eventorganiser_timezone');
    if (false === $tzstring) {
        $tzstring = get_option('timezone_string');
        $offset = get_option('gmt_offset');
        // Remove old Etc mappings.  Fallback to gmt_offset.
        if (!empty($tz_string) && false !== strpos($tzstring, 'Etc/GMT')) {
            $tzstring = '';
        }
        if (empty($tzstring) && $offset != 0) {
            //use offset
            $offset *= 3600;
            // convert hour offset to seconds
            $allowed_zones = timezone_abbreviations_list();
            foreach ($allowed_zones as $abbr) {
                foreach ($abbr as $city) {
                    if ($city['offset'] == $offset) {
                        $tzstring = $city['timezone_id'];
                        break 2;
                    }
                }
            }
        }
        //Issue with the timezone selected, set to 'UTC'
        if (empty($tzstring)) {
            $tzstring = 'UTC';
        }
        //Cache timezone string not timezone object
        //Thanks to Ben Huson https://wordpress.org/support/topic/plugin-event-organiser-getting-500-is-error-when-w3-total-cache-is-on
        wp_cache_set('eventorganiser_timezone', $tzstring);
    }
    if ($tzstring instanceof DateTimeZone) {
        return $tzstring;
    }
    $timezone = new DateTimeZone($tzstring);
    return $timezone;
}