[TYPO3-core] RFC #16878: Feature: Make t3lib_utility_Client::getBrowserInfo() aware of more operating systems
Andreas Lappe
nd at off-pist.de
Thu Dec 30 22:00:32 CET 2010
This is an SVN patch request.
Type: Feature
Bugtracker references:
http://bugs.typo3.org/view.php?id=16878
Branches:
trunk
Problem:
t3lib_utility_Client::getBrowserInfo() currently misses to correcly detect
around 120 million iOS-devices and 60 million android-devices. Windows XP,
Vista and 7 are all detected as Windows NT – which is correct if talking
about the kernel but wrong otherwise. I'd vote for separate detection of
them, but it's debatable.
Solution:
Add iOS and android as system-variables and conditions to detect them.
Notes:
I also added some unittests for OS I could look up by firing up vmware –
this could be extended, but that's another RFC.
It'd be nice to see this in 4.5 as it's more or less a no-brainer, but
if people rely on detecting Windows XP by matching on NT, it might break
that. So maybe you see this different…
So long
Andy
--
,,Sicher spinne ich, was aber nicht heißt, daß ich mich irre. Ich bin
verrückt, nicht krank.´´
-Werwolf Brücke, R.A.W.
-------------- next part --------------
diff --git a/t3lib/utility/class.t3lib_utility_client.php b/t3lib/utility/class.t3lib_utility_client.php
index 701e8ba..481dd65 100644
--- a/t3lib/utility/class.t3lib_utility_client.php
+++ b/t3lib/utility/class.t3lib_utility_client.php
@@ -104,6 +104,7 @@ final class t3lib_utility_Client {
}
// system
+ // Microsoft Documentation about Platform tokens: http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
$browserInfo['system'] = '';
if (strstr($userAgent, 'Win')) {
// windows
@@ -111,16 +112,32 @@ final class t3lib_utility_Client {
$browserInfo['system'] = 'win98';
} elseif (strstr($userAgent, 'Win95') || strstr($userAgent, 'Windows 95')) {
$browserInfo['system'] = 'win95';
+ } elseif (strstr($userAgent, 'Windows NT 6.1')) {
+ $browserInfo['system'] = 'win7';
+ } elseif (strstr($userAgent, 'Windows NT 6.0')) {
+ $browserInfo['system'] = 'winVista';
+ } elseif (strstr($userAgent, 'Windows NT 5.1')) {
+ $browserInfo['system'] = 'winXP';
+ } elseif (strstr($userAgent, 'Windows NT 5.0') || strstr($userAgent, 'Windows NT 5.01')) {
+ $browserInfo['system'] = 'win2k';
} elseif (strstr($userAgent, 'WinNT') || strstr($userAgent, 'Windows NT')) {
$browserInfo['system'] = 'winNT';
} elseif (strstr($userAgent, 'Win16') || strstr($userAgent, 'Windows 311')) {
$browserInfo['system'] = 'win311';
}
} elseif (strstr($userAgent, 'Mac')) {
- $browserInfo['system'] = 'mac';
+ if (strstr($userAgent, 'iPad') || strstr($userAgent, 'iPhone') || strstr($userAgent, 'iPod')) {
+ $browserInfo['system'] = 'iOS';
+ } else {
+ $browserInfo['system'] = 'mac';
+ }
// unixes
} elseif (strstr($userAgent, 'Linux')) {
- $browserInfo['system'] = 'linux';
+ if (strstr($userAgent, 'Android')) {
+ $browserInfo['system'] = 'android';
+ } else {
+ $browserInfo['system'] = 'linux';
+ }
} elseif (strstr($userAgent, 'SGI') && strstr($userAgent, ' IRIX ')) {
$browserInfo['system'] = 'unix_sgi';
} elseif (strstr($userAgent, ' SunOS ')) {
@@ -212,4 +229,4 @@ final class t3lib_utility_Client {
}
}
-?>
\ No newline at end of file
+?>
diff --git a/tests/t3lib/utility/t3lib_utility_clientTest.php b/tests/t3lib/utility/t3lib_utility_clientTest.php
index 7955a81..4222228 100644
--- a/tests/t3lib/utility/t3lib_utility_clientTest.php
+++ b/tests/t3lib/utility/t3lib_utility_clientTest.php
@@ -201,5 +201,187 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
$infoArray['all']['gecko']
);
}
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindows7() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'win7',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindowsVista() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'winVista',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindowsXp() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'winXP',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindows2k() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'win2k',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindows2kServicePack1() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.01; SV1)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'win2k',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfWindowsNt() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'winNT',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringContainingNtAsFallback() {
+ $userAgentString = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT)';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'winNT',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfIpad() {
+ $userAgentString = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'iOS',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfIphone() {
+ $userAgentString = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'iOS',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfIpod() {
+ $userAgentString = 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Geckto) Version/3.0 Mobile/3A101a Safari/419.3';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'iOS',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfMacOsX() {
+ $userAgentString = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/534.15+ (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'mac',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfLinux() {
+ $userAgentString = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'linux',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfSolaris() {
+ $userAgentString = 'Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.1.9) Gecko/20100525 Firefox/3.5.9';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'unix_sun',
+ $infoArray['system']
+ );
+ }
+
+ /**
+ * @test
+ */
+ public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfAndroid() {
+ $userAgentString = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
+ $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
+
+ $this->assertSame(
+ 'android',
+ $infoArray['system']
+ );
+ }
}
-?>
\ No newline at end of file
+?>
More information about the TYPO3-team-core
mailing list