From 4f91b4b9b08146fee8a0fdb33815c09597cb4d55 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Thu, 9 Jan 2014 21:22:13 +0000 Subject: use custom safe_version_compare instead of version_compare to handle versions numbers with letters git-svn-id: http://piwigo.org/svn/trunk@26591 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions.inc.php | 32 ++++++++++++++++++++++++++++++++ include/functions_plugins.inc.php | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index 616d17569..219f6dcce 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -2089,4 +2089,36 @@ SELECT COUNT(DISTINCT(com.id)) return $user['nb_available_comments']; } +/** + * Compare two versions with version_compare after having converted + * single chars to their decimal values. + * Needed because version_compare does not understand versions like '2.5.c'. + * @since 2.6 + * + * @param string $a + * @param string $b + * @param string $op + */ +function safe_version_compare($a, $b, $op=null) +{ + $replace_chars = create_function('$m', 'return ord(strtolower($m[1]));'); + + // add dot before groups of letters (version_compare does the same thing) + $a = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $a); + $b = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $b); + + // apply ord() to any single letter + $a = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $a); + $b = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $b); + + if (empty($op)) + { + return version_compare($a, $b); + } + else + { + return version_compare($a, $b, $op); + } +} + ?> \ No newline at end of file diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php index 035a0bea8..d71f58491 100644 --- a/include/functions_plugins.inc.php +++ b/include/functions_plugins.inc.php @@ -78,7 +78,7 @@ abstract class PluginMaintain $current_version = $pwg_loaded_plugins[$this->plugin_id]['version']; if ( $version == 'auto' or $current_version == 'auto' - or version_compare($current_version, $version, '<') + or safe_version_compare($current_version, $version, '<') ) { if (!empty($on_update)) @@ -144,7 +144,7 @@ SELECT version list($current_version) = pwg_db_fetch_row(pwg_query($query)); if ( $version == 'auto' or $current_version == 'auto' - or version_compare($current_version, $version, '<') + or safe_version_compare($current_version, $version, '<') ) { if (!empty($on_update)) -- cgit v1.2.3