diff options
-rw-r--r-- | phpBB/includes/functions.php | 24 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 16 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_prefs.php | 4 | ||||
-rw-r--r-- | phpBB/language/en/ucp.php | 1 |
4 files changed, 33 insertions, 12 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3ec4b76091..55f7f0531c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1139,34 +1139,38 @@ function tz_select($default = '', $truncate = false) if (!isset($timezones)) { - $timezones = DateTimeZone::listIdentifiers(); + $unsorted_timezones = DateTimeZone::listIdentifiers(); + $timezones = array(); - foreach ($timezones as &$timezone) + foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); $dt = new phpbb_datetime('now', $tz); $offset = $dt->getOffset(); $offset_string = phpbb_format_timezone_offset($offset); - $timezone = 'GMT' . $offset_string . ' - ' . $timezone; + $timezones['GMT' . $offset_string . ' - ' . $timezone] = array( + 'tz' => $timezone, + 'label' => 'GMT' . $offset_string . ' - ' . $timezone, + ); } - unset($timezone); + unset($unsorted_timezones); - usort($timezones, 'tz_select_compare'); + uksort($timezones, 'tz_select_compare'); } $tz_select = ''; foreach ($timezones as $timezone) { - if (isset($user->lang['timezones'][$timezone])) + if (isset($user->lang['timezones'][$timezone['tz']])) { - $title = $label = $user->lang['timezones'][$timezone]; + $title = $label = $user->lang['timezones'][$timezone['tz']]; } else { // No label, we'll figure one out // @todo rtl languages? - $bits = explode('/', str_replace('_', ' ', $timezone)); + $bits = explode('/', str_replace('_', ' ', $timezone['label'])); $title = $label = implode(' - ', $bits); } @@ -1176,8 +1180,8 @@ function tz_select($default = '', $truncate = false) $label = truncate_string($label, 50, 255, false, '...'); } - $selected = ($timezone === $default) ? ' selected="selected"' : ''; - $tz_select .= '<option title="' . $title . '" value="' . $timezone . '"' . $selected . '>' . $label . '</option>'; + $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; + $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>'; } return $tz_select; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9b102b7387..3a77407c20 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1396,6 +1396,22 @@ function validate_language_iso_name($lang_iso) } /** +* Validate Timezone Name +* +* Tests whether a timezone name is valid +* +* @param string $timezone The timezone string to test +* +* @return bool|string Either false if validation succeeded or +* a string which will be used as the error message +* (with the variable name appended) +*/ +function validate_timezone($timezone) +{ + return (in_array($timezone, DateTimeZone::listIdentifiers())) ? false : 'TIMEZONE_INVALID'; +} + +/** * Check to see if the username has been taken, or if it is disallowed. * Also checks if it includes the " character, which we don't allow in usernames. * Used for registering, changing names, and posting anonymously with a username diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 0c9f20f266..45e3bb8951 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -41,7 +41,7 @@ class ucp_prefs 'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), 'lang' => basename(request_var('lang', $user->data['user_lang'])), 'style' => request_var('style', (int) $user->data['user_style']), - 'tz' => request_var('tz', (float) $user->data['user_timezone']), + 'tz' => request_var('tz', $user->data['user_timezone']), 'dst' => request_var('dst', (bool) $user->data['user_dst']), 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), @@ -72,7 +72,7 @@ class ucp_prefs $error = validate_data($data, array( 'dateformat' => array('string', false, 1, 30), 'lang' => array('language_iso_name'), - 'tz' => array('num', false, -14, 14), + 'tz' => array('timezone'), )); if (!check_form_key('ucp_prefs_personal')) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index a80862890a..f9558bc6d3 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -422,6 +422,7 @@ $lang = array_merge($lang, array( 'SORT_SIZE' => 'File size', 'TIMEZONE' => 'Timezone', + 'TIMEZONE_INVALID' => 'The timezone you selected is invalid.', 'TO' => 'To', 'TOO_MANY_RECIPIENTS' => 'You tried to send a private message to too many recipients.', 'TOO_MANY_REGISTERS' => 'You have exceeded the maximum number of registration attempts for this session. Please try again later.', |