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

📄 stats.php

📁 极限网络智能办公系统 Office Automation V3.0官方100%源代码.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php

/*
	[Discuz!] (C)2001-2007 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$RCSfile: stats.php,v $
	$Revision: 1.44.2.2 $
	$Date: 2007/03/21 15:52:05 $
*/

define('NOROBOT', TRUE);
require_once './include/common.inc.php';

$discuz_action = 131;

$statscachelife = $statscachelife * 60;

if(!$allowviewstats) {
	showmessage('group_nopermission', NULL, 'NOPERM');
}

$navstyle = array();
$navstyle['forumsrank'] = $navstyle['threadsrank'] = $navstyle['postsrank'] = $navstyle['creditsrank'] = $navstyle['onlinetime'] = $navstyle['team'] = '';

if(!empty($type)) {
	$navstyle[$type] = 'class="altbg2"';
}
$navwidth = floor(100 / (7 + ($statstatus ? 3 : 0) + ($oltimespan ? 1 : 0) + ($modworkstatus ? 1 : 0))).'%';

$stattype = '';
if(!empty($type)) {
	if($type == 'agent') {
		$stattype = "'os', 'browser'";
	} elseif($type == 'views') {
		$stattype = "'week', 'hour'";
	}
} elseif($statstatus) {
	$stattype = "'total', 'month', 'hour'";
}

$stats_total = array();

if($stattype) {
	$query = $db->query("SELECT * FROM {$tablepre}stats WHERE type IN ($stattype) ORDER BY type");
	while($stats = $db->fetch_array($query)) {
		switch($stats['type']) {
			case 'total':
				$stats_total[$stats['variable']] = $stats['count'];
				break;
			case 'os':
				$stats_os[$stats['variable']] = $stats['count'];
				if($stats['count'] > $maxos) {
					$maxos = $stats['count'];
				}
				break;
			case 'browser':
				$stats_browser[$stats['variable']] = $stats['count'];
				if($stats['count'] > $maxbrowser) {
					$maxbrowser = $stats['count'];
				}
				break;
			case 'month':
				$stats_month[$stats['variable']] = $stats['count'];
				if($stats['count'] > $maxmonth) {
					$maxmonth = $stats['count'];
					$maxmonth_year = intval($stats['variable'] / 100);
					$maxmonth_month = $stats['variable'] - $maxmonth_year * 100;
				}
				ksort($stats_month);
				break;
			case 'week':
				$stats_week[$stats['variable']] = $stats['count'];
				if($stats['count'] > $maxweek) {
					$maxweek = $stats['count'];
					$maxweek_day = $stats['variable'];
				}
				ksort($stats_week);
				break;
			case 'hour':
				$stats_hour[$stats['variable']] = $stats['count'];
				if($stats['count'] > $maxhour) {
					$maxhour = $stats['count'];
					$maxhourfrom = $stats['variable'];
					$maxhourto = $maxhourfrom + 1;
				}
				ksort($stats_hour);
				break;
		}
	}
}

