优化后台爬虫与浏览器类型显示

This commit is contained in:
Zhai Yiming 2017-07-13 21:30:01 +08:00
parent 5a6c048195
commit 8362a5d8d3
3 changed files with 23 additions and 6 deletions

View File

@ -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']);

View File

@ -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 = '';
}
}

View File

@ -77,7 +77,7 @@ $access = new Access_Core();
<tr id="<?php echo $log['id']; ?>" data-id="<?php echo $log['id']; ?>">
<td><input type="checkbox" data-id="<?php echo $log['id']; ?>" value="<?php echo $log['id']; ?>" name="id[]"/></td>
<td><a target="_blank" href="<?php echo str_replace("%23", "#", $log['url']); ?>"><?php echo urldecode(str_replace("%23", "#", $log['url'])); ?></a></td>
<td><a data-action="ua" href="#" title="<?php echo $log['ua'];?>"><?php echo $access->ua->getBrowserName() . ' / ' . $access->ua->getBrowserVersion(); ?></a></td>
<td><a data-action="ua" href="#" title="<?php echo $log['ua'];?>"><?php echo $log['display_name']; ?></a></td>
<td><a data-action="ip" data-ip="<?php echo long2ip($log['ip']); ?>" href="#"><?php echo long2ip($log['ip']); ?></a></td>
<td><a target="_blank" data-action="referer" href="<?php echo $log['referer']; ?>"><?php echo $log['referer']; ?></a></td>
<td><?php echo date('Y-m-d H:i:s',$log['time']); ?></td>