forum_guide.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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: forum_guide.php 34066 2013-09-27 08:36:09Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $view = $_GET['view'];
  12. loadcache('forum_guide');
  13. if(!in_array($view, array('hot', 'digest', 'new', 'my', 'newthread', 'sofa'))) {
  14. $view = 'hot';
  15. }
  16. $lang = lang('forum/template');
  17. $navtitle = $lang['guide'].'-'.$lang['guide_'.$view];
  18. $perpage = 50;
  19. $start = $perpage * ($_G['page'] - 1);
  20. $data = array();
  21. if($_GET['rss'] == 1) {
  22. if($view == 'index' || $view == 'my') {
  23. showmessage('URL_ERROR');
  24. }
  25. $ttl = 30;
  26. $charset = $_G['config']['output']['charset'];
  27. dheader("Content-type: application/xml");
  28. echo "<?xml version=\"1.0\" encoding=\"".$charset."\"?>\n".
  29. "<rss version=\"2.0\">\n".
  30. " <channel>\n".
  31. " <title>{$_G[setting][bbname]} - $lang[guide] - ".$lang['guide_'.$view]."</title>\n".
  32. " <link>{$_G[siteurl]}forum.php?mod=guide&amp;view=$view</link>\n".
  33. " <description>".$lang['guide_'.$view]."</description>\n".
  34. " <copyright>Copyright(C) {$_G[setting][bbname]}</copyright>\n".
  35. " <generator>Discuz! Board by Comsenz Inc.</generator>\n".
  36. " <lastBuildDate>".gmdate('r', TIMESTAMP)."</lastBuildDate>\n".
  37. " <ttl>$ttl</ttl>\n".
  38. " <image>\n".
  39. " <url>{$_G[siteurl]}static/image/common/logo_88_31.gif</url>\n".
  40. " <title>{$_G[setting][bbname]}</title>\n".
  41. " <link>{$_G[siteurl]}</link>\n".
  42. " </image>\n";
  43. $info = C::t('forum_rsscache')->fetch_all_by_guidetype($view, $perpage);
  44. if(empty($info) || (TIMESTAMP - $info[0]['lastupdate'] > $ttl * 60)) {
  45. update_guide_rsscache($view, $perpage);
  46. }
  47. foreach($info as $thread) {
  48. list($thread['description'], $attachremote, $attachfile, $attachsize) = explode("\t", $thread['description']);
  49. if($attachfile) {
  50. if($attachremote) {
  51. $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attachfile;
  52. } else {
  53. $filename = $_G['siteurl'].$_G['setting']['attachurl'].'forum/'.$attachfile;
  54. }
  55. }
  56. echo " <item>\n".
  57. " <title>".$thread['subject']."</title>\n".
  58. " <link>$_G[siteurl]".($trewriteflag ? rewriteoutput('forum_viewthread', 1, '', $thread['tid']) : "forum.php?mod=viewthread&amp;tid=$thread[tid]")."</link>\n".
  59. " <description><![CDATA[".dhtmlspecialchars($thread['description'])."]]></description>\n".
  60. " <category>".dhtmlspecialchars($thread['forum'])."</category>\n".
  61. " <author>".dhtmlspecialchars($thread['author'])."</author>\n".
  62. ($attachfile ? '<enclosure url="'.$filename.'" length="'.$attachsize.'" type="image/jpeg" />' : '').
  63. " <pubDate>".gmdate('r', $thread['dateline'])."</pubDate>\n".
  64. " </item>\n";
  65. }
  66. echo " </channel>\n".
  67. "</rss>";
  68. exit();
  69. }
  70. if($view != 'index') {
  71. $theurl = 'forum.php?mod=guide&view='.$view;
  72. if($view == 'my') {
  73. if(!$_G['uid']) {
  74. showmessage('to_login', '', array(), array('login' => 1));
  75. }
  76. $lang = lang('forum/template');
  77. $filter_array = array( 'common' => $lang['have_posted'], 'save' => $lang['guide_draft'], 'close' => $lang['close'], 'aduit' => $lang['pending'], 'ignored' => $lang['have_ignored'], 'recyclebin' => $lang['forum_recyclebin']);
  78. $viewtype = in_array($_GET['type'], array('reply', 'thread', 'postcomment')) ? $_GET['type'] : 'thread';
  79. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  80. $searchkey = dhtmlspecialchars($searchkey);
  81. }
  82. $theurl .= '&type='.$viewtype;
  83. $filter = in_array($_GET['filter'], array_keys($filter_array)) ? $_GET['filter'] : '';
  84. $searchbody = 0;
  85. if($filter) {
  86. $theurl .= '&filter='.$filter;
  87. $searchbody = 1;
  88. }
  89. if($_GET['fid']) {
  90. $theurl .= '&fid='.intval($_GET['fid']);
  91. $searchbody = 1;
  92. }
  93. if($searchkey) {
  94. $theurl .= '&searchkey='.$searchkey;
  95. $searchbody = 1;
  96. }
  97. require_once libfile('function/forumlist');
  98. $forumlist = forumselect(FALSE, 0, intval($_GET['fid']));
  99. $data['my'] = get_my_threads($viewtype, $_GET['fid'], $filter, $searchkey, $start, $perpage, $theurl);
  100. $tids = $data['my']['tids'];
  101. $posts = $data['my']['posts'];
  102. } else {
  103. $data[$view] = get_guide_list($view, $start, $perpage);
  104. }
  105. if(empty($data['my']['multi'])) {
  106. $multipage = multi($data[$view]['threadcount'], $perpage, $_G['page'], $theurl, $_G['setting']['threadmaxpages']);
  107. } else {
  108. $multipage = $data['my']['multi'];
  109. }
  110. } else {
  111. $data['hot'] = get_guide_list('hot', 0, 30);
  112. $data['digest'] = get_guide_list('digest', 0, 30);
  113. $data['new'] = get_guide_list('new', 0, 30);
  114. $data['newthread'] = get_guide_list('newthread', 0, 30);
  115. }
  116. loadcache('stamps');
  117. $currentview[$view] = 'class="xw1 a"';
  118. $navigation = $view != 'index' ? ' <em>&rsaquo;</em> <a href="forum.php?mod=guide&view='.$view.'">'.$lang['guide_'.$view].'</a>' : '';
  119. include template('forum/guide');
  120. function get_guide_list($view, $start = 0, $num = 50, $again = 0) {
  121. global $_G;
  122. $setting_guide = unserialize($_G['setting']['guide']);
  123. if(!in_array($view, array('hot', 'digest', 'new', 'newthread', 'sofa'))) {
  124. return array();
  125. }
  126. loadcache('forums');
  127. $cachetimelimit = ($view != 'sofa') ? 900 : 60;
  128. $cache = $_G['cache']['forum_guide'][$view.($view=='sofa' && $_G['fid'] ? $_G['fid'] : '')];
  129. if($cache && (TIMESTAMP - $cache['cachetime']) < $cachetimelimit) {
  130. $tids = $cache['data'];
  131. $threadcount = count($tids);
  132. $tids = array_slice($tids, $start, $num, true);
  133. $updatecache = false;
  134. if(empty($tids)) {
  135. return array();
  136. }
  137. } else {
  138. $dateline = 0;
  139. $maxnum = 50000;
  140. if($setting_guide[$view.'dt']) {
  141. $dateline = time() - intval($setting_guide[$view.'dt']);
  142. }
  143. if($view != 'sofa') {
  144. $maxtid = C::t('forum_thread')->fetch_max_tid();
  145. $limittid = max(0,($maxtid - $maxnum));
  146. if($again) {
  147. $limittid = max(0,($limittid - $maxnum));
  148. }
  149. $tids = array();
  150. }
  151. foreach($_G['cache']['forums'] as $fid => $forum) {
  152. if($forum['type'] != 'group' && $forum['status'] > 0 && !$forum['viewperm'] && !$forum['havepassword']) {
  153. $fids[] = $fid;
  154. }
  155. }
  156. if(empty($fids)) {
  157. return array();
  158. }
  159. if($view == 'sofa') {
  160. if($_GET['fid']) {
  161. $sofa = C::t('forum_sofa')->fetch_all_by_fid($_GET['fid'], $start, $num);
  162. } else {
  163. $sofa = C::t('forum_sofa')->range($start, $num);
  164. foreach($sofa as $sofatid => $sofathread) {
  165. if(!in_array($sofathread, $fids)) {
  166. unset($sofathread[$sofatid]);
  167. }
  168. }
  169. }
  170. $tids = array_keys($sofa);
  171. }
  172. $updatecache = true;
  173. }
  174. $query = C::t('forum_thread')->fetch_all_for_guide($view, $limittid, $tids, $_G['setting']['heatthread']['guidelimit'], $dateline);
  175. $n = 0;
  176. foreach($query as $thread) {
  177. if(empty($tids) && ($thread['isgroup'] || !in_array($thread['fid'], $fids))) {
  178. continue;
  179. }
  180. if($thread['displayorder'] < 0) {
  181. continue;
  182. }
  183. $thread = guide_procthread($thread);
  184. $threadids[] = $thread['tid'];
  185. if($tids || ($n >= $start && $n < ($start + $num))) {
  186. $list[$thread[tid]] = $thread;
  187. $fids[$thread[fid]] = $thread['fid'];
  188. }
  189. $n ++;
  190. }
  191. if($limittid > $maxnum && !$again && count($list) < 50) {
  192. return get_guide_list($view, $start, $num, 1);
  193. }
  194. $forumnames = array();
  195. if($fids) {
  196. $forumnames = C::t('forum_forum')->fetch_all_name_by_fid($fids);
  197. }
  198. $threadlist = array();
  199. if($tids) {
  200. $threadids = array();
  201. foreach($tids as $key => $tid) {
  202. if($list[$tid]) {
  203. $threadlist[$key] = $list[$tid];
  204. $threadids[] = $tid;
  205. }
  206. }
  207. } else {
  208. $threadlist = $list;
  209. }
  210. unset($list);
  211. if($updatecache) {
  212. $threadcount = count($threadids);
  213. $data = array('cachetime' => TIMESTAMP, 'data' => $threadids);
  214. $_G['cache']['forum_guide'][$view.($view=='sofa' && $_G['fid'] ? $_G['fid'] : '')] = $data;
  215. savecache('forum_guide', $_G['cache']['forum_guide']);
  216. }
  217. return array('forumnames' => $forumnames, 'threadcount' => $threadcount, 'threadlist' => $threadlist);
  218. }
  219. function get_my_threads($viewtype, $fid = 0, $filter = '', $searchkey = '', $start = 0, $perpage = 20, $theurl = '') {
  220. global $_G;
  221. $fid = $fid ? intval($fid) : null;
  222. loadcache('forums');
  223. $dglue = '=';
  224. if($viewtype == 'thread') {
  225. $authorid = $_G['uid'];
  226. $dglue = '=';
  227. if($filter == 'recyclebin') {
  228. $displayorder = -1;
  229. } elseif($filter == 'aduit') {
  230. $displayorder = -2;
  231. } elseif($filter == 'ignored') {
  232. $displayorder = -3;
  233. } elseif($filter == 'save') {
  234. $displayorder = -4;
  235. } elseif($filter == 'close') {
  236. $closed = 1;
  237. } elseif($filter == 'common') {
  238. $closed = 0;
  239. $displayorder = 0;
  240. $dglue = '>=';
  241. }
  242. $gids = $fids = $forums = array();
  243. foreach(C::t('forum_thread')->fetch_all_by_authorid_displayorder($authorid, $displayorder, $dglue, $closed, $searchkey, $start, $perpage, null, $fid) as $tid => $value) {
  244. if(!isset($_G['cache']['forums'][$value['fid']])) {
  245. $gids[$value['fid']] = $value['fid'];
  246. } else {
  247. $forumnames[$value['fid']] = array('fid'=> $value['fid'], 'name' => $_G['cache']['forums'][$value['fid']]['name']);
  248. }
  249. $list[$value['tid']] = guide_procthread($value);
  250. }
  251. if(!empty($gids)) {
  252. $gforumnames = C::t('forum_forum')->fetch_all_name_by_fid($gids);
  253. foreach($gforumnames as $fid => $val) {
  254. $forumnames[$fid] = $val;
  255. }
  256. }
  257. $listcount = count($list);
  258. } elseif($viewtype == 'postcomment') {
  259. require_once libfile('function/post');
  260. $pids = $tids = array();
  261. $postcommentarr = C::t('forum_postcomment')->fetch_all_by_authorid($_G['uid'], $start, $perpage);
  262. foreach($postcommentarr as $value) {
  263. $pids[] = $value['pid'];
  264. $tids[] = $value['tid'];
  265. }
  266. $pids = C::t('forum_post')->fetch_all(0, $pids);
  267. $tids = C::t('forum_thread')->fetch_all($tids);
  268. $list = $fids = array();
  269. foreach($postcommentarr as $value) {
  270. $value['authorid'] = $pids[$value['pid']]['authorid'];
  271. $value['fid'] = $pids[$value['pid']]['fid'];
  272. $value['invisible'] = $pids[$value['pid']]['invisible'];
  273. $value['dateline'] = $pids[$value['pid']]['dateline'];
  274. $value['message'] = $pids[$value['pid']]['message'];
  275. $value['special'] = $tids[$value['tid']]['special'];
  276. $value['status'] = $tids[$value['tid']]['status'];
  277. $value['subject'] = $tids[$value['tid']]['subject'];
  278. $value['digest'] = $tids[$value['tid']]['digest'];
  279. $value['attachment'] = $tids[$value['tid']]['attachment'];
  280. $value['replies'] = $tids[$value['tid']]['replies'];
  281. $value['views'] = $tids[$value['tid']]['views'];
  282. $value['lastposter'] = $tids[$value['tid']]['lastposter'];
  283. $value['lastpost'] = $tids[$value['tid']]['lastpost'];
  284. $value['icon'] = $tids[$value['tid']]['icon'];
  285. $value['tid'] = $pids[$value['pid']]['tid'];
  286. $fids[] = $value['fid'];
  287. $value['comment'] = messagecutstr($value['comment'], 100);
  288. $list[] = guide_procthread($value);
  289. }
  290. unset($pids, $tids, $postcommentarr);
  291. if($fids) {
  292. $fids = array_unique($fids);
  293. $forumnames = C::t('forum_forum')->fetch_all_name_by_fid($gids);
  294. }
  295. $listcount = count($list);
  296. } else {
  297. $invisible = null;
  298. if($filter == 'recyclebin') {
  299. $invisible = -5;
  300. } elseif($filter == 'aduit') {
  301. $invisible = -2;
  302. } elseif($filter == 'save' || $filter == 'ignored') {
  303. $invisible = -3;
  304. $displayorder = -4;
  305. } elseif($filter == 'close') {
  306. $closed = 1;
  307. } elseif($filter == 'common') {
  308. $invisible = 0;
  309. $displayorder = 0;
  310. $dglue = '>=';
  311. $closed = 0;
  312. }
  313. require_once libfile('function/post');
  314. $posts = C::t('forum_post')->fetch_all_by_authorid(0, $_G['uid'], true, 'DESC', $start, $perpage, null, $invisible, $fid, $followfid);
  315. $listcount = count($posts);
  316. foreach($posts as $pid => $post) {
  317. $tids[$post['tid']][] = $pid;
  318. $post['message'] = !getstatus($post['status'], 2) || $post['authorid'] == $_G['uid'] ? messagecutstr($post['message'], 100) : '';
  319. $posts[$pid] = $post;
  320. }
  321. if(!empty($tids)) {
  322. $threads = C::t('forum_thread')->fetch_all_by_tid_displayorder(array_keys($tids), $displayorder, $dglue, array(), $closed);
  323. foreach($threads as $tid => $thread) {
  324. if(!isset($_G['cache']['forums'][$thread['fid']])) {
  325. $gids[$thread['fid']] = $thread['fid'];
  326. } else {
  327. $forumnames[$thread[fid]] = array('fid' => $thread['fid'], 'name' => $_G['cache']['forums'][$thread[fid]]['name']);
  328. }
  329. $threads[$tid] = guide_procthread($thread);
  330. }
  331. if(!empty($gids)) {
  332. $groupforums = C::t('forum_forum')->fetch_all_name_by_fid($gids);
  333. foreach($groupforums as $fid => $val) {
  334. $forumnames[$fid] = $val;
  335. }
  336. }
  337. $list = array();
  338. foreach($tids as $key => $val) {
  339. $list[$key] = $threads[$key];
  340. }
  341. unset($threads);
  342. }
  343. }
  344. $multi = simplepage($listcount, $perpage, $_G['page'], $theurl);
  345. return array('forumnames' => $forumnames, 'threadcount' => $listcount, 'threadlist' => $list, 'multi' => $multi, 'tids' => $tids, 'posts' => $posts);
  346. }
  347. function guide_procthread($thread) {
  348. global $_G;
  349. $todaytime = strtotime(dgmdate(TIMESTAMP, 'Ymd'));
  350. $thread['lastposterenc'] = rawurlencode($thread['lastposter']);
  351. $thread['multipage'] = '';
  352. $topicposts = $thread['special'] ? $thread['replies'] : $thread['replies'] + 1;
  353. if($topicposts > $_G['ppp']) {
  354. $pagelinks = '';
  355. $thread['pages'] = ceil($topicposts / $_G['ppp']);
  356. for($i = 2; $i <= 6 && $i <= $thread['pages']; $i++) {
  357. $pagelinks .= "<a href=\"forum.php?mod=viewthread&tid=$thread[tid]&amp;extra=$extra&amp;page=$i\">$i</a>";
  358. }
  359. if($thread['pages'] > 6) {
  360. $pagelinks .= "..<a href=\"forum.php?mod=viewthread&tid=$thread[tid]&amp;extra=$extra&amp;page=$thread[pages]\">$thread[pages]</a>";
  361. }
  362. $thread['multipage'] = '&nbsp;...'.$pagelinks;
  363. }
  364. if($thread['highlight']) {
  365. $string = sprintf('%02d', $thread['highlight']);
  366. $stylestr = sprintf('%03b', $string[0]);
  367. $thread['highlight'] = ' style="';
  368. $thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
  369. $thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
  370. $thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
  371. $thread['highlight'] .= $string[1] ? 'color: '.$_G['forum_colorarray'][$string[1]] : '';
  372. $thread['highlight'] .= '"';
  373. } else {
  374. $thread['highlight'] = '';
  375. }
  376. $thread['recommendicon'] = '';
  377. if(!empty($_G['setting']['recommendthread']['status']) && $thread['recommends']) {
  378. foreach($_G['setting']['recommendthread']['iconlevels'] as $k => $i) {
  379. if($thread['recommends'] > $i) {
  380. $thread['recommendicon'] = $k+1;
  381. break;
  382. }
  383. }
  384. }
  385. $thread['moved'] = $thread['heatlevel'] = $thread['new'] = 0;
  386. $thread['icontid'] = $thread['forumstick'] || !$thread['moved'] && $thread['isgroup'] != 1 ? $thread['tid'] : $thread['closed'];
  387. $thread['folder'] = 'common';
  388. $thread['weeknew'] = TIMESTAMP - 604800 <= $thread['dbdateline'];
  389. if($thread['replies'] > $thread['views']) {
  390. $thread['views'] = $thread['replies'];
  391. }
  392. if($_G['setting']['heatthread']['iconlevels']) {
  393. foreach($_G['setting']['heatthread']['iconlevels'] as $k => $i) {
  394. if($thread['heats'] > $i) {
  395. $thread['heatlevel'] = $k + 1;
  396. break;
  397. }
  398. }
  399. }
  400. $thread['istoday'] = $thread['dateline'] > $todaytime ? 1 : 0;
  401. $thread['dbdateline'] = $thread['dateline'];
  402. $thread['dateline'] = dgmdate($thread['dateline'], 'u', '9999', getglobal('setting/dateformat'));
  403. $thread['dblastpost'] = $thread['lastpost'];
  404. $thread['lastpost'] = dgmdate($thread['lastpost'], 'u');
  405. if(in_array($thread['displayorder'], array(1, 2, 3, 4))) {
  406. $thread['id'] = 'stickthread_'.$thread['tid'];
  407. } else {
  408. $thread['id'] = 'normalthread_'.$thread['tid'];
  409. }
  410. $thread['rushreply'] = getstatus($thread['status'], 3);
  411. return $thread;
  412. }
  413. function update_guide_rsscache($type, $perpage) {
  414. global $_G;
  415. $processname = 'guide_rss_cache';
  416. if(discuz_process::islocked($processname, 600)) {
  417. return false;
  418. }
  419. C::t('forum_rsscache')->delete_by_guidetype($type);
  420. require_once libfile('function/post');
  421. $data = get_guide_list($type, 0, $perpage);
  422. foreach($data['threadlist'] as $thread) {
  423. $thread['author'] = $thread['author'] != '' ? addslashes($thread['author']) : 'Anonymous';
  424. $thread['subject'] = addslashes($thread['subject']);
  425. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  426. $attachdata = '';
  427. if($post['attachment'] == 2) {
  428. $attach = C::t('forum_attachment_n')->fetch_max_image('tid:'.$thread['tid'], 'pid', $post['pid']);
  429. $attachdata = "\t".$attach['remote']."\t".$attach['attachment']."\t".$attach['filesize'];
  430. }
  431. $thread['message'] = $post['message'];
  432. $thread['status'] = $post['status'];
  433. $thread['description'] = $thread['readperm'] > 0 || $thread['price'] > 0 || $thread['status'] & 1 ? '' : addslashes(messagecutstr($thread['message'], 250 - strlen($attachdata)).$attachdata);
  434. C::t('forum_rsscache')->insert(array(
  435. 'lastupdate'=>$_G['timestamp'],
  436. 'fid'=>$thread['fid'],
  437. 'tid'=>$thread['tid'],
  438. 'dateline'=>$thread['dbdateline'],
  439. 'forum'=>strip_tags($data['forumnames'][$thread[fid]]['name']),
  440. 'author'=>$thread['author'],
  441. 'subject'=>$thread['subject'],
  442. 'description'=>$thread['description'],
  443. 'guidetype'=>$type
  444. ), false, true);
  445. }
  446. discuz_process::unlock($processname);
  447. return true;
  448. }
  449. ?>