1.7.1版
This commit is contained in:
52
online2_callback.php
Normal file
52
online2_callback.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* 在线统计插件
|
||||
* @copyright (c) xiaosong.org All Rights Reserved
|
||||
*/
|
||||
if(!defined('EMLOG_ROOT')) {exit('error!');}
|
||||
|
||||
function callback_init(){
|
||||
$DB = MySql::getInstance();
|
||||
$is_exist_online_query = $DB->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("<?php exit;//", '', $data);
|
||||
Option::updateOption('maxOnline', $data);
|
||||
unlink($cachefile);
|
||||
}
|
||||
}
|
||||
|
||||
function callback_rm(){
|
||||
$DB = MySql::getInstance();
|
||||
$query = $DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."online2");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user