stats.php
来自「Discuz_7.0.0 是一款社区程序源码!! 国内80 的站长使用此程序」· PHP 代码 · 共 950 行 · 第 1/3 页
PHP
950 行
$statvars['forums']++;
$threads[] = $forum;
}
$newstatvars[] = "'forumsrank', 'threads', '".addslashes(serialize($threads))."'";
$newstatvars[] = "'forumsrank', 'forums', '$statvars[forums]'";
}
$statvars['forums'] = $statvars['forums'] ? $statvars['forums'] : 20;
if(isset($statvars['posts'])) {
$posts = unserialize($statvars['posts']);
} else {
$query = $db->query("SELECT fid, name, posts FROM {$tablepre}forums WHERE status>0 AND type<>'group' ORDER BY posts DESC LIMIT 0, $statvars[forums]");
while($forum = $db->fetch_array($query)) {
$posts[] = $forum;
}
$newstatvars[] = "'forumsrank', 'posts', '".addslashes(serialize($posts))."'";
}
if(isset($statvars['thismonth'])) {
$thismonth = unserialize($statvars['thismonth']);
} else {
$query = $db->query("SELECT DISTINCT(p.fid) AS fid, f.name, COUNT(pid) AS posts FROM {$tablepre}posts p
LEFT JOIN {$tablepre}forums f USING (fid)
WHERE dateline>='$timestamp'-86400*30 AND invisible='0' AND authorid>'0'
GROUP BY p.fid ORDER BY posts DESC LIMIT 0, $statvars[forums]");
while($forum = $db->fetch_array($query)) {
$thismonth[] = $forum;
}
$newstatvars[] = "'forumsrank', 'thismonth', '".addslashes(serialize($thismonth))."'";
}
if(isset($statvars['today'])) {
$today = unserialize($statvars['today']);
} else {
$query = $db->query("SELECT DISTINCT(p.fid) AS fid, f.name, COUNT(pid) AS posts FROM {$tablepre}posts p
LEFT JOIN {$tablepre}forums f USING (fid)
WHERE dateline>='$timestamp'-86400 AND invisible='0' AND authorid>'0'
GROUP BY p.fid ORDER BY posts DESC LIMIT 0, $statvars[forums]");
while($forum = $db->fetch_array($query)) {
$today[] = $forum;
}
$newstatvars[] = "'forumsrank', 'today', '".addslashes(serialize($today))."'";
}
for($i = 0; $i < $statvars['forums']; $i++) {
$bgclass = $i % 2 ? ' class="colplural"' : '';
@$forumsrank[0] .= $threads[$i]['name'] || $posts[$i]['name'] ? "<tr".$bgclass."><td class=\"stat_subject\"><a href=\"forumdisplay.php?fid={$threads[$i]['fid']}\" target=\"_blank\">{$threads[$i]['name']}</a></td><td class=\"stat_num\">{$threads[$i]['threads']}</td>\n".
"<td class=\"stat_subject\"><a href=\"forumdisplay.php?fid={$posts[$i]['fid']}\" target=\"_blank\">{$posts[$i]['name']}</a></td><td class=\"stat_num\">{$posts[$i]['posts']}</td>\n" : '';
@$forumsrank[1] .= $thismonth[$i]['name'] || $today[$i]['name'] ? "<tr".$bgclass."><td class=\"stat_subject\"><a href=\"forumdisplay.php?fid={$thismonth[$i]['fid']}\" target=\"_blank\">{$thismonth[$i]['name']}</a></td><td class=\"stat_num\">{$thismonth[$i]['posts']}</td>\n".
"<td class=\"stat_subject\"><a href=\"forumdisplay.php?fid={$today[$i]['fid']}\" target=\"_blank\">{$today[$i]['name']}</a></td><td class=\"stat_num\">{$today[$i]['posts']}</td></tr>\n" : '';
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
updatenewstatvars();
include template('stats_misc');
} elseif($type == 'postsrank') {
$postsrank = '';
$statvars = array();
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='postsrank'");
while($variable = $db->fetch_array($query)) {
$statvars[$variable['variable']] = $variable['value'];
}
if($timestamp - $statvars['lastupdate'] > $statscachelife) {
$statvars = array('lastupdate' => $timestamp);
$newstatvars[] = "'postsrank', 'lastupdate', '$timestamp'";
}
$posts = $digestposts = $thismonth = $today = array();
if(isset($statvars['posts'])) {
$posts = unserialize($statvars['posts']);
} else {
$query = $db->query("SELECT username, uid, posts FROM {$tablepre}members ORDER BY posts DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$posts[] = $member;
}
$newstatvars[] = "'postsrank', 'posts', '".addslashes(serialize($posts))."'";
}
if(isset($statvars['digestposts'])) {
$digestposts = unserialize($statvars['digestposts']);
} else {
$query = $db->query("SELECT username, uid, digestposts FROM {$tablepre}members ORDER BY digestposts DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$digestposts[] = $member;
}
$newstatvars[] = "'postsrank', 'digestposts', '".addslashes(serialize($digestposts))."'";
}
if(isset($statvars['thismonth'])) {
$thismonth = unserialize($statvars['thismonth']);
} else {
$query = $db->query("SELECT DISTINCT(author) AS username, COUNT(pid) AS posts
FROM {$tablepre}posts WHERE dateline>='$timestamp'-86400*30 AND invisible='0' AND authorid>'0'
GROUP BY author ORDER BY posts DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$thismonth[] = $member;
}
$newstatvars[] = "'postsrank', 'thismonth', '".addslashes(serialize($thismonth))."'";
}
if(isset($statvars['today'])) {
$today = unserialize($statvars['today']);
} else {
$query = $db->query("SELECT DISTINCT(author) AS username, COUNT(pid) AS posts
FROM {$tablepre}posts WHERE dateline >='$timestamp'-86400 AND invisible='0' AND authorid>'0'
GROUP BY author ORDER BY posts DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$today[] = $member;
}
$newstatvars[] = "'postsrank', 'today', '".addslashes(serialize($today))."'";
}
for($i = 0; $i < 20; $i++) {
$bgclass = $i % 2 ? ' class="colplural"' : '';
@$postsrank .= "<tr".$bgclass."><td class=\"stat_subject\"><a href=\"space.php?username=".rawurlencode($posts[$i]['username'])."\" target=\"_blank\">{$posts[$i]['username']}</a> </td><td class=\"stat_num\">{$posts[$i]['posts']}</td>\n".
"<td class=\"stat_subject\"><a href=\"space.php?username=".rawurlencode($digestposts[$i]['username'])."\" target=\"_blank\">{$digestposts[$i]['username']}</a></td><td class=\"stat_num\">{$digestposts[$i]['digestposts']}</td>\n".
"<td class=\"stat_subject\"><a href=\"space.php?username=".rawurlencode($thismonth[$i]['username'])."\" target=\"_blank\">{$thismonth[$i]['username']}</a></td><td class=\"stat_num\">{$thismonth[$i]['posts']}</td>\n".
"<td class=\"stat_subject\"><a href=\"space.php?username=".rawurlencode($today[$i]['username'])."\" target=\"_blank\">{$today[$i]['username']}</a></td><td class=\"stat_num\">{$today[$i]['posts']}</td></tr>\n";
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
updatenewstatvars();
include template('stats_misc');
} elseif($type == 'creditsrank') {
$creditsrank = '';
$statvars = array();
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='creditsrank'");
while($variable = $db->fetch_array($query)) {
$statvars[$variable['variable']] = $variable['value'];
}
if($timestamp - $statvars['lastupdate'] > $statscachelife) {
$statvars = array('lastupdate' => $timestamp);
$newstatvars[] = "'creditsrank', 'lastupdate', '$timestamp'";
}
//ATTENTION: initialize the arrays first!
$credits = $extendedcredits = array();
if(isset($statvars['credits'])) {
$credits = unserialize($statvars['credits']);
} else {
$query = $db->query("SELECT username, uid, credits FROM {$tablepre}members ORDER BY credits DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$credits[] = $member;
}
$newstatvars[] = "'creditsrank', 'credits', '".addslashes(serialize($credits))."'";
}
if(isset($statvars['extendedcredits'])) {
$extendedcredits = unserialize($statvars['extendedcredits']);
} else {
foreach($extcredits as $id => $credit) {
$query = $db->query("SELECT username, uid, extcredits$id AS credits FROM {$tablepre}members ORDER BY extcredits$id DESC LIMIT 0, 20");
while($member = $db->fetch_array($query)) {
$extendedcredits[$id][] = $member;
}
}
$newstatvars[] = "'creditsrank', 'extendedcredits', '".addslashes(serialize($extendedcredits))."'";
}
if(is_array($extendedcredits)) {
$extcreditfirst = 0;$extcreditkeys = $creditsrank = array();
foreach($extendedcredits as $key => $extendedcredit) {
$max = $extendedcredit[0]['credits'];
!$extcreditfirst && $extcreditfirst = $key;
$extcreditkeys[] = $key;
foreach($extendedcredit as $i => $members) {
@$width = intval(370 * $members['credits'] / $max);
$width += 2;
$creditsrank[$key] .= "<tr><td width=\"100\"><a href=\"space.php?uid=$members[uid]\" target=\"_blank\">$members[username]</a></strong></td>\n".
"<td><div class=\"optionbar\"><div style=\"width: {$width}px\"> </div></div> <strong>$members[credits]</strong></td></tr>\n";
}
}
$extcredit = empty($extcredit) || !in_array($extcredit, $extcreditkeys) ? $extcreditfirst : intval($extcredit);
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
updatenewstatvars();
include template('stats_misc');
} elseif($type == 'onlinetime' && $oltimespan) {
$onlines = '';
$statvars = array();
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='onlines'");
while($variable = $db->fetch_array($query)) {
$statvars[$variable['variable']] = $variable['value'];
}
if($timestamp - $statvars['lastupdate'] > $statscachelife) {
$statvars = array('lastupdate' => $timestamp);
$newstatvars[] = "'onlines', 'lastupdate', '$timestamp'";
}
$total = $thismonth = array();
if(isset($statvars['total'])) {
$total = unserialize($statvars['total']);
} else {
$query = $db->query("SELECT o.uid, m.username, o.total AS time
FROM {$tablepre}onlinetime o
LEFT JOIN {$tablepre}members m USING (uid)
ORDER BY o.total DESC LIMIT 20");
while($online = $db->fetch_array($query)) {
$online['time'] = round($online['time'] / 60, 2);
$total[] = $online;
}
$newstatvars[] = "'onlines', 'total', '".addslashes(serialize($total))."'";
}
if(isset($statvars['thismonth'])) {
$thismonth = unserialize($statvars['thismonth']);
} else {
$dateline = strtotime(gmdate('Y-n-01', $timestamp));
$query = $db->query("SELECT o.uid, m.username, o.thismonth AS time
FROM {$tablepre}onlinetime o, {$tablepre}members m
WHERE o.uid=m.uid AND m.lastactivity>='$dateline'
ORDER BY o.thismonth DESC LIMIT 20");
while($online = $db->fetch_array($query)) {
$online['time'] = round($online['time'] / 60, 2);
$thismonth[] = $online;
}
$newstatvars[] = "'onlines', 'thismonth', '".addslashes(serialize($thismonth))."'";
}
for($i = 0; $i < 20; $i++) {
$bgclass = $i % 2 ? ' class="colplural"' : '';
@$onlines .= "<tr".$bgclass."><td class=\"stat_subject\"><a href=\"space.php?uid={$total[$i]['uid']}\" target=\"_blank\">{$total[$i]['username']}</a> </td><td class=\"stat_num\">{$total[$i]['time']}</td>\n".
"<td class=\"stat_subject\"><a href=\"space.php?uid={$thismonth[$i]['uid']}\" target=\"_blank\">{$thismonth[$i]['username']}</a></td><td class=\"stat_num\">{$thismonth[$i]['time']}</td></tr>\n";
}
$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);
updatenewstatvars();
include template('stats_onlinetime');
} elseif($type == 'team') {
$statvars = array();
$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='team'");
while($variable = $db->fetch_array($query)) {
$statvars[$variable['variable']] = $variable['value'];
}
if($timestamp - $statvars['lastupdate'] > $statscachelife) {
$statvars = array('lastupdate' => $timestamp);
$newstatvars[] = "'team', 'lastupdate', '$timestamp'";
}
$team = array();
if(isset($statvars['team'])) {
$team = unserialize($statvars['team']);
} else {
$forums = $moderators = $members = $fuptemp = array();
$categories = array(0 => array('fid' => 0, 'fup' => 0, 'type' => 'group', 'name' => $bbname));
$uids = 0;
$query = $db->query("SELECT fid, uid FROM {$tablepre}moderators WHERE inherited='0' ORDER BY displayorder");
while($moderator = $db->fetch_array($query)) {
$moderators[$moderator['fid']][] = $moderator['uid'];
$uids .= ','.$moderator['uid'];
}
if($oltimespan) {
$oltimeadd1 = ', o.thismonth AS thismonthol, o.total AS totalol';
$oltimeadd2 = "LEFT JOIN {$tablepre}onlinetime o ON o.uid=m.uid";
} else {
$oltimeadd1 = $oltimeadd2 = '';
}
$totaloffdays = $totalol = $totalthismonthol = 0;
$query = $db->query("SELECT m.uid, m.username, m.adminid, m.lastactivity, m.credits, m.posts $oltimeadd1
FROM {$tablepre}members m $oltimeadd2
WHERE m.uid IN ($uids) OR m.adminid IN (1, 2) ORDER BY m.adminid");
$admins = array();
while($member = $db->fetch_array($query)) {
if($member['adminid'] == 1 || $member['adminid'] == 2) {
$admins[] = $member['uid'];
}
$member['offdays'] = intval(($timestamp - $member['lastactivity']) / 86400);
$totaloffdays += $member['offdays'];
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'];
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?