[feature/new-tz-handling] Fix selecting and validating of timezone in UCP

PHPBB3-9558
This commit is contained in:
Joas Schilling 2012-06-04 19:06:46 +02:00
parent 8f027b68d6
commit 50936cb2ef
4 changed files with 33 additions and 12 deletions

View file

@ -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;

View file

@ -1395,6 +1395,22 @@ function validate_language_iso_name($lang_iso)
return ($lang_id) ? false : 'WRONG_DATA';
}
/**
* 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.

View file

@ -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'))

View file

@ -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.',