marge
[phpbb.git] / phpBB / viewforum.php
blob8a7a458706cb883f61c23a89a090ba9cd6a05bc3
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 if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
16 if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
17 include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
18 include(PHPBB_ROOT_PATH . 'includes/functions_display.' . PHP_EXT);
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 $sort_days = request_var('st', ((!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0));
30 $sort_key = request_var('sk', ((!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'));
31 $sort_dir = request_var('sd', ((!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'));
33 // Check if the user has actually sent a forum ID with his/her request
34 // If not give them a nice error page.
35 if (!$forum_id)
37 trigger_error('NO_FORUM');
40 $sql_from = FORUMS_TABLE . ' f';
41 $lastread_select = '';
43 // Grab appropriate forum data
44 if ($config['load_db_lastread'] && $user->data['is_registered'])
46 $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
47 AND ft.forum_id = f.forum_id)';
48 $lastread_select .= ', ft.mark_time';
51 if ($user->data['is_registered'])
53 $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
54 $lastread_select .= ', fw.notify_status';
57 $sql = "SELECT f.* $lastread_select
58 FROM $sql_from
59 WHERE f.forum_id = $forum_id";
60 $result = $db->sql_query($sql);
61 $forum_data = $db->sql_fetchrow($result);
62 $db->sql_freeresult($result);
64 if (!$forum_data)
66 trigger_error('NO_FORUM');
70 // Configure style, language, etc.
71 $user->setup('viewforum', $forum_data['forum_style']);
73 // Redirect to login upon emailed notification links
74 if (isset($_GET['e']) && !$user->data['is_registered'])
76 login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
79 // Permissions check
80 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)))
82 if ($user->data['user_id'] != ANONYMOUS)
84 trigger_error('SORRY_AUTH_READ');
87 login_box('', $user->lang['LOGIN_VIEWFORUM']);
90 // Forum is passworded ... check whether access has been granted to this
91 // user this session, if not show login box
92 if ($forum_data['forum_password'])
94 login_forum_box($forum_data);
97 // Is this forum a link? ... User got here either because the
98 // number of clicks is being tracked or they guessed the id
99 if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
101 // Does it have click tracking enabled?
102 if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
104 $sql = 'UPDATE ' . FORUMS_TABLE . '
105 SET forum_posts = forum_posts + 1
106 WHERE forum_id = ' . $forum_id;
107 $db->sql_query($sql);
110 // We redirect to the url. The third parameter indicates that external redirects are allowed.
111 redirect($forum_data['forum_link'], false, true);
112 exit;
115 // Build navigation links
116 generate_forum_nav($forum_data);
118 // Forum Rules
119 if ($auth->acl_get('f_read', $forum_id))
121 generate_forum_rules($forum_data);
124 // Do we have subforums?
125 $active_forum_ary = $moderators = array();
127 if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
129 list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
131 else
133 $template->assign_var('S_HAS_SUBFORUM', false);
134 get_moderators($moderators, $forum_id);
137 // Dump out the page header and load viewforum template
138 page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']);
140 $template->set_filenames(array(
141 'body' => 'viewforum_body.html')
144 make_jumpbox(append_sid('viewforum'), $forum_id);
146 $template->assign_vars(array(
147 'U_VIEW_FORUM' => append_sid('viewforum', "f=$forum_id&amp;start=$start"),
150 // Not postable forum or showing active topics?
151 if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
153 page_footer();
156 // Ok, if someone has only list-access, we only display the forum list.
157 // We also make this circumstance available to the template in case we want to display a notice. ;)
158 if (!$auth->acl_get('f_read', $forum_id))
160 $template->assign_vars(array(
161 'S_NO_READ_ACCESS' => true,
162 'S_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false,
163 'S_LOGIN_ACTION' => append_sid('ucp', 'mode=login') . '&amp;redirect=' . urlencode(str_replace('&amp;', '&', build_url(array('_f_')))),
166 page_footer();
169 // Handle marking posts
170 if ($mark_read == 'topics')
172 markread('topics', $forum_id);
174 $redirect_url = append_sid('viewforum', 'f=' . $forum_id);
175 meta_refresh(3, $redirect_url);
177 trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
180 // Is a forum specific topic count required?
181 if ($forum_data['forum_topics_per_page'])
183 $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
186 // Do the forum Prune thang - cron type job ...
187 if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
189 $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid('cron', 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
192 // Forum rules and subscription info
193 $s_watching_forum = array(
194 'link' => '',
195 'title' => '',
196 'is_watching' => false,
199 if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
201 $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
202 watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status);
205 $s_forum_rules = '';
206 gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
208 // Topic ordering options
209 $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']);
211 $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']);
212 $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');
214 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
215 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);
217 // Limit topics to certain time frame, obtain correct topic count
218 // global announcements must not be counted, normal announcements have to
219 // be counted, as forum_topics(_real) includes them
220 if ($sort_days)
222 $min_post_time = time() - ($sort_days * 86400);
224 $sql = 'SELECT COUNT(topic_id) AS num_topics
225 FROM ' . TOPICS_TABLE . "
226 WHERE forum_id = $forum_id
227 AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time)
228 OR topic_type = " . POST_ANNOUNCE . ")
229 " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
230 $result = $db->sql_query($sql);
231 $topics_count = (int) $db->sql_fetchfield('num_topics');
232 $db->sql_freeresult($result);
234 if (isset($_POST['sort']))
236 $start = 0;
238 $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
240 // Make sure we have information about day selection ready
241 $template->assign_var('S_SORT_DAYS', true);
243 else
245 $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
246 $sql_limit_time = '';
249 // Make sure $start is set to the last page if it exceeds the amount
250 if ($start < 0 || $start > $topics_count)
252 $start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
255 // Basic pagewide vars
256 $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
258 // Display active topics?
259 $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
261 $template->assign_vars(array(
262 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
264 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
265 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
266 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
267 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'),
268 'FOLDER_NEW_IMG' => $user->img('topic_unread', 'NEW_POSTS'),
269 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_NEW_POSTS_HOT'),
270 'FOLDER_HOT_NEW_IMG' => $user->img('topic_unread_hot', 'NEW_POSTS_HOT'),
271 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_NEW_POSTS_LOCKED'),
272 'FOLDER_LOCKED_NEW_IMG' => $user->img('topic_unread_locked', 'NEW_POSTS_LOCKED'),
273 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
274 'FOLDER_STICKY_NEW_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
275 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
276 'FOLDER_ANNOUNCE_NEW_IMG' => $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
277 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
278 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
279 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
280 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
282 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
284 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
286 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
287 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
288 'S_DISPLAY_ACTIVE' => $s_display_active,
289 'S_SELECT_SORT_DIR' => $s_sort_dir,
290 'S_SELECT_SORT_KEY' => $s_sort_key,
291 'S_SELECT_SORT_DAYS' => $s_limit_days,
292 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
293 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
294 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
295 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
296 'S_FORUM_ACTION' => append_sid('viewforum', "f=$forum_id&amp;start=$start"),
297 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
298 'S_SEARCHBOX_ACTION' => append_sid('search', 'fid[]=' . $forum_id),
299 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
300 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
301 'S_VIEWFORUM' => true,
303 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid('mcp', "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
304 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid('posting', 'mode=post&amp;f=' . $forum_id) : '',
305 'U_VIEW_FORUM' => append_sid('viewforum', "f=$forum_id&amp;$u_sort_param&amp;start=$start"),
306 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid('viewforum', "f=$forum_id&amp;mark=topics") : '',
309 // Grab icons
310 $icons = cache::obtain_icons();
312 // Grab all topic data
313 $rowset = $announcement_list = $topic_list = $global_announce_list = array();
315 $sql_array = array(
316 'SELECT' => 't.*',
317 'FROM' => array(
318 TOPICS_TABLE => 't'
320 'LEFT_JOIN' => array(),
323 $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
325 if ($user->data['is_registered'])
327 if ($config['load_db_track'])
329 $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']);
330 $sql_array['SELECT'] .= ', tp.topic_posted';
333 if ($config['load_db_lastread'])
335 $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']);
336 $sql_array['SELECT'] .= ', tt.mark_time';
338 if ($s_display_active && sizeof($active_forum_ary))
340 $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']);
341 $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
346 if ($forum_data['forum_type'] == FORUM_POST)
348 // Obtain announcements ... removed sort ordering, sort by time in all cases
349 $sql = $db->sql_build_query('SELECT', array(
350 'SELECT' => $sql_array['SELECT'],
351 'FROM' => $sql_array['FROM'],
352 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
354 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
355 AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
357 'ORDER_BY' => 't.topic_time DESC',
359 $result = $db->sql_query($sql);
361 while ($row = $db->sql_fetchrow($result))
363 $rowset[$row['topic_id']] = $row;
364 $announcement_list[] = $row['topic_id'];
366 if ($row['topic_type'] == POST_GLOBAL)
368 $global_announce_list[$row['topic_id']] = true;
370 else
372 $topics_count--;
375 $db->sql_freeresult($result);
378 // If the user is trying to reach late pages, start searching from the end
379 $store_reverse = false;
380 $sql_limit = $config['topics_per_page'];
381 if ($start > $topics_count / 2)
383 $store_reverse = true;
385 if ($start + $config['topics_per_page'] > $topics_count)
387 $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
390 // Select the sort order
391 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
392 $sql_start = max(0, $topics_count - $sql_limit - $start);
394 else
396 // Select the sort order
397 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
398 $sql_start = $start;
401 if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
403 $sql_where = 't.forum_id = ' . $forum_id;
405 else if (empty($active_forum_ary['exclude_forum_id']))
407 $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
409 else
411 $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
412 $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
415 // Grab just the sorted topic ids
416 $sql = 'SELECT t.topic_id
417 FROM ' . TOPICS_TABLE . " t
418 WHERE $sql_where
419 AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
420 $sql_approved
421 $sql_limit_time
422 ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
423 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
425 while ($row = $db->sql_fetchrow($result))
427 $topic_list[] = (int) $row['topic_id'];
429 $db->sql_freeresult($result);
431 // For storing shadow topics
432 $shadow_topic_list = array();
434 if (sizeof($topic_list))
436 // SQL array for obtaining topics/stickies
437 $sql_array = array(
438 'SELECT' => $sql_array['SELECT'],
439 'FROM' => $sql_array['FROM'],
440 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
442 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
445 // If store_reverse, then first obtain topics, then stickies, else the other way around...
446 // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
447 // the number of stickies are not known
448 $sql = $db->sql_build_query('SELECT', $sql_array);
449 $result = $db->sql_query($sql);
451 while ($row = $db->sql_fetchrow($result))
453 if ($row['topic_status'] == ITEM_MOVED)
455 $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
458 $rowset[$row['topic_id']] = $row;
460 $db->sql_freeresult($result);
463 // If we have some shadow topics, update the rowset to reflect their topic information
464 if (sizeof($shadow_topic_list))
466 $sql = 'SELECT *
467 FROM ' . TOPICS_TABLE . '
468 WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
469 $result = $db->sql_query($sql);
471 while ($row = $db->sql_fetchrow($result))
473 $orig_topic_id = $shadow_topic_list[$row['topic_id']];
475 // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
476 if (isset($rowset[$row['topic_id']]))
478 // We need to remove any trace regarding this topic. :)
479 unset($rowset[$orig_topic_id]);
480 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
481 $topics_count--;
483 continue;
486 // Do not include those topics the user has no permission to access
487 if (!$auth->acl_get('f_read', $row['forum_id']))
489 // We need to remove any trace regarding this topic. :)
490 unset($rowset[$orig_topic_id]);
491 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
492 $topics_count--;
494 continue;
497 // We want to retain some values
498 $row = array_merge($row, array(
499 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
500 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
501 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
504 $rowset[$orig_topic_id] = $row;
506 $db->sql_freeresult($result);
508 unset($shadow_topic_list);
510 // Ok, adjust topics count for active topics list
511 if ($s_display_active)
513 $topics_count = 1;
516 $template->assign_vars(array(
517 'PAGINATION' => generate_pagination(append_sid('viewforum', "f=$forum_id&amp;$u_sort_param"), $topics_count, $config['topics_per_page'], $start),
518 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
519 'TOTAL_TOPICS' => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)))
522 $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
523 $topic_tracking_info = $tracking_topics = array();
525 // Okay, lets dump out the page ...
526 if (sizeof($topic_list))
528 $mark_forum_read = true;
529 $mark_time_forum = 0;
531 // Active topics?
532 if ($s_display_active && sizeof($active_forum_ary))
534 // Generate topic forum list...
535 $topic_forum_list = array();
536 foreach ($rowset as $t_id => $row)
538 $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;
539 $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
542 if ($config['load_db_lastread'] && $user->data['is_registered'])
544 foreach ($topic_forum_list as $f_id => $topic_row)
546 $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
549 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
551 foreach ($topic_forum_list as $f_id => $topic_row)
553 $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
557 unset($topic_forum_list);
559 else
561 if ($config['load_db_lastread'] && $user->data['is_registered'])
563 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
564 $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
566 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
568 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
570 if (!$user->data['is_registered'])
572 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
574 $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'];
578 $s_type_switch = 0;
579 foreach ($topic_list as $topic_id)
581 $row = &$rowset[$topic_id];
583 // This will allow the style designer to output a different header
584 // or even separate the list of announcements from sticky and normal topics
585 $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
587 // Replies
588 $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
590 if ($row['topic_status'] == ITEM_MOVED)
592 $topic_id = $row['topic_moved_id'];
593 $unread_topic = false;
595 else
597 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
600 // Get folder img, topic status/type related information
601 $folder_img = $folder_alt = $topic_type = '';
602 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
604 // Generate all the URIs ...
605 $view_topic_url = append_sid('viewtopic', 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
607 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
608 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
609 $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid('mcp', 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
611 // Send vars to template
612 $template->assign_block_vars('topicrow', array(
613 'FORUM_ID' => $forum_id,
614 'TOPIC_ID' => $topic_id,
615 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
616 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
617 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
618 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
619 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
620 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
621 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
622 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
623 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
624 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
626 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
627 'REPLIES' => $replies,
628 'VIEWS' => $row['topic_views'],
629 'TOPIC_TITLE' => censor_text($row['topic_title']),
630 'TOPIC_TYPE' => $topic_type,
632 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
633 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
634 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
635 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
636 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
637 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
638 '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']) : '',
639 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
641 'S_TOPIC_TYPE' => $row['topic_type'],
642 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
643 'S_UNREAD_TOPIC' => $unread_topic,
644 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
645 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
646 'S_POSTS_UNAPPROVED' => $posts_unapproved,
647 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
648 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
649 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
650 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
651 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
652 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
654 'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread',
655 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
656 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
657 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
658 'U_VIEW_TOPIC' => $view_topic_url,
659 'U_MCP_REPORT' => append_sid('mcp', 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
660 'U_MCP_QUEUE' => $u_mcp_queue,
662 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
665 $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
667 if ($unread_topic)
669 $mark_forum_read = false;
672 unset($rowset[$topic_id]);
676 // This is rather a fudge but it's the best I can think of without requiring information
677 // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
678 // any it updates the forum last read cookie. This requires that the user visit the forum
679 // after reading a topic
680 if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
682 update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
685 page_footer();