PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/libraries/browser.php

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