Changeset 26591


Ignore:
Timestamp:
Jan 9, 2014, 10:22:13 PM (7 years ago)
Author:
mistic100
Message:

use custom safe_version_compare instead of version_compare to handle versions numbers with letters

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r26461 r26591  
    20902090}
    20912091
     2092/**
     2093 * Compare two versions with version_compare after having converted
     2094 * single chars to their decimal values.
     2095 * Needed because version_compare does not understand versions like '2.5.c'.
     2096 * @since 2.6
     2097 *
     2098 * @param string $a
     2099 * @param string $b
     2100 * @param string $op
     2101 */
     2102function safe_version_compare($a, $b, $op=null)
     2103{
     2104  $replace_chars = create_function('$m', 'return ord(strtolower($m[1]));');
     2105 
     2106  // add dot before groups of letters (version_compare does the same thing)
     2107  $a = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $a);
     2108  $b = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $b);
     2109 
     2110  // apply ord() to any single letter
     2111  $a = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $a);
     2112  $b = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $b);
     2113 
     2114  if (empty($op))
     2115  {
     2116    return version_compare($a, $b);
     2117  }
     2118  else
     2119  {
     2120    return version_compare($a, $b, $op);
     2121  }
     2122}
     2123
    20922124?>
  • trunk/include/functions_plugins.inc.php

    r26461 r26591  
    7979   
    8080    if ( $version == 'auto' or $current_version == 'auto'
    81         or version_compare($current_version, $version, '<')
     81        or safe_version_compare($current_version, $version, '<')
    8282      )
    8383    {
     
    145145   
    146146    if ( $version == 'auto' or $current_version == 'auto'
    147         or version_compare($current_version, $version, '<')
     147        or safe_version_compare($current_version, $version, '<')
    148148      )
    149149    {
Note: See TracChangeset for help on using the changeset viewer.