SimpleCalendarBrowser

File: Browser.php Author: Chris Schuld (http://chrisschuld.com/) Last Modified: July 4th, 2014.

Defined (1)

The class is defined in the following location(s).

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