Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libs/UserAgentParser/UserAgentParser.php')
-rw-r--r--libs/UserAgentParser/UserAgentParser.php452
1 files changed, 121 insertions, 331 deletions
diff --git a/libs/UserAgentParser/UserAgentParser.php b/libs/UserAgentParser/UserAgentParser.php
index a1c081f9fe..4aa70356e2 100644
--- a/libs/UserAgentParser/UserAgentParser.php
+++ b/libs/UserAgentParser/UserAgentParser.php
@@ -29,213 +29,91 @@ class UserAgentParser
// browser regex => browser ID
// if there are aliases, the common name should be last
static protected $browsers = array(
- 'abrowse' => 'AB',
- 'amaya' => 'AM',
- 'amigavoyager' => 'AV',
- 'amiga-aweb' => 'AW',
- 'android' => 'AN',
- 'arora' => 'AR',
- 'beonex' => 'BE',
- 'blackberry' => 'BB',
- 'browsex' => 'BX',
-
- // Camino (and earlier incarnation)
- 'chimera' => 'CA',
- 'camino' => 'CA',
-
- 'cheshire' => 'CS',
-
- // Chrome, Chromium, and ChromePlus
- 'chrome' => 'CH',
-
- 'cometbird' => 'CO',
- 'dillo' => 'DI',
- 'elinks' => 'EL',
- 'epiphany' => 'EP',
- 'fennec' => 'FE',
-
- // Firefox (in its many incarnations and rebranded versions)
- 'phoenix' => 'PX',
- 'mozilla firebird' => 'FB',
- 'firebird' => 'FB',
- 'bonecho' => 'FF',
- 'minefield' => 'FF',
- 'namoroka' => 'FF',
- 'shiretoko' => 'FF',
- 'granparadiso' => 'FF',
- 'iceweasel' => 'FF',
- 'icecat' => 'FF',
- 'firefox' => 'FF',
-
- 'flock' => 'FL',
- 'fluid' => 'FD',
- 'galeon' => 'GA',
- 'google earth' => 'GE',
- 'hana' => 'HA',
- 'hotjava' => 'HJ',
- 'ibrowse' => 'IB',
- 'icab' => 'IC',
-
- // IE (including shells: Acoo, AOL, Avant, Crazy Browser, Green Browser, KKMAN, Maxathon)
- 'msie' => 'IE',
- 'microsoft internet explorer' => 'IE',
- 'internet explorer' => 'IE',
-
- 'iron' => 'IR',
- 'kapiko' => 'KP',
- 'kazehakase' => 'KZ',
- 'k-meleon' => 'KM',
- 'konqueror' => 'KO',
- 'links' => 'LI',
- 'lynx' => 'LX',
- 'midori' => 'MI',
-
- // SeaMonkey (formerly Mozilla Suite) (and rebranded versions)
- 'mozilla' => 'MO',
- 'gnuzilla' => 'SM',
- 'iceape' => 'SM',
- 'seamonkey' => 'SM',
-
- // NCSA Mosaic (and incarnations)
- 'mosaic' => 'MC',
- 'ncsa mosaic' => 'MC',
-
- // Netscape Navigator
- 'navigator' => 'NS',
- 'netscape6' => 'NS',
- 'netscape' => 'NS',
-
- 'omniweb' => 'OW',
-
- // Opera
- 'nitro) opera' => 'OP',
- 'opera' => 'OP',
-
- // Safari
- 'safari' => 'SF',
-
- 'webos' => 'WO',
- 'webpro' => 'WP',
- );
-
- // browser family (by layout engine)
- static protected $browserType = array(
- 'ie' => array('IE'),
- 'gecko' => array('NS', 'PX', 'FF', 'FB', 'CA', 'GA', 'KM', 'MO', 'SM', 'CO', 'FE', 'KP', 'KZ'),
- 'khtml' => array('KO'),
- 'webkit' => array('SF', 'CH', 'OW', 'AR', 'EP', 'FL', 'WO', 'AN', 'AB', 'IR', 'CS', 'FD', 'HA', 'MI', 'GE'),
- 'opera' => array('OP'),
- );
-
- // WebKit version numbers to Apple Safari version numbers (if Version/X.Y.Z not present)
- static protected $safariVersions = array(
- '533.16' => array('5', '0'),
- '533.4' => array('4', '1'),
- '526.11.2' => array('4', '0'),
- '525.26' => array('3', '2'),
- '525.13' => array('3', '1'),
- '522.11' => array('3', '0'),
- '412' => array('2', '0'),
- '312' => array('1', '3'),
- '125' => array('1', '1'),
- '85' => array('1', '0'),
- '73' => array('0', '9'),
- '48' => array('0', '8'),
- );
-
- // OmniWeb build numbers to OmniWeb version numbers (if Version/X.Y.Z not present)
- static protected $omniWebVersions = array(
- '622.10' => array('5', '10'),
- '622.8' => array('5', '9'),
- '622.3' => array('5', '8'),
- '621' => array('5', '7'),
- '613' => array('5', '6'),
- '607' => array('5', '5'),
- '563.34' => array('5', '1'),
- '558.36' => array('5', '0'),
- '496' => array('4', '5'),
- );
+ 'opera' => 'OP',
+ 'msie' => 'IE',
+ 'microsoft internet explorer' => 'IE',
+ 'internet explorer' => 'IE',
+ 'netscape6' => 'NS',
+ 'netscape' => 'NS',
+ 'galeon' => 'GA',
+ 'minefield' => 'FF',
+ 'namoroka' => 'FF',
+ 'shiretoko' => 'FF',
+ 'bonecho' => 'FF',
+ 'granparidiso' => 'FF',
+ 'mozilla firebird' => 'FB',
+ 'firebird' => 'FB',
+ 'firefox' => 'FF',
+ 'phoenix' => 'PX',
+ 'seamonkey' => 'SM',
+ 'camino' => 'CA',
+ 'safari' => 'SF',
+ 'chrome' => 'CH',
+ 'k-meleon' => 'KM',
+ 'mozilla' => 'MO',
+ 'konqueror' => 'KO',
+ 'blackberry' => 'BB',
+ 'icab' => 'IC',
+ 'lynx' => 'LX',
+ 'links' => 'LI',
+ 'ncsa mosaic' => 'MC',
+ 'amaya' => 'AM',
+ 'omniweb' => 'OW',
+ 'hotjava' => 'HJ',
+ 'browsex' => 'BX',
+ 'amigavoyager' => 'AV',
+ 'amiga-aweb' => 'AW',
+ 'ibrowse' => 'IB',
+ 'arora' => 'AR',
+ 'iron' => 'IR',
+ );
// OS regex => OS ID
static protected $operatingSystems = array(
- 'Android' => 'AND',
- 'Linux' => 'LIN',
-
- 'CYGWIN_NT-6.1' => 'WI7',
- 'Windows NT 6.1' => 'WI7',
- 'Windows 7' => 'WI7',
- 'CYGWIN_NT-6.0' => 'WVI',
- 'Windows NT 6.0' => 'WVI',
- 'Windows Vista' => 'WVI',
- 'CYGWIN_NT-5.2' => 'WS3',
- 'Windows NT 5.2' => 'WS3',
- 'Windows Server 2003 / XP x64' => 'WS3',
- 'CYGWIN_NT-5.1' => 'WXP',
- 'Windows NT 5.1' => 'WXP',
- 'Windows XP' => 'WXP',
- 'CYGWIN_NT-5.0' => 'W2K',
- 'Windows NT 5.0' => 'W2K',
- 'Windows 2000' => 'W2K',
- 'CYGWIN_NT-4.0' => 'WNT',
- 'Windows NT 4.0' => 'WNT',
- 'WinNT' => 'WNT',
- 'Windows NT' => 'WNT',
- 'CYGWIN_ME-4.90' => 'WME',
- 'Win 9x 4.90' => 'WME',
- 'Windows ME' => 'WME',
- 'CYGWIN_98-4.10' => 'W98',
- 'Win98' => 'W98',
- 'Windows 98' => 'W98',
- 'CYGWIN_95-4.0' => 'W95',
- 'Win32' => 'W95',
- 'Win95' => 'W95',
- 'Windows 95' => 'W95',
-
- 'iPod' => 'IPD',
- 'iPad' => 'IPA',
- 'iPhone' => 'IPH',
-// 'iOS' => 'IOS',
- 'Darwin' => 'MAC',
- 'Macintosh' => 'MAC',
- 'Power Macintosh' => 'MAC',
- 'Mac_PowerPC' => 'MAC',
- 'Mac PPC' => 'MAC',
- 'PPC' => 'MAC',
- 'Mac PowerPC' => 'MAC',
- 'Mac OS' => 'MAC',
-
- 'webOS' => 'WOS',
- 'Palm webOS' => 'WOS',
- 'PalmOS' => 'POS',
- 'Palm OS' => 'POS',
-
- 'BlackBerry' => 'BLB',
-
- 'SunOS' => 'SOS',
- 'AIX' => 'AIX',
- 'HP-UX' => 'HPX',
-
- 'FreeBSD' => 'BSD',
- 'NetBSD' => 'NBS',
- 'OpenBSD' => 'OBS',
- 'DragonFly' => 'DFB',
- 'Syllable' => 'SYL',
-
- 'Nintendo Wii' => 'WII',
- 'Nitro' => 'NDS',
- 'Nintendo DS ' => 'NDS',
- 'Nintendo DSi' => 'DSI',
- 'PlayStation Portable' => 'PSP',
- 'PlayStation 3' => 'PS3',
-
- 'IRIX' => 'IRI',
- 'OSF1' => 'T64',
- 'OS/2' => 'OS2',
- 'BEOS' => 'BEO',
- 'Amiga' => 'AMI',
- 'AmigaOS' => 'AMI',
+ 'iPod' => 'IPD',
+ 'iPhone' => 'IPH',
+ 'Nintendo Wii' => 'WII',
+ 'PlayStation Portable' => 'PSP',
+ 'PlayStation 3' => 'PS3',
+ 'Android' => 'AND',
+ 'PalmOS' => 'POS',
+ 'Palm OS' => 'POS',
+ 'BlackBerry' => 'BLB',
+ 'Windows NT 6.1' => 'WI7',
+ 'Windows 7' => 'WI7',
+ 'Windows NT 6.0' => 'WVI',
+ 'Windows Vista' => 'WVI',
+ 'Windows NT 5.2' => 'WS3',
+ 'Windows Server 2003' => 'WS3',
+ 'Windows NT 5.1' => 'WXP',
+ 'Windows XP' => 'WXP',
+ 'Win98' => 'W98',
+ 'Windows 98' => 'W98',
+ 'Windows NT 5.0' => 'W2K',
+ 'Windows 2000' => 'W2K',
+ 'Windows NT 4.0' => 'WNT',
+ 'WinNT' => 'WNT',
+ 'Windows NT' => 'WNT',
+ 'Win 9x 4.90' => 'WME',
+ 'Windows ME' => 'WME',
+ 'Win32' => 'W95',
+ 'Win95' => 'W95',
+ 'Windows 95' => 'W95',
+ 'Mac_PowerPC' => 'MAC',
+ 'Mac PPC' => 'MAC',
+ 'PPC' => 'MAC',
+ 'Mac PowerPC' => 'MAC',
+ 'Mac OS' => 'MAC',
+ 'Linux' => 'LIN',
+ 'SunOS' => 'SOS',
+ 'FreeBSD' => 'BSD',
+ 'AIX' => 'AIX',
+ 'IRIX' => 'IRI',
+ 'HP-UX' => 'HPX',
+ 'OS/2' => 'OS2',
+ 'NetBSD' => 'NBS',
);
-
+
static protected $browserIdToName;
static protected $browserIdToShortName;
static protected $operatingSystemsIdToName;
@@ -276,12 +154,10 @@ class UserAgentParser
*
* @param string $userAgent
* @return array false if the browser is "unknown", or
- * array( 'id' => '', // 2 letters ID, eg. FF
- * 'name' => '', // 2 letters ID, eg. FF
- * 'short_name' => '', // 2 letters ID, eg. FF
+ * array( 'name' => '', // 2 letters ID, eg. FF
* 'major_number' => '', // 2 in firefox 2.0.12
* 'minor_number' => '', // 0 in firefox 2.0.12
- * 'version' => '', // major_number.minor_number
+ * 'version' => '' // major_number.minor_number
* );
* @see self::$browsers for the list of OS
*/
@@ -296,52 +172,31 @@ class UserAgentParser
'major_number' => '',
'minor_number' => '',
'version' => '',
- );
-
- $browsers = self::$browsers;
+ );
- // derivative browsers often clone the base browser's useragent
- unset($browsers['firefox']);
- unset($browsers['mozilla']);
- unset($browsers['safari']);
-
- $browsersPattern = str_replace(')', '\)', implode('|', array_keys($browsers)));
+ $browser = implode('|', array_keys(self::$browsers));
$results = array();
- // Misbehaving IE add-ons
- $userAgent = preg_replace('/[; ]Mozilla\/[0-9.]+ \([^)]+\)/', '', $userAgent);
-
- if (preg_match_all("/($browsersPattern)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
- || preg_match_all("/(firefox|safari)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
- || preg_match_all("/^(mozilla)\/([0-9]+)([\.0-9a-z-]+)?(?: \[[a-z]{2}\])? (?:\([^)]*\))$/i", $userAgent, $results)
- || preg_match_all("/^(mozilla)\/[0-9]+(?:[\.0-9a-z-]+)?\s\(.* rv:([0-9]+)([.0-9a-z]+)\) gecko(\/[0-9]{8}|$)(?:.*)/i", $userAgent, $results)
+ // added fixes for Mozilla Suite and Chrome/Iron detection
+ if (preg_match_all("/(mozilla)[\/\sa-z;.0-9-(]+rv:([0-9]+)([.0-9a-z]+)\) gecko\/[0-9]{8}$/i", $userAgent, $results)
+ || preg_match_all("/(chrome|iron)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
+ || preg_match_all("/($browser)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
)
{
- // browser code (usually the first match)
- $count = 0;
- $info['id'] = self::$browsers[strtolower($results[1][0])];
-
- // sometimes there's a better match at the end
- if(($info['id'] == 'IE' || $info['id'] == 'LX') && (count($results[0]) > 1)) {
- $count = count($results[0]) - 1;
- $info['id'] = self::$browsers[strtolower($results[1][$count])];
- }
+ $count = count($results[0])-1;
- // Netscape fix
- if($info['id'] == 'MO' && $count == 0) {
- if(strpos($userAgent, 'PlayStation Portable') !== false) return false;
- if(count($results) == 4) {
- $info['id'] = 'NS';
- }
- }
+ // browser code
+ $info['id'] = self::$browsers[strtolower($results[1][$count])];
+ $info['name'] = self::getBrowserNameFromId($info['id']);
+ $info['short_name'] = self::getBrowserShortNameFromId($info['id']);
- // Version/X.Y.Z override
- if(preg_match_all("/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
+ // Opera 10 fix
+ if($info['id'] == 'OP' && preg_match_all("/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
$results = $newResults;
$count = count($results[0])-1;
}
-
+
// major version number (1 in mozilla 1.7)
$info['major_number'] = $results[2][$count];
@@ -363,39 +218,7 @@ class UserAgentParser
else {
$info['minor_number'] = '0';
}
- $info['version'] = $info['major_number'] . '.' . $info['minor_number'];
-
- // Safari fix
- if($info['id'] == 'SF') {
- foreach(self::$safariVersions as $buildVersion => $productVersion) {
- if(version_compare($info['version'], $buildVersion) >= 0) {
- $info['major_number'] = $productVersion[0];
- $info['minor_number'] = $productVersion[1];
- $info['version'] = $productVersion[0] . '.' . $productVersion[1];
- break;
- }
- }
- }
-
- // OmniWeb fix
- if($info['id'] == 'OW') {
- foreach(self::$omniWebVersions as $buildVersion => $productVersion) {
- if(version_compare($info['version'], $buildVersion) >= 0) {
- $info['major_number'] = $productVersion[0];
- $info['minor_number'] = $productVersion[1];
- $info['version'] = $productVersion[0] . '.' . $productVersion[1];
- break;
- }
- }
- }
-
- // SeaMonkey fix
- if($info['id'] == 'MO' && $info['version'] == '1.9') {
- $info['id'] = 'SM';
- }
-
- $info['name'] = self::getBrowserNameFromId($info['id']);
- $info['short_name'] = self::getBrowserShortNameFromId($info['id']);
+ $info['version'] = $info['major_number'] . "." . $info['minor_number'];
return $info;
}
@@ -410,47 +233,19 @@ class UserAgentParser
// init browser names and short names
self::$browserIdToName = array_map('ucwords',array_flip(self::$browsers));
- self::$browserIdToName['AB'] = 'ABrowse';
- self::$browserIdToName['AV'] = 'AmigaVoyager';
- self::$browserIdToName['AW'] = 'Amiga AWeb';
- self::$browserIdToName['BB'] = 'BlackBerry';
- self::$browserIdToName['BX'] = 'BrowseX';
- self::$browserIdToName['CO'] = 'CometBird';
- self::$browserIdToName['EL'] = 'ELinks';
- self::$browserIdToName['FF'] = 'Firefox';
- self::$browserIdToName['HJ'] = 'HotJava';
- self::$browserIdToName['IB'] = 'IBrowse';
- self::$browserIdToName['IC'] = 'iCab';
- self::$browserIdToName['KM'] = 'K-Meleon';
- self::$browserIdToName['MC'] = 'NCSA Mosaic';
- self::$browserIdToName['OW'] = 'OmniWeb';
- self::$browserIdToName['SF'] = 'Safari';
- self::$browserIdToName['SM'] = 'SeaMonkey';
- self::$browserIdToName['WO'] = 'Palm webOS';
- self::$browserIdToName['WP'] = 'WebPro';
+ self::$browserIdToName['CH'] = "Google Chrome";
self::$browserIdToShortName = self::$browserIdToName;
- self::$browserIdToShortName['AW'] = 'AWeb';
- self::$browserIdToShortName['FB'] = 'Firebird';
- self::$browserIdToShortName['IE'] = 'IE';
- self::$browserIdToShortName['MC'] = 'Mosaic';
- self::$browserIdToShortName['WO'] = 'webOS';
+ self::$browserIdToShortName['IE'] = "IE";
+ self::$browserIdToShortName['FB'] = "Firebird";
// init OS names and short names
- self::$operatingSystemsIdToName = array_merge(array_flip(self::$operatingSystems), array(
- 'IPD' => 'iPod',
- 'IPA' => 'iPad',
- 'WME' => 'Windows Me',
- 'BEO' => 'BeOS',
- 'T64' => 'Tru64',
- 'NDS' => 'Nintendo DS',
- ));
+ self::$operatingSystemsIdToName = array_flip(self::$operatingSystems);
self::$operatingSystemsIdToShortName = array_merge(self::$operatingSystemsIdToName, array(
'PS3' => 'PS3',
'PSP' => 'PSP',
- 'WII' => 'Wii',
- 'NDS' => 'DS',
- 'DSI' => 'DSi',
+ 'IPH' => 'iPhone',
+ 'WII' => 'WII',
'WI7' => 'Win 7',
'WVI' => 'Win Vista',
'WS3' => 'Win S2003',
@@ -459,13 +254,22 @@ class UserAgentParser
'W2K' => 'Win 2000',
'WNT' => 'Win NT',
'WME' => 'Win Me',
- 'W95' => 'Win 95',
+ 'W95' => 'Win 95',
'WCE' => 'Win CE',
- 'WOS' => 'webOS',
+ 'MAC' => 'Mac OS',
+ 'LIN' => 'Linux',
+ 'INC' => 'Inconnu',
+ 'SOS' => 'SunOS',
+ 'BSD' => 'FreeBSD',
+ 'AIX' => 'AIX',
+ 'IRI' => 'IRIX',
+ 'HPX' => 'HPX',
+ 'OS2' => 'OS/2',
+ 'NBS' => 'NetBSD',
'UNK' => 'Unknown',
- ));
+ ));
}
-
+
static public function getBrowserNameFromId($browserId)
{
self::init();
@@ -474,7 +278,7 @@ class UserAgentParser
}
return false;
}
-
+
static public function getBrowserShortNameFromId($browserId)
{
self::init();
@@ -483,22 +287,7 @@ class UserAgentParser
}
return false;
}
-
- static public function getBrowserFamilyFromId($browserId)
- {
- self::init();
- $familyNameToUse = 'unknown';
- foreach(self::$browserType as $familyName => $aBrowsers)
- {
- if(in_array($browserId, $aBrowsers))
- {
- $familyNameToUse = $familyName;
- break;
- }
- }
- return $familyNameToUse;
- }
-
+
static public function getOperatingSystemNameFromId($osId)
{
self::init();
@@ -515,5 +304,6 @@ class UserAgentParser
return self::$operatingSystemsIdToShortName[$osId];
}
return false;
- }
+
+ }
}