All pastes #246373 Raw Edit

Miscellany

public text v1 · immutable
#246373 ·published 2006-11-12 04:00 UTC
rendered paste body
function system_extract_version($version_string) {
  $core_version = substr(VERSION, 0, strpos(VERSION, '.'));
  $pattern =  '/DRUPAL-'. $core_version .'(?:--(?P<major>\d+)(?:-(?P<minor>\d+))?)?/';

  if (!$version_string) {
    $version = t('undefined');
  }
  elseif (empty($version_string)) {
    $version = t('latest dev');
  }
  elseif (preg_match($pattern, $version_string, $matches)) {
    if (!isset($matches['major'])) {
      $version = "$core_version.x-dev";
    }
    elseif (!isset($matches['minor'])) {
      $version = "$core_version.x-{$matches['major']}-dev";
    }
    else {
      $version = "$core_version.x-{$matches['major']}-{$matches['minor']}";
    }
  }

  return $version;
}