www/adium.im 373:dec50ec646eb: Further improve Mac OS X version ...
commits at adium.im
commits at adium.im
Fri Jan 7 01:26:47 UTC 2011
details: http://hg.adium.im/www/adium.im/rev/dec50ec646eb
revision: 373:dec50ec646eb
author: Evan Schoenberg
date: Thu Jan 06 19:26:40 2011 -0600
Further improve Mac OS X version detection from the user agent string, cleaning up the PHP and supporting both . and _ as version delimiters since both are used in the wild
diffs (46 lines):
diff -r c558ba50c516 -r dec50ec646eb index.php
--- a/index.php Tue Jan 04 00:16:19 2011 -0600
+++ b/index.php Thu Jan 06 19:26:40 2011 -0600
@@ -31,22 +31,29 @@
if (strstr($userAgent, "iPhone") || strstr($userAgent, "iPad") || strstr($userAgent, "iPod")) {
$operatingSystem = "iPhone";
} else if (strstr($userAgent, "Mac OS X ")) {
- // e.g. Mac OS X 10_6_4
- $macOSXMajor = substr($userAgent, strpos($userAgent, "Mac OS X ") + strlen("Mac OS X "));
- $macOSXMajor = substr($macOSXMajor, 0, strpos($macOSXMajor, "_"));
+ // e.g. "Mac OS X 10_6_4;" or "Mac OS X 10.4;"
+
+ // Figure out where the Mac OS X version starts
+ $verStart_pos = strpos($userAgent, "Mac OS X ") + strlen("Mac OS X ");
+
+ // Figure out where the Mac OS X version ends, which is the first semicolon after 'Mac OS X '
+ $verToEnd = substr($userAgent, $verStart_pos);
+
+ $verEnd_pos = strpos($verToEnd, ";");
- $macOSXMinor = substr($userAgent, strpos($userAgent, "Mac OS X ".$macOSXMajor."_") + strlen("Mac OS X ".$macOSXMajor."_"));
- if (strpos($macOSXMinor, "_") !== false) {
- $macOSXMinor = substr($macOSXMinor, 0, strpos($macOSXMinor, "_"));
+ $ver = substr($verToEnd, 0, $verEnd_pos);
- $macOSXMicro = substr($userAgent, strpos($userAgent, "Mac OS X ".$macOSXMajor."_".$macOSXMinor."_") + strlen("Mac OS X ".$macOSXMajor."_".$macOSXMinor."_"));
- $macOSXMicro = substr($macOSXMicro, 0, strpos($macOSXMicro, ";"));
- }
+ //First, look for the form 10_6_4, which is what Safari sends (at least on Mac OS X 10.6)
+ $versionComponents = explode("_", $ver);
- $major = intval($macOSXMajor);
- $minor = intval($macOSXMinor);
- $micro = intval($macOSXMicro);
-
+ //If that didn't explode into multiple components, try the form 10.4.3, which is what Firefox sends
+ if (count($versionComponents) == 1)
+ $versionComponents = explode(".", $ver);
+
+ $major = intval($versionComponents[0]);
+ $minor = intval($versionComponents[1]);
+ $micro = intval($versionComponents[2]);
+
if ($major == 10) {
if ($minor >= 6) {
$operatingSystem = "10.6";
More information about the commits
mailing list