PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/discuzx/upload/source/class/block/html/block_stat.php

https://github.com/bluelovers/Discuz
PHP | 200 lines | 185 code | 9 blank | 6 comment | 31 complexity | 5c3e6d6e1f5335443cac9267bf6441a7 MD5 | raw file
  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_blank.php 6757 2010-03-25 09:01:29Z cnteacher $
  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. global $_G;
  114. if(in_array('posts', $parameter['option']) || in_array('bbsnewposts', $parameter['option'])) {
  115. $sql = "SELECT sum(f.posts) AS posts, sum(f.todayposts) AS todayposts FROM ".DB::table('forum_forum')." f WHERE f.status='1'";
  116. $forum = DB::fetch_first($sql);
  117. }
  118. if(in_array('groups', $parameter['option']) || in_array('groupnewposts', $parameter['option'])) {
  119. loadcache('groupindex');
  120. }
  121. $index = count($parameter['option']) - 1;
  122. $html = '<div class="tns"><table cellspacing="0" cellpadding="4" border="0"><tbody><tr>';
  123. if(in_array('posts', $parameter['option'])) {
  124. $class = ($index-- == 0) ? ' class="bbn"' : '';
  125. $html .= "<th$class><p>".intval($forum['posts']).'</p>'.(!empty($parameter['posts_title']) ? $parameter['posts_title'] : lang('block/stat', 'stat_posts')).'</th>';
  126. }
  127. if(in_array('groups', $parameter['option'])) {
  128. $class = ($index-- == 0) ? ' class="bbn"' : '';
  129. $html .= "<th$class><p>".intval($_G['cache']['groupindex']['groupnum']).'</p>'.(!empty($parameter['groups_title']) ? $parameter['groups_title'] : lang('block/stat', 'stat_groups')).'</th>';
  130. }
  131. if(in_array('members', $parameter['option'])) {
  132. loadcache('userstats');
  133. $class = ($index-- == 0) ? ' class="bbn"' : '';
  134. $html .= "<th$class><p>".intval($_G['cache']['userstats']['totalmembers']).'</p>'.(!empty($parameter['members_title']) ? $parameter['members_title'] : lang('block/stat', 'stat_members')).'</th>';
  135. }
  136. if(in_array('groupnewposts', $parameter['option'])) {
  137. $class = ($index-- == 0) ? ' class="bbn"' : '';
  138. $html .= "<th$class><p>".intval($_G['cache']['groupindex']['todayposts']).'</p>'.(!empty($parameter['groupnewposts_title']) ? $parameter['groupnewposts_title'] : lang('block/stat', 'stat_groupnewposts')).'</th>';
  139. }
  140. if(in_array('bbsnewposts', $parameter['option'])) {
  141. $class = ($index-- == 0) ? ' class="bbn"' : '';
  142. $html .= "<th$class><p>".intval($forum['todayposts']).'</p>'.(!empty($parameter['bbsnewposts_title']) ? $parameter['bbsnewposts_title'] : lang('block/stat', 'stat_bbsnewposts')).'</th>';
  143. }
  144. if(in_array('bbslastposts', $parameter['option'])) {
  145. loadcache('historyposts');
  146. $postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array();
  147. $class = ($index-- == 0) ? ' class="bbn"' : '';
  148. $html .= "<th$class><p>".intval($postdata[0]).'</p>'.(!empty($parameter['bbslastposts_title']) ? $parameter['bbslastposts_title'] : lang('block/stat', 'stat_bbslastposts')).'</th>';
  149. }
  150. if(in_array('onlinemembers', $parameter['option'])) {
  151. $num = !empty($_G['cookie']['onlineusernum']) ? intval($_G['cookie']['onlineusernum']) : DB::result_first("SELECT count(*) FROM ".DB::table('common_session'));
  152. $class = ($index-- == 0) ? ' class="bbn"' : '';
  153. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['onlinemembers_title']) ? $parameter['onlinemembers_title'] : lang('block/stat', 'stat_onlinemembers')).'</th>';
  154. }
  155. if(in_array('maxmembers', $parameter['option'])) {
  156. loadcache('onlinerecord');
  157. $onlineinfo = explode("\t", $_G['cache']['onlinerecord']);
  158. $num = !empty($onlineinfo[0]) ? intval($onlineinfo[0]) : 0;
  159. $class = ($index-- == 0) ? ' class="bbn"' : '';
  160. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['maxmembers_title']) ? $parameter['maxmembers_title'] : lang('block/stat', 'stat_maxmembers')).'</th>';
  161. }
  162. if(in_array('doings', $parameter['option'])) {
  163. $num = DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_doing'));
  164. $class = ($index-- == 0) ? ' class="bbn"' : '';
  165. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['doings_title']) ? $parameter['doings_title'] : lang('block/stat', 'stat_doings')).'</th>';
  166. }
  167. if(in_array('blogs', $parameter['option'])) {
  168. $num = DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_blog'));
  169. $class = ($index-- == 0) ? ' class="bbn"' : '';
  170. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['blogs_title']) ? $parameter['blogs_title'] : lang('block/stat', 'stat_blogs')).'</th>';
  171. }
  172. if(in_array('albums', $parameter['option'])) {
  173. $num = DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_album'));
  174. $class = ($index-- == 0) ? ' class="bbn"' : '';
  175. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['albums_title']) ? $parameter['albums_title'] : lang('block/stat', 'stat_albums')).'</th>';
  176. }
  177. if(in_array('pics', $parameter['option'])) {
  178. $num = DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_pic'));
  179. $class = ($index-- == 0) ? ' class="bbn"' : '';
  180. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['pics_title']) ? $parameter['pics_title'] : lang('block/stat', 'stat_pics')).'</th>';
  181. }
  182. if(in_array('shares', $parameter['option'])) {
  183. $num = DB::result_first('SELECT COUNT(*) FROM '.DB::table('home_share'));
  184. $class = ($index-- == 0) ? ' class="bbn"' : '';
  185. $html .= "<th$class><p>".intval($num).'</p>'.(!empty($parameter['shares_title']) ? $parameter['shares_title'] : lang('block/stat', 'stat_shares')).'</th>';
  186. }
  187. $html .= '</tr></tbody></table></div>';
  188. return array('html' => $html, 'data' => null);
  189. }
  190. }
  191. ?>