6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 define('IN_PHPBB', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH
: './';
16 $phpEx = substr(strrchr(__FILE__
, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
18 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
19 include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
21 // Start session management
22 $user->session_begin();
23 $auth->acl($user->data
);
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);
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)
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);
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);
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);
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);
132 $user->setup('viewtopic');
133 trigger_error(($view == 'next') ?
'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
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)
166 'SELECT' => 't.*, 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'
210 $sql_array['WHERE'] = "t.topic_id = $topic_id";
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';
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
. ')';
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);
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&t=$topic_id"));
252 trigger_error('NO_TOPIC');
255 // This is for determining where we are (page)
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'];
268 $topic_data['prev_posts'] = 0;
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');
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&t=$topic_id");
339 if ($user->data
['user_id'] == ANONYMOUS
)
341 login_box($redirect_url . "&p=$post_id&e=$jump_to", $user->lang
['LOGIN_NOTIFY_TOPIC']);
346 // We direct the already logged in user to the correct post...
347 redirect($redirect_url . ((!$post_id) ?
"&p=$jump_to" : "&p=$post_id") . "#p$jump_to");
351 // What is start equal to?
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
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']))
408 $total_posts = $topic_replies +
1;
409 $limit_posts_time = '';
412 // Was a highlight request part of the URI?
413 $highlight_match = $highlight = '';
416 foreach (explode(' ', trim($hilit_words)) as $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&t=$topic_id&start=$start&$u_sort_param" . (($highlight_match) ?
"&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);
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);
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);
474 $ranks = $cache->obtain_ranks();
477 $icons = $cache->obtain_icons();
480 $extensions = array();
481 if ($topic_data['topic_attachment'])
483 $extensions = $cache->obtain_attach_extensions($forum_id);
486 // Forum rules listing
488 gen_forum_auth_level('topic', $forum_id, $topic_data['forum_status']);
491 $allow_change_type = ($auth->acl_get('m_', $forum_id) ||
($user->data
['is_registered'] && $user->data
['user_id'] == $topic_data['topic_poster'])) ?
true : false;
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&t=$topic_id&$u_sort_param" . (($highlight_match) ?
"&hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
511 generate_forum_nav($topic_data);
514 generate_forum_rules($topic_data);
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&mode=topic_view&f=$forum_id&t=$topic_id&start=$start&$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&t=$topic_id&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&t=$topic_id&quickmod=1&redirect=" . urlencode(str_replace('&', '&', $viewtopic_url)), true, $user->session_id
),
575 'S_VIEWTOPIC' => true,
576 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ?
true : false,
577 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 't=' . $topic_id),
579 'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST
&& ($auth->acl_get('f_post', $forum_id) ||
$user->data
['user_id'] == ANONYMOUS
)) ?
true : false,
580 'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST
&& ($auth->acl_get('f_reply', $forum_id) ||
$user->data
['user_id'] == ANONYMOUS
)) ?
true : false,
582 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id",
583 'U_FORUM' => $server_path,
584 'U_VIEW_TOPIC' => $viewtopic_url,
585 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
586 'U_VIEW_OLDER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=previous"),
587 'U_VIEW_NEWER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=next"),
588 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ?
$viewtopic_url . '&view=print' : '',
589 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ?
append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&t=$topic_id") : '',
591 'U_WATCH_TOPIC' => $s_watching_topic['link'],
592 'L_WATCH_TOPIC' => $s_watching_topic['title'],
593 'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'],
595 'U_BOOKMARK_TOPIC' => ($user->data
['is_registered'] && $config['allow_bookmarks']) ?
$viewtopic_url . '&bookmark=1' : '',
596 'L_BOOKMARK_TOPIC' => ($user->data
['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ?
$user->lang
['BOOKMARK_TOPIC_REMOVE'] : $user->lang
['BOOKMARK_TOPIC'],
598 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) ||
$user->data
['user_id'] == ANONYMOUS
) ?
append_sid("{$phpbb_root_path}posting.$phpEx", "mode=post&f=$forum_id") : '',
599 '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&f=$forum_id&t=$topic_id") : '',
600 '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&f=$forum_id&t=$topic_id") : '')
603 // Does this topic contain a poll?
604 if (!empty($topic_data['poll_start']))
606 $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
607 FROM ' . POLL_OPTIONS_TABLE
. ' o, ' . POSTS_TABLE
. " p
608 WHERE o.topic_id = $topic_id
609 AND p.post_id = {$topic_data['topic_first_post_id']}
610 AND p.topic_id = o.topic_id
611 ORDER BY o.poll_option_id";
612 $result = $db->sql_query($sql);
614 $poll_info = array();
615 while ($row = $db->sql_fetchrow($result))
619 $db->sql_freeresult($result);
621 $cur_voted_id = array();
622 if ($user->data
['is_registered'])
624 $sql = 'SELECT poll_option_id
625 FROM ' . POLL_VOTES_TABLE
. '
626 WHERE topic_id = ' . $topic_id . '
627 AND vote_user_id = ' . $user->data
['user_id'];
628 $result = $db->sql_query($sql);
630 while ($row = $db->sql_fetchrow($result))
632 $cur_voted_id[] = $row['poll_option_id'];
634 $db->sql_freeresult($result);
638 // Cookie based guest tracking ... I don't like this but hum ho
639 // it's oft requested. This relies on "nice" users who don't feel
640 // the need to delete cookies to mess with results.
641 if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
643 $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
644 $cur_voted_id = array_map('intval', $cur_voted_id);
648 $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
649 ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change'])) &&
650 (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] +
$topic_data['poll_length'] > time()) ||
$topic_data['poll_length'] == 0) &&
651 $topic_data['topic_status'] != ITEM_LOCKED
&&
652 $topic_data['forum_status'] != ITEM_LOCKED
) ?
true : false;
653 $s_display_results = (!$s_can_vote ||
($s_can_vote && sizeof($cur_voted_id)) ||
$view == 'viewpoll') ?
true : false;
655 if ($update && $s_can_vote)
657 if (!sizeof($voted_id) ||
sizeof($voted_id) > $topic_data['poll_max_options'])
659 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start");
661 meta_refresh(5, $redirect_url);
663 $message = (!sizeof($voted_id)) ?
'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS';
664 $message = $user->lang
[$message] . '<br /><br />' . sprintf($user->lang
['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
665 trigger_error($message);
668 foreach ($voted_id as $option)
670 if (in_array($option, $cur_voted_id))
675 $sql = 'UPDATE ' . POLL_OPTIONS_TABLE
. '
676 SET poll_option_total = poll_option_total + 1
677 WHERE poll_option_id = ' . (int) $option . '
678 AND topic_id = ' . (int) $topic_id;
679 $db->sql_query($sql);
681 if ($user->data
['is_registered'])
684 'topic_id' => (int) $topic_id,
685 'poll_option_id' => (int) $option,
686 'vote_user_id' => (int) $user->data
['user_id'],
687 'vote_user_ip' => (string) $user->ip
,
690 $sql = 'INSERT INTO ' . POLL_VOTES_TABLE
. ' ' . $db->sql_build_array('INSERT', $sql_ary);
691 $db->sql_query($sql);
695 foreach ($cur_voted_id as $option)
697 if (!in_array($option, $voted_id))
699 $sql = 'UPDATE ' . POLL_OPTIONS_TABLE
. '
700 SET poll_option_total = poll_option_total - 1
701 WHERE poll_option_id = ' . (int) $option . '
702 AND topic_id = ' . (int) $topic_id;
703 $db->sql_query($sql);
705 if ($user->data
['is_registered'])
707 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE
. '
708 WHERE topic_id = ' . (int) $topic_id . '
709 AND poll_option_id = ' . (int) $option . '
710 AND vote_user_id = ' . (int) $user->data
['user_id'];
711 $db->sql_query($sql);
716 if ($user->data
['user_id'] == ANONYMOUS
&& !$user->data
['is_bot'])
718 $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() +
31536000);
721 $sql = 'UPDATE ' . TOPICS_TABLE
. '
722 SET poll_last_vote = ' . time() . "
723 WHERE topic_id = $topic_id";
724 //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
725 $db->sql_query($sql);
727 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start");
729 meta_refresh(5, $redirect_url);
730 trigger_error($user->lang
['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang
['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
734 foreach ($poll_info as $poll_option)
736 $poll_total +
= $poll_option['poll_option_total'];
739 if ($poll_info[0]['bbcode_bitfield'])
741 $poll_bbcode = new bbcode();
745 $poll_bbcode = false;
748 for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++
)
750 $poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
752 if ($poll_bbcode !== false)
754 $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
757 $poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
758 $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
761 $topic_data['poll_title'] = censor_text($topic_data['poll_title']);
763 if ($poll_bbcode !== false)
765 $poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
768 $topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
769 $topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
773 foreach ($poll_info as $poll_option)
775 $option_pct = ($poll_total > 0) ?
$poll_option['poll_option_total'] / $poll_total : 0;
776 $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100));
778 $template->assign_block_vars('poll_option', array(
779 'POLL_OPTION_ID' => $poll_option['poll_option_id'],
780 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
781 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
782 'POLL_OPTION_PERCENT' => $option_pct_txt,
783 'POLL_OPTION_PCT' => round($option_pct * 100),
784 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
785 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ?
true : false)
789 $poll_end = $topic_data['poll_length'] +
$topic_data['poll_start'];
791 $template->assign_vars(array(
792 'POLL_QUESTION' => $topic_data['poll_title'],
793 'TOTAL_VOTES' => $poll_total,
794 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
795 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
797 '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']),
798 'L_POLL_LENGTH' => ($topic_data['poll_length']) ?
sprintf($user->lang
[($poll_end > time()) ?
'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
800 'S_HAS_POLL' => true,
801 'S_CAN_VOTE' => $s_can_vote,
802 'S_DISPLAY_RESULTS' => $s_display_results,
803 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ?
true : false,
804 'S_POLL_ACTION' => $viewtopic_url,
806 'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll')
809 unset($poll_end, $poll_info, $voted_id);
812 // If the user is trying to reach the second half of the topic, fetch it starting from the end
813 $store_reverse = false;
814 $sql_limit = $config['posts_per_page'];
816 if ($start > $total_posts / 2)
818 $store_reverse = true;
820 if ($start +
$config['posts_per_page'] > $total_posts)
822 $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
825 // Select the sort order
826 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ?
'ASC' : 'DESC');
827 $sql_start = max(0, $total_posts - $sql_limit - $start);
831 // Select the sort order
832 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ?
'DESC' : 'ASC');
836 // Container for user details, only process once
837 $post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
838 $has_attachments = $display_notice = false;
839 $bbcode_bitfield = '';
842 // Go ahead and pull all data for this topic
843 $sql = 'SELECT p.post_id
844 FROM ' . POSTS_TABLE
. ' p' . (($sort_by_sql[$sort_key][0] == 'u') ?
', ' . USERS_TABLE
. ' u': '') . "
845 WHERE p.topic_id = $topic_id
846 " . ((!$auth->acl_get('m_approve', $forum_id)) ?
'AND p.post_approved = 1' : '') . "
847 " . (($sort_by_sql[$sort_key][0] == 'u') ?
'AND u.user_id = p.poster_id': '') . "
849 ORDER BY $sql_sort_order";
850 $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
852 $i = ($store_reverse) ?
$sql_limit - 1 : 0;
853 while ($row = $db->sql_fetchrow($result))
855 $post_list[$i] = $row['post_id'];
856 ($store_reverse) ?
$i-- : $i++
;
858 $db->sql_freeresult($result);
860 if (!sizeof($post_list))
864 trigger_error('NO_POSTS_TIME_FRAME');
868 trigger_error('NO_TOPIC');
872 // Holding maximum post time for marking topic read
873 // We need to grab it because we do reverse ordering sometimes
876 $sql = $db->sql_build_query('SELECT', array(
877 'SELECT' => 'u.*, z.friend, z.foe, p.*',
884 'LEFT_JOIN' => array(
886 'FROM' => array(ZEBRA_TABLE
=> 'z'),
887 'ON' => 'z.user_id = ' . $user->data
['user_id'] . ' AND z.zebra_id = p.poster_id'
891 'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '
892 AND u.user_id = p.poster_id'
895 $result = $db->sql_query($sql);
897 $now = getdate(time() +
$user->timezone +
$user->dst
- date('Z'));
899 // Posts are stored in the $rowset array while $attach_list, $user_cache
900 // and the global bbcode_bitfield are built
901 while ($row = $db->sql_fetchrow($result))
904 if ($row['post_time'] > $max_post_time)
906 $max_post_time = $row['post_time'];
909 $poster_id = $row['poster_id'];
911 // Does post have an attachment? If so, add it to the list
912 if ($row['post_attachment'] && $config['allow_attachments'])
914 $attach_list[] = $row['post_id'];
916 if ($row['post_approved'])
918 $has_attachments = true;
922 $rowset[$row['post_id']] = array(
923 'hide_post' => ($row['foe'] && ($view != 'show' ||
$post_id != $row['post_id'])) ?
true : false,
925 'post_id' => $row['post_id'],
926 'post_time' => $row['post_time'],
927 'user_id' => $row['user_id'],
928 'username' => $row['username'],
929 'user_colour' => $row['user_colour'],
930 'topic_id' => $row['topic_id'],
931 'forum_id' => $row['forum_id'],
932 'post_subject' => $row['post_subject'],
933 'post_edit_count' => $row['post_edit_count'],
934 'post_edit_time' => $row['post_edit_time'],
935 'post_edit_reason' => $row['post_edit_reason'],
936 'post_edit_user' => $row['post_edit_user'],
938 // Make sure the icon actually exists
939 'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ?
$row['icon_id'] : 0,
940 'post_attachment' => $row['post_attachment'],
941 'post_approved' => $row['post_approved'],
942 'post_reported' => $row['post_reported'],
943 'post_username' => $row['post_username'],
944 'post_text' => $row['post_text'],
945 'bbcode_uid' => $row['bbcode_uid'],
946 'bbcode_bitfield' => $row['bbcode_bitfield'],
947 'enable_smilies' => $row['enable_smilies'],
948 'enable_sig' => $row['enable_sig'],
949 'friend' => $row['friend'],
950 'foe' => $row['foe'],
953 // Define the global bbcode bitfield, will be used to load bbcodes
954 $bbcode_bitfield = $bbcode_bitfield |
base64_decode($row['bbcode_bitfield']);
956 // Is a signature attached? Are we going to display it?
957 if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
959 $bbcode_bitfield = $bbcode_bitfield |
base64_decode($row['user_sig_bbcode_bitfield']);
962 // Cache various user specific data ... so we don't have to recompute
963 // this each time the same user appears on this page
964 if (!isset($user_cache[$poster_id]))
966 if ($poster_id == ANONYMOUS
)
968 $user_cache[$poster_id] = array(
974 'sig_bbcode_uid' => '',
975 'sig_bbcode_bitfield' => '',
981 'rank_image_src' => '',
988 'icq_status_img' => '',
997 'username' => $row['username'],
998 'user_colour' => $row['user_colour'],
1008 // We add the signature to every posters entry because enable_sig is post dependant
1009 if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
1011 $user_sig = $row['user_sig'];
1014 $id_cache[] = $poster_id;
1016 $user_cache[$poster_id] = array(
1017 'joined' => $user->format_date($row['user_regdate']),
1018 'posts' => $row['user_posts'],
1019 'warnings' => (isset($row['user_warnings'])) ?
$row['user_warnings'] : 0,
1020 'from' => (!empty($row['user_from'])) ?
$row['user_from'] : '',
1023 'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ?
$row['user_sig_bbcode_uid'] : '',
1024 'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ?
$row['user_sig_bbcode_bitfield'] : '',
1026 'viewonline' => $row['user_allow_viewonline'],
1027 'allow_pm' => $row['user_allow_pm'],
1029 'avatar' => ($user->optionget('viewavatars')) ?
get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
1034 'rank_image_src' => '',
1036 'username' => $row['username'],
1037 'user_colour' => $row['user_colour'],
1040 'profile' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&u=$poster_id"),
1041 'www' => $row['user_website'],
1042 'aim' => ($row['user_aim'] && $auth->acl_get('u_sendim')) ?
append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=aim&u=$poster_id") : '',
1043 'msn' => ($row['user_msnm'] && $auth->acl_get('u_sendim')) ?
append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=msnm&u=$poster_id") : '',
1044 'yim' => ($row['user_yim']) ?
'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&.src=pg' : '',
1045 'jabber' => ($row['user_jabber'] && $auth->acl_get('u_sendim')) ?
append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=jabber&u=$poster_id") : '',
1046 'search' => ($auth->acl_get('u_search')) ?
append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($row['username']) .'&showresults=posts') : '',
1049 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']);
1051 if (!empty($row['user_allow_viewemail']) ||
$auth->acl_get('a_email'))
1053 $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ?
append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ?
'' : 'mailto:' . $row['user_email']);
1057 $user_cache[$poster_id]['email'] = '';
1060 if (!empty($row['user_icq']))
1062 $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $row['user_icq'];
1063 $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&img=5" width="18" height="18" alt="" />';
1067 $user_cache[$poster_id]['icq_status_img'] = '';
1068 $user_cache[$poster_id]['icq'] = '';
1071 if ($config['allow_birthdays'] && !empty($row['user_birthday']))
1073 list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
1077 $diff = $now['mon'] - $bday_month;
1080 $diff = ($now['mday'] - $bday_day < 0) ?
1 : 0;
1084 $diff = ($diff < 0) ?
1 : 0;
1087 $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
1093 $db->sql_freeresult($result);
1095 // Load custom profile fields
1096 if ($config['load_cpf_viewtopic'])
1098 include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1099 $cp = new custom_profile();
1101 // Grab all profile fields from users in id cache for later use - similar to the poster cache
1102 $profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache);
1105 // Generate online information for user
1106 if ($config['load_onlinetrack'] && sizeof($id_cache))
1108 $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
1109 FROM ' . SESSIONS_TABLE
. '
1110 WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
1111 GROUP BY session_user_id';
1112 $result = $db->sql_query($sql);
1114 $update_time = $config['load_online_time'] * 60;
1115 while ($row = $db->sql_fetchrow($result))
1117 $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline']) ||
$auth->acl_get('u_viewonline'))) ?
true : false;
1119 $db->sql_freeresult($result);
1123 // Pull attachment data
1124 if (sizeof($attach_list))
1126 if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
1129 FROM ' . ATTACHMENTS_TABLE
. '
1130 WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
1132 ORDER BY filetime DESC, post_msg_id ASC';
1133 $result = $db->sql_query($sql);
1135 while ($row = $db->sql_fetchrow($result))
1137 $attachments[$row['post_msg_id']][] = $row;
1139 $db->sql_freeresult($result);
1141 // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
1142 if (!sizeof($attachments))
1144 $sql = 'UPDATE ' . POSTS_TABLE
. '
1145 SET post_attachment = 0
1146 WHERE ' . $db->sql_in_set('post_id', $attach_list);
1147 $db->sql_query($sql);
1149 // We need to update the topic indicator too if the complete topic is now without an attachment
1150 if (sizeof($rowset) != $total_posts)
1152 // Not all posts are displayed so we query the db to find if there's any attachment for this topic
1153 $sql = 'SELECT a.post_msg_id as post_id
1154 FROM ' . ATTACHMENTS_TABLE
. ' a, ' . POSTS_TABLE
. " p
1155 WHERE p.topic_id = $topic_id
1156 AND p.post_approved = 1
1157 AND p.topic_id = a.topic_id";
1158 $result = $db->sql_query_limit($sql, 1);
1159 $row = $db->sql_fetchrow($result);
1160 $db->sql_freeresult($result);
1164 $sql = 'UPDATE ' . TOPICS_TABLE
. "
1165 SET topic_attachment = 0
1166 WHERE topic_id = $topic_id";
1167 $db->sql_query($sql);
1172 $sql = 'UPDATE ' . TOPICS_TABLE
. "
1173 SET topic_attachment = 0
1174 WHERE topic_id = $topic_id";
1175 $db->sql_query($sql);
1178 else if ($has_attachments && !$topic_data['topic_attachment'])
1180 // Topic has approved attachments but its flag is wrong
1181 $sql = 'UPDATE ' . TOPICS_TABLE
. "
1182 SET topic_attachment = 1
1183 WHERE topic_id = $topic_id";
1184 $db->sql_query($sql);
1186 $topic_data['topic_attachment'] = 1;
1191 $display_notice = true;
1195 // Instantiate BBCode if need be
1196 if ($bbcode_bitfield !== '')
1198 $bbcode = new bbcode(base64_encode($bbcode_bitfield));
1201 $i_total = sizeof($rowset) - 1;
1204 $template->assign_vars(array(
1205 'S_NUM_POSTS' => sizeof($post_list))
1209 $first_unread = $post_unread = false;
1210 for ($i = 0, $end = sizeof($post_list); $i < $end; ++
$i)
1212 // A non-existing rowset only happens if there was no user present for the entered poster_id
1213 // This could be a broken posts table.
1214 if (!isset($rowset[$post_list[$i]]))
1219 $row =& $rowset[$post_list[$i]];
1220 $poster_id = $row['user_id'];
1222 // End signature parsing, only if needed
1223 if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
1225 $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
1227 if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
1229 $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
1232 $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
1233 $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
1234 $user_cache[$poster_id]['sig_parsed'] = true;
1237 // Parse the message and subject
1238 $message = censor_text($row['post_text']);
1240 // Second parse bbcode here
1241 if ($row['bbcode_bitfield'])
1243 $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
1246 $message = bbcode_nl2br($message);
1247 $message = smiley_text($message);
1249 if (!empty($attachments[$row['post_id']]))
1251 parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
1254 // Replace naughty words such as farty pants
1255 $row['post_subject'] = censor_text($row['post_subject']);
1257 // Highlight active words (primarily for search)
1258 if ($highlight_match)
1260 $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message);
1261 $row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $row['post_subject']);
1264 // Editing information
1265 if (($row['post_edit_count'] && $config['display_last_edited']) ||
$row['post_edit_reason'])
1267 // Get usernames for all following posts if not already stored
1268 if (!sizeof($post_edit_list) && ($row['post_edit_reason'] ||
($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))))
1270 // Remove all post_ids already parsed (we do not have to check them)
1271 $post_storage_list = (!$store_reverse) ?
array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i);
1273 $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour
1274 FROM ' . POSTS_TABLE
. ' p, ' . USERS_TABLE
. ' u
1275 WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . '
1276 AND p.post_edit_count <> 0
1277 AND p.post_edit_user <> 0
1278 AND p.post_edit_user = u.user_id';
1279 $result2 = $db->sql_query($sql);
1280 while ($user_edit_row = $db->sql_fetchrow($result2))
1282 $post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
1284 $db->sql_freeresult($result2);
1286 unset($post_storage_list);
1289 $l_edit_time_total = ($row['post_edit_count'] == 1) ?
$user->lang
['EDITED_TIME_TOTAL'] : $user->lang
['EDITED_TIMES_TOTAL'];
1291 if ($row['post_edit_reason'])
1293 // User having edited the post also being the post author?
1294 if (!$row['post_edit_user'] ||
$row['post_edit_user'] == $poster_id)
1296 $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1300 $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']);
1303 $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1307 if ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))
1309 $user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
1312 // User having edited the post also being the post author?
1313 if (!$row['post_edit_user'] ||
$row['post_edit_user'] == $poster_id)
1315 $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1319 $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']);
1322 $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1331 if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) )
1333 // It is safe to grab the username from the user cache array, we are at the last
1334 // post and only the topic poster and last poster are allowed to bump.
1335 // Admins and mods are bound to the above rules too...
1336 $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']));
1346 if ($config['load_cpf_viewtopic'])
1348 $cp_row = (isset($profile_fields_cache[$poster_id])) ?
$cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
1351 $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ?
true : false;
1353 $s_first_unread = false;
1354 if (!$first_unread && $post_unread)
1356 $s_first_unread = $first_unread = true;
1361 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1362 'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1363 'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1364 'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1366 'RANK_TITLE' => $user_cache[$poster_id]['rank_title'],
1367 'RANK_IMG' => $user_cache[$poster_id]['rank_image'],
1368 'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'],
1369 'POSTER_JOINED' => $user_cache[$poster_id]['joined'],
1370 'POSTER_POSTS' => $user_cache[$poster_id]['posts'],
1371 'POSTER_FROM' => $user_cache[$poster_id]['from'],
1372 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'],
1373 'POSTER_WARNINGS' => $user_cache[$poster_id]['warnings'],
1374 'POSTER_AGE' => $user_cache[$poster_id]['age'],
1376 'POST_DATE' => $user->format_date($row['post_time']),
1377 'POST_SUBJECT' => $row['post_subject'],
1378 'MESSAGE' => $message,
1379 'SIGNATURE' => ($row['enable_sig']) ?
$user_cache[$poster_id]['sig'] : '',
1380 'EDITED_MESSAGE' => $l_edited_by,
1381 'EDIT_REASON' => $row['post_edit_reason'],
1382 'BUMPED_MESSAGE' => $l_bumped_by,
1384 'MINI_POST_IMG' => ($post_unread) ?
$user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
1385 'POST_ICON_IMG' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ?
$icons[$row['icon_id']]['img'] : '',
1386 'POST_ICON_IMG_WIDTH' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ?
$icons[$row['icon_id']]['width'] : '',
1387 'POST_ICON_IMG_HEIGHT' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ?
$icons[$row['icon_id']]['height'] : '',
1388 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'],
1389 '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')),
1390 'S_ONLINE' => ($poster_id == ANONYMOUS ||
!$config['load_onlinetrack']) ?
false : (($user_cache[$poster_id]['online']) ?
true : false),
1392 '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&f=$forum_id&p={$row['post_id']}") : ''),
1393 'U_QUOTE' => ($auth->acl_get('f_reply', $forum_id)) ?
append_sid("{$phpbb_root_path}posting.$phpEx", "mode=quote&f=$forum_id&p={$row['post_id']}") : '',
1394 'U_INFO' => ($auth->acl_get('m_info', $forum_id)) ?
append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=post_details&f=$forum_id&p=" . $row['post_id'], true, $user->session_id
) : '',
1395 '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&f=$forum_id&p={$row['post_id']}") : ''),
1397 'U_PROFILE' => $user_cache[$poster_id]['profile'],
1398 'U_SEARCH' => $user_cache[$poster_id]['search'],
1399 '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&mode=compose&action=quotepost&p=' . $row['post_id']) : '',
1400 'U_EMAIL' => $user_cache[$poster_id]['email'],
1401 'U_WWW' => $user_cache[$poster_id]['www'],
1402 'U_ICQ' => $user_cache[$poster_id]['icq'],
1403 'U_AIM' => $user_cache[$poster_id]['aim'],
1404 'U_MSN' => $user_cache[$poster_id]['msn'],
1405 'U_YIM' => $user_cache[$poster_id]['yim'],
1406 'U_JABBER' => $user_cache[$poster_id]['jabber'],
1408 'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ?
append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $row['post_id']) : '',
1409 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ?
append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id
) : '',
1410 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ?
append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id
) : '',
1411 'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . (($topic_data['topic_type'] == POST_GLOBAL
) ?
'&f=' . $forum_id : '') . '#p' . $row['post_id'],
1412 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i +
1]])) ?
$rowset[$post_list[$i +
1]]['post_id'] : '',
1413 'U_PREV_POST_ID' => $prev_post_id,
1414 'U_NOTES' => ($auth->acl_getf_global('m_')) ?
append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $poster_id, true, $user->session_id
) : '',
1415 '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&mode=warn_post&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id
) : '',
1417 'POST_ID' => $row['post_id'],
1418 'POSTER_ID' => $poster_id,
1420 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ?
true : false,
1421 'S_POST_UNAPPROVED' => ($row['post_approved']) ?
false : true,
1422 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ?
true : false,
1423 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
1424 'S_FRIEND' => ($row['friend']) ?
true : false,
1425 'S_UNREAD_POST' => $post_unread,
1426 'S_FIRST_UNREAD' => $s_first_unread,
1427 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ?
true : false,
1428 'S_TOPIC_POSTER' => ($topic_data['topic_poster'] == $poster_id) ?
true : false,
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 . "&p={$row['post_id']}&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);
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)
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&t=$topic_id&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&t=$topic_id&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;
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);