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