From 407a7bd6a99bc36118eb147e8186927b356d89ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Tue, 9 Oct 2012 14:50:13 +0200 Subject: [PATCH] MDL-35469 fix Gecko based browser checks The problem is that latest firefox versions stopped using dates because they lost the meaning over the time. --- lib/moodlelib.php | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fa8101229d8..3abb77d2621 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8197,18 +8197,45 @@ function check_php_version($version='5.2.4') { case 'Gecko': /// Gecko based browsers - if (empty($version) and substr_count($agent, 'Camino')) { - // MacOS X Camino support - $version = 20041110; + // Do not look for dates any more, we expect real Firefox version here. + if (empty($version)) { + $version = 1; + } else if ($version > 20000000) { + // This is just a guess, it is not supposed to be 100% accurate! + if (preg_match('/^201/', $version)) { + $version = 3.6; + } else if (preg_match('/^200[7-9]/', $version)) { + $version = 3; + } else if (preg_match('/^2006/', $version)) { + $version = 2; + } else { + $version = 1.5; + } } - - // the proper string - Gecko/CCYYMMDD Vendor/Version - // Faster version and work-a-round No IDN problem. - if (preg_match("/Gecko\/([0-9]+)/i", $agent, $match)) { - if ($match[1] > $version) { - return true; + if (preg_match("/(Iceweasel|Firefox)\/([0-9\.]+)/i", $agent, $match)) { + // Use real Firefox version if specified in user agent string. + if (version_compare($match[2], $version) >= 0) { + return true; + } + } else if (preg_match("/Gecko\/([0-9\.]+)/i", $agent, $match)) { + // Gecko might contain date or Firefox revision, let's just guess the Firefox version from the date. + $browserver = $match[1]; + if ($browserver > 20000000) { + // This is just a guess, it is not supposed to be 100% accurate! + if (preg_match('/^201/', $browserver)) { + $browserver = 3.6; + } else if (preg_match('/^200[7-9]/', $browserver)) { + $browserver = 3; + } else if (preg_match('/^2006/', $version)) { + $browserver = 2; + } else { + $browserver = 1.5; } } + if (version_compare($browserver, $version) >= 0) { + return true; + } + } break;