From: joshuaruesweg Date: Tue, 27 Oct 2020 18:01:48 +0000 (+0100) Subject: Add UserUtil::getBrowser() method X-Git-Tag: 5.4.0_Alpha_1~656^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8e515d6c21101872cd0a645155cfa25e6a3ea5e2;p=GitHub%2FWoltLab%2FWCF.git Add UserUtil::getBrowser() method --- diff --git a/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php b/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php index bc36c76f0e..e69426859d 100644 --- a/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php +++ b/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php @@ -134,172 +134,7 @@ class UserOnline extends UserProfile { return $parameters['browser']; } - // lunascape - if (preg_match('~lunascape[ /]([\d\.]+)~i', $this->userAgent, $match)) { - return 'Lunascape '.$match[1]; - } - - // sleipnir - if (preg_match('~sleipnir/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Sleipnir '.$match[1]; - } - - // uc browser - if (preg_match('~(?:ucbrowser|uc browser|ucweb)[ /]?([\d\.]+)~i', $this->userAgent, $match)) { - return 'UC Browser '.$match[1]; - } - - // baidu browser - if (preg_match('~(?:baidubrowser|flyflow)[ /]?([\d\.x]+)~i', $this->userAgent, $match)) { - return 'Baidubrowser '.$match[1]; - } - - // blackberry - if (preg_match('~blackberry.*version/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Blackberry '.$match[1]; - } - - // opera mobile - if (preg_match('~opera/([\d\.]+).*(mobi|mini)~i', $this->userAgent, $match)) { - return 'Opera Mobile '.$match[1]; - } - - // opera - if (preg_match('~opera.*version/([\d\.]+)|opr/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Opera '.(isset($match[2]) ? $match[2] : $match[1]); - } - - // thunderbird - if (preg_match('~thunderbird/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Thunderbird '.$match[1]; - } - - // icedragon - if (preg_match('~icedragon/([\d\.]+)~i', $this->userAgent, $match)) { - return 'IceDragon '.$match[1]; - } - - // palemoon - if (preg_match('~palemoon/([\d\.]+)~i', $this->userAgent, $match)) { - return 'PaleMoon '.$match[1]; - } - - // flock - if (preg_match('~flock/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Flock '.$match[1]; - } - - // iceweasel - if (preg_match('~iceweasel/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Iceweasel '.$match[1]; - } - - // firefox mobile - if (preg_match('~(?:mobile.*firefox|fxios)/([\d\.]+)|fennec/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Firefox Mobile '.(isset($match[2]) ? $match[2] : $match[1]); - } - - // tapatalk 4 - if (preg_match('~tapatalk/([\d\.]+)?~i', $this->userAgent, $match)) { - return 'Tapatalk '.(isset($match[1]) ? $match[1] : 4); - } - - // firefox - if (preg_match('~firefox/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Firefox '.$match[1]; - } - - // maxthon - if (preg_match('~maxthon[ /]([\d\.]+)~i', $this->userAgent, $match)) { - return 'Maxthon '.$match[1]; - } - - // iemobile - if (preg_match('~iemobile[ /]([\d\.]+)|MSIE ([\d\.]+).*XBLWP7~i', $this->userAgent, $match)) { - return 'Internet Explorer Mobile '.(isset($match[2]) ? $match[2] : $match[1]); - } - - // ie - if (preg_match('~msie ([\d\.]+)|Trident\/\d{1,2}.\d{1,2}; .*rv:([0-9]*)~i', $this->userAgent, $match)) { - return 'Internet Explorer '.(isset($match[2]) ? $match[2] : $match[1]); - } - - // edge - if (preg_match('~edge?/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Microsoft Edge '.$match[1]; - } - - // edge mobile - if (preg_match('~edga/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Microsoft Edge Mobile '.$match[1]; - } - - // vivaldi - if (preg_match('~vivaldi/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Vivaldi '.$match[1]; - } - - // iron - if (preg_match('~iron/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Iron '.$match[1]; - } - - // coowon - if (preg_match('~coowon/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Coowon '.$match[1]; - } - - // coolnovo - if (preg_match('~(?:coolnovo|chromeplus)/([\d\.]+)~i', $this->userAgent, $match)) { - return 'CoolNovo '.$match[1]; - } - - // yandex - if (preg_match('~yabrowser/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Yandex '.$match[1]; - } - - // midori - if (preg_match('~midori/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Midori '.$match[1]; - } - - // chrome mobile - if (preg_match('~(?:crios|crmo)/([\d\.]+)|chrome/([\d\.]+).*mobile~i', $this->userAgent, $match)) { - return 'Chrome Mobile '.(isset($match[2]) ? $match[2] : $match[1]); - } - - // kindle - if (preg_match('~kindle/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Kindle '.$match[1]; - } - - // silk - if (preg_match('~silk/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Silk '.$match[1]; - } - - // android browser - if (preg_match('~Android ([\d\.]+).*AppleWebKit~i', $this->userAgent, $match)) { - return 'Android Browser '.$match[1]; - } - - // safari mobile - if (preg_match('~([\d\.]+) Mobile/\w+ safari~i', $this->userAgent, $match)) { - return 'Safari Mobile '.$match[1]; - } - - // chrome - if (preg_match('~(?:chromium|chrome)/([\d\.]+)~i', $this->userAgent, $match)) { - return 'Chrome '.$match[1]; - } - - // safari - if (preg_match('~([\d\.]+) safari~i', $this->userAgent, $match)) { - return 'Safari '.$match[1]; - } - - return $this->userAgent; + return UserUtil::getBrowser($this->userAgent); } /** diff --git a/wcfsetup/install/files/lib/util/UserUtil.class.php b/wcfsetup/install/files/lib/util/UserUtil.class.php index 0c3fe77227..f2d96ca1b0 100644 --- a/wcfsetup/install/files/lib/util/UserUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserUtil.class.php @@ -1,5 +1,6 @@ '', 'userAgent' => $userAgent]; + EventHandler::getInstance()->fireAction(self::class, 'getBrowser', $parameters); + if (!empty($parameters['browser'])) { + return $parameters['browser']; + } + + // lunascape + if (preg_match('~lunascape[ /]([\d\.]+)~i', $userAgent, $match)) { + return 'Lunascape '.$match[1]; + } + + // sleipnir + if (preg_match('~sleipnir/([\d\.]+)~i', $userAgent, $match)) { + return 'Sleipnir '.$match[1]; + } + + // uc browser + if (preg_match('~(?:ucbrowser|uc browser|ucweb)[ /]?([\d\.]+)~i', $userAgent, $match)) { + return 'UC Browser '.$match[1]; + } + + // baidu browser + if (preg_match('~(?:baidubrowser|flyflow)[ /]?([\d\.x]+)~i', $userAgent, $match)) { + return 'Baidubrowser '.$match[1]; + } + + // blackberry + if (preg_match('~blackberry.*version/([\d\.]+)~i', $userAgent, $match)) { + return 'Blackberry '.$match[1]; + } + + // opera mobile + if (preg_match('~opera/([\d\.]+).*(mobi|mini)~i', $userAgent, $match)) { + return 'Opera Mobile '.$match[1]; + } + + // opera + if (preg_match('~opera.*version/([\d\.]+)|opr/([\d\.]+)~i', $userAgent, $match)) { + return 'Opera '.(isset($match[2]) ? $match[2] : $match[1]); + } + + // thunderbird + if (preg_match('~thunderbird/([\d\.]+)~i', $userAgent, $match)) { + return 'Thunderbird '.$match[1]; + } + + // icedragon + if (preg_match('~icedragon/([\d\.]+)~i', $userAgent, $match)) { + return 'IceDragon '.$match[1]; + } + + // palemoon + if (preg_match('~palemoon/([\d\.]+)~i', $userAgent, $match)) { + return 'PaleMoon '.$match[1]; + } + + // flock + if (preg_match('~flock/([\d\.]+)~i', $userAgent, $match)) { + return 'Flock '.$match[1]; + } + + // iceweasel + if (preg_match('~iceweasel/([\d\.]+)~i', $userAgent, $match)) { + return 'Iceweasel '.$match[1]; + } + + // firefox mobile + if (preg_match('~(?:mobile.*firefox|fxios)/([\d\.]+)|fennec/([\d\.]+)~i', $userAgent, $match)) { + return 'Firefox Mobile '.(isset($match[2]) ? $match[2] : $match[1]); + } + + // tapatalk 4 + if (preg_match('~tapatalk/([\d\.]+)?~i', $userAgent, $match)) { + return 'Tapatalk '.(isset($match[1]) ? $match[1] : 4); + } + + // firefox + if (preg_match('~firefox/([\d\.]+)~i', $userAgent, $match)) { + return 'Firefox '.$match[1]; + } + + // maxthon + if (preg_match('~maxthon[ /]([\d\.]+)~i', $userAgent, $match)) { + return 'Maxthon '.$match[1]; + } + + // iemobile + if (preg_match('~iemobile[ /]([\d\.]+)|MSIE ([\d\.]+).*XBLWP7~i', $userAgent, $match)) { + return 'Internet Explorer Mobile '.(isset($match[2]) ? $match[2] : $match[1]); + } + + // ie + if (preg_match('~msie ([\d\.]+)|Trident\/\d{1,2}.\d{1,2}; .*rv:([0-9]*)~i', $userAgent, $match)) { + return 'Internet Explorer '.(isset($match[2]) ? $match[2] : $match[1]); + } + + // edge + if (preg_match('~edge?/([\d\.]+)~i', $userAgent, $match)) { + return 'Microsoft Edge '.$match[1]; + } + + // edge mobile + if (preg_match('~edga/([\d\.]+)~i', $userAgent, $match)) { + return 'Microsoft Edge Mobile '.$match[1]; + } + + // vivaldi + if (preg_match('~vivaldi/([\d\.]+)~i', $userAgent, $match)) { + return 'Vivaldi '.$match[1]; + } + + // iron + if (preg_match('~iron/([\d\.]+)~i', $userAgent, $match)) { + return 'Iron '.$match[1]; + } + + // coowon + if (preg_match('~coowon/([\d\.]+)~i', $userAgent, $match)) { + return 'Coowon '.$match[1]; + } + + // coolnovo + if (preg_match('~(?:coolnovo|chromeplus)/([\d\.]+)~i', $userAgent, $match)) { + return 'CoolNovo '.$match[1]; + } + + // yandex + if (preg_match('~yabrowser/([\d\.]+)~i', $userAgent, $match)) { + return 'Yandex '.$match[1]; + } + + // midori + if (preg_match('~midori/([\d\.]+)~i', $userAgent, $match)) { + return 'Midori '.$match[1]; + } + + // chrome mobile + if (preg_match('~(?:crios|crmo)/([\d\.]+)|chrome/([\d\.]+).*mobile~i', $userAgent, $match)) { + return 'Chrome Mobile '.(isset($match[2]) ? $match[2] : $match[1]); + } + + // kindle + if (preg_match('~kindle/([\d\.]+)~i', $userAgent, $match)) { + return 'Kindle '.$match[1]; + } + + // silk + if (preg_match('~silk/([\d\.]+)~i', $userAgent, $match)) { + return 'Silk '.$match[1]; + } + + // android browser + if (preg_match('~Android ([\d\.]+).*AppleWebKit~i', $userAgent, $match)) { + return 'Android Browser '.$match[1]; + } + + // safari mobile + if (preg_match('~([\d\.]+) Mobile/\w+ safari~i', $userAgent, $match)) { + return 'Safari Mobile '.$match[1]; + } + + // chrome + if (preg_match('~(?:chromium|chrome)/([\d\.]+)~i', $userAgent, $match)) { + return 'Chrome '.$match[1]; + } + + // safari + if (preg_match('~([\d\.]+) safari~i', $userAgent, $match)) { + return 'Safari '.$match[1]; + } + + return $userAgent; + } + /** * Returns the ipv6 address of the client. *