From 50936cb2eff3f80d99390c76ef6ac535e73f6cc3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 19:06:46 +0200 Subject: [feature/new-tz-handling] Fix selecting and validating of timezone in UCP PHPBB3-9558 --- phpBB/includes/functions_user.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9b102b7387..3a77407c20 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -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. -- cgit v1.2.1 From 963d4afc2cf5fb2903ed02ada20cdbf0188d57db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 4 Jun 2012 23:14:41 +0200 Subject: [feature/new-tz-handling] Replace gmmktime() and mktime() with phpbb_datetime PHPBB3-9558 --- phpBB/includes/functions_user.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3a77407c20..f235b2be55 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -197,7 +197,6 @@ function user_add($user_row, $cp_data = false) 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, - 'user_dst' => (int) $config['board_dst'], 'user_colour' => '', 'user_occ' => '', 'user_interests' => '', @@ -677,8 +676,10 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas if (sizeof($ban_other) == 3 && ((int)$ban_other[0] < 9999) && (strlen($ban_other[0]) == 4) && (strlen($ban_other[1]) == 2) && (strlen($ban_other[2]) == 2)) { - $time_offset = (isset($user->timezone) && isset($user->dst)) ? (int) $user->timezone + (int) $user->dst : 0; - $ban_end = max($current_time, gmmktime(0, 0, 0, (int)$ban_other[1], (int)$ban_other[2], (int)$ban_other[0]) - $time_offset); + $ban_end = max($current_time, $user->create_datetime() + ->setDate((int) $ban_other[0], (int) $ban_other[1], (int) $ban_other[2]) + ->setTime(0, 0, 0) + ->getTimestamp() + $user->tz->getOffset(new DateTime('UTC'))); } else { -- cgit v1.2.1 From b61ac43abecafdd4e9597022fe8b09323854aac9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Jul 2012 18:41:30 +0200 Subject: [feature/new-tz-handling] Allow phpbb prefix for user data validation functions PHPBB3-9558 --- phpBB/includes/functions_user.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f235b2be55..27f4b60189 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1248,10 +1248,21 @@ function validate_data($data, $val_ary) $function = array_shift($validate); array_unshift($validate, $data[$var]); - if ($result = call_user_func_array('validate_' . $function, $validate)) + if (function_exists('phpbb_validate_' . $function)) { - // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. - $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + if ($result = call_user_func_array('phpbb_validate_' . $function, $validate)) + { + // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. + $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + } + } + else + { + if ($result = call_user_func_array('validate_' . $function, $validate)) + { + // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. + $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); + } } } } @@ -1407,7 +1418,7 @@ function validate_language_iso_name($lang_iso) * a string which will be used as the error message * (with the variable name appended) */ -function validate_timezone($timezone) +function phpbb_validate_timezone($timezone) { return (in_array($timezone, DateTimeZone::listIdentifiers())) ? false : 'TIMEZONE_INVALID'; } -- cgit v1.2.1 From a71e60cdbd3e47c62a565dd777a28aec6832fb88 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Jul 2012 16:52:52 +0200 Subject: [feature/new-tz-handling] Rename $user->tz back to $user->timezone PHPBB3-9558 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 27f4b60189..9bc72cbaa6 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -679,7 +679,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas $ban_end = max($current_time, $user->create_datetime() ->setDate((int) $ban_other[0], (int) $ban_other[1], (int) $ban_other[2]) ->setTime(0, 0, 0) - ->getTimestamp() + $user->tz->getOffset(new DateTime('UTC'))); + ->getTimestamp() + $user->timezone->getOffset(new DateTime('UTC'))); } else { -- cgit v1.2.1 From 6de222065e737bdab4ecdd010773fb70c415fb3b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 14:36:20 +0200 Subject: [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 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') 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'; } /** -- cgit v1.2.1