From 8362a5d8d332df6d0864ee2d1e82c268ae13f505 Mon Sep 17 00:00:00 2001 From: Zhai Yiming Date: Thu, 13 Jul 2017 21:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=8E=E5=8F=B0=E7=88=AC?= =?UTF-8?q?=E8=99=AB=E4=B8=8E=E6=B5=8F=E8=A7=88=E5=99=A8=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Access_Core.php | 17 +++++++++++++++++ Access_UA.php | 10 +++++----- page/console.php | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Access_Core.php b/Access_Core.php index 51b489a..d3af8c3 100644 --- a/Access_Core.php +++ b/Access_Core.php @@ -84,6 +84,23 @@ class Access_Core break; } $this->logs['list'] = $this->db->fetchAll($query); + foreach ($this->logs['list'] as &$row) { + $ua = new Access_UA($row['ua']); + if ($ua->isRobot()) { + $name = $ua->getRobotID(); + $version = $ua->getRobotVersion(); + } else { + $name = $ua->getBrowserName(); + $version = $ua->getBrowserVersion(); + } + if ($name == '') { + $row['display_name'] = _t('未知'); + } elseif ($version == '') { + $row['display_name'] = $name; + } else { + $row['display_name'] = $name . ' / ' . $version; + } + } $this->htmlEncode($this->logs['list']); diff --git a/Access_UA.php b/Access_UA.php index 9daa84f..051828e 100644 --- a/Access_UA.php +++ b/Access_UA.php @@ -102,14 +102,14 @@ class Access_UA { if ($this->robotID === null) { if (!empty($this->ua)) { - if (preg_match('#([a-zA-Z0-9]+(?:bot|spider))[ /]*([0-9.]*)#i', $this->ua, $matches)) { + if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /]*([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) { $this->robotID = $this->robotName = $val; - $this->robotVersion = $val; + $this->robotVersion = ''; } } } @@ -117,7 +117,7 @@ class Access_UA if ($this->robotName == null) $this->robotName = ''; if ($this->robotVersion == null) $this->robotVersion = ''; } - return $this->robotID !== '' || $this->robotName !== ''; + return $this->robotID !== ''; } /** @@ -189,7 +189,7 @@ class Access_UA $this->osVersion = ''; } else { $this->osID = ''; - $this->osName = '未知'; + $this->osName = ''; $this->osVersion = ''; } } @@ -285,7 +285,7 @@ class Access_UA $this->browserVersion = $matches[2]; } else { $this->browserID = ''; - $this->browserName = '未知'; + $this->browserName = ''; $this->browserVersion = ''; } } diff --git a/page/console.php b/page/console.php index 8afc7b1..b6cf490 100644 --- a/page/console.php +++ b/page/console.php @@ -77,7 +77,7 @@ $access = new Access_Core(); "> - ua->getBrowserName() . ' / ' . $access->ua->getBrowserVersion(); ?> +