From d8c97819950c3b6252f60fe701dd4a9c849eceb5 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 10 Mar 2009 00:50:00 +0000 Subject: [PATCH] Timezone support. Props Otto42. see #3962 git-svn-id: http://svn.automattic.com/wordpress/trunk@10753 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/options-general.php | 23 ++++++++ wp-admin/options.php | 2 +- wp-includes/default-filters.php | 2 + wp-includes/functions.php | 93 ++++++++++++++++++++++++++++++++- 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/wp-admin/options-general.php b/wp-admin/options-general.php index d1f7308dcd..5bd6a6d69c 100644 --- a/wp-admin/options-general.php +++ b/wp-admin/options-general.php @@ -93,6 +93,9 @@ include('./admin-header.php'); + + + + +UTC time is %s'), date_i18n(__('Y-m-d G:i:s'), false, 'gmt')); ?> + + %2$s'), get_option('timezone_string'), date_i18n(__('Y-m-d G:i:s'))); ?> + +
+ + + + diff --git a/wp-admin/options.php b/wp-admin/options.php index ad048ca889..6609614e0b 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -22,7 +22,7 @@ $parent_file = 'options-general.php'; wp_reset_vars(array('action')); $whitelist_options = array( - 'general' => array( 'blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'default_role' ), + 'general' => array( 'blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'default_role', 'timezone_string' ), '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' ), 'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path' ), 'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ), diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 826079df84..65b3097bd6 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -203,4 +203,6 @@ add_action('edit_post', 'wp_check_for_changed_slugs'); add_action('edit_form_advanced', 'wp_remember_old_slug'); add_action('init', '_show_post_preview'); +add_filter('pre_option_gmt_offset','wp_timezone_override_offset'); + ?> diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 4ffa836e2f..8aa5f58f7b 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3049,5 +3049,96 @@ function update_site_option( $key, $value ) { return update_option($key, $value); } +/** + * gmt_offset modification for smart timezone handling + * + * Overrides the gmt_offset option if we have a timezone_string available + */ +function wp_timezone_override_offset() { + if (!wp_timezone_supported()) return false; -?> + $tz = get_option('timezone_string'); + if (empty($tz)) return false; + + @date_default_timezone_set($tz); + + $dateTimeZoneSelected = timezone_open($tz); + $dateTimeServer = date_create(); + if ($dateTimeZoneSelected === false || $dateTimeServer === false) return false; + + $timeOffset = timezone_offset_get($dateTimeZoneSelected, $dateTimeServer); + $timeOffset = $timeOffset / 3600; + + return $timeOffset; +} + +/** + * Check for PHP timezone support + * + */ +function wp_timezone_supported() { + if (function_exists('date_default_timezone_set') + && function_exists('timezone_identifiers_list') + && function_exists('timezone_open') + && function_exists('timezone_offset_get') + ) + return true; + + return false; +} + +/** + * Gives a nicely formatted list of timezone strings // temporary! Not in final + * + * @param string $selectedzone - which zone should be the selected one + * + */ +function wp_timezone_choice($selectedzone) { + $all = timezone_identifiers_list(); + + $i = 0; + foreach ( $all as $zone ) { + $zone = explode('/',$zone); + $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : ''; + $zonen[$i]['city'] = isset($zone[1]) ? $zone[1] : ''; + $zonen[$i]['subcity'] = isset($zone[2]) ? $zone[2] : ''; + $i++; + } + + asort($zonen); + $structure = ''; + $pad = '   '; + + if ( empty($selectedzone) ) + $structure .= '\n"; + foreach ( $zonen as $zone ) { + extract($zone); + if ( empty($selectcontinent) && !empty($city) ) { + $selectcontinent = $continent; + $structure .= '' . "\n"; // continent + } elseif ( !empty($selectcontinent) && $selectcontinent != $continent ) { + $structure .= "\n"; + $selectcontinent = ''; + if ( !empty($city) ) { + $selectcontinent = $continent; + $structure .= '' . "\n"; // continent + } + } + + if ( !empty($city) ) { + if ( !empty($subcity) ) { + $city = $city . '/'. $subcity; + } + $structure .= "\t\n"; //Timezone + } else { + $structure .= "\n"; //Timezone + } + } + + if ( !empty($selectcontinent) ) + $structure .= "\n"; + return $structure; +} + + +?> \ No newline at end of file