Make WordPress Core


Ignore:
Timestamp:
03/10/2009 12:50:00 AM (18 years ago)
Author:
ryan
Message:

Timezone support. Props Otto42. see #3962

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r10740 r10753  
    30503050}
    30513051
     3052/**
     3053 * gmt_offset modification for smart timezone handling
     3054 *
     3055 * Overrides the gmt_offset option if we have a timezone_string available
     3056 */
     3057function wp_timezone_override_offset() {
     3058        if (!wp_timezone_supported()) return false;
     3059
     3060        $tz = get_option('timezone_string');
     3061        if (empty($tz)) return false;
     3062
     3063        @date_default_timezone_set($tz);
     3064               
     3065        $dateTimeZoneSelected = timezone_open($tz);
     3066        $dateTimeServer = date_create();
     3067        if ($dateTimeZoneSelected === false || $dateTimeServer === false) return false;
     3068               
     3069        $timeOffset = timezone_offset_get($dateTimeZoneSelected, $dateTimeServer);
     3070        $timeOffset = $timeOffset / 3600;
     3071               
     3072        return $timeOffset;
     3073}
     3074
     3075/**
     3076 * Check for PHP timezone support
     3077 *
     3078 */
     3079function wp_timezone_supported() {
     3080        if (function_exists('date_default_timezone_set')
     3081                && function_exists('timezone_identifiers_list')
     3082                && function_exists('timezone_open')
     3083                && function_exists('timezone_offset_get')
     3084                )
     3085                return true;
     3086
     3087        return false;
     3088}
     3089
     3090/**
     3091 * Gives a nicely formatted list of timezone strings // temporary! Not in final
     3092 *
     3093 * @param string $selectedzone - which zone should be the selected one
     3094 *
     3095 */
     3096function wp_timezone_choice($selectedzone) {
     3097        $all = timezone_identifiers_list();
     3098
     3099        $i = 0;
     3100        foreach ( $all as $zone ) {
     3101                $zone = explode('/',$zone);
     3102                $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
     3103                $zonen[$i]['city'] = isset($zone[1]) ? $zone[1] : '';
     3104                $zonen[$i]['subcity'] = isset($zone[2]) ? $zone[2] : '';
     3105                $i++;
     3106        }
     3107
     3108        asort($zonen);
     3109        $structure = '';
     3110        $pad = '   ';
     3111
     3112        if ( empty($selectedzone) )
     3113                $structure .= '<option selected="selected" value="">' . __('Select a city') . "</option>\n";
     3114        foreach ( $zonen as $zone ) {
     3115                extract($zone);
     3116                if ( empty($selectcontinent) && !empty($city) ) {
     3117                        $selectcontinent = $continent;
     3118                        $structure .= '<optgroup label="'.$continent.'">' . "\n"; // continent
     3119                } elseif ( !empty($selectcontinent) && $selectcontinent != $continent ) {
     3120                        $structure .= "</optgroup>\n";
     3121                        $selectcontinent = '';
     3122                        if ( !empty($city) ) {
     3123                                $selectcontinent = $continent;
     3124                                $structure .= '<optgroup label="'.$continent.'">' . "\n"; // continent
     3125                        }
     3126                }
     3127
     3128                if ( !empty($city) ) {
     3129                        if ( !empty($subcity) ) {
     3130                                $city = $city . '/'. $subcity;
     3131                        }
     3132                        $structure .= "\t<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">$pad".str_replace('_',' ',$city)."</option>\n"; //Timezone
     3133                } else {
     3134                        $structure .= "<option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>\n"; //Timezone
     3135                }
     3136        }
     3137
     3138        if ( !empty($selectcontinent) )
     3139                $structure .= "</optgroup>\n";
     3140        return $structure;
     3141}
     3142
    30523143
    30533144?>
Note: See TracChangeset for help on using the changeset viewer.