PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/class/browser.class.php

http://eude.googlecode.com/
PHP | 868 lines | 543 code | 40 blank | 285 comment | 75 complexity | 35a402a7167dd4d42c37dca11eb75c7d MD5 | raw file
  1. <?php
  2. /**
  3. * File: Browser.php
  4. * Author: Chris Schuld (http://chrisschuld.com/)
  5. * Last Modified: November 08, 2009
  6. * @version 1.6
  7. * @package PegasusPHP
  8. *
  9. * Copyright (C) 2008-2009 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. * Gary White noted: "Since browser detection is so unreliable, I am
  36. * no longer maintaining this script. You are free to use and or
  37. * modify/update it as you want, however the author assumes no
  38. * responsibility for the accuracy of the detected values."
  39. *
  40. * Anyone experienced with Gary's script might be interested in these notes:
  41. *
  42. * Added class constants
  43. * Added detection and version detection for Google's Chrome
  44. * Updated the version detection for Amaya
  45. * Updated the version detection for Firefox
  46. * Updated the version detection for Lynx
  47. * Updated the version detection for WebTV
  48. * Updated the version detection for NetPositive
  49. * Updated the version detection for IE
  50. * Updated the version detection for OmniWeb
  51. * Updated the version detection for iCab
  52. * Updated the version detection for Safari
  53. * Updated Safari to remove mobile devices (iPhone)
  54. * Added detection for iPhone
  55. * Added detection for robots
  56. * Added detection for mobile devices
  57. * Added detection for BlackBerry
  58. * Removed Netscape checks (matches heavily with firefox & mozilla)
  59. *
  60. *
  61. * ADDITIONAL UPDATES:
  62. *
  63. * 2008-11-07:
  64. * + Added Google's Chrome to the detection list
  65. * + Added isBrowser(string) to the list of functions special thanks to
  66. * Daniel 'mavrick' Lang for the function concept (http://mavrick.id.au)
  67. *
  68. * 2008-12-09:
  69. * + Removed unused constant
  70. *
  71. * 2009-02-16: (Rick Hale)
  72. * + Added version detection for Android phones.
  73. *
  74. * 2009-03-14:
  75. * + Added detection for iPods.
  76. * + Added Platform detection for iPhones
  77. * + Added Platform detection for iPods
  78. *
  79. * 2009-04-22:
  80. * + Added detection for GoogleBot
  81. * + Added detection for the W3C Validator.
  82. * + Added detection for Yahoo! Slurp
  83. *
  84. * 2009-04-27:
  85. * + Updated the IE check to remove a typo and bug (thanks John)
  86. *
  87. * 2009-08-18:
  88. * + Updated to support PHP 5.3 - removed all deprecated function calls
  89. * + Updated to remove all double quotes (") -- converted to single quotes (')
  90. *
  91. * 2009-11-08:
  92. * + PHP 5.3 Support
  93. * + Added support for BlackBerry OS and BlackBerry browser
  94. * + Added support for the Opera Mini browser
  95. * + Added additional documenation
  96. * + Added support for isRobot() and isMobile()
  97. * + Added support for Opera version 10
  98. * + Added support for deprecated Netscape Navigator version 9
  99. * + Added support for IceCat
  100. * + Added support for Shiretoko
  101. */
  102. class Browser {
  103. private $_agent = '';
  104. private $_browser_name = '';
  105. private $_version = '';
  106. private $_platform = '';
  107. private $_os = '';
  108. private $_is_aol = false;
  109. private $_is_mobile = false;
  110. private $_is_robot = false;
  111. private $_aol_version = '';
  112. const BROWSER_UNKNOWN = 'unknown';
  113. const VERSION_UNKNOWN = 'unknown';
  114. const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
  115. const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
  116. const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
  117. const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
  118. const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  119. const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
  120. const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
  121. const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
  122. const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
  123. const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
  124. const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
  125. const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
  126. const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
  127. const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
  128. const BROWSER_SAFARI = 'Safari'; // http://apple.com
  129. const BROWSER_IPHONE = 'iPhone'; // http://apple.com
  130. const BROWSER_IPOD = 'iPod'; // http://apple.com
  131. const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
  132. const BROWSER_ANDROID = 'Android'; // http://www.android.com/
  133. const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
  134. const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
  135. const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
  136. const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
  137. const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
  138. const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
  139. const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
  140. const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
  141. const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
  142. const PLATFORM_UNKNOWN = 'unknown';
  143. const PLATFORM_WINDOWS = 'Windows';
  144. const PLATFORM_WINDOWS_CE = 'Windows CE';
  145. const PLATFORM_APPLE = 'Apple';
  146. const PLATFORM_LINUX = 'Linux';
  147. const PLATFORM_OS2 = 'OS/2';
  148. const PLATFORM_BEOS = 'BeOS';
  149. const PLATFORM_IPHONE = 'iPhone';
  150. const PLATFORM_IPOD = 'iPod';
  151. const PLATFORM_BLACKBERRY = 'BlackBerry';
  152. const OPERATING_SYSTEM_UNKNOWN = 'unknown';
  153. public function __construct() {
  154. $this->reset();
  155. $this->determine();
  156. }
  157. /**
  158. * Reset all properties
  159. */
  160. public function reset() {
  161. $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
  162. $this->_browser_name = self::BROWSER_UNKNOWN;
  163. $this->_version = self::VERSION_UNKNOWN;
  164. $this->_platform = self::PLATFORM_UNKNOWN;
  165. $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
  166. $this->_is_aol = false;
  167. $this->_is_mobile = false;
  168. $this->_is_robot = false;
  169. $this->_aol_version = self::VERSION_UNKNOWN;
  170. }
  171. /**
  172. * Check to see if the specific browser is valid
  173. * @param string $browserName
  174. * @return True if the browser is the specified browser
  175. */
  176. function isBrowser($browserName) { return( 0 == strcasecmp($this->_browser_name, trim($browserName))); }
  177. /**
  178. * The name of the browser. All return types are from the class contants
  179. * @return string Name of the browser
  180. */
  181. public function getBrowser() { return $this->_browser_name; }
  182. /**
  183. * Set the name of the browser
  184. * @param $browser The name of the Browser
  185. */
  186. public function setBrowser($browser) { return $this->_browser_name = $browser; }
  187. /**
  188. * The name of the platform. All return types are from the class contants
  189. * @return string Name of the browser
  190. */
  191. public function getPlatform() { return $this->_platform; }
  192. /**
  193. * Set the name of the platform
  194. * @param $platform The name of the Platform
  195. */
  196. public function setPlatform($platform) { return $this->_platform = $platform; }
  197. /**
  198. * The version of the browser.
  199. * @return string Version of the browser (will only contain alpha-numeric characters and a period)
  200. */
  201. public function getVersion() { return $this->_version; }
  202. /**
  203. * Set the version of the browser
  204. * @param $version The version of the Browser
  205. */
  206. public function setVersion($version) { $this->_version = preg_replace('[^0-9,.,a-z,A-Z]','',$version); }
  207. /**
  208. * The version of AOL.
  209. * @return string Version of AOL (will only contain alpha-numeric characters and a period)
  210. */
  211. public function getAolVersion() { return $this->_aol_version; }
  212. /**
  213. * Set the version of AOL
  214. * @param $version The version of AOL
  215. */
  216. public function setAolVersion($version) { $this->_aol_version = preg_replace('[^0-9,.,a-z,A-Z]','',$version); }
  217. /**
  218. * Is the browser from AOL?
  219. * @return boolean True if the browser is from AOL otherwise false
  220. */
  221. public function isAol() { return $this->_is_aol; }
  222. /**
  223. * Is the browser from a mobile device?
  224. * @return boolean True if the browser is from a mobile device otherwise false
  225. */
  226. public function isMobile() { return $this->_is_mobile; }
  227. /**
  228. * Is the browser from a robot (ex Slurp,GoogleBot)?
  229. * @return boolean True if the browser is from a robot otherwise false
  230. */
  231. public function isRobot() { return $this->_is_robot; }
  232. /**
  233. * Set the browser to be from AOL
  234. * @param $isAol
  235. */
  236. public function setAol($isAol) { $this->_is_aol = $isAol; }
  237. /**
  238. * Get the user agent value in use to determine the browser
  239. * @return string The user agent from the HTTP header
  240. */
  241. public function getUserAgent() { return $this->_agent; }
  242. /**
  243. * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
  244. * @param $agent_string The value for the User Agent
  245. */
  246. public function setUserAgent($agent_string) {
  247. $this->reset();
  248. $this->_agent = $agent_string;
  249. $this->determine();
  250. }
  251. protected function setMobile($value=true) {
  252. $this->_is_mobile = $value;
  253. }
  254. protected function setRobot($value=true) {
  255. $this->_is_robot = $value;
  256. }
  257. /**
  258. * Protected routine to calculate and determine what the browser is in use (including platform)
  259. */
  260. protected function determine() {
  261. $this->checkPlatform();
  262. $this->checkBrowsers();
  263. $this->checkForAol();
  264. }
  265. /**
  266. * Protected routine to determine the browser type
  267. * @return boolean True if the browser was detected otherwise false
  268. */
  269. protected function checkBrowsers() {
  270. return (
  271. $this->checkBrowserGoogleBot() ||
  272. $this->checkBrowserSlurp() ||
  273. $this->checkBrowserInternetExplorer() ||
  274. $this->checkBrowserShiretoko() ||
  275. $this->checkBrowserIceCat() ||
  276. $this->checkBrowserNetscapeNavigator9Plus() ||
  277. $this->checkBrowserFirefox() ||
  278. $this->checkBrowserChrome() ||
  279. $this->checkBrowserAndroid() ||
  280. $this->checkBrowserSafari() ||
  281. $this->checkBrowserOpera() ||
  282. $this->checkBrowserNetPositive() ||
  283. $this->checkBrowserFirebird() ||
  284. $this->checkBrowserGaleon() ||
  285. $this->checkBrowserKonqueror() ||
  286. $this->checkBrowserIcab() ||
  287. $this->checkBrowserOmniWeb() ||
  288. $this->checkBrowserPhoenix() ||
  289. $this->checkBrowserWebTv() ||
  290. $this->checkBrowserAmaya() ||
  291. $this->checkBrowserLynx() ||
  292. $this->checkBrowseriPhone() ||
  293. $this->checkBrowseriPod() ||
  294. $this->checkBrowserBlackBerry() ||
  295. $this->checkBrowserW3CValidator() ||
  296. $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
  297. );
  298. }
  299. /**
  300. * Determine if the user is using a BlackBerry
  301. * @return boolean True if the browser is the BlackBerry browser otherwise false
  302. */
  303. protected function checkBrowserBlackBerry() {
  304. $retval = false;
  305. if( preg_match('/blackberry/i',$this->_agent) ) {
  306. $aresult = explode("/",stristr($this->_agent,"BlackBerry"));
  307. $aversion = explode(' ',$aresult[1]);
  308. $this->setVersion($aversion[0]);
  309. $this->_browser_name = self::BROWSER_BLACKBERRY;
  310. $this->setMobile();
  311. $retval = true;
  312. }
  313. return $retval;
  314. }
  315. /**
  316. * Determine if the user is using an AOL User Agent
  317. * @return boolean True if the browser is from AOL otherwise false
  318. */
  319. protected function checkForAol() {
  320. $retval = false;
  321. if( preg_match('/aol/i', $this->_agent) ) {
  322. $aversion = explode(' ',stristr($this->_agent, 'AOL'));
  323. $this->setAol(true);
  324. $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
  325. $retval = true;
  326. }
  327. else {
  328. $this->setAol(false);
  329. $this->setAolVersion(self::VERSION_UNKNOWN);
  330. $retval = true;
  331. }
  332. return $retval;
  333. }
  334. /**
  335. * Determine if the browser is the GoogleBot or not
  336. * @return boolean True if the browser is the GoogletBot otherwise false
  337. */
  338. protected function checkBrowserGoogleBot() {
  339. $retval = false;
  340. if( preg_match('/googlebot/i',$this->_agent) ) {
  341. $aresult = explode('/',stristr($this->_agent,'googlebot'));
  342. $aversion = explode(' ',$aresult[1]);
  343. $this->setVersion(str_replace(';','',$aversion[0]));
  344. $this->_browser_name = self::BROWSER_GOOGLEBOT;
  345. $this->setRobot();
  346. $retval = true;
  347. }
  348. return $retval;
  349. }
  350. /**
  351. * Determine if the browser is the W3C Validator or not
  352. * @return boolean True if the browser is the W3C Validator otherwise false
  353. */
  354. protected function checkBrowserW3CValidator() {
  355. $retval = false;
  356. if( preg_match('/W3C-checklink/i',$this->_agent) ) {
  357. $aresult = explode('/',stristr($this->_agent,'W3C-checklink'));
  358. $aversion = explode(' ',$aresult[1]);
  359. $this->setVersion($aversion[0]);
  360. $this->_browser_name = self::BROWSER_W3CVALIDATOR;
  361. $retval = true;
  362. }
  363. return $retval;
  364. }
  365. /**
  366. * Determine if the browser is the W3C Validator or not
  367. * @return boolean True if the browser is the W3C Validator otherwise false
  368. */
  369. protected function checkBrowserSlurp() {
  370. $retval = false;
  371. if( preg_match('/Slurp/i',$this->_agent) ) {
  372. $aresult = explode('/',stristr($this->_agent,'Slurp'));
  373. $aversion = explode(' ',$aresult[1]);
  374. $this->setVersion($aversion[0]);
  375. $this->_browser_name = self::BROWSER_SLURP;
  376. $this->setRobot();
  377. $retval = true;
  378. }
  379. return $retval;
  380. }
  381. /**
  382. * Determine if the browser is Internet Explorer or not
  383. * @return boolean True if the browser is Internet Explorer otherwise false
  384. */
  385. protected function checkBrowserInternetExplorer() {
  386. $retval = false;
  387. // Test for v1 - v1.5 IE
  388. if( preg_match('/microsoft internet explorer/i', $this->_agent) ) {
  389. $this->setBrowser(self::BROWSER_IE);
  390. $this->setVersion('1.0');
  391. $aresult = stristr($this->_agent, '/');
  392. if( preg_match('/308|425|426|474|0b1/i', $aresult) ) {
  393. $this->setVersion('1.5');
  394. }
  395. $retval = true;
  396. }
  397. // Test for versions > 1.5
  398. else if( preg_match('/msie/i',$this->_agent) && !preg_match('/opera/i',$this->_agent) ) {
  399. $aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie'));
  400. $this->setBrowser( self::BROWSER_IE );
  401. $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
  402. $retval = true;
  403. }
  404. // Test for Pocket IE
  405. else if( preg_match('/mspie/i',$this->_agent) || preg_match('/pocket/i', $this->_agent) ) {
  406. $aresult = explode(' ',stristr($this->_agent,'mspie'));
  407. $this->setPlatform( self::PLATFORM_WINDOWS_CE );
  408. $this->setBrowser( self::BROWSER_POCKET_IE );
  409. $this->setMobile();
  410. if( preg_match('/mspie/i', $this->_agent) ) {
  411. $this->setVersion($aresult[1]);
  412. }
  413. else {
  414. $aversion = explode('/',$this->_agent);
  415. $this->setVersion($aversion[1]);
  416. }
  417. $retval = true;
  418. }
  419. return $retval;
  420. }
  421. /**
  422. * Determine if the browser is Opera or not
  423. * @return boolean True if the browser is Opera otherwise false
  424. */
  425. protected function checkBrowserOpera() {
  426. $retval = false;
  427. if( preg_match('/opera mini/i',$this->_agent) ) {
  428. $resultant = stristr($this->_agent, 'opera mini');
  429. if( preg_match('/\//',$resultant) ) {
  430. $aresult = explode('/',$resultant);
  431. $aversion = explode(' ',$aresult[1]);
  432. $this->setVersion($aversion[0]);
  433. $this->_browser_name = self::BROWSER_OPERA_MINI;
  434. $this->setMobile();
  435. $retval = true;
  436. }
  437. else {
  438. $aversion = explode(' ',stristr($resultant,'opera mini'));
  439. $this->setVersion($aversion[1]);
  440. $this->_browser_name = self::BROWSER_OPERA_MINI;
  441. $this->setMobile();
  442. $retval = true;
  443. }
  444. }
  445. else if( preg_match('/opera/i',$this->_agent) ) {
  446. $resultant = stristr($this->_agent, 'opera');
  447. if( preg_match('/Version\/(10.*)$/',$resultant,$matches) ) {
  448. $this->setVersion($matches[1]);
  449. $this->_browser_name = self::BROWSER_OPERA;
  450. $retval = true;
  451. }
  452. else if( preg_match('/\//',$resultant) ) {
  453. $aresult = explode('/',$resultant);
  454. $aversion = explode(' ',$aresult[1]);
  455. $this->setVersion($aversion[0]);
  456. $this->_browser_name = self::BROWSER_OPERA;
  457. $retval = true;
  458. }
  459. else {
  460. $aversion = explode(' ',stristr($resultant,'opera'));
  461. $this->setVersion($aversion[1]);
  462. $this->_browser_name = self::BROWSER_OPERA;
  463. $retval = true;
  464. }
  465. }
  466. return $retval;
  467. }
  468. /**
  469. * Determine if the browser is WebTv or not
  470. * @return boolean True if the browser is WebTv otherwise false
  471. */
  472. protected function checkBrowserWebTv() {
  473. $retval = false;
  474. if( preg_match('/webtv/i',$this->_agent) ) {
  475. $aresult = explode('/',stristr($this->_agent,'webtv'));
  476. $aversion = explode(' ',$aresult[1]);
  477. $this->setVersion($aversion[0]);
  478. $this->_browser_name = self::BROWSER_WEBTV;
  479. $retval = true;
  480. }
  481. return $retval;
  482. }
  483. /**
  484. * Determine if the browser is NetPositive or not
  485. * @return boolean True if the browser is NetPositive otherwise false
  486. */
  487. protected function checkBrowserNetPositive() {
  488. $retval = false;
  489. if( preg_match('/NetPositive/i',$this->_agent) ) {
  490. $aresult = explode('/',stristr($this->_agent,'NetPositive'));
  491. $aversion = explode(' ',$aresult[1]);
  492. $this->setVersion(str_replace(array('(',')',';'),'',$aversion[0]));
  493. $this->_browser_name = self::BROWSER_NETPOSITIVE;
  494. $this->_platform = self::PLATFORM_BEOS;
  495. $retval = true;
  496. }
  497. return $retval;
  498. }
  499. /**
  500. * Determine if the browser is Galeon or not
  501. * @return boolean True if the browser is Galeon otherwise false
  502. */
  503. protected function checkBrowserGaleon() {
  504. $retval = false;
  505. if( preg_match('/galeon/i',$this->_agent) ) {
  506. $aresult = explode(' ',stristr($this->_agent,'galeon'));
  507. $aversion = explode('/',$aresult[0]);
  508. $this->setVersion($aversion[1]);
  509. $this->setBrowser(self::BROWSER_GALEON);
  510. $retval = true;
  511. }
  512. return $retval;
  513. }
  514. /**
  515. * Determine if the browser is Konqueror or not
  516. * @return boolean True if the browser is Konqueror otherwise false
  517. */
  518. protected function checkBrowserKonqueror() {
  519. $retval = false;
  520. if( preg_match('/Konqueror/i',$this->_agent) ) {
  521. $aresult = explode(' ',stristr($this->_agent,'Konqueror'));
  522. $aversion = explode('/',$aresult[0]);
  523. $this->setVersion($aversion[1]);
  524. $this->setBrowser(self::BROWSER_KONQUEROR);
  525. $retval = true;
  526. }
  527. return $retval;
  528. }
  529. /**
  530. * Determine if the browser is iCab or not
  531. * @return boolean True if the browser is iCab otherwise false
  532. */
  533. protected function checkBrowserIcab() {
  534. $retval = false;
  535. if( preg_match('/icab/i',$this->_agent) ) {
  536. $aversion = explode(' ',stristr(str_replace('/',' ',$this->_agent),'icab'));
  537. $this->setVersion($aversion[1]);
  538. $this->setBrowser(self::BROWSER_ICAB);
  539. $retval = true;
  540. }
  541. return $retval;
  542. }
  543. /**
  544. * Determine if the browser is OmniWeb or not
  545. * @return boolean True if the browser is OmniWeb otherwise false
  546. */
  547. protected function checkBrowserOmniWeb() {
  548. $retval = false;
  549. if( preg_match('/omniweb/i',$this->_agent) ) {
  550. $aresult = explode('/',stristr($this->_agent,'omniweb'));
  551. $aversion = explode(' ',$aresult[1]);
  552. $this->setVersion($aversion[0]);
  553. $this->setBrowser(self::BROWSER_OMNIWEB);
  554. $retval = true;
  555. }
  556. return $retval;
  557. }
  558. /**
  559. * Determine if the browser is Phoenix or not
  560. * @return boolean True if the browser is Phoenix otherwise false
  561. */
  562. protected function checkBrowserPhoenix() {
  563. $retval = false;
  564. if( preg_match('/Phoenix/i',$this->_agent) ) {
  565. $aversion = explode('/',stristr($this->_agent,'Phoenix'));
  566. $this->setVersion($aversion[1]);
  567. $this->setBrowser(self::BROWSER_PHOENIX);
  568. $retval = true;
  569. }
  570. return $retval;
  571. }
  572. /**
  573. * Determine if the browser is Firebird or not
  574. * @return boolean True if the browser is Firebird otherwise false
  575. */
  576. protected function checkBrowserFirebird() {
  577. $retval = false;
  578. if( preg_match('/Firebird/i',$this->_agent) ) {
  579. $aversion = explode('/',stristr($this->_agent,'Firebird'));
  580. $this->setVersion($aversion[1]);
  581. $this->setBrowser(self::BROWSER_FIREBIRD);
  582. $retval = true;
  583. }
  584. return $retval;
  585. }
  586. /**
  587. * Determine if the browser is Netscape Navigator 9+ or not (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
  588. * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
  589. */
  590. protected function checkBrowserNetscapeNavigator9Plus() {
  591. $retval = false;
  592. if( preg_match('/Firefox/i',$this->_agent) && preg_match('/Navigator\/([^ ]*)/i',$this->_agent,$matches) ) {
  593. $this->setVersion($matches[1]);
  594. $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
  595. $retval = true;
  596. }
  597. return $retval;
  598. }
  599. /**
  600. * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko)
  601. * @return boolean True if the browser is Shiretoko otherwise false
  602. */
  603. protected function checkBrowserShiretoko() {
  604. $retval = false;
  605. if( preg_match('/Mozilla/i',$this->_agent) && preg_match('/Shiretoko\/([^ ]*)/i',$this->_agent,$matches) ) {
  606. $this->setVersion($matches[1]);
  607. $this->setBrowser(self::BROWSER_SHIRETOKO);
  608. $retval = true;
  609. }
  610. return $retval;
  611. }
  612. /**
  613. * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat)
  614. * @return boolean True if the browser is Ice Cat otherwise false
  615. */
  616. protected function checkBrowserIceCat() {
  617. $retval = false;
  618. if( preg_match('/Mozilla/i',$this->_agent) && preg_match('/IceCat\/([^ ]*)/i',$this->_agent,$matches) ) {
  619. $this->setVersion($matches[1]);
  620. $this->setBrowser(self::BROWSER_ICECAT);
  621. $retval = true;
  622. }
  623. return $retval;
  624. }
  625. /**
  626. * Determine if the browser is Firefox or not
  627. * @return boolean True if the browser is Firefox otherwise false
  628. */
  629. protected function checkBrowserFirefox() {
  630. $retval = false;
  631. if( preg_match('/Firefox/i',$this->_agent) ) {
  632. $aresult = explode('/',stristr($this->_agent,'Firefox'));
  633. $aversion = explode(' ',$aresult[1]);
  634. $this->setVersion($aversion[0]);
  635. $this->setBrowser(self::BROWSER_FIREFOX);
  636. $retval = true;
  637. }
  638. if( preg_match('/Iceweasel/i',$this->_agent) ) {
  639. $aresult = explode('/',stristr($this->_agent,'Iceweasel'));
  640. $aversion = explode(' ',$aresult[1]);
  641. $this->setVersion($aversion[0]);
  642. $this->setBrowser(self::BROWSER_FIREFOX);
  643. $retval = true;
  644. }
  645. return $retval;
  646. }
  647. /**
  648. * Determine if the browser is Mozilla or not
  649. * @return boolean True if the browser is Mozilla otherwise false
  650. */
  651. protected function checkBrowserMozilla() {
  652. $retval = false;
  653. if( preg_match('/mozilla/i',$this->_agent) && preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent) && !preg_match('/netscape/i',$this->_agent)) {
  654. $aversion = explode(' ',stristr($this->_agent,'rv:'));
  655. preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent,$aversion);
  656. $this->setVersion(str_replace('rv:','',$aversion[0]));
  657. $this->setBrowser(self::BROWSER_MOZILLA);
  658. $retval = true;
  659. }
  660. else if( preg_match('/mozilla/i',$this->_agent) && preg_match('/rv:[0-9]\.[0-9]/i',$this->_agent) && !preg_match('/netscape/i',$this->_agent) ) {
  661. $aversion = explode('',stristr($this->_agent,'rv:'));
  662. preg_match('/rv:[0-9]\.[0-9]\.[0-9]/i',$this->_agent,$aversion);
  663. echo
  664. $this->setVersion(str_replace('rv:','',$aversion[0]));
  665. $this->setBrowser(self::BROWSER_MOZILLA);
  666. $retval = true;
  667. }
  668. return $retval;
  669. }
  670. /**
  671. * Determine if the browser is Lynx or not
  672. * @return boolean True if the browser is Lynx otherwise false
  673. */
  674. protected function checkBrowserLynx() {
  675. $retval = false;
  676. if( preg_match('/libwww/i',$this->_agent) && preg_match('/lynx/i', $this->_agent) ) {
  677. $aresult = explode('/',stristr($this->_agent,'Lynx'));
  678. $aversion = explode(' ',$aresult[1]);
  679. $this->setVersion($aversion[0]);
  680. $this->setBrowser(self::BROWSER_LYNX);
  681. $retval = true;
  682. }
  683. return $retval;
  684. }
  685. /**
  686. * Determine if the browser is Amaya or not
  687. * @return boolean True if the browser is Amaya otherwise false
  688. */
  689. protected function checkBrowserAmaya() {
  690. $retval = false;
  691. if( preg_match('/libwww/i',$this->_agent) && preg_match('/amaya/i', $this->_agent) ) {
  692. $aresult = explode('/',stristr($this->_agent,'Amaya'));
  693. $aversion = explode(' ',$aresult[1]);
  694. $this->setVersion($aversion[0]);
  695. $this->setBrowser(self::BROWSER_AMAYA);
  696. $retval = true;
  697. }
  698. return $retval;
  699. }
  700. /**
  701. * Determine if the browser is Chrome or not
  702. * @return boolean True if the browser is Chrome otherwise false
  703. */
  704. protected function checkBrowserChrome() {
  705. $retval = false;
  706. if( preg_match('/Chrome/i',$this->_agent) ) {
  707. $aresult = explode('/',stristr($this->_agent,'Chrome'));
  708. $aversion = explode(' ',$aresult[1]);
  709. $this->setVersion($aversion[0]);
  710. $this->setBrowser(self::BROWSER_CHROME);
  711. $retval = true;
  712. }
  713. return $retval;
  714. }
  715. /**
  716. * Determine if the browser is Safari or not
  717. * @return boolean True if the browser is Safari otherwise false
  718. */
  719. protected function checkBrowserSafari() {
  720. $retval = false;
  721. if( preg_match('/Safari/i',$this->_agent) && ! preg_match('/iPhone/i',$this->_agent) && ! preg_match('/iPod/i',$this->_agent) ) {
  722. $aresult = explode('/',stristr($this->_agent,'Version'));
  723. if( isset($aresult[1]) ) {
  724. $aversion = explode(' ',$aresult[1]);
  725. $this->setVersion($aversion[0]);
  726. }
  727. else {
  728. $this->setVersion(self::VERSION_UNKNOWN);
  729. }
  730. $this->setBrowser(self::BROWSER_SAFARI);
  731. $retval = true;
  732. }
  733. return $retval;
  734. }
  735. /**
  736. * Determine if the browser is iPhone or not
  737. * @return boolean True if the browser is iPhone otherwise false
  738. */
  739. protected function checkBrowseriPhone() {
  740. $retval = false;
  741. if( preg_match('/iPhone/i',$this->_agent) ) {
  742. $aresult = explode('/',stristr($this->_agent,'Version'));
  743. if( isset($aresult[1]) ) {
  744. $aversion = explode(' ',$aresult[1]);
  745. $this->setVersion($aversion[0]);
  746. }
  747. else {
  748. $this->setVersion(self::VERSION_UNKNOWN);
  749. }
  750. $this->setMobile();
  751. $this->setBrowser(self::BROWSER_IPHONE);
  752. $retval = true;
  753. }
  754. return $retval;
  755. }
  756. /**
  757. * Determine if the browser is iPod or not
  758. * @return boolean True if the browser is iPod otherwise false
  759. */
  760. protected function checkBrowseriPod() {
  761. $retval = false;
  762. if( preg_match('/iPod/i',$this->_agent) ) {
  763. $aresult = explode('/',stristr($this->_agent,'Version'));
  764. if( isset($aresult[1]) ) {
  765. $aversion = explode(' ',$aresult[1]);
  766. $this->setVersion($aversion[0]);
  767. }
  768. else {
  769. $this->setVersion(self::VERSION_UNKNOWN);
  770. }
  771. $this->setMobile();
  772. $this->setBrowser(self::BROWSER_IPOD);
  773. $retval = true;
  774. }
  775. return $retval;
  776. }
  777. /**
  778. * Determine if the browser is Android or not
  779. * @return boolean True if the browser is Android otherwise false
  780. */
  781. protected function checkBrowserAndroid() {
  782. $retval = false;
  783. if( preg_match('/Android/i',$this->_agent) ) {
  784. $aresult = explode('/',stristr($this->_agent,'Version'));
  785. if( isset($aresult[1]) ) {
  786. $aversion = explode(' ',$aresult[1]);
  787. $this->setVersion($aversion[0]);
  788. }
  789. else {
  790. $this->setVersion(self::VERSION_UNKNOWN);
  791. }
  792. $this->setMobile();
  793. $this->setBrowser(self::BROWSER_ANDROID);
  794. $retval = true;
  795. }
  796. return $retval;
  797. }
  798. /**
  799. * Determine the user's platform
  800. */
  801. protected function checkPlatform() {
  802. if( preg_match('/iPhone/i', $this->_agent) ) {
  803. $this->_platform = self::PLATFORM_IPHONE;
  804. }
  805. else if( preg_match('/iPod/i', $this->_agent) ) {
  806. $this->_platform = self::PLATFORM_IPOD;
  807. }
  808. else if( preg_match('/BlackBerry/i', $this->_agent) ) {
  809. $this->_platform = self::PLATFORM_BLACKBERRY;
  810. }
  811. else if( preg_match('/win/i', $this->_agent) ) {
  812. $this->_platform = self::PLATFORM_WINDOWS;
  813. }
  814. elseif( preg_match('/mac/i', $this->_agent) ) {
  815. $this->_platform = self::PLATFORM_APPLE;
  816. }
  817. elseif( preg_match('/linux/i', $this->_agent) ) {
  818. $this->_platform = self::PLATFORM_LINUX;
  819. }
  820. elseif( preg_match('/OS\/2/i', $this->_agent) ) {
  821. $this->_platform = self::PLATFORM_OS2;
  822. }
  823. elseif( preg_match('/BeOS/i', $this->_agent) ) {
  824. $this->_platform = self::PLATFORM_BEOS;
  825. }
  826. }
  827. }
  828. ?>