6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
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
);
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 (phpbb
::$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 (phpbb_request
::is_set('e', phpbb_request
::GET
) && !$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, phpbb
::$config['load_moderators'], phpbb
::$config['load_moderators']);
137 $template->assign_var('S_HAS_SUBFORUM', false);
138 get_moderators($moderators, $forum_id);
141 // Dump out the page header and load viewforum template
142 page_header($user->lang
['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']);
144 $template->set_filenames(array(
145 'body' => 'viewforum_body.html')
148 make_jumpbox(append_sid('viewforum'), $forum_id);
150 $template->assign_vars(array(
151 'U_VIEW_FORUM' => append_sid('viewforum', "f=$forum_id&start=$start"),
154 // Not postable forum or showing active topics?
155 if (!($forum_data['forum_type'] == FORUM_POST ||
(($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS
) && $forum_data['forum_type'] == FORUM_CAT
)))
160 // Ok, if someone has only list-access, we only display the forum list.
161 // We also make this circumstance available to the template in case we want to display a notice. ;)
162 if (!$auth->acl_get('f_read', $forum_id))
164 $template->assign_vars(array(
165 'S_NO_READ_ACCESS' => true,
166 'S_AUTOLOGIN_ENABLED' => (phpbb
::$config['allow_autologin']) ?
true : false,
167 'S_LOGIN_ACTION' => append_sid('ucp', 'mode=login') . '&redirect=' . urlencode(str_replace('&', '&', build_url(array('_f_')))),
173 // Handle marking posts
174 if ($mark_read == 'topics')
176 $token = request_var('hash', '');
177 if (check_link_hash($token, 'global'))
179 markread('topics', $forum_id);
181 $redirect_url = append_sid('viewforum', 'f=' . $forum_id);
182 meta_refresh(3, $redirect_url);
184 trigger_error($user->lang
['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang
['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
187 // Is a forum specific topic count required?
188 if ($forum_data['forum_topics_per_page'])
190 phpbb
::$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
193 // Do the forum Prune thang - cron type job ...
194 if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
196 $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid('cron', 'cron_type=prune_forum&f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
199 // Forum rules and subscription info
200 $s_watching_forum = array(
203 'is_watching' => false,
206 if ((phpbb
::$config['email_enable'] || phpbb
::$config['jab_enable']) && phpbb
::$config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST
&& $auth->acl_get('f_subscribe', $forum_id))
208 $notify_status = (isset($forum_data['notify_status'])) ?
$forum_data['notify_status'] : NULL;
209 watch_topic_forum('forum', $s_watching_forum, $user->data
['user_id'], $forum_id, 0, $notify_status);
213 gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
215 // Topic ordering options
216 $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']);
218 $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']);
219 $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');
221 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
222 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);
224 // Limit topics to certain time frame, obtain correct topic count
225 // global announcements must not be counted, normal announcements have to
226 // be counted, as forum_topics(_real) includes them
229 $min_post_time = time() - ($sort_days * 86400);
231 $sql = 'SELECT COUNT(topic_id) AS num_topics
232 FROM ' . TOPICS_TABLE
. "
233 WHERE forum_id = $forum_id
234 AND ((topic_type <> " . POST_GLOBAL
. " AND topic_last_post_time >= $min_post_time)
235 OR topic_type = " . POST_ANNOUNCE
. ")
236 " . (($auth->acl_get('m_approve', $forum_id)) ?
'' : 'AND topic_approved = 1');
237 $result = $db->sql_query($sql);
238 $topics_count = (int) $db->sql_fetchfield('num_topics');
239 $db->sql_freeresult($result);
241 if (phpbb_request
::is_set_post('sort'))
245 $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
247 // Make sure we have information about day selection ready
248 $template->assign_var('S_SORT_DAYS', true);
252 $topics_count = ($auth->acl_get('m_approve', $forum_id)) ?
$forum_data['forum_topics_real'] : $forum_data['forum_topics'];
253 $sql_limit_time = '';
256 // Make sure $start is set to the last page if it exceeds the amount
257 if ($start < 0 ||
$start > $topics_count)
259 $start = ($start < 0) ?
0 : floor(($topics_count - 1) / phpbb
::$config['topics_per_page']) * phpbb
::$config['topics_per_page'];
262 // Basic pagewide vars
263 $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED
) ?
$user->lang
['FORUM_LOCKED'] : $user->lang
['POST_NEW_TOPIC'];
265 // Display active topics?
266 $s_display_active = ($forum_data['forum_type'] == FORUM_CAT
&& ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS
)) ?
true : false;
268 $template->assign_vars(array(
269 'MODERATORS' => (!empty($moderators[$forum_id])) ?
implode(', ', $moderators[$forum_id]) : '',
271 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED
) ?
$user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
272 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
273 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
274 'FOLDER_IMG' => $user->img('topic_read', 'NO_NEW_POSTS'),
275 'FOLDER_NEW_IMG' => $user->img('topic_unread', 'NEW_POSTS'),
276 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_NEW_POSTS_HOT'),
277 'FOLDER_HOT_NEW_IMG' => $user->img('topic_unread_hot', 'NEW_POSTS_HOT'),
278 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_NEW_POSTS_LOCKED'),
279 'FOLDER_LOCKED_NEW_IMG' => $user->img('topic_unread_locked', 'NEW_POSTS_LOCKED'),
280 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
281 'FOLDER_STICKY_NEW_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
282 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
283 'FOLDER_ANNOUNCE_NEW_IMG' => $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
284 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
285 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
286 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
287 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
289 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED
) ?
$user->lang
['POST_FORUM_LOCKED'] : $user->lang
['NO_TOPICS'],
291 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST
&& ($auth->acl_get('f_post', $forum_id) ||
$user->data
['user_id'] == ANONYMOUS
)) ?
true : false,
293 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST
) ?
true : false,
294 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ?
true : false,
295 'S_DISPLAY_ACTIVE' => $s_display_active,
296 'S_SELECT_SORT_DIR' => $s_sort_dir,
297 'S_SELECT_SORT_KEY' => $s_sort_key,
298 'S_SELECT_SORT_DAYS' => $s_limit_days,
299 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ?
max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ?
true : false),
300 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
301 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
302 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
303 'S_FORUM_ACTION' => append_sid('viewforum', "f=$forum_id&start=$start"),
304 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && phpbb
::$config['load_search']) ?
true : false,
305 'S_SEARCHBOX_ACTION' => append_sid('search', 'fid[]=' . $forum_id),
306 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ?
false : true,
307 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED
) ?
true : false,
308 'S_VIEWFORUM' => true,
310 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ?
append_sid('mcp', "f=$forum_id&i=main&mode=forum_view", true, $user->session_id
) : '',
311 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) ||
$user->data
['user_id'] == ANONYMOUS
) ?
append_sid('posting', 'mode=post&f=' . $forum_id) : '',
312 'U_VIEW_FORUM' => append_sid('viewforum', "f=$forum_id" . ((strlen($u_sort_param)) ?
"&$u_sort_param" : '') . "&start=$start"),
313 'U_MARK_TOPICS' => ($user->data
['is_registered'] || phpbb
::$config['load_anon_lastread']) ?
append_sid('viewforum', 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics") : '',
317 $icons = phpbb_cache
::obtain_icons();
319 // Grab all topic data
320 $rowset = $announcement_list = $topic_list = $global_announce_list = array();
327 'LEFT_JOIN' => array(),
330 $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ?
'' : 'AND t.topic_approved = 1';
332 if ($user->data
['is_registered'])
334 if (phpbb
::$config['load_db_track'])
336 $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']);
337 $sql_array['SELECT'] .= ', tp.topic_posted';
340 if (phpbb
::$config['load_db_lastread'])
342 $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']);
343 $sql_array['SELECT'] .= ', tt.mark_time';
345 if ($s_display_active && sizeof($active_forum_ary))
347 $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']);
348 $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
353 if ($forum_data['forum_type'] == FORUM_POST
)
355 // Obtain announcements ... removed sort ordering, sort by time in all cases
356 $sql = $db->sql_build_query('SELECT', array(
357 'SELECT' => $sql_array['SELECT'],
358 'FROM' => $sql_array['FROM'],
359 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
361 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
362 AND t.topic_type IN (' . POST_ANNOUNCE
. ', ' . POST_GLOBAL
. ')',
364 'ORDER_BY' => 't.topic_time DESC',
366 $result = $db->sql_query($sql);
368 while ($row = $db->sql_fetchrow($result))
370 $rowset[$row['topic_id']] = $row;
371 $announcement_list[] = $row['topic_id'];
373 if ($row['topic_type'] == POST_GLOBAL
)
375 $global_announce_list[$row['topic_id']] = true;
382 $db->sql_freeresult($result);
385 // If the user is trying to reach late pages, start searching from the end
386 $store_reverse = false;
387 $sql_limit = phpbb
::$config['topics_per_page'];
388 if ($start > $topics_count / 2)
390 $store_reverse = true;
392 if ($start + phpbb
::$config['topics_per_page'] > $topics_count)
394 $sql_limit = min(phpbb
::$config['topics_per_page'], max(1, $topics_count - $start));
397 // Select the sort order
398 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ?
'ASC' : 'DESC');
399 $sql_start = max(0, $topics_count - $sql_limit - $start);
403 // Select the sort order
404 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ?
'DESC' : 'ASC');
408 if ($forum_data['forum_type'] == FORUM_POST ||
!sizeof($active_forum_ary))
410 $sql_where = 't.forum_id = ' . $forum_id;
412 else if (empty($active_forum_ary['exclude_forum_id']))
414 $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
418 $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
419 $sql_where = (sizeof($get_forum_ids)) ?
$db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
422 // Grab just the sorted topic ids
423 $sql = 'SELECT t.topic_id
424 FROM ' . TOPICS_TABLE
. " t
426 AND t.topic_type IN (" . POST_NORMAL
. ', ' . POST_STICKY
. ")
429 ORDER BY t.topic_type " . ((!$store_reverse) ?
'DESC' : 'ASC') . ', ' . $sql_sort_order;
430 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
432 while ($row = $db->sql_fetchrow($result))
434 $topic_list[] = (int) $row['topic_id'];
436 $db->sql_freeresult($result);
438 // For storing shadow topics
439 $shadow_topic_list = array();
441 if (sizeof($topic_list))
443 // SQL array for obtaining topics/stickies
445 'SELECT' => $sql_array['SELECT'],
446 'FROM' => $sql_array['FROM'],
447 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
449 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
452 // If store_reverse, then first obtain topics, then stickies, else the other way around...
453 // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
454 // the number of stickies are not known
455 $sql = $db->sql_build_query('SELECT', $sql_array);
456 $result = $db->sql_query($sql);
458 while ($row = $db->sql_fetchrow($result))
460 if ($row['topic_status'] == ITEM_MOVED
)
462 $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
465 $rowset[$row['topic_id']] = $row;
467 $db->sql_freeresult($result);
470 // If we have some shadow topics, update the rowset to reflect their topic information
471 if (sizeof($shadow_topic_list))
474 FROM ' . TOPICS_TABLE
. '
475 WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
476 $result = $db->sql_query($sql);
478 while ($row = $db->sql_fetchrow($result))
480 $orig_topic_id = $shadow_topic_list[$row['topic_id']];
482 // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
483 if (isset($rowset[$row['topic_id']]))
485 // We need to remove any trace regarding this topic. :)
486 unset($rowset[$orig_topic_id]);
487 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
493 // Do not include those topics the user has no permission to access
494 if (!$auth->acl_get('f_read', $row['forum_id']))
496 // We need to remove any trace regarding this topic. :)
497 unset($rowset[$orig_topic_id]);
498 unset($topic_list[array_search($orig_topic_id, $topic_list)]);
504 // We want to retain some values
505 $row = array_merge($row, array(
506 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
507 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
508 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
511 // Shadow topics are never reported
512 $row['topic_reported'] = 0;
514 $rowset[$orig_topic_id] = $row;
516 $db->sql_freeresult($result);
518 unset($shadow_topic_list);
520 // Ok, adjust topics count for active topics list
521 if ($s_display_active)
526 $template->assign_vars(array(
527 'PAGINATION' => generate_pagination(append_sid('viewforum', "f=$forum_id" . ((strlen($u_sort_param)) ?
"&$u_sort_param" : '')), $topics_count, phpbb
::$config['topics_per_page'], $start),
528 'PAGE_NUMBER' => on_page($topics_count, phpbb
::$config['topics_per_page'], $start),
529 'TOTAL_TOPICS' => ($s_display_active) ?
false : (($topics_count == 1) ?
$user->lang
['VIEW_FORUM_TOPIC'] : sprintf($user->lang
['VIEW_FORUM_TOPICS'], $topics_count)))
532 $topic_list = ($store_reverse) ?
array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
533 $topic_tracking_info = $tracking_topics = array();
535 // Okay, lets dump out the page ...
536 if (sizeof($topic_list))
538 $mark_forum_read = true;
539 $mark_time_forum = 0;
542 if ($s_display_active && sizeof($active_forum_ary))
544 // Generate topic forum list...
545 $topic_forum_list = array();
546 foreach ($rowset as $t_id => $row)
548 $topic_forum_list[$row['forum_id']]['forum_mark_time'] = (phpbb
::$config['load_db_lastread'] && $user->data
['is_registered'] && isset($row['forum_mark_time'])) ?
$row['forum_mark_time'] : 0;
549 $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
552 if (phpbb
::$config['load_db_lastread'] && $user->data
['is_registered'])
554 foreach ($topic_forum_list as $f_id => $topic_row)
556 $topic_tracking_info +
= get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
559 else if (phpbb
::$config['load_anon_lastread'] ||
$user->data
['is_registered'])
561 foreach ($topic_forum_list as $f_id => $topic_row)
563 $topic_tracking_info +
= get_complete_topic_tracking($f_id, $topic_row['topics'], false);
567 unset($topic_forum_list);
571 if (phpbb
::$config['load_db_lastread'] && $user->data
['is_registered'])
573 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
574 $mark_time_forum = (!empty($forum_data['mark_time'])) ?
$forum_data['mark_time'] : $user->data
['user_lastmark'];
576 else if (phpbb
::$config['load_anon_lastread'] ||
$user->data
['is_registered'])
578 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
580 if (!$user->data
['is_registered'])
582 $user->data
['user_lastmark'] = (isset($tracking_topics['l'])) ?
(int) (base_convert($tracking_topics['l'], 36, 10) + phpbb
::$config['board_startdate']) : 0;
584 $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ?
(int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + phpbb
::$config['board_startdate']) : $user->data
['user_lastmark'];
589 foreach ($topic_list as $topic_id)
591 $row = &$rowset[$topic_id];
593 // This will allow the style designer to output a different header
594 // or even separate the list of announcements from sticky and normal topics
595 $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE ||
$row['topic_type'] == POST_GLOBAL
) ?
1 : 0;
598 $replies = ($auth->acl_get('m_approve', $forum_id)) ?
$row['topic_replies_real'] : $row['topic_replies'];
600 if ($row['topic_status'] == ITEM_MOVED
)
602 $topic_id = $row['topic_moved_id'];
603 $unread_topic = false;
607 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ?
true : false;
610 // Get folder img, topic status/type related information
611 $folder_img = $folder_alt = $topic_type = '';
612 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
614 // Generate all the URIs ...
615 $view_topic_url = append_sid('viewtopic', 'f=' . (($row['forum_id']) ?
$row['forum_id'] : $forum_id) . '&t=' . $topic_id);
617 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ?
true : false;
618 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ?
true : false;
619 $u_mcp_queue = ($topic_unapproved ||
$posts_unapproved) ?
append_sid('mcp', 'i=queue&mode=' . (($topic_unapproved) ?
'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id
) : '';
621 // Send vars to template
622 $template->assign_block_vars('topicrow', array(
623 'FORUM_ID' => $forum_id,
624 'TOPIC_ID' => $topic_id,
625 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
626 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
627 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
628 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
629 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
630 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
631 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
632 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
633 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
634 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
636 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
637 'REPLIES' => $replies,
638 'VIEWS' => $row['topic_views'],
639 'TOPIC_TITLE' => censor_text($row['topic_title']),
640 'TOPIC_TYPE' => $topic_type,
642 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
643 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, 'src'),
644 'TOPIC_FOLDER_IMG_ALT' => $user->lang
[$folder_alt],
645 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', 'width'),
646 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', 'height'),
648 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['img'] : '',
649 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['width'] : '',
650 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['height'] : '',
651 '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']) : '',
652 'UNAPPROVED_IMG' => ($topic_unapproved ||
$posts_unapproved) ?
$user->img('icon_topic_unapproved', ($topic_unapproved) ?
'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
654 'S_TOPIC_TYPE' => $row['topic_type'],
655 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ?
true : false,
656 'S_UNREAD_TOPIC' => $unread_topic,
657 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ?
true : false,
658 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
659 'S_POSTS_UNAPPROVED' => $posts_unapproved,
660 'S_HAS_POLL' => ($row['poll_start']) ?
true : false,
661 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE
) ?
true : false,
662 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL
) ?
true : false,
663 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY
) ?
true : false,
664 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED
) ?
true : false,
665 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED
) ?
true : false,
667 'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread',
668 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
669 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
670 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
671 'U_VIEW_TOPIC' => $view_topic_url,
672 'U_MCP_REPORT' => append_sid('mcp', 'i=reports&mode=reports&f=' . $forum_id . '&t=' . $topic_id, true, $user->session_id
),
673 'U_MCP_QUEUE' => $u_mcp_queue,
675 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ?
-1 : $s_type_switch_test)
678 $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE ||
$row['topic_type'] == POST_GLOBAL
) ?
1 : 0;
682 $mark_forum_read = false;
685 unset($rowset[$topic_id]);
689 // This is rather a fudge but it's the best I can think of without requiring information
690 // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
691 // any it updates the forum last read cookie. This requires that the user visit the forum
692 // after reading a topic
693 if ($forum_data['forum_type'] == FORUM_POST
&& sizeof($topic_list) && $mark_forum_read)
695 update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);