From 0f320a6c48d63154bba45c2937adeee79165816c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 8 Jul 2010 21:56:51 +0100 Subject: [PATCH] [feature/new-tz-handling] Update tz_select() to use the PHP timezone database. tz_select() now uses the PHP timezone database to generate the timezone selection box, it tries to use a translated language string otherwise falls back to a label produced from the timezone identifier. I've done this so new timezones are available immediately without a new language pack. PHPBB3-9558 --- phpBB/includes/functions.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9e2e57dd5e..fb8ea93e32 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1071,28 +1071,45 @@ function style_select($default = '', $all = false) /** * Pick a timezone +* @todo Possible HTML escaping */ function tz_select($default = '', $truncate = false) { global $user; - $tz_select = ''; - foreach ($user->lang['tz_zones'] as $offset => $zone) + static $timezones; + + if (!isset($timezones)) { - if ($truncate) + $timezones = DateTimeZone::listIdentifiers(); + + sort($timezones); + } + + $tz_select = ''; + + foreach ($timezones as $timezone) + { + if (isset($user->lang['timezones'][$timezone])) { - $zone_trunc = truncate_string($zone, 50, 255, false, '...'); + $title = $label = $user->lang['timezones'][$timezone]; } else { - $zone_trunc = $zone; + // No label, we'll figure one out + // @todo rtl languages? + $bits = explode('/', strtolower(str_replace('_', ' ', $timezone))); + + $title = $label = ucwords(implode(' - ', $bits)); } - if (is_numeric($offset)) + if ($truncate) { - $selected = ($offset == $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $label = truncate_string($label, 50, 255, false, '...'); } + + $selected = ($timezone === $default) ? ' selected="selected"' : ''; + $tz_select .= ''; } return $tz_select;