PageRenderTime 1314ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/UserAgentParser/UserAgentParser.php

https://github.com/quarkness/piwik
PHP | 620 lines | 431 code | 69 blank | 120 comment | 50 complexity | 99ad7034ab2e318397c453160d54f656 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2009, 2010 Matthieu Aubry
  4. * All rights reserved.
  5. *
  6. * @link http://dev.piwik.org/trac/browser/trunk/libs/UserAgentParser
  7. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  8. * @version $Id$
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are
  12. * met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. *
  21. * * Neither the name of Matthieu Aubry nor the names of its contributors
  22. * may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /**
  38. * Example usage
  39. *
  40. * Browser info:
  41. * var_dump(UserAgentParser::getBrowser($_SERVER['HTTP_USER_AGENT']));
  42. *
  43. * Outputs:
  44. * array
  45. * 'id' => 'FF'
  46. * 'name' => 'Firefox'
  47. * 'short_name' => 'Firefox'
  48. * 'version' => '3.0'
  49. * 'major_number' => '3'
  50. * 'minor_number' => '0'
  51. *
  52. * Operating System info:
  53. * var_dump(UserAgentParser::getOperatingSystem($_SERVER['HTTP_USER_AGENT']));
  54. *
  55. * Outputs:
  56. * array
  57. * 'id' => 'WXP'
  58. * 'name' => 'Windows XP'
  59. * 'short_name' => 'Win XP'
  60. *
  61. */
  62. class UserAgentParser
  63. {
  64. // browser regex => browser ID
  65. // if there are aliases, the common name should be last
  66. static protected $browsers = array(
  67. 'abrowse' => 'AB',
  68. 'amaya' => 'AM',
  69. 'amigavoyager' => 'AV',
  70. 'amiga-aweb' => 'AW',
  71. 'arora' => 'AR',
  72. 'beonex' => 'BE',
  73. // BlackBerry smartphones and tablets
  74. 'blackberry' => 'BB', // BlackBerry 6 and PlayBook adopted webkit
  75. 'playbook' => 'BP',
  76. 'browsex' => 'BX',
  77. // Camino (and earlier incarnation)
  78. 'chimera' => 'CA',
  79. 'camino' => 'CA',
  80. 'cheshire' => 'CS',
  81. // Chrome, Chromium, and ChromePlus
  82. 'chrome' => 'CH',
  83. 'cometbird' => 'CO',
  84. 'dillo' => 'DI',
  85. 'elinks' => 'EL',
  86. 'epiphany' => 'EP',
  87. 'fennec' => 'FE',
  88. // Dolfin (or Dolphin)
  89. 'dolfin' => 'DF',
  90. // Firefox (in its many incarnations and rebranded versions)
  91. 'phoenix' => 'PX',
  92. 'mozilla firebird' => 'FB',
  93. 'firebird' => 'FB',
  94. 'bonecho' => 'FF',
  95. 'minefield' => 'FF',
  96. 'namoroka' => 'FF',
  97. 'shiretoko' => 'FF',
  98. 'granparadiso' => 'FF',
  99. 'iceweasel' => 'FF',
  100. 'icecat' => 'FF',
  101. 'firefox' => 'FF',
  102. 'flock' => 'FL',
  103. 'fluid' => 'FD',
  104. 'galeon' => 'GA',
  105. 'google earth' => 'GE',
  106. 'hana' => 'HA',
  107. 'hotjava' => 'HJ',
  108. 'ibrowse' => 'IB',
  109. 'icab' => 'IC',
  110. // IE (including shells: Acoo, AOL, Avant, Crazy Browser, Green Browser, KKMAN, Maxathon)
  111. 'msie' => 'IE',
  112. 'microsoft internet explorer' => 'IE',
  113. 'internet explorer' => 'IE',
  114. 'iron' => 'IR',
  115. 'kapiko' => 'KP',
  116. 'kazehakase' => 'KZ',
  117. 'k-meleon' => 'KM',
  118. 'konqueror' => 'KO',
  119. 'links' => 'LI',
  120. 'lynx' => 'LX',
  121. 'midori' => 'MI',
  122. // SeaMonkey (formerly Mozilla Suite) (and rebranded versions)
  123. 'mozilla' => 'MO',
  124. 'gnuzilla' => 'SM',
  125. 'iceape' => 'SM',
  126. 'seamonkey' => 'SM',
  127. // NCSA Mosaic (and incarnations)
  128. 'mosaic' => 'MC',
  129. 'ncsa mosaic' => 'MC',
  130. // Netscape Navigator
  131. 'navigator' => 'NS',
  132. 'netscape6' => 'NS',
  133. 'netscape' => 'NS',
  134. 'omniweb' => 'OW',
  135. // Opera
  136. 'nitro) opera' => 'OP',
  137. 'opera' => 'OP',
  138. // Safari
  139. 'safari' => 'SF',
  140. 'applewebkit' => 'SF',
  141. 'titanium' => 'TI',
  142. 'webos' => 'WO',
  143. 'webpro' => 'WP',
  144. );
  145. // browser family (by layout engine)
  146. static protected $browserType = array(
  147. 'ie' => array('IE'),
  148. 'gecko' => array('NS', 'PX', 'FF', 'FB', 'CA', 'GA', 'KM', 'MO', 'SM', 'CO', 'FE', 'KP', 'KZ'),
  149. 'khtml' => array('KO'),
  150. 'webkit' => array('SF', 'CH', 'OW', 'AR', 'EP', 'FL', 'WO', 'AB', 'IR', 'CS', 'FD', 'HA', 'MI', 'GE', 'DF', 'BB', 'BP', 'TI'),
  151. 'opera' => array('OP'),
  152. );
  153. // WebKit version numbers to Apple Safari version numbers (if Version/X.Y.Z not present)
  154. static protected $safariVersions = array(
  155. '534.48' => array('5', '1'),
  156. '533.16' => array('5', '0'),
  157. '533.4' => array('4', '1'),
  158. '526.11.2' => array('4', '0'),
  159. '525.26' => array('3', '2'),
  160. '525.13' => array('3', '1'),
  161. '522.11' => array('3', '0'),
  162. '412' => array('2', '0'),
  163. '312' => array('1', '3'),
  164. '125' => array('1', '2'),
  165. '100' => array('1', '1'),
  166. '85' => array('1', '0'),
  167. '73' => array('0', '9'),
  168. '48' => array('0', '8'),
  169. );
  170. // OmniWeb build numbers to OmniWeb version numbers (if Version/X.Y.Z not present)
  171. static protected $omniWebVersions = array(
  172. '622.15' => array('5', '11'),
  173. '622.10' => array('5', '10'),
  174. '622.8' => array('5', '9'),
  175. '622.3' => array('5', '8'),
  176. '621' => array('5', '7'),
  177. '613' => array('5', '6'),
  178. '607' => array('5', '5'),
  179. '563.34' => array('5', '1'),
  180. '558.36' => array('5', '0'),
  181. '496' => array('4', '5'),
  182. );
  183. // OS regex => OS ID
  184. static protected $operatingSystems = array(
  185. 'Android' => 'AND',
  186. 'Maemo' => 'MAE',
  187. 'Linux' => 'LIN',
  188. // workaround for vendors who changed the WinPhone 7 user agent
  189. 'WP7' => 'WP7',
  190. 'CYGWIN_NT-6.1' => 'WI7',
  191. 'Windows NT 6.1' => 'WI7',
  192. 'Windows 7' => 'WI7',
  193. 'CYGWIN_NT-6.0' => 'WVI',
  194. 'Windows NT 6.0' => 'WVI',
  195. 'Windows Vista' => 'WVI',
  196. 'CYGWIN_NT-5.2' => 'WS3',
  197. 'Windows NT 5.2' => 'WS3',
  198. 'Windows Server 2003 / XP x64' => 'WS3',
  199. 'CYGWIN_NT-5.1' => 'WXP',
  200. 'Windows NT 5.1' => 'WXP',
  201. 'Windows XP' => 'WXP',
  202. 'CYGWIN_NT-5.0' => 'W2K',
  203. 'Windows NT 5.0' => 'W2K',
  204. 'Windows 2000' => 'W2K',
  205. 'CYGWIN_NT-4.0' => 'WNT',
  206. 'Windows NT 4.0' => 'WNT',
  207. 'WinNT' => 'WNT',
  208. 'Windows NT' => 'WNT',
  209. 'CYGWIN_ME-4.90' => 'WME',
  210. 'Win 9x 4.90' => 'WME',
  211. 'Windows ME' => 'WME',
  212. 'CYGWIN_98-4.10' => 'W98',
  213. 'Win98' => 'W98',
  214. 'Windows 98' => 'W98',
  215. 'CYGWIN_95-4.0' => 'W95',
  216. 'Win32' => 'W95',
  217. 'Win95' => 'W95',
  218. 'Windows 95' => 'W95',
  219. 'Windows Phone OS 7.5' => 'W75',
  220. 'Windows Phone OS 7.0' => 'WP7',
  221. 'Windows Mobile 6.5' => 'W65',
  222. 'Windows Mobile 6.1' => 'W61',
  223. 'Windows CE' => 'WCE',
  224. 'iPod' => 'IPD',
  225. 'iPad' => 'IPA',
  226. 'iPhone' => 'IPH',
  227. // 'iOS' => 'IOS',
  228. 'Darwin' => 'MAC',
  229. 'Macintosh' => 'MAC',
  230. 'Power Macintosh' => 'MAC',
  231. 'Mac_PowerPC' => 'MAC',
  232. 'Mac PPC' => 'MAC',
  233. 'PPC' => 'MAC',
  234. 'Mac PowerPC' => 'MAC',
  235. 'Mac OS' => 'MAC',
  236. 'webOS' => 'WOS',
  237. 'Palm webOS' => 'WOS',
  238. 'PalmOS' => 'POS',
  239. 'Palm OS' => 'POS',
  240. 'BlackBerry' => 'BLB',
  241. 'RIM Tablet OS' => 'QNX',
  242. 'QNX' => 'QNX',
  243. 'SymbOS' => 'SYM',
  244. 'Symbian OS' => 'SYM',
  245. 'SymbianOS' => 'SYM',
  246. 'bada' => 'SBA',
  247. 'SunOS' => 'SOS',
  248. 'AIX' => 'AIX',
  249. 'HP-UX' => 'HPX',
  250. 'OpenVMS' => 'VMS',
  251. 'FreeBSD' => 'BSD',
  252. 'NetBSD' => 'NBS',
  253. 'OpenBSD' => 'OBS',
  254. 'DragonFly' => 'DFB',
  255. 'Syllable' => 'SYL',
  256. 'Nintendo Wii' => 'WII',
  257. 'Nitro' => 'NDS',
  258. 'Nintendo DS ' => 'NDS',
  259. 'Nintendo DSi' => 'DSI',
  260. 'PlayStation Portable' => 'PSP',
  261. 'PlayStation 3' => 'PS3',
  262. 'IRIX' => 'IRI',
  263. 'OSF1' => 'T64',
  264. 'OS/2' => 'OS2',
  265. 'BEOS' => 'BEO',
  266. 'Amiga' => 'AMI',
  267. 'AmigaOS' => 'AMI',
  268. );
  269. static protected $browserIdToName;
  270. static protected $browserIdToShortName;
  271. static protected $operatingSystemsIdToName;
  272. static protected $operatingSystemsIdToShortName;
  273. static private $init = false;
  274. /**
  275. * Returns an array of the OS for the submitted user agent
  276. * 'id' => '',
  277. * 'name' => '',
  278. * 'short_name' => '',
  279. *
  280. * @param string $userAgent
  281. * @return string false if OS couldn't be identified, or 3 letters ID (eg. WXP)
  282. * @see UserAgentParser/OperatingSystems.php for the list of OS (also available in self::$operatingSystems)
  283. */
  284. static public function getOperatingSystem($userAgent)
  285. {
  286. self::init();
  287. $info = array(
  288. 'id' => '',
  289. 'name' => '',
  290. 'short_name' => '',
  291. );
  292. foreach(self::$operatingSystems as $key => $value) {
  293. if (stristr($userAgent, $key) !== false) {
  294. $info['id'] = $value;
  295. break;
  296. }
  297. }
  298. if(empty($info['id'])) {
  299. return false;
  300. }
  301. $info['name'] = self::getOperatingSystemNameFromId($info['id']);
  302. $info['short_name'] = self::getOperatingSystemShortNameFromId($info['id']);
  303. return $info;
  304. }
  305. /**
  306. * Returns the browser information array, given a user agent string.
  307. *
  308. * @param string $userAgent
  309. * @return array false if the browser is "unknown", or
  310. * array( 'id' => '', // 2 letters ID, eg. FF
  311. * 'name' => '', // 2 letters ID, eg. FF
  312. * 'short_name' => '', // 2 letters ID, eg. FF
  313. * 'major_number' => '', // 2 in firefox 2.0.12
  314. * 'minor_number' => '', // 0 in firefox 2.0.12
  315. * 'version' => '', // major_number.minor_number
  316. * );
  317. * @see self::$browsers for the list of OS
  318. */
  319. static public function getBrowser($userAgent)
  320. {
  321. self::init();
  322. $info = array(
  323. 'id' => '',
  324. 'name' => '',
  325. 'short_name' => '',
  326. 'major_number' => '',
  327. 'minor_number' => '',
  328. 'version' => '',
  329. );
  330. $browsers = self::$browsers;
  331. // derivative browsers often clone the base browser's useragent
  332. unset($browsers['firefox']);
  333. unset($browsers['mozilla']);
  334. unset($browsers['safari']);
  335. unset($browsers['applewebkit']);
  336. $browsersPattern = str_replace(')', '\)', implode('|', array_keys($browsers)));
  337. $results = array();
  338. // Misbehaving IE add-ons
  339. $userAgent = preg_replace('/[; ]Mozilla\/[0-9.]+ \([^)]+\)/', '', $userAgent);
  340. // Clean-up BlackBerry device UAs
  341. $userAgent = preg_replace('~^BlackBerry\d+/~', 'BlackBerry/', $userAgent);
  342. if (preg_match_all("/($browsersPattern)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
  343. || (strpos($userAgent, 'Shiira') === false && preg_match_all("/(firefox|safari)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results))
  344. || preg_match_all("/(applewebkit)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
  345. || preg_match_all("/^(mozilla)\/([0-9]+)([\.0-9a-z-]+)?(?: \[[a-z]{2}\])? (?:\([^)]*\))$/i", $userAgent, $results)
  346. || preg_match_all("/^(mozilla)\/[0-9]+(?:[\.0-9a-z-]+)?\s\(.* rv:([0-9]+)([.0-9a-z]+)\) gecko(\/[0-9]{8}|$)(?:.*)/i", $userAgent, $results)
  347. )
  348. {
  349. // browser code (usually the first match)
  350. $count = 0;
  351. $info['id'] = self::$browsers[strtolower($results[1][0])];
  352. // sometimes there's a better match at the end
  353. if(($info['id'] == 'IE' || $info['id'] == 'LX') && (count($results[0]) > 1)) {
  354. $count = count($results[0]) - 1;
  355. $info['id'] = self::$browsers[strtolower($results[1][$count])];
  356. }
  357. // Netscape fix
  358. if($info['id'] == 'MO' && $count == 0) {
  359. if(stripos($userAgent, 'PlayStation') !== false) {
  360. return false;
  361. }
  362. if(count($results) == 4) {
  363. $info['id'] = 'NS';
  364. }
  365. }
  366. // BlackBerry devices
  367. else if(strpos($userAgent, 'BlackBerry') !== false) {
  368. $info['id'] = 'BB';
  369. }
  370. else if(strpos($userAgent, 'RIM Tablet OS') !== false) {
  371. $info['id'] = 'BP';
  372. }
  373. // Version/X.Y.Z override
  374. if(preg_match_all("/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults))
  375. {
  376. $results = $newResults;
  377. $count = count($results[0])-1;
  378. }
  379. // major version number (1 in mozilla 1.7)
  380. $info['major_number'] = $results[2][$count];
  381. // is an minor version number ? If not, 0
  382. $match = array();
  383. preg_match('/([.\0-9]+)?([\.a-z0-9]+)?/i', $results[3][$count], $match);
  384. if(isset($match[1])) {
  385. // find minor version number (7 in mozilla 1.7, 9 in firefox 0.9.3)
  386. $dot = strpos(substr($match[1], 1), '.');
  387. if($dot !== false) {
  388. $info['minor_number'] = substr($match[1], 1, $dot);
  389. }
  390. else {
  391. $info['minor_number'] = substr($match[1], 1);
  392. }
  393. }
  394. else {
  395. $info['minor_number'] = '0';
  396. }
  397. $info['version'] = $info['major_number'] . '.' . $info['minor_number'];
  398. // IE compatibility mode
  399. if($info['id'] == 'IE'
  400. && strncmp($userAgent, 'Mozilla/4.0', 11) == 0
  401. && preg_match('~ Trident/([0-9]+)\.[0-9]+~', $userAgent, $tridentVersion))
  402. {
  403. $info['major_number'] = $tridentVersion[1] + 4;
  404. $info['minor_number'] = '0';
  405. $info['version'] = $info['major_number'] . '.' .$info['minor_number'];
  406. }
  407. // Safari fix
  408. if($info['id'] == 'SF') {
  409. foreach(self::$safariVersions as $buildVersion => $productVersion) {
  410. if(version_compare($info['version'], $buildVersion) >= 0) {
  411. $info['major_number'] = $productVersion[0];
  412. $info['minor_number'] = $productVersion[1];
  413. $info['version'] = $info['major_number'] . '.' . $info['minor_number'];
  414. break;
  415. }
  416. }
  417. }
  418. // OmniWeb fix
  419. if($info['id'] == 'OW') {
  420. foreach(self::$omniWebVersions as $buildVersion => $productVersion) {
  421. if(version_compare($info['version'], $buildVersion) >= 0) {
  422. $info['major_number'] = $productVersion[0];
  423. $info['minor_number'] = $productVersion[1];
  424. $info['version'] = $info['major_number'] . '.' . $info['minor_number'];
  425. break;
  426. }
  427. }
  428. }
  429. // SeaMonkey fix
  430. if($info['id'] == 'MO' && $info['version'] == '1.9') {
  431. $info['id'] = 'SM';
  432. }
  433. $info['name'] = self::getBrowserNameFromId($info['id']);
  434. $info['short_name'] = self::getBrowserShortNameFromId($info['id']);
  435. return $info;
  436. }
  437. return false;
  438. }
  439. static protected function init() {
  440. if(self::$init) {
  441. return;
  442. }
  443. self::$init = true;
  444. // init browser names and short names
  445. self::$browserIdToName = array_map('ucwords',array_flip(self::$browsers));
  446. self::$browserIdToName['AB'] = 'ABrowse';
  447. self::$browserIdToName['AV'] = 'AmigaVoyager';
  448. self::$browserIdToName['AW'] = 'Amiga AWeb';
  449. self::$browserIdToName['BB'] = 'BlackBerry';
  450. self::$browserIdToName['BP'] = 'PlayBook';
  451. self::$browserIdToName['BX'] = 'BrowseX';
  452. self::$browserIdToName['CO'] = 'CometBird';
  453. self::$browserIdToName['EL'] = 'ELinks';
  454. self::$browserIdToName['FF'] = 'Firefox';
  455. self::$browserIdToName['HJ'] = 'HotJava';
  456. self::$browserIdToName['IB'] = 'IBrowse';
  457. self::$browserIdToName['IC'] = 'iCab';
  458. self::$browserIdToName['KM'] = 'K-Meleon';
  459. self::$browserIdToName['MC'] = 'NCSA Mosaic';
  460. self::$browserIdToName['OW'] = 'OmniWeb';
  461. self::$browserIdToName['SF'] = 'Safari';
  462. self::$browserIdToName['SM'] = 'SeaMonkey';
  463. self::$browserIdToName['WO'] = 'Palm webOS';
  464. self::$browserIdToName['WP'] = 'WebPro';
  465. self::$browserIdToShortName = self::$browserIdToName;
  466. self::$browserIdToShortName['AW'] = 'AWeb';
  467. self::$browserIdToShortName['FB'] = 'Firebird';
  468. self::$browserIdToShortName['IE'] = 'IE';
  469. self::$browserIdToShortName['MC'] = 'Mosaic';
  470. self::$browserIdToShortName['BP'] = 'PlayBook';
  471. self::$browserIdToShortName['WO'] = 'webOS';
  472. // init OS names and short names
  473. self::$operatingSystemsIdToName = array_merge(array_flip(self::$operatingSystems), array(
  474. 'IPD' => 'iPod',
  475. 'IPA' => 'iPad',
  476. 'WME' => 'Windows Me',
  477. 'BEO' => 'BeOS',
  478. 'T64' => 'Tru64',
  479. 'NDS' => 'Nintendo DS',
  480. ));
  481. self::$operatingSystemsIdToShortName = array_merge(self::$operatingSystemsIdToName, array(
  482. 'PS3' => 'PS3',
  483. 'PSP' => 'PSP',
  484. 'WII' => 'Wii',
  485. 'NDS' => 'DS',
  486. 'DSI' => 'DSi',
  487. 'WI7' => 'Win 7',
  488. 'WVI' => 'Win Vista',
  489. 'WS3' => 'Win S2003',
  490. 'WXP' => 'Win XP',
  491. 'W98' => 'Win 98',
  492. 'W2K' => 'Win 2000',
  493. 'WNT' => 'Win NT',
  494. 'WME' => 'Win Me',
  495. 'W95' => 'Win 95',
  496. 'W75' => 'WinPhone 7.5',
  497. 'WP7' => 'WinPhone 7',
  498. 'W65' => 'WinMo 6.5',
  499. 'W61' => 'WinMo 6.1',
  500. 'WCE' => 'Win CE',
  501. 'WOS' => 'webOS',
  502. 'UNK' => 'Unknown',
  503. ));
  504. }
  505. static public function getBrowserNameFromId($browserId)
  506. {
  507. self::init();
  508. if(isset(self::$browserIdToName[$browserId])) {
  509. return self::$browserIdToName[$browserId];
  510. }
  511. return false;
  512. }
  513. static public function getBrowserShortNameFromId($browserId)
  514. {
  515. self::init();
  516. if(isset(self::$browserIdToShortName[$browserId])) {
  517. return self::$browserIdToShortName[$browserId];
  518. }
  519. return false;
  520. }
  521. static public function getBrowserFamilyFromId($browserId)
  522. {
  523. self::init();
  524. $familyNameToUse = 'unknown';
  525. foreach(self::$browserType as $familyName => $aBrowsers)
  526. {
  527. if(in_array($browserId, $aBrowsers))
  528. {
  529. $familyNameToUse = $familyName;
  530. break;
  531. }
  532. }
  533. return $familyNameToUse;
  534. }
  535. static public function getOperatingSystemNameFromId($osId)
  536. {
  537. self::init();
  538. if(isset(self::$operatingSystemsIdToName[$osId])) {
  539. return self::$operatingSystemsIdToName[$osId];
  540. }
  541. return false;
  542. }
  543. static public function getOperatingSystemShortNameFromId($osId)
  544. {
  545. self::init();
  546. if(isset(self::$operatingSystemsIdToShortName[$osId])) {
  547. return self::$operatingSystemsIdToShortName[$osId];
  548. }
  549. return false;
  550. }
  551. }