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

/ReduxCore/inc/browser.php

https://github.com/samzoom/redux-framework
PHP | 1195 lines | 643 code | 147 blank | 405 comment | 93 complexity | 0758d67951edb03442bcfe728c8573b0 MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file