PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/extensions/EWebBrowser/EWebBrowser.php

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