PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wwwroot/phpbb/viewforum.php

https://github.com/spring/spring-website
PHP | 1084 lines | 696 code | 153 blank | 235 comment | 155 complexity | 8b91809fe3ce12c3508c7ea130bca678 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. define('IN_PHPBB', true);
  17. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  18. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  19. include($phpbb_root_path . 'common.' . $phpEx);
  20. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  21. // Start session
  22. $user->session_begin();
  23. $auth->acl($user->data);
  24. // Start initial var setup
  25. $forum_id = $request->variable('f', 0);
  26. $mark_read = $request->variable('mark', '');
  27. $start = $request->variable('start', 0);
  28. $default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
  29. $default_sort_key = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
  30. $default_sort_dir = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
  31. $sort_days = $request->variable('st', $default_sort_days);
  32. $sort_key = $request->variable('sk', $default_sort_key);
  33. $sort_dir = $request->variable('sd', $default_sort_dir);
  34. /* @var $pagination \phpbb\pagination */
  35. $pagination = $phpbb_container->get('pagination');
  36. // Check if the user has actually sent a forum ID with his/her request
  37. // If not give them a nice error page.
  38. if (!$forum_id)
  39. {
  40. trigger_error('NO_FORUM');
  41. }
  42. $sql_from = FORUMS_TABLE . ' f';
  43. $lastread_select = '';
  44. // Grab appropriate forum data
  45. if ($config['load_db_lastread'] && $user->data['is_registered'])
  46. {
  47. $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
  48. AND ft.forum_id = f.forum_id)';
  49. $lastread_select .= ', ft.mark_time';
  50. }
  51. if ($user->data['is_registered'])
  52. {
  53. $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
  54. $lastread_select .= ', fw.notify_status';
  55. }
  56. $sql = "SELECT f.* $lastread_select
  57. FROM $sql_from
  58. WHERE f.forum_id = $forum_id";
  59. $result = $db->sql_query($sql);
  60. $forum_data = $db->sql_fetchrow($result);
  61. $db->sql_freeresult($result);
  62. if (!$forum_data)
  63. {
  64. trigger_error('NO_FORUM');
  65. }
  66. // Configure style, language, etc.
  67. $user->setup('viewforum', $forum_data['forum_style']);
  68. // Redirect to login upon emailed notification links
  69. if (isset($_GET['e']) && !$user->data['is_registered'])
  70. {
  71. login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
  72. }
  73. // Permissions check
  74. if (!$auth->acl_gets('f_list', 'f_list_topics', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)))
  75. {
  76. if ($user->data['user_id'] != ANONYMOUS)
  77. {
  78. send_status_line(403, 'Forbidden');
  79. trigger_error('SORRY_AUTH_READ');
  80. }
  81. login_box('', $user->lang['LOGIN_VIEWFORUM']);
  82. }
  83. // Forum is passworded ... check whether access has been granted to this
  84. // user this session, if not show login box
  85. if ($forum_data['forum_password'])
  86. {
  87. login_forum_box($forum_data);
  88. }
  89. // Is this forum a link? ... User got here either because the
  90. // number of clicks is being tracked or they guessed the id
  91. if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
  92. {
  93. // Does it have click tracking enabled?
  94. if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
  95. {
  96. $sql = 'UPDATE ' . FORUMS_TABLE . '
  97. SET forum_posts_approved = forum_posts_approved + 1
  98. WHERE forum_id = ' . $forum_id;
  99. $db->sql_query($sql);
  100. }
  101. // We redirect to the url. The third parameter indicates that external redirects are allowed.
  102. redirect($forum_data['forum_link'], false, true);
  103. return;
  104. }
  105. // Build navigation links
  106. generate_forum_nav($forum_data);
  107. // Forum Rules
  108. if ($auth->acl_get('f_read', $forum_id))
  109. {
  110. generate_forum_rules($forum_data);
  111. }
  112. // Do we have subforums?
  113. $active_forum_ary = $moderators = array();
  114. if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
  115. {
  116. list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
  117. }
  118. else
  119. {
  120. $template->assign_var('S_HAS_SUBFORUM', false);
  121. if ($config['load_moderators'])
  122. {
  123. get_moderators($moderators, $forum_id);
  124. }
  125. }
  126. // Is a forum specific topic count required?
  127. if ($forum_data['forum_topics_per_page'])
  128. {
  129. $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
  130. }
  131. /* @var $phpbb_content_visibility \phpbb\content_visibility */
  132. $phpbb_content_visibility = $phpbb_container->get('content.visibility');
  133. // Dump out the page header and load viewforum template
  134. $topics_count = $phpbb_content_visibility->get_count('forum_topics', $forum_data, $forum_id);
  135. $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
  136. $page_title = $forum_data['forum_name'] . ($start ? ' - ' . $user->lang('PAGE_TITLE_NUMBER', $pagination->get_on_page($config['topics_per_page'], $start)) : '');
  137. /**
  138. * You can use this event to modify the page title of the viewforum page
  139. *
  140. * @event core.viewforum_modify_page_title
  141. * @var string page_title Title of the viewforum page
  142. * @var array forum_data Array with forum data
  143. * @var int forum_id The forum ID
  144. * @var int start Start offset used to calculate the page
  145. * @since 3.2.2-RC1
  146. */
  147. $vars = array('page_title', 'forum_data', 'forum_id', 'start');
  148. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_page_title', compact($vars)));
  149. page_header($page_title, true, $forum_id);
  150. $template->set_filenames(array(
  151. 'body' => 'viewforum_body.html')
  152. );
  153. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
  154. $template->assign_vars(array(
  155. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
  156. ));
  157. // Not postable forum or showing active topics?
  158. if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
  159. {
  160. page_footer();
  161. }
  162. // Ok, if someone has only list-access, we only display the forum list.
  163. // We also make this circumstance available to the template in case we want to display a notice. ;)
  164. if (!$auth->acl_gets('f_read', 'f_list_topics', $forum_id))
  165. {
  166. $template->assign_vars(array(
  167. 'S_NO_READ_ACCESS' => true,
  168. ));
  169. page_footer();
  170. }
  171. // Handle marking posts
  172. if ($mark_read == 'topics')
  173. {
  174. $token = $request->variable('hash', '');
  175. if (check_link_hash($token, 'global'))
  176. {
  177. markread('topics', array($forum_id), false, $request->variable('mark_time', 0));
  178. }
  179. $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  180. meta_refresh(3, $redirect_url);
  181. if ($request->is_ajax())
  182. {
  183. // Tell the ajax script what language vars and URL need to be replaced
  184. $data = array(
  185. 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
  186. 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
  187. 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics&mark_time=" . time(), false) : '',
  188. 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
  189. 'MESSAGE_TEXT' => $user->lang['TOPICS_MARKED']
  190. );
  191. $json_response = new \phpbb\json_response();
  192. $json_response->send($data);
  193. }
  194. trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
  195. }
  196. // Do the forum Prune thang - cron type job ...
  197. if (!$config['use_system_cron'])
  198. {
  199. /* @var $cron \phpbb\cron\manager */
  200. $cron = $phpbb_container->get('cron.manager');
  201. $task = $cron->find_task('cron.task.core.prune_forum');
  202. $task->set_forum_data($forum_data);
  203. if ($task->is_ready())
  204. {
  205. $url = $task->get_url();
  206. $template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="cron" />');
  207. }
  208. else
  209. {
  210. // See if we should prune the shadow topics instead
  211. $task = $cron->find_task('cron.task.core.prune_shadow_topics');
  212. $task->set_forum_data($forum_data);
  213. if ($task->is_ready())
  214. {
  215. $url = $task->get_url();
  216. $template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="cron" />');
  217. }
  218. }
  219. }
  220. // Forum rules and subscription info
  221. $s_watching_forum = array(
  222. 'link' => '',
  223. 'link_toggle' => '',
  224. 'title' => '',
  225. 'title_toggle' => '',
  226. 'is_watching' => false,
  227. );
  228. if ($config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_subscribe', $forum_id) || $user->data['user_id'] == ANONYMOUS))
  229. {
  230. $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
  231. watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status, $start, $forum_data['forum_name']);
  232. }
  233. $s_forum_rules = '';
  234. gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
  235. // Topic ordering options
  236. $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']);
  237. $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']);
  238. $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => array('t.topic_last_post_time', 't.topic_last_post_id'), 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved'), 's' => 'LOWER(t.topic_title)', 'v' => 't.topic_views');
  239. /**
  240. * Modify the topic ordering if needed
  241. *
  242. * @event core.viewforum_modify_topic_ordering
  243. * @var array sort_by_text Topic ordering options
  244. * @var array sort_by_sql Topic orderings options SQL equivalent
  245. * @since 3.2.5-RC1
  246. */
  247. $vars = array(
  248. 'sort_by_text',
  249. 'sort_by_sql',
  250. );
  251. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topic_ordering', compact($vars)));
  252. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  253. 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);
  254. // Limit topics to certain time frame, obtain correct topic count
  255. if ($sort_days)
  256. {
  257. $min_post_time = time() - ($sort_days * 86400);
  258. $sql_array = array(
  259. 'SELECT' => 'COUNT(t.topic_id) AS num_topics',
  260. 'FROM' => array(
  261. TOPICS_TABLE => 't',
  262. ),
  263. 'WHERE' => 't.forum_id = ' . $forum_id . '
  264. AND (t.topic_last_post_time >= ' . $min_post_time . '
  265. OR t.topic_type = ' . POST_ANNOUNCE . '
  266. OR t.topic_type = ' . POST_GLOBAL . ')
  267. AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.'),
  268. );
  269. /**
  270. * Modify the sort data SQL query for getting additional fields if needed
  271. *
  272. * @event core.viewforum_modify_sort_data_sql
  273. * @var int forum_id The forum_id whose topics are being listed
  274. * @var int start Variable containing start for pagination
  275. * @var int sort_days The oldest topic displayable in elapsed days
  276. * @var string sort_key The sorting by. It is one of the first character of (in low case):
  277. * Author, Post time, Replies, Subject, Views
  278. * @var string sort_dir Either "a" for ascending or "d" for descending
  279. * @var array sql_array The SQL array to get the data of all topics
  280. * @since 3.1.9-RC1
  281. */
  282. $vars = array(
  283. 'forum_id',
  284. 'start',
  285. 'sort_days',
  286. 'sort_key',
  287. 'sort_dir',
  288. 'sql_array',
  289. );
  290. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_sort_data_sql', compact($vars)));
  291. $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array));
  292. $topics_count = (int) $db->sql_fetchfield('num_topics');
  293. $db->sql_freeresult($result);
  294. if (isset($_POST['sort']))
  295. {
  296. $start = 0;
  297. }
  298. $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
  299. // Make sure we have information about day selection ready
  300. $template->assign_var('S_SORT_DAYS', true);
  301. }
  302. else
  303. {
  304. $sql_limit_time = '';
  305. }
  306. // Basic pagewide vars
  307. $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
  308. // Display active topics?
  309. $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  310. $s_search_hidden_fields = array('fid' => array($forum_id));
  311. if ($_SID)
  312. {
  313. $s_search_hidden_fields['sid'] = $_SID;
  314. }
  315. if (!empty($_EXTRA_URL))
  316. {
  317. foreach ($_EXTRA_URL as $url_param)
  318. {
  319. $url_param = explode('=', $url_param, 2);
  320. $s_search_hidden_fields[$url_param[0]] = $url_param[1];
  321. }
  322. }
  323. $template->assign_vars(array(
  324. 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode($user->lang['COMMA_SEPARATOR'], $moderators[$forum_id]) : '',
  325. 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
  326. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  327. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  328. 'FOLDER_IMG' => $user->img('topic_read', 'NO_UNREAD_POSTS'),
  329. 'FOLDER_UNREAD_IMG' => $user->img('topic_unread', 'UNREAD_POSTS'),
  330. 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_UNREAD_POSTS_HOT'),
  331. 'FOLDER_HOT_UNREAD_IMG' => $user->img('topic_unread_hot', 'UNREAD_POSTS_HOT'),
  332. 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_UNREAD_POSTS_LOCKED'),
  333. 'FOLDER_LOCKED_UNREAD_IMG' => $user->img('topic_unread_locked', 'UNREAD_POSTS_LOCKED'),
  334. 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
  335. 'FOLDER_STICKY_UNREAD_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
  336. 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
  337. 'FOLDER_ANNOUNCE_UNREAD_IMG'=> $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
  338. 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
  339. 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
  340. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
  341. 'DELETED_IMG' => $user->img('icon_topic_deleted', 'TOPIC_DELETED'),
  342. 'POLL_IMG' => $user->img('icon_topic_poll', 'TOPIC_POLL'),
  343. 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
  344. 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
  345. 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
  346. 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  347. 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
  348. 'S_DISPLAY_ACTIVE' => $s_display_active,
  349. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  350. 'S_SELECT_SORT_KEY' => $s_sort_key,
  351. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  352. 'S_TOPIC_ICONS' => ($s_display_active && count($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
  353. 'U_WATCH_FORUM_LINK' => $s_watching_forum['link'],
  354. 'U_WATCH_FORUM_TOGGLE' => $s_watching_forum['link_toggle'],
  355. 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
  356. 'S_WATCH_FORUM_TOGGLE' => $s_watching_forum['title_toggle'],
  357. 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
  358. 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
  359. 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
  360. 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx"),
  361. 'S_SEARCH_LOCAL_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields),
  362. 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && count($moderators[$forum_id]) > 1) ? false : true,
  363. 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
  364. 'S_VIEWFORUM' => true,
  365. '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) : '',
  366. '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) : '',
  367. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($start == 0) ? '' : "&amp;start=$start")),
  368. 'U_CANONICAL' => generate_board_url() . '/' . append_sid("viewforum.$phpEx", "f=$forum_id" . (($start) ? "&amp;start=$start" : ''), true, ''),
  369. '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&amp;mark_time=" . time()) : '',
  370. 'U_SEARCH_FORUM' => append_sid("{$phpbb_root_path}search.$phpEx", 'fid%5B%5D=' . $forum_id),
  371. ));
  372. // Grab icons
  373. $icons = $cache->obtain_icons();
  374. // Grab all topic data
  375. $rowset = $announcement_list = $topic_list = $global_announce_forums = array();
  376. $sql_array = array(
  377. 'SELECT' => 't.*',
  378. 'FROM' => array(
  379. TOPICS_TABLE => 't'
  380. ),
  381. 'LEFT_JOIN' => array(),
  382. );
  383. /**
  384. * Event to modify the SQL query before the topic data is retrieved
  385. *
  386. * It may also be used to override the above assigned template vars
  387. *
  388. * @event core.viewforum_get_topic_data
  389. * @var array forum_data Array with forum data
  390. * @var array sql_array The SQL array to get the data of all topics
  391. * @var int forum_id The forum_id whose topics are being listed
  392. * @var int topics_count The total number of topics for display
  393. * @var int sort_days The oldest topic displayable in elapsed days
  394. * @var string sort_key The sorting by. It is one of the first character of (in low case):
  395. * Author, Post time, Replies, Subject, Views
  396. * @var string sort_dir Either "a" for ascending or "d" for descending
  397. * @since 3.1.0-a1
  398. * @changed 3.1.0-RC4 Added forum_data var
  399. * @changed 3.1.4-RC1 Added forum_id, topics_count, sort_days, sort_key and sort_dir vars
  400. * @changed 3.1.9-RC1 Fix types of properties
  401. */
  402. $vars = array(
  403. 'forum_data',
  404. 'sql_array',
  405. 'forum_id',
  406. 'topics_count',
  407. 'sort_days',
  408. 'sort_key',
  409. 'sort_dir',
  410. );
  411. extract($phpbb_dispatcher->trigger_event('core.viewforum_get_topic_data', compact($vars)));
  412. $sql_approved = ' AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.');
  413. if ($user->data['is_registered'])
  414. {
  415. if ($config['load_db_track'])
  416. {
  417. $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']);
  418. $sql_array['SELECT'] .= ', tp.topic_posted';
  419. }
  420. if ($config['load_db_lastread'])
  421. {
  422. $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']);
  423. $sql_array['SELECT'] .= ', tt.mark_time';
  424. if ($s_display_active && count($active_forum_ary))
  425. {
  426. $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']);
  427. $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
  428. }
  429. }
  430. }
  431. if ($forum_data['forum_type'] == FORUM_POST)
  432. {
  433. // Get global announcement forums
  434. $g_forum_ary = $auth->acl_getf('f_read', true);
  435. $g_forum_ary = array_unique(array_keys($g_forum_ary));
  436. $sql_anounce_array['LEFT_JOIN'] = $sql_array['LEFT_JOIN'];
  437. $sql_anounce_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id');
  438. $sql_anounce_array['SELECT'] = $sql_array['SELECT'] . ', f.forum_name';
  439. // Obtain announcements ... removed sort ordering, sort by time in all cases
  440. $sql_ary = array(
  441. 'SELECT' => $sql_anounce_array['SELECT'],
  442. 'FROM' => $sql_array['FROM'],
  443. 'LEFT_JOIN' => $sql_anounce_array['LEFT_JOIN'],
  444. 'WHERE' => '(t.forum_id = ' . $forum_id . '
  445. AND t.topic_type = ' . POST_ANNOUNCE . ') OR
  446. (' . $db->sql_in_set('t.forum_id', $g_forum_ary, false, true) . '
  447. AND t.topic_type = ' . POST_GLOBAL . ')',
  448. 'ORDER_BY' => 't.topic_time DESC',
  449. );
  450. /**
  451. * Event to modify the SQL query before the announcement topic ids data is retrieved
  452. *
  453. * @event core.viewforum_get_announcement_topic_ids_data
  454. * @var array forum_data Data about the forum
  455. * @var array g_forum_ary Global announcement forums array
  456. * @var array sql_anounce_array SQL announcement array
  457. * @var array sql_ary SQL query array to get the announcement topic ids data
  458. * @var int forum_id The forum ID
  459. *
  460. * @since 3.1.10-RC1
  461. */
  462. $vars = array(
  463. 'forum_data',
  464. 'g_forum_ary',
  465. 'sql_anounce_array',
  466. 'sql_ary',
  467. 'forum_id',
  468. );
  469. extract($phpbb_dispatcher->trigger_event('core.viewforum_get_announcement_topic_ids_data', compact($vars)));
  470. $sql = $db->sql_build_query('SELECT', $sql_ary);
  471. $result = $db->sql_query($sql);
  472. while ($row = $db->sql_fetchrow($result))
  473. {
  474. if (!$phpbb_content_visibility->is_visible('topic', $row['forum_id'], $row))
  475. {
  476. // Do not display announcements that are waiting for approval or soft deleted.
  477. continue;
  478. }
  479. $rowset[$row['topic_id']] = $row;
  480. $announcement_list[] = $row['topic_id'];
  481. if ($forum_id != $row['forum_id'])
  482. {
  483. $topics_count++;
  484. $global_announce_forums[] = $row['forum_id'];
  485. }
  486. }
  487. $db->sql_freeresult($result);
  488. }
  489. $forum_tracking_info = array();
  490. if ($user->data['is_registered'] && $config['load_db_lastread'])
  491. {
  492. $forum_tracking_info[$forum_id] = $forum_data['mark_time'];
  493. if (!empty($global_announce_forums))
  494. {
  495. $sql = 'SELECT forum_id, mark_time
  496. FROM ' . FORUMS_TRACK_TABLE . '
  497. WHERE ' . $db->sql_in_set('forum_id', $global_announce_forums) . '
  498. AND user_id = ' . $user->data['user_id'];
  499. $result = $db->sql_query($sql);
  500. while ($row = $db->sql_fetchrow($result))
  501. {
  502. $forum_tracking_info[$row['forum_id']] = $row['mark_time'];
  503. }
  504. $db->sql_freeresult($result);
  505. }
  506. }
  507. // If the user is trying to reach late pages, start searching from the end
  508. $store_reverse = false;
  509. $sql_limit = $config['topics_per_page'];
  510. if ($start > $topics_count / 2)
  511. {
  512. $store_reverse = true;
  513. // Select the sort order
  514. $direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
  515. $sql_limit = $pagination->reverse_limit($start, $sql_limit, $topics_count - count($announcement_list));
  516. $sql_start = $pagination->reverse_start($start, $sql_limit, $topics_count - count($announcement_list));
  517. }
  518. else
  519. {
  520. // Select the sort order
  521. $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
  522. $sql_start = $start;
  523. }
  524. /**
  525. * Modify the topics sort ordering if needed
  526. *
  527. * @event core.viewforum_modify_sort_direction
  528. * @var string direction Topics sort order
  529. * @since 3.2.5-RC1
  530. */
  531. $vars = array(
  532. 'direction',
  533. );
  534. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_sort_direction', compact($vars)));
  535. if (is_array($sort_by_sql[$sort_key]))
  536. {
  537. $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
  538. }
  539. else
  540. {
  541. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
  542. }
  543. if ($forum_data['forum_type'] == FORUM_POST || !count($active_forum_ary))
  544. {
  545. $sql_where = 't.forum_id = ' . $forum_id;
  546. }
  547. else if (empty($active_forum_ary['exclude_forum_id']))
  548. {
  549. $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
  550. }
  551. else
  552. {
  553. $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
  554. $sql_where = (count($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
  555. }
  556. // Grab just the sorted topic ids
  557. $sql_ary = array(
  558. 'SELECT' => 't.topic_id',
  559. 'FROM' => array(
  560. TOPICS_TABLE => 't',
  561. ),
  562. 'WHERE' => "$sql_where
  563. AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
  564. $sql_approved
  565. $sql_limit_time",
  566. 'ORDER_BY' => 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order,
  567. );
  568. /**
  569. * Event to modify the SQL query before the topic ids data is retrieved
  570. *
  571. * @event core.viewforum_get_topic_ids_data
  572. * @var array forum_data Data about the forum
  573. * @var array sql_ary SQL query array to get the topic ids data
  574. * @var string sql_approved Topic visibility SQL string
  575. * @var int sql_limit Number of records to select
  576. * @var string sql_limit_time SQL string to limit topic_last_post_time data
  577. * @var array sql_sort_order SQL sorting string
  578. * @var int sql_start Offset point to start selection from
  579. * @var string sql_where SQL WHERE clause string
  580. * @var bool store_reverse Flag indicating if we select from the late pages
  581. *
  582. * @since 3.1.0-RC4
  583. *
  584. * @changed 3.1.3 Added forum_data
  585. */
  586. $vars = array(
  587. 'forum_data',
  588. 'sql_ary',
  589. 'sql_approved',
  590. 'sql_limit',
  591. 'sql_limit_time',
  592. 'sql_sort_order',
  593. 'sql_start',
  594. 'sql_where',
  595. 'store_reverse',
  596. );
  597. extract($phpbb_dispatcher->trigger_event('core.viewforum_get_topic_ids_data', compact($vars)));
  598. $sql = $db->sql_build_query('SELECT', $sql_ary);
  599. $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
  600. while ($row = $db->sql_fetchrow($result))
  601. {
  602. $topic_list[] = (int) $row['topic_id'];
  603. }
  604. $db->sql_freeresult($result);
  605. // For storing shadow topics
  606. $shadow_topic_list = array();
  607. if (count($topic_list))
  608. {
  609. // SQL array for obtaining topics/stickies
  610. $sql_array = array(
  611. 'SELECT' => $sql_array['SELECT'],
  612. 'FROM' => $sql_array['FROM'],
  613. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  614. 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
  615. );
  616. /**
  617. * Event to modify the SQL query before obtaining topics/stickies
  618. *
  619. * @event core.viewforum_modify_topic_list_sql
  620. * @var int forum_id The forum ID
  621. * @var array forum_data Data about the forum
  622. * @var array topic_list Topic ids array
  623. * @var array sql_array SQL query array for obtaining topics/stickies
  624. *
  625. * @since 3.2.10-RC1
  626. * @since 3.3.1-RC1
  627. */
  628. $vars = [
  629. 'forum_id',
  630. 'forum_data',
  631. 'topic_list',
  632. 'sql_array',
  633. ];
  634. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topic_list_sql', compact($vars)));
  635. // If store_reverse, then first obtain topics, then stickies, else the other way around...
  636. // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
  637. // the number of stickies are not known
  638. $sql = $db->sql_build_query('SELECT', $sql_array);
  639. $result = $db->sql_query($sql);
  640. while ($row = $db->sql_fetchrow($result))
  641. {
  642. if ($row['topic_status'] == ITEM_MOVED)
  643. {
  644. $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
  645. }
  646. $rowset[$row['topic_id']] = $row;
  647. }
  648. $db->sql_freeresult($result);
  649. }
  650. // If we have some shadow topics, update the rowset to reflect their topic information
  651. if (count($shadow_topic_list))
  652. {
  653. // SQL array for obtaining shadow topics
  654. $sql_array = array(
  655. 'SELECT' => 't.*',
  656. 'FROM' => array(
  657. TOPICS_TABLE => 't'
  658. ),
  659. 'WHERE' => $db->sql_in_set('t.topic_id', array_keys($shadow_topic_list)),
  660. );
  661. /**
  662. * Event to modify the SQL query before the shadowtopic data is retrieved
  663. *
  664. * @event core.viewforum_get_shadowtopic_data
  665. * @var array sql_array SQL array to get the data of any shadowtopics
  666. * @since 3.1.0-a1
  667. */
  668. $vars = array('sql_array');
  669. extract($phpbb_dispatcher->trigger_event('core.viewforum_get_shadowtopic_data', compact($vars)));
  670. $sql = $db->sql_build_query('SELECT', $sql_array);
  671. $result = $db->sql_query($sql);
  672. while ($row = $db->sql_fetchrow($result))
  673. {
  674. $orig_topic_id = $shadow_topic_list[$row['topic_id']];
  675. // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
  676. if (isset($rowset[$row['topic_id']]))
  677. {
  678. // We need to remove any trace regarding this topic. :)
  679. unset($rowset[$orig_topic_id]);
  680. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  681. $topics_count--;
  682. continue;
  683. }
  684. // Do not include those topics the user has no permission to access
  685. if (!$auth->acl_gets('f_read', 'f_list_topics', $row['forum_id']))
  686. {
  687. // We need to remove any trace regarding this topic. :)
  688. unset($rowset[$orig_topic_id]);
  689. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  690. $topics_count--;
  691. continue;
  692. }
  693. // We want to retain some values
  694. $row = array_merge($row, array(
  695. 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
  696. 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
  697. 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
  698. 'topic_title' => $rowset[$orig_topic_id]['topic_title'],
  699. ));
  700. // Shadow topics are never reported
  701. $row['topic_reported'] = 0;
  702. $rowset[$orig_topic_id] = $row;
  703. }
  704. $db->sql_freeresult($result);
  705. }
  706. unset($shadow_topic_list);
  707. // Ok, adjust topics count for active topics list
  708. if ($s_display_active)
  709. {
  710. $topics_count = 1;
  711. }
  712. // We need to remove the global announcements from the forums total topic count,
  713. // otherwise the number is different from the one on the forum list
  714. $total_topic_count = $topics_count - count($announcement_list);
  715. $base_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : ''));
  716. $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_topic_count, $config['topics_per_page'], $start);
  717. $template->assign_vars(array(
  718. 'TOTAL_TOPICS' => ($s_display_active) ? false : $user->lang('VIEW_FORUM_TOPICS', (int) $total_topic_count),
  719. ));
  720. $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
  721. $topic_tracking_info = $tracking_topics = array();
  722. /**
  723. * Modify topics data before we display the viewforum page
  724. *
  725. * @event core.viewforum_modify_topics_data
  726. * @var array topic_list Array with current viewforum page topic ids
  727. * @var array rowset Array with topics data (in topic_id => topic_data format)
  728. * @var int total_topic_count Forum's total topic count
  729. * @var int forum_id Forum identifier
  730. * @since 3.1.0-b3
  731. * @changed 3.1.11-RC1 Added forum_id
  732. */
  733. $vars = array('topic_list', 'rowset', 'total_topic_count', 'forum_id');
  734. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topics_data', compact($vars)));
  735. // Okay, lets dump out the page ...
  736. if (count($topic_list))
  737. {
  738. $mark_forum_read = true;
  739. $mark_time_forum = 0;
  740. // Generate topic forum list...
  741. $topic_forum_list = array();
  742. foreach ($rowset as $t_id => $row)
  743. {
  744. if (isset($forum_tracking_info[$row['forum_id']]))
  745. {
  746. $row['forum_mark_time'] = $forum_tracking_info[$row['forum_id']];
  747. }
  748. $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;
  749. $topic_forum_list[$row['forum_id']]['topics'][] = (int) $t_id;
  750. }
  751. if ($config['load_db_lastread'] && $user->data['is_registered'])
  752. {
  753. foreach ($topic_forum_list as $f_id => $topic_row)
  754. {
  755. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
  756. }
  757. }
  758. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  759. {
  760. foreach ($topic_forum_list as $f_id => $topic_row)
  761. {
  762. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
  763. }
  764. }
  765. unset($topic_forum_list);
  766. if (!$s_display_active)
  767. {
  768. if ($config['load_db_lastread'] && $user->data['is_registered'])
  769. {
  770. $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
  771. }
  772. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  773. {
  774. if (!$user->data['is_registered'])
  775. {
  776. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  777. }
  778. $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'];
  779. }
  780. }
  781. $s_type_switch = 0;
  782. foreach ($topic_list as $topic_id)
  783. {
  784. $row = &$rowset[$topic_id];
  785. $topic_forum_id = ($row['forum_id']) ? (int) $row['forum_id'] : $forum_id;
  786. // This will allow the style designer to output a different header
  787. // or even separate the list of announcements from sticky and normal topics
  788. $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  789. // Replies
  790. $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $topic_forum_id) - 1;
  791. // Correction for case of unapproved topic visible to poster
  792. if ($replies < 0)
  793. {
  794. $replies = 0;
  795. }
  796. if ($row['topic_status'] == ITEM_MOVED)
  797. {
  798. $topic_id = $row['topic_moved_id'];
  799. $unread_topic = false;
  800. }
  801. else
  802. {
  803. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  804. }
  805. // Get folder img, topic status/type related information
  806. $folder_img = $folder_alt = $topic_type = '';
  807. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  808. // Generate all the URIs ...
  809. $view_topic_url_params = 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id;
  810. $view_topic_url = $auth->acl_get('f_read', $forum_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params) : false;
  811. $topic_unapproved = (($row['topic_visibility'] == ITEM_UNAPPROVED || $row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $row['forum_id']));
  812. $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id']));
  813. $topic_deleted = $row['topic_visibility'] == ITEM_DELETED;
  814. $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) : '';
  815. $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=deleted_topics&amp;t=' . $topic_id, true, $user->session_id) : $u_mcp_queue;
  816. // Send vars to template
  817. $topic_row = array(
  818. 'FORUM_ID' => $row['forum_id'],
  819. 'TOPIC_ID' => $topic_id,
  820. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  821. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  822. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  823. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  824. 'FIRST_POST_TIME_RFC3339' => gmdate(DATE_RFC3339, $row['topic_time']),
  825. 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
  826. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  827. 'LAST_POST_TIME_RFC3339' => gmdate(DATE_RFC3339, $row['topic_last_post_time']),
  828. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  829. 'LAST_VIEW_TIME_RFC3339' => gmdate(DATE_RFC3339, $row['topic_last_view_time']),
  830. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  831. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  832. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  833. 'REPLIES' => $replies,
  834. 'VIEWS' => $row['topic_views'],
  835. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  836. 'TOPIC_TYPE' => $topic_type,
  837. 'FORUM_NAME' => (isset($row['forum_name'])) ? $row['forum_name'] : $forum_data['forum_name'],
  838. 'TOPIC_IMG_STYLE' => $folder_img,
  839. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  840. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  841. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  842. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  843. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  844. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
  845. 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
  846. 'S_TOPIC_TYPE' => $row['topic_type'],
  847. 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
  848. 'S_UNREAD_TOPIC' => $unread_topic,
  849. 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
  850. 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
  851. 'S_POSTS_UNAPPROVED' => $posts_unapproved,
  852. 'S_TOPIC_DELETED' => $topic_deleted,
  853. 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
  854. 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
  855. 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
  856. 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
  857. 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
  858. 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
  859. 'U_NEWEST_POST' => $auth->acl_get('f_read', $forum_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread' : false,
  860. 'U_LAST_POST' => $auth->acl_get('f_read', $forum_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'] : false,
  861. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  862. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  863. 'U_VIEW_TOPIC' => $view_topic_url,
  864. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
  865. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $row['forum_id'] . '&amp;t=' . $topic_id, true, $user->session_id),
  866. 'U_MCP_QUEUE' => $u_mcp_queue,
  867. 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test,
  868. );
  869. /**
  870. * Modify the topic data before it is assigned to the template
  871. *
  872. * @event core.viewforum_modify_topicrow
  873. * @var array row Array with topic data
  874. * @var array topic_row Template array with topic data
  875. * @var bool s_type_switch Flag indicating if the topic type is [global] announcement
  876. * @var bool s_type_switch_test Flag indicating if the test topic type is [global] announcement
  877. * @since 3.1.0-a1
  878. *
  879. * @changed 3.1.10-RC1 Added s_type_switch, s_type_switch_test
  880. */
  881. $vars = array('row', 'topic_row', 's_type_switch', 's_type_switch_test');
  882. extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topicrow', compact($vars)));
  883. $template->assign_block_vars('topicrow', $topic_row);
  884. $pagination->generate_template_pagination($topic_row['U_VIEW_TOPIC'], 'topicrow.pagination', 'start', (int) $topic_row['REPLIES'] + 1, $config['posts_per_page'], 1, true, true);
  885. $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  886. /**
  887. * Event after the topic data has been assigned to the template
  888. *
  889. * @event core.viewforum_topic_row_after
  890. * @var array row Array with the topic data
  891. * @var array rowset Array with topics data (in topic_id => topic_data format)
  892. * @var bool s_type_switch Flag indicating if the topic type is [global] announcement
  893. * @var int topic_id The topic ID
  894. * @var array topic_list Array with current viewforum page topic ids
  895. * @var array topic_row Template array with topic data
  896. * @since 3.1.3-RC1
  897. */
  898. $vars = array(
  899. 'row',
  900. 'rowset',
  901. 's_type_switch',
  902. 'topic_id',
  903. 'topic_list',
  904. 'topic_row',
  905. );
  906. extract($phpbb_dispatcher->trigger_event('core.viewforum_topic_row_after', compact($vars)));
  907. if ($unread_topic)
  908. {
  909. $mark_forum_read = false;
  910. }
  911. unset($rowset[$topic_id]);
  912. }
  913. }
  914. /**
  915. * This event is to perform additional actions on viewforum page
  916. *
  917. * @event core.viewforum_generate_page_after
  918. * @var array forum_data Array with the forum data
  919. * @since 3.2.2-RC1
  920. */
  921. $vars = array('forum_data');
  922. extract($phpbb_dispatcher->trigger_event('core.viewforum_generate_page_after', compact($vars)));
  923. // This is rather a fudge but it's the best I can think of without requiring information
  924. // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
  925. // any it updates the forum last read cookie. This requires that the user visit the forum
  926. // after reading a topic
  927. if ($forum_data['forum_type'] == FORUM_POST && count($topic_list) && $mark_forum_read)
  928. {
  929. update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
  930. }
  931. page_footer();