1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 16:27:38 +02:00

Merge branch 'feature/new-tz-handling' of https://github.com/p/phpbb3 into feature/new-tz-handling

Conflicts:
	phpBB/includes/functions_profile_fields.php
	phpBB/includes/session.php
	phpBB/install/database_update.php
This commit is contained in:
Joas Schilling
2012-06-04 18:09:35 +02:00
26 changed files with 395 additions and 211 deletions

View File

@@ -1068,30 +1068,116 @@ function style_select($default = '', $all = false)
return $style_options;
}
function phpbb_format_timezone_offset($tz_offset)
{
$sign = ($tz_offset < 0) ? '-' : '+';
$time_offset = abs($tz_offset);
$offset_seconds = $time_offset % 3600;
$offset_minutes = $offset_seconds / 60;
$offset_hours = ($time_offset - $offset_seconds) / 3600;
$offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes);
return $offset_string;
}
// Compares two time zone labels.
// Arranges them in increasing order by timezone offset.
// Places UTC before other timezones in the same offset.
function tz_select_compare($a, $b)
{
$a_sign = $a[3];
$b_sign = $b[3];
if ($a_sign != $b_sign)
{
return $a_sign == '-' ? -1 : 1;
}
$a_offset = substr($a, 4, 5);
$b_offset = substr($b, 4, 5);
if ($a_offset == $b_offset)
{
$a_name = substr($a, 12);
$b_name = substr($b, 12);
if ($a_name == $b_name)
{
return 0;
} else if ($a_name == 'UTC')
{
return -1;
} else if ($b_name == 'UTC')
{
return 1;
}
else
{
return $a_name < $b_name ? -1 : 1;
}
}
else
{
if ($a_sign == '-')
{
return $a_offset > $b_offset ? -1 : 1;
}
else
{
return $a_offset < $b_offset ? -1 : 1;
}
}
}
/**
* 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();
foreach ($timezones as &$timezone)
{
$zone_trunc = truncate_string($zone, 50, 255, false, '...');
$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;
}
unset($timezone);
usort($timezones, 'tz_select_compare');
}
$tz_select = '';
foreach ($timezones as $timezone)
{
if (isset($user->lang['timezones'][$timezone]))
{
$title = $label = $user->lang['timezones'][$timezone];
}
else
{
$zone_trunc = $zone;
// No label, we'll figure one out
// @todo rtl languages?
$bits = explode('/', str_replace('_', ' ', $timezone));
$title = $label = 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;