From ba67678fa88c5c275593bfdfc6f44004fbafb211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE?= Date: Thu, 18 Oct 2012 09:28:53 +0800 Subject: [PATCH] =?UTF-8?q?1.7.1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 22 ++++++ .gitignore | 163 +++++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++ online2.php | 113 ++++++++++++++++++++++++++++++ online2_callback.php | 52 ++++++++++++++ online2_config.php | 5 ++ online2_setting.php | 71 +++++++++++++++++++ 7 files changed, 432 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.md create mode 100644 online2.php create mode 100644 online2_callback.php create mode 100644 online2_config.php create mode 100644 online2_setting.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ebd21a --- /dev/null +++ b/.gitignore @@ -0,0 +1,163 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..e58b81b --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +emlog 在线统计插件 +==================== + +显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记。在前台可以显示当前在线人数及最高记录,还可显示数据库查询次数。 + +[插件主页](http://xiaosong.org/tech/new-version-online-statistics-plugin-released) \ No newline at end of file diff --git a/online2.php b/online2.php new file mode 100644 index 0000000..5daf10e --- /dev/null +++ b/online2.php @@ -0,0 +1,113 @@ +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 $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.''; +} + +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) ? '暂无在线访客' : ''.$row['ip'].$iplocation.''.$row['dt'].''.$row['useragent'].''; + } + 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 ''; +} +addAction('adm_sidebar_ext', 'online_menu'); +?> \ No newline at end of file diff --git a/online2_callback.php b/online2_callback.php new file mode 100644 index 0000000..09f6a0f --- /dev/null +++ b/online2_callback.php @@ -0,0 +1,52 @@ +query('show tables like "'.DB_PREFIX.'online2"'); + $is_exist_maxonline_query = $DB->query('show tables like "'.DB_PREFIX.'maxonline"'); + $is_exist_option = $DB->query("SELECT 1 FROM ".DB_PREFIX."options WHERE option_name='maxOnline'"); + $dbcharset = 'utf8'; + $type = 'MYISAM'; + $add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";":"TYPE=".$type.";"; + if ($DB->num_rows($is_exist_online_query) == 0) { + $sql_online = " +CREATE TABLE `".DB_PREFIX."online2` ( +`id` int(10) unsigned NOT NULL auto_increment, +`ip` varchar(128) NOT NULL default '', +`dt` timestamp NOT NULL default CURRENT_TIMESTAMP, +`useragent` varchar(255) NOT NULL default '', +PRIMARY KEY (`id`), +UNIQUE KEY `ip` (`ip`) +)".$add; + $DB->query($sql_online); + } + if ($DB->num_rows($is_exist_maxonline_query) != 0) { + $res_max = $DB->once_fetch_array("SELECT maximum, DATE(dt) AS maxDate FROM ".DB_PREFIX."maxonline"); + $timeUTC = emStrtotime($res_max["maxDate"]); + $cacheData = serialize(array('maximum' => $res_max["maximum"], 'maxDate' => $timeUTC)); + $CACHE = Cache::getInstance(); + $CACHE->cacheWrite($cacheData, 'maxOnline'); + $query = $DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."maxonline"); + } + if (!$DB->num_rows($is_exist_option)) { + $DB->query("INSERT INTO ".DB_PREFIX."options (option_name, option_value) VALUES('maxOnline', '".serialize(array('maximum' => 0, 'maxDate' => time()))."')"); + } + $cachefile = EMLOG_ROOT . '/content/cache/maxOnline.php'; + if (file_exists($cachefile) && filesize($cachefile) > 0) { + $data = file_get_contents($cachefile); + $data = str_replace("query("DROP TABLE IF EXISTS ".DB_PREFIX."online2"); +} +?> \ No newline at end of file diff --git a/online2_config.php b/online2_config.php new file mode 100644 index 0000000..6114c6b --- /dev/null +++ b/online2_config.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/online2_setting.php b/online2_setting.php new file mode 100644 index 0000000..07bf4b1 --- /dev/null +++ b/online2_setting.php @@ -0,0 +1,71 @@ + + +
在线统计 +插件设置完成 +
+
+ +

+
+ + + + + + + + + +
ip地址上线时间UserAgent信息
+ +
+
你可以根据上面的在线信息,添加你要排除在外的蜘蛛的特征UserAgent信息,每一个特征字符串用(|)分开,不区分大小写
+
+

+

可用变量:{queryCount} -- 查询次数

+

样式和位置完全取决于主题!

+

+
+"; + $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); +} +?> \ No newline at end of file