6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 define('IN_PHPBB', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
18 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
21 $user->session_begin();
22 $auth->acl($user->data);
24 // Start initial var setup
25 $forum_id = request_var('f', 0);
26 $mark_read = request_var('mark', '');
27 $start = request_var('start', 0);
29 $default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
30 $default_sort_key = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
31 $default_sort_dir = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
33 $sort_days = request_var('st', $default_sort_days);
34 $sort_key = request_var('sk', $default_sort_key);
35 $sort_dir = request_var('sd', $default_sort_dir);
37 // Check if the user has actually sent a forum ID with his/her request
38 // If not give them a nice error page.
41 trigger_error('NO_FORUM');
44 $sql_from = FORUMS_TABLE . ' f';
45 $lastread_select = '';
47 // Grab appropriate forum data
48 if ($config['load_db_lastread'] && $user->data['is_registered'])
50 $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
51 AND ft.forum_id = f.forum_id)';
52 $lastread_select .= ', ft.mark_time';
55 if ($user->data['is_registered'])
57 $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
58 $lastread_select .= ', fw.notify_status';
61 $sql = "SELECT f.* $lastread_select
63 WHERE f.forum_id = $forum_id";
64 $result = $db->sql_query($sql);
65 $forum_data = $db->sql_fetchrow($result);
66 $db->sql_freeresult($result);
70 trigger_error('NO_FORUM');
74 // Configure style, language, etc.
75 $user->setup('viewforum', $forum_data['forum_style']);
77 // Redirect to login upon emailed notification links
78 if (isset($_GET['e']) && !$user->data['is_registered'])
80 login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
84 if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)))
86 if ($user->data['user_id'] != ANONYMOUS)
88 trigger_error('SORRY_AUTH_READ');
91 login_box('', $user->lang['LOGIN_VIEWFORUM']);
94 // Forum is passworded ... check whether access has been granted to this
95 // user this session, if not show login box
96 if ($forum_data['forum_password'])
98 login_forum_box($forum_data);
101 // Is this forum a link? ... User got here either because the
102 // number of clicks is being tracked or they guessed the id
103 if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
105 // Does it have click tracking enabled?
106 if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
108 $sql = 'UPDATE ' . FORUMS_TABLE . '
109 SET forum_posts = forum_posts + 1
110 WHERE forum_id = ' . $forum_id;
111 $db->sql_query($sql);
114 // We redirect to the url. The third parameter indicates that external redirects are allowed.
115 redirect($forum_data['forum_link'], false, true);
119 // Build navigation links
120 generate_forum_nav($forum_data);
123 if ($auth->acl_get('f_read', $forum_id))
125 generate_forum_rules($forum_data);
128 // Do we have subforums?
129 $active_forum_ary = $moderators = array();
131 if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
133 list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
137 $template->assign_var('S_HAS_SUBFORUM', false);
138 if ($config['load_moderators'])
140 get_moderators($moderators, $forum_id);
144 // Dump out the page header and load viewforum template
145 page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name'], true, $forum_id);
147 $template->set_filenames(array(
148 'body' => 'viewforum_body.html')
151 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
153 $template->assign_vars(array(
154 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&start=$start")),
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)))
163 // Ok, if someone has only list-access, we only display the forum list.
164 // We also make this circumstance available to the template in case we want to display a notice. ;)
165 if (!$auth->acl_get('f_read', $forum_id))
167 $template->assign_vars(array(
168 'S_NO_READ_ACCESS' => true,
174 // Handle marking posts
175 if ($mark_read == 'topics')
177 $token = request_var('hash', '');
178 if (check_link_hash($token, 'global'))
180 // Add 0 to forums array to mark global announcements correctly
181 markread('topics', array($forum_id, 0));
183 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
184 meta_refresh(3, $redirect_url);
186 trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
189 // Is a forum specific topic count required?
190 if ($forum_data['forum_topics_per_page'])
192 $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
195 // Do the forum Prune thang - cron type job ...
196 if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
198 $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
201 // Forum rules and subscription info
202 $s_watching_forum = array(
205 'is_watching' => false,
208 if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_subscribe', $forum_id) || $user->data['user_id'] == ANONYMOUS))
210 $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
211 watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status, $start, $forum_data['forum_name']);
215 gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
217 // Topic ordering options
218 $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']);
220 $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']);
221 $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
223 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
224 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);
226 // Limit topics to certain time frame, obtain correct topic count
227 // global announcements must not be counted, normal announcements have to
228 // be counted, as forum_topics(_real) includes them
231 $min_post_time = time() - ($sort_days * 86400);
233 $sql = 'SELECT COUNT(topic_id) AS num_topics
234 FROM ' . TOPICS_TABLE . "
235 WHERE forum_id = $forum_id
236 AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time)
237 OR topic_type = " . POST_ANNOUNCE . ")
238 " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
239 $result = $db->sql_query($sql);
240 $topics_count = (int) $db->sql_fetchfield('num_topics');
241 $db->sql_freeresult($result);
243 if (isset($_POST['sort']))
247 $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
249 // Make sure we have information about day selection ready
250 $template->assign_var('S_SORT_DAYS', true);
254 $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
255 $sql_limit_time = '';
258 // Make sure $start is set to the last page if it exceeds the amount
259 if ($start < 0 || $start > $topics_count)
261 $start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
264 // Basic pagewide vars
265 $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
267 // Display active topics?
268 $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
270 $s_search_hidden_fields = array('fid' => array($forum_id));
273 $s_search_hidden_fields['sid'] = $_SID;
276 if (!empty($_EXTRA_URL))
278 foreach ($_EXTRA_URL as $url_param)
280 $url_param = explode('=', $url_param, 2);
281 $s_hidden_fields[$url_param[0]] = $url_param[1];
285 $template->assign_vars(array(
286 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
288 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
289 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
290 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
291 'FOLDER_IMG' => $user->img('topic_read', 'NO_UNREAD_POSTS'),
292 'FOLDER_UNREAD_IMG' => $user->img('topic_unread', 'UNREAD_POSTS'),
293 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_UNREAD_POSTS_HOT'),
294 'FOLDER_HOT_UNREAD_IMG' => $user->img('topic_unread_hot', 'UNREAD_POSTS_HOT'),
295 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_UNREAD_POSTS_LOCKED'),
296 'FOLDER_LOCKED_UNREAD_IMG' => $user->img('topic_unread_locked', 'UNREAD_POSTS_LOCKED'),
297 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
298 'FOLDER_STICKY_UNREAD_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
299 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
300 'FOLDER_ANNOUNCE_UNREAD_IMG'=> $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
301 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
302 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
303 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
304 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
306 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
308 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
310 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
311 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
312 'S_DISPLAY_ACTIVE' => $s_display_active,
313 'S_SELECT_SORT_DIR' => $s_sort_dir,
314 'S_SELECT_SORT_KEY' => $s_sort_key,
315 'S_SELECT_SORT_DAYS' => $s_limit_days,
316 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
317 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
318 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
319 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
320 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&start=$start")),
321 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
322 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx"),
323 'S_SEARCH_LOCAL_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields),
324 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
325 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
326 'S_VIEWFORUM' => true,
328 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", true, $user->session_id) : '',
329 '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&f=' . $forum_id) : '',
330 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($start == 0) ? '' : "&start=$start")),
331 '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") : '',
335 $icons = $cache->obtain_icons();
337 // Grab all topic data
338 $rowset = $announcement_list = $topic_list = $global_announce_list = array();
345 'LEFT_JOIN' => array(),
348 $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
350 if ($user->data['is_registered'])
352 if ($config['load_db_track'])
354 $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']);
355 $sql_array['SELECT'] .= ', tp.topic_posted';
358 if ($config['load_db_lastread'])
360 $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']);
361 $sql_array['SELECT'] .= ', tt.mark_time';
363 if ($s_display_active && sizeof($active_forum_ary))
365 $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']);
366 $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
371 if ($forum_data['forum_type'] == FORUM_POST)
373 // Obtain announcements ... removed sort ordering, sort by time in all cases
374 $sql = $db->sql_build_query('SELECT', array(
375 'SELECT' => $sql_array['SELECT'],
376 'FROM' => $sql_array['FROM'],
377 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
379 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
380 AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
382 'ORDER_BY' => 't.topic_time DESC',
384 $result = $db->sql_query($sql);
386 while ($row = $db->sql_fetchrow($result))
388 if (!$row['topic_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
390 // Do not display announcements that are waiting for approval.
394 $rowset[$row['topic_id']] = $row;
395 $announcement_list[] = $row['topic_id'];
397 if ($row['topic_type'] == POST_GLOBAL)
399 $global_announce_list[$row['topic_id']] = true;
406 $db->sql_freeresult($result);
409 // If the user is trying to reach late pages, start searching from the end
410 $store_reverse = false;
411 $sql_limit = $config['topics_per_page'];
412 if ($start > $topics_count / 2)
414 $store_reverse = true;
416 if ($start + $config['topics_per_page'] > $topics_count)
418 $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
421 // Select the sort order
422 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
423 $sql_start = max(0, $topics_count - $sql_limit - $start);
427 // Select the sort order
428 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
432 if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
434 $sql_where = 't.forum_id = ' . $forum_id;
436 else if (empty($active_forum_ary['exclude_forum_id']))
438 $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
442 $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
443 $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
446 // Grab just the sorted topic ids
447 $sql = 'SELECT t.topic_id
448 FROM ' . TOPICS_TABLE . " t
450 AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
453 ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
454 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
456 while ($row = $db->sql_fetchrow($result))
458 $topic_list[] = (int) $row['topic_id'];
460 $db->sql_freeresult($result);
462 // For storing shadow topics
463 $shadow_topic_list = array();
465 if (sizeof($topic_list))
467 // SQL array for obtaining topics/stickies
469 'SELECT' => $sql_array['SELECT'],
470 'FROM' => $sql_array['FROM'],
471 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
473 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
476 // If store_reverse, then first obtain topics, then stickies, else the other way around...
477 // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
478 // the number of stickies are not known
479 $sql = $db->sql_build_query('SELECT', $sql_array);
480 $result = $db->sql_query($sql);
482 while ($row = $db->sql_fetchrow($result))
484 if ($row['topic_status'] == ITEM_MOVED)
486 $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
489 $rowset[$row['topic_id']] = $row;
491 $db->sql_freeresult($result);
494 // If we have some shadow topics, update the rowset to reflect their topic information
495 if (sizeof($shadow_topic_list))
498 FROM ' . TOPICS_TABLE . '
499 WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
500 $result = $db->sql_query($sql);
502 while ($row = $db->sql_fetchrow($result))
504 $orig_topic_id = $shadow_topic_list[$row['topic_id']];
506 // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
507 if (isset($rowset[$row['topic_id']]))
509 // We need to remove any trace regarding this topic. :)
510 unset($rowset[$orig_topic_id]);
511 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
517 // Do not include those topics the user has no permission to access
518 if (!$auth->acl_get('f_read', $row['forum_id']))
520 // We need to remove any trace regarding this topic. :)
521 unset($rowset[$orig_topic_id]);
522 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
528 // We want to retain some values
529 $row = array_merge($row, array(
530 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
531 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
532 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
533 'topic_title' => $rowset[$orig_topic_id]['topic_title'],
536 // Shadow topics are never reported
537 $row['topic_reported'] = 0;
539 $rowset[$orig_topic_id] = $row;
541 $db->sql_freeresult($result);
543 unset($shadow_topic_list);
545 // Ok, adjust topics count for active topics list
546 if ($s_display_active)
551 // We need to readd the local announcements to the forums total topic count, otherwise the number is different from the one on the forum list
552 $total_topic_count = $topics_count + sizeof($announcement_list) - sizeof($global_announce_list);
554 $template->assign_vars(array(
555 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
556 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
557 'TOTAL_TOPICS' => ($s_display_active) ? false : (($total_topic_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $total_topic_count)))
560 $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
561 $topic_tracking_info = $tracking_topics = array();
563 // Okay, lets dump out the page ...
564 if (sizeof($topic_list))
566 $mark_forum_read = true;
567 $mark_time_forum = 0;
570 if ($s_display_active && sizeof($active_forum_ary))
572 // Generate topic forum list...
573 $topic_forum_list = array();
574 foreach ($rowset as $t_id => $row)
576 $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;
577 $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
580 if ($config['load_db_lastread'] && $user->data['is_registered'])
582 foreach ($topic_forum_list as $f_id => $topic_row)
584 $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
587 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
589 foreach ($topic_forum_list as $f_id => $topic_row)
591 $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
595 unset($topic_forum_list);
599 if ($config['load_db_lastread'] && $user->data['is_registered'])
601 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
602 $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
604 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
606 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
608 if (!$user->data['is_registered'])
610 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
612 $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'];
617 foreach ($topic_list as $topic_id)
619 $row = &$rowset[$topic_id];
621 $topic_forum_id = ($row['forum_id']) ? (int) $row['forum_id'] : $forum_id;
623 // This will allow the style designer to output a different header
624 // or even separate the list of announcements from sticky and normal topics
625 $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
628 $replies = ($auth->acl_get('m_approve', $topic_forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
630 if ($row['topic_status'] == ITEM_MOVED)
632 $topic_id = $row['topic_moved_id'];
633 $unread_topic = false;
637 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
640 // Get folder img, topic status/type related information
641 $folder_img = $folder_alt = $topic_type = '';
642 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
644 // Generate all the URIs ...
645 $view_topic_url_params = 'f=' . $topic_forum_id . '&t=' . $topic_id;
646 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
648 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
649 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
650 $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : '';
652 // Send vars to template
653 $template->assign_block_vars('topicrow', array(
654 'FORUM_ID' => $topic_forum_id,
655 'TOPIC_ID' => $topic_id,
656 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
657 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
658 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
659 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
660 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
661 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
662 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
663 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
664 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
665 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
667 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
668 'REPLIES' => $replies,
669 'VIEWS' => $row['topic_views'],
670 'TOPIC_TITLE' => censor_text($row['topic_title']),
671 'TOPIC_TYPE' => $topic_type,
673 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
674 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
675 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
676 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
677 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
679 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
680 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
681 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
682 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
683 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
685 'S_TOPIC_TYPE' => $row['topic_type'],
686 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
687 'S_UNREAD_TOPIC' => $unread_topic,
688 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $topic_forum_id)) ? true : false,
689 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
690 'S_POSTS_UNAPPROVED' => $posts_unapproved,
691 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
692 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
693 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
694 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
695 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
696 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
698 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread',
699 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
700 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
701 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
702 'U_VIEW_TOPIC' => $view_topic_url,
703 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&f=' . $topic_forum_id . '&t=' . $topic_id, true, $user->session_id),
704 'U_MCP_QUEUE' => $u_mcp_queue,
706 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
709 $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
713 $mark_forum_read = false;
716 unset($rowset[$topic_id]);
720 // This is rather a fudge but it's the best I can think of without requiring information
721 // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
722 // any it updates the forum last read cookie. This requires that the user visit the forum
723 // after reading a topic
724 if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
726 update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);