Fixed bug #14201: getBrowserInfo delivers wrong info
authorSteffen Kamper <info@sk-typo3.de>
Tue, 27 Apr 2010 20:23:33 +0000 (20:23 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Tue, 27 Apr 2010 20:23:33 +0000 (20:23 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7438 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/utility/class.t3lib_utility_client.php

index 3e0b061..6fb1118 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-04-27  Steffen Kamper  <info@sk-typo3.de>
 
+       * Fixed bug #14201: getBrowserInfo delivers wrong info
        * Fixed bug #14137: Startup in module does not work (thanks to Stefan Galinski)
 
 2010-04-27  Susanne Moog  <typo3@susanne-moog.de>
index 9d7f3e7..dda3704 100644 (file)
@@ -63,98 +63,56 @@ final class t3lib_utility_Client {
                        'useragent' => $userAgent,
                );
 
-               if ($userAgent) {
-                       // browser
-                       if (strstr($userAgent,'MSIE'))  {
-                               $browserInfo['browser']='msie';
-                       } elseif(strstr($userAgent,'Konqueror'))        {
-                               $browserInfo['browser']='konqueror';
-                       } elseif(strstr($userAgent,'Opera'))    {
-                               $browserInfo['browser']='opera';
-                       } elseif(strstr($userAgent,'Lynx'))     {
-                               $browserInfo['browser']='lynx';
-                       } elseif(strstr($userAgent,'PHP'))      {
-                               $browserInfo['browser']='php';
-                       } elseif(strstr($userAgent,'AvantGo'))  {
-                               $browserInfo['browser']='avantgo';
-                       } elseif(strstr($userAgent,'WebCapture'))       {
-                               $browserInfo['browser']='acrobat';
-                       } elseif(strstr($userAgent,'IBrowse'))  {
-                               $browserInfo['browser']='ibrowse';
-                       } elseif(strstr($userAgent,'Teleport')) {
-                               $browserInfo['browser']='teleport';
-                       } elseif(strstr($userAgent,'Mozilla'))  {
-                               $browserInfo['browser']='netscape';
-                       } else {
-                               $browserInfo['browser']='unknown';
-                       }
+               // Analyze the userAgent string
+               // Declare known browsers to look for
+
+               $known = array('msie', 'firefox', 'webkit', 'opera', 'netscape', 'konqueror',
+                               'gecko', 'chrome', 'safari', 'seamonkey', 'navigator', 'mosaic',
+                               'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol');
+               $matches = array();
 
-                       // version
-                       switch($browserInfo['browser']) {
-                               case 'netscape':
-                                       $browserInfo['version'] = self::getVersion(substr($userAgent, 8));
-                                       if (strstr($userAgent, 'Netscape6')) {
-                                               $browserInfo['version'] = 6;
-                                       }
-                               break;
-                               case 'msie':
-                                       $tmp = strstr($userAgent, 'MSIE');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 4));
-                               break;
-                               case 'opera':
-                                       $tmp = strstr($userAgent, 'Opera');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 5));
-                               break;
-                               case 'lynx':
-                                       $tmp = strstr($userAgent, 'Lynx/');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 5));
-                               break;
-                               case 'php':
-                                       $tmp = strstr($userAgent, 'PHP/');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 4));
-                               break;
-                               case 'avantgo':
-                                       $tmp = strstr($userAgent, 'AvantGo');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 7));
-                               break;
-                               case 'acrobat':
-                                       $tmp = strstr($userAgent, 'WebCapture');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 10));
-                               break;
-                               case 'ibrowse':
-                                       $tmp = strstr($userAgent, 'IBrowse/');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp ,8));
-                               break;
-                               case 'konqueror':
-                                       $tmp = strstr($userAgent, 'Konqueror/');
-                                       $browserInfo['version'] = self::getVersion(substr($tmp, 10));
-                               break;
+               $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
+                       // Find all phrases (or return empty array if none found)
+               if (!preg_match_all($pattern, strtolower($userAgent), $matches)) {
+                       $browserInfo['browser'] = 'unknown';
+               } else {
+                               // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
+                               // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
+                               // in the UA).  That's usually the most correct.
+                       $i = count($matches['browser']) - 1;
+                       $browserInfo['browser'] = $matches['browser'][$i];
+                       $browserInfo['version'] = $matches['version'][$i];
+                               //But return all parsed browsers / version in an extra array
+                       for ($i = 0; $i < count($matches['browser']); $i++) {
+                               $browserInfo['all'][$matches['browser'][$i]] = $matches['version'][$i];
                        }
-                       // system
-                       $browserInfo['system'] = '';
-                       if (strstr($userAgent, 'Win')) {
-                               // windows
-                               if (strstr($userAgent, 'Win98') || strstr($userAgent, 'Windows 98')) {
-                                       $browserInfo['system'] = 'win98';
-                               } elseif (strstr($userAgent, 'Win95') || strstr($userAgent, 'Windows 95')) {
-                                       $browserInfo['system'] = 'win95';
-                               } 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';
-                               // unixes
-                       } elseif (strstr($userAgent, 'Linux')) {
-                               $browserInfo['system'] = 'linux';
-                       } elseif (strstr($userAgent, 'SGI') && strstr($userAgent, ' IRIX ')) {
-                               $browserInfo['system'] = 'unix_sgi';
-                       } elseif (strstr($userAgent, ' SunOS ')) {
-                               $browserInfo['system'] = 'unix_sun';
-                       } elseif (strstr($userAgent, ' HP-UX ')) {
-                               $browserInfo['system'] = 'unix_hp';
+               }
+
+
+               // system
+               $browserInfo['system'] = '';
+               if (strstr($userAgent, 'Win')) {
+                       // windows
+                       if (strstr($userAgent, 'Win98') || strstr($userAgent, 'Windows 98')) {
+                               $browserInfo['system'] = 'win98';
+                       } elseif (strstr($userAgent, 'Win95') || strstr($userAgent, 'Windows 95')) {
+                               $browserInfo['system'] = 'win95';
+                       } 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';
+                       // unixes
+               } elseif (strstr($userAgent, 'Linux')) {
+                       $browserInfo['system'] = 'linux';
+               } elseif (strstr($userAgent, 'SGI') && strstr($userAgent, ' IRIX ')) {
+                       $browserInfo['system'] = 'unix_sgi';
+               } elseif (strstr($userAgent, ' SunOS ')) {
+                       $browserInfo['system'] = 'unix_sun';
+               } elseif (strstr($userAgent, ' HP-UX ')) {
+                       $browserInfo['system'] = 'unix_hp';
                }
 
                return $browserInfo;