block_thread.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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_thread.php 32768 2013-03-07 09:40:05Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_thread extends discuz_block {
  12. var $setting = array();
  13. function block_thread(){
  14. $this->setting = array(
  15. 'tids' => array(
  16. 'title' => 'threadlist_tids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'threadlist_uids',
  21. 'type' => 'text'
  22. ),
  23. 'keyword' => array(
  24. 'title' => 'threadlist_keyword',
  25. 'type' => 'text'
  26. ),
  27. 'tagkeyword' => array(
  28. 'title' => 'threadlist_tagkeyword',
  29. 'type' => 'text'
  30. ),
  31. 'fids' => array(
  32. 'title' => 'threadlist_fids',
  33. 'type' => 'mselect',
  34. 'value' => array()
  35. ),
  36. 'typeids' => array(
  37. 'title' => 'threadlist_typeids',
  38. 'type' => 'text'
  39. ),
  40. 'sortids' => array(
  41. 'title' => 'threadlist_sortids',
  42. 'type' => 'mselect',
  43. 'value' => array()
  44. ),
  45. 'digest' => array(
  46. 'title' => 'threadlist_digest',
  47. 'type' => 'mcheckbox',
  48. 'value' => array(
  49. array(1, 'threadlist_digest_1'),
  50. array(2, 'threadlist_digest_2'),
  51. array(3, 'threadlist_digest_3'),
  52. array(0, 'threadlist_digest_0')
  53. ),
  54. ),
  55. 'stick' => array(
  56. 'title' => 'threadlist_stick',
  57. 'type' => 'mcheckbox',
  58. 'value' => array(
  59. array(1, 'threadlist_stick_1'),
  60. array(2, 'threadlist_stick_2'),
  61. array(3, 'threadlist_stick_3'),
  62. array(0, 'threadlist_stick_0')
  63. ),
  64. ),
  65. 'recommend' => array(
  66. 'title' => 'threadlist_recommend',
  67. 'type' => 'radio'
  68. ),
  69. 'special' => array(
  70. 'title' => 'threadlist_special',
  71. 'type' => 'mcheckbox',
  72. 'value' => array(
  73. array(1, 'threadlist_special_1'),
  74. array(2, 'threadlist_special_2'),
  75. array(3, 'threadlist_special_3'),
  76. array(4, 'threadlist_special_4'),
  77. array(5, 'threadlist_special_5'),
  78. array(0, 'threadlist_special_0'),
  79. )
  80. ),
  81. 'viewmod' => array(
  82. 'title' => 'threadlist_viewmod',
  83. 'type' => 'radio'
  84. ),
  85. 'rewardstatus' => array(
  86. 'title' => 'threadlist_special_reward',
  87. 'type' => 'mradio',
  88. 'value' => array(
  89. array(0, 'threadlist_special_reward_0'),
  90. array(1, 'threadlist_special_reward_1'),
  91. array(2, 'threadlist_special_reward_2')
  92. ),
  93. 'default' => 0,
  94. ),
  95. 'picrequired' => array(
  96. 'title' => 'threadlist_picrequired',
  97. 'type' => 'radio',
  98. 'value' => '0'
  99. ),
  100. 'orderby' => array(
  101. 'title' => 'threadlist_orderby',
  102. 'type'=> 'mradio',
  103. 'value' => array(
  104. array('lastpost', 'threadlist_orderby_lastpost'),
  105. array('dateline', 'threadlist_orderby_dateline'),
  106. array('replies', 'threadlist_orderby_replies'),
  107. array('views', 'threadlist_orderby_views'),
  108. array('heats', 'threadlist_orderby_heats'),
  109. array('recommends', 'threadlist_orderby_recommends'),
  110. ),
  111. 'default' => 'lastpost'
  112. ),
  113. 'postdateline' => array(
  114. 'title' => 'threadlist_postdateline',
  115. 'type'=> 'mradio',
  116. 'value' => array(
  117. array('0', 'threadlist_postdateline_nolimit'),
  118. array('3600', 'threadlist_postdateline_hour'),
  119. array('86400', 'threadlist_postdateline_day'),
  120. array('604800', 'threadlist_postdateline_week'),
  121. array('2592000', 'threadlist_postdateline_month'),
  122. ),
  123. 'default' => '0'
  124. ),
  125. 'lastpost' => array(
  126. 'title' => 'threadlist_lastpost',
  127. 'type'=> 'mradio',
  128. 'value' => array(
  129. array('0', 'threadlist_lastpost_nolimit'),
  130. array('3600', 'threadlist_lastpost_hour'),
  131. array('86400', 'threadlist_lastpost_day'),
  132. array('604800', 'threadlist_lastpost_week'),
  133. array('2592000', 'threadlist_lastpost_month'),
  134. ),
  135. 'default' => '0'
  136. ),
  137. 'highlight' => array(
  138. 'title' => 'threadlist_highlight',
  139. 'type' => 'radio',
  140. 'default' => 0,
  141. ),
  142. 'titlelength' => array(
  143. 'title' => 'threadlist_titlelength',
  144. 'type' => 'text',
  145. 'default' => 40
  146. ),
  147. 'summarylength' => array(
  148. 'title' => 'threadlist_summarylength',
  149. 'type' => 'text',
  150. 'default' => 80
  151. ),
  152. 'startrow' => array(
  153. 'title' => 'threadlist_startrow',
  154. 'type' => 'text',
  155. 'default' => 0
  156. ),
  157. );
  158. }
  159. function name() {
  160. return lang('blockclass', 'blockclass_thread_script_thread');
  161. }
  162. function blockclass() {
  163. return array('thread', lang('blockclass', 'blockclass_forum_thread'));
  164. }
  165. function fields() {
  166. return array(
  167. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  168. 'url' => array('name' => lang('blockclass', 'blockclass_thread_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  169. 'title' => array('name' => lang('blockclass', 'blockclass_thread_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  170. 'pic' => array('name' => lang('blockclass', 'blockclass_thread_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  171. 'summary' => array('name' => lang('blockclass', 'blockclass_thread_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  172. 'author' => array('name' => lang('blockclass', 'blockclass_thread_field_author'), 'formtype' => 'text', 'datatype' => 'string'),
  173. 'authorid' => array('name' => lang('blockclass', 'blockclass_thread_field_authorid'), 'formtype' => 'text', 'datatype' => 'int'),
  174. 'avatar' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar'), 'formtype' => 'text', 'datatype' => 'string'),
  175. 'avatar_middle' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar_middle'), 'formtype' => 'text', 'datatype' => 'string'),
  176. 'avatar_big' => array('name' => lang('blockclass', 'blockclass_thread_field_avatar_big'), 'formtype' => 'text', 'datatype' => 'string'),
  177. 'forumurl' => array('name' => lang('blockclass', 'blockclass_thread_field_forumurl'), 'formtype' => 'text', 'datatype' => 'string'),
  178. 'forumname' => array('name' => lang('blockclass', 'blockclass_thread_field_forumname'), 'formtype' => 'text', 'datatype' => 'string'),
  179. 'typename' => array('name' => lang('blockclass', 'blockclass_thread_field_typename'), 'formtype' => 'text', 'datatype' => 'string'),
  180. 'typeicon' => array('name' => lang('blockclass', 'blockclass_thread_field_typeicon'), 'formtype' => 'text', 'datatype' => 'string'),
  181. 'typeurl' => array('name' => lang('blockclass', 'blockclass_thread_field_typeurl'), 'formtype' => 'text', 'datatype' => 'string'),
  182. 'sortname' => array('name' => lang('blockclass', 'blockclass_thread_field_sortname'), 'formtype' => 'text', 'datatype' => 'string'),
  183. 'sorturl' => array('name' => lang('blockclass', 'blockclass_thread_field_sorturl'), 'formtype' => 'text', 'datatype' => 'string'),
  184. 'posts' => array('name' => lang('blockclass', 'blockclass_thread_field_posts'), 'formtype' => 'text', 'datatype' => 'int'),
  185. 'todayposts' => array('name' => lang('blockclass', 'blockclass_thread_field_todayposts'), 'formtype' => 'text', 'datatype' => 'int'),
  186. 'lastpost' => array('name' => lang('blockclass', 'blockclass_thread_field_lastpost'), 'formtype' => 'date', 'datatype' => 'date'),
  187. 'dateline' => array('name' => lang('blockclass', 'blockclass_thread_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  188. 'replies' => array('name' => lang('blockclass', 'blockclass_thread_field_replies'), 'formtype' => 'text', 'datatype' => 'int'),
  189. 'views' => array('name' => lang('blockclass', 'blockclass_thread_field_views'), 'formtype' => 'text', 'datatype' => 'int'),
  190. 'heats' => array('name' => lang('blockclass', 'blockclass_thread_field_heats'), 'formtype' => 'text', 'datatype' => 'int'),
  191. 'recommends' => array('name' => lang('blockclass', 'blockclass_thread_field_recommends'), 'formtype' => 'text', 'datatype' => 'int'),
  192. );
  193. }
  194. function fieldsconvert() {
  195. return array(
  196. 'portal_article' => array(
  197. 'name' => lang('blockclass', 'blockclass_portal_article'),
  198. 'script' => 'article',
  199. 'searchkeys' => array('author', 'authorid', 'forumurl', 'forumname', 'posts', 'views', 'replies'),
  200. 'replacekeys' => array('username', 'uid', 'caturl', 'catname', 'articles', 'viewnum', 'commentnum'),
  201. ),
  202. 'space_blog' => array(
  203. 'name' => lang('blockclass', 'blockclass_space_blog'),
  204. 'script' => 'blog',
  205. 'searchkeys' => array('author', 'authorid', 'views', 'replies'),
  206. 'replacekeys' => array('username', 'uid', 'viewnum', 'replynum'),
  207. ),
  208. 'group_thread' => array(
  209. 'name' => lang('blockclass', 'blockclass_group_thread'),
  210. 'script' => 'groupthread',
  211. 'searchkeys' => array('forumname', 'forumurl'),
  212. 'replacekeys' => array('groupname', 'groupurl'),
  213. ),
  214. );
  215. }
  216. function getsetting() {
  217. global $_G;
  218. $settings = $this->setting;
  219. if($settings['fids']) {
  220. loadcache('forums');
  221. $settings['fids']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
  222. foreach($_G['cache']['forums'] as $fid => $forum) {
  223. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  224. }
  225. }
  226. if($settings['sortids']) {
  227. $settings['sortids']['value'][] = array(0, 'threadlist_sortids_all');
  228. $query = DB::query("SELECT typeid, name, special FROM ".DB::table('forum_threadtype')." WHERE special>'0' ORDER BY typeid DESC");
  229. while($threadtype = DB::fetch($query)) {
  230. $settings['sortids']['value'][] = array($threadtype['typeid'], $threadtype['name']);
  231. }
  232. }
  233. return $settings;
  234. }
  235. function getdata($style, $parameter) {
  236. global $_G;
  237. $returndata = array('html' => '', 'data' => '');
  238. $parameter = $this->cookparameter($parameter);
  239. loadcache('forums', 'stamps');
  240. $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array();
  241. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  242. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  243. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  244. $digest = isset($parameter['digest']) ? $parameter['digest'] : 0;
  245. $stick = isset($parameter['stick']) ? $parameter['stick'] : 0;
  246. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
  247. $lastpost = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0;
  248. $postdateline = isset($parameter['postdateline']) ? intval($parameter['postdateline']) : 0;
  249. $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  250. $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
  251. $recommend = !empty($parameter['recommend']) ? 1 : 0;
  252. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : '';
  253. $tagkeyword = !empty($parameter['tagkeyword']) ? $parameter['tagkeyword'] : '';
  254. $typeids = !empty($parameter['typeids']) ? explode(',',$parameter['typeids']) : array();
  255. $sortids = !empty($parameter['sortids']) && !in_array(0, (array)$parameter['sortids']) ? $parameter['sortids'] : array();
  256. $special = !empty($parameter['special']) ? $parameter['special'] : array();
  257. $rewardstatus = !empty($parameter['rewardstatus']) ? intval($parameter['rewardstatus']) : 0;
  258. $picrequired = !empty($parameter['picrequired']) ? 1 : 0;
  259. $viewmod = !empty($parameter['viewmod']) ? 1 : 0;
  260. $highlight = !empty($parameter['highlight']) ? 1 : 0;
  261. $fids = array();
  262. if(!empty($parameter['fids'])) {
  263. if(isset($parameter['fids'][0]) && $parameter['fids'][0] == '0') {
  264. unset($parameter['fids'][0]);
  265. }
  266. $fids = $parameter['fids'];
  267. }
  268. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  269. require_once libfile('function/post');
  270. require_once libfile('function/search');
  271. $datalist = $list = $listtids = $pictids = $pics = $threadtids = $threadtypeids = $tagids = array();
  272. $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : '';
  273. if($tagkeyword) {
  274. if(!($tagids = DB::fetch_all('SELECT tagid FROM '.DB::table('common_tag').' WHERE 1'.searchkey($tagkeyword, "tagname LIKE '%{text}%'"), '', 'tagid'))) {
  275. return array('data' => '');
  276. }
  277. }
  278. $threadsorts = $threadtypes = array();
  279. $querytmp = DB::query("SELECT typeid, name, special FROM ".DB::table('forum_threadtype')." WHERE special>'0'");
  280. while($value = DB::fetch($querytmp)) {
  281. $threadsorts[$value['typeid']] = $value;
  282. }
  283. $querytmp = DB::query("SELECT * FROM ".DB::table('forum_threadclass'));
  284. foreach(C::t('forum_threadclass')->range() as $value) {
  285. $threadtypes[$value['typeid']] = $value;
  286. }
  287. $sql = ($fids ? ' AND t.fid IN ('.dimplode($fids).')' : '')
  288. .($tids ? ' AND t.tid IN ('.dimplode($tids).')' : '')
  289. .($uids ? ' AND t.authorid IN ('.dimplode($uids).')' : '')
  290. .($typeids ? ' AND t.typeid IN ('.dimplode($typeids).')' : '')
  291. .($sortids ? ' AND t.sortid IN ('.dimplode($sortids).')' : '')
  292. .($special ? ' AND t.special IN ('.dimplode($special).')' : '')
  293. .((in_array(3, $special) && $rewardstatus) ? ($rewardstatus == 1 ? ' AND t.price < 0' : ' AND t.price > 0') : '')
  294. .($digest ? ' AND t.digest IN ('.dimplode($digest).')' : '')
  295. .($stick ? ' AND t.displayorder IN ('.dimplode($stick).')' : '')
  296. .($bannedids ? ' AND t.tid NOT IN ('.dimplode($bannedids).')' : '')
  297. .$keyword
  298. ." AND t.isgroup='0'";
  299. if($postdateline) {
  300. $time = TIMESTAMP - $postdateline;
  301. $sql .= " AND t.dateline >= '$time'";
  302. }
  303. if($lastpost) {
  304. $time = TIMESTAMP - $lastpost;
  305. $sql .= " AND t.lastpost >= '$time'";
  306. }
  307. if($orderby == 'heats') {
  308. $sql .= " AND t.heats>'0'";
  309. }
  310. $sqlfrom = $sqlfield = $joinmethodpic = '';
  311. if($picrequired) {
  312. $joinmethodpic = 'INNER';
  313. } else if($style['getpic']) {
  314. $joinmethodpic = 'LEFT';
  315. }
  316. if($joinmethodpic) {
  317. $sqlfrom .= " $joinmethodpic JOIN `".DB::table('forum_threadimage')."` ti ON t.tid=ti.tid";
  318. $sqlfield = ', ti.attachment as attachmenturl, ti.remote';
  319. }
  320. $joinmethod = empty($tids) ? 'INNER' : 'LEFT';
  321. if($recommend) {
  322. $sqlfrom .= " $joinmethod JOIN `".DB::table('forum_forumrecommend')."` fc ON fc.tid=t.tid";
  323. }
  324. if($tagids) {
  325. $sqlfrom .= " $joinmethod JOIN `".DB::table('common_tagitem')."` tim ON tim.tagid IN (".dimplode(array_keys($tagids)).") AND tim.itemid=t.tid AND tim.idtype='tid' ";
  326. }
  327. $maxwhere = '';
  328. if(!$tids && !$fids && !$digest && !$stick && $_G['setting']['blockmaxaggregationitem']) {
  329. $maxwhere = ($maxid = $this->getmaxid() - $_G['setting']['blockmaxaggregationitem']) > 0 ? 't.tid > '.$maxid.' AND ' : '';
  330. }
  331. $query = DB::query("SELECT DISTINCT t.*$sqlfield
  332. FROM `".DB::table('forum_thread')."` t
  333. $sqlfrom WHERE {$maxwhere}t.readperm='0'
  334. $sql
  335. AND t.displayorder>='0'
  336. ORDER BY t.$orderby DESC
  337. LIMIT $startrow,$items;"
  338. );
  339. while($data = DB::fetch($query)) {
  340. $_G['block_thread'][$data['tid']] = $data;
  341. if($style['getsummary']) {
  342. $threadtids[$data['posttableid']][] = $data['tid'];
  343. }
  344. $listtids[$data['tid']] = $data['tid'];
  345. $list[$data['tid']] = array(
  346. 'id' => $data['tid'],
  347. 'idtype' => 'tid',
  348. 'title' => cutstr(str_replace('\\\'', '&#39;', addslashes($data['subject'])), $titlelength, ''),
  349. 'url' => 'forum.php?mod=viewthread&tid='.$data['tid'].($viewmod ? '&from=portal' : ''),
  350. 'pic' => $data['attachmenturl'] ? 'forum/'.$data['attachmenturl'] : STATICURL.'image/common/nophoto.gif',
  351. 'picflag' => $data['attachmenturl'] ? ($data['remote'] ? '2' : '1') : '0',
  352. 'fields' => array(
  353. 'fulltitle' => str_replace('\\\'', '&#39;', addslashes($data['subject'])),
  354. 'threads' => $data['threads'],
  355. 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'],
  356. 'authorid' => $data['author'] ? $data['authorid'] : 0,
  357. 'avatar' => avatar(($data['author'] ? $data['authorid'] : 0), 'small', true, false, false, $_G['setting']['ucenterurl']),
  358. 'avatar_middle' => avatar(($data['author'] ? $data['authorid'] : 0), 'middle', true, false, false, $_G['setting']['ucenterurl']),
  359. 'avatar_big' => avatar(($data['author'] ? $data['authorid'] : 0), 'big', true, false, false, $_G['setting']['ucenterurl']),
  360. 'posts' => $data['posts'],
  361. 'todayposts' => $data['todayposts'],
  362. 'lastpost' => $data['lastpost'],
  363. 'dateline' => $data['dateline'],
  364. 'replies' => $data['replies'],
  365. 'forumurl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'],
  366. 'forumname' => $_G['cache']['forums'][$data['fid']]['name'],
  367. 'typename' => $threadtypes[$data['typeid']]['name'],
  368. 'typeicon' => $threadtypes[$data['typeid']]['icon'],
  369. 'typeurl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'].'&filter=typeid&typeid='.$data['typeid'],
  370. 'sortname' => $threadsorts[$data['sortid']]['name'],
  371. 'sorturl' => 'forum.php?mod=forumdisplay&fid='.$data['fid'].'&filter=sortid&sortid='.$data['sortid'],
  372. 'views' => $data['views'],
  373. 'heats' => $data['heats'],
  374. 'recommends' => $data['recommends'],
  375. 'hourviews' => $data['views'],
  376. 'todayviews' => $data['views'],
  377. 'weekviews' => $data['views'],
  378. 'monthviews' => $data['views']
  379. )
  380. );
  381. if($highlight && $data['highlight']) {
  382. $list[$data['tid']]['fields']['showstyle'] = $this->getthreadstyle($data['highlight']);
  383. }
  384. }
  385. if($listtids) {
  386. $threads = $this->getthread($threadtids, $summarylength);
  387. if($threads) {
  388. foreach($threads as $tid => $var) {
  389. $list[$tid]['summary'] = $var;
  390. }
  391. }
  392. foreach($listtids as $key => $value) {
  393. $datalist[] = $list[$value];
  394. }
  395. }
  396. $returndata['data'] = $datalist;
  397. return $returndata;
  398. }
  399. function getthread($tidarray, $messagelength = 80, $nospecial = false) {
  400. global $_G;
  401. if(!$tidarray) {
  402. return '';
  403. }
  404. $notexists = $messagearr = $returnarr = array();
  405. foreach($tidarray as $var) {
  406. foreach($var as $v) {
  407. if(empty($_G['block_thread'][$v])) {
  408. $notexists[] = $v;
  409. }
  410. }
  411. }
  412. if($notexists) {
  413. $query = DB::query("SELECT tid, fid, subject, posttableid, price, special FROM ".DB::table('forum_thread')." WHERE tid IN (".dimplode($notexists).")");
  414. while($result = DB::fetch($query)) {
  415. $_G['block_thread'][$result['tid']] = $result;
  416. }
  417. }
  418. foreach($tidarray as $key => $var) {
  419. if($key == 0) {
  420. $posttable = 'forum_post';
  421. } else {
  422. $posttable = "forum_post_{$key}";
  423. }
  424. $query = DB::query("SELECT tid, message FROM ".DB::table($posttable)." WHERE tid IN (".dimplode($var).") AND first=1");
  425. while($result = DB::fetch($query)) {
  426. $messagearr[$result['tid']] = $result['message'];
  427. }
  428. }
  429. require_once libfile('function/post');
  430. require_once libfile('function/discuzcode');
  431. if($messagearr) {
  432. foreach($messagearr as $tid => $var) {
  433. $thread = $_G['block_thread'][$tid];
  434. if($nospecial) {
  435. $thread['special'] = 0;
  436. }
  437. if($thread['special'] == 1) {
  438. $polloptions = array();
  439. $multiple = DB::result_first("SELECT multiple FROM ".DB::table('forum_poll')." WHERE tid='$tid'");
  440. $optiontype = $multiple ? 'checkbox' : 'radio';
  441. $query = DB::query("SELECT polloptionid, polloption FROM ".DB::table('forum_polloption')." WHERE tid='$tid' ORDER BY displayorder");
  442. while($polloption = DB::fetch($query)) {
  443. $polloption['polloption'] = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i",
  444. "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $polloption['polloption']);
  445. $polloptions[] = $polloption;
  446. }
  447. } elseif($thread['special'] == 2) {
  448. $trade = C::t('forum_trade')->fetch_first_goods($tid);
  449. $trade['aid'] = $trade['aid'] ? getforumimg($trade['aid']) : '';
  450. $trades[$tid][] = $trade;
  451. } elseif($thread['special'] == 3) {
  452. $extcredits = $_G['settings']['extcredits'];
  453. $creditstransextra = $_G['settings']['creditstransextra'];
  454. $rewardend = $thread['price'] < 0;
  455. $rewardprice = abs($thread['price']);
  456. $message = messagecutstr($var, $messagelength, '');
  457. } elseif($thread['special'] == 4) {
  458. $message = messagecutstr($var, $messagelength, '');
  459. $activity = DB::fetch_first("SELECT aid, number, applynumber FROM ".DB::table('forum_activity')." WHERE tid='$tid'");
  460. $activity['aid'] = $activity['aid'] ? getforumimg($activity['aid']) : '';
  461. $activity['aboutmember'] = $activity['number'] - $activity['applynumber'];
  462. } elseif($thread['special'] == 5) {
  463. $message = messagecutstr($var, $messagelength, '');
  464. $debate = C::t('forum_debate')->fetch($tid);
  465. $debate['affirmvoteswidth'] = $debate['affirmvotes'] ? intval(80 * (($debate['affirmvotes'] + 1) / ($debate['affirmvotes'] + $debate['negavotes'] + 1))) : 1;
  466. $debate['negavoteswidth'] = $debate['negavotes'] ? intval(80 * (($debate['negavotes'] + 1) / ($debate['affirmvotes'] + $debate['negavotes'] + 1))) : 1;
  467. $debate['affirmpoint'] = discuzcode($debate['affirmpoint'], 0, 0, 0, 1, 1, 0, 0, 0, 0, 0);
  468. $debate['negapoint'] = discuzcode($debate['negapoint'], 0, 0, 0, 1, 1, 0, 0, 0, 0, 0);
  469. } else {
  470. $message = messagecutstr($var, $messagelength, '');
  471. }
  472. include template('common/block_thread');
  473. $returnarr[$tid] = $return;
  474. }
  475. }
  476. return $returnarr;
  477. }
  478. function getpic($tid) {
  479. global $_G;
  480. if(!$tid) {
  481. return '';
  482. }
  483. $pic = DB::fetch_first("SELECT attachment, remote FROM ".DB::table(getattachtablebytid($tid))." WHERE tid='$tid' AND isimage IN (1, -1) ORDER BY dateline DESC LIMIT 0,1");
  484. return $pic;
  485. }
  486. function getpics($tids) {
  487. $data = array();
  488. $tids = !empty($tids) && is_array($tids) ? $tids : array($tids);
  489. $tids = array_map('intval', $tids);
  490. $tids = array_filter($tids);
  491. if(!empty($tids)) {
  492. $query = DB::query('SELECT * FROM '.DB::table('forum_threadimage').' WHERE tid IN ('.dimplode($tids).')');
  493. while($value = DB::fetch($query)) {
  494. $data[$value['tid']] = $value;
  495. }
  496. }
  497. return $data;
  498. }
  499. function getthreadstyle($highlight) {
  500. $rt = array();
  501. if($highlight) {
  502. $color = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  503. $string = sprintf('%02d', $highlight);
  504. $stylestr = sprintf('%03b', $string[0]);
  505. $rt = array(
  506. 'title_b' => $stylestr[0] ? '1' : '',
  507. 'title_i' => $stylestr[1] ? '1' : '',
  508. 'title_u' => $stylestr[2] ? '1' : '',
  509. 'title_c' => $string[1] ? $color[$string[1]] : '',
  510. );
  511. }
  512. return $rt;
  513. }
  514. function getmaxid() {
  515. loadcache('databasemaxid');
  516. $data = getglobal('cache/databasemaxid');
  517. if(!isset($data['thread']) || TIMESTAMP - $data['thread']['dateline'] >= 86400) {
  518. $data['thread']['dateline'] = TIMESTAMP;
  519. $data['thread']['id'] = DB::result_first('SELECT MAX(tid) FROM '.DB::table('forum_thread'));
  520. savecache('databasemaxid', $data);
  521. }
  522. return $data['thread']['id'];
  523. }
  524. }
  525. ?>