[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Environment/ -> Browser.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Environment;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Browser class, provides capability information about the current web client.
  18   *
  19   * Browser identification is performed by examining the HTTP_USER_AGENT
  20   * environment variable provided by the web server.
  21   *
  22   * This class has many influences from the lib/Browser.php code in
  23   * version 3 of Horde by Chuck Hagenbuch and Jon Parise.
  24   *
  25   * @since  1.7.0
  26   */
  27  class Browser
  28  {
  29      /**
  30       * @var    integer  Major version number
  31       * @since  3.0.0
  32       */
  33      protected $majorVersion = 0;
  34  
  35      /**
  36       * @var    integer  Minor version number
  37       * @since  3.0.0
  38       */
  39      protected $minorVersion = 0;
  40  
  41      /**
  42       * @var    string  Browser name.
  43       * @since  3.0.0
  44       */
  45      protected $browser = '';
  46  
  47      /**
  48       * @var    string  Full user agent string.
  49       * @since  3.0.0
  50       */
  51      protected $agent = '';
  52  
  53      /**
  54       * @var    string  Lower-case user agent string
  55       * @since  3.0.0
  56       */
  57      protected $lowerAgent = '';
  58  
  59      /**
  60       * @var    string  HTTP_ACCEPT string.
  61       * @since  3.0.0
  62       */
  63      protected $accept = '';
  64  
  65      /**
  66       * @var    array  Parsed HTTP_ACCEPT string
  67       * @since  3.0.0
  68       */
  69      protected $acceptParsed = array();
  70  
  71      /**
  72       * @var    string  Platform the browser is running on
  73       * @since  3.0.0
  74       */
  75      protected $platform = '';
  76  
  77      /**
  78       * @var    array  Known robots.
  79       * @since  3.0.0
  80       */
  81      protected $robots = array(
  82          'Googlebot\/',
  83          'Googlebot-Mobile',
  84          'Googlebot-Image',
  85          'Googlebot-News',
  86          'Googlebot-Video',
  87          'AdsBot-Google([^-]|$)',
  88          'AdsBot-Google-Mobile',
  89          'Feedfetcher-Google',
  90          'Mediapartners-Google',
  91          'Mediapartners \(Googlebot\)',
  92          'APIs-Google',
  93          'bingbot',
  94          'Slurp',
  95          '[wW]get',
  96          'curl',
  97          'LinkedInBot',
  98          'Python-urllib',
  99          'python-requests',
 100          'libwww',
 101          'httpunit',
 102          'nutch',
 103          'Go-http-client',
 104          'phpcrawl',
 105          'msnbot',
 106          'jyxobot',
 107          'FAST-WebCrawler',
 108          'FAST Enterprise Crawler',
 109          'BIGLOTRON',
 110          'Teoma',
 111          'convera',
 112          'seekbot',
 113          'Gigabot',
 114          'Gigablast',
 115          'exabot',
 116          'ia_archiver',
 117          'GingerCrawler',
 118          'webmon ',
 119          'HTTrack',
 120          'grub.org',
 121          'UsineNouvelleCrawler',
 122          'antibot',
 123          'netresearchserver',
 124          'speedy',
 125          'fluffy',
 126          'bibnum.bnf',
 127          'findlink',
 128          'msrbot',
 129          'panscient',
 130          'yacybot',
 131          'AISearchBot',
 132          'ips-agent',
 133          'tagoobot',
 134          'MJ12bot',
 135          'woriobot',
 136          'yanga',
 137          'buzzbot',
 138          'mlbot',
 139          'YandexBot',
 140          'yandex.com\/bots',
 141          'purebot',
 142          'Linguee Bot',
 143          'CyberPatrol',
 144          'voilabot',
 145          'Baiduspider',
 146          'citeseerxbot',
 147          'spbot',
 148          'twengabot',
 149          'postrank',
 150          'turnitinbot',
 151          'scribdbot',
 152          'page2rss',
 153          'sitebot',
 154          'linkdex',
 155          'Adidxbot',
 156          'blekkobot',
 157          'ezooms',
 158          'dotbot',
 159          'Mail.RU_Bot',
 160          'discobot',
 161          'heritrix',
 162          'findthatfile',
 163          'europarchive.org',
 164          'NerdByNature.Bot',
 165          'sistrix crawler',
 166          'Ahrefs(Bot|SiteAudit)',
 167          'fuelbot',
 168          'CrunchBot',
 169          'centurybot9',
 170          'IndeedBot',
 171          'mappydata',
 172          'woobot',
 173          'ZoominfoBot',
 174          'PrivacyAwareBot',
 175          'Multiviewbot',
 176          'SWIMGBot',
 177          'Grobbot',
 178          'eright',
 179          'Apercite',
 180          'semanticbot',
 181          'Aboundex',
 182          'domaincrawler',
 183          'wbsearchbot',
 184          'summify',
 185          'CCBot',
 186          'edisterbot',
 187          'seznambot',
 188          'ec2linkfinder',
 189          'gslfbot',
 190          'aiHitBot',
 191          'intelium_bot',
 192          'facebookexternalhit',
 193          'Yeti',
 194          'RetrevoPageAnalyzer',
 195          'lb-spider',
 196          'Sogou',
 197          'lssbot',
 198          'careerbot',
 199          'wotbox',
 200          'wocbot',
 201          'ichiro',
 202          'DuckDuckBot',
 203          'lssrocketcrawler',
 204          'drupact',
 205          'webcompanycrawler',
 206          'acoonbot',
 207          'openindexspider',
 208          'gnam gnam spider',
 209          'web-archive-net.com.bot',
 210          'backlinkcrawler',
 211          'coccoc',
 212          'integromedb',
 213          'content crawler spider',
 214          'toplistbot',
 215          'it2media-domain-crawler',
 216          'ip-web-crawler.com',
 217          'siteexplorer.info',
 218          'elisabot',
 219          'proximic',
 220          'changedetection',
 221          'arabot',
 222          'WeSEE:Search',
 223          'niki-bot',
 224          'CrystalSemanticsBot',
 225          'rogerbot',
 226          '360Spider',
 227          'psbot',
 228          'InterfaxScanBot',
 229          'CC Metadata Scaper',
 230          'g00g1e.net',
 231          'GrapeshotCrawler',
 232          'urlappendbot',
 233          'brainobot',
 234          'fr-crawler',
 235          'binlar',
 236          'SimpleCrawler',
 237          'Twitterbot',
 238          'cXensebot',
 239          'smtbot',
 240          'bnf.fr_bot',
 241          'A6-Indexer',
 242          'ADmantX',
 243          'Facebot',
 244          'OrangeBot\/',
 245          'memorybot',
 246          'AdvBot',
 247          'MegaIndex',
 248          'SemanticScholarBot',
 249          'ltx71',
 250          'nerdybot',
 251          'xovibot',
 252          'BUbiNG',
 253          'Qwantify',
 254          'archive.org_bot',
 255          'Applebot',
 256          'TweetmemeBot',
 257          'crawler4j',
 258          'findxbot',
 259          'S[eE][mM]rushBot',
 260          'yoozBot',
 261          'lipperhey',
 262          'Y!J',
 263          'Domain Re-Animator Bot',
 264          'AddThis',
 265          'Screaming Frog SEO Spider',
 266          'MetaURI',
 267          'Scrapy',
 268          'Livelap[bB]ot',
 269          'OpenHoseBot',
 270          'CapsuleChecker',
 271          '[email protected]',
 272          'IstellaBot',
 273          'DeuSu\/',
 274          'betaBot',
 275          'Cliqzbot\/',
 276          'MojeekBot\/',
 277          'netEstate NE Crawler',
 278          'SafeSearch microdata crawler',
 279          'Gluten Free Crawler\/',
 280          'Sonic',
 281          'Sysomos',
 282          'Trove',
 283          'deadlinkchecker',
 284          'Slack-ImgProxy',
 285          'Embedly',
 286          'RankActiveLinkBot',
 287          'iskanie',
 288          'SafeDNSBot',
 289          'SkypeUriPreview',
 290          'Veoozbot',
 291          'Slackbot',
 292          'redditbot',
 293          'datagnionbot',
 294          'Google-Adwords-Instant',
 295          'adbeat_bot',
 296          'WhatsApp',
 297          'contxbot',
 298          'pinterest',
 299          'electricmonk',
 300          'GarlikCrawler',
 301          'BingPreview\/',
 302          'vebidoobot',
 303          'FemtosearchBot',
 304          'Yahoo Link Preview',
 305          'MetaJobBot',
 306          'DomainStatsBot',
 307          'mindUpBot',
 308          'Daum\/',
 309          'Jugendschutzprogramm-Crawler',
 310          'Xenu Link Sleuth',
 311          'Pcore-HTTP',
 312          'moatbot',
 313          'KosmioBot',
 314          'pingdom',
 315          'PhantomJS',
 316          'Gowikibot',
 317          'PiplBot',
 318          'Discordbot',
 319          'TelegramBot',
 320          'Jetslide',
 321          'newsharecounts',
 322          'James BOT',
 323          'Barkrowler',
 324          'TinEye',
 325          'SocialRankIOBot',
 326          'trendictionbot',
 327          'Ocarinabot',
 328          'epicbot',
 329          'Primalbot',
 330          'DuckDuckGo-Favicons-Bot',
 331          'GnowitNewsbot',
 332          'Leikibot',
 333          'LinkArchiver',
 334          'YaK\/',
 335          'PaperLiBot',
 336          'Digg Deeper',
 337          'dcrawl',
 338          'Snacktory',
 339          'AndersPinkBot',
 340          'Fyrebot',
 341          'EveryoneSocialBot',
 342          'Mediatoolkitbot',
 343          'Luminator-robots',
 344          'ExtLinksBot',
 345          'SurveyBot',
 346          'NING\/',
 347          'okhttp',
 348          'Nuzzel',
 349          'omgili',
 350          'PocketParser',
 351          'YisouSpider',
 352          'um-LN',
 353          'ToutiaoSpider',
 354          'MuckRack',
 355          'Jamie\'s Spider',
 356          'AHC\/',
 357          'NetcraftSurveyAgent',
 358          'Laserlikebot',
 359          'Apache-HttpClient',
 360          'AppEngine-Google',
 361          'Jetty',
 362          'Upflow',
 363          'Thinklab',
 364          'Traackr.com',
 365          'Twurly',
 366          'Mastodon',
 367          'http_get',
 368          'DnyzBot',
 369          'botify',
 370          '007ac9 Crawler',
 371          'BehloolBot',
 372          'BrandVerity',
 373          'check_http',
 374          'BDCbot',
 375          'ZumBot',
 376          'EZID',
 377          'ICC-Crawler',
 378          'ArchiveBot',
 379          '^LCC ',
 380          'filterdb.iss.net\/crawler',
 381          'BLP_bbot',
 382          'BomboraBot',
 383          'Buck\/',
 384          'Companybook-Crawler',
 385          'Genieo',
 386          'magpie-crawler',
 387          'MeltwaterNews',
 388          'Moreover',
 389          'newspaper\/',
 390          'ScoutJet',
 391          '(^| )sentry\/',
 392          'StorygizeBot',
 393          'UptimeRobot',
 394          'OutclicksBot',
 395          'seoscanners',
 396          'Hatena',
 397          'Google Web Preview',
 398          'MauiBot',
 399          'AlphaBot',
 400          'SBL-BOT',
 401          'IAS crawler',
 402          'adscanner',
 403          'Netvibes',
 404          'acapbot',
 405          'Baidu-YunGuanCe',
 406          'bitlybot',
 407          'blogmuraBot',
 408          'Bot.AraTurka.com',
 409          'bot-pge.chlooe.com',
 410          'BoxcarBot',
 411          'BTWebClient',
 412          'ContextAd Bot',
 413          'Digincore bot',
 414          'Disqus',
 415          'Feedly',
 416          'Fetch\/',
 417          'Fever',
 418          'Flamingo_SearchEngine',
 419          'FlipboardProxy',
 420          'g2reader-bot',
 421          'imrbot',
 422          'K7MLWCBot',
 423          'Kemvibot',
 424          'Landau-Media-Spider',
 425          'linkapediabot',
 426          'vkShare',
 427          'Siteimprove.com',
 428          'BLEXBot\/',
 429          'DareBoost',
 430          'ZuperlistBot\/',
 431          'Miniflux\/',
 432          'Feedspotbot\/',
 433          'Diffbot\/',
 434          'SEOkicks',
 435          'tracemyfile',
 436          'Nimbostratus-Bot',
 437          'zgrab',
 438          'PR-CY.RU',
 439          'AdsTxtCrawler',
 440          'Datafeedwatch',
 441          'Zabbix',
 442          'TangibleeBot',
 443          'google-xrawler',
 444          'axios',
 445          'Amazon CloudFront',
 446          'Pulsepoint',
 447      );
 448  
 449      /**
 450       * @var    boolean  Is this a mobile browser?
 451       * @since  3.0.0
 452       */
 453      protected $mobile = false;
 454  
 455      /**
 456       * List of viewable image MIME subtypes.
 457       * This list of viewable images works for IE and Netscape/Mozilla.
 458       *
 459       * @var    array
 460       * @since  3.0.0
 461       */
 462      protected $images = array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp');
 463  
 464      /**
 465       * @var    array  Browser instances container.
 466       * @since  1.7.3
 467       */
 468      protected static $instances = array();
 469  
 470      /**
 471       * Create a browser instance (constructor).
 472       *
 473       * @param   string  $userAgent  The browser string to parse.
 474       * @param   string  $accept     The HTTP_ACCEPT settings to use.
 475       *
 476       * @since   1.7.0
 477       */
 478      public function __construct($userAgent = null, $accept = null)
 479      {
 480          $this->match($userAgent, $accept);
 481      }
 482  
 483      /**
 484       * Returns the global Browser object, only creating it
 485       * if it doesn't already exist.
 486       *
 487       * @param   string  $userAgent  The browser string to parse.
 488       * @param   string  $accept     The HTTP_ACCEPT settings to use.
 489       *
 490       * @return  Browser  The Browser object.
 491       *
 492       * @since   1.7.0
 493       */
 494      public static function getInstance($userAgent = null, $accept = null)
 495      {
 496          $signature = serialize(array($userAgent, $accept));
 497  
 498          if (empty(self::$instances[$signature])) {
 499              self::$instances[$signature] = new static($userAgent, $accept);
 500          }
 501  
 502          return self::$instances[$signature];
 503      }
 504  
 505      /**
 506       * Parses the user agent string and inititializes the object with
 507       * all the known features and quirks for the given browser.
 508       *
 509       * @param   string  $userAgent  The browser string to parse.
 510       * @param   string  $accept     The HTTP_ACCEPT settings to use.
 511       *
 512       * @return  void
 513       *
 514       * @since   1.7.0
 515       */
 516      public function match($userAgent = null, $accept = null)
 517      {
 518          // Set our agent string.
 519          if (\is_null($userAgent)) {
 520              if (isset($_SERVER['HTTP_USER_AGENT'])) {
 521                  $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
 522              }
 523          } else {
 524              $this->agent = $userAgent;
 525          }
 526  
 527          $this->lowerAgent = strtolower($this->agent);
 528  
 529          // Set our accept string.
 530          if (\is_null($accept)) {
 531              if (isset($_SERVER['HTTP_ACCEPT'])) {
 532                  $this->accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
 533              }
 534          } else {
 535              $this->accept = strtolower($accept);
 536          }
 537  
 538          if (!empty($this->agent)) {
 539              $this->_setPlatform();
 540  
 541              /*
 542               * Determine if mobile. Note: Some Handhelds have their screen resolution in the
 543               * user agent string, which we can use to look for mobile agents.
 544               */
 545              if (
 546                  strpos($this->agent, 'MOT-') !== false
 547                  || strpos($this->lowerAgent, 'j-') !== false
 548                  || preg_match('/(mobileexplorer|openwave|opera mini|opera mobi|operamini|avantgo|wap|elaine)/i', $this->agent)
 549                  || preg_match('/(iPhone|iPod|iPad|Android|Mobile|Phone|BlackBerry|Xiino|Palmscape|palmsource)/i', $this->agent)
 550                  || preg_match('/(Nokia|Ericsson|docomo|digital paths|portalmmm|CriOS[\/ ]([0-9.]+))/i', $this->agent)
 551                  || preg_match('/(UP|UP.B|UP.L)/', $this->agent)
 552                  || preg_match('/; (120x160|240x280|240x320|320x320)\)/', $this->agent)
 553              ) {
 554                  $this->mobile = true;
 555              }
 556  
 557              /*
 558               * We have to check for Edge as the first browser, because Edge has something like:
 559               * Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393
 560               */
 561              if (preg_match('|Edge\/([0-9.]+)|', $this->agent, $version)) {
 562                  $this->setBrowser('edge');
 563  
 564                  if (strpos($version[1], '.') !== false) {
 565                      list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 566                  } else {
 567                      $this->majorVersion = $version[1];
 568                      $this->minorVersion = 0;
 569                  }
 570              } elseif (preg_match('|Edg\/([0-9.]+)|', $this->agent, $version)) {
 571                  /**
 572                   * We have to check for Edge as the first browser, because Edge has something like:
 573                   * Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3738.0 Safari/537.36 Edg/75.0.107.0
 574                   */
 575                  $this->setBrowser('edg');
 576  
 577                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 578              } elseif (preg_match('|Opera[\/ ]([0-9.]+)|', $this->agent, $version)) {
 579                  $this->setBrowser('opera');
 580  
 581                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 582  
 583                  /*
 584                   * Due to changes in Opera UA, we need to check Version/xx.yy,
 585                   * but only if version is > 9.80. See: http://dev.opera.com/articles/view/opera-ua-string-changes/
 586                   */
 587                  if ($this->majorVersion == 9 && $this->minorVersion >= 80) {
 588                      $this->identifyBrowserVersion();
 589                  }
 590              } elseif (preg_match('/OPR[\/ ]([0-9.]+)/', $this->agent, $version)) {
 591                  // Opera 15+
 592                  $this->setBrowser('opera');
 593  
 594                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 595              } elseif (
 596                  preg_match('/Chrome[\/ ]([0-9.]+)/i', $this->agent, $version)
 597                  || preg_match('/CrMo[\/ ]([0-9.]+)/i', $this->agent, $version)
 598                  || preg_match('/CriOS[\/ ]([0-9.]+)/i', $this->agent, $version)
 599              ) {
 600                  $this->setBrowser('chrome');
 601  
 602                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 603              } elseif (
 604                  strpos($this->lowerAgent, 'elaine/') !== false
 605                  || strpos($this->lowerAgent, 'palmsource') !== false
 606                  || strpos($this->lowerAgent, 'digital paths') !== false
 607              ) {
 608                  $this->setBrowser('palm');
 609              } elseif (
 610                  preg_match('/MSIE ([0-9.]+)/i', $this->agent, $version)
 611                  || preg_match('/IE ([0-9.]+)/i', $this->agent, $version)
 612                  || preg_match('/Internet Explorer[\/ ]([0-9.]+)/i', $this->agent, $version)
 613                  || preg_match('/Trident\/.*rv:([0-9.]+)/i', $this->agent, $version)
 614              ) {
 615                  $this->setBrowser('msie');
 616  
 617                  // Special case for IE 11+
 618                  if (strpos($version[0], 'Trident') !== false && strpos($version[0], 'rv:') !== false) {
 619                      preg_match('|rv:([0-9.]+)|', $this->agent, $version);
 620                  }
 621  
 622                  if (strpos($version[1], '.') !== false) {
 623                      list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 624                  } else {
 625                      $this->majorVersion = $version[1];
 626                      $this->minorVersion = 0;
 627                  }
 628              } elseif (preg_match('|amaya\/([0-9.]+)|', $this->agent, $version)) {
 629                  $this->setBrowser('amaya');
 630                  $this->majorVersion = $version[1];
 631  
 632                  if (isset($version[2])) {
 633                      $this->minorVersion = $version[2];
 634                  }
 635              } elseif (preg_match('|ANTFresco\/([0-9]+)|', $this->agent, $version)) {
 636                  $this->setBrowser('fresco');
 637              } elseif (strpos($this->lowerAgent, 'avantgo') !== false) {
 638                  $this->setBrowser('avantgo');
 639              } elseif (preg_match('|[Kk]onqueror\/([0-9]+)|', $this->agent, $version) || preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->agent, $version)) {
 640                  // Konqueror and Apple's Safari both use the KHTML rendering engine.
 641                  $this->setBrowser('konqueror');
 642                  $this->majorVersion = $version[1];
 643  
 644                  if (isset($version[2])) {
 645                      $this->minorVersion = $version[2];
 646                  }
 647  
 648                  if (strpos($this->agent, 'Safari') !== false && $this->majorVersion >= 60) {
 649                      // Safari.
 650                      $this->setBrowser('safari');
 651                      $this->identifyBrowserVersion();
 652                  }
 653              } elseif (preg_match('|Firefox\/([0-9.]+)|', $this->agent, $version)) {
 654                  $this->setBrowser('firefox');
 655  
 656                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 657              } elseif (preg_match('|Lynx\/([0-9]+)|', $this->agent, $version)) {
 658                  $this->setBrowser('lynx');
 659              } elseif (preg_match('|Links \(([0-9]+)|', $this->agent, $version)) {
 660                  $this->setBrowser('links');
 661              } elseif (preg_match('|HotJava\/([0-9]+)|', $this->agent, $version)) {
 662                  $this->setBrowser('hotjava');
 663              } elseif (strpos($this->agent, 'UP/') !== false || strpos($this->agent, 'UP.B') !== false || strpos($this->agent, 'UP.L') !== false) {
 664                  $this->setBrowser('up');
 665              } elseif (strpos($this->agent, 'Xiino/') !== false) {
 666                  $this->setBrowser('xiino');
 667              } elseif (strpos($this->agent, 'Palmscape/') !== false) {
 668                  $this->setBrowser('palmscape');
 669              } elseif (strpos($this->agent, 'Nokia') !== false) {
 670                  $this->setBrowser('nokia');
 671              } elseif (strpos($this->agent, 'Ericsson') !== false) {
 672                  $this->setBrowser('ericsson');
 673              } elseif (strpos($this->lowerAgent, 'wap') !== false) {
 674                  $this->setBrowser('wap');
 675              } elseif (strpos($this->lowerAgent, 'docomo') !== false || strpos($this->lowerAgent, 'portalmmm') !== false) {
 676                  $this->setBrowser('imode');
 677              } elseif (strpos($this->agent, 'BlackBerry') !== false) {
 678                  $this->setBrowser('blackberry');
 679              } elseif (strpos($this->agent, 'MOT-') !== false) {
 680                  $this->setBrowser('motorola');
 681              } elseif (strpos($this->lowerAgent, 'j-') !== false) {
 682                  $this->setBrowser('mml');
 683              } elseif (preg_match('|Mozilla\/([0-9.]+)|', $this->agent, $version)) {
 684                  $this->setBrowser('mozilla');
 685  
 686                  list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 687              }
 688          }
 689      }
 690  
 691      /**
 692       * Match the platform of the browser.
 693       *
 694       * This is a pretty simplistic implementation, but it's intended
 695       * to let us tell what line breaks to send, so it's good enough
 696       * for its purpose.
 697       *
 698       * @return  void
 699       *
 700       * @since   1.7.0
 701       */
 702      protected function _setPlatform()
 703      {
 704          if (strpos($this->lowerAgent, 'wind') !== false) {
 705              $this->platform = 'win';
 706          } elseif (strpos($this->lowerAgent, 'mac') !== false) {
 707              $this->platform = 'mac';
 708          } else {
 709              $this->platform = 'unix';
 710          }
 711      }
 712  
 713      /**
 714       * Return the currently matched platform.
 715       *
 716       * @return  string  The user's platform.
 717       *
 718       * @since   1.7.0
 719       */
 720      public function getPlatform()
 721      {
 722          return $this->platform;
 723      }
 724  
 725      /**
 726       * Set browser version, not by engine version
 727       * Fallback to use when no other method identify the engine version
 728       *
 729       * @return  void
 730       *
 731       * @since   1.7.0
 732       */
 733      protected function identifyBrowserVersion()
 734      {
 735          if (preg_match('|Version[/ ]([0-9.]+)|', $this->agent, $version)) {
 736              list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
 737  
 738              return;
 739          }
 740  
 741          // Can't identify browser version
 742          $this->majorVersion = 0;
 743          $this->minorVersion = 0;
 744      }
 745  
 746      /**
 747       * Sets the current browser.
 748       *
 749       * @param   string  $browser  The browser to set as current.
 750       *
 751       * @return  void
 752       *
 753       * @since   1.7.0
 754       */
 755      public function setBrowser($browser)
 756      {
 757          $this->browser = $browser;
 758      }
 759  
 760      /**
 761       * Retrieve the current browser.
 762       *
 763       * @return  string  The current browser.
 764       *
 765       * @since   1.7.0
 766       */
 767      public function getBrowser()
 768      {
 769          return $this->browser;
 770      }
 771  
 772      /**
 773       * Retrieve the current browser's major version.
 774       *
 775       * @return  integer  The current browser's major version
 776       *
 777       * @since   1.7.0
 778       */
 779      public function getMajor()
 780      {
 781          return $this->majorVersion;
 782      }
 783  
 784      /**
 785       * Retrieve the current browser's minor version.
 786       *
 787       * @return  integer  The current browser's minor version.
 788       *
 789       * @since   1.7.0
 790       */
 791      public function getMinor()
 792      {
 793          return $this->minorVersion;
 794      }
 795  
 796      /**
 797       * Retrieve the current browser's version.
 798       *
 799       * @return  string  The current browser's version.
 800       *
 801       * @since   1.7.0
 802       */
 803      public function getVersion()
 804      {
 805          return $this->majorVersion . '.' . $this->minorVersion;
 806      }
 807  
 808      /**
 809       * Return the full browser agent string.
 810       *
 811       * @return  string  The browser agent string
 812       *
 813       * @since   1.7.0
 814       */
 815      public function getAgentString()
 816      {
 817          return $this->agent;
 818      }
 819  
 820      /**
 821       * Returns the server protocol in use on the current server.
 822       *
 823       * @return  string  The HTTP server protocol version.
 824       *
 825       * @since   1.7.0
 826       */
 827      public function getHTTPProtocol()
 828      {
 829          if (isset($_SERVER['SERVER_PROTOCOL'])) {
 830              if (($pos = strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) {
 831                  return substr($_SERVER['SERVER_PROTOCOL'], $pos + 1);
 832              }
 833          }
 834      }
 835  
 836      /**
 837       * Determines if a browser can display a given MIME type.
 838       *
 839       * Note that  image/jpeg and image/pjpeg *appear* to be the same
 840       * entity, but Mozilla doesn't seem to want to accept the latter.
 841       * For our purposes, we will treat them the same.
 842       *
 843       * @param   string  $mimetype  The MIME type to check.
 844       *
 845       * @return  boolean  True if the browser can display the MIME type.
 846       *
 847       * @since   1.7.0
 848       */
 849      public function isViewable($mimetype)
 850      {
 851          $mimetype = strtolower($mimetype);
 852          list($type, $subtype) = explode('/', $mimetype);
 853  
 854          if (!empty($this->accept)) {
 855              $wildcard_match = false;
 856  
 857              if (strpos($this->accept, $mimetype) !== false) {
 858                  return true;
 859              }
 860  
 861              if (strpos($this->accept, '*/*') !== false) {
 862                  $wildcard_match = true;
 863  
 864                  if ($type !== 'image') {
 865                      return true;
 866                  }
 867              }
 868  
 869              // Deal with Mozilla pjpeg/jpeg issue
 870              if ($this->isBrowser('mozilla') && ($mimetype === 'image/pjpeg') && (strpos($this->accept, 'image/jpeg') !== false)) {
 871                  return true;
 872              }
 873  
 874              if (!$wildcard_match) {
 875                  return false;
 876              }
 877          }
 878  
 879          if ($type !== 'image') {
 880              return false;
 881          }
 882  
 883          return \in_array($subtype, $this->images);
 884      }
 885  
 886      /**
 887       * Determine if the given browser is the same as the current.
 888       *
 889       * @param   string  $browser  The browser to check.
 890       *
 891       * @return  boolean  Is the given browser the same as the current?
 892       *
 893       * @since   1.7.0
 894       */
 895      public function isBrowser($browser)
 896      {
 897          return $this->browser === $browser;
 898      }
 899  
 900      /**
 901       * Determines if the browser is a robot or not.
 902       *
 903       * @return  boolean  True if browser is a known robot.
 904       *
 905       * @since   1.7.0
 906       */
 907      public function isRobot()
 908      {
 909          foreach ($this->robots as $robot) {
 910              if (preg_match('/' . $robot . '/', $this->agent)) {
 911                  return true;
 912              }
 913          }
 914  
 915          return false;
 916      }
 917  
 918      /**
 919       * Determines if the browser is mobile version or not.
 920       *
 921       * @return boolean  True if browser is a known mobile version.
 922       *
 923       * @since   1.7.0
 924       */
 925      public function isMobile()
 926      {
 927          return $this->mobile;
 928      }
 929  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer