PageRenderTime 105ms CodeModel.GetById 29ms RepoModel.GetById 14ms app.codeStats 0ms

/code/wright/includes/browser.php

https://bitbucket.org/sprakdata/wright
PHP | 1234 lines | 798 code | 66 blank | 370 comment | 90 complexity | 2e335b7cfd146543e9f50137c4fb7522 MD5 | raw file
  1. <?php
  2. /**
  3. * File: Browser.php
  4. * Author: Chris Schuld (http://chrisschuld.com/)
  5. * Last Modified: August 20th, 2010
  6. * @version 1.9
  7. * @package PegasusPHP
  8. *
  9. * Copyright (C) 2008-2010 Chris Schuld (chris@chrisschuld.com)
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details at:
  20. * http://www.gnu.org/copyleft/gpl.html
  21. *
  22. *
  23. * Typical Usage:
  24. *
  25. * $browser = new Browser();
  26. * if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
  27. * echo 'You have FireFox version 2 or greater';
  28. * }
  29. *
  30. * User Agents Sampled from: http://www.useragentstring.com/
  31. *
  32. * This implementation is based on the original work from Gary White
  33. * http://apptools.com/phptools/browser/
  34. *
  35. * UPDATES:
  36. *
  37. * 2010-08-20 (v1.9):
  38. * + Added MSN Explorer Browser (legacy)
  39. * + Added Bing/MSN Robot (Thanks Rob MacDonald)
  40. * + Added the Android Platform (PLATFORM_ANDROID)
  41. * + Fixed issue with Android 1.6/2.2 (Thanks Tom Hirashima)
  42. *
  43. * 2010-04-27 (v1.8):
  44. * + Added iPad Support
  45. *
  46. * 2010-03-07 (v1.7):
  47. * + *MAJOR* Rebuild (preg_match and other "slow" routine removal(s))
  48. * + Almost allof Gary's original code has been replaced
  49. * + Large PHPUNIT testing environment created to validate new releases and additions
  50. * + Added FreeBSD Platform
  51. * + Added OpenBSD Platform
  52. * + Added NetBSD Platform
  53. * + Added SunOS Platform
  54. * + Added OpenSolaris Platform
  55. * + Added support of the Iceweazel Browser
  56. * + Added isChromeFrame() call to check if chromeframe is in use
  57. * + Moved the Opera check in front of the Firefox check due to legacy Opera User Agents
  58. * + Added the __toString() method (Thanks Deano)
  59. *
  60. * 2009-11-15:
  61. * + Updated the checkes for Firefox
  62. * + Added the NOKIA platform
  63. * + Added Checks for the NOKIA brower(s)
  64. *
  65. * 2009-11-08:
  66. * + PHP 5.3 Support
  67. * + Added support for BlackBerry OS and BlackBerry browser
  68. * + Added support for the Opera Mini browser
  69. * + Added additional documenation
  70. * + Added support for isRobot() and isMobile()
  71. * + Added support for Opera version 10
  72. * + Added support for deprecated Netscape Navigator version 9
  73. * + Added support for IceCat
  74. * + Added support for Shiretoko
  75. *
  76. * 2010-04-27 (v1.8):
  77. * + Added iPad Support
  78. *
  79. * 2009-08-18:
  80. * + Updated to support PHP 5.3 - removed all deprecated function calls
  81. * + Updated to remove all double quotes (") -- converted to single quotes (')
  82. *
  83. * 2009-04-27:
  84. * + Updated the IE check to remove a typo and bug (thanks John)
  85. *
  86. * 2009-04-22:
  87. * + Added detection for GoogleBot
  88. * + Added detection for the W3C Validator.
  89. * + Added detection for Yahoo! Slurp
  90. *
  91. * 2009-03-14:
  92. * + Added detection for iPods.
  93. * + Added Platform detection for iPhones
  94. * + Added Platform detection for iPods
  95. *
  96. * 2009-02-16: (Rick Hale)
  97. * + Added version detection for Android phones.
  98. *
  99. * 2008-12-09:
  100. * + Removed unused constant
  101. *
  102. * 2008-11-07:
  103. * + Added Google's Chrome to the detection list
  104. * + Added isBrowser(string) to the list of functions special thanks to
  105. * Daniel 'mavrick' Lang for the function concept (http://mavrick.id.au)
  106. *
  107. *
  108. * Gary White noted: "Since browser detection is so unreliable, I am
  109. * no longer maintaining this script. You are free to use and or
  110. * modify/update it as you want, however the author assumes no
  111. * responsibility for the accuracy of the detected values."
  112. *
  113. * Anyone experienced with Gary's script might be interested in these notes:
  114. *
  115. * Added class constants
  116. * Added detection and version detection for Google's Chrome
  117. * Updated the version detection for Amaya
  118. * Updated the version detection for Firefox
  119. * Updated the version detection for Lynx
  120. * Updated the version detection for WebTV
  121. * Updated the version detection for NetPositive
  122. * Updated the version detection for IE
  123. * Updated the version detection for OmniWeb
  124. * Updated the version detection for iCab
  125. * Updated the version detection for Safari
  126. * Updated Safari to remove mobile devices (iPhone)
  127. * Added detection for iPhone
  128. * Added detection for robots
  129. * Added detection for mobile devices
  130. * Added detection for BlackBerry
  131. * Removed Netscape checks (matches heavily with firefox & mozilla)
  132. *
  133. */
  134. class Browser
  135. {
  136. private $_agent = '';
  137. private $_browser_name = '';
  138. private $_version = '';
  139. private $_platform = '';
  140. private $_os = '';
  141. private $_is_aol = false;
  142. private $_is_mobile = false;
  143. private $_is_robot = false;
  144. private $_aol_version = '';
  145. const BROWSER_UNKNOWN = 'unknown';
  146. const VERSION_UNKNOWN = 'unknown';
  147. const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
  148. const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
  149. const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
  150. const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
  151. const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  152. const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
  153. const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
  154. const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
  155. const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
  156. const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
  157. const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
  158. const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
  159. const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
  160. const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
  161. const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
  162. const BROWSER_SAFARI = 'Safari'; // http://apple.com
  163. const BROWSER_IPHONE = 'iPhone'; // http://apple.com
  164. const BROWSER_IPOD = 'iPod'; // http://apple.com
  165. const BROWSER_IPAD = 'iPad'; // http://apple.com
  166. const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
  167. const BROWSER_ANDROID = 'Android'; // http://www.android.com/
  168. const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
  169. const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
  170. const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
  171. const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
  172. const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
  173. const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
  174. const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
  175. const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
  176. const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
  177. // http://en.wikipedia.org/wiki/Msnbot (used for Bing as well)
  178. const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
  179. const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
  180. const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
  181. const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
  182. const PLATFORM_UNKNOWN = 'unknown';
  183. const PLATFORM_WINDOWS = 'Windows';
  184. const PLATFORM_WINDOWS_CE = 'Windows CE';
  185. const PLATFORM_APPLE = 'Apple';
  186. const PLATFORM_LINUX = 'Linux';
  187. const PLATFORM_OS2 = 'OS/2';
  188. const PLATFORM_BEOS = 'BeOS';
  189. const PLATFORM_IPHONE = 'iPhone';
  190. const PLATFORM_IPOD = 'iPod';
  191. const PLATFORM_IPAD = 'iPad';
  192. const PLATFORM_BLACKBERRY = 'BlackBerry';
  193. const PLATFORM_NOKIA = 'Nokia';
  194. const PLATFORM_FREEBSD = 'FreeBSD';
  195. const PLATFORM_OPENBSD = 'OpenBSD';
  196. const PLATFORM_NETBSD = 'NetBSD';
  197. const PLATFORM_SUNOS = 'SunOS';
  198. const PLATFORM_OPENSOLARIS = 'OpenSolaris';
  199. const PLATFORM_ANDROID = 'Android';
  200. const OPERATING_SYSTEM_UNKNOWN = 'unknown';
  201. public function Browser($useragent="")
  202. {
  203. $this->reset();
  204. if ($useragent != "")
  205. {
  206. $this->setUserAgent($useragent);
  207. }
  208. else
  209. {
  210. $this->determine();
  211. }
  212. }
  213. /**
  214. * Reset all properties
  215. */
  216. public function reset()
  217. {
  218. $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
  219. $this->_browser_name = self::BROWSER_UNKNOWN;
  220. $this->_version = self::VERSION_UNKNOWN;
  221. $this->_platform = self::PLATFORM_UNKNOWN;
  222. $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
  223. $this->_is_aol = false;
  224. $this->_is_mobile = false;
  225. $this->_is_robot = false;
  226. $this->_aol_version = self::VERSION_UNKNOWN;
  227. }
  228. /**
  229. * Check to see if the specific browser is valid
  230. * @param string $browserName
  231. * @return True if the browser is the specified browser
  232. */
  233. function isBrowser($browserName)
  234. {
  235. return( 0 == strcasecmp($this->_browser_name, trim($browserName)));
  236. }
  237. /**
  238. * The name of the browser. All return types are from the class contants
  239. * @return string Name of the browser
  240. */
  241. public function getBrowser()
  242. {
  243. return $this->_browser_name;
  244. }
  245. /**
  246. * Set the name of the browser
  247. * @param $browser The name of the Browser
  248. */
  249. public function setBrowser($browser)
  250. {
  251. return $this->_browser_name = $browser;
  252. }
  253. /**
  254. * The name of the platform. All return types are from the class contants
  255. * @return string Name of the browser
  256. */
  257. public function getPlatform()
  258. {
  259. return $this->_platform;
  260. }
  261. /**
  262. * Set the name of the platform
  263. * @param $platform The name of the Platform
  264. */
  265. public function setPlatform($platform)
  266. {
  267. return $this->_platform = $platform;
  268. }
  269. /**
  270. * The version of the browser.
  271. * @return string Version of the browser (will only contain alpha-numeric characters and a period)
  272. */
  273. public function getVersion()
  274. {
  275. return $this->_version;
  276. }
  277. /**
  278. * Set the version of the browser
  279. * @param $version The version of the Browser
  280. */
  281. public function setVersion($version)
  282. {
  283. $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version);
  284. }
  285. /**
  286. * The version of AOL.
  287. * @return string Version of AOL (will only contain alpha-numeric characters and a period)
  288. */
  289. public function getAolVersion()
  290. {
  291. return $this->_aol_version;
  292. }
  293. /**
  294. * Set the version of AOL
  295. * @param $version The version of AOL
  296. */
  297. public function setAolVersion($version)
  298. {
  299. $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version);
  300. }
  301. /**
  302. * Is the browser from AOL?
  303. * @return boolean True if the browser is from AOL otherwise false
  304. */
  305. public function isAol()
  306. {
  307. return $this->_is_aol;
  308. }
  309. /**
  310. * Is the browser from a mobile device?
  311. * @return boolean True if the browser is from a mobile device otherwise false
  312. */
  313. public function isMobile()
  314. {
  315. return $this->_is_mobile;
  316. }
  317. /**
  318. * Is the browser from a robot (ex Slurp,GoogleBot)?
  319. * @return boolean True if the browser is from a robot otherwise false
  320. */
  321. public function isRobot()
  322. {
  323. return $this->_is_robot;
  324. }
  325. /**
  326. * Set the browser to be from AOL
  327. * @param $isAol
  328. */
  329. public function setAol($isAol)
  330. {
  331. $this->_is_aol = $isAol;
  332. }
  333. /**
  334. * Set the Browser to be mobile
  335. * @param boolean $value is the browser a mobile brower or not
  336. */
  337. protected function setMobile($value=true)
  338. {
  339. $this->_is_mobile = $value;
  340. }
  341. /**
  342. * Set the Browser to be a robot
  343. * @param boolean $value is the browser a robot or not
  344. */
  345. protected function setRobot($value=true)
  346. {
  347. $this->_is_robot = $value;
  348. }
  349. /**
  350. * Get the user agent value in use to determine the browser
  351. * @return string The user agent from the HTTP header
  352. */
  353. public function getUserAgent()
  354. {
  355. return $this->_agent;
  356. }
  357. /**
  358. * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
  359. * @param $agent_string The value for the User Agent
  360. */
  361. public function setUserAgent($agent_string)
  362. {
  363. $this->reset();
  364. $this->_agent = $agent_string;
  365. $this->determine();
  366. }
  367. /**
  368. * Used to determine if the browser is actually "chromeframe"
  369. * @since 1.7
  370. * @return boolean True if the browser is using chromeframe
  371. */
  372. public function isChromeFrame()
  373. {
  374. return( strpos($this->_agent, "chromeframe") !== false );
  375. }
  376. /**
  377. * Returns a formatted string with a summary of the details of the browser.
  378. * @return string formatted string with a summary of the browser
  379. */
  380. public function __toString()
  381. {
  382. return "<strong>Browser Name:</strong>{$this->getBrowser()}<br/>\n" .
  383. "<strong>Browser Version:</strong>{$this->getVersion()}<br/>\n" .
  384. "<strong>Browser User Agent String:</strong>{$this->getUserAgent()}<br/>\n" .
  385. "<strong>Platform:</strong>{$this->getPlatform()}<br/>";
  386. }
  387. /**
  388. * Protected routine to calculate and determine what the browser is in use (including platform)
  389. */
  390. protected function determine()
  391. {
  392. $this->checkPlatform();
  393. $this->checkBrowsers();
  394. $this->checkForAol();
  395. }
  396. /**
  397. * Protected routine to determine the browser type
  398. * @return boolean True if the browser was detected otherwise false
  399. */
  400. protected function checkBrowsers()
  401. {
  402. return (
  403. // well-known, well-used
  404. // Special Notes:
  405. // (1) Opera must be checked before FireFox due to the odd
  406. // user agents used in some older versions of Opera
  407. // (2) WebTV is strapped onto Internet Explorer so we must
  408. // check for WebTV before IE
  409. // (3) (deprecated) Galeon is based on Firefox and needs to be
  410. // tested before Firefox is tested
  411. // (4) OmniWeb is based on Safari so OmniWeb check must occur
  412. // before Safari
  413. // (5) Netscape 9+ is based on Firefox so Netscape checks
  414. // before FireFox are necessary
  415. $this->checkBrowserWebTv() ||
  416. $this->checkBrowserInternetExplorer() ||
  417. $this->checkBrowserOpera() ||
  418. $this->checkBrowserGaleon() ||
  419. $this->checkBrowserNetscapeNavigator9Plus() ||
  420. $this->checkBrowserFirefox() ||
  421. $this->checkBrowserChrome() ||
  422. $this->checkBrowserOmniWeb() ||
  423. // common mobile
  424. $this->checkBrowserAndroid() ||
  425. $this->checkBrowseriPad() ||
  426. $this->checkBrowseriPod() ||
  427. $this->checkBrowseriPhone() ||
  428. $this->checkBrowserBlackBerry() ||
  429. $this->checkBrowserNokia() ||
  430. // common bots
  431. $this->checkBrowserGoogleBot() ||
  432. $this->checkBrowserMSNBot() ||
  433. $this->checkBrowserSlurp() ||
  434. // WebKit base check (post mobile and others)
  435. $this->checkBrowserSafari() ||
  436. // everyone else
  437. $this->checkBrowserNetPositive() ||
  438. $this->checkBrowserFirebird() ||
  439. $this->checkBrowserKonqueror() ||
  440. $this->checkBrowserIcab() ||
  441. $this->checkBrowserPhoenix() ||
  442. $this->checkBrowserAmaya() ||
  443. $this->checkBrowserLynx() ||
  444. $this->checkBrowserShiretoko() ||
  445. $this->checkBrowserIceCat() ||
  446. $this->checkBrowserW3CValidator() ||
  447. $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
  448. );
  449. }
  450. /**
  451. * Determine if the user is using a BlackBerry (last updated 1.7)
  452. * @return boolean True if the browser is the BlackBerry browser otherwise false
  453. */
  454. protected function checkBrowserBlackBerry()
  455. {
  456. if (stripos($this->_agent, 'blackberry') !== false)
  457. {
  458. $aresult = explode("/", stristr($this->_agent, "BlackBerry"));
  459. $aversion = explode(' ', $aresult[1]);
  460. $this->setVersion($aversion[0]);
  461. $this->_browser_name = self::BROWSER_BLACKBERRY;
  462. $this->setMobile(true);
  463. return true;
  464. }
  465. return false;
  466. }
  467. /**
  468. * Determine if the user is using an AOL User Agent (last updated 1.7)
  469. * @return boolean True if the browser is from AOL otherwise false
  470. */
  471. protected function checkForAol()
  472. {
  473. $this->setAol(false);
  474. $this->setAolVersion(self::VERSION_UNKNOWN);
  475. if (stripos($this->_agent, 'aol') !== false)
  476. {
  477. $aversion = explode(' ', stristr($this->_agent, 'AOL'));
  478. $this->setAol(true);
  479. $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
  480. return true;
  481. }
  482. return false;
  483. }
  484. /**
  485. * Determine if the browser is the GoogleBot or not (last updated 1.7)
  486. * @return boolean True if the browser is the GoogletBot otherwise false
  487. */
  488. protected function checkBrowserGoogleBot()
  489. {
  490. if (stripos($this->_agent, 'googlebot') !== false)
  491. {
  492. $aresult = explode('/', stristr($this->_agent, 'googlebot'));
  493. $aversion = explode(' ', $aresult[1]);
  494. $this->setVersion(str_replace(';', '', $aversion[0]));
  495. $this->_browser_name = self::BROWSER_GOOGLEBOT;
  496. $this->setRobot(true);
  497. return true;
  498. }
  499. return false;
  500. }
  501. /**
  502. * Determine if the browser is the MSNBot or not (last updated 1.9)
  503. * @return boolean True if the browser is the MSNBot otherwise false
  504. */
  505. protected function checkBrowserMSNBot()
  506. {
  507. if (stripos($this->_agent, "msnbot") !== false)
  508. {
  509. $aresult = explode("/", stristr($this->_agent, "msnbot"));
  510. $aversion = explode(" ", $aresult[1]);
  511. $this->setVersion(str_replace(";", "", $aversion[0]));
  512. $this->_browser_name = self::BROWSER_MSNBOT;
  513. $this->setRobot(true);
  514. return true;
  515. }
  516. return false;
  517. }
  518. /**
  519. * Determine if the browser is the W3C Validator or not (last updated 1.7)
  520. * @return boolean True if the browser is the W3C Validator otherwise false
  521. */
  522. protected function checkBrowserW3CValidator()
  523. {
  524. if (stripos($this->_agent, 'W3C-checklink') !== false)
  525. {
  526. $aresult = explode('/', stristr($this->_agent, 'W3C-checklink'));
  527. $aversion = explode(' ', $aresult[1]);
  528. $this->setVersion($aversion[0]);
  529. $this->_browser_name = self::BROWSER_W3CVALIDATOR;
  530. return true;
  531. }
  532. else if (stripos($this->_agent, 'W3C_Validator') !== false)
  533. {
  534. // Some of the Validator versions do not delineate w/ a slash - add it back in
  535. $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
  536. $aresult = explode('/', stristr($ua, 'W3C_Validator'));
  537. $aversion = explode(' ', $aresult[1]);
  538. $this->setVersion($aversion[0]);
  539. $this->_browser_name = self::BROWSER_W3CVALIDATOR;
  540. return true;
  541. }
  542. return false;
  543. }
  544. /**
  545. * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
  546. * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
  547. */
  548. protected function checkBrowserSlurp()
  549. {
  550. if (stripos($this->_agent, 'slurp') !== false)
  551. {
  552. $aresult = explode('/', stristr($this->_agent, 'Slurp'));
  553. $aversion = explode(' ', $aresult[1]);
  554. $this->setVersion($aversion[0]);
  555. $this->_browser_name = self::BROWSER_SLURP;
  556. $this->setRobot(true);
  557. $this->setMobile(false);
  558. return true;
  559. }
  560. return false;
  561. }
  562. /**
  563. * Determine if the browser is Internet Explorer or not (last updated 1.7)
  564. * @return boolean True if the browser is Internet Explorer otherwise false
  565. */
  566. protected function checkBrowserInternetExplorer()
  567. {
  568. // Test for v1 - v1.5 IE
  569. if (stripos($this->_agent, 'microsoft internet explorer') !== false)
  570. {
  571. $this->setBrowser(self::BROWSER_IE);
  572. $this->setVersion('1.0');
  573. $aresult = stristr($this->_agent, '/');
  574. if (preg_match('/308|425|426|474|0b1/i', $aresult))
  575. {
  576. $this->setVersion('1.5');
  577. }
  578. return true;
  579. }
  580. // Test for versions > 1.5
  581. else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false)
  582. {
  583. // See if the browser is the odd MSN Explorer
  584. if (stripos($this->_agent, 'msnb') !== false)
  585. {
  586. $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN'));
  587. $this->setBrowser(self::BROWSER_MSN);
  588. $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
  589. return true;
  590. }
  591. $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie'));
  592. $this->setBrowser(self::BROWSER_IE);
  593. $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
  594. return true;
  595. }
  596. // Test for Pocket IE
  597. else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false)
  598. {
  599. $aresult = explode(' ', stristr($this->_agent, 'mspie'));
  600. $this->setPlatform(self::PLATFORM_WINDOWS_CE);
  601. $this->setBrowser(self::BROWSER_POCKET_IE);
  602. $this->setMobile(true);
  603. if (stripos($this->_agent, 'mspie') !== false)
  604. {
  605. $this->setVersion($aresult[1]);
  606. }
  607. else
  608. {
  609. $aversion = explode('/', $this->_agent);
  610. $this->setVersion($aversion[1]);
  611. }
  612. return true;
  613. }
  614. return false;
  615. }
  616. /**
  617. * Determine if the browser is Opera or not (last updated 1.7)
  618. * @return boolean True if the browser is Opera otherwise false
  619. */
  620. protected function checkBrowserOpera()
  621. {
  622. if (stripos($this->_agent, 'opera mini') !== false)
  623. {
  624. $resultant = stristr($this->_agent, 'opera mini');
  625. if (preg_match('/\//', $resultant))
  626. {
  627. $aresult = explode('/', $resultant);
  628. $aversion = explode(' ', $aresult[1]);
  629. $this->setVersion($aversion[0]);
  630. }
  631. else
  632. {
  633. $aversion = explode(' ', stristr($resultant, 'opera mini'));
  634. $this->setVersion($aversion[1]);
  635. }
  636. $this->_browser_name = self::BROWSER_OPERA_MINI;
  637. $this->setMobile(true);
  638. return true;
  639. }
  640. else if (stripos($this->_agent, 'opera') !== false)
  641. {
  642. $resultant = stristr($this->_agent, 'opera');
  643. if (preg_match('/Version\/(10.*)$/', $resultant, $matches))
  644. {
  645. $this->setVersion($matches[1]);
  646. }
  647. else if (preg_match('/\//', $resultant))
  648. {
  649. $aresult = explode('/', str_replace("(", " ", $resultant));
  650. $aversion = explode(' ', $aresult[1]);
  651. $this->setVersion($aversion[0]);
  652. }
  653. else
  654. {
  655. $aversion = explode(' ', stristr($resultant, 'opera'));
  656. $this->setVersion(isset($aversion[1]) ? $aversion[1] : "");
  657. }
  658. $this->_browser_name = self::BROWSER_OPERA;
  659. return true;
  660. }
  661. return false;
  662. }
  663. /**
  664. * Determine if the browser is Chrome or not (last updated 1.7)
  665. * @return boolean True if the browser is Chrome otherwise false
  666. */
  667. protected function checkBrowserChrome()
  668. {
  669. if (stripos($this->_agent, 'Chrome') !== false)
  670. {
  671. $aresult = explode('/', stristr($this->_agent, 'Chrome'));
  672. $aversion = explode(' ', $aresult[1]);
  673. $this->setVersion($aversion[0]);
  674. $this->setBrowser(self::BROWSER_CHROME);
  675. return true;
  676. }
  677. return false;
  678. }
  679. /**
  680. * Determine if the browser is WebTv or not (last updated 1.7)
  681. * @return boolean True if the browser is WebTv otherwise false
  682. */
  683. protected function checkBrowserWebTv()
  684. {
  685. if (stripos($this->_agent, 'webtv') !== false)
  686. {
  687. $aresult = explode('/', stristr($this->_agent, 'webtv'));
  688. $aversion = explode(' ', $aresult[1]);
  689. $this->setVersion($aversion[0]);
  690. $this->setBrowser(self::BROWSER_WEBTV);
  691. return true;
  692. }
  693. return false;
  694. }
  695. /**
  696. * Determine if the browser is NetPositive or not (last updated 1.7)
  697. * @return boolean True if the browser is NetPositive otherwise false
  698. */
  699. protected function checkBrowserNetPositive()
  700. {
  701. if (stripos($this->_agent, 'NetPositive') !== false)
  702. {
  703. $aresult = explode('/', stristr($this->_agent, 'NetPositive'));
  704. $aversion = explode(' ', $aresult[1]);
  705. $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
  706. $this->setBrowser(self::BROWSER_NETPOSITIVE);
  707. return true;
  708. }
  709. return false;
  710. }
  711. /**
  712. * Determine if the browser is Galeon or not (last updated 1.7)
  713. * @return boolean True if the browser is Galeon otherwise false
  714. */
  715. protected function checkBrowserGaleon()
  716. {
  717. if (stripos($this->_agent, 'galeon') !== false)
  718. {
  719. $aresult = explode(' ', stristr($this->_agent, 'galeon'));
  720. $aversion = explode('/', $aresult[0]);
  721. $this->setVersion($aversion[1]);
  722. $this->setBrowser(self::BROWSER_GALEON);
  723. return true;
  724. }
  725. return false;
  726. }
  727. /**
  728. * Determine if the browser is Konqueror or not (last updated 1.7)
  729. * @return boolean True if the browser is Konqueror otherwise false
  730. */
  731. protected function checkBrowserKonqueror()
  732. {
  733. if (stripos($this->_agent, 'Konqueror') !== false)
  734. {
  735. $aresult = explode(' ', stristr($this->_agent, 'Konqueror'));
  736. $aversion = explode('/', $aresult[0]);
  737. $this->setVersion($aversion[1]);
  738. $this->setBrowser(self::BROWSER_KONQUEROR);
  739. return true;
  740. }
  741. return false;
  742. }
  743. /**
  744. * Determine if the browser is iCab or not (last updated 1.7)
  745. * @return boolean True if the browser is iCab otherwise false
  746. */
  747. protected function checkBrowserIcab()
  748. {
  749. if (stripos($this->_agent, 'icab') !== false)
  750. {
  751. $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab'));
  752. $this->setVersion($aversion[1]);
  753. $this->setBrowser(self::BROWSER_ICAB);
  754. return true;
  755. }
  756. return false;
  757. }
  758. /**
  759. * Determine if the browser is OmniWeb or not (last updated 1.7)
  760. * @return boolean True if the browser is OmniWeb otherwise false
  761. */
  762. protected function checkBrowserOmniWeb()
  763. {
  764. if (stripos($this->_agent, 'omniweb') !== false)
  765. {
  766. $aresult = explode('/', stristr($this->_agent, 'omniweb'));
  767. $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : "");
  768. $this->setVersion($aversion[0]);
  769. $this->setBrowser(self::BROWSER_OMNIWEB);
  770. return true;
  771. }
  772. return false;
  773. }
  774. /**
  775. * Determine if the browser is Phoenix or not (last updated 1.7)
  776. * @return boolean True if the browser is Phoenix otherwise false
  777. */
  778. protected function checkBrowserPhoenix()
  779. {
  780. if (stripos($this->_agent, 'Phoenix') !== false)
  781. {
  782. $aversion = explode('/', stristr($this->_agent, 'Phoenix'));
  783. $this->setVersion($aversion[1]);
  784. $this->setBrowser(self::BROWSER_PHOENIX);
  785. return true;
  786. }
  787. return false;
  788. }
  789. /**
  790. * Determine if the browser is Firebird or not (last updated 1.7)
  791. * @return boolean True if the browser is Firebird otherwise false
  792. */
  793. protected function checkBrowserFirebird()
  794. {
  795. if (stripos($this->_agent, 'Firebird') !== false)
  796. {
  797. $aversion = explode('/', stristr($this->_agent, 'Firebird'));
  798. $this->setVersion($aversion[1]);
  799. $this->setBrowser(self::BROWSER_FIREBIRD);
  800. return true;
  801. }
  802. return false;
  803. }
  804. /**
  805. * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
  806. * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
  807. * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
  808. */
  809. protected function checkBrowserNetscapeNavigator9Plus()
  810. {
  811. if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches))
  812. {
  813. $this->setVersion($matches[1]);
  814. $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
  815. return true;
  816. }
  817. else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches))
  818. {
  819. $this->setVersion($matches[1]);
  820. $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
  821. return true;
  822. }
  823. return false;
  824. }
  825. /**
  826. * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
  827. * @return boolean True if the browser is Shiretoko otherwise false
  828. */
  829. protected function checkBrowserShiretoko()
  830. {
  831. if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches))
  832. {
  833. $this->setVersion($matches[1]);
  834. $this->setBrowser(self::BROWSER_SHIRETOKO);
  835. return true;
  836. }
  837. return false;
  838. }
  839. /**
  840. * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
  841. * @return boolean True if the browser is Ice Cat otherwise false
  842. */
  843. protected function checkBrowserIceCat()
  844. {
  845. if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches))
  846. {
  847. $this->setVersion($matches[1]);
  848. $this->setBrowser(self::BROWSER_ICECAT);
  849. return true;
  850. }
  851. return false;
  852. }
  853. /**
  854. * Determine if the browser is Nokia or not (last updated 1.7)
  855. * @return boolean True if the browser is Nokia otherwise false
  856. */
  857. protected function checkBrowserNokia()
  858. {
  859. if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches))
  860. {
  861. $this->setVersion($matches[2]);
  862. if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false)
  863. {
  864. $this->setBrowser(self::BROWSER_NOKIA_S60);
  865. }
  866. else
  867. {
  868. $this->setBrowser(self::BROWSER_NOKIA);
  869. }
  870. $this->setMobile(true);
  871. return true;
  872. }
  873. return false;
  874. }
  875. /**
  876. * Determine if the browser is Firefox or not (last updated 1.7)
  877. * @return boolean True if the browser is Firefox otherwise false
  878. */
  879. protected function checkBrowserFirefox()
  880. {
  881. if (stripos($this->_agent, 'safari') === false)
  882. {
  883. if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches))
  884. {
  885. $this->setVersion($matches[1]);
  886. $this->setBrowser(self::BROWSER_FIREFOX);
  887. return true;
  888. }
  889. else if (preg_match("/Firefox$/i", $this->_agent, $matches))
  890. {
  891. $this->setVersion("");
  892. $this->setBrowser(self::BROWSER_FIREFOX);
  893. return true;
  894. }
  895. }
  896. return false;
  897. }
  898. /**
  899. * Determine if the browser is Firefox or not (last updated 1.7)
  900. * @return boolean True if the browser is Firefox otherwise false
  901. */
  902. protected function checkBrowserIceweasel()
  903. {
  904. if (stripos($this->_agent, 'Iceweasel') !== false)
  905. {
  906. $aresult = explode('/', stristr($this->_agent, 'Iceweasel'));
  907. $aversion = explode(' ', $aresult[1]);
  908. $this->setVersion($aversion[0]);
  909. $this->setBrowser(self::BROWSER_ICEWEASEL);
  910. return true;
  911. }
  912. return false;
  913. }
  914. /**
  915. * Determine if the browser is Mozilla or not (last updated 1.7)
  916. * @return boolean True if the browser is Mozilla otherwise false
  917. */
  918. protected function checkBrowserMozilla()
  919. {
  920. if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false)
  921. {
  922. $aversion = explode(' ', stristr($this->_agent, 'rv:'));
  923. preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion);
  924. $this->setVersion(str_replace('rv:', '', $aversion[0]));
  925. $this->setBrowser(self::BROWSER_MOZILLA);
  926. return true;
  927. }
  928. else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false)
  929. {
  930. $aversion = explode('', stristr($this->_agent, 'rv:'));
  931. $this->setVersion(str_replace('rv:', '', $aversion[0]));
  932. $this->setBrowser(self::BROWSER_MOZILLA);
  933. return true;
  934. }
  935. else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false)
  936. {
  937. $this->setVersion($matches[1]);
  938. $this->setBrowser(self::BROWSER_MOZILLA);
  939. return true;
  940. }
  941. return false;
  942. }
  943. /**
  944. * Determine if the browser is Lynx or not (last updated 1.7)
  945. * @return boolean True if the browser is Lynx otherwise false
  946. */
  947. protected function checkBrowserLynx()
  948. {
  949. if (stripos($this->_agent, 'lynx') !== false)
  950. {
  951. $aresult = explode('/', stristr($this->_agent, 'Lynx'));
  952. $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ""));
  953. $this->setVersion($aversion[0]);
  954. $this->setBrowser(self::BROWSER_LYNX);
  955. return true;
  956. }
  957. return false;
  958. }
  959. /**
  960. * Determine if the browser is Amaya or not (last updated 1.7)
  961. * @return boolean True if the browser is Amaya otherwise false
  962. */
  963. protected function checkBrowserAmaya()
  964. {
  965. if (stripos($this->_agent, 'amaya') !== false)
  966. {
  967. $aresult = explode('/', stristr($this->_agent, 'Amaya'));
  968. $aversion = explode(' ', $aresult[1]);
  969. $this->setVersion($aversion[0]);
  970. $this->setBrowser(self::BROWSER_AMAYA);
  971. return true;
  972. }
  973. return false;
  974. }
  975. /**
  976. * Determine if the browser is Safari or not (last updated 1.7)
  977. * @return boolean True if the browser is Safari otherwise false
  978. */
  979. protected function checkBrowserSafari()
  980. {
  981. if (stripos($this->_agent, 'Safari') !== false && stripos($this->_agent, 'iPhone') === false && stripos($this->_agent, 'iPod') === false)
  982. {
  983. $aresult = explode('/', stristr($this->_agent, 'Version'));
  984. if (isset($aresult[1]))
  985. {
  986. $aversion = explode(' ', $aresult[1]);
  987. $this->setVersion($aversion[0]);
  988. }
  989. else
  990. {
  991. $this->setVersion(self::VERSION_UNKNOWN);
  992. }
  993. $this->setBrowser(self::BROWSER_SAFARI);
  994. return true;
  995. }
  996. return false;
  997. }
  998. /**
  999. * Determine if the browser is iPhone or not (last updated 1.7)
  1000. * @return boolean True if the browser is iPhone otherwise false
  1001. */
  1002. protected function checkBrowseriPhone()
  1003. {
  1004. if (stripos($this->_agent, 'iPhone') !== false)
  1005. {
  1006. $aresult = explode('/', stristr($this->_agent, 'Version'));
  1007. if (isset($aresult[1]))
  1008. {
  1009. $aversion = explode(' ', $aresult[1]);
  1010. $this->setVersion($aversion[0]);
  1011. }
  1012. else
  1013. {
  1014. $this->setVersion(self::VERSION_UNKNOWN);
  1015. }
  1016. $this->setMobile(true);
  1017. $this->setBrowser(self::BROWSER_IPHONE);
  1018. return true;
  1019. }
  1020. return false;
  1021. }
  1022. /**
  1023. * Determine if the browser is iPod or not (last updated 1.7)
  1024. * @return boolean True if the browser is iPod otherwise false
  1025. */
  1026. protected function checkBrowseriPad()
  1027. {
  1028. if (stripos($this->_agent, 'iPad') !== false)
  1029. {
  1030. $aresult = explode('/', stristr($this->_agent, 'Version'));
  1031. if (isset($aresult[1]))
  1032. {
  1033. $aversion = explode(' ', $aresult[1]);
  1034. $this->setVersion($aversion[0]);
  1035. }
  1036. else
  1037. {
  1038. $this->setVersion(self::VERSION_UNKNOWN);
  1039. }
  1040. $this->setMobile(true);
  1041. $this->setBrowser(self::BROWSER_IPAD);
  1042. return true;
  1043. }
  1044. return false;
  1045. }
  1046. /**
  1047. * Determine if the browser is iPod or not (last updated 1.7)
  1048. * @return boolean True if the browser is iPod otherwise false
  1049. */
  1050. protected function checkBrowseriPod()
  1051. {
  1052. if (stripos($this->_agent, 'iPod') !== false)
  1053. {
  1054. $aresult = explode('/', stristr($this->_agent, 'Version'));
  1055. if (isset($aresult[1]))
  1056. {
  1057. $aversion = explode(' ', $aresult[1]);
  1058. $this->setVersion($aversion[0]);
  1059. }
  1060. else
  1061. {
  1062. $this->setVersion(self::VERSION_UNKNOWN);
  1063. }
  1064. $this->setMobile(true);
  1065. $this->setBrowser(self::BROWSER_IPOD);
  1066. return true;
  1067. }
  1068. return false;
  1069. }
  1070. /**
  1071. * Determine if the browser is Android or not (last updated 1.7)
  1072. * @return boolean True if the browser is Android otherwise false
  1073. */
  1074. protected function checkBrowserAndroid()
  1075. {
  1076. if (stripos($this->_agent, 'Android') !== false)
  1077. {
  1078. $aresult = explode(' ', stristr($this->_agent, 'Android'));
  1079. if (isset($aresult[1]))
  1080. {
  1081. $aversion = explode(' ', $aresult[1]);
  1082. $this->setVersion($aversion[0]);
  1083. }
  1084. else
  1085. {
  1086. $this->setVersion(self::VERSION_UNKNOWN);
  1087. }
  1088. $this->setMobile(true);
  1089. $this->setBrowser(self::BROWSER_ANDROID);
  1090. return true;
  1091. }
  1092. return false;
  1093. }
  1094. /**
  1095. * Determine the user's platform (last updated 1.7)
  1096. */
  1097. protected function checkPlatform()
  1098. {
  1099. if (stripos($this->_agent, 'windows') !== false)
  1100. {
  1101. $this->_platform = self::PLATFORM_WINDOWS;
  1102. }
  1103. else if (stripos($this->_agent, 'iPad') !== false)
  1104. {
  1105. $this->_platform = self::PLATFORM_IPAD;
  1106. }
  1107. else if (stripos($this->_agent, 'iPod') !== false)
  1108. {
  1109. $this->_platform = self::PLATFORM_IPOD;
  1110. }
  1111. else if (stripos($this->_agent, 'iPhone') !== false)
  1112. {
  1113. $this->_platform = self::PLATFORM_IPHONE;
  1114. }
  1115. elseif (stripos($this->_agent, 'mac') !== false)
  1116. {
  1117. $this->_platform = self::PLATFORM_APPLE;
  1118. }
  1119. elseif (stripos($this->_agent, 'android') !== false)
  1120. {
  1121. $this->_platform = self::PLATFORM_ANDROID;
  1122. }
  1123. elseif (stripos($this->_agent, 'linux') !== false)
  1124. {
  1125. $this->_platform = self::PLATFORM_LINUX;
  1126. }
  1127. else if (stripos($this->_agent, 'Nokia') !== false)
  1128. {
  1129. $this->_platform = self::PLATFORM_NOKIA;
  1130. }
  1131. else if (stripos($this->_agent, 'BlackBerry') !== false)
  1132. {
  1133. $this->_platform = self::PLATFORM_BLACKBERRY;
  1134. }
  1135. elseif (stripos($this->_agent, 'FreeBSD') !== false)
  1136. {
  1137. $this->_platform = self::PLATFORM_FREEBSD;
  1138. }
  1139. elseif (stripos($this->_agent, 'OpenBSD') !== false)
  1140. {
  1141. $this->_platform = self::PLATFORM_OPENBSD;
  1142. }
  1143. elseif (stripos($this->_agent, 'NetBSD') !== false)
  1144. {
  1145. $this->_platform = self::PLATFORM_NETBSD;
  1146. }
  1147. elseif (stripos($this->_agent, 'OpenSolaris') !== false)
  1148. {
  1149. $this->_platform = self::PLATFORM_OPENSOLARIS;
  1150. }
  1151. elseif (stripos($this->_agent, 'SunOS') !== false)
  1152. {
  1153. $this->_platform = self::PLATFORM_SUNOS;
  1154. }
  1155. elseif (stripos($this->_agent, 'OS\/2') !== false)
  1156. {
  1157. $this->_platform = self::PLATFORM_OS2;
  1158. }
  1159. elseif (stripos($this->_agent, 'BeOS') !== false)
  1160. {
  1161. $this->_platform = self::PLATFORM_BEOS;
  1162. }
  1163. elseif (stripos($this->_agent, 'win') !== false)
  1164. {
  1165. $this->_platform = self::PLATFORM_WINDOWS;
  1166. }
  1167. }
  1168. }