diff --git a/Access_Bootstrap.php b/Access_Bootstrap.php
new file mode 100644
index 0000000..55795dd
--- /dev/null
+++ b/Access_Bootstrap.php
@@ -0,0 +1,17 @@
+pageSize == null || $this->isDrop == null) {
throw new Typecho_Plugin_Exception('请先设置插件!');
}
+ $this->parser = new Access_Parser();
switch ($this->request->get('action')) {
case 'logs':
default:
@@ -42,146 +48,11 @@ class Access_Extend
}
}
- public $spiderArray = array(
- "TencentTraveler",
- "Baiduspider",
- "BaiduGame",
- "Googlebot",
- "msnbot",
- "Sosospider+",
- "Sogou web spider",
- "ia_archiver",
- "Yahoo! Slurp",
- "YoudaoBot",
- "Yahoo Slurp",
- "MSNBot",
- "Java (Often spam bot)",
- "BaiDuSpider",
- "Voila",
- "Yandex bot",
- "BSpider",
- "twiceler",
- "Sogou Spider",
- "Speedy Spider",
- "Google AdSense",
- "Heritrix",
- "Python-urllib",
- "Alexa (IA Archiver)",
- "Ask",
- "Exabot",
- "Custo",
- "OutfoxBot/YodaoBot",
- "yacy",
- "SurveyBot",
- "legs",
- "lwp-trivial",
- "Nutch",
- "StackRambler",
- "The web archive (IA Archiver)",
- "Perl tool",
- "MJ12bot",
- "Netcraft",
- "MSIECrawler",
- "WGet tools",
- "larbin",
- "Fish search",
- "crawler",
- "bingbot",
- );
-
- public function parseUA($ua)
- {
- $os = null;
- if ($this->isSpider($ua)) {
- $os = '爬虫';
- } elseif (preg_match('/Windows NT 6.0/i', $ua)) {
- $os = "Windows Vista";
- } elseif (preg_match('/Windows NT 6.1/i', $ua)) {
- $os = "Windows 7";
- } elseif (preg_match('/Windows NT 6.2/i', $ua)) {
- $os = "Windows 8";
- } elseif (preg_match('/Windows NT 6.3/i', $ua)) {
- $os = "Windows 8.1";
- } elseif (preg_match('/Windows NT 10.0/i', $ua)) {
- $os = "Windows 10";
- } elseif (preg_match('/Windows NT 5.1/i', $ua)) {
- $os = "Windows XP";
- } elseif (preg_match('/Windows NT 5.2/i', $ua) && preg_match('/Win64/i', $ua)) {
- $os = "Windows XP 64 bit";
- } elseif (preg_match('/Android ([0-9.]+)/i', $ua, $matches)) {
- $os = "Android " . $matches[1];
- } elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) {
- $os = 'iPhone ' . $matches[1];
- } elseif (preg_match('/Ubuntu/i', $ua, $matches)) {
- $os = 'Ubuntu ';
- } elseif (preg_match('/Mac OS X ([0-9_]+)/i', $ua, $matches)) {
- $os = 'Mac OS X ' . $matches[1];
- } elseif (preg_match('/Linux/i', $ua, $matches)) {
- $os = 'Linux';
- } else {
- $os = '未知';
- }
-
- if ($this->isSpider($ua)) {
- $browser = '爬虫';
- } elseif (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Camino ' . $matches[2];
- } elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = '搜狗浏览器 2' . $matches[1];
- } elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = '360浏览器 ' . $matches[1];
- } elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Maxthon ' . $matches[2];
- } elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Chrome ' . $matches[1];
- } elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $ua, $matches)) {
- $browser = '小米浏览器 ' . $matches[1];
- } elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Safari ' . $matches[1];
- } elseif (preg_match('#opera mini#i', $ua)) {
- preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches);
- $browser = 'Opera Mini ' . $matches[1];
- } elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Opera ' . $matches[1];
- } elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = '腾讯TT浏览器 ' . $matches[1];
- } elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'UCWEB ' . $matches[1];
- } elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Internet Explorer ' . $matches[1];
- } elseif (preg_match('#Trident#', $ua, $matches)) {
- $browser = 'Internet Explorer 11';
- } elseif (preg_match('#Edge/12.0#i', $ua, $matches)) {
- //win10中spartan浏览器
- $browser = 'Spartan';
- } elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
- $browser = 'Firefox ' . $matches[2];
- } else {
- $browser = '未知';
- }
- return $os . " / " . $browser;
- }
-
- public function isSpider($ua)
- {
- $ua = strtolower($ua);
- if (!empty($ua)) {
- foreach ($this->spiderArray as $val) {
- $str = strtolower($val);
- if (strpos($ua, $str) !== false) {
- return true;
- }
- }
- } else {
- return false;
- }
- }
-
protected function getWhere($type)
{
$where_str = '';
- foreach ($this->spiderArray as $value) {
- $where_str .= "ua {1} LIKE " . "'%{$value}%' {2} ";
+ foreach ($this->parser->bots as $value) {
+ $where_str .= "replace(LOWER(`ua`), ' ', '') {1} LIKE " . "'%{$this->parser->filter($value)}%' {2} ";
}
$where_str = rtrim($where_str, '{2} ');
switch ($type) {
@@ -212,9 +83,13 @@ class Access_Extend
$this->logs['list'] = $this->db->fetchAll("SELECT * FROM {$this->table} {$where} ORDER BY id DESC LIMIT {$this->pageSize} OFFSET {$offset}");
$this->logs['rows'] = count($this->db->fetchAll("SELECT * FROM {$this->table} {$where}"));
- include_once dirname(__FILE__) . '/lib/Page.php';
- $pager = new Page($this->pageSize, $this->logs['rows'], $p, 10);
- $this->logs['page'] = $pager->show();
+
+ $page = new Access_Page($this->pageSize, $this->logs['rows'], $p, 10, array(
+ 'panel' => Access_Plugin::$panel,
+ 'action' => 'logs',
+ 'type' => $type,
+ ));
+ $this->logs['page'] = $page->show();
}
protected function parseReferer()
@@ -273,7 +148,7 @@ class Access_Extend
protected function buildObject($array, $quote)
{
- $obj = json_encode($array);
+ $obj = Json::encode($array);
$obj = str_replace("\"", "'", $obj);
if ($quote) {
return $obj;
diff --git a/lib/Page.php b/Access_Page.php
similarity index 67%
rename from lib/Page.php
rename to Access_Page.php
index 42efd58..e5cad88 100644
--- a/lib/Page.php
+++ b/Access_Page.php
@@ -1,5 +1,9 @@
each_disNums = intval($each_disNums);
$this->nums = intval($nums);
- if (!$current_page)
- {
+ if (!$current_page) {
$this->current_page = 1;
- }
- else
- {
+ } else {
$this->current_page = intval($current_page);
}
$this->sub_pages = intval($sub_pages);
$this->pageNums = ceil($nums / $each_disNums);
+ $this->otherParams = $otherParams;
}
- /*
- __destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
- */
- public function __destruct()
- {
- unset($each_disNums);
- unset($nums);
- unset($current_page);
- unset($sub_pages);
- unset($pageNums);
- unset($page_array);
- }
/*
用来给建立分页的数组初始化的函数。
*/
public function initArray()
{
- for ($i = 0; $i < $this->sub_pages; $i++)
- {
+ for ($i = 0; $i < $this->sub_pages; $i++) {
$this->page_array[$i] = $i;
}
return $this->page_array;
@@ -67,35 +57,23 @@ class Page
*/
public function construct_num_Page()
{
- if ($this->pageNums < $this->sub_pages)
- {
+ if ($this->pageNums < $this->sub_pages) {
$current_array = array();
- for ($i = 0; $i < $this->pageNums; $i++)
- {
+ for ($i = 0; $i < $this->pageNums; $i++) {
$current_array[$i] = $i + 1;
}
- }
- else
- {
+ } else {
$current_array = $this->initArray();
- if ($this->current_page <= 3)
- {
- for ($i = 0; $i < count($current_array); $i++)
- {
+ if ($this->current_page <= 3) {
+ for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = $i + 1;
}
- }
- elseif ($this->current_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1)
- {
- for ($i = 0; $i < count($current_array); $i++)
- {
+ } elseif ($this->current_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1) {
+ for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = ($this->pageNums) - ($this->sub_pages) + 1 + $i;
}
- }
- else
- {
- for ($i = 0; $i < count($current_array); $i++)
- {
+ } else {
+ for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = $this->current_page - 2 + $i;
}
}
@@ -109,40 +87,30 @@ class Page
public function show()
{
$str = "";
- if ($this->current_page > 1)
- {
+ if ($this->current_page > 1) {
$firstPageUrl = $this->buildUrl(1);
$prevPageUrl = $this->buildUrl($this->current_page - 1);
$str .= '
«';
- }
- else
- {
+ } else {
$str .= '';
}
$a = $this->construct_num_Page();
- for ($i = 0; $i < count($a); $i++)
- {
+ for ($i = 0; $i < count($a); $i++) {
$s = $a[$i];
- if ($s == $this->current_page)
- {
+ if ($s == $this->current_page) {
$url = Typecho_Request::getInstance()->getRequestUrl();
$str .= '' . $s . '';
- }
- else
- {
+ } else {
$url = $this->buildUrl($s);
$str .= '' . $s . '';
}
}
- if ($this->current_page < $this->pageNums)
- {
+ if ($this->current_page < $this->pageNums) {
$lastPageUrl = $this->buildUrl($this->pageNums);
$nextPageUrl = $this->buildUrl($this->current_page + 1);
$str .= '»';
- }
- else
- {
+ } else {
$str .= '';
}
return $str;
@@ -150,7 +118,11 @@ class Page
private function buildUrl($page)
{
- $url = Typecho_Common::url('extending.php?' . http_build_query(array('panel' => Access_Plugin::$panel, 'action' => 'logs', 'page' => $page)), Typecho_Widget::widget('Widget_Options')->adminUrl);
+ $url = Typecho_Common::url('extending.php?' . http_build_query(array_merge($this->otherParams,
+ array(
+ 'page' => $page,
+ ))),
+ Typecho_Widget::widget('Widget_Options')->adminUrl);
return $url;
}
diff --git a/Access_Parser.php b/Access_Parser.php
new file mode 100644
index 0000000..6c4d89c
--- /dev/null
+++ b/Access_Parser.php
@@ -0,0 +1,155 @@
+isBot($ua)) {
+ return $this->currentBot;
+ } elseif (preg_match('/Windows NT 6.0/i', $ua)) {
+ $os = 'Windows Vista';
+ } elseif (preg_match('/Windows NT 6.1/i', $ua)) {
+ $os = 'Windows 7';
+ } elseif (preg_match('/Windows NT 6.2/i', $ua)) {
+ $os = 'Windows 8';
+ } elseif (preg_match('/Windows NT 6.3/i', $ua)) {
+ $os = 'Windows 8.1';
+ } elseif (preg_match('/Windows NT 10.0/i', $ua)) {
+ $os = 'Windows 10';
+ } elseif (preg_match('/Windows NT 5.1/i', $ua)) {
+ $os = 'Windows XP';
+ } elseif (preg_match('/Windows NT 5.2/i', $ua) && preg_match('/Win64/i', $ua)) {
+ $os = 'Windows XP 64 bit';
+ } elseif (preg_match('/Android ([0-9.]+)/i', $ua, $matches)) {
+ $os = 'Android ' . $matches[1];
+ } elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) {
+ $os = 'iPhone ' . $matches[1];
+ } elseif (preg_match('/Ubuntu/i', $ua, $matches)) {
+ $os = 'Ubuntu ';
+ } elseif (preg_match('/Mac OS X ([0-9_]+)/i', $ua, $matches)) {
+ $os = 'Mac OS X ' . $matches[1];
+ } elseif (preg_match('/Linux/i', $ua, $matches)) {
+ $os = 'Linux';
+ } else {
+ $os = '未知';
+ }
+
+ if ($this->isBot($ua)) {
+ return $this->currentBot;
+ } elseif (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Camino ' . $matches[2];
+ } elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = '搜狗浏览器 2' . $matches[1];
+ } elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = '360浏览器 ' . $matches[1];
+ } elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Maxthon ' . $matches[2];
+ } elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Chrome ' . $matches[1];
+ } elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $ua, $matches)) {
+ $browser = '小米浏览器 ' . $matches[1];
+ } elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Safari ' . $matches[1];
+ } elseif (preg_match('#opera mini#i', $ua)) {
+ preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches);
+ $browser = 'Opera Mini ' . $matches[1];
+ } elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Opera ' . $matches[1];
+ } elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = '腾讯TT浏览器 ' . $matches[1];
+ } elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'UCWEB ' . $matches[1];
+ } elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Internet Explorer ' . $matches[1];
+ } elseif (preg_match('#Trident#', $ua, $matches)) {
+ $browser = 'Internet Explorer 11';
+ } elseif (preg_match('#Edge/12.0#i', $ua, $matches)) {
+ //win10中spartan浏览器
+ $browser = 'Spartan';
+ } elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
+ $browser = 'Firefox ' . $matches[2];
+ } else {
+ $browser = '未知';
+ }
+ return $os . ' / ' . $browser;
+ }
+
+ public function isBot($ua)
+ {
+ $ua = $this->filter($ua);
+ if (!empty($ua)) {
+ foreach ($this->bots as $val) {
+ $str = $this->filter($val);
+ if (strpos($ua, $str) !== false) {
+ $this->currentBot = $str;
+ return true;
+ }
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function filter($str)
+ {
+ return $this->removeSpace(strtolower($str));
+ }
+
+ protected function removeSpace($str)
+ {
+ return preg_replace('/\s+/', '', $str);
+ }
+}
diff --git a/Plugin.php b/Plugin.php
index 78b0335..06b7c60 100644
--- a/Plugin.php
+++ b/Plugin.php
@@ -4,7 +4,7 @@
*
* @package Access
* @author Kokororin
- * @version 1.4
+ * @version 1.5
* @link https://kotori.love
*/
class Access_Plugin implements Typecho_Plugin_Interface
@@ -16,7 +16,7 @@ class Access_Plugin implements Typecho_Plugin_Interface
Helper::addPanel(1, self::$panel, 'Access控制台', 'Access插件控制台', 'subscriber');
Helper::addRoute("access_ip", "/access/ip.json", "Access_Action", 'ip');
Helper::addRoute("access_delete_logs", "/access/log/delete", "Access_Action", 'deleteLogs');
- Typecho_Plugin::factory('Widget_Archive')->header = array('Access_Plugin', 'start');
+ Typecho_Plugin::factory('Widget_Archive')->beforeRender = array('Access_Plugin', 'start');
Typecho_Plugin::factory('admin/footer.php')->end = array('Access_Plugin', 'adminFooter');
return _t($msg);
}
@@ -95,6 +95,10 @@ class Access_Plugin implements Typecho_Plugin_Interface
if (('Mysql' == $type && $code == (1050 || '42S01'))) {
$script = 'SELECT * from `' . $prefix . 'access`';
$installDb->query($script, Typecho_Db::READ);
+ if (!array_key_exists('referer', $installDb->fetchRow($installDb->select()->from('table.access')))) {
+ $installDb->query('ALTER TABLE `' . $prefix . 'access` ADD `referer` varchar(255) NULL AFTER `ip`, ADD `referer_domain` varchar(100) NULL AFTER `referer`;');
+ return '数据表结构已更新,插件启用成功,' . $configLink;
+ }
return '数据表已存在,插件启用成功,' . $configLink;
} else {
throw new Typecho_Plugin_Exception('数据表建立失败,插件启用失败。错误号:' . $code);
@@ -102,11 +106,11 @@ class Access_Plugin implements Typecho_Plugin_Interface
}
}
- public static function start()
+ public static function start($archive)
{
- require_once __DIR__ . '/Access.php';
- $extend = new Access_Extend();
- if ($extend->isAdmin()) {
+ require_once __DIR__ . '/Access_Bootstrap.php';
+ $access = new Access_Core();
+ if ($access->isAdmin()) {
return;
}
$config = Typecho_Widget::widget('Widget_Options')->plugin('Access');
diff --git a/README.md b/README.md
index dba2c60..7eea26b 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@
* 查看来源页和来源域名排名
* 修复Referer记录错误的bug
* 添加删除日志的功能
+* 修复旧版本升级错误的提示,自动更新数据表结构
### 使用须知
diff --git a/page/console.php b/page/console.php
index a75d112..f158032 100644
--- a/page/console.php
+++ b/page/console.php
@@ -2,25 +2,25 @@
include_once 'common.php';
include 'header.php';
include 'menu.php';
-require dirname(__FILE__) . '/../Access.php';
-$extend = new Access_Extend();
+require_once __DIR__ . '/../Access_Bootstrap.php';
+$access = new Access_Core();
?>
-
title;?>
+ title;?>
- - action == 'overview' ? ' class="current"' : '')?>>
- - action == 'logs' ? ' class="current"' : '')?>>
+ - action == 'overview' ? ' class="current"' : '')?>>
+ - action == 'logs' ? ' class="current"' : '')?>>
- action == 'logs'):?>
+ action == 'logs'):?>
@@ -41,12 +41,11 @@ $extend = new Access_Extend();
page)): ?>
-
@@ -73,12 +72,12 @@ $extend = new Access_Extend();
- logs['list'])): ?>
- logs['list'] as $log): ?>
+ logs['list'])): ?>
+ logs['list'] as $log): ?>
|
"> |
- parseUA($log['ua']); ?> |
+ parser->getBrowser($log['ua']); ?> |
|
|
|
@@ -108,16 +107,16 @@ $extend = new Access_Extend();
- logs['rows'] > 1): ?>
+ logs['rows'] > 1): ?>
- action == 'overview'):?>
+ action == 'overview'):?>
@@ -144,21 +143,21 @@ $extend = new Access_Extend();
今日 |
- overview['pv']['today']['total'];?> |
- overview['uv']['today']['total'];?> |
- overview['ip']['today']['total'];?> |
+ overview['pv']['today']['total'];?> |
+ overview['uv']['today']['total'];?> |
+ overview['ip']['today']['total'];?> |
昨日 |
- overview['pv']['yesterday']['total'];?> |
- overview['uv']['yesterday']['total'];?> |
- overview['ip']['yesterday']['total'];?> |
+ overview['pv']['yesterday']['total'];?> |
+ overview['uv']['yesterday']['total'];?> |
+ overview['ip']['yesterday']['total'];?> |
总计 |
- overview['pv']['all']['total'];?> |
- overview['uv']['all']['total'];?> |
- overview['ip']['all']['total'];?> |
+ overview['pv']['all']['total'];?> |
+ overview['uv']['all']['total'];?> |
+ overview['ip']['all']['total'];?> |
@@ -181,7 +180,7 @@ $extend = new Access_Extend();
- referer['domain'] as $key => $value):?>
+ referer['domain'] as $key => $value):?>
|
|
@@ -209,7 +208,7 @@ $extend = new Access_Extend();
- referer['url'] as $key => $value):?>
+ referer['url'] as $key => $value):?>
|
|
@@ -340,17 +339,21 @@ $(document).ready(function() {
var t = $(this);
t.parents('.dropdown-menu').hide().prev().removeClass('active');
});
+
+ $('form select[data-action="filter"]').change(function() {
+ $(this).parents('form').submit();
+ });
});
-action == 'overview'):?>
+action == 'overview'):?>
-plugin('Access') == 1):?>
+config->cancanAnalytize == 1):?>