<?php
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is KaiRo's userAgent detection.
- *
- * The Initial Developer of the Original Code is
- * KaiRo - Robert Kaiser.
- * Portions created by the Initial Developer are Copyright (C) 2003-2007
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s): Robert Kaiser <kairo@kairo.at>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
class userAgent {
// userAgent PHP class
private $version;
private $bot = false;
private $mobile = false;
- private $uadata = array();
+ private $uadata = [];
function __construct($ua_string = '') {
// *** constructor ***
$this->bot = false;
}
- $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
- 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
- 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
- 'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
- 'FavOrg','findlinks','DataCha0s','ichiro','Francis','CoralWebPrx','DoCoMo','Ocelli','Sogou Video',
- 'Yandex','Yeti','Austronaut-URL-Checker');
+ $botArray = [
+ 'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL',
+ 'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver',
+ 'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch',
+ 'appie', 'larbin', 'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com',
+ 'FavOrg', 'findlinks', 'DataCha0s', 'ichiro', 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video',
+ 'Yandex', 'Yeti', 'Austronaut-URL-Checker'
+ ];
if (in_array($this->brand, $botArray)) {
$this->bot = true;
}
}
- public function getBrand() { return $this->brand; }
- public function getVersion() { return $this->version; }
+ public function getBrand() {
+ return $this->brand;
+ }
+
+ public function getVersion() {
+ return $this->version;
+ }
public function getAcceptLanguages() {
if (!isset($this->uadata['accept-languages'])) {
$headers = getAllHeaders();
- $accLcomp = explode(',', $headers['Accept-Language']);
- $accLang = array();
+ $accLcomp = explode(',', ($headers['Accept-Language'] ?? ''));
+ $accLang = [];
foreach ($accLcomp as $lcomp) {
if (strlen($lcomp)) {
$ldef = explode(';', $lcomp);
- $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
+ if (count($ldef) > 1 && strpos($ldef[1], 'q=') === 0) {
+ $accLang[$ldef[0]] = substr($ldef[1], 2);
+ }
+ else {
+ $accLang[$ldef[0]] = 1;
+ }
}
}
$this->uadata['accept-languages'] = $accLang;
}
- return $this->uadata['accept-languages'];
+ return $this->uadata['accept-languages'];
}
- public function getUAString() { return $this->uastring; }
+ public function getUAString() {
+ return $this->uastring;
+ }
public function getEngine() {
// return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
}
}
}
- return $this->uadata['engine'];
+ return $this->uadata['engine'];
}
- public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
+ public function hasEngine($rnd_engine) {
+ return ($this->getEngine() == $rnd_engine);
+ }
public function getEngineVersion() {
if (!isset($this->uadata['eng_version'])) {
// getOS() should get the date for us
$this->getOS();
}
- return $this->uadata['eng_version'];
+ return $this->uadata['eng_version'];
}
public function getOS() {
$this->uadata['lang'] = null;
$this->uadata['eng_version'] = null;
}
+ if (($this->brand == 'Firefox') && (intval($this->version) >= 110)) {
+ $this->uadata['eng_version'] = $this->version;
+ }
}
elseif ($this->hasEngine('edgehtml')) {
if (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Win64); ([^\);]+)\)#', $this->uastring, $regs)) {
elseif (preg_match('/iPhone OS ([\d_]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
elseif (preg_match('/Mac ?OS ?X/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
elseif (preg_match('/Mac_P(ower|)PC/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
- elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
- elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
- elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
- elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; }
elseif (preg_match('/Android \(Linux (.+)\)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
- elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; }
elseif (preg_match('/Symbian ?OS/i', $this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
- if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
- elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
- elseif (strpos($this->uadata['os'], 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
- elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
- elseif (strpos($this->uadata['os'], 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
- elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
- elseif (strpos($this->uadata['os'], 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
- elseif (strpos($this->uadata['os'], 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
- elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
- elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
- elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
- elseif (strpos($this->uadata['os'], 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
- elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
- elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
- elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
- elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
- elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
- elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
- elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
- elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
- elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
- elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
- elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
- elseif (strpos($this->uadata['os'], 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
- elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
- elseif (strpos($this->uadata['os'], 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
- elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
- elseif (strpos($this->uadata['os'], 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
- elseif (strpos($this->uadata['os'], 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
- elseif (strpos($this->uadata['os'], 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
- elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
- elseif (strpos($this->uadata['os'], 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
+ if (strpos($this->uadata['os'] ?? '', 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
+ elseif (strpos($this->uadata['os'] ?? '', 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
else { $this->uadata['platform'] = $this->uadata['os']; }
- if (strpos($this->uadata['os'], 'Windows Phone OS') !== false) { $this->mobile = true; }
- elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->mobile = true; }
+ if (strpos($this->uadata['os'] ?? '', 'Windows Phone OS') !== false) { $this->mobile = true; }
+ elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->mobile = true; }
- $this->uadata['lang'] = str_replace('_', '-', @$this->uadata['lang']);
+ $this->uadata['lang'] = str_replace('_', '-', ($this->uadata['lang'] ?? ''));
}
}
- return $this->uadata['os'];
+ return $this->uadata['os'];
}
public function getPlatform() {
// getOS() should get the date for us
$this->getOS();
}
- return $this->uadata['platform'];
+ return $this->uadata['platform'];
}
public function getLanguage() {
// getOS() should get the date for us
$this->getOS();
}
- return $this->uadata['lang'];
+ return $this->uadata['lang'];
}
public function getGeckoDate() {
// getEngine() should get the date for us
$this->getEngine();
}
- return $this->uadata['geckodate'];
+ return $this->uadata['geckodate'];
}
public function getGeckoTime() {
if ($use_time) { date_default_timezone_set($old_tz); }
}
}
- return $this->uadata['geckotime'];
+ return $this->uadata['geckotime'];
}
- public function isBot() { return $this->bot; }
+ public function isBot() {
+ return $this->bot;
+ }
public function isMobile() {
if (!isset($this->uadata['os'])) {