Skip to content

Commit

Permalink
fixes #3557 - add Xbox and NetFront browser (WiiU, PS Vita, 3DS) dete…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
robocoder committed Feb 18, 2013
1 parent 645fddf commit 573f6a3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 12 deletions.
50 changes: 39 additions & 11 deletions libs/UserAgentParser/UserAgentParser.php
Expand Up @@ -153,6 +153,9 @@ class UserAgentParser
'netscape6' => 'NS',
'netscape' => 'NS',

'nx' => 'NF',
'netfront' => 'NF',

'omniweb' => 'OW',

// Opera
Expand All @@ -176,7 +179,7 @@ class UserAgentParser
'ie' => array('IE'),
'gecko' => array('NS', 'PX', 'FF', 'FB', 'CA', 'GA', 'KM', 'MO', 'SM', 'CO', 'FE', 'KP', 'KZ', 'TB'),
'khtml' => array('KO'),
'webkit' => array('SF', 'CH', 'OW', 'AR', 'EP', 'FL', 'WO', 'AB', 'IR', 'CS', 'FD', 'HA', 'MI', 'GE', 'DF', 'BB', 'BP', 'TI', 'CF', 'RK', 'B2'),
'webkit' => array('SF', 'CH', 'OW', 'AR', 'EP', 'FL', 'WO', 'AB', 'IR', 'CS', 'FD', 'HA', 'MI', 'GE', 'DF', 'BB', 'BP', 'TI', 'CF', 'RK', 'B2', 'NF'),
'opera' => array('OP'),
);

Expand Down Expand Up @@ -217,9 +220,11 @@ class UserAgentParser
static protected $operatingSystems = array(
'Android' => 'AND',
'Maemo' => 'MAE',
'CrOS ' => 'LIN',
'CrOS ' => 'LIN',
'Linux' => 'LIN',

'Xbox' => 'XBX',

// workaround for vendors who changed the WinPhone 7 user agent
'WP7' => 'WPH',

Expand Down Expand Up @@ -306,10 +311,14 @@ class UserAgentParser
'DragonFly' => 'DFB',
'Syllable' => 'SYL',

'Nintendo WiiU' => 'WIU',
'Nintendo Wii' => 'WII',
'Nitro' => 'NDS',
'Nintendo DS ' => 'NDS',
'Nintendo DSi' => 'DSI',
'Nintendo DS' => 'NDS',
'Nintendo 3DS' => '3DS',

'PlayStation Vita' => 'PSV',
'PlayStation Portable' => 'PSP',
'PlayStation 3' => 'PS3',

Expand All @@ -319,7 +328,6 @@ class UserAgentParser
'BEOS' => 'BEO',
'Amiga' => 'AMI',
'AmigaOS' => 'AMI',

);