if((empty($type) && empty($statstatus)) || (isset($type) && $type == 'posts')) {

	$maxmonthposts = $maxdayposts = 0;
	$stats_monthposts = $stats_dayposts = array();

	$stats_dayposts['starttime'] = gmdate('Ymd', $timestamp - 86400 * 30);
	$db->query("DELETE FROM {$tablepre}statvars WHERE type='dayposts' AND variable<'$stats_dayposts[starttime]'");

	$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='monthposts' OR type='dayposts' ORDER BY variable");
	while($variable = $db->fetch_array($query)) {
		$variable['type'] == 'monthposts' ?	$stats_monthposts[$variable['variable']] = $variable['value'] :
							$stats_dayposts[$variable['variable']] = $variable['value'];
	}

	if(!isset($stats_monthposts['starttime'])) {
		$query = $db->query("SELECT MIN(dateline) FROM {$tablepre}posts");
		$starttime = $db->result($query, 0);
		$stats_monthposts['starttime'] = gmdate('Y-m-01', ($starttime ? $starttime : $timestamp));
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('monthposts', 'starttime', '$stats_monthposts[starttime]')");
	}

	for($dateline = strtotime($stats_monthposts['starttime']); $dateline < strtotime(gmdate('Y-m-01', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600)); $dateline += gmdate('t', $dateline + 86400 * 15) * 86400) {
		$month = gmdate('Ym', $dateline + $_DCACHE['settings']['timeoffset'] * 3600);
		if(!isset($stats_monthposts[$month])) {
			$query = $db->query("SELECT COUNT(*) FROM {$tablepre}posts WHERE dateline BETWEEN $dateline AND $dateline+2592000 AND invisible='0'");
			$stats_monthposts[$month] = $db->result($query, 0);
			$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
				VALUES ('monthposts', '$month', '$stats_monthposts[$month]')");
		}
		if($stats_monthposts[$month] > $maxmonthposts) {
			$maxmonthposts = $stats_monthposts[$month];
		}
	}

	for($dateline = strtotime($stats_dayposts['starttime']); $dateline < strtotime(gmdate('Y-m-d', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600)); $dateline += 86400) {
		$day = gmdate('Ymd', $dateline + $_DCACHE['settings']['timeoffset'] * 3600);
		if(!isset($stats_dayposts[$day])) {
			$query = $db->query("SELECT COUNT(*) FROM {$tablepre}posts WHERE dateline BETWEEN $dateline AND $dateline+86400 AND invisible='0'");
			$stats_dayposts[$day] = $db->result($query, 0);
			$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
				VALUES ('dayposts', '$day', '$stats_dayposts[$day]')");
		}
		if($stats_dayposts[$day] > $maxdayposts) {
			$maxdayposts = $stats_dayposts[$day];
		}
	}

	unset($stats_monthposts['starttime'], $stats_dayposts['starttime']);

	ksort($stats_dayposts);
	ksort($stats_monthposts);

}

