PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/Browser.php

http://ponyo.googlecode.com/
PHP | 861 lines | 536 code | 40 blank | 285 comment | 74 complexity | 3d5957c2cdfcea62c0a22ac7c2f32773 MD5 | raw file
Possible License(s): GPL-3.0
  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. return $retval;
  639. }
  640. /**
  641. * Determine if the browser is Mozilla or not
  642. * @return boolean True if the browser is Mozilla otherwise false
  643. */
  644. protected function checkBrowserMozilla() {
  645. $retval = false;
  646. 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)) {
  647. $aversion = explode(' ',stristr($this->_agent,'rv:'));
  648. preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent,$aversion);
  649. $this->setVersion(str_replace('rv:','',$aversion[0]));
  650. $this->setBrowser(self::BROWSER_MOZILLA);
  651. $retval = true;
  652. }
  653. else if( preg_match('/mozilla/i',$this->_agent) && preg_match('/rv:[0-9]\.[0-9]/i',$this->_agent) && !preg_match('/netscape/i',$this->_agent) ) {
  654. $aversion = explode('',stristr($this->_agent,'rv:'));
  655. preg_match('/rv:[0-9]\.[0-9]\.[0-9]/i',$this->_agent,$aversion);
  656. echo
  657. $this->setVersion(str_replace('rv:','',$aversion[0]));
  658. $this->setBrowser(self::BROWSER_MOZILLA);
  659. $retval = true;
  660. }
  661. return $retval;
  662. }
  663. /**
  664. * Determine if the browser is Lynx or not
  665. * @return boolean True if the browser is Lynx otherwise false
  666. */
  667. protected function checkBrowserLynx() {
  668. $retval = false;
  669. if( preg_match('/libwww/i',$this->_agent) && preg_match('/lynx/i', $this->_agent) ) {
  670. $aresult = explode('/',stristr($this->_agent,'Lynx'));
  671. $aversion = explode(' ',$aresult[1]);
  672. $this->setVersion($aversion[0]);
  673. $this->setBrowser(self::BROWSER_LYNX);
  674. $retval = true;
  675. }
  676. return $retval;
  677. }
  678. /**
  679. * Determine if the browser is Amaya or not
  680. * @return boolean True if the browser is Amaya otherwise false
  681. */
  682. protected function checkBrowserAmaya() {
  683. $retval = false;
  684. if( preg_match('/libwww/i',$this->_agent) && preg_match('/amaya/i', $this->_agent) ) {
  685. $aresult = explode('/',stristr($this->_agent,'Amaya'));
  686. $aversion = explode(' ',$aresult[1]);
  687. $this->setVersion($aversion[0]);
  688. $this->setBrowser(self::BROWSER_AMAYA);
  689. $retval = true;
  690. }
  691. return $retval;
  692. }
  693. /**
  694. * Determine if the browser is Chrome or not
  695. * @return boolean True if the browser is Chrome otherwise false
  696. */
  697. protected function checkBrowserChrome() {
  698. $retval = false;
  699. if( preg_match('/Chrome/i',$this->_agent) ) {
  700. $aresult = explode('/',stristr($this->_agent,'Chrome'));
  701. $aversion = explode(' ',$aresult[1]);
  702. $this->setVersion($aversion[0]);
  703. $this->setBrowser(self::BROWSER_CHROME);
  704. $retval = true;
  705. }
  706. return $retval;
  707. }
  708. /**
  709. * Determine if the browser is Safari or not
  710. * @return boolean True if the browser is Safari otherwise false
  711. */
  712. protected function checkBrowserSafari() {
  713. $retval = false;
  714. if( preg_match('/Safari/i',$this->_agent) && ! preg_match('/iPhone/i',$this->_agent) && ! preg_match('/iPod/i',$this->_agent) ) {
  715. $aresult = explode('/',stristr($this->_agent,'Version'));
  716. if( isset($aresult[1]) ) {
  717. $aversion = explode(' ',$aresult[1]);
  718. $this->setVersion($aversion[0]);
  719. }
  720. else {
  721. $this->setVersion(self::VERSION_UNKNOWN);
  722. }
  723. $this->setBrowser(self::BROWSER_SAFARI);
  724. $retval = true;
  725. }
  726. return $retval;
  727. }
  728. /**
  729. * Determine if the browser is iPhone or not
  730. * @return boolean True if the browser is iPhone otherwise false
  731. */
  732. protected function checkBrowseriPhone() {
  733. $retval = false;
  734. if( preg_match('/iPhone/i',$this->_agent) ) {
  735. $aresult = explode('/',stristr($this->_agent,'Version'));
  736. if( isset($aresult[1]) ) {
  737. $aversion = explode(' ',$aresult[1]);
  738. $this->setVersion($aversion[0]);
  739. }
  740. else {
  741. $this->setVersion(self::VERSION_UNKNOWN);
  742. }
  743. $this->setMobile();
  744. $this->setBrowser(self::BROWSER_IPHONE);
  745. $retval = true;
  746. }
  747. return $retval;
  748. }
  749. /**
  750. * Determine if the browser is iPod or not
  751. * @return boolean True if the browser is iPod otherwise false
  752. */
  753. protected function checkBrowseriPod() {
  754. $retval = false;
  755. if( preg_match('/iPod/i',$this->_agent) ) {
  756. $aresult = explode('/',stristr($this->_agent,'Version'));
  757. if( isset($aresult[1]) ) {
  758. $aversion = explode(' ',$aresult[1]);
  759. $this->setVersion($aversion[0]);
  760. }
  761. else {
  762. $this->setVersion(self::VERSION_UNKNOWN);
  763. }
  764. $this->setMobile();
  765. $this->setBrowser(self::BROWSER_IPOD);
  766. $retval = true;
  767. }
  768. return $retval;
  769. }
  770. /**
  771. * Determine if the browser is Android or not
  772. * @return boolean True if the browser is Android otherwise false
  773. */
  774. protected function checkBrowserAndroid() {
  775. $retval = false;
  776. if( preg_match('/Android/i',$this->_agent) ) {
  777. $aresult = explode('/',stristr($this->_agent,'Version'));
  778. if( isset($aresult[1]) ) {
  779. $aversion = explode(' ',$aresult[1]);
  780. $this->setVersion($aversion[0]);
  781. }
  782. else {
  783. $this->setVersion(self::VERSION_UNKNOWN);
  784. }
  785. $this->setMobile();
  786. $this->setBrowser(self::BROWSER_ANDROID);
  787. $retval = true;
  788. }
  789. return $retval;
  790. }
  791. /**
  792. * Determine the user's platform
  793. */
  794. protected function checkPlatform() {
  795. if( preg_match('/iPhone/i', $this->_agent) ) {
  796. $this->_platform = self::PLATFORM_IPHONE;
  797. }
  798. else if( preg_match('/iPod/i', $this->_agent) ) {
  799. $this->_platform = self::PLATFORM_IPOD;
  800. }
  801. else if( preg_match('/BlackBerry/i', $this->_agent) ) {
  802. $this->_platform = self::PLATFORM_BLACKBERRY;
  803. }
  804. else if( preg_match('/win/i', $this->_agent) ) {
  805. $this->_platform = self::PLATFORM_WINDOWS;
  806. }
  807. elseif( preg_match('/mac/i', $this->_agent) ) {
  808. $this->_platform = self::PLATFORM_APPLE;
  809. }
  810. elseif( preg_match('/linux/i', $this->_agent) ) {
  811. $this->_platform = self::PLATFORM_LINUX;
  812. }
  813. elseif( preg_match('/OS\/2/i', $this->_agent) ) {
  814. $this->_platform = self::PLATFORM_OS2;
  815. }
  816. elseif( preg_match('/BeOS/i', $this->_agent) ) {
  817. $this->_platform = self::PLATFORM_BEOS;
  818. }
  819. }
  820. }
  821. ?>