block_groupthread.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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_groupthread.php 29437 2012-04-12 05:24:35Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_groupthread extends discuz_block {
  12. var $setting = array();
  13. function block_groupthread(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'groupthread_tids',
  17. 'type' => 'text'
  18. ),
  19. 'fids' => array(
  20. 'title' => 'groupthread_fids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'threadlist_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'gtids' => array(
  28. 'title' => 'groupthread_gtids',
  29. 'type' => 'mselect',
  30. 'value' => array(
  31. ),
  32. ),
  33. 'uids' => array(
  34. 'title' => 'groupthread_uids',
  35. 'type' => 'text'
  36. ),
  37. 'digest' => array(
  38. 'title' => 'groupthread_digest',
  39. 'type' => 'mcheckbox',
  40. 'value' => array(
  41. array(1, 'groupthread_digest_1'),
  42. array(2, 'groupthread_digest_2'),
  43. array(3, 'groupthread_digest_3'),
  44. array(0, 'groupthread_digest_0')
  45. ),
  46. ),
  47. 'stick' => array(
  48. 'title' => 'groupthread_stick',
  49. 'type' => 'mcheckbox',
  50. 'value' => array(
  51. array(1, 'groupthread_stick_1'),
  52. array(0, 'groupthread_stick_0')
  53. ),
  54. ),
  55. 'special' => array(
  56. 'title' => 'groupthread_special',
  57. 'type' => 'mcheckbox',
  58. 'value' => array(
  59. array(1, 'groupthread_special_1'),
  60. array(2, 'groupthread_special_2'),
  61. array(3, 'groupthread_special_3'),
  62. array(4, 'groupthread_special_4'),
  63. array(5, 'groupthread_special_5'),
  64. array(0, 'groupthread_special_0'),
  65. )
  66. ),
  67. 'rewardstatus' => array(
  68. 'title' => 'groupthread_special_reward',
  69. 'type' => 'mradio',
  70. 'value' => array(
  71. array(0, 'groupthread_special_reward_0'),
  72. array(1, 'groupthread_special_reward_1'),
  73. array(2, 'groupthread_special_reward_2')
  74. ),
  75. 'default' => 0,
  76. ),
  77. 'picrequired' => array(
  78. 'title' => 'groupthread_picrequired',
  79. 'type' => 'radio',
  80. 'value' => '0'
  81. ),
  82. 'orderby' => array(
  83. 'title' => 'groupthread_orderby',
  84. 'type'=> 'mradio',
  85. 'value' => array(
  86. array('lastpost', 'groupthread_orderby_lastpost'),
  87. array('dateline', 'groupthread_orderby_dateline'),
  88. array('replies', 'groupthread_orderby_replies'),
  89. array('views', 'groupthread_orderby_views'),
  90. array('heats', 'groupthread_orderby_heats'),
  91. array('recommends', 'groupthread_orderby_recommends'),
  92. ),
  93. 'default' => 'lastpost'
  94. ),
  95. 'postdateline' => array(
  96. 'title' => 'groupthread_postdateline',
  97. 'type'=> 'mradio',
  98. 'value' => array(
  99. array('0', 'groupthread_postdateline_nolimit'),
  100. array('3600', 'groupthread_postdateline_hour'),
  101. array('86400', 'groupthread_postdateline_day'),
  102. array('604800', 'groupthread_postdateline_week'),
  103. array('2592000', 'groupthread_postdateline_month'),
  104. ),
  105. 'default' => '0'
  106. ),
  107. 'lastpost' => array(
  108. 'title' => 'groupthread_lastpost',
  109. 'type'=> 'mradio',
  110. 'value' => array(
  111. array('0', 'groupthread_lastpost_nolimit'),
  112. array('3600', 'groupthread_lastpost_hour'),
  113. array('86400', 'groupthread_lastpost_day'),
  114. array('604800', 'groupthread_lastpost_week'),
  115. array('2592000', 'groupthread_lastpost_month'),
  116. ),
  117. 'default' => '0'
  118. ),
  119. 'gviewperm' => array(
  120. 'title' => 'groupthread_gviewperm',
  121. 'type' => 'mradio',
  122. 'value' => array(
  123. array('-1', 'groupthread_gviewperm_nolimit'),
  124. array('0', 'groupthread_gviewperm_only_member'),
  125. array('1', 'groupthread_gviewperm_all_member')
  126. ),
  127. 'default' => '-1'
  128. ),
  129. 'highlight' => array(
  130. 'title' => 'groupthread_highlight',
  131. 'type' => 'radio',
  132. 'default' => 0,
  133. ),
  134. 'titlelength' => array(
  135. 'title' => 'groupthread_titlelength',
  136. 'type' => 'text',
  137. 'default' => 40
  138. ),
  139. 'summarylength' => array(
  140. 'title' => 'groupthread_summarylength',
  141. 'type' => 'text',
  142. 'default' => 80
  143. ),
  144. 'startrow' => array(
  145. 'title' => 'groupthread_startrow',
  146. 'type' => 'text',
  147. 'default' => 0
  148. ),
  149. );
  150. }
  151. function name() {
  152. return lang('blockclass', 'blockclass_groupthread_script_groupthread');
  153. }
  154. function blockclass() {
  155. return array('thread', lang('blockclass', 'blockclass_group_thread'));
  156. }
  157. function fields() {
  158. return array(
  159. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  160. 'url' => array('name' => lang('blockclass', 'blockclass_groupthread_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  161. 'title' => array('name' => lang('blockclass', 'blockclass_groupthread_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  162. 'pic' => array('name' => lang('blockclass', 'blockclass_groupthread_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  163. 'summary' => array('name' => lang('blockclass', 'blockclass_groupthread_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  164. 'author' => array('name' => lang('blockclass', 'blockclass_groupthread_field_author'), 'formtype' => 'text', 'datatype' => 'string'),
  165. 'authorid' => array('name' => lang('blockclass', 'blockclass_groupthread_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  166. 'avatar' => array('name' => lang('blockclass', 'blockclass_groupthread_field_avatar'), 'formtype' => 'text', 'datatype' => 'string'),
  167. 'avatar_middle' => array('name' => lang('blockclass', 'blockclass_groupthread_field_avatar_middle'), 'formtype' => 'text', 'datatype' => 'string'),
  168. 'avatar_big' => array('name' => lang('blockclass', 'blockclass_groupthread_field_avatar_big'), 'formtype' => 'text', 'datatype' => 'string'),
  169. 'posts' => array('name' => lang('blockclass', 'blockclass_groupthread_field_posts'), 'formtype' => 'text', 'datatype' => 'int'),
  170. 'todayposts' => array('name' => lang('blockclass', 'blockclass_groupthread_field_todayposts'), 'formtype' => 'text', 'datatype' => 'int'),
  171. 'lastpost' => array('name' => lang('blockclass', 'blockclass_groupthread_field_lastpost'), 'formtype' => 'date', 'datatype' => 'date'),
  172. 'dateline' => array('name' => lang('blockclass', 'blockclass_groupthread_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  173. 'replies' => array('name' => lang('blockclass', 'blockclass_groupthread_field_replies'), 'formtype' => 'text', 'datatype' => 'int'),
  174. 'views' => array('name' => lang('blockclass', 'blockclass_groupthread_field_views'), 'formtype' => 'text', 'datatype' => 'int'),
  175. 'heats' => array('name' => lang('blockclass', 'blockclass_groupthread_field_heats'), 'formtype' => 'text', 'datatype' => 'int'),
  176. 'recommends' => array('name' => lang('blockclass', 'blockclass_groupthread_field_recommends'), 'formtype' => 'text', 'datatype' => 'int'),
  177. 'groupname' => array('name' => lang('blockclass', 'blockclass_groupthread_field_groupname'), 'formtype' => 'text', 'datatype' => 'string'),
  178. 'groupurl' => array('name' => lang('blockclass', 'blockclass_groupthread_field_groupurl'), 'formtype' => 'text', 'datatype' => 'string'),
  179. );
  180. }
  181. function fieldsconvert() {
  182. return array(
  183. 'portal_article' => array(
  184. 'name' => lang('blockclass', 'blockclass_portal_article'),
  185. 'script' => 'article',
  186. 'searchkeys' => array('author', 'authorid', 'groupurl', 'groupname', 'posts', 'views', 'replies'),
  187. 'replacekeys' => array('username', 'uid', 'caturl', 'catname', 'articles', 'viewnum', 'commentnum'),
  188. ),
  189. 'space_blog' => array(
  190. 'name' => lang('blockclass', 'blockclass_space_blog'),
  191. 'script' => 'blog',
  192. 'searchkeys' => array('author', 'authorid', 'views', 'replies'),
  193. 'replacekeys' => array('username', 'uid', 'viewnum', 'replynum'),
  194. ),
  195. 'forum_thread' => array(
  196. 'name' => lang('blockclass', 'blockclass_forum_thread'),
  197. 'script' => 'thread',
  198. 'replacekeys' => array('forumname', 'forumurl'),
  199. 'searchkeys' => array('groupname', 'groupurl'),
  200. ),
  201. );
  202. }
  203. function getsetting() {
  204. global $_G;
  205. $settings = $this->setting;
  206. if($settings['gtids']) {
  207. loadcache('grouptype');
  208. $settings['gtids']['value'][] = array(0, lang('portalcp', 'block_all_type'));
  209. foreach($_G['cache']['grouptype']['first'] as $gid=>$group) {
  210. $settings['gtids']['value'][] = array($gid, $group['name']);
  211. if($group['secondlist']) {
  212. foreach($group['secondlist'] as $subgid) {
  213. $settings['gtids']['value'][] = array($subgid, '&nbsp;&nbsp;'.$_G['cache']['grouptype']['second'][$subgid]['name']);
  214. }
  215. }
  216. }
  217. }
  218. return $settings;
  219. }
  220. function getdata($style, $parameter) {
  221. global $_G;
  222. $parameter = $this->cookparameter($parameter);
  223. loadcache('grouptype');
  224. $typeids = array();
  225. if(!empty($parameter['gtids'])) {
  226. if(isset($parameter['gtids'][0]) && $parameter['gtids'][0] == '0') {
  227. unset($parameter['gtids'][0]);
  228. }
  229. $typeids = $parameter['gtids'];
  230. }
  231. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  232. $fids = !empty($parameter['fids']) ? explode(',', $parameter['fids']) : array();
  233. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  234. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  235. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  236. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  237. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  238. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  239. $special = isset($parameter['special']) ? $parameter['special'] : array();
  240. $lastpost = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0;
  241. $postdateline = isset($parameter['postdateline']) ? intval($parameter['postdateline']) : 0;
  242. $rewardstatus = isset($parameter['rewardstatus']) ? intval($parameter['rewardstatus']) : 0;
  243. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  244. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  245. $orderby = in_array($parameter['orderby'], array('dateline','replies','views','threads', 'heats', 'recommends')) ? $parameter['orderby'] : 'lastpost';
  246. $picrequired = !empty($parameter['picrequired']) ? 1 : 0;
  247. $gviewperm = isset($parameter['gviewperm']) ? intval($parameter['gviewperm']) : -1;
  248. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  249. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  250. $gviewwhere = $gviewperm == -1 ? '' : " AND ff.gviewperm='$gviewperm'";
  251. $groups = array();
  252. if(empty($fids) && $typeids) {
  253. $query = DB::query('SELECT f.fid, f.name, ff.description FROM '.DB::table('forum_forum')." f LEFT JOIN ".DB::table('forum_forumfield')." ff ON f.fid = ff.fid WHERE f.fup IN (".dimplode($typeids).") AND threads > 0$gviewwhere");
  254. while($value = DB::fetch($query)) {
  255. $groups[$value['fid']] = $value;
  256. $fids[] = intval($value['fid']);
  257. }
  258. if(empty($fids)){
  259. return array('html' => '', 'data' => '');
  260. }
  261. }
  262. require_once libfile('function/post');
  263. require_once libfile('function/search');
  264. $datalist = $list = $listtids = $pictids = $pics = $threadtids = $threads = array();
  265. $threadtypeids = array();
  266. $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  267. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  268. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  269. .($bannedids ? ' AND t.tid NOT IN ('.dimplode($bannedids).')' : '')
  270. .($uids ? ' AND t.authorid IN ('.dimplode($uids).')' : '')
  271. .($special ? ' AND t.special IN ('.dimplode($special).')' : '')
  272. .((in_array(3, $special) && $rewardstatus) ? ($rewardstatus == 1 ? ' AND t.price < 0' : ' AND t.price > 0') : '')
  273. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  274. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  275. .$keyword;
  276. if(empty($fids)) {
  277. $sql .= " AND t.isgroup='1'";
  278. if($gviewwhere) {
  279. $sql .= $gviewwhere;
  280. }
  281. }
  282. if($postdateline) {
  283. $time = TIMESTAMP - $postdateline;
  284. $sql .= " AND t.dateline >= '$time'";
  285. }
  286. if($lastpost) {
  287. $time = TIMESTAMP - $lastpost;
  288. $sql .= " AND t.lastpost >= '$time'";
  289. }
  290. if($orderby == 'heats') {
  291. $sql .= " AND t.heats>'0'";
  292. }
  293. $sqlfrom = $sqlfield = $joinmethodpic = '';
  294. if($picrequired) {
  295. $joinmethodpic = 'INNER';
  296. } else if($style['getpic']) {
  297. $joinmethodpic = 'LEFT';
  298. }
  299. if($joinmethodpic) {
  300. $sqlfrom .= " $joinmethodpic JOIN `".DB::table('forum_threadimage')."` ti ON t.tid=ti.tid AND ti.tid>0";
  301. $sqlfield = ', ti.attachment as attachmenturl, ti.remote';
  302. }
  303. if(empty($fids)) {
  304. $sqlfield .= ', f.name groupname';
  305. $sqlfrom .= ' LEFT JOIN '.DB::table('forum_forum').' f ON t.fid=f.fid LEFT JOIN '.DB::table('forum_forumfield').' ff ON f.fid = ff.fid';
  306. }
  307. $query = DB::query("SELECT t.* $sqlfield
  308. FROM `".DB::table('forum_thread')."` t
  309. $sqlfrom WHERE t.readperm='0'
  310. $sql
  311. AND t.displayorder>='0'
  312. ORDER BY t.$orderby DESC
  313. LIMIT $startrow,$items;"
  314. );
  315. require_once libfile('block_thread', 'class/block/forum');
  316. $bt = new block_thread();
  317. while($data = DB::fetch($query)) {
  318. if($data['closed'] > 1 && $data['closed'] < $data['tid']) continue;
  319. $_G['block_thread'][$data['tid']] = $data;
  320. if($style['getsummary']) {
  321. $threadtids[$data['posttableid']][] = $data['tid'];
  322. }
  323. $listtids[] = $data['tid'];
  324. $list[$data['tid']] = array(
  325. 'id' => $data['tid'],
  326. 'idtype' => 'tid',
  327. 'title' => cutstr(str_replace('\\\'', '&#39;', $data['subject']), $titlelength, ''),
  328. 'url' => 'forum.php?mod=viewthread&tid='.$data['tid'],
  329. 'pic' => $data['attachmenturl'] ? 'forum/'.$data['attachmenturl'] : STATICURL.'image/common/nophoto.gif',
  330. 'picflag' => $data['attachmenturl'] ? ($data['remote'] ? '2' : '1') : '0',
  331. 'fields' => array(
  332. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  333. 'icon' => 'forum/'.$data['icon'],
  334. 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'],
  335. 'authorid' => $data['author'] ? $data['authorid'] : 0,
  336. 'avatar' => avatar(($data['author'] ? $data['authorid'] : 0), 'small', true, false, false, $_G['setting']['ucenterurl']),
  337. 'avatar_middle' => avatar(($data['author'] ? $data['authorid'] : 0), 'middle', true, false, false, $_G['setting']['ucenterurl']),
  338. 'avatar_big' => avatar(($data['author'] ? $data['authorid'] : 0), 'big', true, false, false, $_G['setting']['ucenterurl']),
  339. 'dateline' => $data['dateline'],
  340. 'lastpost' => $data['lastpost'],
  341. 'posts' => $data['posts'],
  342. 'todayposts' => $data['todayposts'],
  343. 'replies' => $data['replies'],
  344. 'views' => $data['views'],
  345. 'heats' => $data['heats'],
  346. 'recommends' => $data['recommends'],
  347. 'groupname' => empty($groups[$data['fid']]['name']) ? $data['groupname'] : $groups[$data['fid']]['name'],
  348. 'groupurl' => 'forum.php?mod=group&fid='.$data['fid'],
  349. )
  350. );
  351. if($highlight && $data['highlight']) {
  352. $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']);
  353. }
  354. }
  355. $threads = $bt->getthread($threadtids, $summarylength);
  356. if($threads) {
  357. foreach($threads as $tid => $var) {
  358. $list[$tid]['summary'] = $var;
  359. }
  360. }
  361. if($listtids) {
  362. foreach($listtids as $key => $value) {
  363. $datalist[] = $list[$value];
  364. }
  365. }
  366. return array('html' => '', 'data' => $datalist);
  367. }
  368. }
  369. ?>