⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stats.php

📁 论坛代码网增加免费空间业务
💻 PHP
📖 第 1 页 / 共 3 页
字号:
	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++) {
		@$forumsrank .= "<tr><td><a href=\"forumdisplay.php?fid={$threads[$i]['fid']}\" target=\"_blank\">{$threads[$i]['name']}</a></td><td align=\"right\">{$threads[$i]['threads']}</td>\n".
			"<td><a href=\"forumdisplay.php?fid={$posts[$i]['fid']}\" target=\"_blank\">{$posts[$i]['name']}</a></td><td align=\"right\">{$posts[$i]['posts']}</td>\n".
			"<td><a href=\"forumdisplay.php?fid={$thismonth[$i]['fid']}\" target=\"_blank\">{$thismonth[$i]['name']}</a></td><td align=\"right\">{$thismonth[$i]['posts']}</td>\n".
			"<td><a href=\"forumdisplay.php?fid={$today[$i]['fid']}\" target=\"_blank\">{$today[$i]['name']}</a></td><td align=\"right\">{$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++) {
		@$postsrank .= "<tr><td><a href=\"space.php?username=".rawurlencode($posts[$i]['username'])."\" target=\"_blank\">{$posts[$i]['username']}</a>&nbsp;</td><td align=\"right\">{$posts[$i]['posts']}</td>\n".
			"<td><a href=\"space.php?username=".rawurlencode($digestposts[$i]['username'])."\" target=\"_blank\">{$digestposts[$i]['username']}</a></td><td align=\"right\">{$digestposts[$i]['digestposts']}</td>\n".
			"<td><a href=\"space.php?username=".rawurlencode($thismonth[$i]['username'])."\" target=\"_blank\">{$thismonth[$i]['username']}</a></td><td align=\"right\">{$thismonth[$i]['posts']}</td>\n".
			"<td><a href=\"space.php?username=".rawurlencode($today[$i]['username'])."\" target=\"_blank\">{$today[$i]['username']}</a></td><td align=\"right\">{$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))."'";
	}

	$countextcredits = count($extcredits);
	if($countextcredits > 4) {
		$arrextcredits = array_chunk($extcredits, ceil(($countextcredits) / 2), TRUE);
		if($countextcredits % 2 != 0) {
			$t = $arrextcredits[0];
			$arrextcredits[0] = $arrextcredits[1];
			$arrextcredits[1] = $t;
		}
	} else {
		$arrextcredits = array($extcredits);
	}

	$creditsrank = array();
	foreach($arrextcredits as $k=>$extcredits) {
		for($i = 0; $i < 20; $i++) {
			$creditsrank[$k] .= "<tr>";
			$creditsrank[$k] .= $k == 0 ? "<td><a href=\"space.php?username=".rawurlencode($credits[$i]['username'])."\" target=\"_blank\">{$credits[$i]['username']}</a>&nbsp;</td><td align=\"right\">{$credits[$i]['credits']}</td>\n" : '';
			foreach($extcredits as $id => $credit) {
				@$creditsrank[$k] .= "<td><a href=\"space.php?username=".rawurlencode($extendedcredits[$id][$i]['username'])."\" target=\"_blank\">{$extendedcredits[$id][$i]['username']}</a></td>
				<td align=\"right\">{$extendedcredits[$id][$i]['credits']} $credit[unit]&nbsp;</td>\n";
			}
			$creditsrank[$k] .= "</tr>\n";
		}
	}

	//$columnwidth = ceil(100 / (count($extcredits) + 1) - 2).'%';
	$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++) {
		@$onlines .= "<tr><td><a href=\"space.php?uid={$total[$i]['uid']}\" target=\"_blank\">{$total[$i]['username']}</a>&nbsp;</td><td align=\"right\">{$total[$i]['time']}</td>\n".
			"<td><a href=\"space.php?uid={$thismonth[$i]['uid']}\" target=\"_blank\">{$thismonth[$i]['username']}</a></td><td align=\"right\">{$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'];
		}

		$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'];
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -