block_otherstat.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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_otherstat.php 25525 2011-11-14 04:39:11Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_otherstat extends discuz_block {
  12. function block_otherstat() {}
  13. function name() {
  14. return lang('blockclass', 'blockclass_other_script_stat');
  15. }
  16. function blockclass() {
  17. return array('otherstat', lang('blockclass', 'blockclass_other_stat'));
  18. }
  19. function fields() {
  20. return array(
  21. 'posts' => array('name' => lang('blockclass', 'blockclass_other_stat_posts'), 'formtype' => 'text', 'datatype' => 'int'),
  22. 'posts_title' => array('name' => lang('blockclass', 'blockclass_other_stat_posts_title'), 'formtype' => 'text', 'datatype' => 'string'),
  23. 'groups' => array('name' => lang('blockclass', 'blockclass_other_stat_groups'), 'formtype' => 'text', 'datatype' => 'int'),
  24. 'groups_title' => array('name' => lang('blockclass', 'blockclass_other_stat_groups_title'), 'formtype' => 'text', 'datatype' => 'string'),
  25. 'members' => array('name' => lang('blockclass', 'blockclass_other_stat_members'), 'formtype' => 'text', 'datatype' => 'int'),
  26. 'members_title' => array('name' => lang('blockclass', 'blockclass_other_stat_members_title'), 'formtype' => 'text', 'datatype' => 'string'),
  27. 'groupnewposts' => array('name' => lang('blockclass', 'blockclass_other_stat_groupnewposts'), 'formtype' => 'text', 'datatype' => 'int'),
  28. 'groupnewposts_title' => array('name' => lang('blockclass', 'blockclass_other_stat_groupnewposts_title'), 'formtype' => 'text', 'datatype' => 'string'),
  29. 'bbsnewposts' => array('name' => lang('blockclass', 'blockclass_other_stat_bbsnewposts'), 'formtype' => 'text', 'datatype' => 'int'),
  30. 'bbsnewposts_title' => array('name' => lang('blockclass', 'blockclass_other_stat_bbsnewposts_title'), 'formtype' => 'text', 'datatype' => 'string'),
  31. 'bbslastposts' => array('name' => lang('blockclass', 'blockclass_other_stat_bbslastposts'), 'formtype' => 'text', 'datatype' => 'int'),
  32. 'bbslastposts_title' => array('name' => lang('blockclass', 'blockclass_other_stat_bbslastposts_title'), 'formtype' => 'text', 'datatype' => 'string'),
  33. 'onlinemembers' => array('name' => lang('blockclass', 'blockclass_other_stat_onlinemembers'), 'formtype' => 'text', 'datatype' => 'int'),
  34. 'onlinemembers_title' => array('name' => lang('blockclass', 'blockclass_other_stat_onlinemembers_title'), 'formtype' => 'text', 'datatype' => 'string'),
  35. 'maxmembers' => array('name' => lang('blockclass', 'blockclass_other_stat_maxmembers'), 'formtype' => 'text', 'datatype' => 'int'),
  36. 'maxmembers_title' => array('name' => lang('blockclass', 'blockclass_other_stat_maxmembers_title'), 'formtype' => 'text', 'datatype' => 'string'),
  37. 'doings' => array('name' => lang('blockclass', 'blockclass_other_stat_doings'), 'formtype' => 'text', 'datatype' => 'int'),
  38. 'doings_title' => array('name' => lang('blockclass', 'blockclass_other_stat_doings_title'), 'formtype' => 'text', 'datatype' => 'string'),
  39. 'blogs' => array('name' => lang('blockclass', 'blockclass_other_stat_blogs'), 'formtype' => 'text', 'datatype' => 'int'),
  40. 'blogs_title' => array('name' => lang('blockclass', 'blockclass_other_stat_blogs_title'), 'formtype' => 'text', 'datatype' => 'string'),
  41. 'albums' => array('name' => lang('blockclass', 'blockclass_other_stat_albums'), 'formtype' => 'text', 'datatype' => 'int'),
  42. 'albums_title' => array('name' => lang('blockclass', 'blockclass_other_stat_albums_title'), 'formtype' => 'text', 'datatype' => 'string'),
  43. 'pics' => array('name' => lang('blockclass', 'blockclass_other_stat_pics'), 'formtype' => 'text', 'datatype' => 'int'),
  44. 'pics_title' => array('name' => lang('blockclass', 'blockclass_other_stat_pics_title'), 'formtype' => 'text', 'datatype' => 'string'),
  45. 'shares' => array('name' => lang('blockclass', 'blockclass_other_stat_shares'), 'formtype' => 'text', 'datatype' => 'int'),
  46. 'shares_title' => array('name' => lang('blockclass', 'blockclass_other_stat_shares_title'), 'formtype' => 'text', 'datatype' => 'string'),
  47. );
  48. }
  49. function getsetting() {
  50. global $_G;
  51. $settings = array(
  52. 'option' => array(
  53. 'title' => 'stat_option',
  54. 'type' => 'mcheckbox',
  55. 'value' => array(
  56. array('posts', 'stat_option_posts'),
  57. array('groups', 'stat_option_groups'),
  58. array('members', 'stat_option_members'),
  59. array('groupnewposts', 'stat_option_groupnewposts'),
  60. array('bbsnewposts', 'stat_option_bbsnewposts'),
  61. array('bbslastposts', 'stat_option_bbslastposts'),
  62. array('onlinemembers', 'stat_option_onlinemembers'),
  63. array('maxmembers', 'stat_option_maxmembers'),
  64. array('doings', 'stat_option_doings'),
  65. array('blogs', 'stat_option_blogs'),
  66. array('albums', 'stat_option_albums'),
  67. array('pics', 'stat_option_pics'),
  68. array('shares', 'stat_option_shares'),
  69. ),
  70. 'default' => array('posts', 'groups', 'members')
  71. ),
  72. 'tip' => array(
  73. 'title' => 'stat_edit_showtitle',
  74. 'type' => lang('block/stat', 'stat_edit_showtitle_detail'),
  75. ),
  76. 'posts_title' => array(
  77. 'title' => 'stat_option_posts',
  78. 'type' => 'text',
  79. 'default' => lang('block/stat', 'stat_posts')
  80. ),
  81. 'groups_title' => array(
  82. 'title' => 'stat_option_groups',
  83. 'type' => 'text',
  84. 'default' => lang('block/stat', 'stat_groups')
  85. ),
  86. 'members_title' => array(
  87. 'title' => 'stat_option_members',
  88. 'type' => 'text',
  89. 'default' => lang('block/stat', 'stat_members')
  90. ),
  91. 'groupnewposts_title' => array(
  92. 'title' => 'stat_option_groupnewposts',
  93. 'type' => 'text',
  94. 'default' => lang('block/stat', 'stat_groupnewposts')
  95. ),
  96. 'bbsnewposts_title' => array(
  97. 'title' => 'stat_option_bbsnewposts',
  98. 'type' => 'text',
  99. 'default' => lang('block/stat', 'stat_bbsnewposts')
  100. ),
  101. 'bbslastposts_title' => array(
  102. 'title' => 'stat_option_bbslastposts',
  103. 'type' => 'text',
  104. 'default' => lang('block/stat', 'stat_bbslastposts')
  105. ),
  106. 'onlinemembers_title' => array(
  107. 'title' => 'stat_option_onlinemembers',
  108. 'type' => 'text',
  109. 'default' => lang('block/stat', 'stat_onlinemembers')
  110. ),
  111. 'maxmembers_title' => array(
  112. 'title' => 'stat_option_maxmembers',
  113. 'type' => 'text',
  114. 'default' => lang('block/stat', 'stat_maxmembers')
  115. ),
  116. 'doings_title' => array(
  117. 'title' => 'stat_option_doings',
  118. 'type' => 'text',
  119. 'default' => lang('block/stat', 'stat_doings')
  120. ),
  121. 'blogs_title' => array(
  122. 'title' => 'stat_option_blogs',
  123. 'type' => 'text',
  124. 'default' => lang('block/stat', 'stat_blogs')
  125. ),
  126. 'albums_title' => array(
  127. 'title' => 'stat_option_albums',
  128. 'type' => 'text',
  129. 'default' => lang('block/stat', 'stat_albums')
  130. ),
  131. 'pics_title' => array(
  132. 'title' => 'stat_option_pics',
  133. 'type' => 'text',
  134. 'default' => lang('block/stat', 'stat_pics')
  135. ),
  136. 'shares_title' => array(
  137. 'title' => 'stat_option_shares',
  138. 'type' => 'text',
  139. 'default' => lang('block/stat', 'stat_shares')
  140. ),
  141. );
  142. return $settings;
  143. }
  144. function getdata($style, $parameter) {
  145. global $_G;
  146. $parameter = $this->cookparameter($parameter);
  147. $fields = array(
  148. 'posts' => 0,
  149. 'posts_title' => !empty($parameter['posts_title']) ? $parameter['posts_title'] : lang('block/stat', 'stat_posts'),
  150. 'groups' => 0,
  151. 'groups_title' => !empty($parameter['groups_title']) ? $parameter['groups_title'] : lang('block/stat', 'stat_groups'),
  152. 'members' => 0,
  153. 'members_title' => !empty($parameter['members_title']) ? $parameter['members_title'] : lang('block/stat', 'stat_members'),
  154. 'groupnewposts' => 0,
  155. 'groupnewposts_title' => !empty($parameter['groupnewposts_title']) ? $parameter['groupnewposts_title'] : lang('block/stat', 'stat_groupnewposts'),
  156. 'bbsnewposts' => 0,
  157. 'bbsnewposts_title' => !empty($parameter['bbsnewposts_title']) ? $parameter['bbsnewposts_title'] : lang('block/stat', 'stat_bbsnewposts'),
  158. 'bbslastposts' => 0,
  159. 'bbslastposts_title' => !empty($parameter['bbslastposts_title']) ? $parameter['bbslastposts_title'] : lang('block/stat', 'stat_bbslastposts'),
  160. 'onlinemembers' => 0,
  161. 'onlinemembers_title' => !empty($parameter['onlinemembers_title']) ? $parameter['onlinemembers_title'] : lang('block/stat', 'stat_onlinemembers'),
  162. 'maxmembers' => 0,
  163. 'maxmembers_title' => !empty($parameter['maxmembers_title']) ? $parameter['maxmembers_title'] : lang('block/stat', 'stat_maxmembers'),
  164. 'doings' => 0,
  165. 'doings_title' => !empty($parameter['doings_title']) ? $parameter['doings_title'] : lang('block/stat', 'stat_doings'),
  166. 'blogs' => 0,
  167. 'blogs_title' => !empty($parameter['blogs_title']) ? $parameter['blogs_title'] : lang('block/stat', 'stat_blogs'),
  168. 'albums' => 0,
  169. 'albums_title' => !empty($parameter['albums_title']) ? $parameter['albums_title'] : lang('block/stat', 'stat_albums'),
  170. 'pics' => 0,
  171. 'pics_title' => !empty($parameter['pics_title']) ? $parameter['pics_title'] : lang('block/stat', 'stat_pics'),
  172. 'shares' => 0,
  173. 'shares_title' => !empty($parameter['shares_title']) ? $parameter['shares_title'] : lang('block/stat', 'stat_shares'),
  174. );
  175. if(in_array('posts', $parameter['option']) || in_array('bbsnewposts', $parameter['option'])) {
  176. $sql = "SELECT sum(f.posts) AS posts, sum(f.todayposts) AS todayposts FROM ".DB::table('forum_forum')." f WHERE f.status='1'";
  177. $forum = DB::fetch_first($sql);
  178. }
  179. if(in_array('groups', $parameter['option']) || in_array('groupnewposts', $parameter['option'])) {
  180. loadcache('groupindex');
  181. }
  182. if(in_array('posts', $parameter['option'])) {
  183. $fields['posts'] = intval($forum['posts']);
  184. }
  185. if(in_array('groups', $parameter['option'])) {
  186. $fields['groups'] = intval($_G['cache']['groupindex']['groupnum']);
  187. }
  188. if(in_array('members', $parameter['option'])) {
  189. loadcache('userstats');
  190. $fields['members'] = intval($_G['cache']['userstats']['totalmembers']);
  191. }
  192. if(in_array('groupnewposts', $parameter['option'])) {
  193. $fields['groupnewposts'] = intval($_G['cache']['groupindex']['todayposts']);
  194. }
  195. if(in_array('bbsnewposts', $parameter['option'])) {
  196. $fields['bbsnewposts'] = intval($forum['todayposts']);
  197. }
  198. if(in_array('bbslastposts', $parameter['option'])) {
  199. loadcache('historyposts');
  200. $postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array();
  201. $fields['bbslastposts'] = intval($postdata[0]);
  202. }
  203. if(in_array('onlinemembers', $parameter['option'])) {
  204. $num = !empty($_G['cookie']['onlineusernum']) ? intval($_G['cookie']['onlineusernum']) : C::app()->session->count();
  205. $fields['onlinemembers'] = intval($num);
  206. }
  207. if(in_array('maxmembers', $parameter['option'])) {
  208. loadcache('onlinerecord');
  209. $onlineinfo = explode("\t", $_G['cache']['onlinerecord']);
  210. $fields['maxmembers'] = !empty($onlineinfo[0]) ? intval($onlineinfo[0]) : 0;
  211. }
  212. if(in_array('doings', $parameter['option'])) {
  213. $num = C::t('home_doing')->count();
  214. $fields['doings'] = intval($num);
  215. }
  216. if(in_array('blogs', $parameter['option'])) {
  217. $num = C::t('home_blog')->count();
  218. $fields['blogs'] = intval($num);
  219. }
  220. if(in_array('albums', $parameter['option'])) {
  221. $num = C::t('home_album')->count();
  222. $fields['albums'] = intval($num);
  223. }
  224. if(in_array('pics', $parameter['option'])) {
  225. $num = C::t('home_pic')->count();
  226. $fields['pics'] = intval($num);
  227. }
  228. if(in_array('shares', $parameter['option'])) {
  229. $num = C::t('home_share')->count();
  230. $fields['shares'] = intval($num);
  231. }
  232. $list = array();
  233. $list[1] = array(
  234. 'id' => 1,
  235. 'idtype' => 'statid',
  236. 'fields' => $fields
  237. );
  238. return array('html' => '', 'data' => $list);
  239. }
  240. }
  241. ?>