From f926acf1b870a6dddcdfb25ee77bb25ec58e3ec0 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 13 Jul 2011 02:33:29 +0200 Subject: [ticket/10263] Add wrapper for version_compare() that allows the use of A and B Add wrapper function for version_compare() that allows using uppercase A and B for alpha and beta release version strings. PHPBB3-10263 --- phpBB/includes/functions.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b1c1c14d0c..a926095004 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -598,6 +598,34 @@ function phpbb_email_hash($email) return sprintf('%u', crc32(strtolower($email))) . strlen($email); } +/** +* Wrapper for version_compare() that allows using uppercase A and B +* for alpha and beta releases. +* +* See http://www.php.net/manual/en/function.version-compare.php +* +* @param string $version1 First version number +* @param string $version2 Second version number +* @param string $operator Comparison operator (optional) +* +* @return mixed Integer (-1, 0, 1) if comparison operator is specified. +* Boolean (true, false) otherwise. +*/ +function phpbb_version_compare($version1, $version2, $operator = null) +{ + $version1 = strtolower($version1); + $version2 = strtolower($version2); + + if (is_null($operator)) + { + return version_compare($version1, $version2); + } + else + { + return version_compare($version1, $version2, $operator); + } +} + /** * Global function for chmodding directories and files for internal use * -- cgit v1.2.1 From b0940f52e5f3ae096b63b82d449aa6fa8bb8555a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 13 Jul 2011 02:40:00 +0200 Subject: [ticket/10263] Call phpbb_version_compare() from includes/acp/acp_update.php PHPBB3-10263 --- phpBB/includes/acp/acp_update.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_update.php b/phpBB/includes/acp/acp_update.php index b0ce8f1084..931fa53165 100644 --- a/phpBB/includes/acp/acp_update.php +++ b/phpBB/includes/acp/acp_update.php @@ -69,12 +69,9 @@ class acp_update $current_version = (!empty($version_update_from)) ? $version_update_from : $config['version']; - $up_to_date_automatic = (version_compare(str_replace('rc', 'RC', strtolower($current_version)), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true; - $up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($config['version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true; - $template->assign_vars(array( - 'S_UP_TO_DATE' => $up_to_date, - 'S_UP_TO_DATE_AUTO' => $up_to_date_automatic, + 'S_UP_TO_DATE' => phpbb_version_compare($latest_version, $config['version'], '<='), + 'S_UP_TO_DATE_AUTO' => phpbb_version_compare($latest_version, $current_version, '<='), 'S_VERSION_CHECK' => true, 'U_ACTION' => $this->u_action, 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'), -- cgit v1.2.1 From 7f56c05f2450dbf33e48d2c1b9885353ddd58beb Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 14 Jul 2011 23:58:51 +0200 Subject: [ticket/10263] Call phpbb_version_compare() from includes/acp/acp_main.php PHPBB3-10263 --- phpBB/includes/acp/acp_main.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 60cebe3c08..68445d814f 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -415,11 +415,8 @@ class acp_main { $latest_version_info = explode("\n", $latest_version_info); - $latest_version = str_replace('rc', 'RC', strtolower(trim($latest_version_info[0]))); - $current_version = str_replace('rc', 'RC', strtolower($config['version'])); - $template->assign_vars(array( - 'S_VERSION_UP_TO_DATE' => version_compare($current_version, $latest_version, '<') ? false : true, + 'S_VERSION_UP_TO_DATE' => phpbb_version_compare(trim($latest_version_info[0]), $config['version'], '<='), )); } -- cgit v1.2.1