space_thread.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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: space_thread.php 31365 2012-08-20 03:19:33Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $minhot = $_G['setting']['feedhotmin']<1?3:$_G['setting']['feedhotmin'];
  12. $page = empty($_GET['page'])?1:intval($_GET['page']);
  13. if($page<1) $page=1;
  14. $id = empty($_GET['id'])?0:intval($_GET['id']);
  15. $opactives['thread'] = 'class="a"';
  16. if(empty($_GET['view'])) $_GET['view'] = 'me';
  17. $_GET['order'] = empty($_GET['order']) ? 'dateline' : $_GET['order'];
  18. $allowviewuserthread = $_G['setting']['allowviewuserthread'];
  19. $perpage = 20;
  20. $start = ($page-1)*$perpage;
  21. ckstart($start, $perpage);
  22. $list = array();
  23. $userlist = array();
  24. $hiddennum = $count = $pricount = 0;
  25. $_GET['from'] = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\]]/", '', $_GET['from']));
  26. $gets = array(
  27. 'mod' => 'space',
  28. 'uid' => $space['uid'],
  29. 'do' => 'thread',
  30. 'fid' => $_GET['fid'],
  31. 'view' => $_GET['view'],
  32. 'type' => $_GET['type'],
  33. 'order' => $_GET['order'],
  34. 'fuid' => $_GET['fuid'],
  35. 'searchkey' => $_GET['searchkey'],
  36. 'from' => $_GET['from'],
  37. 'filter' => $_GET['filter']
  38. );
  39. $theurl = 'home.php?'.url_implode($gets);
  40. unset($gets['fid']);
  41. $forumurl = 'home.php?'.url_implode($gets);
  42. $multi = '';
  43. $authorid = 0;
  44. $replies = $closed = $displayorder = null;
  45. $dglue = '=';
  46. $vfid = $_GET['fid'] ? intval($_GET['fid']) : null;
  47. require_once libfile('function/misc');
  48. require_once libfile('function/forum');
  49. loadcache(array('forums'));
  50. $fids = $comma = '';
  51. if($_GET['view'] != 'me') {
  52. $displayorder = 0;
  53. $dglue = '>=';
  54. }
  55. $f_index = '';
  56. $ordersql = 't.dateline DESC';
  57. $need_count = true;
  58. $viewuserthread = false;
  59. $listcount = 0;
  60. if($_GET['view'] == 'me') {
  61. if($_GET['from'] == 'space') $diymode = 1;
  62. $allowview = true;
  63. $viewtype = in_array($_GET['type'], array('reply', 'thread', 'postcomment')) ? $_GET['type'] : 'thread';
  64. $filter = in_array($_GET['filter'], array('recyclebin', 'ignored', 'save', 'aduit', 'close', 'common')) ? $_GET['filter'] : '';
  65. if($space['uid'] != $_G['uid'] && in_array($viewtype, array('reply', 'thread'))) {
  66. if($allowviewuserthread === -1 && $_G['adminid'] != 1) {
  67. $allowview = false;
  68. }
  69. if($allowview) {
  70. $viewuserthread = true;
  71. $viewfids = str_replace("'", '', $allowviewuserthread);
  72. if(!empty($viewfids)) {
  73. $viewfids = explode(',', $viewfids);
  74. }
  75. }
  76. }
  77. if($viewtype == 'thread' && $allowview) {
  78. $authorid = $space['uid'];
  79. if($filter == 'recyclebin') {
  80. $displayorder = -1;
  81. } elseif($filter == 'aduit') {
  82. $displayorder = -2;
  83. } elseif($filter == 'ignored') {
  84. $displayorder = -3;
  85. } elseif($filter == 'save') {
  86. $displayorder = -4;
  87. } elseif($filter == 'close') {
  88. $closed = 1;
  89. } elseif($filter == 'common') {
  90. $closed = 0;
  91. $displayorder = 0;
  92. $dglue = '>=';
  93. }
  94. $ordersql = 't.tid DESC';
  95. } elseif($viewtype == 'postcomment') {
  96. $posttable = getposttable();
  97. require_once libfile('function/post');
  98. $pids = $tids = array();
  99. $postcommentarr = C::t('forum_postcomment')->fetch_all_by_authorid($_G['uid'], $start, $perpage);
  100. foreach($postcommentarr as $value) {
  101. $pids[] = $value['pid'];
  102. $tids[] = $value['tid'];
  103. }
  104. $pids = C::t('forum_post')->fetch_all(0, $pids);
  105. $tids = C::t('forum_thread')->fetch_all($tids);
  106. $list = $fids = array();
  107. foreach($postcommentarr as $value) {
  108. $value['authorid'] = $pids[$value['pid']]['authorid'];
  109. $value['fid'] = $pids[$value['pid']]['fid'];
  110. $value['invisible'] = $pids[$value['pid']]['invisible'];
  111. $value['dateline'] = $pids[$value['pid']]['dateline'];
  112. $value['message'] = $pids[$value['pid']]['message'];
  113. $value['special'] = $tids[$value['tid']]['special'];
  114. $value['status'] = $tids[$value['tid']]['status'];
  115. $value['subject'] = $tids[$value['tid']]['subject'];
  116. $value['digest'] = $tids[$value['tid']]['digest'];
  117. $value['attachment'] = $tids[$value['tid']]['attachment'];
  118. $value['replies'] = $tids[$value['tid']]['replies'];
  119. $value['views'] = $tids[$value['tid']]['views'];
  120. $value['lastposter'] = $tids[$value['tid']]['lastposter'];
  121. $value['lastpost'] = $tids[$value['tid']]['lastpost'];
  122. $value['tid'] = $pids[$value['pid']]['tid'];
  123. $fids[] = $value['fid'];
  124. $value['comment'] = messagecutstr($value['comment'], 100);
  125. $list[] = procthread($value);
  126. }
  127. unset($pids, $tids, $postcommentarr);
  128. if($fids) {
  129. $fids = array_unique($fids);
  130. $query = C::t('forum_forum')->fetch_all($fids);
  131. foreach($query as $forum) {
  132. $forums[$forum['fid']] = $forum['name'];
  133. }
  134. }
  135. $multi = simplepage(count($list), $perpage, $page, $theurl);
  136. $need_count = false;
  137. } elseif($allowview) {
  138. $invisible = null;
  139. $postsql = $threadsql = '';
  140. if($filter == 'recyclebin') {
  141. $invisible = -5;
  142. } elseif($filter == 'aduit') {
  143. $invisible = -2;
  144. } elseif($filter == 'save' || $filter == 'ignored') {
  145. $invisible = -3;
  146. $displayorder = -4;
  147. } elseif($filter == 'close') {
  148. $closed = 1;
  149. } elseif($filter == 'common') {
  150. $invisible = 0;
  151. $displayorder = 0;
  152. $dglue = '>=';
  153. $closed = 0;
  154. } else {
  155. if($space['uid'] != $_G['uid']) {
  156. $invisible = 0;
  157. }
  158. }
  159. require_once libfile('function/post');
  160. $posts = C::t('forum_post')->fetch_all_by_authorid(0, $space['uid'], true, 'DESC', $start, $perpage, 0, $invisible, $vfid);
  161. $listcount = count($posts);
  162. foreach($posts as $pid => $post) {
  163. $delrow = false;
  164. if($post['anonymous'] && $post['authorid'] != $_G['uid']) {
  165. $delrow = true;
  166. } elseif($viewuserthread && $post['authorid'] != $_G['uid']) {
  167. if(($_G['adminid'] != 1 && !empty($viewfids) && !in_array($post['fid'], $viewfids))) {
  168. $delrow = true;
  169. }
  170. }
  171. if($delrow) {
  172. unset($posts[$pid]);
  173. $hiddennum++;
  174. continue;
  175. } else {
  176. $tids[$post['tid']][] = $pid;
  177. $post['message'] = !getstatus($post['status'], 2) || $post['authorid'] == $_G['uid'] ? messagecutstr($post['message'], 100) : '';
  178. $posts[$pid] = $post;
  179. }
  180. }
  181. if(!empty($tids)) {
  182. $threads = C::t('forum_thread')->fetch_all_by_tid_displayorder(array_keys($tids), $displayorder, $dglue, array(), $closed);
  183. foreach($threads as $tid => $thread) {
  184. $delrow = false;
  185. if($_G['adminid'] != 1 && $thread['displayorder'] < 0) {
  186. $delrow = true;
  187. } elseif($_G['adminid'] != 1 && $_G['uid'] != $thread['authorid'] && getstatus($thread['status'], 2)) {
  188. $delrow = true;
  189. } elseif(!isset($_G['cache']['forums'][$thread['fid']])) {
  190. if(!$_G['setting']['groupstatus']) {
  191. $delrow = true;
  192. } else {
  193. $gids[$thread['fid']] = $thread['tid'];
  194. }
  195. }
  196. if($delrow) {
  197. foreach($tids[$tid] as $pid) {
  198. unset($posts[$pid]);
  199. $hiddennum++;
  200. }
  201. unset($tids[$tid]);
  202. unset($threads[$tid]);
  203. continue;
  204. } else {
  205. $threads[$tid] = procthread($thread);
  206. $forums[$thread['fid']] = $threads[$tid]['forumname'];
  207. }
  208. }
  209. if(!empty($gids)) {
  210. $groupforums = C::t('forum_forum')->fetch_all_name_by_fid(array_keys($gids));
  211. foreach($gids as $fid => $tid) {
  212. $threads[$tid]['forumname'] = $groupforums[$fid]['name'];
  213. $forums[$fid] = $groupforums[$fid]['name'];
  214. }
  215. }
  216. if(!empty($tids)) {
  217. foreach($tids as $tid => $pids) {
  218. foreach($pids as $pid) {
  219. if(!isset($threads[$tid])) {
  220. unset($posts[$pid]);
  221. unset($tids[$tid]);
  222. $hiddennum++;
  223. continue;
  224. }
  225. }
  226. }
  227. }
  228. $list = &$threads;
  229. }
  230. $multi = simplepage($listcount, $perpage, $page, $theurl);
  231. $need_count = false;
  232. }
  233. if(!$allowview) {
  234. $need_count = false;
  235. }
  236. $orderactives = array($viewtype => ' class="a"');
  237. } else {
  238. space_merge($space, 'field_home');
  239. if($space['feedfriend']) {
  240. $fuid_actives = array();
  241. require_once libfile('function/friend');
  242. $fuid = intval($_GET['fuid']);
  243. if($fuid && friend_check($fuid, $space['uid'])) {
  244. $authorid = $fuid;
  245. $fuid_actives = array($fuid=>' selected');
  246. } else {
  247. $authorid = explode(',', $space['feedfriend']);
  248. }
  249. $query = C::t('home_friend')->fetch_all_by_uid($_G['uid'], 0, 100, true);
  250. foreach($query as $value) {
  251. $userlist[] = $value;
  252. }
  253. } else {
  254. $need_count = false;
  255. }
  256. }
  257. $actives = array($_GET['view'] =>' class="a"');
  258. if($need_count) {
  259. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  260. $searchkey = dhtmlspecialchars($searchkey);
  261. }
  262. loadcache('forums');
  263. $gids = $fids = $forums = array();
  264. foreach(C::t('forum_thread')->fetch_all_by_authorid_displayorder($authorid, $displayorder, $dglue, $closed, $searchkey, $start, $perpage, $replies, $vfid) as $tid => $value) {
  265. if(empty($value['author']) && $value['authorid'] != $_G['uid']) {
  266. $hiddennum++;
  267. continue;
  268. } elseif($viewuserthread && $value['authorid'] != $_G['uid']) {
  269. if(($_G['adminid'] != 1 && !empty($viewfids) && !in_array($value['fid'], $viewfids)) || $value['displayorder'] < 0) {
  270. $hiddennum++;
  271. continue;
  272. }
  273. } elseif(!isset($_G['cache']['forums'][$value['fid']])) {
  274. if(!$_G['setting']['groupstatus']) {
  275. $hiddennum++;
  276. continue;
  277. } else {
  278. $gids[$value['fid']] = $value['tid'];
  279. }
  280. }
  281. $list[$value['tid']] = procthread($value);
  282. $forums[$value['fid']] = $list[$value['tid']]['forumname'];
  283. }
  284. if(!empty($gids)) {
  285. $gforumnames = C::t('forum_forum')->fetch_all_name_by_fid(array_keys($gids));
  286. foreach($gids as $fid => $tid) {
  287. $list[$tid]['forumname'] = $gforumnames[$fid]['name'];
  288. $forums[$fid] = $gforumnames[$fid]['name'];
  289. }
  290. }
  291. $threads = &$list;
  292. if($_GET['view'] != 'all') {
  293. $listcount = count($list)+$hiddennum;
  294. $multi = simplepage($listcount, $perpage, $page, $theurl);
  295. }
  296. }
  297. require_once libfile('function/forumlist');
  298. $forumlist = forumselect(FALSE, 0, intval($_GET['fid']));
  299. dsetcookie('home_diymode', $diymode);
  300. if($_G['uid']) {
  301. $_GET['view'] = !$_GET['view'] ? 'we' : $_GET['view'];
  302. $navtitle = lang('core', 'title_'.$_GET['view'].'_thread');
  303. } else {
  304. $navtitle = lang('core', 'title_thread');
  305. }
  306. if($space['username']) {
  307. $navtitle = lang('space', 'sb_thread', array('who' => $space['username']));
  308. }
  309. $metakeywords = $navtitle;
  310. $metadescription = $navtitle;
  311. if(!$_G['follow']) {
  312. include_once template("diy:home/space_thread");
  313. }
  314. ?>