if(empty($type)) {

	$statvars = array();
	$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='main'");
	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 ('main', 'lastupdate', '$timestamp')");
	}

	if(isset($statvars['forums'])) {
		$forums = $statvars['forums'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}forums WHERE type IN ('forum', 'sub') AND status>0");
		$forums = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'forums', '$forums')");
	}

	if(isset($statvars['threads'])) {
		$threads = $statvars['threads'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}threads WHERE displayorder>='0'");
		$threads = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'threads', '$threads')");
	}

	if(isset($statvars['posts']) && isset($statvars['runtime'])) {
		$posts = $statvars['posts'];
		$runtime = $statvars['runtime'];
	} else {
		$query = $db->query("SELECT COUNT(*), (MAX(dateline)-MIN(dateline))/86400 FROM {$tablepre}posts");
		list($posts, $runtime) = $db->fetch_row($query);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'posts', '$posts')");
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'runtime', '$runtime')");
	}

	if(isset($statvars['members'])) {
		$members = $statvars['members'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}members");
		$members = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'members', '$members')");
	}

	if(isset($statvars['postsaddtoday'])) {
		$postsaddtoday = $statvars['postsaddtoday'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}posts WHERE dateline>='".($timestamp - 86400)."' AND invisible='0'");
		$postsaddtoday = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'postsaddtoday', '$postsaddtoday')");
	}

	if(isset($statvars['membersaddtoday'])) {
		$membersaddtoday = $statvars['membersaddtoday'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}members WHERE regdate>='".($timestamp - 86400)."'");
		$membersaddtoday = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'membersaddtoday', '$membersaddtoday')");
	}

	if(isset($statvars['admins'])) {
		$admins = $statvars['admins'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}members WHERE adminid>'0'");
		$admins = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'admins', '$admins')");
	}

	if(isset($statvars['memnonpost'])) {
		$memnonpost = $statvars['memnonpost'];
	} else {
		$query = $db->query("SELECT COUNT(*) FROM {$tablepre}members WHERE posts='0'");
		$memnonpost = $db->result($query, 0);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'memnonpost', '$memnonpost')");
	}

	if(isset($statvars['hotforum'])) {
		$hotforum = unserialize($statvars['hotforum']);
	} else {
		$query = $db->query("SELECT posts, threads, fid, name FROM {$tablepre}forums WHERE status>0 ORDER BY posts DESC LIMIT 1");
		$hotforum = $db->fetch_array($query);
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'hotforum', '".addslashes(serialize($hotforum))."')");
	}

	if(isset($statvars['bestmem']) && isset($statvars['bestmemposts'])) {
		$bestmem = $statvars['bestmem'];
		$bestmemposts = $statvars['bestmemposts'];
	} else {
		$query = $db->query("SELECT author, COUNT(*) AS posts FROM {$tablepre}posts WHERE dateline>='$timestamp'-86400 AND invisible='0' AND authorid>'0' GROUP BY author ORDER BY posts DESC LIMIT 1");
		list($bestmem, $bestmemposts) = $db->fetch_row($query);
		if($bestmem) {
			$bestmem = '<a href="space.php?username='.rawurlencode($bestmem).'"><span class="bold">'.$bestmem.'</span></a>';
		} else {
			$bestmem = 'None';
			$bestmemposts = 0;
		}
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'bestmem', '$bestmem')");
		$db->query("REPLACE INTO {$tablepre}statvars (type, variable, value)
			VALUES ('main', 'bestmemposts', '$bestmemposts')");
	}

	$mempost = $members - $memnonpost;
	@$mempostavg = sprintf ("%01.2f", $posts / $members);
	@$threadreplyavg = sprintf ("%01.2f", ($posts - $threads) / $threads);
	@$mempostpercent = sprintf ("%01.2f", 100 * $mempost / $members);
	@$postsaddavg = round($posts / $runtime);
	@$membersaddavg = round($members / $runtime);

	@$stats_total['visitors'] = $stats_total['members'] + $stats_total['guests'];
	@$pageviewavg = sprintf ("%01.2f", $stats_total['hits'] / $stats_total['visitors']);
	@$activeindex = round(($membersaddavg / $members + $postsaddavg / $posts) * 1500 + $threadreplyavg * 10 + $mempostavg * 1 + $mempostpercent / 10 + $pageviewavg);

	if($statstatus) {
		$statsbar_month = statsdata('month', $maxmonth, 'ksort');
	} else {
		$statsbar_monthposts = statsdata('monthposts', $maxmonthposts);
		$statsbar_dayposts = statsdata('dayposts', $maxdayposts);
	}

	$lastupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $timeoffset * 3600);
	$nextupdate = gmdate("$dateformat $timeformat", $statvars['lastupdate'] + $statscachelife + $timeoffset * 3600);

	include template('stats_main');

} elseif($type == 'posts' || ($statstatus && in_array($type, array('views', 'agent')))) {

	switch($type) {
		case 'views':	$statsbar_week = statsdata('week', $maxweek);
				$statsbar_hour = statsdata('hour', $maxhour);
				break;
		case 'agent':	$statsbar_browser = statsdata('browser', $maxbrowser, 'arsort');
				$statsbar_os = statsdata('os', $maxos, 'arsort');
				break;
		case 'posts':	$statsbar_monthposts = statsdata('monthposts', $maxmonthposts);
				$statsbar_dayposts = statsdata('dayposts', $maxdayposts);
				break;
	}

	include template('stats_misc');

} elseif($type == 'threadsrank') {

	$threadsrank = '';

	$threadview = $threadreply = array();
	$query = $db->query("SELECT views, tid, subject FROM {$tablepre}threads WHERE displayorder>='0' ORDER BY views DESC LIMIT 0, 20");
	while($thread = $db->fetch_array($query)) {
		$thread['subject'] = cutstr($thread['subject'], 45);
		$threadview[] = $thread;
	}
	$query = $db->query("SELECT replies, tid, subject FROM {$tablepre}threads WHERE displayorder>='0' ORDER BY replies DESC LIMIT 0, 20");
	while($thread = $db->fetch_array($query)) {
		$thread['subject'] = cutstr($thread['subject'], 50);
		$threadreply[] = $thread;
	}

	for($i = 0; $i < 20; $i++) {
		$bgclass = empty($bgclass) ? 'class="altbg1"' : '';
		$threadsrank .= "<tr $bgclass><td><a href=\"viewthread.php?tid={$threadview[$i]['tid']}\">{$threadview[$i]['subject']}</a>&nbsp;</td><td align=\"right\">{$threadview[$i]['views']}</td><td></td>\n".
			"<td><a href=\"viewthread.php?tid={$threadreply[$i]['tid']}\">{$threadreply[$i]['subject']}</a><td align=\"right\">{$threadreply[$i]['replies']}</td></tr>\n";
	}

	include template('stats_misc');

} elseif($type == 'forumsrank') {

	$forumsrank = '';

	$statvars = array();
	$query = $db->query("SELECT * FROM {$tablepre}statvars WHERE type='forumsrank'");
	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 ('forumsrank', 'lastupdate', '$timestamp')");

⌨️ 快捷键说明

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