From 0d0c7beb2a3e2d073225fe111fe4f4d4fd7df3a5 Mon Sep 17 00:00:00 2001 From: Anthon Pang Date: Sun, 17 Feb 2013 19:40:52 -0500 Subject: [PATCH] fixes #3557 - add Xbox and NetFront browser (WiiU, PS Vita, 3DS) detection --- libs/UserAgentParser/UserAgentParser.php | 50 +++++++++++++++----- plugins/UserSettings/images/browsers/NF.gif | Bin 0 -> 612 bytes plugins/UserSettings/images/os/3DS.gif | Bin 0 -> 1085 bytes plugins/UserSettings/images/os/PSV.gif | Bin 0 -> 200 bytes plugins/UserSettings/images/os/WIU.gif | Bin 0 -> 310 bytes plugins/UserSettings/images/os/XBX.gif | Bin 0 -> 1043 bytes tests/PHPUnit/Plugins/UserSettingsTest.php | 32 ++++++++++++- 7 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 plugins/UserSettings/images/browsers/NF.gif create mode 100644 plugins/UserSettings/images/os/3DS.gif create mode 100644 plugins/UserSettings/images/os/PSV.gif create mode 100644 plugins/UserSettings/images/os/WIU.gif create mode 100644 plugins/UserSettings/images/os/XBX.gif diff --git a/libs/UserAgentParser/UserAgentParser.php b/libs/UserAgentParser/UserAgentParser.php index 1877e2c28f5..2bf477a309d 100644 --- a/libs/UserAgentParser/UserAgentParser.php +++ b/libs/UserAgentParser/UserAgentParser.php @@ -153,6 +153,9 @@ class UserAgentParser 'netscape6' => 'NS', 'netscape' => 'NS', + 'nx' => 'NF', + 'netfront' => 'NF', + 'omniweb' => 'OW', // Opera @@ -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'), ); @@ -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', @@ -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', @@ -319,7 +328,6 @@ class UserAgentParser 'BEOS' => 'BEO', 'Amiga' => 'AMI', 'AmigaOS' => 'AMI', - ); // os family @@ -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') @@ -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) @@ -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])]; } @@ -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)) @@ -546,6 +567,7 @@ static public function getBrowser($userAgent) return $info; } + return false; } @@ -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'; @@ -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', @@ -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', diff --git a/plugins/UserSettings/images/browsers/NF.gif b/plugins/UserSettings/images/browsers/NF.gif new file mode 100644 index 0000000000000000000000000000000000000000..8ad4aff66689a87d3477f837b8b6bf9c186ac70f GIT binary patch literal 612 zcmZ?wbhEHb6krfwI99>Hz%ZAAVIBj+A_j&f3=B&d7?v?GEN5U?!N9PRfngN`!x{#L zwTx`@8Tcl!b1fC-n#jewgiByPufP&+@o5U;(-bAAiYZN1QS1@d?A0@DR56>NYqm_^ ze3^&uMvsJvXZ@MZ2QuFdWVjK+kd(RodL+w@NanPR{WqdmGb>hnNMZPx%J3|M<9#~A z@{*YAIqE;t7#geRe9K@ct=aK1hpnJ#$>#!=(zaFai?}|O@_sJmu5a7(t(4 z?*C;B|EqwAv7vu$|D5EV<#^iJ9+u|smsUDojG^m>bZ+ouUxxz{l?8}w=Ung zee=$pJ9j}C1nvRx{Tui1-MjnX;hhIh9zDGO;PLfGkM2KybpOfY2alfIee&e~(IdiwV5!*_2VfB5j=KMtVylZBCsp`Jkp7!$x45ny0oKiE*; z)Lif3(bCcE5|W-C;?mjV9hROH7njuM+Tt0ZoSZd%(acbG26^sd`NU z9Y;3ZHMN%9b zqV`(;K8lannZwiF8DH5OYg(&6dMs1+q9S60o_oKj0*k6eLPNtulVGWU9~&PrD{*u2 sc_e&3c8pa)Md@#6gF~CNu4Ka(;h*e>#mt=}R8oGjvrh47WMHrc0BmU~AOHXW literal 0 HcmV?d00001 diff --git a/plugins/UserSettings/images/os/3DS.gif b/plugins/UserSettings/images/os/3DS.gif new file mode 100644 index 0000000000000000000000000000000000000000..39e72e68f5182ccd1bd74d2d60a4336517fd154b GIT binary patch literal 1085 zcmZ?wbhEHb6krfwcz&CKjfI_uotu}Po1aylkCRt`n~$G|Pk={2kVin6OHq(lK#*5Z zkWWB}Ur`iy{{mCp4DEEGds!QW>{AD>Jh?etAXGin@$74H+vNN@nzyls1*j zZ7Ew+`jtZ#*s^pZ~wWo?(vIfU*F&R z@c!M$5AQ#I`0()~5Pkgo@x$j&A3uNk^!4+{ub)4C`}*bk_isOc{P_73h<^V1`SZ{3 zpMU=R`TG}${{91^fB*i|7byN@VdP@?&!EEq1fV>@!10gaf2gAJGViH6VY46w*LQ*Ra+oa6P+s<6qi8?>QVu8TNMiz$STN1m?dZo7J zdMYGzSSUC#SybIQv2t>|zXG4Qnv2X;&kzltX-bY!Q#dXv*pw;p{k+uFt?oO=EcR50 zhjY7tVC9uri#uj)NIY1;=>7DO`wa2_d`lyZR$gBlzo+DFQYzDFPRU*l&!EpI!&b*^ z2w7Xi>U^A6y8qD^$KaP!G=r7~EMziu=A0nW!}B+?m{nkkS&eKZjVTVUW~Uro4roo{eI)clBZl$%^M*$p USCTkBOrF%^QhfH0HVcC_0H`8h^Z)<= literal 0 HcmV?d00001 diff --git a/plugins/UserSettings/images/os/WIU.gif b/plugins/UserSettings/images/os/WIU.gif new file mode 100644 index 0000000000000000000000000000000000000000..6d7e64e1621af2c07278759aed2b1bd1772f8b48 GIT binary patch literal 310 zcmZ?wbhEHb6krfwSgOFlF!gv-QAc+KM;Tk5QA1g@h1x-7lS>64g(N?{KUW(>@cCgLr1Fr#FC%h1{B89P5K!G7#hELpq=S-r;2^OaA0}Lq)rdq#6Er%j(R(~-d%00g+kp8x;= literal 0 HcmV?d00001 diff --git a/plugins/UserSettings/images/os/XBX.gif b/plugins/UserSettings/images/os/XBX.gif new file mode 100644 index 0000000000000000000000000000000000000000..a9d567660e08c8d13db3f5f22a88252f90e56732 GIT binary patch literal 1043 zcmd^;`A<>-0LP!5=xnoc%dV|EYc*Xf(~c#QnrY58R^eQlI@Vg+Dm!PF_souk1r5R{ z_BeYWh=7U$@;EfW7vTkH<`D#9XjEiB*z51;^Zo3*egA-OYFbKs!i5MR0&u|qzVb+F zRboM1UjFm*#dSr=4TMw>Gv#vq#oC&>^rn?p`qB5!H6)8+c zBgkYmf^S(MR3WT{nmEu~?yb%ws({9Zcvn;>IS`-2=5g5k(k=pzBj9lPH#O;e9xUKv z3TZ8`-w8zUJCP7>7Q*6YSRxXNMM8;KBzcVFNSdW$u~Z^%t<~pLYpbh_q$*=hi=)YFu9hmK%3Z)cQ3pY8O9P>~ zDwRg9>ei@{ZVjT+Dz#c2qSeDTGJ+Vob=WZIb;cIkZG*nYXy}m)-0A5x_4b~@F4;dDAjN1UUhBcH~`#+?%*6JG@rlT%YupC`Sr%QfzDxjinA+x^w+ z^-g=Ir>A`$pT{%f@%d(Ed|2H7YUZ2&n}2q8?)&#ZAn@bYPb_o6U?3O_&j0>{vGBjL z`S+5LFkk`L17Q671c37c3!xiMG=un4P5TpAKY!GJ#y-#LdMRHm0$X(z23voqmDK zD?|M&$+{>4^|(?^2_tS?zvjLISN5fx5`XBB5)ai9x5sUZRYdQrE(_nW>}kgQWGH3p zF+wE5UBwN-E!u1hB-GcS%mdkR@mb~W+@-+Yn!>dOC3F>#Y& zRZQuo@OAOy$3s^~6P@R*I?ERPQYdP6Wns_DeWg*PYeCTp#*v4SM|Vd>0EhnqrJBca literal 0 HcmV?d00001 diff --git a/tests/PHPUnit/Plugins/UserSettingsTest.php b/tests/PHPUnit/Plugins/UserSettingsTest.php index 0c776cf1443..a6dfc860f92 100644 --- a/tests/PHPUnit/Plugins/UserSettingsTest.php +++ b/tests/PHPUnit/Plugins/UserSettingsTest.php @@ -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'))), @@ -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'), @@ -937,7 +968,6 @@ public function getUserAgents() array('CH', 'Chrome', 'Chrome', '4.0', '4', '0', 'webkit'), array('LIN', 'Linux', 'Linux'))), - // Email Clients // Thunderbird