block_stat.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: block_stat.php 25525 2011-11-14 04:39:11Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('commonblock_html', 'class/block/html');
  12. class block_stat extends commonblock_html {
  13. function block_stat() {}
  14. function name() {
  15. return lang('blockclass', 'blockclass_html_script_stat');
  16. }
  17. function getsetting() {
  18. global $_G;
  19. $settings = array(
  20. 'option' => array(
  21. 'title' => 'stat_option',
  22. 'type' => 'mcheckbox',
  23. 'value' => array(
  24. array('posts', 'stat_option_posts'),
  25. array('groups', 'stat_option_groups'),
  26. array('members', 'stat_option_members'),
  27. array('groupnewposts', 'stat_option_groupnewposts'),
  28. array('bbsnewposts', 'stat_option_bbsnewposts'),
  29. array('bbslastposts', 'stat_option_bbslastposts'),
  30. array('onlinemembers', 'stat_option_onlinemembers'),
  31. array('maxmembers', 'stat_option_maxmembers'),
  32. array('doings', 'stat_option_doings'),
  33. array('blogs', 'stat_option_blogs'),
  34. array('albums', 'stat_option_albums'),
  35. array('pics', 'stat_option_pics'),
  36. array('shares', 'stat_option_shares'),
  37. ),
  38. 'default' => array('posts', 'groups', 'members')
  39. ),
  40. 'tip' => array(
  41. 'title' => 'stat_edit_showtitle',
  42. 'type' => lang('block/stat', 'stat_edit_showtitle_detail'),
  43. ),
  44. 'posts_title' => array(
  45. 'title' => 'stat_option_posts',
  46. 'type' => 'text',
  47. 'default' => lang('block/stat', 'stat_posts')
  48. ),
  49. 'groups_title' => array(
  50. 'title' => 'stat_option_groups',
  51. 'type' => 'text',
  52. 'default' => lang('block/stat', 'stat_groups')
  53. ),
  54. 'members_title' => array(
  55. 'title' => 'stat_option_members',
  56. 'type' => 'text',
  57. 'default' => lang('block/stat', 'stat_members')
  58. ),
  59. 'groupnewposts_title' => array(
  60. 'title' => 'stat_option_groupnewposts',
  61. 'type' => 'text',
  62. 'default' => lang('block/stat', 'stat_groupnewposts')
  63. ),
  64. 'bbsnewposts_title' => array(
  65. 'title' => 'stat_option_bbsnewposts',
  66. 'type' => 'text',
  67. 'default' => lang('block/stat', 'stat_bbsnewposts')
  68. ),
  69. 'bbslastposts_title' => array(
  70. 'title' => 'stat_option_bbslastposts',
  71. 'type' => 'text',
  72. 'default' => lang('block/stat', 'stat_bbslastposts')
  73. ),
  74. 'onlinemembers_title' => array(
  75. 'title' => 'stat_option_onlinemembers',
  76. 'type' => 'text',
  77. 'default' => lang('block/stat', 'stat_onlinemembers')
  78. ),
  79. 'maxmembers_title' => array(
  80. 'title' => 'stat_option_maxmembers',
  81. 'type' => 'text',
  82. 'default' => lang('block/stat', 'stat_maxmembers')
  83. ),
  84. 'doings_title' => array(
  85. 'title' => 'stat_option_doings',
  86. 'type' => 'text',
  87. 'default' => lang('block/stat', 'stat_doings')
  88. ),
  89. 'blogs_title' => array(
  90. 'title' => 'stat_option_blogs',
  91. 'type' => 'text',
  92. 'default' => lang('block/stat', 'stat_blogs')
  93. ),
  94. 'albums_title' => array(
  95. 'title' => 'stat_option_albums',
  96. 'type' => 'text',
  97. 'default' => lang('block/stat', 'stat_albums')
  98. ),
  99. 'pics_title' => array(
  100. 'title' => 'stat_option_pics',
  101. 'type' => 'text',
  102. 'default' => lang('block/stat', 'stat_pics')
  103. ),
  104. 'shares_title' => array(
  105. 'title' => 'stat_option_shares',
  106. 'type' => 'text',
  107. 'default' => lang('block/stat', 'stat_shares')
  108. ),
  109. );
  110. return $settings;
  111. }
  112. function getdata($style, $parameter) {
  113. $parameter = $this->cookparameter($parameter);
  114. global $_G;
  115. if(in_array('posts', $parameter['option']) || in_array('bbsnewposts', $parameter['option'])) {
  116. $sql = "SELECT sum(f.posts) AS posts, sum(f.todayposts) AS todayposts FROM ".DB::table('forum_forum')." f WHERE f.status='1'";
  117. $forum = DB::fetch_first($sql);
  118. }
  119. if(in_array('groups', $parameter['option']) || in_array('groupnewposts', $parameter['option'])) {
  120. loadcache('groupindex');
  121. }
  122. $index = count($parameter['option']) - 1;
  123. $html = '<div class="tns"><table cellspacing="0" cellpadding="4" border="0"><tbody><tr>';
  124. if(in_array('posts', $parameter['option'])) {
  125. $class = ($index-- == 0) ? ' class="bbn"' : '';
  126. $html .= "<th$class><p>".intval($forum['posts']).'</p>'.(!empty($parameter['posts_title']) ? $parameter['posts_title'] : lang('block/stat', 'stat_posts')).'</th>';
  127. }
  128. if(in_array('groups', $parameter['option'])) {
  129. $class = ($index-- == 0) ? ' class="bbn"' : '';
  130. $html .= "<th$class><p>".intval($_G['cache']['groupindex']['groupnum']).'</p>'.(!empty($parameter['groups_title']) ? $parameter['groups_title'] : lang('block/stat', 'stat_groups')).'</th>';
  131. }
  132. if(in_array('members', $parameter['option'])) {
  133. loadcache('userstats');
  134. $class = ($index-- == 0) ? ' class="bbn"' : '';
  135. $html .= "<th$class><p>".intval($_G['cache']['userstats']['totalmembers']).'</p>'.(!empty($parameter['members_title']) ? $parameter['members_title'] : lang('block/stat', 'stat_members')).'</th>';
  136. }
  137. if(in_array('groupnewposts', $parameter['option'])) {
  138. $class = ($index-- == 0) ? ' class="bbn"' : '';
  139. $html .= "<th$class><p>".intval($_G['cache']['groupindex']['todayposts']).'</p>'.(!empty($parameter['groupnewposts_title']) ? $parameter['groupnewposts_title'] : lang('block/stat', 'stat_groupnewposts')).'</th>';
  140. }
  141. if(in_array('bbsnewposts', $parameter['option'])) {
  142. $class = ($index-- == 0) ? ' class="bbn"' : '';
  143. $html .= "<th$class><p>".intval($forum['todayposts']).'</p>'.(!empty($parameter['bbsnewposts_title']) ? $parameter['bbsnewposts_title'] : lang('block/stat', 'stat_bbsnewposts')).'</th>';
  144. }
  145. if(in_array('bbslastposts', $parameter['option'])) {
  146. loadcache('historyposts');
  147. $postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array();
  148. $class = ($index-- == 0) ? ' class="bbn"' : '';
  149. $html .= "<th$class><p>".intval($postdata[0]).'</p>'.(!empty($parameter['bbslastposts_title']) ? $parameter['bbslastposts_title'] : lang('block/stat', 'stat_bbslastposts')).'</th>';
  150. }
  151. if(in_array('onlinemembers', $parameter['option'])) {
  152. $num = !empty($_G['cookie']['onlineusernum']) ? intval($_G['cookie']['onlineusernum']) : C::app()->session->count();
  153. $class = ($index-- == 0) ? ' class="bbn"' : '';
  154. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['onlinemembers_title']) ? $parameter['onlinemembers_title'] : lang('block/stat', 'stat_onlinemembers')).'</th>';
  155. }
  156. if(in_array('maxmembers', $parameter['option'])) {
  157. loadcache('onlinerecord');
  158. $onlineinfo = explode("\t", $_G['cache']['onlinerecord']);
  159. $num = !empty($onlineinfo[0]) ? intval($onlineinfo[0]) : 0;
  160. $class = ($index-- == 0) ? ' class="bbn"' : '';
  161. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['maxmembers_title']) ? $parameter['maxmembers_title'] : lang('block/stat', 'stat_maxmembers')).'</th>';
  162. }
  163. if(in_array('doings', $parameter['option'])) {
  164. $num = C::t('home_doing')->count();
  165. $class = ($index-- == 0) ? ' class="bbn"' : '';
  166. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['doings_title']) ? $parameter['doings_title'] : lang('block/stat', 'stat_doings')).'</th>';
  167. }
  168. if(in_array('blogs', $parameter['option'])) {
  169. $num = C::t('home_blog')->count();
  170. $class = ($index-- == 0) ? ' class="bbn"' : '';
  171. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['blogs_title']) ? $parameter['blogs_title'] : lang('block/stat', 'stat_blogs')).'</th>';
  172. }
  173. if(in_array('albums', $parameter['option'])) {
  174. $num = C::t('home_album')->count();
  175. $class = ($index-- == 0) ? ' class="bbn"' : '';
  176. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['albums_title']) ? $parameter['albums_title'] : lang('block/stat', 'stat_albums')).'</th>';
  177. }
  178. if(in_array('pics', $parameter['option'])) {
  179. $num = C::t('home_pic')->count();
  180. $class = ($index-- == 0) ? ' class="bbn"' : '';
  181. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['pics_title']) ? $parameter['pics_title'] : lang('block/stat', 'stat_pics')).'</th>';
  182. }
  183. if(in_array('shares', $parameter['option'])) {
  184. $num = C::t('home_share')->count();
  185. $class = ($index-- == 0) ? ' class="bbn"' : '';
  186. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['shares_title']) ? $parameter['shares_title'] : lang('block/stat', 'stat_shares')).'</th>';
  187. }
  188. $html .= '</tr></tbody></table></div>';
  189. return array('html' => $html, 'data' => null);
  190. }
  191. }
  192. ?>