// os family
Expand All @@ -332,8 +340,8 @@ class UserAgentParser
'iOS' => array('IPD', 'IPA', 'IPH'),
'Android' => array('AND'),
'Windows Mobile' => array('WPH', 'WMO', 'WCE'),
'Gaming Console' => array('WII', 'PS3'),
'Mobile Gaming Console' => array('PSP', 'NDS', 'DSI'),
'Gaming Console' => array('WII', 'WIU', 'PS3', 'XBX'),
'Mobile Gaming Console' => array('PSP', 'PSV', 'NDS', 'DSI', '3DS'),
'Unix' => array('SOS', 'AIX', 'HP-UX', 'BSD', 'NBS', 'OBS', 'DFB', 'SYL', 'IRI', 'T64'),
'Other Mobile' => array('MAE', 'WOS', 'POS', 'BLB', 'QNX', 'SYM', 'SBA'),
'Other' => array('VMS', 'OS2', 'BEOS', 'AMI')
Expand Down Expand Up @@ -436,6 +444,7 @@ static public function getBrowser($userAgent)
|| preg_match_all("/(applewebkit)[\/\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)
|| (strpos($userAgent, 'Nintendo 3DS') !== false && preg_match_all("/^(mozilla).*version\/([0-9]+)([.0-9a-z]+)?/i", $userAgent, $results))
)
{
// browser code (usually the first match)
Expand All @@ -447,7 +456,7 @@ static public function getBrowser($userAgent)
$count = count($results[0]) - 1;
$info['id'] = 'CF';
}
else if(($info['id'] == 'IE' || $info['id'] == 'LX') && (count($results[0]) > 1)) {
elseif(($info['id'] == 'IE' || $info['id'] == 'LX') && (count($results[0]) > 1)) {
$count = count($results[0]) - 1;
$info['id'] = self::$browsers[strtolower($results[1][$count])];
}
Expand All @@ -457,20 +466,32 @@ static public function getBrowser($userAgent)
if(stripos($userAgent, 'PlayStation') !== false) {
return false;
}
if(count($results) == 4) {
if(strpos($userAgent, 'Nintendo 3DS') !== false) {
$info['id'] = 'NF';
}
elseif(count($results) == 4) {
$info['id'] = 'NS';
}
}
// BlackBerry devices
else if(strpos($userAgent, 'BlackBerry') !== false) {
elseif(strpos($userAgent, 'BlackBerry') !== false) {
$info['id'] = 'BB';
}
else if(strpos($userAgent, 'RIM Tablet OS') !== false) {
elseif(strpos($userAgent, 'RIM Tablet OS') !== false) {
$info['id'] = 'BP';
}
else if(strpos($userAgent, 'BB10') !== false) {
elseif(strpos($userAgent, 'BB10') !== false) {
$info['id'] = 'B2';
}
elseif(strpos($userAgent, 'Playstation Vita') !== false) {
$info['id'] = 'NF';

if(preg_match_all("/(silk)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults))
{
$results = $newResults;
$count = count($results[0])-1;
}
}

// Version/X.Y.Z override
if(preg_match_all("/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults))
Expand Down Expand Up @@ -546,6 +567,7 @@ static public function getBrowser($userAgent)

return $info;
}

return false;
}

Expand Down Expand Up @@ -573,6 +595,7 @@ static protected function init() {
self::$browserIdToName['IC'] = 'iCab';
self::$browserIdToName['KM'] = 'K-Meleon';
self::$browserIdToName['MC'] = 'NCSA Mosaic';
self::$browserIdToName['NF'] = 'NetFront';
self::$browserIdToName['OW'] = 'OmniWeb';
self::$browserIdToName['SF'] = 'Safari';
self::$browserIdToName['SM'] = 'SeaMonkey';
Expand All @@ -595,6 +618,8 @@ static protected function init() {
'BEO' => 'BeOS',
'T64' => 'Tru64',
'NDS' => 'Nintendo DS',
'WIU' => 'Nintendo Wii U',
'3DS' => 'Nintendo 3DS',

// These are for BC purposes only
'W75' => 'WinPhone 7.5',
Expand All @@ -607,8 +632,11 @@ static protected function init() {
'PS3' => 'PS3',
'PSP' => 'PSP',
'WII' => 'Wii',
'WIU' => 'Wii U',
'NDS' => 'DS',
'DSI' => 'DSi',
'3DS' => '3DS',
'PSV' => 'PS Vita',
'WI8' => 'Win 8',
'WI7' => 'Win 7',
'WVI' => 'Win Vista',
Expand Down
Binary file added plugins/UserSettings/images/browsers/NF.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/UserSettings/images/os/3DS.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/UserSettings/images/os/PSV.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/UserSettings/images/os/WIU.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/UserSettings/images/os/XBX.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion tests/PHPUnit/Plugins/UserSettingsTest.php
Expand Up @@ -514,6 +514,12 @@ public function getUserAgents()
array('MAC', 'Mac OS', 'Mac OS'))),

// Internet Explorer
array('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)', array(
array('IE', 'Internet Explorer', 'IE', '9.0', '9', '0', 'ie'),
array('XBX', 'Xbox', 'Xbox'))),
array('Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Xbox)', array(
array('IE', 'Internet Explorer', 'IE', '9.0', '9', '0', 'ie'),
array('XBX', 'Xbox', 'Xbox'))),
array('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)', array(
array('IE', 'Internet Explorer', 'IE', '10.0', '10', '0', 'ie'),
array('WI8', 'Windows 8', 'Win 8'))),
Expand Down Expand Up @@ -748,6 +754,31 @@ public function getUserAgents()
array('NS', 'Netscape', 'Netscape', '2.02', '2', '02', 'gecko'),
array('WNT', 'Windows NT', 'Win NT'))),

// NetFront NX
array('Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Gecko) NX/2.1.0.8.21 NintendoBrowser/1.0.0.7494.US', array(
array('NF', 'NetFront', 'NetFront', '2.1', '2', '1', 'webkit'),
array('WIU', 'Nintendo Wii U', 'Wii U'))),
array('Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US', array(
array('NF', 'NetFront', 'NetFront', '1.7498', '1', '7498', 'webkit'),
array('3DS', 'Nintendo 3DS', '3DS'))),
array('Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2', array(
array('NF', 'NetFront', 'NetFront', '3.2', '3', '2', 'webkit'),
array('PSV', 'PlayStation Vita', 'PS Vita'))),

// Kindle
array('Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)', array(
array('NF', 'NetFront', 'NetFront', '3.3', '3', '3', 'webkit'),
array('LIN', 'Linux', 'Linux'))),
array('Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', array(
array('SF', 'Safari', 'Safari', '4.0', '4', '0', 'webkit'),
array('AND', 'Android', 'Android'))),
array('Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)', array(
array('SF', 'Safari', 'Safari', '4.0', '4', '0', 'webkit'),
array('LIN', 'Linux', 'Linux'))),
array('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true', array(
array('SF', 'Safari', 'Safari', '5.0', '5', '0', 'webkit'),
array('MAC', 'Mac OS', 'Mac OS'))),

// Omniweb
array('Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/525.18 (KHTML, like Gecko, Safari/525.20) OmniWeb/v622.3.0.105198', array(
array('OW', 'OmniWeb', 'OmniWeb', '5.8', '5', '8', 'webkit'),
Expand Down Expand Up @@ -937,7 +968,6 @@ public function getUserAgents()
array('CH', 'Chrome', 'Chrome', '4.0', '4', '0', 'webkit'),
array('LIN', 'Linux', 'Linux'))),


// Email Clients

// Thunderbird
Expand Down

0 comments on commit 573f6a3

Please sign in to comment.