/viewforum.php

https://github.com/sietf/sietf.org · PHP · 701 lines · 510 code · 114 blank · 77 comment · 137 complexity · 2c33cd27f33bc7849d50758eb5f1a5c2 MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: viewforum.php 9459 2009-04-17 15:08:09Z acydburn $
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  18. // Start session
  19. $user->session_begin();
  20. $auth->acl($user->data);
  21. // Start initial var setup
  22. $forum_id = request_var('f', 0);
  23. $mark_read = request_var('mark', '');
  24. $start = request_var('start', 0);
  25. $default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
  26. $default_sort_key = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
  27. $default_sort_dir = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
  28. $sort_days = request_var('st', $default_sort_days);
  29. $sort_key = request_var('sk', $default_sort_key);
  30. $sort_dir = request_var('sd', $default_sort_dir);
  31. // Check if the user has actually sent a forum ID with his/her request
  32. // If not give them a nice error page.
  33. if (!$forum_id)
  34. {
  35. trigger_error('NO_FORUM');
  36. }
  37. $sql_from = FORUMS_TABLE . ' f';
  38. $lastread_select = '';
  39. // Grab appropriate forum data
  40. if ($config['load_db_lastread'] && $user->data['is_registered'])
  41. {
  42. $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
  43. AND ft.forum_id = f.forum_id)';
  44. $lastread_select .= ', ft.mark_time';
  45. }
  46. if ($user->data['is_registered'])
  47. {
  48. $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
  49. $lastread_select .= ', fw.notify_status';
  50. }
  51. $sql = "SELECT f.* $lastread_select
  52. FROM $sql_from
  53. WHERE f.forum_id = $forum_id";
  54. $result = $db->sql_query($sql);
  55. $forum_data = $db->sql_fetchrow($result);
  56. $db->sql_freeresult($result);
  57. if (!$forum_data)
  58. {
  59. trigger_error('NO_FORUM');
  60. }
  61. // Configure style, language, etc.
  62. $user->setup('viewforum', $forum_data['forum_style']);
  63. // Redirect to login upon emailed notification links
  64. if (isset($_GET['e']) && !$user->data['is_registered'])
  65. {
  66. login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
  67. }
  68. // Permissions check
  69. if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)))
  70. {
  71. if ($user->data['user_id'] != ANONYMOUS)
  72. {
  73. trigger_error('SORRY_AUTH_READ');
  74. }
  75. login_box('', $user->lang['LOGIN_VIEWFORUM']);
  76. }
  77. // Forum is passworded ... check whether access has been granted to this
  78. // user this session, if not show login box
  79. if ($forum_data['forum_password'])
  80. {
  81. login_forum_box($forum_data);
  82. }
  83. // Is this forum a link? ... User got here either because the
  84. // number of clicks is being tracked or they guessed the id
  85. if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
  86. {
  87. // Does it have click tracking enabled?
  88. if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
  89. {
  90. $sql = 'UPDATE ' . FORUMS_TABLE . '
  91. SET forum_posts = forum_posts + 1
  92. WHERE forum_id = ' . $forum_id;
  93. $db->sql_query($sql);
  94. }
  95. // We redirect to the url. The third parameter indicates that external redirects are allowed.
  96. redirect($forum_data['forum_link'], false, true);
  97. return;
  98. }
  99. // Build navigation links
  100. generate_forum_nav($forum_data);
  101. // Forum Rules
  102. if ($auth->acl_get('f_read', $forum_id))
  103. {
  104. generate_forum_rules($forum_data);
  105. }
  106. // Do we have subforums?
  107. $active_forum_ary = $moderators = array();
  108. if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
  109. {
  110. list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
  111. }
  112. else
  113. {
  114. $template->assign_var('S_HAS_SUBFORUM', false);
  115. get_moderators($moderators, $forum_id);
  116. }
  117. // Dump out the page header and load viewforum template
  118. page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']);
  119. $template->set_filenames(array(
  120. 'body' => 'viewforum_body.html')
  121. );
  122. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
  123. $template->assign_vars(array(
  124. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
  125. ));
  126. // Not postable forum or showing active topics?
  127. if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
  128. {
  129. page_footer();
  130. }
  131. // Ok, if someone has only list-access, we only display the forum list.
  132. // We also make this circumstance available to the template in case we want to display a notice. ;)
  133. if (!$auth->acl_get('f_read', $forum_id))
  134. {
  135. $template->assign_vars(array(
  136. 'S_NO_READ_ACCESS' => true,
  137. 'S_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false,
  138. 'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') . '&amp;redirect=' . urlencode(str_replace('&amp;', '&', build_url())),
  139. ));
  140. page_footer();
  141. }
  142. // Handle marking posts
  143. if ($mark_read == 'topics')
  144. {
  145. $token = request_var('hash', '');
  146. if (check_link_hash($token, 'global'))
  147. {
  148. markread('topics', $forum_id);
  149. }
  150. $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  151. meta_refresh(3, $redirect_url);
  152. trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
  153. }
  154. // Is a forum specific topic count required?
  155. if ($forum_data['forum_topics_per_page'])
  156. {
  157. $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
  158. }
  159. // Do the forum Prune thang - cron type job ...
  160. if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
  161. {
  162. $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
  163. }
  164. // Forum rules and subscription info
  165. $s_watching_forum = array(
  166. 'link' => '',
  167. 'title' => '',
  168. 'is_watching' => false,
  169. );
  170. if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && $auth->acl_get('f_subscribe', $forum_id))
  171. {
  172. $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
  173. watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status);
  174. }
  175. $s_forum_rules = '';
  176. gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
  177. // Topic ordering options
  178. $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  179. $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
  180. $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
  181. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  182. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
  183. // Limit topics to certain time frame, obtain correct topic count
  184. // global announcements must not be counted, normal announcements have to
  185. // be counted, as forum_topics(_real) includes them
  186. if ($sort_days)
  187. {
  188. $min_post_time = time() - ($sort_days * 86400);
  189. $sql = 'SELECT COUNT(topic_id) AS num_topics
  190. FROM ' . TOPICS_TABLE . "
  191. WHERE forum_id = $forum_id
  192. AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time)
  193. OR topic_type = " . POST_ANNOUNCE . ")
  194. " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
  195. $result = $db->sql_query($sql);
  196. $topics_count = (int) $db->sql_fetchfield('num_topics');
  197. $db->sql_freeresult($result);
  198. if (isset($_POST['sort']))
  199. {
  200. $start = 0;
  201. }
  202. $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
  203. // Make sure we have information about day selection ready
  204. $template->assign_var('S_SORT_DAYS', true);
  205. }
  206. else
  207. {
  208. $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
  209. $sql_limit_time = '';
  210. }
  211. // Make sure $start is set to the last page if it exceeds the amount
  212. if ($start < 0 || $start > $topics_count)
  213. {
  214. $start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
  215. }
  216. // Basic pagewide vars
  217. $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
  218. // Display active topics?
  219. $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  220. $template->assign_vars(array(
  221. 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
  222. 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
  223. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  224. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  225. 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'),
  226. 'FOLDER_NEW_IMG' => $user->img('topic_unread', 'NEW_POSTS'),
  227. 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_NEW_POSTS_HOT'),
  228. 'FOLDER_HOT_NEW_IMG' => $user->img('topic_unread_hot', 'NEW_POSTS_HOT'),
  229. 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_NEW_POSTS_LOCKED'),
  230. 'FOLDER_LOCKED_NEW_IMG' => $user->img('topic_unread_locked', 'NEW_POSTS_LOCKED'),
  231. 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
  232. 'FOLDER_STICKY_NEW_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
  233. 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
  234. 'FOLDER_ANNOUNCE_NEW_IMG' => $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
  235. 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
  236. 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
  237. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
  238. 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
  239. 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
  240. 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
  241. 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  242. 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
  243. 'S_DISPLAY_ACTIVE' => $s_display_active,
  244. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  245. 'S_SELECT_SORT_KEY' => $s_sort_key,
  246. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  247. 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
  248. 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
  249. 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
  250. 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
  251. 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
  252. 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
  253. 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 'fid[]=' . $forum_id),
  254. 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
  255. 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
  256. 'S_VIEWFORUM' => true,
  257. 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
  258. 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&amp;f=' . $forum_id) : '',
  259. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . "&amp;start=$start"),
  260. 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&amp;f=$forum_id&amp;mark=topics") : '',
  261. ));
  262. // Grab icons
  263. $icons = $cache->obtain_icons();
  264. // Grab all topic data
  265. $rowset = $announcement_list = $topic_list = $global_announce_list = array();
  266. $sql_array = array(
  267. 'SELECT' => 't.*',
  268. 'FROM' => array(
  269. TOPICS_TABLE => 't'
  270. ),
  271. 'LEFT_JOIN' => array(),
  272. );
  273. $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
  274. if ($user->data['is_registered'])
  275. {
  276. if ($config['load_db_track'])
  277. {
  278. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
  279. $sql_array['SELECT'] .= ', tp.topic_posted';
  280. }
  281. if ($config['load_db_lastread'])
  282. {
  283. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
  284. $sql_array['SELECT'] .= ', tt.mark_time';
  285. if ($s_display_active && sizeof($active_forum_ary))
  286. {
  287. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
  288. $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
  289. }
  290. }
  291. }
  292. if ($forum_data['forum_type'] == FORUM_POST)
  293. {
  294. // Obtain announcements ... removed sort ordering, sort by time in all cases
  295. $sql = $db->sql_build_query('SELECT', array(
  296. 'SELECT' => $sql_array['SELECT'],
  297. 'FROM' => $sql_array['FROM'],
  298. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  299. 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
  300. AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
  301. 'ORDER_BY' => 't.topic_time DESC',
  302. ));
  303. $result = $db->sql_query($sql);
  304. while ($row = $db->sql_fetchrow($result))
  305. {
  306. $rowset[$row['topic_id']] = $row;
  307. $announcement_list[] = $row['topic_id'];
  308. if ($row['topic_type'] == POST_GLOBAL)
  309. {
  310. $global_announce_list[$row['topic_id']] = true;
  311. }
  312. else
  313. {
  314. $topics_count--;
  315. }
  316. }
  317. $db->sql_freeresult($result);
  318. }
  319. // If the user is trying to reach late pages, start searching from the end
  320. $store_reverse = false;
  321. $sql_limit = $config['topics_per_page'];
  322. if ($start > $topics_count / 2)
  323. {
  324. $store_reverse = true;
  325. if ($start + $config['topics_per_page'] > $topics_count)
  326. {
  327. $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
  328. }
  329. // Select the sort order
  330. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
  331. $sql_start = max(0, $topics_count - $sql_limit - $start);
  332. }
  333. else
  334. {
  335. // Select the sort order
  336. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  337. $sql_start = $start;
  338. }
  339. if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
  340. {
  341. $sql_where = 't.forum_id = ' . $forum_id;
  342. }
  343. else if (empty($active_forum_ary['exclude_forum_id']))
  344. {
  345. $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
  346. }
  347. else
  348. {
  349. $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
  350. $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
  351. }
  352. // Grab just the sorted topic ids
  353. $sql = 'SELECT t.topic_id
  354. FROM ' . TOPICS_TABLE . " t
  355. WHERE $sql_where
  356. AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
  357. $sql_approved
  358. $sql_limit_time
  359. ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
  360. $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
  361. while ($row = $db->sql_fetchrow($result))
  362. {
  363. $topic_list[] = (int) $row['topic_id'];
  364. }
  365. $db->sql_freeresult($result);
  366. // For storing shadow topics
  367. $shadow_topic_list = array();
  368. if (sizeof($topic_list))
  369. {
  370. // SQL array for obtaining topics/stickies
  371. $sql_array = array(
  372. 'SELECT' => $sql_array['SELECT'],
  373. 'FROM' => $sql_array['FROM'],
  374. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  375. 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
  376. );
  377. // If store_reverse, then first obtain topics, then stickies, else the other way around...
  378. // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
  379. // the number of stickies are not known
  380. $sql = $db->sql_build_query('SELECT', $sql_array);
  381. $result = $db->sql_query($sql);
  382. while ($row = $db->sql_fetchrow($result))
  383. {
  384. if ($row['topic_status'] == ITEM_MOVED)
  385. {
  386. $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
  387. }
  388. $rowset[$row['topic_id']] = $row;
  389. }
  390. $db->sql_freeresult($result);
  391. }
  392. // If we have some shadow topics, update the rowset to reflect their topic information
  393. if (sizeof($shadow_topic_list))
  394. {
  395. $sql = 'SELECT *
  396. FROM ' . TOPICS_TABLE . '
  397. WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
  398. $result = $db->sql_query($sql);
  399. while ($row = $db->sql_fetchrow($result))
  400. {
  401. $orig_topic_id = $shadow_topic_list[$row['topic_id']];
  402. // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
  403. if (isset($rowset[$row['topic_id']]))
  404. {
  405. // We need to remove any trace regarding this topic. :)
  406. unset($rowset[$orig_topic_id]);
  407. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  408. $topics_count--;
  409. continue;
  410. }
  411. // Do not include those topics the user has no permission to access
  412. if (!$auth->acl_get('f_read', $row['forum_id']))
  413. {
  414. // We need to remove any trace regarding this topic. :)
  415. unset($rowset[$orig_topic_id]);
  416. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  417. $topics_count--;
  418. continue;
  419. }
  420. // We want to retain some values
  421. $row = array_merge($row, array(
  422. 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
  423. 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
  424. 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
  425. ));
  426. // Shadow topics are never reported
  427. $row['topic_reported'] = 0;
  428. $rowset[$orig_topic_id] = $row;
  429. }
  430. $db->sql_freeresult($result);
  431. }
  432. unset($shadow_topic_list);
  433. // Ok, adjust topics count for active topics list
  434. if ($s_display_active)
  435. {
  436. $topics_count = 1;
  437. }
  438. $template->assign_vars(array(
  439. 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
  440. 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
  441. 'TOTAL_TOPICS' => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)))
  442. );
  443. $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
  444. $topic_tracking_info = $tracking_topics = array();
  445. // Okay, lets dump out the page ...
  446. if (sizeof($topic_list))
  447. {
  448. $mark_forum_read = true;
  449. $mark_time_forum = 0;
  450. // Active topics?
  451. if ($s_display_active && sizeof($active_forum_ary))
  452. {
  453. // Generate topic forum list...
  454. $topic_forum_list = array();
  455. foreach ($rowset as $t_id => $row)
  456. {
  457. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0;
  458. $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
  459. }
  460. if ($config['load_db_lastread'] && $user->data['is_registered'])
  461. {
  462. foreach ($topic_forum_list as $f_id => $topic_row)
  463. {
  464. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
  465. }
  466. }
  467. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  468. {
  469. foreach ($topic_forum_list as $f_id => $topic_row)
  470. {
  471. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
  472. }
  473. }
  474. unset($topic_forum_list);
  475. }
  476. else
  477. {
  478. if ($config['load_db_lastread'] && $user->data['is_registered'])
  479. {
  480. $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
  481. $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
  482. }
  483. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  484. {
  485. $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
  486. if (!$user->data['is_registered'])
  487. {
  488. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  489. }
  490. $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
  491. }
  492. }
  493. $s_type_switch = 0;
  494. foreach ($topic_list as $topic_id)
  495. {
  496. $row = &$rowset[$topic_id];
  497. // This will allow the style designer to output a different header
  498. // or even separate the list of announcements from sticky and normal topics
  499. $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  500. // Replies
  501. $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
  502. if ($row['topic_status'] == ITEM_MOVED)
  503. {
  504. $topic_id = $row['topic_moved_id'];
  505. $unread_topic = false;
  506. }
  507. else
  508. {
  509. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  510. }
  511. // Get folder img, topic status/type related information
  512. $folder_img = $folder_alt = $topic_type = '';
  513. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  514. // Generate all the URIs ...
  515. $view_topic_url_params = 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id;
  516. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
  517. $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
  518. $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
  519. $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
  520. // Send vars to template
  521. $template->assign_block_vars('topicrow', array(
  522. 'FORUM_ID' => $forum_id,
  523. 'TOPIC_ID' => $topic_id,
  524. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  525. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  526. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  527. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  528. 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
  529. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  530. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  531. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  532. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  533. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  534. 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
  535. 'REPLIES' => $replies,
  536. 'VIEWS' => $row['topic_views'],
  537. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  538. 'TOPIC_TYPE' => $topic_type,
  539. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  540. 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
  541. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  542. 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
  543. 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
  544. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  545. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  546. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  547. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
  548. 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
  549. 'S_TOPIC_TYPE' => $row['topic_type'],
  550. 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
  551. 'S_UNREAD_TOPIC' => $unread_topic,
  552. 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
  553. 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
  554. 'S_POSTS_UNAPPROVED' => $posts_unapproved,
  555. 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
  556. 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
  557. 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
  558. 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
  559. 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
  560. 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
  561. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
  562. 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
  563. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  564. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  565. 'U_VIEW_TOPIC' => $view_topic_url,
  566. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
  567. 'U_MCP_QUEUE' => $u_mcp_queue,
  568. 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
  569. );
  570. $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  571. if ($unread_topic)
  572. {
  573. $mark_forum_read = false;
  574. }
  575. unset($rowset[$topic_id]);
  576. }
  577. }
  578. // This is rather a fudge but it's the best I can think of without requiring information
  579. // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
  580. // any it updates the forum last read cookie. This requires that the user visit the forum
  581. // after reading a topic
  582. if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
  583. {
  584. update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
  585. }
  586. page_footer();
  587. ?>