Changes from branches/2.8/wp-includes/functions.php at r11678 to trunk/wp-includes/functions.php at r11544
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r11678 r11544 2683 2683 $wp_smiliessearch .= '|'; 2684 2684 } 2685 $wp_smiliessearch .= preg_quote($rest , '/');2685 $wp_smiliessearch .= preg_quote($rest); 2686 2686 } 2687 2687 … … 3150 3150 */ 3151 3151 function wp_timezone_override_offset() { 3152 if ( !wp_timezone_supported() ) { 3153 return false; 3154 } 3155 if ( !$timezone_string = get_option( 'timezone_string' ) ) { 3156 return false; 3157 } 3158 3159 @date_default_timezone_set( $timezone_string ); 3160 $timezone_object = timezone_open( $timezone_string ); 3161 $datetime_object = date_create(); 3162 if ( false === $timezone_object || false === $datetime_object ) { 3163 return false; 3164 } 3165 return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); 3152 if (!wp_timezone_supported()) return false; 3153 3154 $tz = get_option('timezone_string'); 3155 if (empty($tz)) return false; 3156 3157 @date_default_timezone_set($tz); 3158 3159 $dateTimeZoneSelected = timezone_open($tz); 3160 $dateTimeServer = date_create(); 3161 if ($dateTimeZoneSelected === false || $dateTimeServer === false) return false; 3162 3163 $timeOffset = timezone_offset_get($dateTimeZoneSelected, $dateTimeServer); 3164 $timeOffset = $timeOffset / 3600; 3165 3166 return $timeOffset; 3166 3167 } 3167 3168 3168 3169 /** 3169 3170 * Check for PHP timezone support 3171 * 3170 3172 */ 3171 3173 function wp_timezone_supported() { 3172 $support = false; 3173 if ( 3174 function_exists( 'date_default_timezone_set' ) && 3175 function_exists( 'timezone_identifiers_list' ) && 3176 function_exists( 'timezone_open' ) && 3177 function_exists( 'timezone_offset_get' ) 3178 ) { 3179 $support = true; 3180 } 3181 return apply_filters( 'timezone_support', $support ); 3182 } 3183 3184 function _wp_timezone_choice_usort_callback( $a, $b ) { 3185 // Don't use translated versions of Etc 3186 if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) { 3187 // Make the order of these more like the old dropdown 3188 if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { 3189 return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) ); 3190 } 3191 if ( 'UTC' === $a['city'] ) { 3192 if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) { 3193 return 1; 3194 } 3195 return -1; 3196 } 3197 if ( 'UTC' === $b['city'] ) { 3198 if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) { 3199 return -1; 3200 } 3201 return 1; 3202 } 3203 return strnatcasecmp( $a['city'], $b['city'] ); 3204 } 3205 if ( $a['t_continent'] == $b['t_continent'] ) { 3206 if ( $a['t_city'] == $b['t_city'] ) { 3207 return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] ); 3208 } 3209 return strnatcasecmp( $a['t_city'], $b['t_city'] ); 3210 } else { 3211 // Force Etc to the bottom of the list 3212 if ( 'Etc' === $a['continent'] ) { 3213 return 1; 3214 } 3215 if ( 'Etc' === $b['continent'] ) { 3216 return -1; 3217 } 3218 return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); 3219 } 3174 if (function_exists('date_default_timezone_set') 3175 && function_exists('timezone_identifiers_list') 3176 && function_exists('timezone_open') 3177 && function_exists('timezone_offset_get') 3178 ) 3179 return apply_filters('timezone_support',true); 3180 3181 return apply_filters('timezone_support',false); 3220 3182 } 3221 3183 … … 3223 3185 * Gives a nicely formatted list of timezone strings // temporary! Not in final 3224 3186 * 3225 * @param $selected_zone string Selected Zone3226 * 3227 */ 3228 function wp_timezone_choice( $selected_zone) {3187 * @param string $selectedzone - which zone should be the selected one 3188 * 3189 */ 3190 function wp_timezone_choice($selectedzone) { 3229 3191 static $mo_loaded = false; 3230 3192 3231 $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc');3193 $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc'); 3232 3194 3233 3195 // Load translations for continents and cities 3234 if ( ! $mo_loaded ) {3196 if ( ! $mo_loaded ) { 3235 3197 $locale = get_locale(); 3236 $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';3237 load_textdomain( 'continents-cities', $mofile);3198 $mofile = WP_LANG_DIR . "/continents-cities-$locale.mo"; 3199 load_textdomain('continents-cities', $mofile); 3238 3200 $mo_loaded = true; 3239 3201 } 3240 3202 3241 $zonen = array(); 3242 foreach ( timezone_identifiers_list() as $zone ) { 3243 $zone = explode( '/', $zone ); 3244 if ( !in_array( $zone[0], $continents ) ) { 3203 $all = timezone_identifiers_list(); 3204 3205 $i = 0; 3206 foreach ( $all as $zone ) { 3207 $zone = explode('/',$zone); 3208 if ( ! in_array($zone[0], $continents) ) 3245 3209 continue; 3246 } 3247 if ( 'Etc' === $zone[0] && in_array( $zone[1], array( 'UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu' ) ) ) { 3210 if ( $zone[0] == 'Etc' && in_array($zone[1], array('UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu')) ) 3248 3211 continue; 3249 } 3250 3251 // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later 3252 $exists = array( 3253 0 => ( isset( $zone[0] ) && $zone[0] ) ? true : false, 3254 1 => ( isset( $zone[1] ) && $zone[1] ) ? true : false, 3255 2 => ( isset( $zone[2] ) && $zone[2] ) ? true : false 3256 ); 3257 $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ) ? true : false; 3258 $exists[4] = ( $exists[1] && $exists[3] ) ? true : false; 3259 $exists[5] = ( $exists[2] && $exists[3] ) ? true : false; 3260 3261 $zonen[] = array( 3262 'continent' => ( $exists[0] ? $zone[0] : '' ), 3263 'city' => ( $exists[1] ? $zone[1] : '' ), 3264 'subcity' => ( $exists[2] ? $zone[2] : '' ), 3265 't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ), 3266 't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ), 3267 't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ) 3268 ); 3269 } 3270 usort( $zonen, '_wp_timezone_choice_usort_callback' ); 3271 3272 $structure = array(); 3273 3274 if ( empty( $selected_zone ) ) { 3275 $structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>'; 3276 } 3277 3278 foreach ( $zonen as $key => $zone ) { 3279 // Build value in an array to join later 3280 $value = array( $zone['continent'] ); 3281 3282 if ( empty( $zone['city'] ) ) { 3283 // It's at the continent level (generally won't happen) 3284 $display = $zone['t_continent']; 3285 } else { 3286 // It's inside a continent group 3287 3288 // Continent optgroup 3289 if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) { 3290 $label = ( 'Etc' === $zone['continent'] ) ? __( 'Manual offsets' ) : $zone['t_continent']; 3291 $structure[] = '<optgroup label="'. esc_attr( $label ) .'">'; 3292 } 3293 3294 // Add the city to the value 3295 $value[] = $zone['city']; 3296 if ( 'Etc' === $zone['continent'] ) { 3297 if ( 'UTC' === $zone['city'] ) { 3298 $display = ''; 3299 } else { 3300 $display = str_replace( 'GMT', '', $zone['city'] ); 3301 $display = strtr( $display, '+-', '-+' ) . ':00'; 3302 } 3303 $display = sprintf( __( 'UTC %s' ), $display ); 3304 } else { 3305 $display = $zone['t_city']; 3306 if ( !empty( $zone['subcity'] ) ) { 3307 // Add the subcity to the value 3308 $value[] = $zone['subcity']; 3309 $display .= ' - ' . $zone['t_subcity']; 3310 } 3212 $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : ''; 3213 $zonen[$i]['city'] = isset($zone[1]) ? $zone[1] : ''; 3214 $zonen[$i]['subcity'] = isset($zone[2]) ? $zone[2] : ''; 3215 $i++; 3216 } 3217 3218 usort($zonen, create_function( 3219 '$a, $b', ' 3220 $t = create_function(\'$s\', \'return translate(str_replace("_", " ", $s), "continents-cities");\'); 3221 $a_continent = $t($a["continent"]); 3222 $b_continent = $t($b["continent"]); 3223 $a_city = $t($a["city"]); 3224 $b_city = $t($b["city"]); 3225 $a_subcity = $t($a["subcity"]); 3226 $b_subcity = $t($b["subcity"]); 3227 if ( $a_continent == $b_continent && $a_city == $b_city ) 3228 return strnatcasecmp($a_subcity, $b_subcity); 3229 elseif ( $a_continent == $b_continent ) 3230 return strnatcasecmp($a_city, $b_city); 3231 else 3232 return strnatcasecmp($a_continent, $b_continent); 3233 ')); 3234 3235 $structure = ''; 3236 $pad = ' '; 3237 3238 if ( empty($selectedzone) ) 3239 $structure .= '<option selected="selected" value="">' . __('Select a city') . "</option>\n"; 3240 foreach ( $zonen as $zone ) { 3241 extract($zone); 3242 if ( empty($selectcontinent) && !empty($city) ) { 3243 $selectcontinent = $continent; 3244 $structure .= '<optgroup label="'. esc_attr( translate( $continent, "continents-cities" ) ) .'">' . "\n"; // continent 3245 } elseif ( !empty($selectcontinent) && $selectcontinent != $continent ) { 3246 $structure .= "</optgroup>\n"; 3247 $selectcontinent = ''; 3248 if ( !empty($city) ) { 3249 $selectcontinent = $continent; 3250 $structure .= '<optgroup label="'. esc_attr( translate( $continent, "continents-cities" ) ) .'">' . "\n"; // continent 3311 3251 } 3312 3252 } 3313 3253 3314 // Build the value 3315 $value = join( '/', $value ); 3316 $selected = ''; 3317 if ( $value === $selected_zone ) { 3318 $selected = 'selected="selected" '; 3254 if ( !empty($city) ) { 3255 $display = str_replace('_',' ',$city); 3256 $display = translate($display, "continents-cities"); 3257 if ( !empty($subcity) ) { 3258 $display_subcity = str_replace('_', ' ', $subcity); 3259 $display_subcity = translate($display_subcity, "continents-cities"); 3260 $city = $city . '/'. $subcity; 3261 $display = $display . '/' . $display_subcity; 3262 } 3263 if ( $continent == 'Etc' ) 3264 $display = strtr($display, '+-', '-+'); 3265 $structure .= "\t<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected"':'')." value=\"".($continent.'/'.$city)."\">$pad".$display."</option>\n"; //Timezone 3266 } else { 3267 $structure .= "<option ".(($continent==$selectedzone)?'selected="selected"':'')." value=\"".$continent."\">" . translate($continent, "continents-cities") . "</option>\n"; //Timezone 3319 3268 } 3320 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>"; 3321 3322 // Close continent optgroup 3323 if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) { 3324 $structure[] = '</optgroup>'; 3325 } 3326 } 3327 3328 return join( "\n", $structure ); 3269 } 3270 3271 if ( !empty($selectcontinent) ) 3272 $structure .= "</optgroup>\n"; 3273 return $structure; 3329 3274 } 3330 3275
Note: See TracChangeset
for help on using the changeset viewer.