Browser

Modified to remove var Chris Christoff on 12/26/2012 Changes: Changes vars to publics.

Defined (1)

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

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