fix Passing null to parameter

This commit is contained in:
Gitea 2022-06-29 11:22:06 +08:00
parent dfc5eafc60
commit 2eb71c484d

View File

@ -77,8 +77,8 @@ class Access_UA {
private $browserVersion = null;
function __construct($ua) {
$this->ua = $ua;
$this->ual = $this->filter($ua);
$this->ua ?: "" = $ua;
$this->ua ?: ""l = $this->filter($ua);
}
public static function filter($str) {
@ -96,7 +96,7 @@ class Access_UA {
* @return string
*/
public function getUA() {
return $this->ua;
return $this->ua ?: "";
}
/**
@ -107,13 +107,13 @@ class Access_UA {
*/
public function isRobot() {
if ($this->robotID === null) {
if (!empty($this->ua)) {
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /v]*([0-9.]*)#i', $this->ua, $matches)) {
if (!empty($this->ua ?: "")) {
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /v]*([0-9.]*)#i', $this->ua ?: "", $matches)) {
$this->robotID = $this->robotName = $matches[1];
$this->robotVersion = $matches[2];
}
foreach (self::$robots as $val) {
if (strpos($this->ual, $this->filter($val)) !== false) {
if (strpos($this->ua ?: ""l, $this->filter($val)) !== false) {
$this->robotID = $this->robotName = $val;
}
}
@ -153,56 +153,56 @@ class Access_UA {
*/
private function parseOS() {
if ($this->osID === null) {
if (preg_match('/Windows NT 6.0/i', $this->ua)) {
if (preg_match('/Windows NT 6.0/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = 'Vista';
} elseif (preg_match('/Windows NT 6.1/i', $this->ua)) {
} elseif (preg_match('/Windows NT 6.1/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = '7';
} elseif (preg_match('/Windows NT 6.2/i', $this->ua)) {
} elseif (preg_match('/Windows NT 6.2/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = '8';
} elseif (preg_match('/Windows NT 6.3/i', $this->ua)) {
} elseif (preg_match('/Windows NT 6.3/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = '8.1';
} elseif (preg_match('/Windows NT 10.0/i', $this->ua)) {
} elseif (preg_match('/Windows NT 10.0/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = '10';
} elseif (preg_match('/Windows NT 5.0/i', $this->ua)) {
} elseif (preg_match('/Windows NT 5.0/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = '2000';
} elseif (preg_match('/Windows NT 5.1/i', $this->ua)) {
} elseif (preg_match('/Windows NT 5.1/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
$this->osVersion = 'XP';
} elseif (preg_match('/Windows NT 5.2/i', $this->ua)) {
} elseif (preg_match('/Windows NT 5.2/i', $this->ua ?: "")) {
$this->osID = $this->osName = 'Windows';
if (preg_match('/Win64/i', $this->ua)) {
if (preg_match('/Win64/i', $this->ua ?: "")) {
$this->osVersion = 'XP (64 bit)';
} else {
$this->osVersion = '2003';
}
} elseif (preg_match('/Android ([0-9.]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/Android ([0-9.]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Android';
$this->osVersion = $matches[1];
} elseif (preg_match('/iPhone OS ([_0-9]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/iPhone OS ([_0-9]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'iPhone OS';
$this->osVersion = str_replace('_', '.', $matches[1]);
} elseif (preg_match('/iPad; CPU OS ([_0-9]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/iPad; CPU OS ([_0-9]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'iPad OS';
$this->osVersion = str_replace('_', '.', $matches[1]);
} elseif (preg_match('/Mac OS X ([0-9_]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/Mac OS X ([0-9_]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Mac OS X';
$this->osVersion = str_replace('_', '.', $matches[1]);
} elseif (preg_match('/Linux/i', $this->ua, $matches)) {
} elseif (preg_match('/Linux/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Linux';
$this->osVersion = '';
} elseif (preg_match('/Ubuntu/i', $this->ua, $matches)) {
} elseif (preg_match('/Ubuntu/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Ubuntu';
$this->osVersion = '';
} elseif (preg_match('/CrOS i686 ([a-zA-Z0-9.]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/CrOS i686 ([a-zA-Z0-9.]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Chrome OS';
$this->osVersion = 'i686 ' . substr($matches[1], 0, 4);
} elseif (preg_match('/CrOS x86_64 ([a-zA-Z0-9.]+)/i', $this->ua, $matches)) {
} elseif (preg_match('/CrOS x86_64 ([a-zA-Z0-9.]+)/i', $this->ua ?: "", $matches)) {
$this->osID = $this->osName = 'Chrome OS';
$this->osVersion = 'x86_64 ' . substr($matches[1], 0, 4);
} else {
@ -252,66 +252,66 @@ class Access_UA {
*/
private function parseBrowser() {
if ($this->browserName === null) {
if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'Camino';
$this->browserName = 'Camino';
$this->browserVersion = $matches[2];
} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'SE 2';
$this->browserName = '搜狗浏览器 2';
$this->browserVersion = $matches[1];
} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = '360';
$this->browserName = '360浏览器';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Maxthon';
$this->browserVersion = $matches[2];
} elseif (preg_match('#Edg/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Edg/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Edge';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Chrome';
$this->browserVersion = $matches[1];
} elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = '小米浏览器';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Safari';
$this->browserVersion = $matches[1];
} elseif (preg_match('#opera mini#i', $this->ua)) {
preg_match('#Opera/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "");
} elseif (preg_match('#opera mini#i', $this->ua ?: "")) {
preg_match('#Opera/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches);
$this->browserID = $this->browserName = 'Opera Mini';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Opera';
$this->browserVersion = $matches[1];
} elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'TencentTraveler';
$this->browserName = '腾讯TT浏览器';
$this->browserVersion = $matches[1];
} elseif (preg_match('#QQ/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#QQ/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'QQ';
$this->browserName = '手机QQ';
$this->browserVersion = $matches[1];
} elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'UCWEB';
$this->browserVersion = $matches[1];
} elseif (preg_match('#UCBrowser/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#UCBrowser/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'UCBrowser';
$this->browserName = 'UC浏览器';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Quark/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Quark/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = 'Quark';
$this->browserName = 'Quark浏览器';
$this->browserVersion = $matches[1];
} elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Internet Explorer';
$this->browserVersion = $matches[1];
} elseif (preg_match('#Trident#', $this->ua, $matches ?: "")) {
} elseif (preg_match('#Trident#', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Internet Explorer';
$this->browserVersion = '11';
} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $this->ua, $matches ?: "")) {
} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $this->ua ?: "", $matches)) {
$this->browserID = $this->browserName = 'Firefox';
$this->browserVersion = $matches[2];
} else {