WordPress.org

Make WordPress Core

Changeset 10753


Ignore:
Timestamp:
03/10/09 00:50:00 (8 years ago)
Author:
ryan
Message:

Timezone support. Props Otto42. see #3962

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-general.php

    r10670 r10753  
    9494</tr> 
    9595<tr> 
     96<?php  
     97if (!wp_timezone_supported()) : // no magic timezone support here  
     98?> 
    9699<th scope="row"><label for="gmt_offset"><?php _e('Timezone') ?> </label></th> 
    97100<td> 
     
    128131<span class="setting-description"><?php _e('Unfortunately, you have to manually update this for Daylight Savings Time. Lame, we know, but will be fixed in the future.'); ?></span> 
    129132</td> 
     133<?php  
     134else: // looks like we can do nice timezone selection! 
     135$current_offset = get_option('gmt_offset'); 
     136?> 
     137<th scope="row"><label for="timezone_string"><?php _e('Timezone') ?></label></th> 
     138<td> 
     139 
     140<select id="timezone_string" name="timezone_string"> 
     141<?php echo wp_timezone_choice(get_option('timezone_string')); ?> 
     142</select> 
     143 
     144<span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n(__('Y-m-d G:i:s'), false, 'gmt')); ?></span> 
     145<?php if (get_option('timezone_string')) : ?> 
     146    <span id="local-time"><?php printf(__('Current time in %1$s is <code>%2$s</code>'), get_option('timezone_string'), date_i18n(__('Y-m-d G:i:s'))); ?></span> 
     147<?php endif; ?> 
     148<br/> 
     149<span class="setting-description"><?php _e('Choose a city in the same timezone as you.'); ?></span> 
     150</td> 
     151 
     152<?php endif; ?> 
    130153</tr> 
    131154<tr> 
  • trunk/wp-admin/options.php

    r10150 r10753  
    2323 
    2424$whitelist_options = array( 
    25     'general' => array( 'blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'default_role' ), 
     25    'general' => array( 'blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'default_role', 'timezone_string' ), 
    2626    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ), 
    2727    'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path' ), 
  • trunk/wp-includes/default-filters.php

    r10521 r10753  
    204204add_action('init', '_show_post_preview'); 
    205205 
     206add_filter('pre_option_gmt_offset','wp_timezone_override_offset'); 
     207 
    206208?> 
  • 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 = '&nbsp;&nbsp;&nbsp;'; 
     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.