PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Browser.php

https://github.com/studio-v/nano
PHP | 870 lines | 541 code | 42 blank | 287 comment | 74 complexity | da034e4dec35a105731fc8764a60ef3a 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. Nano_Log::message(var_export($this, true));
  157. Nano_Log::message(var_export($_SERVER, true));
  158. }
  159. /**
  160. * Reset all properties
  161. */
  162. public function reset() {
  163. $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
  164. $this->_browser_name = self::BROWSER_UNKNOWN;
  165. $this->_version = self::VERSION_UNKNOWN;
  166. $this->_platform = self::PLATFORM_UNKNOWN;
  167. $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
  168. $this->_is_aol = false;
  169. $this->_is_mobile = false;
  170. $this->_is_robot = false;
  171. $this->_aol_version = self::VERSION_UNKNOWN;
  172. }
  173. /**
  174. * Check to see if the specific browser is valid
  175. * @param string $browserName
  176. * @return True if the browser is the specified browser
  177. */
  178. function isBrowser($browserName) { return( 0 == strcasecmp($this->_browser_name, trim($browserName))); }
  179. /**
  180. * The name of the browser. All return types are from the class contants
  181. * @return string Name of the browser
  182. */
  183. public function getBrowser() { return $this->_browser_name; }
  184. /**
  185. * Set the name of the browser
  186. * @param $browser The name of the Browser
  187. */
  188. public function setBrowser($browser) { return $this->_browser_name = $browser; }
  189. /**
  190. * The name of the platform. All return types are from the class contants
  191. * @return string Name of the browser
  192. */
  193. public function getPlatform() { return $this->_platform; }
  194. /**
  195. * Set the name of the platform
  196. * @param $platform The name of the Platform
  197. */
  198. public function setPlatform($platform) { return $this->_platform = $platform; }
  199. /**
  200. * The version of the browser.
  201. * @return string Version of the browser (will only contain alpha-numeric characters and a period)
  202. */
  203. public function getVersion() { return $this->_version; }
  204. /**
  205. * Set the version of the browser
  206. * @param $version The version of the Browser
  207. */
  208. public function setVersion($version) { $this->_version = preg_replace('[^0-9,.,a-z,A-Z]','',$version); }
  209. /**
  210. * The version of AOL.
  211. * @return string Version of AOL (will only contain alpha-numeric characters and a period)
  212. */
  213. public function getAolVersion() { return $this->_aol_version; }
  214. /**
  215. * Set the version of AOL
  216. * @param $version The version of AOL
  217. */
  218. public function setAolVersion($version) { $this->_aol_version = preg_replace('[^0-9,.,a-z,A-Z]','',$version); }
  219. /**
  220. * Is the browser from AOL?
  221. * @return boolean True if the browser is from AOL otherwise false
  222. */
  223. public function isAol() { return $this->_is_aol; }
  224. /**
  225. * Is the browser from a mobile device?
  226. * @return boolean True if the browser is from a mobile device otherwise false
  227. */
  228. public function isMobile() { return $this->_is_mobile; }
  229. /**
  230. * Is the browser from a robot (ex Slurp,GoogleBot)?
  231. * @return boolean True if the browser is from a robot otherwise false
  232. */
  233. public function isRobot() { return $this->_is_robot; }
  234. /**
  235. * Set the browser to be from AOL
  236. * @param $isAol
  237. */
  238. public function setAol($isAol) { $this->_is_aol = $isAol; }
  239. /**
  240. * Get the user agent value in use to determine the browser
  241. * @return string The user agent from the HTTP header
  242. */
  243. public function getUserAgent() { return $this->_agent; }
  244. /**
  245. * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
  246. * @param $agent_string The value for the User Agent
  247. */
  248. public function setUserAgent($agent_string) {
  249. $this->reset();
  250. $this->_agent = $agent_string;
  251. $this->determine();
  252. }
  253. protected function setMobile($value=true) {
  254. $this->_is_mobile = $value;
  255. }
  256. protected function setRobot($value=true) {
  257. $this->_is_robot = $value;
  258. }
  259. /**
  260. * Protected routine to calculate and determine what the browser is in use (including platform)
  261. */
  262. protected function determine() {
  263. $this->checkPlatform();
  264. $this->checkBrowsers();
  265. $this->checkForAol();
  266. $this->checkMobilePhones();
  267. }
  268. /**
  269. * Protected routine to determine the browser type
  270. * @return boolean True if the browser was detected otherwise false
  271. */
  272. protected function checkBrowsers() {
  273. return (
  274. $this->checkBrowserGoogleBot() ||
  275. $this->checkBrowserSlurp() ||
  276. $this->checkBrowserInternetExplorer() ||
  277. $this->checkBrowserShiretoko() ||
  278. $this->checkBrowserIceCat() ||
  279. $this->checkBrowserNetscapeNavigator9Plus() ||
  280. $this->checkBrowserFirefox() ||
  281. $this->checkBrowserChrome() ||
  282. $this->checkBrowserAndroid() ||
  283. $this->checkBrowserSafari() ||
  284. $this->checkBrowserOpera() ||
  285. $this->checkBrowserNetPositive() ||
  286. $this->checkBrowserFirebird() ||
  287. $this->checkBrowserGaleon() ||
  288. $this->checkBrowserKonqueror() ||
  289. $this->checkBrowserIcab() ||
  290. $this->checkBrowserOmniWeb() ||
  291. $this->checkBrowserPhoenix() ||
  292. $this->checkBrowserWebTv() ||
  293. $this->checkBrowserAmaya() ||
  294. $this->checkBrowserLynx() ||
  295. $this->checkBrowseriPhone() ||
  296. $this->checkBrowseriPod() ||
  297. $this->checkBrowserBlackBerry() ||
  298. $this->checkBrowserW3CValidator() ||
  299. $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
  300. );
  301. }
  302. /**
  303. * Determine if the user is using a BlackBerry
  304. * @return boolean True if the browser is the BlackBerry browser otherwise false
  305. */
  306. protected function checkBrowserBlackBerry() {
  307. $retval = false;
  308. if( preg_match('/blackberry/i',$this->_agent) ) {
  309. $aresult = explode("/",stristr($this->_agent,"BlackBerry"));
  310. $aversion = explode(' ',$aresult[1]);
  311. $this->setVersion($aversion[0]);
  312. $this->_browser_name = self::BROWSER_BLACKBERRY;
  313. $this->setMobile();
  314. $retval = true;
  315. }
  316. return $retval;
  317. }
  318. /**
  319. * Determine if the user is using an AOL User Agent
  320. * @return boolean True if the browser is from AOL otherwise false
  321. */
  322. protected function checkForAol() {
  323. $retval = false;
  324. if( preg_match('/aol/i', $this->_agent) ) {
  325. $aversion = explode(' ',stristr($this->_agent, 'AOL'));
  326. $this->setAol(true);
  327. $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
  328. $retval = true;
  329. }
  330. else {
  331. $this->setAol(false);
  332. $this->setAolVersion(self::VERSION_UNKNOWN);
  333. $retval = true;
  334. }
  335. return $retval;
  336. }
  337. /**
  338. * Determine if the browser is the GoogleBot or not
  339. * @return boolean True if the browser is the GoogletBot otherwise false
  340. */
  341. protected function checkBrowserGoogleBot() {
  342. $retval = false;
  343. if( preg_match('/googlebot/i',$this->_agent) ) {
  344. $aresult = explode('/',stristr($this->_agent,'googlebot'));
  345. $aversion = explode(' ',$aresult[1]);
  346. $this->setVersion(str_replace(';','',$aversion[0]));
  347. $this->_browser_name = self::BROWSER_GOOGLEBOT;
  348. $this->setRobot();
  349. $retval = true;
  350. }
  351. return $retval;
  352. }
  353. /**
  354. * Determine if the browser is the W3C Validator or not
  355. * @return boolean True if the browser is the W3C Validator otherwise false
  356. */
  357. protected function checkBrowserW3CValidator() {
  358. $retval = false;
  359. if( preg_match('/W3C-checklink/i',$this->_agent) ) {
  360. $aresult = explode('/',stristr($this->_agent,'W3C-checklink'));
  361. $aversion = explode(' ',$aresult[1]);
  362. $this->setVersion($aversion[0]);
  363. $this->_browser_name = self::BROWSER_W3CVALIDATOR;
  364. $retval = true;
  365. }
  366. return $retval;
  367. }
  368. /**
  369. * Determine if the browser is the W3C Validator or not
  370. * @return boolean True if the browser is the W3C Validator otherwise false
  371. */
  372. protected function checkBrowserSlurp() {
  373. $retval = false;
  374. if( preg_match('/Slurp/i',$this->_agent) ) {
  375. $aresult = explode('/',stristr($this->_agent,'Slurp'));
  376. $aversion = explode(' ',$aresult[1]);
  377. $this->setVersion($aversion[0]);
  378. $this->_browser_name = self::BROWSER_SLURP;
  379. $this->setRobot();
  380. $retval = true;
  381. }
  382. return $retval;
  383. }
  384. /**
  385. * Determine if the browser is Internet Explorer or not
  386. * @return boolean True if the browser is Internet Explorer otherwise false
  387. */
  388. protected function checkBrowserInternetExplorer() {
  389. $retval = false;
  390. // Test for v1 - v1.5 IE
  391. if( preg_match('/microsoft internet explorer/i', $this->_agent) ) {
  392. $this->setBrowser(self::BROWSER_IE);
  393. $this->setVersion('1.0');
  394. $aresult = stristr($this->_agent, '/');
  395. if( preg_match('/308|425|426|474|0b1/i', $aresult) ) {
  396. $this->setVersion('1.5');
  397. }
  398. $retval = true;
  399. }
  400. // Test for versions > 1.5
  401. else if( preg_match('/msie/i',$this->_agent) && !preg_match('/opera/i',$this->_agent) ) {
  402. $aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie'));
  403. $this->setBrowser( self::BROWSER_IE );
  404. $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
  405. $retval = true;
  406. }
  407. // Test for Pocket IE
  408. else if( preg_match('/mspie/i',$this->_agent) || preg_match('/pocket/i', $this->_agent) ) {
  409. $aresult = explode(' ',stristr($this->_agent,'mspie'));
  410. $this->setPlatform( self::PLATFORM_WINDOWS_CE );
  411. $this->setBrowser( self::BROWSER_POCKET_IE );
  412. $this->setMobile();
  413. if( preg_match('/mspie/i', $this->_agent) ) {
  414. $this->setVersion($aresult[1]);
  415. }
  416. else {
  417. $aversion = explode('/',$this->_agent);
  418. $this->setVersion($aversion[1]);
  419. }
  420. $retval = true;
  421. }
  422. return $retval;
  423. }
  424. /**
  425. * Determine if the browser is Opera or not
  426. * @return boolean True if the browser is Opera otherwise false
  427. */
  428. protected function checkBrowserOpera() {
  429. $retval = false;
  430. if( preg_match('/opera mini/i',$this->_agent) ) {
  431. $resultant = stristr($this->_agent, 'opera mini');
  432. if( preg_match('/\//',$resultant) ) {
  433. $aresult = explode('/',$resultant);
  434. $aversion = explode(' ',$aresult[1]);
  435. $this->setVersion($aversion[0]);
  436. $this->_browser_name = self::BROWSER_OPERA_MINI;
  437. $this->setMobile();
  438. $retval = true;
  439. }
  440. else {
  441. $aversion = explode(' ',stristr($resultant,'opera mini'));
  442. $this->setVersion($aversion[1]);
  443. $this->_browser_name = self::BROWSER_OPERA_MINI;
  444. $this->setMobile();
  445. $retval = true;
  446. }
  447. }
  448. else if( preg_match('/opera/i',$this->_agent) ) {
  449. $resultant = stristr($this->_agent, 'opera');
  450. if( preg_match('/Version\/(10.*)$/',$resultant,$matches) ) {
  451. $this->setVersion($matches[1]);
  452. $this->_browser_name = self::BROWSER_OPERA;
  453. $retval = true;
  454. }
  455. else if( preg_match('/\//',$resultant) ) {
  456. $aresult = explode('/',$resultant);
  457. $aversion = explode(' ',$aresult[1]);
  458. $this->setVersion($aversion[0]);
  459. $this->_browser_name = self::BROWSER_OPERA;
  460. $retval = true;
  461. }
  462. else {
  463. $aversion = explode(' ',stristr($resultant,'opera'));
  464. $this->setVersion($aversion[1]);
  465. $this->_browser_name = self::BROWSER_OPERA;
  466. $retval = true;
  467. }
  468. }
  469. return $retval;
  470. }
  471. /**
  472. * Determine if the browser is WebTv or not
  473. * @return boolean True if the browser is WebTv otherwise false
  474. */
  475. protected function checkBrowserWebTv() {
  476. $retval = false;
  477. if( preg_match('/webtv/i',$this->_agent) ) {
  478. $aresult = explode('/',stristr($this->_agent,'webtv'));
  479. $aversion = explode(' ',$aresult[1]);
  480. $this->setVersion($aversion[0]);
  481. $this->_browser_name = self::BROWSER_WEBTV;
  482. $retval = true;
  483. }
  484. return $retval;
  485. }
  486. /**
  487. * Determine if the browser is NetPositive or not
  488. * @return boolean True if the browser is NetPositive otherwise false
  489. */
  490. protected function checkBrowserNetPositive() {
  491. $retval = false;
  492. if( preg_match('/NetPositive/i',$this->_agent) ) {
  493. $aresult = explode('/',stristr($this->_agent,'NetPositive'));
  494. $aversion = explode(' ',$aresult[1]);
  495. $this->setVersion(str_replace(array('(',')',';'),'',$aversion[0]));
  496. $this->_browser_name = self::BROWSER_NETPOSITIVE;
  497. $this->_platform = self::PLATFORM_BEOS;
  498. $retval = true;
  499. }
  500. return $retval;
  501. }
  502. /**
  503. * Determine if the browser is Galeon or not
  504. * @return boolean True if the browser is Galeon otherwise false
  505. */
  506. protected function checkBrowserGaleon() {
  507. $retval = false;
  508. if( preg_match('/galeon/i',$this->_agent) ) {
  509. $aresult = explode(' ',stristr($this->_agent,'galeon'));
  510. $aversion = explode('/',$aresult[0]);
  511. $this->setVersion($aversion[1]);
  512. $this->setBrowser(self::BROWSER_GALEON);
  513. $retval = true;
  514. }
  515. return $retval;
  516. }
  517. /**
  518. * Determine if the browser is Konqueror or not
  519. * @return boolean True if the browser is Konqueror otherwise false
  520. */
  521. protected function checkBrowserKonqueror() {
  522. $retval = false;
  523. if( preg_match('/Konqueror/i',$this->_agent) ) {
  524. $aresult = explode(' ',stristr($this->_agent,'Konqueror'));
  525. $aversion = explode('/',$aresult[0]);
  526. $this->setVersion($aversion[1]);
  527. $this->setBrowser(self::BROWSER_KONQUEROR);
  528. $retval = true;
  529. }
  530. return $retval;
  531. }
  532. /**
  533. * Determine if the browser is iCab or not
  534. * @return boolean True if the browser is iCab otherwise false
  535. */
  536. protected function checkBrowserIcab() {
  537. $retval = false;
  538. if( preg_match('/icab/i',$this->_agent) ) {
  539. $aversion = explode(' ',stristr(str_replace('/',' ',$this->_agent),'icab'));
  540. $this->setVersion($aversion[1]);
  541. $this->setBrowser(self::BROWSER_ICAB);
  542. $retval = true;
  543. }
  544. return $retval;
  545. }
  546. /**
  547. * Determine if the browser is OmniWeb or not
  548. * @return boolean True if the browser is OmniWeb otherwise false
  549. */
  550. protected function checkBrowserOmniWeb() {
  551. $retval = false;
  552. if( preg_match('/omniweb/i',$this->_agent) ) {
  553. $aresult = explode('/',stristr($this->_agent,'omniweb'));
  554. $aversion = explode(' ',$aresult[1]);
  555. $this->setVersion($aversion[0]);
  556. $this->setBrowser(self::BROWSER_OMNIWEB);
  557. $retval = true;
  558. }
  559. return $retval;
  560. }
  561. /**
  562. * Determine if the browser is Phoenix or not
  563. * @return boolean True if the browser is Phoenix otherwise false
  564. */
  565. protected function checkBrowserPhoenix() {
  566. $retval = false;
  567. if( preg_match('/Phoenix/i',$this->_agent) ) {
  568. $aversion = explode('/',stristr($this->_agent,'Phoenix'));
  569. $this->setVersion($aversion[1]);
  570. $this->setBrowser(self::BROWSER_PHOENIX);
  571. $retval = true;
  572. }
  573. return $retval;
  574. }
  575. /**
  576. * Determine if the browser is Firebird or not
  577. * @return boolean True if the browser is Firebird otherwise false
  578. */
  579. protected function checkBrowserFirebird() {
  580. $retval = false;
  581. if( preg_match('/Firebird/i',$this->_agent) ) {
  582. $aversion = explode('/',stristr($this->_agent,'Firebird'));
  583. $this->setVersion($aversion[1]);
  584. $this->setBrowser(self::BROWSER_FIREBIRD);
  585. $retval = true;
  586. }
  587. return $retval;
  588. }
  589. /**
  590. * Determine if the browser is Netscape Navigator 9+ or not (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
  591. * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
  592. */
  593. protected function checkBrowserNetscapeNavigator9Plus() {
  594. $retval = false;
  595. if( preg_match('/Firefox/i',$this->_agent) && preg_match('/Navigator\/([^ ]*)/i',$this->_agent,$matches) ) {
  596. $this->setVersion($matches[1]);
  597. $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
  598. $retval = true;
  599. }
  600. return $retval;
  601. }
  602. /**
  603. * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko)
  604. * @return boolean True if the browser is Shiretoko otherwise false
  605. */
  606. protected function checkBrowserShiretoko() {
  607. $retval = false;
  608. if( preg_match('/Mozilla/i',$this->_agent) && preg_match('/Shiretoko\/([^ ]*)/i',$this->_agent,$matches) ) {
  609. $this->setVersion($matches[1]);
  610. $this->setBrowser(self::BROWSER_SHIRETOKO);
  611. $retval = true;
  612. }
  613. return $retval;
  614. }
  615. /**
  616. * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat)
  617. * @return boolean True if the browser is Ice Cat otherwise false
  618. */
  619. protected function checkBrowserIceCat() {
  620. $retval = false;
  621. if( preg_match('/Mozilla/i',$this->_agent) && preg_match('/IceCat\/([^ ]*)/i',$this->_agent,$matches) ) {
  622. $this->setVersion($matches[1]);
  623. $this->setBrowser(self::BROWSER_ICECAT);
  624. $retval = true;
  625. }
  626. return $retval;
  627. }
  628. /**
  629. * Determine if the browser is Firefox or not
  630. * @return boolean True if the browser is Firefox otherwise false
  631. */
  632. protected function checkBrowserFirefox() {
  633. $retval = false;
  634. if( preg_match('/Firefox/i',$this->_agent) ) {
  635. $aresult = explode('/',stristr($this->_agent,'Firefox'));
  636. $aversion = explode(' ',$aresult[1]);
  637. $this->setVersion($aversion[0]);
  638. $this->setBrowser(self::BROWSER_FIREFOX);
  639. $retval = true;
  640. }
  641. return $retval;
  642. }
  643. /**
  644. * Determine if the browser is Mozilla or not
  645. * @return boolean True if the browser is Mozilla otherwise false
  646. */
  647. protected function checkBrowserMozilla() {
  648. $retval = false;
  649. 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)) {
  650. $aversion = explode(' ',stristr($this->_agent,'rv:'));
  651. preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent,$aversion);
  652. $this->setVersion(str_replace('rv:','',$aversion[0]));
  653. $this->setBrowser(self::BROWSER_MOZILLA);
  654. $retval = true;
  655. }
  656. else if( preg_match('/mozilla/i',$this->_agent) && preg_match('/rv:[0-9]\.[0-9]/i',$this->_agent) && !preg_match('/netscape/i',$this->_agent) ) {
  657. $aversion = explode('',stristr($this->_agent,'rv:'));
  658. preg_match('/rv:[0-9]\.[0-9]\.[0-9]/i',$this->_agent,$aversion);
  659. echo
  660. $this->setVersion(str_replace('rv:','',$aversion[0]));
  661. $this->setBrowser(self::BROWSER_MOZILLA);
  662. $retval = true;
  663. }
  664. return $retval;
  665. }
  666. /**
  667. * Determine if the browser is Lynx or not
  668. * @return boolean True if the browser is Lynx otherwise false
  669. */
  670. protected function checkBrowserLynx() {
  671. $retval = false;
  672. if( preg_match('/libwww/i',$this->_agent) && preg_match('/lynx/i', $this->_agent) ) {
  673. $aresult = explode('/',stristr($this->_agent,'Lynx'));
  674. $aversion = explode(' ',$aresult[1]);
  675. $this->setVersion($aversion[0]);
  676. $this->setBrowser(self::BROWSER_LYNX);
  677. $retval = true;
  678. }
  679. return $retval;
  680. }
  681. /**
  682. * Determine if the browser is Amaya or not
  683. * @return boolean True if the browser is Amaya otherwise false
  684. */
  685. protected function checkBrowserAmaya() {
  686. $retval = false;
  687. if( preg_match('/libwww/i',$this->_agent) && preg_match('/amaya/i', $this->_agent) ) {
  688. $aresult = explode('/',stristr($this->_agent,'Amaya'));
  689. $aversion = explode(' ',$aresult[1]);
  690. $this->setVersion($aversion[0]);
  691. $this->setBrowser(self::BROWSER_AMAYA);
  692. $retval = true;
  693. }
  694. return $retval;
  695. }
  696. /**
  697. * Determine if the browser is Chrome or not
  698. * @return boolean True if the browser is Chrome otherwise false
  699. */
  700. protected function checkBrowserChrome() {
  701. $retval = false;
  702. if( preg_match('/Chrome/i',$this->_agent) ) {
  703. $aresult = explode('/',stristr($this->_agent,'Chrome'));
  704. $aversion = explode(' ',$aresult[1]);
  705. $this->setVersion($aversion[0]);
  706. $this->setBrowser(self::BROWSER_CHROME);
  707. $retval = true;
  708. }
  709. return $retval;
  710. }
  711. /**
  712. * Determine if the browser is Safari or not
  713. * @return boolean True if the browser is Safari otherwise false
  714. */
  715. protected function checkBrowserSafari() {
  716. $retval = false;
  717. if( preg_match('/Safari/i',$this->_agent) && ! preg_match('/iPhone/i',$this->_agent) && ! preg_match('/iPod/i',$this->_agent) ) {
  718. $aresult = explode('/',stristr($this->_agent,'Version'));
  719. if( isset($aresult[1]) ) {
  720. $aversion = explode(' ',$aresult[1]);
  721. $this->setVersion($aversion[0]);
  722. }
  723. else {
  724. $this->setVersion(self::VERSION_UNKNOWN);
  725. }
  726. $this->setBrowser(self::BROWSER_SAFARI);
  727. $retval = true;
  728. }
  729. return $retval;
  730. }
  731. /**
  732. * Determine if the browser is iPhone or not
  733. * @return boolean True if the browser is iPhone otherwise false
  734. */
  735. protected function checkBrowseriPhone() {
  736. $retval = false;
  737. if( preg_match('/iPhone/i',$this->_agent) ) {
  738. $aresult = explode('/',stristr($this->_agent,'Version'));
  739. if( isset($aresult[1]) ) {
  740. $aversion = explode(' ',$aresult[1]);
  741. $this->setVersion($aversion[0]);
  742. }
  743. else {
  744. $this->setVersion(self::VERSION_UNKNOWN);
  745. }
  746. $this->setMobile();
  747. $this->setBrowser(self::BROWSER_IPHONE);
  748. $retval = true;
  749. }
  750. return $retval;
  751. }
  752. /**
  753. * Determine if the browser is iPod or not
  754. * @return boolean True if the browser is iPod otherwise false
  755. */
  756. protected function checkBrowseriPod() {
  757. $retval = false;
  758. if( preg_match('/iPod/i',$this->_agent) ) {
  759. $aresult = explode('/',stristr($this->_agent,'Version'));
  760. if( isset($aresult[1]) ) {
  761. $aversion = explode(' ',$aresult[1]);
  762. $this->setVersion($aversion[0]);
  763. }
  764. else {
  765. $this->setVersion(self::VERSION_UNKNOWN);
  766. }
  767. $this->setMobile();
  768. $this->setBrowser(self::BROWSER_IPOD);
  769. $retval = true;
  770. }
  771. return $retval;
  772. }
  773. /**
  774. * Determine if the browser is Android or not
  775. * @return boolean True if the browser is Android otherwise false
  776. */
  777. protected function checkBrowserAndroid() {
  778. $retval = false;
  779. if( preg_match('/Android/i',$this->_agent) ) {
  780. $aresult = explode('/',stristr($this->_agent,'Version'));
  781. if( isset($aresult[1]) ) {
  782. $aversion = explode(' ',$aresult[1]);
  783. $this->setVersion($aversion[0]);
  784. }
  785. else {
  786. $this->setVersion(self::VERSION_UNKNOWN);
  787. }
  788. $this->setMobile();
  789. $this->setBrowser(self::BROWSER_ANDROID);
  790. $retval = true;
  791. }
  792. return $retval;
  793. }
  794. /**
  795. * Determine the user's platform
  796. */
  797. protected function checkPlatform() {
  798. if( preg_match('/iPhone/i', $this->_agent) ) {
  799. $this->_platform = self::PLATFORM_IPHONE;
  800. }
  801. else if( preg_match('/iPod/i', $this->_agent) ) {
  802. $this->_platform = self::PLATFORM_IPOD;
  803. }
  804. else if( preg_match('/BlackBerry/i', $this->_agent) ) {
  805. $this->_platform = self::PLATFORM_BLACKBERRY;
  806. }
  807. else if( preg_match('/win/i', $this->_agent) ) {
  808. $this->_platform = self::PLATFORM_WINDOWS;
  809. }
  810. elseif( preg_match('/mac/i', $this->_agent) ) {
  811. $this->_platform = self::PLATFORM_APPLE;
  812. }
  813. elseif( preg_match('/linux/i', $this->_agent) ) {
  814. $this->_platform = self::PLATFORM_LINUX;
  815. }
  816. elseif( preg_match('/OS\/2/i', $this->_agent) ) {
  817. $this->_platform = self::PLATFORM_OS2;
  818. }
  819. elseif( preg_match('/BeOS/i', $this->_agent) ) {
  820. $this->_platform = self::PLATFORM_BEOS;
  821. }
  822. }
  823. protected function checkMobilePhones() {
  824. //Windows CE; IEMobile 7.11
  825. //Windows CE; IEMobile 7.11
  826. }
  827. }
  828. ?>