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