1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-25 12:33:29 +01:00

[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
This commit is contained in:
Chris Smith 2010-07-08 21:56:51 +01:00 committed by Oleg Pudeyev
parent 1665434853
commit 0f320a6c48

View File

@ -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 .= '<option title="' . $zone . '" value="' . $offset . '"' . $selected . '>' . $zone_trunc . '</option>';
$label = truncate_string($label, 50, 255, false, '...');
}
$selected = ($timezone === $default) ? ' selected="selected"' : '';
$tz_select .= '<option title="' . $title . '" value="' . $timezone . '"' . $selected . '>' . $label . '</option>';
}
return $tz_select;