1.7.1
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
|||||||
emlog 在线统计插件
|
emlog 在线统计插件
|
||||||
====================
|
====================
|
||||||
|
|
||||||
显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记。在前台可以显示当前在线人数及最高记录,还可显示数据库查询次数。
|
显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记。在前台可以显示当前在线人数及最高记录,还可显示数据库查询次数。
|
||||||
|
|
||||||
[插件主页](http://xiaosong.org/tech/new-version-online-statistics-plugin-released)
|
[插件主页](http://xiaosong.org/tech/new-version-online-statistics-plugin-released)
|
||||||
224
online2.php
224
online2.php
@@ -1,113 +1,113 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: 在线统计
|
Plugin Name: 在线统计
|
||||||
Version: 1.7.1
|
Version: 1.7.1
|
||||||
Plugin URL: http://xiaosong.org/tech/new-version-online-statistics-plugin-released
|
Plugin URL: http://xiaosong.org/tech/new-version-online-statistics-plugin-released
|
||||||
Description: 显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记
|
Description: 显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记
|
||||||
ForEmlog:4.2.1+
|
ForEmlog:4.2.1+
|
||||||
Author: 小松
|
Author: 小松
|
||||||
Author Email: sahala_2007@126.com
|
Author Email: sahala_2007@126.com
|
||||||
Author URL: http://xiaosong.org/
|
Author URL: http://xiaosong.org/
|
||||||
*/
|
*/
|
||||||
!defined('EMLOG_ROOT') && exit('access deined!');
|
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||||
|
|
||||||
require_once('online2_config.php');
|
require_once('online2_config.php');
|
||||||
|
|
||||||
function is_bot(){
|
function is_bot(){
|
||||||
global $ua_block;
|
global $ua_block;
|
||||||
if (empty($ua_block)) {
|
if (empty($ua_block)) {
|
||||||
return false; // Not block bot
|
return false; // Not block bot
|
||||||
}
|
}
|
||||||
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
|
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||||
$ua_blocks = strtolower($ua_block);
|
$ua_blocks = strtolower($ua_block);
|
||||||
$ua_block_array = explode("|", $ua_blocks);
|
$ua_block_array = explode("|", $ua_blocks);
|
||||||
$botlist = $ua_block_array;
|
$botlist = $ua_block_array;
|
||||||
foreach($botlist as $bot){
|
foreach($botlist as $bot){
|
||||||
if(strpos($ua, $bot) !== false)
|
if(strpos($ua, $bot) !== false)
|
||||||
return true; // Is a bot
|
return true; // Is a bot
|
||||||
}
|
}
|
||||||
return false; // Not a bot
|
return false; // Not a bot
|
||||||
}
|
}
|
||||||
|
|
||||||
function online2(){
|
function online2(){
|
||||||
$DB = MySql::getInstance();
|
$DB = MySql::getInstance();
|
||||||
$stringIp = getIp();
|
$stringIp = getIp();
|
||||||
$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
|
$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
|
||||||
if (!empty($stringIp) && !is_bot()) {
|
if (!empty($stringIp) && !is_bot()) {
|
||||||
$inDB = $DB->query("SELECT 1 FROM ".DB_PREFIX."online2 WHERE ip='".$stringIp."'");
|
$inDB = $DB->query("SELECT 1 FROM ".DB_PREFIX."online2 WHERE ip='".$stringIp."'");
|
||||||
if (!$DB->num_rows($inDB)) {
|
if (!$DB->num_rows($inDB)) {
|
||||||
$DB->query("INSERT INTO ".DB_PREFIX."online2 (ip, useragent) VALUES('".$stringIp."', '".$useragent."')");
|
$DB->query("INSERT INTO ".DB_PREFIX."online2 (ip, useragent) VALUES('".$stringIp."', '".$useragent."')");
|
||||||
} else {
|
} else {
|
||||||
$DB->query("UPDATE ".DB_PREFIX."online2 SET dt=NOW(), useragent = '".$useragent."' WHERE ip='".$stringIp."'");
|
$DB->query("UPDATE ".DB_PREFIX."online2 SET dt=NOW(), useragent = '".$useragent."' WHERE ip='".$stringIp."'");
|
||||||
}
|
}
|
||||||
if (ROLE == 'admin') {
|
if (ROLE == 'admin') {
|
||||||
$DB->query("DELETE FROM ".DB_PREFIX."online2 WHERE dt<SUBTIME(NOW(),'0 0:10:0')");
|
$DB->query("DELETE FROM ".DB_PREFIX."online2 WHERE dt<SUBTIME(NOW(),'0 0:10:0')");
|
||||||
}
|
}
|
||||||
$nowOnline = nowOnline();
|
$nowOnline = nowOnline();
|
||||||
$res_max = maxOnline();
|
$res_max = maxOnline();
|
||||||
$maxOnline = $res_max['maximum'];
|
$maxOnline = $res_max['maximum'];
|
||||||
if ($nowOnline > $maxOnline) {
|
if ($nowOnline > $maxOnline) {
|
||||||
$cacheData = serialize(array('maximum' => $nowOnline, 'maxDate' => time()));
|
$cacheData = serialize(array('maximum' => $nowOnline, 'maxDate' => time()));
|
||||||
Option::updateOption('maxOnline', $cacheData);
|
Option::updateOption('maxOnline', $cacheData);
|
||||||
$CACHE = Cache::getInstance();
|
$CACHE = Cache::getInstance();
|
||||||
$CACHE->updateCache('options');
|
$CACHE->updateCache('options');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addAction('index_head', 'online2');
|
addAction('index_head', 'online2');
|
||||||
addAction('adm_head', 'online2');
|
addAction('adm_head', 'online2');
|
||||||
|
|
||||||
function maxOnline(){
|
function maxOnline(){
|
||||||
$data = unserialize(Option::get('maxOnline'));
|
$data = unserialize(Option::get('maxOnline'));
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function nowOnline(){
|
function nowOnline(){
|
||||||
$DB = MySql::getInstance();
|
$DB = MySql::getInstance();
|
||||||
$res_now = $DB->once_fetch_array("SELECT count(1) AS total FROM ".DB_PREFIX."online2 WHERE dt>SUBTIME(NOW(),'0 0:10:0') ");
|
$res_now = $DB->once_fetch_array("SELECT count(1) AS total FROM ".DB_PREFIX."online2 WHERE dt>SUBTIME(NOW(),'0 0:10:0') ");
|
||||||
$nowOnline = $res_now['total'];
|
$nowOnline = $res_now['total'];
|
||||||
return $nowOnline;
|
return $nowOnline;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlineOutput(){
|
function onlineOutput(){
|
||||||
global $is_querycount, $query_template;
|
global $is_querycount, $query_template;
|
||||||
$DB = MySql::getInstance();
|
$DB = MySql::getInstance();
|
||||||
$maxOnline = maxOnline();
|
$maxOnline = maxOnline();
|
||||||
$nowOnline = nowOnline();
|
$nowOnline = nowOnline();
|
||||||
$maxOnlineTime = smartDate($maxOnline["maxDate"], 'Y-m-d');
|
$maxOnlineTime = smartDate($maxOnline["maxDate"], 'Y-m-d');
|
||||||
$queryCount = $DB->getQueryCount();
|
$queryCount = $DB->getQueryCount();
|
||||||
$queryCountTemplate = str_replace('{queryCount}', $queryCount, $query_template);
|
$queryCountTemplate = str_replace('{queryCount}', $queryCount, $query_template);
|
||||||
$queryCountOutput = (isset($is_querycount) && $is_querycount == 'true') ? $queryCountTemplate : '';
|
$queryCountOutput = (isset($is_querycount) && $is_querycount == 'true') ? $queryCountTemplate : '';
|
||||||
echo '总计 '.$nowOnline.' 人在线 - 最高纪录是 '.$maxOnline["maximum"].' 于 '.$maxOnlineTime.$queryCountOutput.'<!-- Powered online2 plugin by xiaosong.org -->';
|
echo '总计 '.$nowOnline.' 人在线 - 最高纪录是 '.$maxOnline["maximum"].' 于 '.$maxOnlineTime.$queryCountOutput.'<!-- Powered online2 plugin by xiaosong.org -->';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_footer == 'true') {
|
if ($is_footer == 'true') {
|
||||||
addAction('index_footer', 'onlineOutput');
|
addAction('index_footer', 'onlineOutput');
|
||||||
}
|
}
|
||||||
|
|
||||||
//仅供后台使用
|
//仅供后台使用
|
||||||
function displayOnlineList(){
|
function displayOnlineList(){
|
||||||
$DB = MySql::getInstance();
|
$DB = MySql::getInstance();
|
||||||
$res_nowonline = $DB->query("SELECT ip, dt, useragent FROM ".DB_PREFIX."online2 order by dt DESC");
|
$res_nowonline = $DB->query("SELECT ip, dt, useragent FROM ".DB_PREFIX."online2 order by dt DESC");
|
||||||
$output_online = '';
|
$output_online = '';
|
||||||
while($row = $DB->fetch_array($res_nowonline)){
|
while($row = $DB->fetch_array($res_nowonline)){
|
||||||
$iplocation = function_exists('convertip') ? '[- '.convertip($row['ip']).']' : '';
|
$iplocation = function_exists('convertip') ? '[- '.convertip($row['ip']).']' : '';
|
||||||
$output_online .= empty($row) ? '<tr><td colspan="3">暂无在线访客</td></tr>' : '<tr><td>'.$row['ip'].$iplocation.'</td><td>'.$row['dt'].'</td><td>'.$row['useragent'].'</td></tr>';
|
$output_online .= empty($row) ? '<tr><td colspan="3">暂无在线访客</td></tr>' : '<tr><td>'.$row['ip'].$iplocation.'</td><td>'.$row['dt'].'</td><td>'.$row['useragent'].'</td></tr>';
|
||||||
}
|
}
|
||||||
return $output_online;
|
return $output_online;
|
||||||
}
|
}
|
||||||
|
|
||||||
function online_backup(){
|
function online_backup(){
|
||||||
$DB = MySql::getInstance();
|
$DB = MySql::getInstance();
|
||||||
global $tables;
|
global $tables;
|
||||||
$is_exist_online2_query = $DB->query('show tables like "'.DB_PREFIX.'online2"');
|
$is_exist_online2_query = $DB->query('show tables like "'.DB_PREFIX.'online2"');
|
||||||
if($DB->num_rows($is_exist_online2_query) != 0) array_push($tables, 'online2');
|
if($DB->num_rows($is_exist_online2_query) != 0) array_push($tables, 'online2');
|
||||||
}
|
}
|
||||||
addAction('data_prebakup', 'online_backup');
|
addAction('data_prebakup', 'online_backup');
|
||||||
|
|
||||||
function online_menu()
|
function online_menu()
|
||||||
{
|
{
|
||||||
echo '<div class="sidebarsubmenu" id="online2"><a href="./plugin.php?plugin=online2">在线统计</a></div>';
|
echo '<div class="sidebarsubmenu" id="online2"><a href="./plugin.php?plugin=online2">在线统计</a></div>';
|
||||||
}
|
}
|
||||||
addAction('adm_sidebar_ext', 'online_menu');
|
addAction('adm_sidebar_ext', 'online_menu');
|
||||||
?>
|
?>
|
||||||
@@ -1,71 +1,71 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* 在线统计插件
|
* 在线统计插件
|
||||||
* @copyright (c) xiaosong.org All Rights Reserved
|
* @copyright (c) xiaosong.org All Rights Reserved
|
||||||
*/
|
*/
|
||||||
!defined('EMLOG_ROOT') && exit('access deined!');
|
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||||
|
|
||||||
function plugin_setting_view() {
|
function plugin_setting_view() {
|
||||||
require_once('online2_config.php');
|
require_once('online2_config.php');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$("#online2").addClass('sidebarsubmenu1');
|
$("#online2").addClass('sidebarsubmenu1');
|
||||||
</script>
|
</script>
|
||||||
<div class="containertitle"><b>在线统计</b>
|
<div class="containertitle"><b>在线统计</b>
|
||||||
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
|
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
|
||||||
</div>
|
</div>
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.online { max-height: 280px; overflow-y: auto; }
|
.online { max-height: 280px; overflow-y: auto; }
|
||||||
.online table { width: 100%; table-layout: fixed; }
|
.online table { width: 100%; table-layout: fixed; }
|
||||||
.online td, .online th { text-align: center; word-wrap: break-word; word-break: break-all; vertical-align: middle; }
|
.online td, .online th { text-align: center; word-wrap: break-word; word-break: break-all; vertical-align: middle; }
|
||||||
.online td { padding: 3px; }
|
.online td { padding: 3px; }
|
||||||
#queryTemplate { width: 200px; }
|
#queryTemplate { width: 200px; }
|
||||||
</style>
|
</style>
|
||||||
<h4><?php echo onlineOutput(); ?></h4>
|
<h4><?php echo onlineOutput(); ?></h4>
|
||||||
<div class="online">
|
<div class="online">
|
||||||
<table cellspacing="0" cellpadding="0" border="0" class="item_list">
|
<table cellspacing="0" cellpadding="0" border="0" class="item_list">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width:38%;"><b>ip地址</b></th>
|
<th style="width:38%;"><b>ip地址</b></th>
|
||||||
<th style="width:16%;"><b>上线时间</b></th>
|
<th style="width:16%;"><b>上线时间</b></th>
|
||||||
<th style="width:44%;"><b>UserAgent信息</b></th>
|
<th style="width:44%;"><b>UserAgent信息</b></th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php echo displayOnlineList(); ?>
|
<?php echo displayOnlineList(); ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$(".item_list tbody tr:odd").addClass("tralt_b");
|
$(".item_list tbody tr:odd").addClass("tralt_b");
|
||||||
$(".item_list tbody tr")
|
$(".item_list tbody tr")
|
||||||
.mouseover(function(){$(this).addClass("trover");})
|
.mouseover(function(){$(this).addClass("trover");})
|
||||||
.mouseout(function(){$(this).removeClass("trover");})
|
.mouseout(function(){$(this).removeClass("trover");})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<div class="des">你可以根据上面的在线信息,添加你要排除在外的蜘蛛的特征UserAgent信息,每一个特征字符串用(|)分开,不区分大小写</div>
|
<div class="des">你可以根据上面的在线信息,添加你要排除在外的蜘蛛的特征UserAgent信息,每一个特征字符串用(|)分开,不区分大小写</div>
|
||||||
<form action="plugin.php?plugin=online2&action=setting" method="post">
|
<form action="plugin.php?plugin=online2&action=setting" method="post">
|
||||||
<p><textarea name="ua_block" style="width: 500px; height: 100px"><?php echo $ua_block; ?></textarea></p>
|
<p><textarea name="ua_block" style="width: 500px; height: 100px"><?php echo $ua_block; ?></textarea></p>
|
||||||
<p><label for="is_querycount"><input type="checkbox" name="is_querycount" id="is_querycount" value="true"<?php if($is_querycount == "true"):?> checked<?php endif;?> /> 显示数据库查询次数</label> <label for="queryTemplate"> <input type="text" name="query_template" id="queryTemplate" value="<?php echo $query_template; ?>"> 显示模版</label> <span style="color:#f00">可用变量:{queryCount} -- 查询次数</span></p>
|
<p><label for="is_querycount"><input type="checkbox" name="is_querycount" id="is_querycount" value="true"<?php if($is_querycount == "true"):?> checked<?php endif;?> /> 显示数据库查询次数</label> <label for="queryTemplate"> <input type="text" name="query_template" id="queryTemplate" value="<?php echo $query_template; ?>"> 显示模版</label> <span style="color:#f00">可用变量:{queryCount} -- 查询次数</span></p>
|
||||||
<p><label for="is_footer"><input type="checkbox" name="is_footer" id="is_footer" value="true"<?php if($is_footer == "true"):?> checked<?php endif;?> /> 通过模版自带插件钩子显示</label> <span style="color:#f00">样式和位置完全取决于主题!</span></p>
|
<p><label for="is_footer"><input type="checkbox" name="is_footer" id="is_footer" value="true"<?php if($is_footer == "true"):?> checked<?php endif;?> /> 通过模版自带插件钩子显示</label> <span style="color:#f00">样式和位置完全取决于主题!</span></p>
|
||||||
<p><input type="submit" value="保存设置" class="button"/></p>
|
<p><input type="submit" value="保存设置" class="button"/></p>
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
function plugin_setting(){
|
function plugin_setting(){
|
||||||
$ua_block = isset($_POST['ua_block']) ? addslashes($_POST['ua_block']) : '';
|
$ua_block = isset($_POST['ua_block']) ? addslashes($_POST['ua_block']) : '';
|
||||||
$query_template = isset($_POST['query_template']) ? addslashes($_POST['query_template']) : '';
|
$query_template = isset($_POST['query_template']) ? addslashes($_POST['query_template']) : '';
|
||||||
$is_querycount = isset($_POST['is_querycount']) ? addslashes(trim($_POST['is_querycount'])) : '';
|
$is_querycount = isset($_POST['is_querycount']) ? addslashes(trim($_POST['is_querycount'])) : '';
|
||||||
$is_footer = isset($_POST['is_footer']) ? addslashes(trim($_POST['is_footer'])) : '';
|
$is_footer = isset($_POST['is_footer']) ? addslashes(trim($_POST['is_footer'])) : '';
|
||||||
$data = "<?php
|
$data = "<?php
|
||||||
\$ua_block = '".$ua_block."';
|
\$ua_block = '".$ua_block."';
|
||||||
\$query_template = '".$query_template."';
|
\$query_template = '".$query_template."';
|
||||||
\$is_querycount = '".$is_querycount."';
|
\$is_querycount = '".$is_querycount."';
|
||||||
\$is_footer = '".$is_footer."';
|
\$is_footer = '".$is_footer."';
|
||||||
?>";
|
?>";
|
||||||
$file = EMLOG_ROOT.'/content/plugins/online2/online2_config.php';
|
$file = EMLOG_ROOT.'/content/plugins/online2/online2_config.php';
|
||||||
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||||
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user