/** * Common function used to compare two Geeklog version numbers * * @param string $version1 First version number to be compared * @param string $version2 Second version number to be sompared * @param string $operator optional string to define how the two versions are to be compared * valid operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne * @return mixed By default, returns -1 if the first version is lower than the second, * 0 if they are equal, and 1 if the second is lower. * When using the optional operator argument, the function will return TRUE * if the relationship is the one specified by the operator, FALSE otherwise. */ function COM_versionCompare($version1, $version2, $operator = '') { // Convert Geeklog version numbers to a ones that can be parsed // by PHP's "version_compare" $version1 = COM_versionConvert($version1); $version2 = COM_versionConvert($version2); // All that there should be left at this point is numbers and dots, // so PHP's built-in function can now take over. if (empty($operator)) { return version_compare($version1, $version2); } else { return version_compare($version1, $version2, $operator); } }
/** * Checks if a string could be a valid geeklog version * * @param string $version Geeklog version number that is being checked * @return bool true/false * */ function isValidVersion($version = '') { $valid = true; // some minimal parameter filtering ... $v = explode('.', $version); if (count($v) != 3 || !is_numeric($v[0]) || !is_numeric($v[1])) { $valid = false; } else { $v = COM_versionConvert($version); $v = explode('.', $v); foreach ($v as $key => $value) { if (!is_numeric($value)) { $valid = false; break; } } } return $valid; }