block_forum.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_forum.php 29623 2012-04-23 06:54:18Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_forum extends discuz_block {
  12. var $setting = array();
  13. function block_forum() {
  14. $this->setting = array(
  15. 'fids' => array(
  16. 'title' => 'forumlist_fids',
  17. 'type' => 'text',
  18. ),
  19. 'fups' => array(
  20. 'title' => 'forumlist_fups',
  21. 'type' => 'mselect',
  22. 'value' => array()
  23. ),
  24. 'titlelength' => array(
  25. 'title' => 'forumlist_titlelength',
  26. 'type' => 'text',
  27. 'default' => 40
  28. ),
  29. 'summarylength' => array(
  30. 'title' => 'forumlist_summarylength',
  31. 'type' => 'text',
  32. 'default' => 80
  33. ),
  34. 'orderby' => array(
  35. 'title' => 'forumlist_orderby',
  36. 'type' => 'mradio',
  37. 'value' => array(
  38. array('displayorder', 'forumlist_orderby_displayorder'),
  39. array('threads', 'forumlist_orderby_threads'),
  40. array('todayposts', 'forumlist_orderby_todayposts'),
  41. array('posts', 'forumlist_orderby_posts')
  42. ),
  43. 'default' => 'displayorder'
  44. )
  45. );
  46. }
  47. function name() {
  48. return lang('blockclass', 'blockclass_forum_script_forum');
  49. }
  50. function blockclass() {
  51. return array('forum', lang('blockclass', 'blockclass_forum_forum'));
  52. }
  53. function fields() {
  54. return array(
  55. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  56. 'url' => array('name' => lang('blockclass', 'blockclass_forum_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  57. 'title' => array('name' => lang('blockclass', 'blockclass_forum_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  58. 'summary' => array('name' => lang('blockclass', 'blockclass_forum_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  59. 'icon' => array('name' => lang('blockclass', 'blockclass_forum_field_icon'), 'formtype' => 'text', 'datatype' => 'string'),
  60. 'posts' => array('name'=>lang('blockclass', 'blockclass_forum_field_posts'), 'formtype' => 'text', 'datatype'=>'int'),
  61. 'threads' => array('name'=>lang('blockclass', 'blockclass_forum_field_threads'), 'formtype' => 'text', 'datatype'=>'int'),
  62. 'todayposts' => array('name'=>lang('blockclass', 'blockclass_forum_field_todayposts'), 'formtype' => 'text', 'datatype'=>'int'),
  63. );
  64. }
  65. function fieldsconvert() {
  66. return array(
  67. 'group_group' => array(
  68. 'name' => lang('blockclass', 'blockclass_group_group'),
  69. 'script' => 'group',
  70. 'searchkeys' => array(),
  71. 'replacekeys' => array(),
  72. ),
  73. 'portal_category' => array(
  74. 'name' => lang('blockclass', 'blockclass_portal_category'),
  75. 'script' => 'portalcategory',
  76. 'searchkeys' => array('threads'),
  77. 'replacekeys' => array('articles'),
  78. ),
  79. );
  80. }
  81. function getsetting() {
  82. global $_G;
  83. $settings = $this->setting;
  84. loadcache('forums');
  85. $settings['fups']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  86. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  87. foreach($_G['cache']['forums'] as $fid => $forum) {
  88. $settings['fups']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  89. }
  90. return $settings;
  91. }
  92. function getdata($style, $parameter) {
  93. global $_G;
  94. $parameter = $this->cookparameter($parameter);
  95. $fids = !empty($parameter['fids']) ? explode(',',$parameter['fids']) : array();
  96. $fups = isset($parameter['fups']) && !in_array(0, (array)$parameter['fups']) ? $parameter['fups'] : '';
  97. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('displayorder','threads','posts', 'todayposts')) ? $parameter['orderby'] : 'displayorder') : 'displayorder';
  98. $titlelength = isset($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  99. $summarylength = isset($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  100. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  101. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  102. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  103. $sqlban = !empty($bannedids) ? ' AND f.fid NOT IN ('.dimplode($bannedids).')' : '';
  104. if(empty($fups)) {
  105. loadcache('forums');
  106. if(empty($_G['cache']['forums'])) {
  107. $fups = array('0');
  108. } else {
  109. $fups = array_keys($_G['cache']['forums']);
  110. }
  111. }
  112. $wheres = array();
  113. if($fids) {
  114. $wheres[] = 'f.`fid` IN ('.dimplode($fids).')';
  115. }
  116. if($fups) {
  117. $wheres[] = 'f.`fup` IN ('.dimplode($fups).')';
  118. }
  119. $wheres[] = "f.`status`='1'";
  120. $wheres[] = "f.`type`!='group'";
  121. $wheresql = implode(' AND ', $wheres);
  122. $ffadd1 = ", ff.icon, ff.description";
  123. $ffadd2 = "LEFT JOIN `".DB::table('forum_forumfield')."` ff ON f.`fid`=ff.`fid`";
  124. $query = DB::query("SELECT f.* $ffadd1
  125. FROM `".DB::table('forum_forum')."` f $ffadd2
  126. WHERE $wheresql
  127. $sqlban
  128. ORDER BY ".($orderby == 'displayorder' ? "f.fup, f.`displayorder` ASC " : "f.`$orderby` DESC")
  129. ." LIMIT $startrow, $items"
  130. );
  131. $datalist = $list = array();
  132. $attachurl = preg_match('/^(http|ftp|ftps|https):\/\//', $_G['setting']['attachurl']) ? $_G['setting']['attachurl'] : $_G['siteurl'].$_G['setting']['attachurl'];
  133. while($data = DB::fetch($query)) {
  134. if(!empty($data['icon'])) {
  135. $data['icon'] = preg_match('/^(http|ftp|ftps|https):\/\//', $data['icon']) ? $data['icon'] : $attachurl.'common/'.$data['icon'];
  136. } else {
  137. $data['icon'] = 'static/image/common/forum_new.gif';
  138. }
  139. $list[] = array(
  140. 'id' => $data['fid'],
  141. 'idtype' => 'fid',
  142. 'title' => cutstr($data['name'], $titlelength, ''),
  143. 'url' => 'forum.php?mod=forumdisplay&fid='.$data['fid'],
  144. 'pic' => '',
  145. 'summary' => cutstr($data['description'], $summarylength, ''),
  146. 'fields' => array(
  147. 'fulltitle' => $data['name'],
  148. 'icon' => $data['icon'],
  149. 'threads' => intval($data['threads']),
  150. 'posts' => intval($data['posts']),
  151. 'todayposts' => intval($data['todayposts'])
  152. )
  153. );
  154. }
  155. return array('html' => '', 'data' => $list);
  156. }
  157. }
  158. ?>