0 || ($c === 0 && !$to_inclusive)) { return false; } } return true; } /** * Ranges: list of array(from_version, from_inclusive, to_version, to_inclusive) */ public static function matches_any($version, $ranges) { foreach ((array) $ranges as $range) { if (!is_array($range)) { continue; } $from = isset($range['from_version']) ? $range['from_version'] : '*'; $to = isset($range['to_version']) ? $range['to_version'] : '*'; $from_inclusive = isset($range['from_inclusive']) ? (bool) $range['from_inclusive'] : true; $to_inclusive = isset($range['to_inclusive']) ? (bool) $range['to_inclusive'] : true; if (self::matches($version, $from, $from_inclusive, $to, $to_inclusive)) { return $range; } } return null; } /** * Lowest patched version above the installed one ('' when none is known) */ public static function minimum_patched($version, $patched) { $best = ''; foreach ((array) $patched as $candidate) { $candidate = self::normalize($candidate); if ($candidate === '' || self::compare($candidate, $version) <= 0) { continue; } if ($best === '' || self::compare($candidate, $best) < 0) { $best = $candidate; } } return $best; } /** * Human readable range, for example "≤ 1.2.3" or "1.0 – 1.2.3" */ public static function describe($range) { $from = isset($range['from_version']) ? (string) $range['from_version'] : '*'; $to = isset($range['to_version']) ? (string) $range['to_version'] : '*'; $to_inclusive = isset($range['to_inclusive']) ? (bool) $range['to_inclusive'] : true; $from_inclusive = isset($range['from_inclusive']) ? (bool) $range['from_inclusive'] : true; if ($from === '*' && $to === '*') { return __('all versions', 'all-in-one-wp-content-security'); } if ($from === '*') { return ($to_inclusive ? '≤ ' : '< ') . $to; } if ($to === '*') { return ($from_inclusive ? '≥ ' : '> ') . $from; } return ($from_inclusive ? '' : '> ') . $from . ' – ' . ($to_inclusive ? '' : '< ') . $to; } }