aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-07-19 14:36:20 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-07-19 14:36:20 +0200
commit6de222065e737bdab4ecdd010773fb70c415fb3b (patch)
tree4b70f21fbd3be39fbe435ede20ca63759ca7680b
parentd099ef8cade0194fa8056439d489b159d5890f29 (diff)
downloadforums-6de222065e737bdab4ecdd010773fb70c415fb3b.tar
forums-6de222065e737bdab4ecdd010773fb70c415fb3b.tar.gz
forums-6de222065e737bdab4ecdd010773fb70c415fb3b.tar.bz2
forums-6de222065e737bdab4ecdd010773fb70c415fb3b.tar.xz
forums-6de222065e737bdab4ecdd010773fb70c415fb3b.zip
[feature/new-tz-handling] Add previous selected value to validation if valid
We also add the selected timezone if we can create an object with it. DateTimeZone::listIdentifiers seems to not add all identifiers to the list, because some are only kept for backward compatible reasons. If the user has a deprecated value, we add it here, so it can still be kept. Once the user changed his value, there is no way back to deprecated values. PHPBB3-9558
-rw-r--r--phpBB/includes/functions.php42
-rw-r--r--phpBB/includes/functions_user.php2
2 files changed, 39 insertions, 5 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index c6abcb27ef..98465ca462 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1139,6 +1139,40 @@ function phpbb_tz_select_compare($a, $b)
}
/**
+* Return list of timezone identifiers
+* We also add the selected timezone if we can create an object with it.
+* DateTimeZone::listIdentifiers seems to not add all identifiers to the list,
+* because some are only kept for backward compatible reasons. If the user has
+* a deprecated value, we add it here, so it can still be kept. Once the user
+* changed his value, there is no way back to deprecated values.
+*
+* @param string $selected_timezone Additional timezone that shall
+* be added to the list of identiers
+* @return array DateTimeZone::listIdentifiers and additional
+* selected_timezone if it is a valid timezone.
+*/
+function phpbb_get_timezone_identifiers($selected_timezone)
+{
+ $timezones = DateTimeZone::listIdentifiers();
+
+ if (!in_array($selected_timezone, $timezones))
+ {
+ try
+ {
+ // Add valid timezones that are currently selected but not returned
+ // by DateTimeZone::listIdentifiers
+ $validate_timezone = new DateTimeZone($selected_timezone);
+ $timezones[] = $selected_timezone;
+ }
+ catch (Exception $e)
+ {
+ }
+ }
+
+ return $timezones;
+}
+
+/**
* Pick a timezone
*
* @param string $default A timezone to select
@@ -1171,9 +1205,9 @@ function phpbb_timezone_select($default = '', $truncate = false)
$default_offset = '';
if (!isset($timezones))
{
- $unsorted_timezones = DateTimeZone::listIdentifiers();
- $timezones = array();
+ $unsorted_timezones = phpbb_get_timezone_identifiers($default);
+ $timezones = array();
foreach ($unsorted_timezones as $timezone)
{
$tz = new DateTimeZone($timezone);
@@ -1207,7 +1241,7 @@ function phpbb_timezone_select($default = '', $truncate = false)
$opt_group = $timezone['offest'];
$selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : '';
- $tz_dates .= '<option value="' . $timezone['offest'] . ' - ' . $timezone['current'] . '"' . $selected . '>' . $timezone['offest'] . ' - ' . $timezone['current'] . ($selected ? ' ' . $user->lang['TIMEZONE_SELECTED'] : '') . '</option>';
+ $tz_dates .= '<option value="' . $timezone['offest'] . ' - ' . $timezone['current'] . '"' . $selected . '>' . $timezone['offest'] . ' - ' . $timezone['current'] . '</option>';
}
if (isset($user->lang['timezones'][$timezone['tz']]))
@@ -1229,7 +1263,7 @@ function phpbb_timezone_select($default = '', $truncate = false)
}
$selected = ($timezone['tz'] === $default) ? ' selected="selected"' : '';
- $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . ($selected ? ' ' . $user->lang['TIMEZONE_SELECTED'] : '') . '</option>';
+ $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>';
}
$tz_select .= '</optgroup>';
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index 9bc72cbaa6..6e658b4ef4 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -1420,7 +1420,7 @@ function validate_language_iso_name($lang_iso)
*/
function phpbb_validate_timezone($timezone)
{
- return (in_array($timezone, DateTimeZone::listIdentifiers())) ? false : 'TIMEZONE_INVALID';
+ return (in_array($timezone, phpbb_get_timezone_identifiers($timezone))) ? false : 'TIMEZONE_INVALID';
}
/**