📄 stats.php
字号:
if($oltimespan) {
$member['totalol'] = round($member['totalol'] / 60, 2);
$member['thismonthol'] = gmdate('Yn', $member['lastactivity']) == gmdate('Yn', $timestamp) ? round($member['thismonthol'] / 60, 2) : 0;
$totalol += $member['totalol'];
$totalthismonthol += $member['thismonthol'];
}
$members[$member['uid']] = $member;
$uids .= ','.$member['uid'];
}
$totalthismonthposts = 0;
$query = $db->query("SELECT authorid, COUNT(*) AS posts FROM {$tablepre}posts
WHERE dateline>=$timestamp-86400*30 AND authorid IN ($uids) AND invisible='0' GROUP BY authorid");
while($post = $db->fetch_array($query)) {
$members[$post['authorid']]['thismonthposts'] = $post['posts'];
$totalthismonthposts += $post['posts'];
}
$totalmodposts = $totalmodactions = 0;
if($modworkstatus) {
$starttime = gmdate("Y-m-1", $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
$query = $db->query("SELECT uid, SUM(count) AS actioncount FROM {$tablepre}modworks
WHERE dateline>='$starttime' GROUP BY uid");
while($member = $db->fetch_array($query)) {
$members[$member['uid']]['modactions'] = $member['actioncount'];
$totalmodactions += $member['actioncount'];
}
}
$query = $db->query("SELECT fid, fup, type, name, inheritedmod FROM {$tablepre}forums WHERE status>0 ORDER BY type, displayorder");
while($forum = $db->fetch_array($query)) {
$forum['moderators'] = count($moderators[$forum['fid']]);
switch($forum['type']) {
case 'group':
$categories[$forum['fid']] = $forum;
$forums[$forum['fid']][$forum['fid']] = $forum;
$catfid = $forum['fid'];
break;
case 'forum':
$forums[$forum['fup']][$forum['fid']] = $forum;
$fuptemp[$forum['fid']] = $forum['fup'];
$catfid = $forum['fup'];
break;
case 'sub':
$forums[$fuptemp[$forum['fup']]][$forum['fid']] = $forum;
$catfid = $fuptemp[$forum['fup']];
break;
}
if(!empty($moderators[$forum['fid']])) {
$categories[$catfid]['moderating'] = 1;
}
}
foreach($categories as $fid => $category) {
if(empty($category['moderating'])) {
unset($categories[$fid]);
}
}
$team = array (
'categories' => $categories,
'forums' => $forums,
'admins' => $admins,
'moderators' => $moderators,
'members' => $members,
'avgoffdays' => @($totaloffdays / count($members)),
'avgthismonthposts' => @($totalthismonthposts / count($members)),
'avgtotalol' => @($totalol / count($members)),
'avgthismonthol' => @($totalthismonthol / count($members)),
'avgmodactions' => @($totalmodactions / count($members)),
);
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
VALUES ('team', 'team', '".addslashes(serialize($team))."')");
}
if(is_array($team)) {
foreach($team['members'] as $uid => $member) {
@$member['thismonthposts'] = intval($member['thismonthposts']);
@$team['members'][$uid]['offdays'] = $member['offdays'] > $team['avgoffdays'] ? '<b><i>'.$member['offdays'].'</i></b>' : $member['offdays'];
@$team['members'][$uid]['thismonthposts'] = $member['thismonthposts'] < $team['avgthismonthposts'] / 2 ? '<b><i>'.$member['thismonthposts'].'</i></b>' : $member['thismonthposts'];
@$team['members'][$uid]['lastactivity'] = gmdate("$dateformat $timeformat", $member['lastactivity'] + $timeoffset * 3600);
@$team['members'][$uid]['thismonthol'] = $member['thismonthol'] < $team['avgthismonthol'] / 2 ? '<b><i>'.$member['thismonthol'].'</i></b>' : $member['thismonthol'];
@$team['members'][$uid]['totalol'] = $member['totalol'] < $team['avgtotalol'] / 2 ? '<b><i>'.$member['totalol'].'</i></b>' : $member['totalol'];
@$team['members'][$uid]['modposts'] = $member['modposts'] < $team['avgmodposts'] / 2 ? '<b><i>'.intval($member['modposts']).'</i></b>' : intval($member['modposts']);
@$team['members'][$uid]['modactions'] = $member['modactions'] < $team['avgmodactions'] / 2 ? '<b><i>'.intval($member['modactions']).'</i></b>' : intval($member['modactions']);
}
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
include template('stats_team');
} elseif($type == 'modworks' && $modworkstatus) {
$before = (isset($before) && $before > 0 && $before <= $maxmodworksmonths) ? intval($before) : 0 ;
list($now['year'], $now['month'], $now['day']) = explode("-", gmdate("Y-n-j", $timestamp + $_DCACHE['settings']['timeoffset'] * 3600));
for($i = 0; $i <= $maxmodworksmonths; $i++) {
$month = date("Y-m", mktime(0, 0, 0, $now['month'] - $i, 1, $now['year']));
if($i != $before) {
$monthlinks[$i] = "<a href=\"stats.php?type=$type&before=$i&uid=$uid\">$month</a>";
} else {
$thismonth = $month;
$starttime = $month.'-01';
$endtime = date("Y-m-01", mktime(0, 0, 0, $now['month'] - $i + 1 , 1, $now['year']));
$daysofmonth = date("t", mktime(0, 0, 0, $now['month'] - $i , 1, $now['year']));
$monthlinks[$i] = "<b>$month</b>";
}
}
$expiretime = date('Y-m', mktime(0, 0, 0, $now['month'] - $maxmodworksmonths - 1, 1, $now['year']));
$daysofmonth = empty($before) ? $now['day'] : $daysofmonth;
$mergeactions = array('OPN' => 'CLS', 'ECL' => 'CLS', 'UEC' => 'CLS', 'EOP' => 'CLS', 'UEO' => 'CLS',
'UDG' => 'DIG', 'EDI' =>'DIG', 'UED' => 'DIG', 'UST' => 'STK', 'EST' => 'STK', 'UES' => 'STK',
'DLP' => 'DEL', 'PRN' => 'DEL', 'UDL' => 'DEL', 'UHL' => 'HLT', 'EHL' => 'HLT', 'UEH' => 'HLT',
'SPL' => 'MRG', 'ABL' => 'EDT', 'RBL' => 'EDT');
if(!empty($uid)) {
$query = $db->query("SELECT username FROM {$tablepre}members WHERE uid='$uid' AND adminid>'0'");
if(!$member = $db->fetch_array($query)) {
showmessage('undefined_action');
}
$modactions = $totalactions = array();
for($i = 1; $i <= $daysofmonth; $i++) {
$modactions[sprintf("$thismonth-%02d", $i)] = array();
}
$query = $db->query("SELECT * FROM {$tablepre}modworks WHERE uid='$uid' AND dateline>='{$starttime}' AND dateline<'$endtime'");
while($data = $db->fetch_array($query)) {
if(isset($mergeactions[$data['modaction']])) {
$data['modaction'] = $mergeactions[$data['modaction']];
}
$modactions[$data['dateline']][$data['modaction']]['count'] += $data['count'];
$modactions[$data['dateline']][$data['modaction']]['posts'] += $data['posts'];
$totalactions[$data['modaction']]['count'] += $data['count'];
$totalactions[$data['modaction']]['posts'] += $data['posts'];
}
} else {
$modworksupdated = false;
$variable = empty($before) ? 'thismonth' : $starttime;
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='modworks' AND variable='$variable'");
if($members = $db->fetch_array($query)) {
$members = unserialize($members['value']);
if( !empty($before) || (($timestamp - $members['lastupdate'] < $statscachelife) && $members['thismonth'] == $starttime)) {
$modworksupdated = true;
}
}
if($modworksupdated) {
if(empty($before)) {
unset($members['lastupdate'], $members['thismonth']);
}
} else {
$members = array();
$uids = $totalmodactions = 0;
$query = $db->query("SELECT uid, username, adminid FROM {$tablepre}members WHERE adminid IN (1, 2, 3) ORDER BY adminid, uid");
while($member = $db->fetch_array($query)) {
$members[$member['uid']] = $member;
$uids .= ', '.$member['uid'];
}
$query = $db->query("SELECT uid, modaction, SUM(count) AS count, SUM(posts) AS posts
FROM {$tablepre}modworks
WHERE uid IN ($uids) AND dateline>='{$starttime}' AND dateline<'$endtime' GROUP BY uid, modaction");
while($data = $db->fetch_array($query)) {
if(isset($mergeactions[$data['modaction']])) {
$data['modaction'] = $mergeactions[$data['modaction']];
}
$members[$data['uid']]['total'] += $data['count'];
$totalmodactioncount += $data['count'];
$members[$data['uid']][$data['modaction']]['count'] += $data['count'];
$members[$data['uid']][$data['modaction']]['posts'] += $data['posts'];
}
$avgmodactioncount = @($totalmodactioncount / count($members));
foreach($members as $id => $member) {
$members[$id]['totalactions'] = intval($members[$id]['totalactions']);
$members[$id]['username'] = ($members[$id]['total'] < $avgmodactioncount / 2) ? ('<b><i>'.$members[$id]['username'].'</i></b>') : ($members[$id]['username']);
}
if(!empty($before)) {
$db->query("DELETE FROM {$tablepre}statvars WHERE type='modworks' AND variable<'$expiretime'", 'UNBUFFERED');
$db->query("DELETE FROM {$tablepre}modworks WHERE dateline<'{$expiretime}-01'", 'UNBUFFERED');
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
VALUES ('modworks', '$starttime', '".addslashes(serialize($members))."')");
} else {
$members['thismonth'] = $starttime;
$members['lastupdate'] = $timestamp;
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
VALUES ('modworks', 'thismonth', '".addslashes(serialize($members))."')");
unset($members['lastupdate'], $members['thismonth']);
}
}
}
include language('modactions');
$bgarray = array();
$thisbg = 'altbg1';
foreach($modactioncode as $key => $val) {
if(isset($mergeactions[$key])) {
unset($modactioncode[$key]);
} else {
$bgarray[$key] = $thisbg = $thisbg == 'altbg1' ? 'altbg2' : 'altbg1';
}
}
$tdcols = count($modactioncode) + 1;
$tdwidth = floor(90 / ($tdcols - 1)).'%';
include template('stats_misc');
} elseif($type == 'trade' && $ec_id) {
$statvars = array();
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='trade'");
while($variable = $db->fetch_array($query)) {
$statvars[$variable['variable']] = $variable['value'];
}
if($timestamp - $statvars['lastupdate'] > $statscachelife) {
$statvars = array('lastupdate' => $timestamp);
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value) VALUES ('trade', 'lastupdate', '$timestamp')");
}
if($statvars['tradesum']) {
$tradesums = unserialize($statvars['tradesum']);
} else {
$query = $db->query("SELECT subject, tid, seller, sellerid, sum(tradesum) as tradesum FROM {$tablepre}trades WHERE tradesum>0 GROUP BY sellerid order by tradesum DESC LIMIT 10");
while($data = $db->fetch_array($query)) {
$tradesums[] = $data;
}
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value) VALUES ('trade', 'tradesums', '".addslashes(serialize($tradesums))."')");
}
if($statvars['totalitems']) {
$totalitems = unserialize($statvars['totalitems']);
} else {
$query = $db->query("SELECT subject, tid, seller, sellerid, sum(totalitems) as totalitems FROM {$tablepre}trades WHERE totalitems>0 GROUP BY sellerid order by totalitems DESC LIMIT 10");
while($data = $db->fetch_array($query)) {
$totalitems[] = $data;
}
$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
VALUES ('trade', 'totalitems', '".addslashes(serialize($totalitems))."')");
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
include template('stats_trade');
} else {
showmessage('undefined_action', NULL, 'HALTED');
}
function statsdata($type, $max, $sortfunc = '') {
global $barno;
$statsbar = '';
$sum = 0;
$datarray = $GLOBALS["stats_$type"];
if(is_array($datarray)) {
if($sortfunc) {
eval("$sortfunc(\$datarray);");
}
foreach($datarray as $count) {
$sum += $count;
}
} else {
$datarray = array();
}
foreach($datarray as $variable => $count) {
$barno ++;
switch($type) {
case $type == 'month' || $type == 'monthposts':
$variable = substr($variable, 0, 4).'-'.substr($variable, -2);
break;
case 'dayposts':
$variable = substr($variable, 0, 4).'-'.substr($variable, -4, 2).'-'.substr($variable, -2);
break;
case 'week':
switch($variable) {
case 00: $variable = 'Sunday'; break;
case 01: $variable = 'Monday'; break;
case 02: $variable = 'Tuesday'; break;
case 03: $variable = 'Wednesday'; break;
case 04: $variable = 'Thursday'; break;
case 05: $variable = 'Friday'; break;
case 06: $variable = 'Saturday'; break;
}
break;
case 'hour':
$variable = intval($variable);
if($variable <= 12) {
$variable = "$variable AM";
} else {
$variable -= 12;
$variable = "$variable PM";
}
break;
default:
$variable = '<img src="images/stats/'.strtolower(str_replace('/', '', $variable)).'.gif" border="0" alt="" /> '.$variable;
break;
}
@$width = intval(370 * $count / $max);
@$percent = sprintf ("%01.1f", 100 * $count / $sum);
$width = $width ? $width : '2';
$variable = $count == $max ? '<span class="bold"><i>'.$variable.'</i></span>' : $variable;
$count = '<div class="percent" style="padding: 0px;"><div style="width: '.$width.'"></div></div> <span class="bold">'.$count.'</span> ('.$percent.'%)';
$statsbar .= "<tr><td width=\"100\">$variable</td><td width=\"500\">$count</td></tr>\n";
}
return $statsbar;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -