(a little test for later merges)
[phpbb.git] / phpBB / viewforum.php
blob95c142d865dd1eed720f5bf6b55d7d194cccf1d9
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
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);
20 // Start session
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.
39 if (!$forum_id)
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
62 FROM $sql_from
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);
68 if (!$forum_data)
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']);
83 // Permissions check
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);
116 return;
119 // Build navigation links
120 generate_forum_nav($forum_data);
122 // Forum Rules
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']);
135 else
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&amp;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)))
160 page_footer();
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,
171 page_footer();
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&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
201 // Forum rules and subscription info
202 $s_watching_forum = array(
203 'link' => '',
204 'title' => '',
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))
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);
214 $s_forum_rules = '';
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
229 if ($sort_days)
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']))
245 $start = 0;
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);
252 else
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 $template->assign_vars(array(
271 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
273 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
274 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
275 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
276 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'),
277 'FOLDER_NEW_IMG' => $user->img('topic_unread', 'NEW_POSTS'),
278 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_NEW_POSTS_HOT'),
279 'FOLDER_HOT_NEW_IMG' => $user->img('topic_unread_hot', 'NEW_POSTS_HOT'),
280 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_NEW_POSTS_LOCKED'),
281 'FOLDER_LOCKED_NEW_IMG' => $user->img('topic_unread_locked', 'NEW_POSTS_LOCKED'),
282 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
283 'FOLDER_STICKY_NEW_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
284 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
285 'FOLDER_ANNOUNCE_NEW_IMG' => $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
286 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
287 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
288 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
289 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
291 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
293 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
295 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
296 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
297 'S_DISPLAY_ACTIVE' => $s_display_active,
298 'S_SELECT_SORT_DIR' => $s_sort_dir,
299 'S_SELECT_SORT_KEY' => $s_sort_key,
300 'S_SELECT_SORT_DAYS' => $s_limit_days,
301 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
302 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
303 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
304 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
305 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
306 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
307 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 'fid[]=' . $forum_id),
308 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
309 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
310 'S_VIEWFORUM' => true,
312 '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) : '',
313 '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) : '',
314 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . "&amp;start=$start"),
315 '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") : '',
318 // Grab icons
319 $icons = $cache->obtain_icons();
321 // Grab all topic data
322 $rowset = $announcement_list = $topic_list = $global_announce_list = array();
324 $sql_array = array(
325 'SELECT' => 't.*',
326 'FROM' => array(
327 TOPICS_TABLE => 't'
329 'LEFT_JOIN' => array(),
332 $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
334 if ($user->data['is_registered'])
336 if ($config['load_db_track'])
338 $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']);
339 $sql_array['SELECT'] .= ', tp.topic_posted';
342 if ($config['load_db_lastread'])
344 $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']);
345 $sql_array['SELECT'] .= ', tt.mark_time';
347 if ($s_display_active && sizeof($active_forum_ary))
349 $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']);
350 $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
355 if ($forum_data['forum_type'] == FORUM_POST)
357 // Obtain announcements ... removed sort ordering, sort by time in all cases
358 $sql = $db->sql_build_query('SELECT', array(
359 'SELECT' => $sql_array['SELECT'],
360 'FROM' => $sql_array['FROM'],
361 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
363 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
364 AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
366 'ORDER_BY' => 't.topic_time DESC',
368 $result = $db->sql_query($sql);
370 while ($row = $db->sql_fetchrow($result))
372 $rowset[$row['topic_id']] = $row;
373 $announcement_list[] = $row['topic_id'];
375 if ($row['topic_type'] == POST_GLOBAL)
377 $global_announce_list[$row['topic_id']] = true;
379 else
381 $topics_count--;
384 $db->sql_freeresult($result);
387 // If the user is trying to reach late pages, start searching from the end
388 $store_reverse = false;
389 $sql_limit = $config['topics_per_page'];
390 if ($start > $topics_count / 2)
392 $store_reverse = true;
394 if ($start + $config['topics_per_page'] > $topics_count)
396 $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
399 // Select the sort order
400 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
401 $sql_start = max(0, $topics_count - $sql_limit - $start);
403 else
405 // Select the sort order
406 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
407 $sql_start = $start;
410 if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
412 $sql_where = 't.forum_id = ' . $forum_id;
414 else if (empty($active_forum_ary['exclude_forum_id']))
416 $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
418 else
420 $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
421 $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
424 // Grab just the sorted topic ids
425 $sql = 'SELECT t.topic_id
426 FROM ' . TOPICS_TABLE . " t
427 WHERE $sql_where
428 AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
429 $sql_approved
430 $sql_limit_time
431 ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
432 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
434 while ($row = $db->sql_fetchrow($result))
436 $topic_list[] = (int) $row['topic_id'];
438 $db->sql_freeresult($result);
440 // For storing shadow topics
441 $shadow_topic_list = array();
443 if (sizeof($topic_list))
445 // SQL array for obtaining topics/stickies
446 $sql_array = array(
447 'SELECT' => $sql_array['SELECT'],
448 'FROM' => $sql_array['FROM'],
449 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
451 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
454 // If store_reverse, then first obtain topics, then stickies, else the other way around...
455 // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
456 // the number of stickies are not known
457 $sql = $db->sql_build_query('SELECT', $sql_array);
458 $result = $db->sql_query($sql);
460 while ($row = $db->sql_fetchrow($result))
462 if ($row['topic_status'] == ITEM_MOVED)
464 $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
467 $rowset[$row['topic_id']] = $row;
469 $db->sql_freeresult($result);
472 // If we have some shadow topics, update the rowset to reflect their topic information
473 if (sizeof($shadow_topic_list))
475 $sql = 'SELECT *
476 FROM ' . TOPICS_TABLE . '
477 WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
478 $result = $db->sql_query($sql);
480 while ($row = $db->sql_fetchrow($result))
482 $orig_topic_id = $shadow_topic_list[$row['topic_id']];
484 // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
485 if (isset($rowset[$row['topic_id']]))
487 // We need to remove any trace regarding this topic. :)
488 unset($rowset[$orig_topic_id]);
489 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
490 $topics_count--;
492 continue;
495 // Do not include those topics the user has no permission to access
496 if (!$auth->acl_get('f_read', $row['forum_id']))
498 // We need to remove any trace regarding this topic. :)
499 unset($rowset[$orig_topic_id]);
500 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
501 $topics_count--;
503 continue;
506 // We want to retain some values
507 $row = array_merge($row, array(
508 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
509 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
510 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
513 // Shadow topics are never reported
514 $row['topic_reported'] = 0;
516 $rowset[$orig_topic_id] = $row;
518 $db->sql_freeresult($result);
520 unset($shadow_topic_list);
522 // Ok, adjust topics count for active topics list
523 if ($s_display_active)
525 $topics_count = 1;
528 $template->assign_vars(array(
529 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
530 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
531 'TOTAL_TOPICS' => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)))
534 $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
535 $topic_tracking_info = $tracking_topics = array();
537 // Okay, lets dump out the page ...
538 if (sizeof($topic_list))
540 $mark_forum_read = true;
541 $mark_time_forum = 0;
543 // Active topics?
544 if ($s_display_active && sizeof($active_forum_ary))
546 // Generate topic forum list...
547 $topic_forum_list = array();
548 foreach ($rowset as $t_id => $row)
550 $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;
551 $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
554 if ($config['load_db_lastread'] && $user->data['is_registered'])
556 foreach ($topic_forum_list as $f_id => $topic_row)
558 $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
561 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
563 foreach ($topic_forum_list as $f_id => $topic_row)
565 $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
569 unset($topic_forum_list);
571 else
573 if ($config['load_db_lastread'] && $user->data['is_registered'])
575 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
576 $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
578 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
580 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
582 if (!$user->data['is_registered'])
584 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
586 $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'];
590 $s_type_switch = 0;
591 foreach ($topic_list as $topic_id)
593 $row = &$rowset[$topic_id];
595 // This will allow the style designer to output a different header
596 // or even separate the list of announcements from sticky and normal topics
597 $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
599 // Replies
600 $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
602 if ($row['topic_status'] == ITEM_MOVED)
604 $topic_id = $row['topic_moved_id'];
605 $unread_topic = false;
607 else
609 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
612 // Get folder img, topic status/type related information
613 $folder_img = $folder_alt = $topic_type = '';
614 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
616 // Generate all the URIs ...
617 $view_topic_url_params = 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id;
618 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
620 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', (($row['forum_id']) ? $row['forum_id'] : $forum_id))) ? true : false;
621 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', (($row['forum_id']) ? $row['forum_id'] : $forum_id))) ? true : false;
622 $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) : '';
624 // Send vars to template
625 $template->assign_block_vars('topicrow', array(
626 'FORUM_ID' => $forum_id,
627 'TOPIC_ID' => $topic_id,
628 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
629 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
630 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
631 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
632 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
633 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
634 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
635 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
636 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
637 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
639 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
640 'REPLIES' => $replies,
641 'VIEWS' => $row['topic_views'],
642 'TOPIC_TITLE' => censor_text($row['topic_title']),
643 'TOPIC_TYPE' => $topic_type,
645 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
646 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
647 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
648 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
649 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
651 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
652 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
653 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
654 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
655 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
657 'S_TOPIC_TYPE' => $row['topic_type'],
658 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
659 'S_UNREAD_TOPIC' => $unread_topic,
660 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
661 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
662 'S_POSTS_UNAPPROVED' => $posts_unapproved,
663 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
664 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
665 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
666 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
667 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
668 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
670 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
671 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
672 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
673 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
674 'U_VIEW_TOPIC' => $view_topic_url,
675 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
676 'U_MCP_QUEUE' => $u_mcp_queue,
678 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
681 $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
683 if ($unread_topic)
685 $mark_forum_read = false;
688 unset($rowset[$topic_id]);
692 // This is rather a fudge but it's the best I can think of without requiring information
693 // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
694 // any it updates the forum last read cookie. This requires that the user visit the forum
695 // after reading a topic
696 if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
698 update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
701 page_footer();