misc_stat.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: misc_stat.php 31889 2012-10-22 03:27:56Z liulanbo $
  6. */
  7. if(!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. define('CACHE_TIME', 18000);
  11. $op = $_GET['op'];
  12. if(!in_array($op, array('basic', 'trade', 'team', 'trend', 'modworks', 'memberlist', 'forumstat', 'trend'))) {
  13. $op = 'basic';
  14. }
  15. if(!$_G['group']['allowstatdata'] && $op != 'trend') {
  16. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  17. }
  18. $navtitle = lang('core', 'title_stats_'.$op).' - '.lang('core', 'title_stats');
  19. loadcache('statvars');
  20. if($op == 'basic') {
  21. $statvars = getstatvars('basic');
  22. extract($statvars);
  23. include template('forum/stat_main');
  24. } elseif($op == 'trade') {
  25. $statvars = getstatvars('trade');
  26. extract($statvars);
  27. include template('forum/stat_trade');
  28. } elseif($op == 'team') {
  29. $statvars = getstatvars('team');
  30. extract($statvars);
  31. include template('forum/stat_team');
  32. } elseif($op == 'modworks' && $_G['setting']['modworkstatus']) {
  33. $statvars = getstatvars('modworks');
  34. extract($statvars);
  35. if($_GET['exportexcel']) {
  36. $filename = 'stat_modworks_'.($username ? $username.'_' : '').$starttime.'_'.$endtime.'.csv';
  37. include template('forum/stat_misc_export');
  38. $csvstr = ob_get_contents();
  39. ob_end_clean();
  40. header('Content-Encoding: none');
  41. header('Content-Type: application/octet-stream');
  42. header('Content-Disposition: attachment; filename='.$filename);
  43. header('Pragma: no-cache');
  44. header('Expires: 0');
  45. if($_G['charset'] != 'gbk') {
  46. $csvstr = diconv($csvstr, $_G['charset'], 'GBK');
  47. }
  48. echo $csvstr;
  49. exit;
  50. } else {
  51. include template('forum/stat_misc');
  52. }
  53. } elseif($op == 'memberlist' && $_G['setting']['memliststatus']) {
  54. $statvars = getstatvars('memberlist');
  55. extract($statvars);
  56. include template('forum/stat_memberlist');
  57. } elseif($op == 'forumstat') {
  58. $statvars = getstatvars('forumstat');
  59. extract($statvars);
  60. include template('forum/stat_misc');
  61. } elseif($op == 'trend') {
  62. include libfile('misc/stat', 'include');
  63. } else {
  64. showmessage('undefined_action');
  65. }
  66. function getstatvars($type) {
  67. global $_G;
  68. $statvars = & $_G['cache']['statvars'][$type];
  69. if(!empty($statvars['lastupdated']) && TIMESTAMP - $statvars['lastupdated'] < CACHE_TIME) {
  70. return $statvars;
  71. }
  72. switch($type) {
  73. case 'basic':
  74. case 'trade':
  75. case 'onlinetime':
  76. case 'team':
  77. case 'modworks':
  78. case 'memberlist':
  79. case 'forumstat':
  80. $statvars = call_user_func('getstatvars_'.$type, ($type == 'forumstat' ? $_GET['fid'] : ''));//getstatvars_forumstat($_GET['fid']);
  81. break;
  82. }
  83. return $statvars;
  84. }
  85. function getstatvars_basic() {
  86. global $_G;
  87. $statvars = array();
  88. $statvars['members'] = C::t('common_member')->count();
  89. $members_runtime = C::t('common_member')->fetch_runtime();
  90. @$statvars['membersaddavg'] = round($statvars['members'] / $members_runtime);
  91. $statvars['memnonpost'] = C::t('common_member_count')->count_by_posts(0);
  92. $statvars['mempost'] = $statvars['members'] - $statvars['memnonpost'];
  93. $statvars['admins'] = C::t('common_member')->count_admins();
  94. $statvars['lastmember'] = C::t('common_member')->count_by_regdate(TIMESTAMP - 86400);
  95. $statvars['mempostpercent'] = number_format((double)$statvars['mempost'] / $statvars['members'] * 100, 2);
  96. $bestmember = C::t('forum_post')->fetch_all_top_post_author(0, $_G['timestamp']-86400, 1);
  97. $bestmember = $bestmember[0];
  98. $bestmember['author'] = $bestmember['username'];
  99. $statvars['bestmem'] = $bestmember['author'];
  100. $statvars['bestmemposts'] = $bestmember['posts'];
  101. $postsinfo = C::t('forum_post')->fetch_posts(0);
  102. $statvars['posts'] = $postsinfo['posts'];
  103. $runtime= $postsinfo['runtime'];
  104. @$statvars['postsaddavg'] = round($statvars['posts'] / $runtime);
  105. @$statvars['mempostavg'] = sprintf ("%01.2f", $statvars['posts'] / $statvars['members']);
  106. $statvars['forums'] = C::t('forum_forum')->fetch_all_fids(0, 'forum', 0, 0, 0, 1);
  107. $hotforum = C::t('forum_forum')->fetch_all_for_ranklist(1, '', 'posts', 0, 1);
  108. $statvars['hotforum'] = array('posts' => $hotforum[0]['posts'], 'threads' => $hotforum[0]['threads'], 'fid' => $hotforum[0]['fid'], 'name' => $hotforum[0]['name']);
  109. $statvars['threads'] = C::t('forum_thread')->count_all_thread();
  110. $statvars['postsaddtoday'] = C::t('forum_post')->count_by_dateline(0, TIMESTAMP - 86400);
  111. @$statvars['threadreplyavg'] = sprintf ("%01.2f", ($statvars['posts'] - $statvars['threads']) / $statvars['threads']);
  112. $statvars['membersaddtoday'] = $statvars['lastmember'];
  113. @$statvars['activeindex'] = round(($statvars['membersaddavg'] / $statvars['members'] + $statvars['postsaddavg'] / $statvars['posts']) * 1500 + $statvars['threadreplyavg'] * 10 + $statvars['mempostavg'] * 1 + $statvars['mempostpercent'] / 10);
  114. $statvars['lastupdate'] = dgmdate(TIMESTAMP);
  115. $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME);
  116. $statvars['lastupdated'] = TIMESTAMP;
  117. $_G['cache']['statvars']['basic'] = $statvars;
  118. savecache('statvars', $_G['cache']['statvars']);
  119. return $statvars;
  120. }
  121. function getstatvars_trade() {
  122. global $_G;
  123. $statvars = array();
  124. $query = C::t('forum_trade')->fetch_all_statvars('tradesum');
  125. foreach($query as $data) {
  126. $tradesums[] = $data;
  127. }
  128. $statvars['tradesums'] = $tradesums;
  129. $query = C::t('forum_trade')->fetch_all_statvars('credittradesum');
  130. foreach($query as $data) {
  131. $credittradesums[] = $data;
  132. }
  133. $statvars['credittradesums'] = $credittradesums;
  134. $query = C::t('forum_trade')->fetch_all_statvars('totalitems');
  135. foreach($query as $data) {
  136. $totalitems[] = $data;
  137. }
  138. $statvars['totalitems'] = $totalitems;
  139. $statvars['lastupdate'] = dgmdate(TIMESTAMP);
  140. $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME);
  141. $statvars['lastupdated'] = TIMESTAMP;
  142. $_G['cache']['statvars']['trade'] = $statvars;
  143. savecache('statvars', $_G['cache']['statvars']);
  144. return $statvars;
  145. }
  146. function getstatvars_team() {
  147. global $_G;
  148. $statvars = array();
  149. $team = array();
  150. $forums = $moderators = $members = $fuptemp = array();
  151. $categories = array(0 => array('fid' => 0, 'fup' => 0, 'type' => 'group', 'name' => $_G['setting']['bbname']));
  152. $uids = array();
  153. foreach(C::t('forum_moderator')->fetch_all_no_inherited() as $moderator) {
  154. $moderators[$moderator['fid']][] = $moderator['uid'];
  155. $uids[$moderator['uid']] = $moderator['uid'];
  156. }
  157. $totaloffdays = $totalol = $totalthismonthol = 0;
  158. $admins = array();
  159. $members = C::t('common_member')->fetch_all($uids) + C::t('common_member')->fetch_all_by_adminid(array(1, 2));
  160. $uids = array_keys($members);
  161. $onlinetime = $_G['setting']['oltimespan'] ? C::t('common_onlinetime')->fetch_all($uids) : array();
  162. $member_status = C::t('common_member_status')->fetch_all($uids);
  163. $member_count = C::t('common_member_count')->fetch_all($uids);
  164. foreach($members as $uid => $member) {
  165. $member = array_merge($member, $member_status[$uid], $member_count[$uid], (array)$onlinetime[$uid]);
  166. $member['thismonthol'] = $member['thismonth'];
  167. $member['totalol'] = $member['total'];
  168. if($member['adminid'] == 1 || $member['adminid'] == 2) {
  169. $admins[] = $member['uid'];
  170. }
  171. $member['offdays'] = intval((TIMESTAMP - $member['lastactivity']) / 86400);
  172. $totaloffdays += $member['offdays'];
  173. if($_G['setting']['oltimespan']) {
  174. $member['totalol'] = round($member['totalol'] / 60, 2);
  175. $member['thismonthol'] = gmdate('Yn', $member['lastactivity']) == gmdate('Yn', TIMESTAMP) ? round($member['thismonthol'] / 60, 2) : 0;
  176. $totalol += $member['totalol'];
  177. $totalthismonthol += $member['thismonthol'];
  178. }
  179. $members[$member['uid']] = $member;
  180. $uids[$member['uid']] = $member['uid'];
  181. }
  182. $totalthismonthposts = 0;
  183. foreach(C::t('forum_post')->fetch_all_author_posts_by_dateline(0, $uids, $_G['timestamp']-86400*30) as $post) {
  184. $members[$post['authorid']]['thismonthposts'] = $post['posts'];
  185. $totalthismonthposts += $post['posts'];
  186. }
  187. $totalmodposts = $totalmodactions = 0;
  188. if($_G['setting']['modworkstatus']) {
  189. $starttime = gmdate("Y-m-1", TIMESTAMP + $_G['setting']['timeoffset'] * 3600);
  190. foreach(C::t('forum_modwork')->fetch_all_user_count_by_dateline($starttime) as $member) {
  191. $members[$member['uid']]['modactions'] = $member['actioncount'];
  192. $totalmodactions += $member['actioncount'];
  193. }
  194. }
  195. $query = C::t('forum_forum')->fetch_all_by_status(1, 1);
  196. foreach($query as $val) {
  197. $forum = array('fid' => $val['fid'], 'fup' => $val['fup'], 'type' => $val['type'], 'name' => $val['name'], 'inheritedmod' => $val['inheritedmod']);
  198. $forum['moderators'] = count($moderators[$forum['fid']]);
  199. switch($forum['type']) {
  200. case 'group':
  201. $categories[$forum['fid']] = $forum;
  202. $forums[$forum['fid']][$forum['fid']] = $forum;
  203. $catfid = $forum['fid'];
  204. break;
  205. case 'forum':
  206. $forums[$forum['fup']][$forum['fid']] = $forum;
  207. $fuptemp[$forum['fid']] = $forum['fup'];
  208. $catfid = $forum['fup'];
  209. break;
  210. case 'sub':
  211. $forums[$fuptemp[$forum['fup']]][$forum['fid']] = $forum;
  212. $catfid = $fuptemp[$forum['fup']];
  213. break;
  214. }
  215. if(!empty($moderators[$forum['fid']])) {
  216. $categories[$catfid]['moderating'] = 1;
  217. }
  218. }
  219. foreach($categories as $fid => $category) {
  220. if(empty($category['moderating'])) {
  221. unset($categories[$fid]);
  222. }
  223. }
  224. $team = array (
  225. 'categories' => $categories,
  226. 'forums' => $forums,
  227. 'admins' => $admins,
  228. 'moderators' => $moderators,
  229. 'members' => $members,
  230. 'avgoffdays' => @($totaloffdays / count($members)),
  231. 'avgthismonthposts' => @($totalthismonthposts / count($members)),
  232. 'avgtotalol' => @($totalol / count($members)),
  233. 'avgthismonthol' => @($totalthismonthol / count($members)),
  234. 'avgmodactions' => @($totalmodactions / count($members)),
  235. );
  236. loadcache('usergroups');
  237. if(is_array($team)) {
  238. foreach($team['members'] as $uid => $member) {
  239. @$member['thismonthposts'] = intval($member['thismonthposts']);
  240. @$team['members'][$uid]['offdays'] = $member['offdays'] > $team['avgoffdays'] ? '<b><i>'.$member['offdays'].'</i></b>' : $member['offdays'];
  241. @$team['members'][$uid]['thismonthposts'] = $member['thismonthposts'] < $team['avgthismonthposts'] / 2 ? '<b><i>'.$member['thismonthposts'].'</i></b>' : $member['thismonthposts'];
  242. @$team['members'][$uid]['lastactivity'] = dgmdate($member['lastactivity'] + $timeoffset * 3600, 'd');
  243. @$team['members'][$uid]['thismonthol'] = $member['thismonthol'] < $team['avgthismonthol'] / 2 ? '<b><i>'.$member['thismonthol'].'</i></b>' : $member['thismonthol'];
  244. @$team['members'][$uid]['totalol'] = $member['totalol'] < $team['avgtotalol'] / 2 ? '<b><i>'.$member['totalol'].'</i></b>' : $member['totalol'];
  245. @$team['members'][$uid]['modposts'] = $member['modposts'] < $team['avgmodposts'] / 2 ? '<b><i>'.intval($member['modposts']).'</i></b>' : intval($member['modposts']);
  246. @$team['members'][$uid]['modactions'] = $member['modactions'] < $team['avgmodactions'] / 2 ? '<b><i>'.intval($member['modactions']).'</i></b>' : intval($member['modactions']);
  247. @$team['members'][$uid]['grouptitle'] = $_G['cache']['usergroups'][$member['adminid']]['grouptitle'];
  248. }
  249. }
  250. $statvars['team'] = $team;
  251. $statvars['lastupdate'] = dgmdate(TIMESTAMP);
  252. $statvars['nextupdate'] = dgmdate(TIMESTAMP + CACHE_TIME);
  253. $statvars['lastupdated'] = TIMESTAMP;
  254. $_G['cache']['statvars']['team'] = $statvars;
  255. savecache('statvars', $_G['cache']['statvars']);
  256. return $statvars;
  257. }
  258. function getstatvars_modworks() {
  259. global $_G;
  260. $statvars = array();
  261. $before = $_GET['before'];
  262. $before = (isset($before) && $before > 0 && $before <= $_G['setting']['maxmodworksmonths']) ? intval($before) : 0 ;
  263. $modworks_starttime = $_GET['modworks_starttime'];
  264. $modworks_endtime = $_GET['modworks_endtime'];
  265. list($now['year'], $now['month'], $now['day']) = explode("-", dgmdate(TIMESTAMP, 'Y-n-j'));
  266. $monthlinks = array();
  267. $uid = !empty($_GET['uid']) ? $_GET['uid'] : 0;
  268. for($i = 0; $i <= $_G['setting']['maxmodworksmonths']; $i++) {
  269. $month = date("Y-m", mktime(0, 0, 0, $now['month'] - $i, 1, $now['year']));
  270. if($i != $before) {
  271. $monthlinks[$i] = "<li><a href=\"misc.php?mod=stat&op=modworks&before=$i&uid=$uid\" hidefocus=\"true\">$month</a></li>";
  272. } else {
  273. if(!isset($_GET['before']) && $modworks_starttime && $modworks_endtime) {
  274. $starttime = dgmdate(strtotime($modworks_starttime), 'Y-m-d');
  275. $endtime = dgmdate(strtotime($modworks_endtime), 'Y-m-d');
  276. $monthlinks[$i] = "<li><a href=\"misc.php?mod=stat&op=modworks&before=$i&uid=$uid\" hidefocus=\"true\">$month</a></li>";
  277. } else {
  278. $starttime = $month.'-01';
  279. $endtime = date("Y-m-01", mktime(0, 0, 0, $now['month'] - $i + 1 , 1, $now['year']));
  280. $monthlinks[$i] = "<li class=\"xw1 a\"><a href=\"misc.php?mod=stat&op=modworks&before=$i&uid=$uid\" hidefocus=\"true\">$month</a></li>";
  281. }
  282. }
  283. }
  284. $statvars['monthlinks'] = $monthlinks;
  285. $expiretime = date('Y-m', mktime(0, 0, 0, $now['month'] - $_G['setting']['maxmodworksmonths'] - 1, 1, $now['year']));
  286. $mergeactions = array('OPN' => 'CLS', 'ECL' => 'CLS', 'UEC' => 'CLS', 'EOP' => 'CLS', 'UEO' => 'CLS',
  287. 'UDG' => 'DIG', 'EDI' =>'DIG', 'UED' => 'DIG', 'UST' => 'STK', 'EST' => 'STK', 'UES' => 'STK',
  288. 'DLP' => 'DEL', 'PRN' => 'DEL', 'UDL' => 'DEL', 'UHL' => 'HLT', 'EHL' => 'HLT', 'UEH' => 'HLT',
  289. 'SPL' => 'MRG', 'ABL' => 'EDT', 'RBL' => 'EDT');
  290. if($uid) {
  291. $uid = $_GET['uid'];
  292. $member = getuserbyuid($uid, 1);
  293. if(!$member || $member['adminid'] == 0) {
  294. showmessage('member_not_found');
  295. }
  296. $modactions = $totalactions = array();
  297. $starttime_dateline = strtotime($starttime);
  298. $endtime_dateline = strtotime($endtime);
  299. $endtime_dateline = $endtime_dateline > TIMESTAMP ? TIMESTAMP : $endtime_dateline;
  300. while($starttime_dateline <= $endtime_dateline) {
  301. $modactions[dgmdate($starttime_dateline, 'Y-m-d')] = array();
  302. $starttime_dateline += 86400;
  303. }
  304. foreach(C::t('forum_modwork')->fetch_all_by_uid_dateline($uid, $starttime, $endtime) as $data) {
  305. if(isset($mergeactions[$data['modaction']])) {
  306. $data['modaction'] = $mergeactions[$data['modaction']];
  307. }
  308. $modactions[$data['dateline']]['total'] += $data['count'];
  309. $modactions[$data['dateline']][$data['modaction']]['count'] += $data['count'];
  310. $modactions[$data['dateline']][$data['modaction']]['posts'] += $data['posts'];
  311. $totalactions[$data['modaction']]['count'] += $data['count'];
  312. $totalactions[$data['modaction']]['posts'] += $data['posts'];
  313. $totalactions['total'] += $data['count'];
  314. }
  315. $statvars['modactions'] = $modactions;
  316. $statvars['totalactions'] = $totalactions;
  317. $statvars['username'] = $member['username'];
  318. } else {
  319. $members = $total = array();
  320. $uids = $totalmodactions = 0;
  321. $members = C::t('common_member')->fetch_all_by_adminid(array(1, 2, 3));
  322. foreach(C::t('forum_modwork')->fetch_all_user_count_posts_by_uid_dateline(array_keys($members), $starttime, $endtime) as $data) {
  323. if(isset($mergeactions[$data['modaction']])) {
  324. $data['modaction'] = $mergeactions[$data['modaction']];
  325. }
  326. $members[$data['uid']]['total'] += $data['count'];
  327. $totalmodactioncount += $data['count'];
  328. $members[$data['uid']][$data['modaction']]['count'] += $data['count'];
  329. $members[$data['uid']][$data['modaction']]['posts'] += $data['posts'];
  330. $total[$data['modaction']]['count'] += $data['count'];
  331. $total[$data['modaction']]['posts'] += $data['posts'];
  332. $total['total'] += $data['count'];
  333. }
  334. $avgmodactioncount = @($totalmodactioncount / count($members));
  335. foreach($members as $id => $member) {
  336. $members[$id]['totalactions'] = intval($members[$id]['totalactions']);
  337. $members[$id]['username'] = ($members[$id]['total'] < $avgmodactioncount / 2) ? ('<b><i>'.$members[$id]['username'].'</i></b>') : ($members[$id]['username']);
  338. }
  339. if(!empty($before)) {
  340. C::t('forum_modwork')->delete_by_dateline($expiretime.'-01');
  341. } else {
  342. $members['thismonth'] = $starttime;
  343. $members['lastupdate'] = TIMESTAMP;
  344. unset($members['lastupdate'], $members['thismonth']);
  345. }
  346. $statvars['members'] = $members;
  347. $statvars['total'] = $total;
  348. }
  349. $modactioncode = lang('forum/modaction');
  350. $bgarray = array();
  351. foreach($modactioncode as $key => $val) {
  352. if(isset($mergeactions[$key])) {
  353. unset($modactioncode[$key]);
  354. }
  355. }
  356. $statvars['modactioncode'] = $modactioncode;
  357. $tdcols = count($modactioncode) + 1;
  358. $tdwidth = floor(90 / ($tdcols - 1)).'%';
  359. $statvars['tdwidth'] = $tdwidth;
  360. $statvars['uid'] = $uid;
  361. $statvars['starttime'] = $starttime;
  362. $statvars['endtime'] = $endtime;
  363. return $statvars;
  364. }
  365. function getstatvars_memberlist() {
  366. global $_G;
  367. $statvars = array();
  368. $srchmem = $_GET['srchmem'];
  369. $page = $_G['setting']['membermaxpages'] && isset($_GET['page']) && $_GET['page'] > $_G['setting']['membermaxpages'] ? 1 : $_GET['page'];
  370. if(empty($page)) {
  371. $page = 1;
  372. }
  373. $start_limit = ($page - 1) * $_G['setting']['memberperpage'];
  374. $statvars['memberlist'] = C::t('common_member')->fetch_all_stat_memberlist($srchmem, $_GET['order'], $_GET['asc'] ? 'ASC' : 'DESC', $start_limit, $_G['setting']['memberperpage']);
  375. $num = !empty($srchmem) ? C::t('common_member')->count_by_like_username($srchmem) : C::t('common_member')->count();
  376. $multipage = multi($num, $_G['setting']['memberperpage'], $page, 'misc.php?mod=stat&op=memberlist&srchmem='.rawurlencode($srchmem).'&order='.rawurlencode($_GET['order']).'&asc='.rawurlencode($_GET['asc']), $_G['setting']['membermaxpages']);
  377. $statvars['multipage'] = $multipage;
  378. return $statvars;
  379. }
  380. function getstatvars_forumstat($fid) {
  381. global $_G;
  382. $xml = "<chart>\n";
  383. $statvars = array();
  384. $monthdays = array('31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
  385. if(!$fid) {
  386. $query = C::t('forum_forum')->fetch_all_fids();
  387. $forums = array();
  388. foreach($query as $val) {
  389. $forums[] = array('fid' => $val['fid'], 'type' => $val['type'], 'name' => $val['name'], 'posts' => $val['posts']);
  390. }
  391. $statvars['forums'] = $forums;
  392. } else {
  393. $foruminfo = C::t('forum_forum')->fetch($fid);
  394. $statvars['foruminfo'] = array('fid' => $foruminfo['fid'], 'name' => $foruminfo['name'], 'posts' => $foruminfo['posts'], 'threads' => $foruminfo['threads'], 'todayposts' => $foruminfo['todayposts']);
  395. $current_date = $end_date = date('Y-m-d');
  396. $current_month = $end_month = date('Y-m');
  397. $current_month_start = $end_month_start = $current_month . '-01';
  398. if($_GET['month']) {
  399. $end_month = trim($_GET['month']);
  400. $month = substr($end_month, strpos($end_month, '-') + 1);
  401. $end_date = $end_month . '-' . $monthdays[$month - 1];
  402. $end_month_start = $end_month . '-' . '01';
  403. }
  404. $statvars['month'] = $end_month;
  405. $logs = array();
  406. $xml .= "<xaxis>\n";
  407. $xmlvalue = '';
  408. $xaxisindex = 0;
  409. foreach(C::t('forum_statlog')->fetch_all_by_logdate($end_month_start, $end_date, $fid) as $log) {
  410. $logs[] = $log;
  411. list($yyyy, $mm, $dd) = explode('-', $log['logdate']);
  412. $xaxisindex++;
  413. $xml .= "<value xid=\"{$xaxisindex}\">{$mm}{$dd}</value>\n";
  414. $xmlvalue .= "<value xid=\"{$xaxisindex}\">{$log['value']}</value>\n";
  415. }
  416. $xml .= "</xaxis>\n";
  417. $xml .= "<graphs>\n";
  418. $xml .= "<graph gid=\"0\" title=\"".diconv(lang('spacecp', 'do_stat_post_number'), CHARSET, 'UTF-8')."\">\n";
  419. $xml .= $xmlvalue;
  420. $xml .= "</graph>\n";
  421. $xml .= "</graphs>\n";
  422. $xml .= "</chart>\n";
  423. if($_GET['xml']) {
  424. @header("Expires: -1");
  425. @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
  426. @header("Pragma: no-cache");
  427. @header("Content-type: application/xml; charset=utf-8");
  428. echo $xml;
  429. exit;
  430. }
  431. $statvars['logs'] = $logs;
  432. $mindate = C::t('forum_statlog')->fetch_min_logdate_by_fid($fid);
  433. list($minyear, $minmonth, $minday) = explode('-', $mindate);
  434. $minmonth = $minyear . '-' . $minmonth;
  435. $month = $minmonth;
  436. $monthlist = array();
  437. while(datecompare($month, $current_month) <= 0) {
  438. $monthlist[] = $month;
  439. $month = getnextmonth($month);
  440. }
  441. $statvars['monthlist'] = $monthlist;
  442. $monthposts = array();
  443. foreach(C::t('forum_statlog')->fetch_all_by_fid_type($fid) as $data) {
  444. list($year, $month, $day) = explode('-', $data['logdate']);
  445. if(isset($monthposts[$year.'-'.$month])) {
  446. $monthposts[$year.'-'.$month] += $data['value'];
  447. } else {
  448. $monthposts[$year.'-'.$month] = $data['value'];
  449. }
  450. }
  451. $statvars['monthposts'] = $monthposts;
  452. }
  453. $statvars['statuspara'] = "path=&settings_file=data/stat_setting.xml&data_file=".urlencode("misc.php?mod=stat&op=forumstat&fid=$fid&month={$_GET['month']}&xml=1");
  454. return $statvars;
  455. }
  456. function datecompare($date1, $date2) {
  457. $year1 = $month1 = $day1 = 1;
  458. $year2 = $month2 = $day2 = 1;
  459. list($year1, $month1, $day1) = explode('-', $date1);
  460. list($year2, $month2, $day2) = explode('-', $date2);
  461. return mktime(0, 0, 0, $month1, $day1, $year1) - mktime(0, 0, 0, $month2, $day2, $year2);
  462. }
  463. function getnextmonth($monthdate) {
  464. list($year, $month) = explode('-', $monthdate);
  465. $month = $month + 1;
  466. if($month > 12) {
  467. $month = 1;
  468. $year = $year + 1;
  469. }
  470. $month = sprintf("%02d", $month);
  471. return $year . '-' . $month;
  472. }