' ) ) { $menutitle = ''; } $menutitle .= __('Timezone', TIMEZONE_DOMAIN); add_options_page(__('Timezone Configuration', TIMEZONE_DOMAIN), $menutitle , 'manage_options', 'timezone-config', 'timezone_conf'); add_filter( 'plugin_action_links', 'timezone_filter_plugin_actions', 10, 2 ); } } add_action('admin_menu', 'timezone_config_page'); /** * timezone_filter_plugin_actions() - Adds an action link to the plugins page * * @since 1.6 */ function timezone_filter_plugin_actions($links, $file){ static $this_plugin; if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__); if( $file == $this_plugin ){ $settings_link = '' . __('Settings') . ''; $links = array_merge( array($settings_link), $links); // before other links } return $links; } /** * timezone_get_timezones() - Gets the list of timezones * (in different possible ways, depending on what is available) * */ function timezone_get_timezones() { if (function_exists('timezone_identifiers_list')) { // modern PHP 5.1 way return timezone_identifiers_list(); } else if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { // older PHP4 on a Linux box approach, try two possible locations for time zone info // this is not the best approach. PHP 5 is better. $zones = `find /usr/share/zoneinfo -type f`; if (empty($zones)) $zones = `find /usr/lib/zoneinfo -type f`; if (empty($zones)) return false; $zones = explode("\n", trim($zones)); $zones = str_replace('/usr/share/zoneinfo/','',$zones); $zones = str_replace('/usr/lib/zoneinfo/','',$zones); return $zones; } else { // PHP 4 on a Windows box? No way to do this sort of thing properly on that setup. return false; } } /** * timezone_conf() - Show/handle the admin config page * */ function timezone_conf() { timezone_load_textdomain(); // did they submit the form? if ( isset($_POST['submit']) ) { // are they allowed to do that? if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__('Cheatin’ uh?')); // check the nonce check_admin_referer( 'timezone-update' ); // get the setting $timezone_string = $_POST['timezone_string']; // validate that the setting makes sense if ( isset( $timezone_string ) ) { // check the input tz string for validity $all = @timezone_get_timezones(); if (in_array($timezone_string,$all)) update_option( 'timezone_string', $timezone_string ); } } ?>

'; _e('This timezone is currently in ', TIMEZONE_DOMAIN); $now = localtime(time(),true); if ($now['tm_isdst']) _e('daylight savings', TIMEZONE_DOMAIN); else _e('standard', TIMEZONE_DOMAIN); _e(' time.', TIMEZONE_DOMAIN); echo '
'; } else { _e('Not Selected', TIMEZONE_DOMAIN); echo '
'; } echo '
'; // output the current server time _e('Current Server Time (UTC) is: ', TIMEZONE_DOMAIN); echo gmdate(__('Y-m-d G:i:s')); echo '
'; if ($current_tz) { _e('Time in ', TIMEZONE_DOMAIN); echo $current_tz; _e(' is: ', TIMEZONE_DOMAIN); echo gmdate(__('Y-m-d G:i:s'), current_time('timestamp')); echo '
'; } /* this next display stuff only works on PHP 5.2 and up. It's nice to see, but not strictly necessary, so I don't see the need to duplicate it for PHP 4 */ if (function_exists('timezone_transitions_get') && $current_tz) { $dateTimeZoneSelected = new DateTimeZone($current_tz); foreach (timezone_transitions_get($dateTimeZoneSelected) as $tr) { if ($tr['ts'] > time()) { $found = true; break; } } if ($found) { echo '

'; _e('This timezone switches to ', TIMEZONE_DOMAIN); $tr['isdst'] ? _e('daylight savings time', TIMEZONE_DOMAIN) : _e('standard time', TIMEZONE_DOMAIN); _e(' on: ', TIMEZONE_DOMAIN); $tz = new DateTimeZone($current_tz); $d = new DateTime( "@{$tr['ts']}" ); $d->setTimezone($tz); echo date_i18n(__('F j, Y @ g:i a T', TIMEZONE_DOMAIN),$d->format('U')). '
'; //echo $d->format(__('F j, Y @ g:i a T', TIMEZONE_DOMAIN)) . '.
'; _e(' The new offset at that time will be: UTC', TIMEZONE_DOMAIN); echo $tr['offset'] /3600 . '

'; } else { echo '

'; _e('This timezone does not observe daylight savings time.', TIMEZONE_DOMAIN); echo '

'; } } ?>

getOffset($dateTimeServer); // convert to hours $timeOffset = $timeOffset / 3600; return $timeOffset; } else { // try it the PHP 4 way... Might not work, but what the heck putenv("TZ=$tz"); $timeOffset = date('O') / 100; return $timeOffset; } } /** * timezone_choice() - Display a nicely formatted list of timezone strings * * @param string $selectedzone - which zone should be the selected one * */ function timezone_choice($selectedzone) { $all = @timezone_get_timezones(); $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 = ''; foreach($zonen AS $zone) { extract($zone); if($continent == 'Africa' || $continent == 'America' || $continent == 'Antarctica' || $continent == 'Arctic' || $continent == 'Asia' || $continent == 'Atlantic' || $continent == 'Australia' || $continent == 'Europe' || $continent == 'Indian' || $continent == 'Pacific') { if(!isset($selectcontinent)) { $structure .= ''; // continent } elseif($selectcontinent != $continent) { $structure .= ''; // continent } if(isset($city) != ''){ if (!empty($subcity) != ''){ $city = $city . '/'. $subcity; } $structure .= ""; //Timezone } else { if (!empty($subcity) != ''){ $city = $city . '/'. $subcity; } $structure .= ""; //Timezone } $selectcontinent = $continent; } } $structure .= ''; return $structure; } /** * timezone_alter_settings_general() - Change the Settings->General Screen to be more clever * */ function timezone_alter_settings_general() { /* Note: I wish there was a nicer way to do this, but the admin pages lack the proper hooks for it. Until it gets them, this works. */ // check to see if we're loading the options-general page global $parent_file; if ( $parent_file != 'options-general.php' ) return; // check to see if the timezone is even set $timezone_setting = get_option('timezone_string'); if ( empty($timezone_setting)) return; // all looks good, turn on the output buffer and attach our callback ob_start('timezone_general_callback'); } add_action('admin_head','timezone_alter_settings_general'); /** * timezone_general_callback() - Put a better comment on the Settings->General page. * * @param string $data - The output buffer holding the page data * */ function timezone_general_callback($data) { timezone_load_textdomain(); return str_replace(__('Unfortunately, you have to manually update this for Daylight Savings Time. Lame, we know, but will be fixed in the future.'), __('Fortunately for you, you\'re using the Automatic Timezone plugin, and it has automatically set this value for you.
This setting will change automatically if Daylight Savings Time rolls around.', TIMEZONE_DOMAIN), $data); } /** * Note: There is no ending PHP tag at the end of this file for a very good reason. * Leaving that out here prevents extra white space at the end of the file from * screwing up WordPress' output. This is always a recommended behavior for WordPress * plugins. They should never make output when they are loaded, except in special cases. * * This is VALID in PHP, the closing tag is optional at the end of a PHP file, because * PHP assumes it to be at the very end of the file if it is not explicitly given. */