Browser.php 39 KB

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