PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/include/utilities/class.browser.inc

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