5
* @version $Id: viewtopic.php,v 1.513 2007/11/06 00:05:53 kellanved Exp $
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);
121
$user->setup('viewtopic');
122
// OK, the topic doesn't exist. This error message is not helpful, but technically correct.
123
trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
127
$sql = 'SELECT topic_id, forum_id
128
FROM ' . TOPICS_TABLE . '
129
WHERE forum_id = ' . $row['forum_id'] . "
130
AND topic_moved_id = 0
131
AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
132
" . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
133
ORDER BY topic_last_post_time $sql_ordering";
134
$result = $db->sql_query_limit($sql, 1);
135
$row = $db->sql_fetchrow($result);
136
$db->sql_freeresult($result);
140
$user->setup('viewtopic');
141
trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
145
$topic_id = $row['topic_id'];
147
// Check for global announcement correctness?
148
if (!$row['forum_id'] && !$forum_id)
150
trigger_error('NO_TOPIC');
152
else if ($row['forum_id'])
154
$forum_id = $row['forum_id'];
160
// Check for global announcement correctness?
161
if ((!isset($row) || !$row['forum_id']) && !$forum_id)
163
trigger_error('NO_TOPIC');
165
else if (isset($row) && $row['forum_id'])
167
$forum_id = $row['forum_id'];
171
// This rather complex gaggle of code handles querying for topics but
172
// also allows for direct linking to a post (and the calculation of which
173
// page the post is on and the correct display of viewtopic)
175
'SELECT' => 't.*, f.*',
182
if ($user->data['is_registered'])
184
$sql_array['SELECT'] .= ', tw.notify_status';
185
$sql_array['LEFT_JOIN'] = array();
187
$sql_array['LEFT_JOIN'][] = array(
188
'FROM' => array(TOPICS_WATCH_TABLE => 'tw'),
189
'ON' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
192
if ($config['allow_bookmarks'])
194
$sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
195
$sql_array['LEFT_JOIN'][] = array(
196
'FROM' => array(BOOKMARKS_TABLE => 'bm'),
197
'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'
201
if ($config['load_db_lastread'])
203
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
205
$sql_array['LEFT_JOIN'][] = array(
206
'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
207
'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
210
$sql_array['LEFT_JOIN'][] = array(
211
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
212
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
219
$sql_array['WHERE'] = "t.topic_id = $topic_id";
223
$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' : '');
224
$sql_array['FROM'][POSTS_TABLE] = 'p';
227
$sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
231
// If it is a global announcement make sure to set the forum id to a postable forum
232
$sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
233
AND f.forum_type = ' . FORUM_POST . ')';
237
$sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
238
AND f.forum_id = $forum_id)";
241
$sql_array['WHERE'] .= ')';
242
$sql_array['FROM'][TOPICS_TABLE] = 't';
244
// Join to forum table on topic forum_id unless topic forum_id is zero
245
// whereupon we join on the forum_id passed as a parameter ... this
246
// is done so navigation, forum name, etc. remain consistent with where
247
// user clicked to view a global topic
248
$sql = $db->sql_build_query('SELECT', $sql_array);
249
$result = $db->sql_query($sql);
250
$topic_data = $db->sql_fetchrow($result);
251
$db->sql_freeresult($result);
255
// If post_id was submitted, we try at least to display the topic as a last resort...
256
if ($post_id && $forum_id && $topic_id)
258
redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"));
261
trigger_error('NO_TOPIC');
264
// This is for determining where we are (page)
267
if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
269
$check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
271
if ($sort_dir == $check_sort)
273
$topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
277
$topic_data['prev_posts'] = 0;
282
$sql = 'SELECT COUNT(p1.post_id) AS prev_posts
283
FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
284
WHERE p1.topic_id = {$topic_data['topic_id']}
285
AND p2.post_id = {$post_id}
286
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
287
AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');
289
$result = $db->sql_query($sql);
290
$row = $db->sql_fetchrow($result);
291
$db->sql_freeresult($result);
293
$topic_data['prev_posts'] = $row['prev_posts'] - 1;
297
$forum_id = (int) $topic_data['forum_id'];
298
$topic_id = (int) $topic_data['topic_id'];
301
$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
303
// Check sticky/announcement time limit
304
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())
306
$sql = 'UPDATE ' . TOPICS_TABLE . '
307
SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0
308
WHERE topic_id = ' . $topic_id;
309
$db->sql_query($sql);
311
$topic_data['topic_type'] = POST_NORMAL;
312
$topic_data['topic_time_limit'] = 0;
315
// Setup look and feel
316
$user->setup('viewtopic', $topic_data['forum_style']);
318
if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
320
trigger_error('NO_TOPIC');
324
if (!$auth->acl_get('f_read', $forum_id))
326
if ($user->data['user_id'] != ANONYMOUS)
328
trigger_error('SORRY_AUTH_READ');
331
login_box('', $user->lang['LOGIN_VIEWFORUM']);
334
// Forum is passworded ... check whether access has been granted to this
335
// user this session, if not show login box
336
if ($topic_data['forum_password'])
338
login_forum_box($topic_data);
341
// Redirect to login or to the correct post upon emailed notification links
342
if (isset($_GET['e']))
344
$jump_to = request_var('e', 0);
346
$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
348
if ($user->data['user_id'] == ANONYMOUS)
350
login_box($redirect_url . "&p=$post_id&e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']);
355
// We direct the already logged in user to the correct post...
356
redirect($redirect_url . ((!$post_id) ? "&p=$jump_to" : "&p=$post_id") . "#p$jump_to");
360
// What is start equal to?
363
$start = floor(($topic_data['prev_posts']) / $config['posts_per_page']) * $config['posts_per_page'];
366
// Get topic tracking info
367
if (!isset($topic_tracking_info))
369
$topic_tracking_info = array();
371
// Get topic tracking info
372
if ($config['load_db_lastread'] && $user->data['is_registered'])
374
$tmp_topic_data = array($topic_id => $topic_data);
375
$topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time']));
376
unset($tmp_topic_data);
378
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
380
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
384
// Post ordering options
385
$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']);
387
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
388
$sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
390
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
391
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);
393
// Obtain correct post count and ordering SQL if user has
394
// requested anything different
397
$min_post_time = time() - ($sort_days * 86400);
399
$sql = 'SELECT COUNT(post_id) AS num_posts
400
FROM ' . POSTS_TABLE . "
401
WHERE topic_id = $topic_id
402
AND post_time >= $min_post_time
403
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1');
404
$result = $db->sql_query($sql);
405
$total_posts = (int) $db->sql_fetchfield('num_posts');
406
$db->sql_freeresult($result);
408
$limit_posts_time = "AND p.post_time >= $min_post_time ";
410
if (isset($_POST['sort']))
417
$total_posts = $topic_replies + 1;
418
$limit_posts_time = '';
421
// Was a highlight request part of the URI?
422
$highlight_match = $highlight = '';
425
foreach (explode(' ', trim($hilit_words)) as $word)
429
$word = str_replace('\*', '\w+?', preg_quote($word, '#'));
430
$word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word);
431
$highlight_match .= (($highlight_match != '') ? '|' : '') . $word;
435
$highlight = urlencode($hilit_words);
438
// Make sure $start is set to the last page if it exceeds the amount
439
if ($start < 0 || $start > $total_posts)
441
$start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
444
// General Viewtopic URL for return links
445
$viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start&$u_sort_param" . (($highlight_match) ? "&hilit=$highlight" : ''));
447
// Are we watching this topic?
448
$s_watching_topic = $s_watching_topic_img = array();
449
$s_watching_topic['link'] = $s_watching_topic['title'] = '';
450
$s_watching_topic['is_watching'] = false;
452
if ($config['email_enable'] && $config['allow_topic_notify'] && $user->data['is_registered'])
454
watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $forum_id, $topic_id, $topic_data['notify_status'], $start);
458
if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0))
460
if (!$topic_data['bookmarked'])
462
$sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
463
'user_id' => $user->data['user_id'],
464
'topic_id' => $topic_id,
466
$db->sql_query($sql);
470
$sql = 'DELETE FROM ' . BOOKMARKS_TABLE . "
471
WHERE user_id = {$user->data['user_id']}
472
AND topic_id = $topic_id";
473
$db->sql_query($sql);
476
meta_refresh(3, $viewtopic_url);
478
$message = (($topic_data['bookmarked']) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
479
trigger_error($message);
483
$ranks = $cache->obtain_ranks();
486
$icons = $cache->obtain_icons();
489
$extensions = array();
490
if ($topic_data['topic_attachment'])
492
$extensions = $cache->obtain_attach_extensions($forum_id);
495
// Forum rules listing
497
gen_forum_auth_level('topic', $forum_id, $topic_data['forum_status']);
500
$allow_change_type = ($auth->acl_get('m_', $forum_id) || ($user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'])) ? true : false;
503
$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>') : '';
504
$topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : '';
505
$topic_mod .= ($auth->acl_get('m_move', $forum_id) && $topic_data['topic_status'] != ITEM_MOVED) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : '';
506
$topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : '';
507
$topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_POSTS'] . '</option>' : '';
508
$topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge_topic">' . $user->lang['MERGE_TOPIC'] . '</option>' : '';
509
$topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : '';
510
$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>' : '';
511
$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>' : '';
512
$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>' : '';
513
$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>' : '';
514
$topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="topic_logs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : '';
516
// If we've got a hightlight set pass it on to pagination.
517
$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);
520
generate_forum_nav($topic_data);
523
generate_forum_rules($topic_data);
526
$forum_moderators = array();
527
get_moderators($forum_moderators, $forum_id);
529
// This is only used for print view so ...
530
$server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';
532
// Replace naughty words in title
533
$topic_data['topic_title'] = censor_text($topic_data['topic_title']);
535
// Send vars to template
536
$template->assign_vars(array(
537
'FORUM_ID' => $forum_id,
538
'FORUM_NAME' => $topic_data['forum_name'],
539
'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']),
540
'TOPIC_ID' => $topic_id,
541
'TOPIC_TITLE' => $topic_data['topic_title'],
542
'TOPIC_POSTER' => $topic_data['topic_poster'],
544
'TOPIC_AUTHOR_FULL' => get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
545
'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
546
'TOPIC_AUTHOR' => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
548
'PAGINATION' => $pagination,
549
'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start),
550
'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts),
551
'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) : '',
552
'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '',
554
'POST_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'),
555
'QUOTE_IMG' => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
556
'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'),
557
'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_POST'),
558
'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_POST'),
559
'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'),
560
'PROFILE_IMG' => $user->img('icon_user_profile', 'READ_PROFILE'),
561
'SEARCH_IMG' => $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
562
'PM_IMG' => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
563
'EMAIL_IMG' => $user->img('icon_contact_email', 'SEND_EMAIL'),
564
'WWW_IMG' => $user->img('icon_contact_www', 'VISIT_WEBSITE'),
565
'ICQ_IMG' => $user->img('icon_contact_icq', 'ICQ'),
566
'AIM_IMG' => $user->img('icon_contact_aim', 'AIM'),
567
'MSN_IMG' => $user->img('icon_contact_msnm', 'MSNM'),
568
'YIM_IMG' => $user->img('icon_contact_yahoo', 'YIM'),
569
'JABBER_IMG' => $user->img('icon_contact_jabber', 'JABBER') ,
570
'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_POST'),
571
'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'),
572
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
573
'WARN_IMG' => $user->img('icon_user_warn', 'WARN_USER'),
575
'S_IS_LOCKED' =>($topic_data['topic_status'] == ITEM_UNLOCKED) ? false : true,
576
'S_SELECT_SORT_DIR' => $s_sort_dir,
577
'S_SELECT_SORT_KEY' => $s_sort_key,
578
'S_SELECT_SORT_DAYS' => $s_limit_days,
579
'S_SINGLE_MODERATOR' => (!empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1) ? false : true,
580
'S_TOPIC_ACTION' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start"),
581
'S_TOPIC_MOD' => ($topic_mod != '') ? '<select name="action">' . $topic_mod . '</select>' : '',
582
'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),
584
'S_VIEWTOPIC' => true,
585
'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
586
'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 't=' . $topic_id),
588
'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
589
'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
591
'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id",
592
'U_FORUM' => $server_path,
593
'U_VIEW_TOPIC' => $viewtopic_url,
594
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
595
'U_VIEW_OLDER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=previous"),
596
'U_VIEW_NEWER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=next"),
597
'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&view=print' : '',
598
'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") : '',
600
'U_WATCH_TOPIC' => $s_watching_topic['link'],
601
'L_WATCH_TOPIC' => $s_watching_topic['title'],
602
'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'],
604
'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&bookmark=1' : '',
605
'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
607
'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") : '',
608
'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") : '',
609
'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") : '')
612
// Does this topic contain a poll?
613
if (!empty($topic_data['poll_start']))
615
$sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
616
FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p
617
WHERE o.topic_id = $topic_id
618
AND p.post_id = {$topic_data['topic_first_post_id']}
619
AND p.topic_id = o.topic_id
620
ORDER BY o.poll_option_id";
621
$result = $db->sql_query($sql);
623
$poll_info = array();
624
while ($row = $db->sql_fetchrow($result))
628
$db->sql_freeresult($result);
630
$cur_voted_id = array();
631
if ($user->data['is_registered'])
633
$sql = 'SELECT poll_option_id
634
FROM ' . POLL_VOTES_TABLE . '
635
WHERE topic_id = ' . $topic_id . '
636
AND vote_user_id = ' . $user->data['user_id'];
637
$result = $db->sql_query($sql);
639
while ($row = $db->sql_fetchrow($result))
641
$cur_voted_id[] = $row['poll_option_id'];
643
$db->sql_freeresult($result);
647
// Cookie based guest tracking ... I don't like this but hum ho
648
// it's oft requested. This relies on "nice" users who don't feel
649
// the need to delete cookies to mess with results.
650
if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
652
$cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
653
$cur_voted_id = array_map('intval', $cur_voted_id);
657
$s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
658
($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change'])) &&
659
(($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
660
$topic_data['topic_status'] != ITEM_LOCKED &&
661
$topic_data['forum_status'] != ITEM_LOCKED) ? true : false;
662
$s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false;
664
if ($update && $s_can_vote)
667
if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id))
669
$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start");
671
meta_refresh(5, $redirect_url);
672
if (!sizeof($voted_id))
674
$message = 'NO_VOTE_OPTION';
676
else if (sizeof($voted_id) > $topic_data['poll_max_options'])
678
$message = 'TOO_MANY_VOTE_OPTIONS';
682
$message = 'VOTE_CONVERTED';
685
$message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
686
trigger_error($message);
689
foreach ($voted_id as $option)
691
if (in_array($option, $cur_voted_id))
696
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
697
SET poll_option_total = poll_option_total + 1
698
WHERE poll_option_id = ' . (int) $option . '
699
AND topic_id = ' . (int) $topic_id;
700
$db->sql_query($sql);
702
if ($user->data['is_registered'])
705
'topic_id' => (int) $topic_id,
706
'poll_option_id' => (int) $option,
707
'vote_user_id' => (int) $user->data['user_id'],
708
'vote_user_ip' => (string) $user->ip,
711
$sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
712
$db->sql_query($sql);
716
foreach ($cur_voted_id as $option)
718
if (!in_array($option, $voted_id))
720
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
721
SET poll_option_total = poll_option_total - 1
722
WHERE poll_option_id = ' . (int) $option . '
723
AND topic_id = ' . (int) $topic_id;
724
$db->sql_query($sql);
726
if ($user->data['is_registered'])
728
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
729
WHERE topic_id = ' . (int) $topic_id . '
730
AND poll_option_id = ' . (int) $option . '
731
AND vote_user_id = ' . (int) $user->data['user_id'];
732
$db->sql_query($sql);
737
if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
739
$user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
742
$sql = 'UPDATE ' . TOPICS_TABLE . '
743
SET poll_last_vote = ' . time() . "
744
WHERE topic_id = $topic_id";
745
//, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
746
$db->sql_query($sql);
748
$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start");
750
meta_refresh(5, $redirect_url);
751
trigger_error($user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
755
foreach ($poll_info as $poll_option)
757
$poll_total += $poll_option['poll_option_total'];
760
if ($poll_info[0]['bbcode_bitfield'])
762
$poll_bbcode = new bbcode();
766
$poll_bbcode = false;
769
for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
771
$poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
773
if ($poll_bbcode !== false)
775
$poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
778
$poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
779
$poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
782
$topic_data['poll_title'] = censor_text($topic_data['poll_title']);
784
if ($poll_bbcode !== false)
786
$poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
789
$topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
790
$topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
794
foreach ($poll_info as $poll_option)
796
$option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
797
$option_pct_txt = sprintf("%.1d%%", ($option_pct * 100));
799
$template->assign_block_vars('poll_option', array(
800
'POLL_OPTION_ID' => $poll_option['poll_option_id'],
801
'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
802
'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
803
'POLL_OPTION_PERCENT' => $option_pct_txt,
804
'POLL_OPTION_PCT' => round($option_pct * 100),
805
'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
806
'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
810
$poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
812
$template->assign_vars(array(
813
'POLL_QUESTION' => $topic_data['poll_title'],
814
'TOTAL_VOTES' => $poll_total,
815
'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
816
'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
818
'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']),
819
'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
821
'S_HAS_POLL' => true,
822
'S_CAN_VOTE' => $s_can_vote,
823
'S_DISPLAY_RESULTS' => $s_display_results,
824
'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false,
825
'S_POLL_ACTION' => $viewtopic_url,
827
'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll')
830
unset($poll_end, $poll_info, $voted_id);
833
// If the user is trying to reach the second half of the topic, fetch it starting from the end
834
$store_reverse = false;
835
$sql_limit = $config['posts_per_page'];
837
if ($start > $total_posts / 2)
839
$store_reverse = true;
841
if ($start + $config['posts_per_page'] > $total_posts)
843
$sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
846
// Select the sort order
847
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
848
$sql_start = max(0, $total_posts - $sql_limit - $start);
852
// Select the sort order
853
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
857
// Container for user details, only process once
858
$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
859
$has_attachments = $display_notice = false;
860
$bbcode_bitfield = '';
863
// Go ahead and pull all data for this topic
864
$sql = 'SELECT p.post_id
865
FROM ' . POSTS_TABLE . ' p' . (($sort_by_sql[$sort_key][0] == 'u') ? ', ' . USERS_TABLE . ' u': '') . "
866
WHERE p.topic_id = $topic_id
867
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . "
868
" . (($sort_by_sql[$sort_key][0] == 'u') ? 'AND u.user_id = p.poster_id': '') . "
870
ORDER BY $sql_sort_order";
871
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
873
$i = ($store_reverse) ? $sql_limit - 1 : 0;
874
while ($row = $db->sql_fetchrow($result))
876
$post_list[$i] = $row['post_id'];
877
($store_reverse) ? $i-- : $i++;
879
$db->sql_freeresult($result);
881
if (!sizeof($post_list))
885
trigger_error('NO_POSTS_TIME_FRAME');
889
trigger_error('NO_TOPIC');
893
// Holding maximum post time for marking topic read
894
// We need to grab it because we do reverse ordering sometimes
897
$sql = $db->sql_build_query('SELECT', array(
898
'SELECT' => 'u.*, z.friend, z.foe, p.*',
905
'LEFT_JOIN' => array(
907
'FROM' => array(ZEBRA_TABLE => 'z'),
908
'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
912
'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '
913
AND u.user_id = p.poster_id'
916
$result = $db->sql_query($sql);
918
$now = getdate(time() + $user->timezone + $user->dst - date('Z'));
920
// Posts are stored in the $rowset array while $attach_list, $user_cache
921
// and the global bbcode_bitfield are built
922
while ($row = $db->sql_fetchrow($result))
925
if ($row['post_time'] > $max_post_time)
927
$max_post_time = $row['post_time'];
930
$poster_id = $row['poster_id'];
932
// Does post have an attachment? If so, add it to the list
933
if ($row['post_attachment'] && $config['allow_attachments'])
935
$attach_list[] = $row['post_id'];
937
if ($row['post_approved'])
939
$has_attachments = true;
943
$rowset[$row['post_id']] = array(
944
'hide_post' => ($row['foe'] && ($view != 'show' || $post_id != $row['post_id'])) ? true : false,
946
'post_id' => $row['post_id'],
947
'post_time' => $row['post_time'],
948
'user_id' => $row['user_id'],
949
'username' => $row['username'],
950
'user_colour' => $row['user_colour'],
951
'topic_id' => $row['topic_id'],
952
'forum_id' => $row['forum_id'],
953
'post_subject' => $row['post_subject'],
954
'post_edit_count' => $row['post_edit_count'],
955
'post_edit_time' => $row['post_edit_time'],
956
'post_edit_reason' => $row['post_edit_reason'],
957
'post_edit_user' => $row['post_edit_user'],
959
// Make sure the icon actually exists
960
'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0,
961
'post_attachment' => $row['post_attachment'],
962
'post_approved' => $row['post_approved'],
963
'post_reported' => $row['post_reported'],
964
'post_username' => $row['post_username'],
965
'post_text' => $row['post_text'],
966
'bbcode_uid' => $row['bbcode_uid'],
967
'bbcode_bitfield' => $row['bbcode_bitfield'],
968
'enable_smilies' => $row['enable_smilies'],
969
'enable_sig' => $row['enable_sig'],
970
'friend' => $row['friend'],
971
'foe' => $row['foe'],
974
// Define the global bbcode bitfield, will be used to load bbcodes
975
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
977
// Is a signature attached? Are we going to display it?
978
if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
980
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
983
// Cache various user specific data ... so we don't have to recompute
984
// this each time the same user appears on this page
985
if (!isset($user_cache[$poster_id]))
987
if ($poster_id == ANONYMOUS)
989
$user_cache[$poster_id] = array(
995
'sig_bbcode_uid' => '',
996
'sig_bbcode_bitfield' => '',
1002
'rank_image_src' => '',
1009
'icq_status_img' => '',
1018
'username' => $row['username'],
1019
'user_colour' => $row['user_colour'],
1029
// We add the signature to every posters entry because enable_sig is post dependant
1030
if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
1032
$user_sig = $row['user_sig'];
1035
$id_cache[] = $poster_id;
1037
$user_cache[$poster_id] = array(
1038
'joined' => $user->format_date($row['user_regdate']),
1039
'posts' => $row['user_posts'],
1040
'warnings' => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
1041
'from' => (!empty($row['user_from'])) ? $row['user_from'] : '',
1044
'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
1045
'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
1047
'viewonline' => $row['user_allow_viewonline'],
1048
'allow_pm' => $row['user_allow_pm'],
1050
'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
1055
'rank_image_src' => '',
1057
'username' => $row['username'],
1058
'user_colour' => $row['user_colour'],
1061
'profile' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&u=$poster_id"),
1062
'www' => $row['user_website'],
1063
'aim' => ($row['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=aim&u=$poster_id") : '',
1064
'msn' => ($row['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=msnm&u=$poster_id") : '',
1065
'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&.src=pg' : '',
1066
'jabber' => ($row['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=jabber&u=$poster_id") : '',
1067
'search' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($row['username']) .'&showresults=posts') : '',
1070
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']);
1072
if (!empty($row['user_allow_viewemail']) || $auth->acl_get('a_email'))
1074
$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']);
1078
$user_cache[$poster_id]['email'] = '';
1081
if (!empty($row['user_icq']))
1083
$user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $row['user_icq'];
1084
$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="" />';
1088
$user_cache[$poster_id]['icq_status_img'] = '';
1089
$user_cache[$poster_id]['icq'] = '';
1092
if ($config['allow_birthdays'] && !empty($row['user_birthday']))
1094
list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
1098
$diff = $now['mon'] - $bday_month;
1101
$diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1105
$diff = ($diff < 0) ? 1 : 0;
1108
$user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
1114
$db->sql_freeresult($result);
1116
// Load custom profile fields
1117
if ($config['load_cpf_viewtopic'])
1119
include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1120
$cp = new custom_profile();
1122
// Grab all profile fields from users in id cache for later use - similar to the poster cache
1123
$profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache);
1126
// Generate online information for user
1127
if ($config['load_onlinetrack'] && sizeof($id_cache))
1129
$sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
1130
FROM ' . SESSIONS_TABLE . '
1131
WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
1132
GROUP BY session_user_id';
1133
$result = $db->sql_query($sql);
1135
$update_time = $config['load_online_time'] * 60;
1136
while ($row = $db->sql_fetchrow($result))
1138
$user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1140
$db->sql_freeresult($result);
1144
// Pull attachment data
1145
if (sizeof($attach_list))
1147
if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
1150
FROM ' . ATTACHMENTS_TABLE . '
1151
WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
1153
ORDER BY filetime DESC, post_msg_id ASC';
1154
$result = $db->sql_query($sql);
1156
while ($row = $db->sql_fetchrow($result))
1158
$attachments[$row['post_msg_id']][] = $row;
1160
$db->sql_freeresult($result);
1162
// No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
1163
if (!sizeof($attachments))
1165
$sql = 'UPDATE ' . POSTS_TABLE . '
1166
SET post_attachment = 0
1167
WHERE ' . $db->sql_in_set('post_id', $attach_list);
1168
$db->sql_query($sql);
1170
// We need to update the topic indicator too if the complete topic is now without an attachment
1171
if (sizeof($rowset) != $total_posts)
1173
// Not all posts are displayed so we query the db to find if there's any attachment for this topic
1174
$sql = 'SELECT a.post_msg_id as post_id
1175
FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p
1176
WHERE p.topic_id = $topic_id
1177
AND p.post_approved = 1
1178
AND p.topic_id = a.topic_id";
1179
$result = $db->sql_query_limit($sql, 1);
1180
$row = $db->sql_fetchrow($result);
1181
$db->sql_freeresult($result);
1185
$sql = 'UPDATE ' . TOPICS_TABLE . "
1186
SET topic_attachment = 0
1187
WHERE topic_id = $topic_id";
1188
$db->sql_query($sql);
1193
$sql = 'UPDATE ' . TOPICS_TABLE . "
1194
SET topic_attachment = 0
1195
WHERE topic_id = $topic_id";
1196
$db->sql_query($sql);
1199
else if ($has_attachments && !$topic_data['topic_attachment'])
1201
// Topic has approved attachments but its flag is wrong
1202
$sql = 'UPDATE ' . TOPICS_TABLE . "
1203
SET topic_attachment = 1
1204
WHERE topic_id = $topic_id";
1205
$db->sql_query($sql);
1207
$topic_data['topic_attachment'] = 1;
1212
$display_notice = true;
1216
// Instantiate BBCode if need be
1217
if ($bbcode_bitfield !== '')
1219
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
1222
$i_total = sizeof($rowset) - 1;
1225
$template->assign_vars(array(
1226
'S_NUM_POSTS' => sizeof($post_list))
1230
$first_unread = $post_unread = false;
1231
for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
1233
// A non-existing rowset only happens if there was no user present for the entered poster_id
1234
// This could be a broken posts table.
1235
if (!isset($rowset[$post_list[$i]]))
1240
$row =& $rowset[$post_list[$i]];
1241
$poster_id = $row['user_id'];
1243
// End signature parsing, only if needed
1244
if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
1246
$user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
1248
if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
1250
$bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
1253
$user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
1254
$user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
1255
$user_cache[$poster_id]['sig_parsed'] = true;
1258
// Parse the message and subject
1259
$message = censor_text($row['post_text']);
1261
// Second parse bbcode here
1262
if ($row['bbcode_bitfield'])
1264
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
1267
$message = bbcode_nl2br($message);
1268
$message = smiley_text($message);
1270
if (!empty($attachments[$row['post_id']]))
1272
parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
1275
// Replace naughty words such as farty pants
1276
$row['post_subject'] = censor_text($row['post_subject']);
1278
// Highlight active words (primarily for search)
1279
if ($highlight_match)
1281
$message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message);
1282
$row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $row['post_subject']);
1285
// Editing information
1286
if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason'])
1288
// Get usernames for all following posts if not already stored
1289
if (!sizeof($post_edit_list) && ($row['post_edit_reason'] || ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))))
1291
// Remove all post_ids already parsed (we do not have to check them)
1292
$post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i);
1294
$sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour
1295
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
1296
WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . '
1297
AND p.post_edit_count <> 0
1298
AND p.post_edit_user <> 0
1299
AND p.post_edit_user = u.user_id';
1300
$result2 = $db->sql_query($sql);
1301
while ($user_edit_row = $db->sql_fetchrow($result2))
1303
$post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
1305
$db->sql_freeresult($result2);
1307
unset($post_storage_list);
1310
$l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
1312
if ($row['post_edit_reason'])
1314
// User having edited the post also being the post author?
1315
if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1317
$display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1321
$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']);
1324
$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1328
if ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))
1330
$user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
1333
// User having edited the post also being the post author?
1334
if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
1336
$display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
1340
$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']);
1343
$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time']), $row['post_edit_count']);
1352
if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) )
1354
// It is safe to grab the username from the user cache array, we are at the last
1355
// post and only the topic poster and last poster are allowed to bump.
1356
// Admins and mods are bound to the above rules too...
1357
$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']));
1367
if ($config['load_cpf_viewtopic'])
1369
$cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
1372
$post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
1374
$s_first_unread = false;
1375
if (!$first_unread && $post_unread)
1377
$s_first_unread = $first_unread = true;
1382
'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1383
'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1384
'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1385
'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
1387
'RANK_TITLE' => $user_cache[$poster_id]['rank_title'],
1388
'RANK_IMG' => $user_cache[$poster_id]['rank_image'],
1389
'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'],
1390
'POSTER_JOINED' => $user_cache[$poster_id]['joined'],
1391
'POSTER_POSTS' => $user_cache[$poster_id]['posts'],
1392
'POSTER_FROM' => $user_cache[$poster_id]['from'],
1393
'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'],
1394
'POSTER_WARNINGS' => $user_cache[$poster_id]['warnings'],
1395
'POSTER_AGE' => $user_cache[$poster_id]['age'],
1397
'POST_DATE' => $user->format_date($row['post_time']),
1398
'POST_SUBJECT' => $row['post_subject'],
1399
'MESSAGE' => $message,
1400
'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '',
1401
'EDITED_MESSAGE' => $l_edited_by,
1402
'EDIT_REASON' => $row['post_edit_reason'],
1403
'BUMPED_MESSAGE' => $l_bumped_by,
1405
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
1406
'POST_ICON_IMG' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '',
1407
'POST_ICON_IMG_WIDTH' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '',
1408
'POST_ICON_IMG_HEIGHT' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '',
1409
'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'],
1410
'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')),
1411
'S_ONLINE' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? false : (($user_cache[$poster_id]['online']) ? true : false),
1413
'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']}") : ''),
1414
'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']}") : '',
1415
'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) : '',
1416
'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']}") : ''),
1418
'U_PROFILE' => $user_cache[$poster_id]['profile'],
1419
'U_SEARCH' => $user_cache[$poster_id]['search'],
1420
'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']) : '',
1421
'U_EMAIL' => $user_cache[$poster_id]['email'],
1422
'U_WWW' => $user_cache[$poster_id]['www'],
1423
'U_ICQ' => $user_cache[$poster_id]['icq'],
1424
'U_AIM' => $user_cache[$poster_id]['aim'],
1425
'U_MSN' => $user_cache[$poster_id]['msn'],
1426
'U_YIM' => $user_cache[$poster_id]['yim'],
1427
'U_JABBER' => $user_cache[$poster_id]['jabber'],
1429
'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $row['post_id']) : '',
1430
'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) : '',
1431
'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) : '',
1432
'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'],
1433
'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '',
1434
'U_PREV_POST_ID' => $prev_post_id,
1435
'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) : '',
1436
'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) : '',
1438
'POST_ID' => $row['post_id'],
1439
'POSTER_ID' => $poster_id,
1441
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
1442
'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,
1443
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
1444
'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
1445
'S_FRIEND' => ($row['friend']) ? true : false,
1446
'S_UNREAD_POST' => $post_unread,
1447
'S_FIRST_UNREAD' => $s_first_unread,
1448
'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1449
'S_TOPIC_POSTER' => ($topic_data['topic_poster'] == $poster_id) ? true : false,
1451
'S_IGNORE_POST' => ($row['hide_post']) ? true : false,
1452
'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>') : '',
1455
if (isset($cp_row['row']) && sizeof($cp_row['row']))
1457
$postrow = array_merge($postrow, $cp_row['row']);
1460
// Dump vars into template
1461
$template->assign_block_vars('postrow', $postrow);
1463
if (!empty($cp_row['blockrow']))
1465
foreach ($cp_row['blockrow'] as $field_data)
1467
$template->assign_block_vars('postrow.custom_fields', $field_data);
1471
// Display not already displayed Attachments for this post, we already parsed them. ;)
1472
if (!empty($attachments[$row['post_id']]))
1474
foreach ($attachments[$row['post_id']] as $attachment)
1476
$template->assign_block_vars('postrow.attachment', array(
1477
'DISPLAY_ATTACHMENT' => $attachment)
1482
$prev_post_id = $row['post_id'];
1484
unset($rowset[$post_list[$i]]);
1485
unset($attachments[$row['post_id']]);
1487
unset($rowset, $user_cache);
1489
// Update topic view and if necessary attachment view counters ... but only if this is the first 'page view'
1490
if (isset($user->data['session_page']) && strpos($user->data['session_page'], '&t=' . $topic_id) === false)
1492
$sql = 'UPDATE ' . TOPICS_TABLE . '
1493
SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
1494
WHERE topic_id = $topic_id";
1495
$db->sql_query($sql);
1497
// Update the attachment download counts
1498
if (sizeof($update_count))
1500
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
1501
SET download_count = download_count + 1
1502
WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
1503
$db->sql_query($sql);
1507
// Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
1508
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])
1510
markread('topic', $forum_id, $topic_id, $max_post_time);
1512
// Update forum info
1513
$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);
1517
$all_marked_read = true;
1520
// If there are absolutely no more unread posts in this forum and unread posts shown, we can savely show the #unread link
1521
if ($all_marked_read)
1525
$template->assign_vars(array(
1526
'U_VIEW_UNREAD_POST' => '#unread',
1529
else if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id])
1531
$template->assign_vars(array(
1532
'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=unread") . '#unread',
1536
else if (!$all_marked_read)
1538
$last_page = ((floor($start / $config['posts_per_page']) + 1) == max(ceil($total_posts / $config['posts_per_page']), 1)) ? true : false;
1540
// What can happen is that we are at the last displayed page. If so, we also display the #unread link based in $post_unread
1541
if ($last_page && $post_unread)
1543
$template->assign_vars(array(
1544
'U_VIEW_UNREAD_POST' => '#unread',
1547
else if (!$last_page)
1549
$template->assign_vars(array(
1550
'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=unread") . '#unread',
1555
// We overwrite $_REQUEST['f'] if there is no forum specified
1556
// to be able to display the correct online list.
1557
// One downside is that the user currently viewing this topic/post is not taken into account.
1558
if (empty($_REQUEST['f']))
1560
$_REQUEST['f'] = $forum_id;
1564
page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_data['topic_title']);
1566
$template->set_filenames(array(
1567
'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html')
1569
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
b'\\ No newline at end of file'