block_group.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_group.php 25525 2011-11-14 04:39:11Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_group extends discuz_block {
  12. var $setting = array();
  13. function block_group(){
  14. $this->setting = array(
  15. 'gtids' => array(
  16. 'title' => 'grouplist_gtids',
  17. 'type' => 'mselect',
  18. 'value' => array(
  19. ),
  20. ),
  21. 'fids' => array(
  22. 'title' => 'grouplist_fids',
  23. 'type' => 'text'
  24. ),
  25. 'titlelength' => array(
  26. 'title' => 'grouplist_titlelength',
  27. 'type' => 'text',
  28. 'default' => 40
  29. ),
  30. 'summarylength' => array(
  31. 'title' => 'grouplist_summarylength',
  32. 'type' => 'text',
  33. 'default' => 80
  34. ),
  35. 'orderby' => array(
  36. 'title' => 'grouplist_orderby',
  37. 'type' => 'mradio',
  38. 'value' => array(
  39. array('displayorder', 'grouplist_orderby_displayorder'),
  40. array('threads', 'grouplist_orderby_threads'),
  41. array('posts', 'grouplist_orderby_posts'),
  42. array('todayposts', 'grouplist_orderby_todayposts'),
  43. array('membernum', 'grouplist_orderby_membernum'),
  44. array('dateline', 'grouplist_orderby_dateline'),
  45. array('level', 'grouplist_orderby_level'),
  46. array('commoncredits', 'grouplist_orderby_commoncredits'),
  47. array('activity', 'grouplist_orderby_activity')
  48. ),
  49. 'default' => 'displayorder'
  50. )
  51. );
  52. }
  53. function getsetting() {
  54. global $_G;
  55. $settings = $this->setting;
  56. if($settings['gtids']) {
  57. loadcache('grouptype');
  58. $settings['gtids']['value'][] = array(0, lang('portalcp', 'block_all_type'));
  59. foreach($_G['cache']['grouptype']['first'] as $gid=>$group) {
  60. $settings['gtids']['value'][] = array($gid, $group['name']);
  61. if($group['secondlist']) {
  62. foreach($group['secondlist'] as $subgid) {
  63. $settings['gtids']['value'][] = array($subgid, '&nbsp;&nbsp;'.$_G['cache']['grouptype']['second'][$subgid]['name']);
  64. }
  65. }
  66. }
  67. }
  68. return $settings;
  69. }
  70. function name() {
  71. return lang('blockclass', 'blockclass_group_script_group');
  72. }
  73. function blockclass() {
  74. return array('group', lang('blockclass', 'blockclass_group_group'));
  75. }
  76. function fields() {
  77. return array(
  78. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  79. 'url' => array('name' => lang('blockclass', 'blockclass_group_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  80. 'title' => array('name' => lang('blockclass', 'blockclass_group_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  81. 'pic' => array('name' => lang('blockclass', 'blockclass_group_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  82. 'summary' => array('name' => lang('blockclass', 'blockclass_group_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  83. 'icon' => array('name' => lang('blockclass', 'blockclass_group_field_icon'), 'formtype' => 'text', 'datatype' => 'string'),
  84. 'foundername' => array('name' => lang('blockclass', 'blockclass_group_field_foundername'), 'formtype' => 'text', 'datatype' => 'string'),
  85. 'founderuid' => array('name' => lang('blockclass', 'blockclass_group_field_founderuid'), 'formtype' => 'text', 'datatype' => 'int'),
  86. 'posts' => array('name' => lang('blockclass', 'blockclass_group_field_posts'), 'formtype' => 'text', 'datatype' => 'int'),
  87. 'todayposts' => array('name' => lang('blockclass', 'blockclass_group_field_todayposts'), 'formtype' => 'text', 'datatype' => 'int'),
  88. 'threads' => array('name' => lang('blockclass', 'blockclass_group_field_threads'), 'formtype' => 'date', 'datatype' => 'int'),
  89. 'membernum' => array('name' => lang('blockclass', 'blockclass_group_field_membernum'), 'formtype' => 'text', 'datatype' => 'int'),
  90. 'dateline' => array('name' => lang('blockclass', 'blockclass_group_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  91. 'level' => array('name' => lang('blockclass', 'blockclass_group_field_level'), 'formtype' => 'text', 'datatype' => 'int'),
  92. 'commoncredits' => array('name' => lang('blockclass', 'blockclass_group_field_commoncredits'), 'formtype' => 'text', 'datatype' => 'int'),
  93. 'activity' => array('name' => lang('blockclass', 'blockclass_group_field_activity'), 'formtype' => 'text', 'datatype' => 'int'),
  94. );
  95. }
  96. function fieldsconvert() {
  97. return array(
  98. 'forum_forum' => array(
  99. 'name' => lang('blockclass', 'blockclass_forum_forum'),
  100. 'script' => 'forum',
  101. 'searchkeys' => array(),
  102. 'replacekeys' => array(),
  103. ),
  104. 'portal_category' => array(
  105. 'name' => lang('blockclass', 'blockclass_portal_category'),
  106. 'script' => 'portalcategory',
  107. 'searchkeys' => array('threads'),
  108. 'replacekeys' => array('articles'),
  109. ),
  110. );
  111. }
  112. function getdata($style, $parameter) {
  113. global $_G;
  114. $parameter = $this->cookparameter($parameter);
  115. loadcache('grouptype');
  116. $typeids = array();
  117. if(!empty($parameter['gtids'])) {
  118. if($parameter['gtids'][0] == '0') {
  119. unset($parameter['gtids'][0]);
  120. }
  121. $typeids = $parameter['gtids'];
  122. }
  123. if(empty($typeids)) $typeids = array_keys($_G['cache']['grouptype']['second']);
  124. $fids = !empty($parameter['fids']) ? explode(',',$parameter['fids']) : array();
  125. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  126. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  127. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  128. $orderby = in_array($parameter['orderby'], array('displayorder','posts','todayposts','threads', 'membernum', 'dateline', 'level', 'activity', 'commoncredits')) ? $parameter['orderby'] : 'displayorder';
  129. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  130. $sqlban = !empty($bannedids) ? ' AND f.fid NOT IN ('.dimplode($bannedids).')' : '';
  131. if($fids) {
  132. $wheresql = "f.fid IN (".dimplode($fids).") AND f.status='3' AND f.type='sub' $sqlban";
  133. } else {
  134. $wheresql = !empty($typeids) ? "f.fup IN (".dimplode($typeids).") AND f.status='3' AND f.type='sub' $sqlban" : "0";
  135. }
  136. $wheresql .= " AND f.level > '0'";
  137. if(in_array($orderby, array('posts', 'todayposts', 'threads', 'level', 'commoncredits'))) {
  138. $orderbysql = "f.$orderby DESC";
  139. } elseif(in_array($orderby, array('dateline', 'activity', 'membernum'))) {
  140. $orderbysql = "ff.$orderby DESC";
  141. } else {
  142. $orderbysql = "f.displayorder ASC";
  143. }
  144. $list = array();
  145. $query = DB::query('SELECT f.*, ff.* FROM '.DB::table('forum_forum').' f LEFT JOIN '.DB::table('forum_forumfield')." ff ON f.fid = ff.fid WHERE $wheresql ORDER BY $orderbysql LIMIT $items");
  146. while($data = DB::fetch($query)) {
  147. $list[] = array(
  148. 'id' => $data['fid'],
  149. 'idtype' => 'fid',
  150. 'title' => cutstr($data['name'], $titlelength, ''),
  151. 'url' => 'forum.php?mod=group&fid='.$data['fid'],
  152. 'pic' => 'group/'.$data['banner'],
  153. 'picflag' => '1',
  154. 'summary' => cutstr($data['description'], $summarylength, ''),
  155. 'fields' => array(
  156. 'fulltitle' => $data['name'],
  157. 'icon' => !empty($data['icon']) ? $_G['setting']['attachurl'].'group/'.$data['icon'] : STATICURL.'image/common/nophoto.gif',
  158. 'founderuid' => $data['founderuid'],
  159. 'foundername' => $data['foundername'],
  160. 'threads' => $data['threads'],
  161. 'posts' => $data['posts'],
  162. 'todayposts' => $data['todayposts'],
  163. 'dateline' => $data['dateline'],
  164. 'level' => $data['level'],
  165. 'membernum' => $data['membernum'],
  166. 'activity' => $data['activity'],
  167. 'commoncredits' => $data['commoncredits'],
  168. )
  169. );
  170. }
  171. return array('html' => '', 'data' => $list);
  172. }
  173. }
  174. ?>