misc_stat.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: misc_stat.php 34937 2014-09-04 03:08:56Z hypowang $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if (empty($_G['setting']['updatestat'])) {
  12. showmessage('not_open_updatestat');
  13. }
  14. $stat_hash = md5($_G['setting']['siteuniqueid'] . "\t" . substr($_G['timestamp'], 0, 6));
  15. if (!checkperm('allowstatdata') && $_GET['hash'] != $stat_hash) {
  16. showmessage('no_privilege_statdata');
  17. }
  18. $cols = array();
  19. $cols['login'] = array('login', 'mobilelogin', 'connectlogin', 'register', 'invite', 'appinvite');
  20. if (!$_G['setting']['connect']['allow']) {
  21. unset($cols['login'][2]);
  22. }
  23. $cols['forum'] = array('thread', 'poll', 'activity', 'reward', 'debate', 'trade', 'post');
  24. $cols['tgroup'] = array('group', 'groupthread', 'grouppost');
  25. $cols['home'] = array('doing', 'docomment', 'blog', 'blogcomment', 'pic', 'piccomment', 'share', 'sharecomment');
  26. $cols['space'] = array('wall', 'poke', 'click', 'sendpm', 'addfriend', 'friend');
  27. $type = !empty($_GET['types']) ? array() : (empty($_GET['type']) ? 'all' : $_GET['type']);
  28. $primarybegin = !empty($_GET['primarybegin']) ? $_GET['primarybegin'] : dgmdate($_G['timestamp'] - 2592000, 'Y-m-d');
  29. $primaryend = !empty($_GET['primaryend']) ? $_GET['primaryend'] : dgmdate($_G['timestamp'], 'Y-m-d');
  30. $beginunixstr = strtotime($primarybegin);
  31. $endunixstr = strtotime($primaryend);
  32. if ($beginunixstr > $endunixstr) {
  33. showmessage('start_time_is_greater_than_end_time', NULL, array(), array('return' => true));
  34. } else if ($beginunixstr == $endunixstr) {
  35. showmessage('start_time_end_time_is_equal_to', NULL, array(), array('return' => true));
  36. }
  37. if (!empty($_GET['xml'])) {
  38. $xaxis = '';
  39. $graph = array();
  40. $count = 1;
  41. $begin = dgmdate($beginunixstr, 'Ymd');
  42. $end = dgmdate($endunixstr, 'Ymd');
  43. $field = '*';
  44. if (!empty($_GET['merge'])) {
  45. if (empty($_GET['types'])) {
  46. $_GET['types'] = array_merge($cols['login'], $cols['forum'], $cols['tgroup'], $cols['home'], $cols['space']);
  47. }
  48. if (!array_diff($_GET['types'], array_merge($cols['login'], $cols['forum'], $cols['tgroup'], $cols['home'], $cols['space']))) {
  49. $field = 'daytime,`' . implode('`+`', $_GET['types']) . '` AS statistic';
  50. }
  51. $type = 'statistic';
  52. }
  53. foreach (C::t('common_stat')->fetch_all($begin, $end, $field) as $value) {
  54. $xaxis .= "<value xid='$count'>" . substr($value['daytime'], 4, 4) . "</value>";
  55. if ($type == 'all') {
  56. foreach ($cols as $ck => $cvs) {
  57. if ($ck == 'login') {
  58. $graph['login'] .= "<value xid='$count'>$value[login]</value>";
  59. $graph['register'] .= "<value xid='$count'>$value[register]</value>";
  60. } else {
  61. $num = 0;
  62. foreach ($cvs as $cvk) {
  63. $num = $value[$cvk] + $num;
  64. }
  65. $graph[$ck] .= "<value xid='$count'>" . $num . "</value>";
  66. }
  67. }
  68. } else {
  69. if (empty($_GET['types']) || !empty($_GET['merge'])) {
  70. $graph[$type] .= "<value xid='$count'>" . $value[$type] . "</value>";
  71. } else {
  72. foreach ($_GET['types'] as $t) {
  73. $graph[$t] .= "<value xid='$count'>" . $value[$t] . "</value>";
  74. }
  75. }
  76. }
  77. $count++;
  78. }
  79. $xml = '';
  80. $xml .= '<' . "?xml version=\"1.0\" encoding=\"utf-8\"?>";
  81. $xml .= '<chart><xaxis>';
  82. $xml .= $xaxis;
  83. $xml .= "</xaxis><graphs>";
  84. $count = 0;
  85. foreach ($graph as $key => $value) {
  86. $xml .= "<graph gid='$count' title='" . diconv(lang('spacecp', "do_stat_$key"), CHARSET, 'utf8') . "'>";
  87. $xml .= $value;
  88. $xml .= '</graph>';
  89. $count++;
  90. }
  91. $xml .= '</graphs></chart>';
  92. @header("Expires: -1");
  93. @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
  94. @header("Pragma: no-cache");
  95. @header("Content-type: application/xml; charset=utf-8");
  96. echo $xml;
  97. exit();
  98. }
  99. $actives = array($type => ' class="a"');
  100. require_once libfile('function/home');
  101. $siteurl = getsiteurl();
  102. $types = '';
  103. $merge = !empty($_GET['merge']) ? '&merge=1' : '';
  104. foreach ($_GET['types'] as $value) {
  105. $types .= '&types[]=' . $value;
  106. $actives[$value] = ' class="a"';
  107. }
  108. $statuspara = "path=&settings_file=data/stat_setting.xml&data_file=" . urlencode("misc.php?mod=stat&op=trend&xml=1&type=$type&primarybegin=$primarybegin&primaryend=$primaryend{$types}{$merge}&hash=$stat_hash");
  109. include template('home/misc_stat');