$_G['group']['grouptitle']), array('login' => 1)); } $navtitle = lang('core', 'title_stats_'.$op).' - '.lang('core', 'title_stats'); loadcache('statvars'); if($op == 'basic') { $statvars = getstatvars('basic'); extract($statvars); include template('forum/stat_main'); } elseif($op == 'trade') { $statvars = getstatvars('trade'); extract($statvars); include template('forum/stat_trade'); } elseif($op == 'team') { $statvars = getstatvars('team'); extract($statvars); include template('forum/stat_team'); } elseif($op == 'modworks' && $_G['setting']['modworkstatus']) { $statvars = getstatvars('modworks'); extract($statvars); if($_GET['exportexcel']) { $filename = 'stat_modworks_'.($username ? $username.'_' : '').$starttime.'_'.$endtime.'.csv'; include template('forum/stat_misc_export'); $csvstr = ob_get_contents(); ob_end_clean(); header('Content-Encoding: none'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$filename); header('Pragma: no-cache'); header('Expires: 0'); if($_G['charset'] != 'gbk') { $csvstr = diconv($csvstr, $_G['charset'], 'GBK'); } echo $csvstr; exit; } else { include template('forum/stat_misc'); } } elseif($op == 'memberlist' && $_G['setting']['memliststatus']) { $statvars = getstatvars('memberlist'); extract($statvars); include template('forum/stat_memberlist'); } elseif($op == 'forumstat') { $statvars = getstatvars('forumstat'); extract($statvars); include template('forum/stat_misc'); } elseif($op == 'trend') { include libfile('misc/stat', 'include'); } else { showmessage('undefined_action'); } function getstatvars($type) { global $_G; $statvars = & $_G['cache']['statvars'][$type]; if(!empty($statvars['lastupdated']) && TIMESTAMP - $statvars['lastupdated'] < CACHE_TIME) { return $statvars; } switch($type) { case 'basic': case 'trade': case 'onlinetime': case 'team': case 'modworks': case 'memberlist': case 'forumstat': $statvars = call_user_func('getstatvars_'.$type, ($type == 'forumstat' ? $_GET['fid'] : ''));//getstatvars_forumstat($_GET['fid']); break; } return $statvars; } function getstatvars_basic() { global $_G; $statvars = array(); $statvars['members'] = C::t('common_member')->count(); $members_runtime = C::t('common_member')->fetch_runtime(); @$statvars['membersaddavg'] = round($statvars['members'] / $members_runtime); $statvars['memnonpost'] = C::t('common_member_count')->count_by_posts(0); $statvars['mempost'] = $statvars['members'] - $statvars['memnonpost']; $statvars['admins'] = C::t('common_member')->count_admins(); $statvars['lastmember'] = C::t('common_member')->count_by_regdate(TIMESTAMP - 86400); $statvars['mempostpercent'] = number_format((double)$statvars['mempost'] / $statvars['members'] * 100, 2); $bestmember = C::t('forum_post')->fetch_all_top_post_author(0, $_G['timestamp']-86400, 1); $bestmember = $bestmember[0]; $bestmember['author'] = $bestmember['username']; $statvars['bestmem'] = $bestmember['author']; $statvars['bestmemposts'] = $bestmember['posts']; $postsinfo = C::t('forum_post')->fetch_posts(0); $statvars['posts'] = $postsinfo['posts']; $runtime= $postsinfo['runtime']; @$statvars['postsaddavg'] = round($statvars['posts'] / $runtime); @$statvars['mempostavg'] = sprintf ("%01.2f", $statvars['posts'] / $statvars['members']); $statvars['forums'] = C::t('forum_forum')->fetch_all_fids(0, 'forum', 0, 0, 0, 1); $hotforum = C::t('forum_forum')->fetch_all_for_ranklist(1, '', 'posts', 0, 1); $statvars['hotforum'] = array('posts' => $hotforum[0]['posts'], 'threads' => $hotforum[0]['threads'], 'fid' => $hotforum[0]['fid'], 'name' => $hotforum[0]['name']); $statvars['threads'] = C::t('forum_thread')->count_all_thread(); $statvars['postsaddtoday'] = C::t('forum_post')->count_by_dateline(0, TIMESTAMP - 86400); @$statvars['threadreplyavg'] = sprintf ("%01.2f", ($statvars['posts'] - $statvars['threads']) / $statvars['threads']); $statvars['membersaddtoday'] = $statvars['lastmember']; @$statvars['activeindex'] = round(($statvars['membersaddavg'] / $statvars['members'] + $statvars['postsaddavg'] / $statvars['posts']) * 1500 + $statvars['threadreplyavg'] * 10 + $statvars['mempostavg'] * 1 + $statvars['mempostpercent'] / 10); $statvars['lastupdate'] = dgmdate(TIMESTAMP); $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME); $statvars['lastupdated'] = TIMESTAMP; $_G['cache']['statvars']['basic'] = $statvars; savecache('statvars', $_G['cache']['statvars']); return $statvars; } function getstatvars_trade() { global $_G; $statvars = array(); $query = C::t('forum_trade')->fetch_all_statvars('tradesum'); foreach($query as $data) { $tradesums[] = $data; } $statvars['tradesums'] = $tradesums; $query = C::t('forum_trade')->fetch_all_statvars('credittradesum'); foreach($query as $data) { $credittradesums[] = $data; } $statvars['credittradesums'] = $credittradesums; $query = C::t('forum_trade')->fetch_all_statvars('totalitems'); foreach($query as $data) { $totalitems[] = $data; } $statvars['totalitems'] = $totalitems; $statvars['lastupdate'] = dgmdate(TIMESTAMP); $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME); $statvars['lastupdated'] = TIMESTAMP; $_G['cache']['statvars']['trade'] = $statvars; savecache('statvars', $_G['cache']['statvars']); return $statvars; } function getstatvars_team() { global $_G; $statvars = array(); $team = array(); $forums = $moderators = $members = $fuptemp = array(); $categories = array(0 => array('fid' => 0, 'fup' => 0, 'type' => 'group', 'name' => $_G['setting']['bbname'])); $uids = array(); foreach(C::t('forum_moderator')->fetch_all_no_inherited() as $moderator) { $moderators[$moderator['fid']][] = $moderator['uid']; $uids[$moderator['uid']] = $moderator['uid']; } $totaloffdays = $totalol = $totalthismonthol = 0; $admins = array(); $members = C::t('common_member')->fetch_all($uids) + C::t('common_member')->fetch_all_by_adminid(array(1, 2)); $uids = array_keys($members); $onlinetime = $_G['setting']['oltimespan'] ? C::t('common_onlinetime')->fetch_all($uids) : array(); $member_status = C::t('common_member_status')->fetch_all($uids); $member_count = C::t('common_member_count')->fetch_all($uids); foreach($members as $uid => $member) { $member = array_merge($member, $member_status[$uid], $member_count[$uid], (array)$onlinetime[$uid]); $member['thismonthol'] = $member['thismonth']; $member['totalol'] = $member['total']; if($member['adminid'] == 1 || $member['adminid'] == 2) { $admins[] = $member['uid']; } $member['offdays'] = intval((TIMESTAMP - $member['lastactivity']) / 86400); $totaloffdays += $member['offdays']; if($_G['setting']['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']] = $member['uid']; } $totalthismonthposts = 0; foreach(C::t('forum_post')->fetch_all_author_posts_by_dateline(0, $uids, $_G['timestamp']-86400*30) as $post) { $members[$post['authorid']]['thismonthposts'] = $post['posts']; $totalthismonthposts += $post['posts']; } $totalmodposts = $totalmodactions = 0; if($_G['setting']['modworkstatus']) { $starttime = gmdate("Y-m-1", TIMESTAMP + $_G['setting']['timeoffset'] * 3600); foreach(C::t('forum_modwork')->fetch_all_user_count_by_dateline($starttime) as $member) { $members[$member['uid']]['modactions'] = $member['actioncount']; $totalmodactions += $member['actioncount']; } } $query = C::t('forum_forum')->fetch_all_by_status(1, 1); foreach($query as $val) { $forum = array('fid' => $val['fid'], 'fup' => $val['fup'], 'type' => $val['type'], 'name' => $val['name'], 'inheritedmod' => $val['inheritedmod']); $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)), ); loadcache('usergroups'); if(is_array($team)) { foreach($team['members'] as $uid => $member) { @$member['thismonthposts'] = intval($member['thismonthposts']); @$team['members'][$uid]['offdays'] = $member['offdays'] > $team['avgoffdays'] ? ''.$member['offdays'].'' : $member['offdays']; @$team['members'][$uid]['thismonthposts'] = $member['thismonthposts'] < $team['avgthismonthposts'] / 2 ? ''.$member['thismonthposts'].'' : $member['thismonthposts']; @$team['members'][$uid]['lastactivity'] = dgmdate($member['lastactivity'] + $timeoffset * 3600, 'd'); @$team['members'][$uid]['thismonthol'] = $member['thismonthol'] < $team['avgthismonthol'] / 2 ? ''.$member['thismonthol'].'' : $member['thismonthol']; @$team['members'][$uid]['totalol'] = $member['totalol'] < $team['avgtotalol'] / 2 ? ''.$member['totalol'].'' : $member['totalol']; @$team['members'][$uid]['modposts'] = $member['modposts'] < $team['avgmodposts'] / 2 ? ''.intval($member['modposts']).'' : intval($member['modposts']); @$team['members'][$uid]['modactions'] = $member['modactions'] < $team['avgmodactions'] / 2 ? ''.intval($member['modactions']).'' : intval($member['modactions']); @$team['members'][$uid]['grouptitle'] = $_G['cache']['usergroups'][$member['adminid']]['grouptitle']; } } $statvars['team'] = $team; $statvars['lastupdate'] = dgmdate(TIMESTAMP); $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME); $statvars['lastupdated'] = TIMESTAMP; $_G['cache']['statvars']['team'] = $statvars; savecache('statvars', $_G['cache']['statvars']); return $statvars; } function getstatvars_modworks() { global $_G; $statvars = array(); $before = $_GET['before']; $before = (isset($before) && $before > 0 && $before <= $_G['setting']['maxmodworksmonths']) ? intval($before) : 0 ; $modworks_starttime = $_GET['modworks_starttime']; $modworks_endtime = $_GET['modworks_endtime']; list($now['year'], $now['month'], $now['day']) = explode("-", dgmdate(TIMESTAMP, 'Y-n-j')); $monthlinks = array(); $uid = !empty($_GET['uid']) ? $_GET['uid'] : 0; for($i = 0; $i <= $_G['setting']['maxmodworksmonths']; $i++) { $month = date("Y-m", mktime(0, 0, 0, $now['month'] - $i, 1, $now['year'])); if($i != $before) { $monthlinks[$i] = "