fixing some annoying bugs
[phpbb.git] / phpBB / viewtopic.php
blob32b35a2060399d02978af8a4f2c320a9d48cb790
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);
19 include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
21 // Start session management
22 $user->session_begin();
23 $auth->acl($user->data);
25 // Initial var setup
26 $forum_id = request_var('f', 0);
27 $topic_id = request_var('t', 0);
28 $post_id = request_var('p', 0);
29 $voted_id = request_var('vote_id', array('' => 0));
31 $start = request_var('start', 0);
32 $view = request_var('view', '');
34 $sort_days = request_var('st', ((!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0));
35 $sort_key = request_var('sk', ((!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'));
36 $sort_dir = request_var('sd', ((!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'));
38 $update = request_var('update', false);
40 /**
41 * @todo normalize?
43 $hilit_words = request_var('hilit', '', true);
45 // Do we have a topic or post id?
46 if (!$topic_id && !$post_id)
48 trigger_error('NO_TOPIC');
51 // Find topic id if user requested a newer or older topic
52 if ($view && !$post_id)
54 if (!$forum_id)
56 $sql = 'SELECT forum_id
57 FROM ' . TOPICS_TABLE . "
58 WHERE topic_id = $topic_id";
59 $result = $db->sql_query($sql);
60 $forum_id = (int) $db->sql_fetchfield('forum_id');
61 $db->sql_freeresult($result);
63 if (!$forum_id)
65 trigger_error('NO_TOPIC');
69 if ($view == 'unread')
71 // Get topic tracking info
72 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
74 $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0;
76 $sql = 'SELECT post_id, topic_id, forum_id
77 FROM ' . POSTS_TABLE . "
78 WHERE topic_id = $topic_id
79 " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . "
80 AND post_time > $topic_last_read
81 ORDER BY post_time ASC";
82 $result = $db->sql_query_limit($sql, 1);
83 $row = $db->sql_fetchrow($result);
84 $db->sql_freeresult($result);
86 if (!$row)
88 $sql = 'SELECT topic_last_post_id as post_id, topic_id, forum_id
89 FROM ' . TOPICS_TABLE . '
90 WHERE topic_id = ' . $topic_id;
91 $result = $db->sql_query($sql);
92 $row = $db->sql_fetchrow($result);
93 $db->sql_freeresult($result);
96 if (!$row)
98 // Setup user environment so we can process lang string
99 $user->setup('viewtopic');
101 trigger_error('NO_TOPIC');
104 $post_id = $row['post_id'];
105 $topic_id = $row['topic_id'];
107 else if ($view == 'next' || $view == 'previous')
109 $sql_condition = ($view == 'next') ? '>' : '<';
110 $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
112 $sql = 'SELECT forum_id, topic_last_post_time
113 FROM ' . TOPICS_TABLE . '
114 WHERE topic_id = ' . $topic_id;
115 $result = $db->sql_query($sql);
116 $row = $db->sql_fetchrow($result);
117 $db->sql_freeresult($result);
119 $sql = 'SELECT topic_id, forum_id
120 FROM ' . TOPICS_TABLE . '
121 WHERE forum_id = ' . $row['forum_id'] . "
122 AND topic_moved_id = 0
123 AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
124 " . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
125 ORDER BY topic_last_post_time $sql_ordering";
126 $result = $db->sql_query_limit($sql, 1);
127 $row = $db->sql_fetchrow($result);
128 $db->sql_freeresult($result);
130 if (!$row)
132 $user->setup('viewtopic');
133 trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
135 else
137 $topic_id = $row['topic_id'];
139 // Check for global announcement correctness?
140 if (!$row['forum_id'] && !$forum_id)
142 trigger_error('NO_TOPIC');
144 else if ($row['forum_id'])
146 $forum_id = $row['forum_id'];
151 // Check for global announcement correctness?
152 if ((!isset($row) || !$row['forum_id']) && !$forum_id)
154 trigger_error('NO_TOPIC');
156 else if (isset($row) && $row['forum_id'])
158 $forum_id = $row['forum_id'];
162 // This rather complex gaggle of code handles querying for topics but
163 // also allows for direct linking to a post (and the calculation of which
164 // page the post is on and the correct display of viewtopic)
165 $sql_array = array(
166 'SELECT' => 't.*, f.*',
168 'FROM' => array(
169 FORUMS_TABLE => 'f',
173 if ($user->data['is_registered'])
175 $sql_array['SELECT'] .= ', tw.notify_status';
176 $sql_array['LEFT_JOIN'] = array();
178 $sql_array['LEFT_JOIN'][] = array(
179 'FROM' => array(TOPICS_WATCH_TABLE => 'tw'),
180 'ON' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
183 if ($config['allow_bookmarks'])
185 $sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
186 $sql_array['LEFT_JOIN'][] = array(
187 'FROM' => array(BOOKMARKS_TABLE => 'bm'),
188 'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'
192 if ($config['load_db_lastread'])
194 $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
196 $sql_array['LEFT_JOIN'][] = array(
197 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
198 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
201 $sql_array['LEFT_JOIN'][] = array(
202 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
203 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
208 if (!$post_id)
210 $sql_array['WHERE'] = "t.topic_id = $topic_id";
212 else
214 $sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id" . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '');
215 $sql_array['FROM'][POSTS_TABLE] = 'p';
218 $sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
220 if (!$forum_id)
222 // If it is a global announcement make sure to set the forum id to a postable forum
223 $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
224 AND f.forum_type = ' . FORUM_POST . ')';
226 else
228 $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
229 AND f.forum_id = $forum_id)";
232 $sql_array['WHERE'] .= ')';
233 $sql_array['FROM'][TOPICS_TABLE] = 't';
235 // Join to forum table on topic forum_id unless topic forum_id is zero
236 // whereupon we join on the forum_id passed as a parameter ... this
237 // is done so navigation, forum name, etc. remain consistent with where
238 // user clicked to view a global topic
239 $sql = $db->sql_build_query('SELECT', $sql_array);
240 $result = $db->sql_query($sql);
241 $topic_data = $db->sql_fetchrow($result);
242 $db->sql_freeresult($result);
244 if (!$topic_data)
246 // If post_id was submitted, we try at least to display the topic as a last resort...
247 if ($post_id && $forum_id && $topic_id)
249 redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id"));
252 trigger_error('NO_TOPIC');
255 // This is for determining where we are (page)
256 if ($post_id)
258 if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
260 $check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
262 if ($sort_dir == $check_sort)
264 $topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
266 else
268 $topic_data['prev_posts'] = 0;
271 else
273 $sql = 'SELECT COUNT(p1.post_id) AS prev_posts
274 FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
275 WHERE p1.topic_id = {$topic_data['topic_id']}
276 AND p2.post_id = {$post_id}
277 " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
278 AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');
280 $result = $db->sql_query($sql);
281 $row = $db->sql_fetchrow($result);
282 $db->sql_freeresult($result);
284 $topic_data['prev_posts'] = $row['prev_posts'] - 1;
288 $forum_id = (int) $topic_data['forum_id'];
289 $topic_id = (int) $topic_data['topic_id'];
292 $topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
294 // Check sticky/announcement time limit
295 if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time())
297 $sql = 'UPDATE ' . TOPICS_TABLE . '
298 SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0
299 WHERE topic_id = ' . $topic_id;
300 $db->sql_query($sql);
302 $topic_data['topic_type'] = POST_NORMAL;
303 $topic_data['topic_time_limit'] = 0;
306 // Setup look and feel
307 $user->setup('viewtopic', $topic_data['forum_style']);
309 if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
311 trigger_error('NO_TOPIC');
314 // Start auth check
315 if (!$auth->acl_get('f_read', $forum_id))
317 if ($user->data['user_id'] != ANONYMOUS)
319 trigger_error('SORRY_AUTH_READ');
322 login_box('', $user->lang['LOGIN_VIEWFORUM']);
325 // Forum is passworded ... check whether access has been granted to this
326 // user this session, if not show login box
327 if ($topic_data['forum_password'])
329 login_forum_box($topic_data);
332 // Redirect to login or to the correct post upon emailed notification links
333 if (isset($_GET['e']))
335 $jump_to = request_var('e', 0);
337 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
339 if ($user->data['user_id'] == ANONYMOUS)
341 login_box($redirect_url . "&amp;p=$post_id&amp;e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']);
344 if ($jump_to > 0)
346 // We direct the already logged in user to the correct post...
347 redirect($redirect_url . ((!$post_id) ? "&amp;p=$jump_to" : "&amp;p=$post_id") . "#p$jump_to");
351 // What is start equal to?
352 if ($post_id)
354 $start = floor(($topic_data['prev_posts']) / $config['posts_per_page']) * $config['posts_per_page'];
357 // Get topic tracking info
358 if (!isset($topic_tracking_info))
360 $topic_tracking_info = array();
362 // Get topic tracking info
363 if ($config['load_db_lastread'] && $user->data['is_registered'])
365 $tmp_topic_data = array($topic_id => $topic_data);
366 $topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time']));
367 unset($tmp_topic_data);
369 else if ($config['load_anon_lastread'] || $user->data['is_registered'])
371 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
375 // Post ordering options
376 $limit_days = array(0 => $user->lang['ALL_POSTS'], 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']);
378 $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
379 $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
381 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
382 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);
384 // Obtain correct post count and ordering SQL if user has
385 // requested anything different
386 if ($sort_days)
388 $min_post_time = time() - ($sort_days * 86400);
390 $sql = 'SELECT COUNT(post_id) AS num_posts
391 FROM ' . POSTS_TABLE . "
392 WHERE topic_id = $topic_id
393 AND post_time >= $min_post_time
394 " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1');
395 $result = $db->sql_query($sql);
396 $total_posts = (int) $db->sql_fetchfield('num_posts');
397 $db->sql_freeresult($result);
399 $limit_posts_time = "AND p.post_time >= $min_post_time ";
401 if (isset($_POST['sort']))
403 $start = 0;
406 else
408 $total_posts = $topic_replies + 1;
409 $limit_posts_time = '';
412 // Was a highlight request part of the URI?
413 $highlight_match = $highlight = '';
414 if ($hilit_words)
416 foreach (explode(' ', trim($hilit_words)) as $word)
418 if (trim($word))
420 $word = str_replace('\*', '\w+?', preg_quote($word, '#'));
421 $word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word);
422 $highlight_match .= (($highlight_match != '') ? '|' : '') . $word;
426 $highlight = urlencode($hilit_words);
429 // Make sure $start is set to the last page if it exceeds the amount
430 if ($start < 0 || $start > $total_posts)
432 $start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
435 // General Viewtopic URL for return links
436 $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start&amp;$u_sort_param" . (($highlight_match) ? "&amp;hilit=$highlight" : ''));
438 // Are we watching this topic?
439 $s_watching_topic = $s_watching_topic_img = array();
440 $s_watching_topic['link'] = $s_watching_topic['title'] = '';
441 $s_watching_topic['is_watching'] = false;
443 if ($config['email_enable'] && $config['allow_topic_notify'] && $user->data['is_registered'])
445 watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $forum_id, $topic_id, $topic_data['notify_status'], $start);
448 // Bookmarks
449 if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0))
451 if (!$topic_data['bookmarked'])
453 $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
454 'user_id' => $user->data['user_id'],
455 'topic_id' => $topic_id,
457 $db->sql_query($sql);
459 else
461 $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . "
462 WHERE user_id = {$user->data['user_id']}
463 AND topic_id = $topic_id";
464 $db->sql_query($sql);
467 meta_refresh(3, $viewtopic_url);
469 $message = (($topic_data['bookmarked']) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
470 trigger_error($message);
473 // Grab ranks
474 $ranks = $cache->obtain_ranks();
476 // Grab icons
477 $icons = $cache->obtain_icons();
479 // Grab extensions
480 $extensions = array();
481 if ($topic_data['topic_attachment'])
483 $extensions = $cache->obtain_attach_extensions($forum_id);
486 // Forum rules listing
487 $s_forum_rules = '';
488 gen_forum_auth_level('topic', $forum_id, $topic_data['forum_status']);
490 // Quick mod tools
491 $allow_change_type = ($auth->acl_get('m_', $forum_id) || ($user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'])) ? true : false;
493 $topic_mod = '';
494 $topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'] && $topic_data['topic_status'] == ITEM_UNLOCKED)) ? (($topic_data['topic_status'] == ITEM_UNLOCKED) ? '<option value="lock">' . $user->lang['LOCK_TOPIC'] . '</option>' : '<option value="unlock">' . $user->lang['UNLOCK_TOPIC'] . '</option>') : '';
495 $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : '';
496 $topic_mod .= ($auth->acl_get('m_move', $forum_id) && $topic_data['topic_status'] != ITEM_MOVED) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : '';
497 $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : '';
498 $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_POSTS'] . '</option>' : '';
499 $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge_topic">' . $user->lang['MERGE_TOPIC'] . '</option>' : '';
500 $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : '';
501 $topic_mod .= ($allow_change_type && $auth->acl_gets('f_sticky', 'f_announce', $forum_id) && $topic_data['topic_type'] != POST_NORMAL) ? '<option value="make_normal">' . $user->lang['MAKE_NORMAL'] . '</option>' : '';
502 $topic_mod .= ($allow_change_type && $auth->acl_get('f_sticky', $forum_id) && $topic_data['topic_type'] != POST_STICKY) ? '<option value="make_sticky">' . $user->lang['MAKE_STICKY'] . '</option>' : '';
503 $topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_ANNOUNCE) ? '<option value="make_announce">' . $user->lang['MAKE_ANNOUNCE'] . '</option>' : '';
504 $topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_GLOBAL) ? '<option value="make_global">' . $user->lang['MAKE_GLOBAL'] . '</option>' : '';
505 $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="topic_logs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : '';
507 // If we've got a hightlight set pass it on to pagination.
508 $pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;$u_sort_param" . (($highlight_match) ? "&amp;hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
510 // Navigation links
511 generate_forum_nav($topic_data);
513 // Forum Rules
514 generate_forum_rules($topic_data);
516 // Moderators
517 $forum_moderators = array();
518 get_moderators($forum_moderators, $forum_id);
520 // This is only used for print view so ...
521 $server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';
523 // Replace naughty words in title
524 $topic_data['topic_title'] = censor_text($topic_data['topic_title']);
526 // Send vars to template
527 $template->assign_vars(array(
528 'FORUM_ID' => $forum_id,
529 'FORUM_NAME' => $topic_data['forum_name'],
530 'FORUM_DESC' => generate_text_for_display($topic_data['forum_desc'], $topic_data['forum_desc_uid'], $topic_data['forum_desc_bitfield'], $topic_data['forum_desc_options']),
531 'TOPIC_ID' => $topic_id,
532 'TOPIC_TITLE' => $topic_data['topic_title'],
533 'TOPIC_POSTER' => $topic_data['topic_poster'],
535 'TOPIC_AUTHOR_FULL' => get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
536 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
537 'TOPIC_AUTHOR' => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
539 'PAGINATION' => $pagination,
540 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start),
541 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts),
542 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;f=$forum_id&amp;t=$topic_id&amp;start=$start&amp;$u_sort_param", true, $user->session_id) : '',
543 'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '',
545 'POST_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'),
546 'QUOTE_IMG' => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
547 'REPLY_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'),
548 'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_POST'),
549 'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_POST'),
550 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'),
551 'PROFILE_IMG' => $user->img('icon_user_profile', 'READ_PROFILE'),
552 'SEARCH_IMG' => $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
553 'PM_IMG' => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
554 'EMAIL_IMG' => $user->img('icon_contact_email', 'SEND_EMAIL'),
555 'WWW_IMG' => $user->img('icon_contact_www', 'VISIT_WEBSITE'),
556 'ICQ_IMG' => $user->img('icon_contact_icq', 'ICQ'),
557 'AIM_IMG' => $user->img('icon_contact_aim', 'AIM'),
558 'MSN_IMG' => $user->img('icon_contact_msnm', 'MSNM'),
559 'YIM_IMG' => $user->img('icon_contact_yahoo', 'YIM'),
560 'JABBER_IMG' => $user->img('icon_contact_jabber', 'JABBER') ,
561 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_POST'),
562 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'),
563 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
564 'WARN_IMG' => $user->img('icon_user_warn', 'WARN_USER'),
566 'S_IS_LOCKED' =>($topic_data['topic_status'] == ITEM_UNLOCKED) ? false : true,
567 'S_SELECT_SORT_DIR' => $s_sort_dir,
568 'S_SELECT_SORT_KEY' => $s_sort_key,
569 'S_SELECT_SORT_DAYS' => $s_limit_days,
570 'S_SINGLE_MODERATOR' => (!empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1) ? false : true,
571 'S_TOPIC_ACTION' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start"),
572 'S_TOPIC_MOD' => ($topic_mod != '') ? '<select name="action">' . $topic_mod . '</select>' : '',
573 'S_MOD_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;quickmod=1&amp;redirect=" . urlencode(str_replace('&amp;', '&', $viewtopic_url)), true, $user->session_id),
575 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
576 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 't=' . $topic_id),
578 'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
579 'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
581 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
582 'U_FORUM' => $server_path,
583 'U_VIEW_TOPIC' => $viewtopic_url,
584 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
585 'U_VIEW_OLDER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=previous"),
586 'U_VIEW_NEWER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=next"),
587 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&amp;view=print' : '',
588 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;t=$topic_id") : '',
590 'U_WATCH_TOPIC' => $s_watching_topic['link'],
591 'L_WATCH_TOPIC' => $s_watching_topic['title'],
592 'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'],
594 'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&amp;bookmark=1' : '',
595 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
597 '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") : '',
598 'U_POST_REPLY_TOPIC' => ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&amp;f=$forum_id&amp;t=$topic_id") : '',
599 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=bump&amp;f=$forum_id&amp;t=$topic_id") : '')
602 // Does this topic contain a poll?
603 if (!empty($topic_data['poll_start']))
605 $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
606 FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p
607 WHERE o.topic_id = $topic_id
608 AND p.post_id = {$topic_data['topic_first_post_id']}
609 AND p.topic_id = o.topic_id
610 ORDER BY o.poll_option_id";
611 $result = $db->sql_query($sql);
613 $poll_info = array();
614 while ($row = $db->sql_fetchrow($result))
616 $poll_info[] = $row;
618 $db->sql_freeresult($result);
620 $cur_voted_id = array();
621 if ($user->data['is_registered'])
623 $sql = 'SELECT poll_option_id
624 FROM ' . POLL_VOTES_TABLE . '
625 WHERE topic_id = ' . $topic_id . '
626 AND vote_user_id = ' . $user->data['user_id'];
627 $result = $db->sql_query($sql);
629 while ($row = $db->sql_fetchrow($result))
631 $cur_voted_id[] = $row['poll_option_id'];
633 $db->sql_freeresult($result);
635 else
637 // Cookie based guest tracking ... I don't like this but hum ho
638 // it's oft requested. This relies on "nice" users who don't feel
639 // the need to delete cookies to mess with results.
640 if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
642 $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
643 $cur_voted_id = array_map('intval', $cur_voted_id);
647 $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
648 ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change'])) &&
649 (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
650 $topic_data['topic_status'] != ITEM_LOCKED &&
651 $topic_data['forum_status'] != ITEM_LOCKED) ? true : false;
652 $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false;
654 if ($update && $s_can_vote)
656 if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'])
658 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start");
660 meta_refresh(5, $redirect_url);
662 $message = (!sizeof($voted_id)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS';
663 $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
664 trigger_error($message);
667 foreach ($voted_id as $option)
669 if (in_array($option, $cur_voted_id))
671 continue;
674 $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
675 SET poll_option_total = poll_option_total + 1
676 WHERE poll_option_id = ' . (int) $option . '
677 AND topic_id = ' . (int) $topic_id;
678 $db->sql_query($sql);
680 if ($user->data['is_registered'])
682 $sql_ary = array(
683 'topic_id' => (int) $topic_id,
684 'poll_option_id' => (int) $option,
685 'vote_user_id' => (int) $user->data['user_id'],
686 'vote_user_ip' => (string) $user->ip,
689 $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
690 $db->sql_query($sql);
694 foreach ($cur_voted_id as $option)
696 if (!in_array($option, $voted_id))
698 $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
699 SET poll_option_total = poll_option_total - 1
700 WHERE poll_option_id = ' . (int) $option . '
701 AND topic_id = ' . (int) $topic_id;
702 $db->sql_query($sql);
704 if ($user->data['is_registered'])
706 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
707 WHERE topic_id = ' . (int) $topic_id . '
708 AND poll_option_id = ' . (int) $option . '
709 AND vote_user_id = ' . (int) $user->data['user_id'];
710 $db->sql_query($sql);
715 if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
717 $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
720 $sql = 'UPDATE ' . TOPICS_TABLE . '
721 SET poll_last_vote = ' . time() . "
722 WHERE topic_id = $topic_id";
723 //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
724 $db->sql_query($sql);
726 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start");
728 meta_refresh(5, $redirect_url);
729 trigger_error($user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
732 $poll_total = 0;
733 foreach ($poll_info as $poll_option)
735 $poll_total += $poll_option['poll_option_total'];
738 if ($poll_info[0]['bbcode_bitfield'])
740 $poll_bbcode = new bbcode();
742 else
744 $poll_bbcode = false;
747 for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
749 $poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
751 if ($poll_bbcode !== false)
753 $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
756 $poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
757 $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
760 $topic_data['poll_title'] = censor_text($topic_data['poll_title']);
762 if ($poll_bbcode !== false)
764 $poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
767 $topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
768 $topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
770 unset($poll_bbcode);
772 foreach ($poll_info as $poll_option)
774 $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
775 $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100));
777 $template->assign_block_vars('poll_option', array(
778 'POLL_OPTION_ID' => $poll_option['poll_option_id'],
779 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
780 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
781 'POLL_OPTION_PERCENT' => $option_pct_txt,
782 'POLL_OPTION_PCT' => round($option_pct * 100),
783 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
784 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
788 $poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
790 $template->assign_vars(array(
791 'POLL_QUESTION' => $topic_data['poll_title'],
792 'TOTAL_VOTES' => $poll_total,
793 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
794 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
796 'L_MAX_VOTES' => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']),
797 'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
799 'S_HAS_POLL' => true,
800 'S_CAN_VOTE' => $s_can_vote,
801 'S_DISPLAY_RESULTS' => $s_display_results,
802 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false,
803 'S_POLL_ACTION' => $viewtopic_url,
805 'U_VIEW_RESULTS' => $viewtopic_url . '&amp;view=viewpoll')
808 unset($poll_end, $poll_info, $voted_id);
811 // If the user is trying to reach the second half of the topic, fetch it starting from the end
812 $store_reverse = false;
813 $sql_limit = $config['posts_per_page'];
815 if ($start > $total_posts / 2)
817 $store_reverse = true;
819 if ($start + $config['posts_per_page'] > $total_posts)
821 $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
824 // Select the sort order
825 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
826 $sql_start = max(0, $total_posts - $sql_limit - $start);
828 else
830 // Select the sort order
831 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
832 $sql_start = $start;
835 // Container for user details, only process once
836 $post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
837 $has_attachments = $display_notice = false;
838 $bbcode_bitfield = '';
839 $i = $i_total = 0;
841 // Go ahead and pull all data for this topic
842 $sql = 'SELECT p.post_id
843 FROM ' . POSTS_TABLE . ' p' . (($sort_by_sql[$sort_key][0] == 'u') ? ', ' . USERS_TABLE . ' u': '') . "
844 WHERE p.topic_id = $topic_id
845 " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . "
846 " . (($sort_by_sql[$sort_key][0] == 'u') ? 'AND u.user_id = p.poster_id': '') . "
847 $limit_posts_time
848 ORDER BY $sql_sort_order";
849 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
851 $i = ($store_reverse) ? $sql_limit - 1 : 0;
852 while ($row = $db->sql_fetchrow($result))
854 $post_list[$i] = $row['post_id'];
855 ($store_reverse) ? $i-- : $i++;
857 $db->sql_freeresult($result);
859 if (!sizeof($post_list))
861 if ($sort_days)
863 trigger_error('NO_POSTS_TIME_FRAME');
865 else
867 trigger_error('NO_TOPIC');
871 // Holding maximum post time for marking topic read
872 // We need to grab it because we do reverse ordering sometimes
873 $max_post_time = 0;
875 $sql = $db->sql_build_query('SELECT', array(
876 'SELECT' => 'u.*, z.friend, z.foe, p.*',
878 'FROM' => array(
879 USERS_TABLE => 'u',
880 POSTS_TABLE => 'p',
883 'LEFT_JOIN' => array(
884 array(
885 'FROM' => array(ZEBRA_TABLE => 'z'),
886 'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
890 'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '
891 AND u.user_id = p.poster_id'
894 $result = $db->sql_query($sql);
896 $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
898 // Posts are stored in the $rowset array while $attach_list, $user_cache
899 // and the global bbcode_bitfield are built
900 while ($row = $db->sql_fetchrow($result))
902 // Set max_post_time
903 if ($row['post_time'] > $max_post_time)
905 $max_post_time = $row['post_time'];
908 $poster_id = $row['poster_id'];
910 // Does post have an attachment? If so, add it to the list
911 if ($row['post_attachment'] && $config['allow_attachments'])
913 $attach_list[] = $row['post_id'];
915 if ($row['post_approved'])
917 $has_attachments = true;
921 $rowset[$row['post_id']] = array(
922 'hide_post' => ($row['foe'] && ($view != 'show' || $post_id != $row['post_id'])) ? true : false,
924 'post_id' => $row['post_id'],
925 'post_time' => $row['post_time'],
926 'user_id' => $row['user_id'],
927 'username' => $row['username'],
928 'user_colour' => $row['user_colour'],
929 'topic_id' => $row['topic_id'],
930 'forum_id' => $row['forum_id'],
931 'post_subject' => $row['post_subject'],
932 'post_edit_count' => $row['post_edit_count'],
933 'post_edit_time' => $row['post_edit_time'],
934 'post_edit_reason' => $row['post_edit_reason'],
935 'post_edit_user' => $row['post_edit_user'],
937 // Make sure the icon actually exists
938 'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0,
939 'post_attachment' => $row['post_attachment'],
940 'post_approved' => $row['post_approved'],
941 'post_reported' => $row['post_reported'],
942 'post_username' => $row['post_username'],
943 'post_text' => $row['post_text'],
944 'bbcode_uid' => $row['bbcode_uid'],
945 'bbcode_bitfield' => $row['bbcode_bitfield'],
946 'enable_smilies' => $row['enable_smilies'],
947 'enable_sig' => $row['enable_sig'],
948 'friend' => $row['friend'],
949 'foe' => $row['foe'],
952 // Define the global bbcode bitfield, will be used to load bbcodes
953 $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
955 // Is a signature attached? Are we going to display it?
956 if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
958 $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
961 // Cache various user specific data ... so we don't have to recompute
962 // this each time the same user appears on this page
963 if (!isset($user_cache[$poster_id]))
965 if ($poster_id == ANONYMOUS)
967 $user_cache[$poster_id] = array(
968 'joined' => '',
969 'posts' => '',
970 'from' => '',
972 'sig' => '',
973 'sig_bbcode_uid' => '',
974 'sig_bbcode_bitfield' => '',
976 'online' => false,
977 'avatar' => '',
978 'rank_title' => '',
979 'rank_image' => '',
980 'rank_image_src' => '',
981 'sig' => '',
982 'posts' => '',
983 'profile' => '',
984 'pm' => '',
985 'email' => '',
986 'www' => '',
987 'icq_status_img' => '',
988 'icq' => '',
989 'aim' => '',
990 'msn' => '',
991 'yim' => '',
992 'jabber' => '',
993 'search' => '',
994 'age' => '',
996 'username' => $row['username'],
997 'user_colour' => $row['user_colour'],
999 'warnings' => 0,
1000 'allow_pm' => 0,
1003 else
1005 $user_sig = '';
1007 // We add the signature to every posters entry because enable_sig is post dependant
1008 if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
1010 $user_sig = $row['user_sig'];
1013 $id_cache[] = $poster_id;
1015 $user_cache[$poster_id] = array(
1016 'joined' => $user->format_date($row['user_regdate']),
1017 'posts' => $row['user_posts'],
1018 'warnings' => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
1019 'from' => (!empty($row['user_from'])) ? $row['user_from'] : '',
1021 'sig' => $user_sig,
1022 'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
1023 'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
1025 'viewonline' => $row['user_allow_viewonline'],
1026 'allow_pm' => $row['user_allow_pm'],
1028 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
1029 'age' => '',
1031 'rank_title' => '',
1032 'rank_image' => '',
1033 'rank_image_src' => '',
1035 'username' => $row['username'],
1036 'user_colour' => $row['user_colour'],
1038 'online' => false,
1039 'profile' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
1040 'www' => $row['user_website'],
1041 'aim' => ($row['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
1042 'msn' => ($row['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
1043 'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&amp;.src=pg' : '',
1044 'jabber' => ($row['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
1045 'search' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($row['username']) .'&amp;showresults=posts') : '',
1048 get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
1050 if (!empty($row['user_allow_viewemail']) || $auth->acl_get('a_email'))
1052 $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']);
1054 else
1056 $user_cache[$poster_id]['email'] = '';
1059 if (!empty($row['user_icq']))
1061 $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $row['user_icq'];
1062 $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
1064 else
1066 $user_cache[$poster_id]['icq_status_img'] = '';
1067 $user_cache[$poster_id]['icq'] = '';
1070 if ($config['allow_birthdays'] && !empty($row['user_birthday']))
1072 list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
1074 if ($bday_year)
1076 $diff = $now['mon'] - $bday_month;
1077 if ($diff == 0)
1079 $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1081 else
1083 $diff = ($diff < 0) ? 1 : 0;
1086 $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
1092 $db->sql_freeresult($result);
1094 // Load custom profile fields
1095 if ($config['load_cpf_viewtopic'])
1097 include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1098 $cp = new custom_profile();
1100 // Grab all profile fields from users in id cache for later use - similar to the poster cache
1101 $profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache);
1104 // Generate online information for user
1105 if ($config['load_onlinetrack'] && sizeof($id_cache))
1107 $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
1108 FROM ' . SESSIONS_TABLE . '
1109 WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
1110 GROUP BY session_user_id';
1111 $result = $db->sql_query($sql);
1113 $update_time = $config['load_online_time'] * 60;
1114 while ($row = $db->sql_fetchrow($result))
1116 $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1118 $db->sql_freeresult($result);
1120 unset($id_cache);
1122 // Pull attachment data
1123 if (sizeof($attach_list))
1125 if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
1127 $sql = 'SELECT *
1128 FROM ' . ATTACHMENTS_TABLE . '
1129 WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
1130 AND in_message = 0
1131 ORDER BY filetime DESC, post_msg_id ASC';
1132 $result = $db->sql_query($sql);
1134 while ($row = $db->sql_fetchrow($result))
1136 $attachments[$row['post_msg_id']][] = $row;
1138 $db->sql_freeresult($result);
1140 // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
1141 if (!sizeof($attachments))
1143 $sql = 'UPDATE ' . POSTS_TABLE . '
1144 SET post_attachment = 0
1145 WHERE ' . $db->sql_in_set('post_id', $attach_list);
1146 $db->sql_query($sql);
1148 // We need to update the topic indicator too if the complete topic is now without an attachment
1149 if (sizeof($rowset) != $total_posts)
1151 // Not all posts are displayed so we query the db to find if there's any attachment for this topic
1152 $sql = 'SELECT a.post_msg_id as post_id
1153 FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p
1154 WHERE p.topic_id = $topic_id
1155 AND p.post_approved = 1
1156 AND p.topic_id = a.topic_id";
1157 $result = $db->sql_query_limit($sql, 1);
1158 $row = $db->sql_fetchrow($result);
1159 $db->sql_freeresult($result);
1161 if (!$row)
1163 $sql = 'UPDATE ' . TOPICS_TABLE . "
1164 SET topic_attachment = 0
1165 WHERE topic_id = $topic_id";
1166 $db->sql_query($sql);
1169 else
1171 $sql = 'UPDATE ' . TOPICS_TABLE . "
1172 SET topic_attachment = 0
1173 WHERE topic_id = $topic_id";
1174 $db->sql_query($sql);
1177 else if ($has_attachments && !$topic_data['topic_attachment'])
1179 // Topic has approved attachments but its flag is wrong
1180 $sql = 'UPDATE ' . TOPICS_TABLE . "
1181 SET topic_attachment = 1
1182 WHERE topic_id = $topic_id";
1183 $db->sql_query($sql);
1185 $topic_data['topic_attachment'] = 1;
1188 else
1190 $display_notice = true;
1194 // Instantiate BBCode if need be
1195 if ($bbcode_bitfield !== '')
1197 $bbcode = new bbcode(base64_encode($bbcode_bitfield));
1200 $i_total = sizeof($rowset) - 1;
1201 $prev_post_id = '';
1203 $template->assign_vars(array(
1204 'S_NUM_POSTS' => sizeof($post_list))
1207 // Output the posts
1208 $first_unread = $post_unread = false;
1209 for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
1211 // A non-existing rowset only happens if there was no user present for the entered poster_id
1212 // This could be a broken posts table.
1213 if (!isset($rowset[$post_list[$i]]))
1215 continue;
1218 $row =& $rowset[$post_list[$i]];
1219 $poster_id = $row['user_id'];
1221 // End signature parsing, only if needed
1222 if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
1224 $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
1226 if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
1228 $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
1231 $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
1232 $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
1233 $user_cache[$poster_id]['sig_parsed'] = true;
1236 // Parse the message and subject
1237 $message = censor_text($row['post_text']);
1239 // Second parse bbcode here
1240 if ($row['bbcode_bitfield'])
1242 $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
1245 $message = bbcode_nl2br($message);
1246 $message = smiley_text($message);
1248 if (!empty($attachments[$row['post_id']]))
1250 parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
1253 // Replace naughty words such as farty pants
1254 $row['post_subject'] = censor_text($row['post_subject']);
1256 // Highlight active words (primarily for search)
1257 if ($highlight_match)
1259 $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message);
1260 $row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $row['post_subject']);
1263 // Editing information
1264 if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason'])
1266 // Get usernames for all following posts if not already stored
1267 if (!sizeof($post_edit_list) && ($row['post_edit_reason'] || ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))))
1269 // Remove all post_ids already parsed (we do not have to check them)
1270 $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i);
1272 $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour
1273 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
1274 WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . '
1275 AND p.post_edit_count <> 0
1276 AND p.post_edit_user <> 0
1277 AND p.post_edit_user = u.user_id';
1278 $result2 = $db->sql_query($sql);
1279 while ($user_edit_row = $db->sql_fetchrow($result2))
1281 $post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
1283 $db->sql_freeresult($result2);
1285 unset($post_storage_list);
1288 $l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
1290 if ($row['post_edit_reason'])
1292 // User having edited the post also being the post author?
1293 if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1295 $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1297 else
1299 $display_username = get_username_string('full', $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour']);
1302 $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1304 else
1306 if ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))
1308 $user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
1311 // User having edited the post also being the post author?
1312 if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1314 $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1316 else
1318 $display_username = get_username_string('full', $row['post_edit_user'], $user_cache[$row['post_edit_user']]['username'], $user_cache[$row['post_edit_user']]['user_colour']);
1321 $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1324 else
1326 $l_edited_by = '';
1329 // Bump information
1330 if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) )
1332 // It is safe to grab the username from the user cache array, we are at the last
1333 // post and only the topic poster and last poster are allowed to bump.
1334 // Admins and mods are bound to the above rules too...
1335 $l_bumped_by = '<br /><br />' . sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_data['topic_bumper']]['username'], $user->format_date($topic_data['topic_last_post_time']));
1337 else
1339 $l_bumped_by = '';
1342 $cp_row = array();
1345 if ($config['load_cpf_viewtopic'])
1347 $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
1350 $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
1352 $s_first_unread = false;
1353 if (!$first_unread && $post_unread)
1355 $s_first_unread = $first_unread = true;
1359 $postrow = array(
1360 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1361 'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1362 'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1363 'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1365 'RANK_TITLE' => $user_cache[$poster_id]['rank_title'],
1366 'RANK_IMG' => $user_cache[$poster_id]['rank_image'],
1367 'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'],
1368 'POSTER_JOINED' => $user_cache[$poster_id]['joined'],
1369 'POSTER_POSTS' => $user_cache[$poster_id]['posts'],
1370 'POSTER_FROM' => $user_cache[$poster_id]['from'],
1371 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'],
1372 'POSTER_WARNINGS' => $user_cache[$poster_id]['warnings'],
1373 'POSTER_AGE' => $user_cache[$poster_id]['age'],
1375 'POST_DATE' => $user->format_date($row['post_time']),
1376 'POST_SUBJECT' => $row['post_subject'],
1377 'MESSAGE' => $message,
1378 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '',
1379 'EDITED_MESSAGE' => $l_edited_by,
1380 'EDIT_REASON' => $row['post_edit_reason'],
1381 'BUMPED_MESSAGE' => $l_bumped_by,
1383 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
1384 'POST_ICON_IMG' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '',
1385 'POST_ICON_IMG_WIDTH' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '',
1386 'POST_ICON_IMG_HEIGHT' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '',
1387 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'],
1388 'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1389 'S_ONLINE' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? false : (($user_cache[$poster_id]['online']) ? true : false),
1391 'U_EDIT' => (!$user->data['is_registered']) ? '' : ((($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f=$forum_id&amp;p={$row['post_id']}") : ''),
1392 'U_QUOTE' => ($auth->acl_get('f_reply', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=quote&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
1393 'U_INFO' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;f=$forum_id&amp;p=" . $row['post_id'], true, $user->session_id) : '',
1394 'U_DELETE' => (!$user->data['is_registered']) ? '' : ((($user->data['user_id'] == $poster_id && $auth->acl_get('f_delete', $forum_id) && $topic_data['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=delete&amp;f=$forum_id&amp;p={$row['post_id']}") : ''),
1396 'U_PROFILE' => $user_cache[$poster_id]['profile'],
1397 'U_SEARCH' => $user_cache[$poster_id]['search'],
1398 'U_PM' => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_cache[$poster_id]['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $row['post_id']) : '',
1399 'U_EMAIL' => $user_cache[$poster_id]['email'],
1400 'U_WWW' => $user_cache[$poster_id]['www'],
1401 'U_ICQ' => $user_cache[$poster_id]['icq'],
1402 'U_AIM' => $user_cache[$poster_id]['aim'],
1403 'U_MSN' => $user_cache[$poster_id]['msn'],
1404 'U_YIM' => $user_cache[$poster_id]['yim'],
1405 'U_JABBER' => $user_cache[$poster_id]['jabber'],
1407 'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '',
1408 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1409 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1410 'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . (($topic_data['topic_type'] == POST_GLOBAL) ? '&amp;f=' . $forum_id : '') . '#p' . $row['post_id'],
1411 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '',
1412 'U_PREV_POST_ID' => $prev_post_id,
1413 'U_NOTES' => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
1414 'U_WARN' => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
1416 'POST_ID' => $row['post_id'],
1417 'POSTER_ID' => $poster_id,
1419 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
1420 'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,
1421 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
1422 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
1423 'S_FRIEND' => ($row['friend']) ? true : false,
1424 'S_UNREAD_POST' => $post_unread,
1425 'S_FIRST_UNREAD' => $s_first_unread,
1426 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1427 'S_TOPIC_POSTER' => ($topic_data['topic_poster'] == $poster_id) ? true : false,
1428 'S_VIEWTOPIC' => true,
1430 'S_IGNORE_POST' => ($row['hide_post']) ? true : false,
1431 'L_IGNORE_POST' => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '<a href="' . $viewtopic_url . "&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}" . '">', '</a>') : '',
1434 if (isset($cp_row['row']) && sizeof($cp_row['row']))
1436 $postrow = array_merge($postrow, $cp_row['row']);
1439 // Dump vars into template
1440 $template->assign_block_vars('postrow', $postrow);
1442 if (!empty($cp_row['blockrow']))
1444 foreach ($cp_row['blockrow'] as $field_data)
1446 $template->assign_block_vars('postrow.custom_fields', $field_data);
1450 // Display not already displayed Attachments for this post, we already parsed them. ;)
1451 if (!empty($attachments[$row['post_id']]))
1453 foreach ($attachments[$row['post_id']] as $attachment)
1455 $template->assign_block_vars('postrow.attachment', array(
1456 'DISPLAY_ATTACHMENT' => $attachment)
1461 $prev_post_id = $row['post_id'];
1463 unset($rowset[$post_list[$i]]);
1464 unset($attachments[$row['post_id']]);
1466 unset($rowset, $user_cache);
1468 // Update topic view and if necessary attachment view counters ... but only if this is the first 'page view'
1469 if (isset($user->data['session_page']) && strpos($user->data['session_page'], '&t=' . $topic_id) === false)
1471 $sql = 'UPDATE ' . TOPICS_TABLE . '
1472 SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
1473 WHERE topic_id = $topic_id";
1474 $db->sql_query($sql);
1476 // Update the attachment download counts
1477 if (sizeof($update_count))
1479 $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
1480 SET download_count = download_count + 1
1481 WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
1482 $db->sql_query($sql);
1486 // Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
1487 if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id])
1489 markread('topic', $forum_id, $topic_id, $max_post_time);
1491 // Update forum info
1492 $all_marked_read = update_forum_tracking_info($forum_id, $topic_data['forum_last_post_time'], (isset($topic_data['forum_mark_time'])) ? $topic_data['forum_mark_time'] : false, false);
1494 else
1496 $all_marked_read = true;
1499 // If there are absolutely no more unread posts in this forum and unread posts shown, we can savely show the #unread link
1500 if ($all_marked_read)
1502 if ($post_unread)
1504 $template->assign_vars(array(
1505 'U_VIEW_UNREAD_POST' => '#unread',
1508 else if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id])
1510 $template->assign_vars(array(
1511 'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
1515 else if (!$all_marked_read)
1517 $last_page = ((floor($start / $config['posts_per_page']) + 1) == max(ceil($total_posts / $config['posts_per_page']), 1)) ? true : false;
1519 // What can happen is that we are at the last displayed page. If so, we also display the #unread link based in $post_unread
1520 if ($last_page && $post_unread)
1522 $template->assign_vars(array(
1523 'U_VIEW_UNREAD_POST' => '#unread',
1526 else if (!$last_page)
1528 $template->assign_vars(array(
1529 'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
1534 // We overwrite $_REQUEST['f'] if there is no forum specified
1535 // to be able to display the correct online list.
1536 // One downside is that the user currently viewing this topic/post is not taken into account.
1537 if (empty($_REQUEST['f']))
1539 $_REQUEST['f'] = $forum_id;
1542 // Output the page
1543 page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_data['topic_title']);
1545 $template->set_filenames(array(
1546 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html')
1548 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
1550 page_footer();