root / tags / milestone_3 / phpBB / viewtopic.php
History | View | Annotate | Download (51.8 kB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package phpBB3 |
| 5 | * @version $Id: viewtopic.php 5247 2005-10-02 18:47:06Z acydburn $ |
| 6 | * @copyright (c) 2005 phpBB Group |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /**
|
| 12 | */ |
| 13 | define('IN_PHPBB', true); |
| 14 | $phpbb_root_path = './'; |
| 15 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 16 | include($phpbb_root_path . 'common.'.$phpEx); |
| 17 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 18 | |
| 19 | // Start session management
|
| 20 | $user->session_begin();
|
| 21 | $auth->acl($user->data); |
| 22 | |
| 23 | // Initial var setup
|
| 24 | $forum_id = request_var('f', 0); |
| 25 | $topic_id = request_var('t', 0); |
| 26 | $post_id = request_var('p', 0); |
| 27 | $voted_id = request_var('vote_id', 0);; |
| 28 | |
| 29 | $start = request_var('start', 0); |
| 30 | $view = request_var('view', ''); |
| 31 | $rate = request_var('rate', 0); |
| 32 | |
| 33 | $sort_days = request_var('st', ((!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0)); |
| 34 | $sort_key = request_var('sk', ((!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't')); |
| 35 | $sort_dir = request_var('sd', ((!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a')); |
| 36 | |
| 37 | $update = request_var('update', false); |
| 38 | |
| 39 | $hilit_words = request_var('hilit', ''); |
| 40 | |
| 41 | // Do we have a topic or post id?
|
| 42 | if (!$topic_id && !$post_id) |
| 43 | {
|
| 44 | trigger_error('NO_TOPIC'); |
| 45 | } |
| 46 | |
| 47 | // Find topic id if user requested a newer or older topic
|
| 48 | $unread_post_id = 0; |
| 49 | if ($view && !$post_id) |
| 50 | {
|
| 51 | if (!$forum_id) |
| 52 | {
|
| 53 | $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . " |
| 54 | WHERE topic_id = $topic_id"; |
| 55 | $db->sql_query_limit($sql, 1); |
| 56 | $result = $db->sql_query($sql); |
| 57 | if ($row = $db->sql_fetchrow($result)) |
| 58 | {
|
| 59 | $forum_id = $row['forum_id']; |
| 60 | } |
| 61 | else
|
| 62 | {
|
| 63 | trigger_error('NO_TOPIC'); |
| 64 | } |
| 65 | $db->sql_freeresult($result); |
| 66 | } |
| 67 | |
| 68 | if ($view == 'unread') |
| 69 | {
|
| 70 | if ($user->data['is_registered']) |
| 71 | {
|
| 72 | $topic_last_read = get_topic_last_read($topic_id, $forum_id); |
| 73 | } |
| 74 | else
|
| 75 | {
|
| 76 | $topic_last_read = 0; |
| 77 | } |
| 78 | |
| 79 | $sql = 'SELECT p.post_id, p.topic_id, p.forum_id |
| 80 | FROM (' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t) |
| 81 | WHERE t.topic_id = $topic_id |
| 82 | AND p.topic_id = t.topic_id |
| 83 | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1') . " |
| 84 | AND (p.post_time > $topic_last_read |
| 85 | OR p.post_id = t.topic_last_post_id) |
| 86 | ORDER BY p.post_time ASC";
|
| 87 | $result = $db->sql_query_limit($sql, 1); |
| 88 | |
| 89 | if (!($row = $db->sql_fetchrow($result))) |
| 90 | {
|
| 91 | // Setup user environment so we can process lang string
|
| 92 | $user->setup('viewtopic'); |
| 93 | |
| 94 | meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 95 | $message = $user->lang['NO_UNREAD_POSTS'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 96 | trigger_error($message); |
| 97 | } |
| 98 | $db->sql_freeresult($result); |
| 99 | |
| 100 | $unread_post_id = $post_id = $row['post_id']; |
| 101 | $topic_id = $row['topic_id']; |
| 102 | } |
| 103 | else if ($view == 'next' || $view == 'previous') |
| 104 | {
|
| 105 | $sql_condition = ($view == 'next') ? '>' : '<'; |
| 106 | $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC'; |
| 107 | |
| 108 | $sql = 'SELECT t.topic_id, t.forum_id |
| 109 | FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . " t2 |
| 110 | WHERE t2.topic_id = $topic_id |
| 111 | AND t.forum_id = t2.forum_id |
| 112 | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . " |
| 113 | AND t.topic_last_post_time $sql_condition t2.topic_last_post_time |
| 114 | ORDER BY t.topic_last_post_time $sql_ordering"; |
| 115 | $result = $db->sql_query_limit($sql, 1); |
| 116 | |
| 117 | if (!($row = $db->sql_fetchrow($result))) |
| 118 | {
|
| 119 | $message = ($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS'; |
| 120 | trigger_error($message); |
| 121 | } |
| 122 | else
|
| 123 | {
|
| 124 | $topic_id = $row['topic_id']; |
| 125 | |
| 126 | // Check for global announcement correctness?
|
| 127 | if (!$row['forum_id'] && !$forum_id) |
| 128 | {
|
| 129 | trigger_error('NO_TOPIC'); |
| 130 | } |
| 131 | else if ($row['forum_id']) |
| 132 | {
|
| 133 | $forum_id = $row['forum_id']; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Check for global announcement correctness?
|
| 139 | if ((!$row || !$row['forum_id']) && !$forum_id) |
| 140 | {
|
| 141 | trigger_error('NO_TOPIC'); |
| 142 | } |
| 143 | else if ($row['forum_id']) |
| 144 | {
|
| 145 | $forum_id = $row['forum_id']; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // This rather complex gaggle of code handles querying for topics but
|
| 150 | // also allows for direct linking to a post (and the calculation of which
|
| 151 | // page the post is on and the correct display of viewtopic)
|
| 152 | $join_sql_table = (!$post_id) ? '' : ', ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2 '; |
| 153 | if (!$post_id) |
| 154 | {
|
| 155 | $join_sql = "t.topic_id = $topic_id"; |
| 156 | } |
| 157 | else
|
| 158 | {
|
| 159 | if ($auth->acl_get('m_approve', $forum_id)) |
| 160 | {
|
| 161 | $join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id"; |
| 162 | } |
| 163 | else
|
| 164 | {
|
| 165 | $join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND p.post_approved = 1 AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_approved = 1 AND p2.post_id <= $post_id"; |
| 166 | } |
| 167 | } |
| 168 | $extra_fields = (!$post_id) ? '' : ', COUNT(p2.post_id) AS prev_posts'; |
| 169 | $order_sql = (!$post_id) ? '' : 'GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style, f.forum_password ORDER BY p.post_id ASC'; |
| 170 | |
| 171 | if ($user->data['is_registered']) |
| 172 | {
|
| 173 | $extra_fields .= ', tw.notify_status' . (($config['allow_bookmarks']) ? ', bm.order_id as bookmarked' : ''); |
| 174 | $join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON (tw.user_id = ' . $user->data['user_id'] . ' |
| 175 | AND t.topic_id = tw.topic_id)';
|
| 176 | $join_sql_table .= ($config['allow_bookmarks']) ? ' LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' |
| 177 | AND t.topic_id = bm.topic_id)' : ''; |
| 178 | } |
| 179 | |
| 180 | // Join to forum table on topic forum_id unless topic forum_id is zero
|
| 181 | // whereupon we join on the forum_id passed as a parameter ... this
|
| 182 | // is done so navigation, forum name, etc. remain consistent with where
|
| 183 | // user clicked to view a global topic
|
| 184 | $sql = 'SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_attachment, t.topic_status, t.topic_approved, t.topic_replies_real, t.topic_replies, t.topic_first_post_id, t.topic_last_post_id, t.topic_last_poster_id, t.topic_last_post_time, t.topic_poster, t.topic_time, t.topic_time_limit, t.topic_type, t.topic_bumped, t.topic_bumper, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, t.poll_vote_change, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_type, f.forum_id, f.forum_style, f.forum_password, f.forum_rules, f.forum_rules_link, f.forum_rules_flags, f.forum_rules_bbcode_uid, f.forum_rules_bbcode_bitfield' . $extra_fields . ' |
| 185 | FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f' . $join_sql_table . " |
| 186 | WHERE $join_sql |
| 187 | AND (f.forum_id = t.forum_id |
| 188 | " . ((!$forum_id) ? '' : 'OR (t.topic_type = ' . POST_GLOBAL . " AND f.forum_id = $forum_id)") . " |
| 189 | ) |
| 190 | $order_sql"; |
| 191 | $result = $db->sql_query($sql); |
| 192 | |
| 193 | if (!($topic_data = $db->sql_fetchrow($result))) |
| 194 | {
|
| 195 | // If post_id was submitted, we try at least to display the topic as a last resort...
|
| 196 | if ($post_id && $forum_id && $topic_id) |
| 197 | {
|
| 198 | redirect("viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id");
|
| 199 | } |
| 200 | trigger_error('NO_TOPIC'); |
| 201 | } |
| 202 | |
| 203 | // Extract the data
|
| 204 | extract($topic_data); |
| 205 | |
| 206 | //
|
| 207 | $topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_replies_real : $topic_replies; |
| 208 | unset($topic_replies_real); |
| 209 | |
| 210 | if ($user->data['is_registered'] && !isset($topic_last_read)) |
| 211 | {
|
| 212 | $topic_last_read = get_topic_last_read($topic_id, $forum_id); |
| 213 | } |
| 214 | else
|
| 215 | {
|
| 216 | $topic_last_read = 0; |
| 217 | } |
| 218 | |
| 219 | // Check sticky/announcement time limit
|
| 220 | if (($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) && $topic_time_limit && ($topic_time + $topic_time_limit) < time()) |
| 221 | {
|
| 222 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 223 | SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0 |
| 224 | WHERE topic_id = ' . $topic_id; |
| 225 | $db->sql_query($sql); |
| 226 | |
| 227 | $topic_type = POST_NORMAL; |
| 228 | $topic_time_limit = 0; |
| 229 | } |
| 230 | |
| 231 | // Setup look and feel
|
| 232 | $user->setup('viewtopic', $forum_style); |
| 233 | |
| 234 | if (!$topic_approved && !$auth->acl_get('m_approve', $forum_id)) |
| 235 | {
|
| 236 | trigger_error('NO_TOPIC'); |
| 237 | } |
| 238 | |
| 239 | // Start auth check
|
| 240 | if (!$auth->acl_get('f_read', $forum_id)) |
| 241 | {
|
| 242 | if ($user->data['user_id'] != ANONYMOUS) |
| 243 | {
|
| 244 | trigger_error($user->lang['SORRY_AUTH_READ']); |
| 245 | } |
| 246 | |
| 247 | login_box('', $user->lang['LOGIN_VIEWFORUM']); |
| 248 | } |
| 249 | |
| 250 | // Forum is passworded ... check whether access has been granted to this
|
| 251 | // user this session, if not show login box
|
| 252 | if ($forum_password) |
| 253 | {
|
| 254 | login_forum_box($topic_data);
|
| 255 | } |
| 256 | |
| 257 | // Redirect to login or to the correct post upon emailed notification links
|
| 258 | if (isset($_GET['e'])) |
| 259 | {
|
| 260 | $jump_to = request_var('e', 0); |
| 261 | |
| 262 | $redirect_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; |
| 263 | |
| 264 | if ($user->data['user_id'] == ANONYMOUS) |
| 265 | {
|
| 266 | login_box($redirect_url . "&p=$post_id&e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']); |
| 267 | } |
| 268 | |
| 269 | if ($jump_to > 0) |
| 270 | {
|
| 271 | // We direct the already logged in user to the correct post...
|
| 272 | redirect($redirect_url . ((!$post_id) ? "&p=$jump_to" : "&p=$post_id") . "#$jump_to"); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // What is start equal to?
|
| 277 | if (!empty($post_id)) |
| 278 | {
|
| 279 | $start = floor(($prev_posts - 1) / $config['posts_per_page']) * $config['posts_per_page']; |
| 280 | } |
| 281 | |
| 282 | // Post ordering options
|
| 283 | $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'], 364 => $user->lang['1_YEAR']); |
| 284 | |
| 285 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
| 286 | $sort_by_sql = array('a' => 'u.username', 't' => 'p.post_id', 's' => 'p.post_subject'); |
| 287 | |
| 288 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; |
| 289 | 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); |
| 290 | |
| 291 | // Obtain correct post count and ordering SQL if user has
|
| 292 | // requested anything different
|
| 293 | if ($sort_days) |
| 294 | {
|
| 295 | $min_post_time = time() - ($sort_days * 86400); |
| 296 | |
| 297 | $sql = 'SELECT COUNT(post_id) AS num_posts |
| 298 | FROM ' . POSTS_TABLE . " |
| 299 | WHERE topic_id = $topic_id |
| 300 | AND post_time >= $min_post_time |
| 301 | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1'); |
| 302 | $result = $db->sql_query($sql); |
| 303 | |
| 304 | if (isset($_POST['sort'])) |
| 305 | {
|
| 306 | $start = 0; |
| 307 | } |
| 308 | $total_posts = ($row = $db->sql_fetchrow($result)) ? $row['num_posts'] : 0; |
| 309 | $limit_posts_time = "AND p.post_time >= $min_post_time "; |
| 310 | } |
| 311 | else
|
| 312 | {
|
| 313 | $total_posts = $topic_replies + 1; |
| 314 | $limit_posts_time = ''; |
| 315 | } |
| 316 | |
| 317 | // Was a highlight request part of the URI?
|
| 318 | $highlight_match = $highlight = ''; |
| 319 | if ($hilit_words) |
| 320 | {
|
| 321 | foreach (explode(' ', trim($hilit_words)) as $word) |
| 322 | {
|
| 323 | if (trim($word)) |
| 324 | {
|
| 325 | $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('\*', '\w*?', preg_quote(urlencode($word), '#')); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | $highlight = urlencode($hilit_words); |
| 330 | } |
| 331 | |
| 332 | // General Viewtopic URL for return links
|
| 333 | $viewtopic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" . (($highlight_match) ? "&hilit=$highlight" : ''); |
| 334 | |
| 335 | // Are we watching this topic?
|
| 336 | $s_watching_topic = $s_watching_topic_img = array(); |
| 337 | $s_watching_topic['link'] = $s_watching_topic['title'] = ''; |
| 338 | if ($config['email_enable'] && $config['allow_topic_notify'] && $user->data['is_registered']) |
| 339 | {
|
| 340 | watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id, $notify_status, $start); |
| 341 | } |
| 342 | |
| 343 | // Bookmarks
|
| 344 | if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0)) |
| 345 | {
|
| 346 | if (!$bookmarked) |
| 347 | {
|
| 348 | $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 349 | 'user_id' => $user->data['user_id'], |
| 350 | 'topic_id' => $topic_id, |
| 351 | 'order_id' => 0) |
| 352 | ); |
| 353 | $db->sql_query($sql); |
| 354 | |
| 355 | $where_sql = ''; |
| 356 | $sign = '+'; |
| 357 | } |
| 358 | else
|
| 359 | {
|
| 360 | $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . " |
| 361 | WHERE user_id = {$user->data['user_id']} |
| 362 | AND topic_id = $topic_id"; |
| 363 | $db->sql_query($sql); |
| 364 | |
| 365 | // Works because of current order_id selected as bookmark value (please do not change because of simplicity)
|
| 366 | $where_sql = " AND order_id > $bookmarked"; |
| 367 | $sign = '-'; |
| 368 | } |
| 369 | |
| 370 | // Re-Sort Bookmarks
|
| 371 | $sql = 'UPDATE ' . BOOKMARKS_TABLE . " |
| 372 | SET order_id = order_id $sign 1 |
| 373 | WHERE user_id = {$user->data['user_id']} |
| 374 | $where_sql"; |
| 375 | $db->sql_query($sql); |
| 376 | |
| 377 | meta_refresh(3, $viewtopic_url); |
| 378 | |
| 379 | $message = (($bookmarked) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); |
| 380 | trigger_error($message); |
| 381 | } |
| 382 | |
| 383 | // Grab ranks
|
| 384 | $ranks = array(); |
| 385 | $cache->obtain_ranks($ranks); |
| 386 | |
| 387 | // Grab icons
|
| 388 | $icons = array(); |
| 389 | $cache->obtain_icons($icons); |
| 390 | |
| 391 | // Grab extensions
|
| 392 | $extensions = array(); |
| 393 | if ($topic_attachment) |
| 394 | {
|
| 395 | $cache->obtain_attach_extensions($extensions); |
| 396 | } |
| 397 | |
| 398 | // Forum rules listing
|
| 399 | $s_forum_rules = ''; |
| 400 | gen_forum_auth_level('topic', $forum_id); |
| 401 | |
| 402 | // Quick mod tools
|
| 403 | $topic_mod = ''; |
| 404 | $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_poster)) ? (($topic_status == ITEM_UNLOCKED) ? '<option value="lock">' . $user->lang['LOCK_TOPIC'] . '</option>' : '<option value="unlock">' . $user->lang['UNLOCK_TOPIC'] . '</option>') : ''; |
| 405 | $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : ''; |
| 406 | $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : ''; |
| 407 | $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : ''; |
| 408 | $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_TOPIC'] . '</option>' : ''; |
| 409 | $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : ''; |
| 410 | $topic_mod .= ($auth->acl_get('m_', $forum_id) && $topic_type != POST_NORMAL) ? '<option value="make_normal">' . $user->lang['MAKE_NORMAL'] . '</option>' : ''; |
| 411 | $topic_mod .= ($auth->acl_get('f_sticky', $forum_id) && $topic_type != POST_STICKY) ? '<option value="make_sticky">' . $user->lang['MAKE_STICKY'] . '</option>' : ''; |
| 412 | $topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_ANNOUNCE) ? '<option value="make_announce">' . $user->lang['MAKE_ANNOUNCE'] . '</option>' : ''; |
| 413 | $topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_GLOBAL) ? '<option value="make_global">' . $user->lang['MAKE_GLOBAL'] . '</option>' : ''; |
| 414 | $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="viewlogs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : ''; |
| 415 | |
| 416 | // If we've got a hightlight set pass it on to pagination.
|
| 417 | $pagination = generate_pagination("{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&$u_sort_param" . (($highlight_match) ? "&hilit=$highlight" : ''), $total_posts, $config['posts_per_page'], $start); |
| 418 | |
| 419 | // Navigation links
|
| 420 | generate_forum_nav($topic_data);
|
| 421 | |
| 422 | // Forum Rules
|
| 423 | generate_forum_rules($topic_data);
|
| 424 | |
| 425 | // Moderators
|
| 426 | $forum_moderators = array(); |
| 427 | get_moderators($forum_moderators, $forum_id); |
| 428 | |
| 429 | // This is only used for print view so ...
|
| 430 | $server_path = (!$view) ? '' : generate_board_url() . '/'; |
| 431 | |
| 432 | // Replace naughty words in title
|
| 433 | $topic_title = censor_text($topic_title); |
| 434 | |
| 435 | // Send vars to template
|
| 436 | $template->assign_vars(array( |
| 437 | 'FORUM_ID' => $forum_id, |
| 438 | 'FORUM_NAME' => $forum_name, |
| 439 | 'FORUM_DESC' => $forum_desc, |
| 440 | 'TOPIC_ID' => $topic_id, |
| 441 | 'TOPIC_TITLE' => $topic_title, |
| 442 | 'PAGINATION' => $pagination, |
| 443 | 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start), |
| 444 | 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), |
| 445 | 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? "mcp.$phpEx?sid=" . $user->session_id . "&mode=topic_view&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" : '', |
| 446 | 'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '', |
| 447 | |
| 448 | 'POST_IMG' => ($forum_status == ITEM_LOCKED) ? $user->img('btn_locked', 'FORUM_LOCKED') : $user->img('btn_post', 'POST_NEW_TOPIC'), |
| 449 | 'QUOTE_IMG' => $user->img('btn_quote', 'REPLY_WITH_QUOTE'), |
| 450 | 'REPLY_IMG' => ($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) ? $user->img('btn_locked', 'TOPIC_LOCKED') : $user->img('btn_reply', 'REPLY_TO_TOPIC'), |
| 451 | 'EDIT_IMG' => $user->img('btn_edit', 'EDIT_POST'), |
| 452 | 'DELETE_IMG' => $user->img('btn_delete', 'DELETE_POST'), |
| 453 | 'INFO_IMG' => $user->img('btn_info', 'VIEW_INFO'), |
| 454 | 'PROFILE_IMG' => $user->img('btn_profile', 'READ_PROFILE'), |
| 455 | 'SEARCH_IMG' => $user->img('btn_search', 'SEARCH_USER_POSTS'), |
| 456 | 'PM_IMG' => $user->img('btn_pm', 'SEND_PRIVATE_MESSAGE'), |
| 457 | 'EMAIL_IMG' => $user->img('btn_email', 'SEND_EMAIL'), |
| 458 | 'WWW_IMG' => $user->img('btn_www', 'VISIT_WEBSITE'), |
| 459 | 'ICQ_IMG' => $user->img('btn_icq', 'ICQ'), |
| 460 | 'AIM_IMG' => $user->img('btn_aim', 'AIM'), |
| 461 | 'MSN_IMG' => $user->img('btn_msnm', 'MSNM'), |
| 462 | 'YIM_IMG' => $user->img('btn_yim', 'YIM'), |
| 463 | 'JABBER_IMG' => $user->img('btn_jabber', 'JABBER') , |
| 464 | 'REPORT_IMG' => $user->img('btn_report', 'REPORT_POST'), |
| 465 | 'REPORTED_IMG' => $user->img('icon_reported', 'POST_REPORTED'), |
| 466 | 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'POST_UNAPPROVED'), |
| 467 | |
| 468 | 'S_SELECT_SORT_DIR' => $s_sort_dir, |
| 469 | 'S_SELECT_SORT_KEY' => $s_sort_key, |
| 470 | 'S_SELECT_SORT_DAYS' => $s_limit_days, |
| 471 | 'S_TOPIC_ACTION' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start", |
| 472 | 'S_TOPIC_MOD' => ($topic_mod != '') ? '<select name="mode">' . $topic_mod . '</select>' : '', |
| 473 | 'S_MOD_ACTION' => "mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&f=$forum_id&quickmod=1", |
| 474 | |
| 475 | 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, |
| 476 | 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&search_forum[]=$forum_id", |
| 477 | |
| 478 | 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id", |
| 479 | 'U_FORUM' => $server_path, |
| 480 | 'U_VIEW_UNREAD_POST' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=unread#unread", |
| 481 | 'U_VIEW_TOPIC' => $viewtopic_url, |
| 482 | 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id", |
| 483 | 'U_VIEW_OLDER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=previous", |
| 484 | 'U_VIEW_NEWER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=next", |
| 485 | 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&view=print' : '', |
| 486 | 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? "memberlist.$phpEx$SID&mode=email&t=$topic_id" : '', |
| 487 | |
| 488 | 'U_WATCH_TOPIC' => $s_watching_topic['link'], |
| 489 | 'L_WATCH_TOPIC' => $s_watching_topic['title'], |
| 490 | |
| 491 | 'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&bookmark=1' : '', |
| 492 | 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $bookmarked) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'], |
| 493 | |
| 494 | 'U_POST_NEW_TOPIC' => "posting.$phpEx$SID&mode=post&f=$forum_id", |
| 495 | 'U_POST_REPLY_TOPIC' => "posting.$phpEx$SID&mode=reply&f=$forum_id&t=$topic_id", |
| 496 | 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id)) ? "posting.$phpEx$SID&mode=bump&f=$forum_id&t=$topic_id" : '') |
| 497 | ); |
| 498 | |
| 499 | // Does this topic contain a poll?
|
| 500 | if (!empty($poll_start)) |
| 501 | {
|
| 502 | $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid |
| 503 | FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p |
| 504 | WHERE o.topic_id = $topic_id |
| 505 | AND p.post_id = $topic_first_post_id |
| 506 | AND p.topic_id = o.topic_id |
| 507 | ORDER BY o.poll_option_id";
|
| 508 | $result = $db->sql_query($sql); |
| 509 | |
| 510 | $poll_info = array(); |
| 511 | while ($row = $db->sql_fetchrow($result)) |
| 512 | {
|
| 513 | $poll_info[] = $row; |
| 514 | } |
| 515 | $db->sql_freeresult($result); |
| 516 | |
| 517 | $cur_voted_id = array(); |
| 518 | if ($user->data['is_registered']) |
| 519 | {
|
| 520 | $sql = 'SELECT poll_option_id |
| 521 | FROM ' . POLL_VOTES_TABLE . ' |
| 522 | WHERE topic_id = ' . $topic_id . ' |
| 523 | AND vote_user_id = ' . $user->data['user_id']; |
| 524 | $result = $db->sql_query($sql); |
| 525 | |
| 526 | while ($row = $db->sql_fetchrow($result)) |
| 527 | {
|
| 528 | $cur_voted_id[] = $row['poll_option_id']; |
| 529 | } |
| 530 | $db->sql_freeresult($result); |
| 531 | } |
| 532 | else
|
| 533 | {
|
| 534 | // Cookie based guest tracking ... I don't like this but hum ho
|
| 535 | // it's oft requested. This relies on "nice" users who don't feel
|
| 536 | // the need to delete cookies to mess with results.
|
| 537 | if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id])) |
| 538 | {
|
| 539 | $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) || |
| 544 | ($auth->acl_get('f_votechg', $forum_id) && $poll_vote_change)) && |
| 545 | (($poll_length != 0 && $poll_start + $poll_length > time()) || $poll_length == 0) && |
| 546 | $topic_status != ITEM_LOCKED && |
| 547 | $forum_status != ITEM_LOCKED) ? true : false; |
| 548 | $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false; |
| 549 | |
| 550 | if ($update && $s_can_vote) |
| 551 | {
|
| 552 | if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options) |
| 553 | {
|
| 554 | meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 555 | |
| 556 | $message = (!sizeof($voted_id)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS'; |
| 557 | $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 558 | trigger_error($message); |
| 559 | } |
| 560 | |
| 561 | foreach ($voted_id as $option) |
| 562 | {
|
| 563 | if (in_array($option, $cur_voted_id)) |
| 564 | {
|
| 565 | continue;
|
| 566 | } |
| 567 | |
| 568 | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " |
| 569 | SET poll_option_total = poll_option_total + 1 |
| 570 | WHERE poll_option_id = $option |
| 571 | AND topic_id = $topic_id"; |
| 572 | $db->sql_query($sql); |
| 573 | |
| 574 | if ($user->data['is_registered']) |
| 575 | {
|
| 576 | $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . " (topic_id, poll_option_id, vote_user_id, vote_user_ip) |
| 577 | VALUES ($topic_id, $option, " . $user->data['user_id'] . ", '$user->ip')"; |
| 578 | $db->sql_query($sql); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | foreach ($cur_voted_id as $option) |
| 583 | {
|
| 584 | if (!in_array($option, $voted_id)) |
| 585 | {
|
| 586 | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " |
| 587 | SET poll_option_total = poll_option_total - 1 |
| 588 | WHERE poll_option_id = $option |
| 589 | AND topic_id = $topic_id"; |
| 590 | $db->sql_query($sql); |
| 591 | |
| 592 | if ($user->data['is_registered']) |
| 593 | {
|
| 594 | $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . " |
| 595 | WHERE topic_id = $topic_id |
| 596 | AND poll_option_id = $option |
| 597 | AND vote_user_id = " . $user->data['user_id']; |
| 598 | $db->sql_query($sql); |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot']) |
| 604 | {
|
| 605 | $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000); |
| 606 | } |
| 607 | |
| 608 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 609 | SET poll_last_vote = ' . time() . " |
| 610 | WHERE topic_id = $topic_id"; |
| 611 | //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
|
| 612 | $db->sql_query($sql); |
| 613 | |
| 614 | meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 615 | |
| 616 | $message = $user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 617 | trigger_error($message); |
| 618 | } |
| 619 | |
| 620 | $poll_total = 0; |
| 621 | foreach ($poll_info as $poll_option) |
| 622 | {
|
| 623 | $poll_total += $poll_option['poll_option_total']; |
| 624 | } |
| 625 | |
| 626 | if ($poll_info[0]['bbcode_bitfield']) |
| 627 | {
|
| 628 | include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 629 | $poll_bbcode = new bbcode(); |
| 630 | |
| 631 | for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++) |
| 632 | {
|
| 633 | $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']); |
| 634 | $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']); |
| 635 | $poll_info[$i]['poll_option_text'] = str_replace("\n", '<br />', censor_text($poll_info[$i]['poll_option_text'])); |
| 636 | } |
| 637 | |
| 638 | $poll_bbcode->bbcode_second_pass($poll_title, $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']); |
| 639 | $poll_title = smiley_text($poll_title); |
| 640 | $poll_title = str_replace("\n", '<br />', censor_text($poll_title)); |
| 641 | |
| 642 | unset($poll_bbcode); |
| 643 | } |
| 644 | |
| 645 | foreach ($poll_info as $poll_option) |
| 646 | {
|
| 647 | $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0; |
| 648 | $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100)); |
| 649 | |
| 650 | $template->assign_block_vars('poll_option', array( |
| 651 | 'POLL_OPTION_ID' => $poll_option['poll_option_id'], |
| 652 | 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'], |
| 653 | 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], |
| 654 | 'POLL_OPTION_PERCENT' => $option_pct_txt, |
| 655 | 'POLL_OPTION_PCT' => round($option_pct * 100), |
| 656 | 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)), |
| 657 | 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false) |
| 658 | ); |
| 659 | } |
| 660 | |
| 661 | $template->assign_vars(array( |
| 662 | 'POLL_QUESTION' => $poll_title, |
| 663 | 'TOTAL_VOTES' => $poll_total, |
| 664 | 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'), |
| 665 | 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'), |
| 666 | |
| 667 | 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options), |
| 668 | 'L_POLL_LENGTH' => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '', |
| 669 | |
| 670 | 'S_HAS_POLL' => true, |
| 671 | 'S_CAN_VOTE' => $s_can_vote, |
| 672 | 'S_DISPLAY_RESULTS' => $s_display_results, |
| 673 | 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, |
| 674 | 'S_POLL_ACTION' => $viewtopic_url, |
| 675 | |
| 676 | 'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll') |
| 677 | ); |
| 678 | |
| 679 | unset($poll_info, $voted_id); |
| 680 | } |
| 681 | |
| 682 | // If the user is trying to reach the second half of the topic, fetch it starting from the end
|
| 683 | $store_reverse = FALSE; |
| 684 | $sql_limit = $config['posts_per_page']; |
| 685 | |
| 686 | if ($start > $total_posts / 2) |
| 687 | {
|
| 688 | $store_reverse = TRUE; |
| 689 | |
| 690 | if ($start + $config['posts_per_page'] > $total_posts) |
| 691 | {
|
| 692 | $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start)); |
| 693 | } |
| 694 | |
| 695 | // Select the sort order
|
| 696 | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC'); |
| 697 | $sql_start = max(0, $total_posts - $sql_limit - $start); |
| 698 | } |
| 699 | else
|
| 700 | {
|
| 701 | // Select the sort order
|
| 702 | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); |
| 703 | $sql_start = $start; |
| 704 | } |
| 705 | |
| 706 | // Container for user details, only process once
|
| 707 | $post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array(); |
| 708 | $has_attachments = $display_notice = false; |
| 709 | $force_encoding = ''; |
| 710 | $bbcode_bitfield = $i = $i_total = 0; |
| 711 | |
| 712 | // Go ahead and pull all data for this topic
|
| 713 | $sql = 'SELECT p.post_id |
| 714 | FROM ' . POSTS_TABLE . ' p' . (($sort_by_sql[$sort_key]{0} == 'u') ? ', ' . USERS_TABLE . ' u': '') . " |
| 715 | WHERE p.topic_id = $topic_id |
| 716 | " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . " |
| 717 | " . (($sort_by_sql[$sort_key]{0} == 'u') ? 'AND u.user_id = p.poster_id': '') . " |
| 718 | $limit_posts_time |
| 719 | ORDER BY $sql_sort_order"; |
| 720 | $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); |
| 721 | |
| 722 | $i = ($store_reverse) ? $sql_limit - 1 : 0; |
| 723 | while ($row = $db->sql_fetchrow($result)) |
| 724 | {
|
| 725 | $post_list[$i] = $row['post_id']; |
| 726 | ($store_reverse) ? --$i : ++$i; |
| 727 | } |
| 728 | $db->sql_freeresult($result); |
| 729 | |
| 730 | if (empty($post_list)) |
| 731 | {
|
| 732 | trigger_error($user->lang['NO_TOPIC']); |
| 733 | } |
| 734 | |
| 735 | $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_jabber, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_allow_viewonline, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, z.friend, z.foe, p.* |
| 736 | FROM (' . POSTS_TABLE . ' p |
| 737 | LEFT JOIN ' . ZEBRA_TABLE . ' z ON (z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id)), ' . USERS_TABLE . ' u |
| 738 | WHERE p.post_id IN (' . implode(', ', $post_list) . ') |
| 739 | AND u.user_id = p.poster_id';
|
| 740 | $result = $db->sql_query($sql); |
| 741 | |
| 742 | // Posts are stored in the $rowset array while $attach_list, $user_cache
|
| 743 | // and the global bbcode_bitfield are built
|
| 744 | while ($row = $db->sql_fetchrow($result)) |
| 745 | {
|
| 746 | $poster_id = $row['poster_id']; |
| 747 | $poster = ($poster_id == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username']; |
| 748 | |
| 749 | if (!$view || $view != 'show' || $post_id != $row['post_id']) |
| 750 | {
|
| 751 | if ($row['foe']) |
| 752 | {
|
| 753 | $rowset[$row['post_id']] = array( |
| 754 | 'foe' => true, |
| 755 | 'post_id' => $row['post_id'], |
| 756 | 'poster' => $poster, |
| 757 | ); |
| 758 | |
| 759 | continue;
|
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // Does post have an attachment? If so, add it to the list
|
| 764 | if ($row['post_attachment'] && $config['allow_attachments']) |
| 765 | {
|
| 766 | $attach_list[] = $row['post_id']; |
| 767 | |
| 768 | if ($row['post_approved']) |
| 769 | {
|
| 770 | $has_attachments = TRUE; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | $rowset[$row['post_id']] = array( |
| 775 | 'post_id' => $row['post_id'], |
| 776 | 'post_time' => $row['post_time'], |
| 777 | 'poster' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster, |
| 778 | 'user_id' => $row['user_id'], |
| 779 | 'topic_id' => $row['topic_id'], |
| 780 | 'forum_id' => $row['forum_id'], |
| 781 | 'post_subject' => $row['post_subject'], |
| 782 | 'post_edit_count' => $row['post_edit_count'], |
| 783 | 'post_edit_time' => $row['post_edit_time'], |
| 784 | 'post_edit_reason' => $row['post_edit_reason'], |
| 785 | 'post_edit_user' => $row['post_edit_user'], |
| 786 | 'icon_id' => $row['icon_id'], |
| 787 | 'post_attachment' => $row['post_attachment'], |
| 788 | 'post_approved' => $row['post_approved'], |
| 789 | 'post_reported' => $row['post_reported'], |
| 790 | 'post_text' => $row['post_text'], |
| 791 | 'post_encoding' => $row['post_encoding'], |
| 792 | 'bbcode_uid' => $row['bbcode_uid'], |
| 793 | 'bbcode_bitfield' => $row['bbcode_bitfield'], |
| 794 | 'enable_html' => $row['enable_html'], |
| 795 | 'enable_smilies' => $row['enable_smilies'], |
| 796 | 'enable_sig' => $row['enable_sig'], |
| 797 | 'friend' => $row['friend'], |
| 798 | ); |
| 799 | |
| 800 | // Define the global bbcode bitfield, will be used to load bbcodes
|
| 801 | $bbcode_bitfield |= $row['bbcode_bitfield']; |
| 802 | |
| 803 | // Is a signature attached? Are we going to display it?
|
| 804 | if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) |
| 805 | {
|
| 806 | $bbcode_bitfield |= $row['user_sig_bbcode_bitfield']; |
| 807 | } |
| 808 | |
| 809 | // Cache various user specific data ... so we don't have to recompute
|
| 810 | // this each time the same user appears on this page
|
| 811 | if (!isset($user_cache[$poster_id])) |
| 812 | {
|
| 813 | if ($poster_id == ANONYMOUS) |
| 814 | {
|
| 815 | $user_cache[$poster_id] = array( |
| 816 | 'joined' => '', |
| 817 | 'posts' => '', |
| 818 | 'from' => '', |
| 819 | |
| 820 | 'sig' => '', |
| 821 | 'sig_bbcode_uid' => '', |
| 822 | 'sig_bbcode_bitfield' => '', |
| 823 | |
| 824 | 'online' => false, |
| 825 | 'avatar' => '', |
| 826 | 'rank_title' => '', |
| 827 | 'rank_image' => '', |
| 828 | 'sig' => '', |
| 829 | 'posts' => '', |
| 830 | 'profile' => '', |
| 831 | 'pm' => '', |
| 832 | 'email' => '', |
| 833 | 'www' => '', |
| 834 | 'icq_status_img'=> '', |
| 835 | 'icq' => '', |
| 836 | 'aim' => '', |
| 837 | 'msn' => '', |
| 838 | 'yim' => '', |
| 839 | 'jabber' => '', |
| 840 | 'search' => '', |
| 841 | 'username' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster |
| 842 | ); |
| 843 | } |
| 844 | else
|
| 845 | {
|
| 846 | $user_sig = ''; |
| 847 | |
| 848 | if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) |
| 849 | {
|
| 850 | $user_sig = $row['user_sig']; |
| 851 | } |
| 852 | |
| 853 | $id_cache[] = $poster_id; |
| 854 | |
| 855 | $user_cache[$poster_id] = array( |
| 856 | 'joined' => $user->format_date($row['user_regdate'], $user->lang['DATE_FORMAT']), |
| 857 | 'posts' => $row['user_posts'], |
| 858 | 'from' => (!empty($row['user_from'])) ? $row['user_from'] : '', |
| 859 | |
| 860 | 'sig' => $user_sig, |
| 861 | 'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '', |
| 862 | 'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '', |
| 863 | |
| 864 | 'viewonline' => $row['user_allow_viewonline'], |
| 865 | |
| 866 | 'avatar' => '', |
| 867 | |
| 868 | 'online' => false, |
| 869 | 'profile' => "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=$poster_id", |
| 870 | 'www' => $row['user_website'], |
| 871 | 'aim' => ($row['user_aim']) ? "memberlist.$phpEx$SID&mode=contact&action=aim&u=$poster_id" : '', |
| 872 | 'msn' => ($row['user_msnm']) ? "memberlist.$phpEx$SID&mode=contact&action=msnm&u=$poster_id" : '', |
| 873 | 'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $row['user_yim'] . '&.src=pg' : '', |
| 874 | 'jabber' => ($row['user_jabber']) ? "memberlist.$phpEx$SID&mode=contact&action=jabber&u=$poster_id" : '', |
| 875 | 'search' => ($auth->acl_get('u_search')) ? "search.$phpEx$SID&search_author=" . urlencode($row['username']) .'&showresults=posts' : '', |
| 876 | 'username' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster |
| 877 | ); |
| 878 | |
| 879 | if ($row['user_avatar'] && $user->optionget('viewavatars')) |
| 880 | {
|
| 881 | $avatar_img = ''; |
| 882 | switch ($row['user_avatar_type']) |
| 883 | {
|
| 884 | case AVATAR_UPLOAD: |
| 885 | $avatar_img = $config['avatar_path'] . '/'; |
| 886 | break;
|
| 887 | case AVATAR_GALLERY: |
| 888 | $avatar_img = $config['avatar_gallery_path'] . '/'; |
| 889 | break;
|
| 890 | } |
| 891 | $avatar_img .= $row['user_avatar']; |
| 892 | |
| 893 | $user_cache[$poster_id]['avatar'] = '<img src="' . $avatar_img . '" width="' . $row['user_avatar_width'] . '" height="' . $row['user_avatar_height'] . '" border="0" alt="" />'; |
| 894 | } |
| 895 | |
| 896 | if (!empty($row['user_rank'])) |
| 897 | {
|
| 898 | $user_cache[$poster_id]['rank_title'] = (isset($ranks['special'][$row['user_rank']])) ? $ranks['special'][$row['user_rank']]['rank_title'] : ''; |
| 899 | $user_cache[$poster_id]['rank_image'] = (!empty($ranks['special'][$row['user_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$row['user_rank']]['rank_image'] . '" border="0" alt="' . $ranks['special'][$row['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$row['user_rank']]['rank_title'] . '" /><br />' : ''; |
| 900 | } |
| 901 | else
|
| 902 | {
|
| 903 | if (isset($ranks['normal']) && sizeof($ranks['normal'])) |
| 904 | {
|
| 905 | foreach ($ranks['normal'] as $rank) |
| 906 | {
|
| 907 | if ($row['user_posts'] >= $rank['rank_min']) |
| 908 | {
|
| 909 | $user_cache[$poster_id]['rank_title'] = $rank['rank_title']; |
| 910 | $user_cache[$poster_id]['rank_image'] = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : ''; |
| 911 | break;
|
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | else
|
| 916 | {
|
| 917 | $user_cache[$poster_id]['rank_title'] = ''; |
| 918 | $user_cache[$poster_id]['rank_image'] = ''; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (!empty($row['user_allow_viewemail']) || $auth->acl_get('a_email')) |
| 923 | {
|
| 924 | $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=email&u=$poster_id" : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']); |
| 925 | } |
| 926 | else
|
| 927 | {
|
| 928 | $user_cache[$poster_id]['email'] = ''; |
| 929 | } |
| 930 | |
| 931 | if (!empty($row['user_icq'])) |
| 932 | {
|
| 933 | $user_cache[$poster_id]['icq'] = "memberlist.$phpEx$SID&mode=contact&action=icq&u=$poster_id"; |
| 934 | $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" border="0" />'; |
| 935 | } |
| 936 | else
|
| 937 | {
|
| 938 | $user_cache[$poster_id]['icq_status_img'] = ''; |
| 939 | $user_cache[$poster_id]['icq'] = ''; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | $db->sql_freeresult($result); |
| 945 | |
| 946 | // Load custom profile fields
|
| 947 | if ($config['load_cpf_viewtopic']) |
| 948 | {
|
| 949 | include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); |
| 950 | $cp = new custom_profile(); |
| 951 | |
| 952 | // Grab all profile fields from users in id cache for later use - similar to the poster cache
|
| 953 | $profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache); |
| 954 | } |
| 955 | |
| 956 | // Generate online information for user
|
| 957 | if ($config['load_onlinetrack'] && sizeof($id_cache)) |
| 958 | {
|
| 959 | $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline |
| 960 | FROM ' . SESSIONS_TABLE . ' |
| 961 | WHERE session_user_id IN (' . implode(', ', $id_cache) . ') |
| 962 | GROUP BY session_user_id';
|
| 963 | $result = $db->sql_query($sql); |
| 964 | |
| 965 | $update_time = $config['load_online_time'] * 60; |
| 966 | while ($row = $db->sql_fetchrow($result)) |
| 967 | {
|
| 968 | $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline'] && $user_cache[$row['session_user_id']]['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false; |
| 969 | } |
| 970 | } |
| 971 | unset($id_cache); |
| 972 | |
| 973 | // Pull attachment data
|
| 974 | if (sizeof($attach_list)) |
| 975 | {
|
| 976 | if ($auth->acl_gets('f_download', 'u_download', $forum_id)) |
| 977 | {
|
| 978 | $sql = 'SELECT * |
| 979 | FROM ' . ATTACHMENTS_TABLE . ' |
| 980 | WHERE post_msg_id IN (' . implode(', ', $attach_list) . ') |
| 981 | AND in_message = 0 |
| 982 | ORDER BY filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC'; |
| 983 | $result = $db->sql_query($sql); |
| 984 | |
| 985 | while ($row = $db->sql_fetchrow($result)) |
| 986 | {
|
| 987 | $attachments[$row['post_msg_id']][] = $row; |
| 988 | } |
| 989 | $db->sql_freeresult($result); |
| 990 | |
| 991 | // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
|
| 992 | if (!sizeof($attachments)) |
| 993 | {
|
| 994 | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 995 | SET post_attachment = 0 |
| 996 | WHERE post_id IN (' . implode(', ', $attach_list) . ')'; |
| 997 | $db->sql_query($sql); |
| 998 | |
| 999 | // We need to update the topic indicator too if the complete topic is now without an attachment
|
| 1000 | if (sizeof($rowset) != $total_posts) |
| 1001 | {
|
| 1002 | // Not all posts are displayed so we query the db to find if there's any attachment for this topic
|
| 1003 | $sql = 'SELECT a.post_msg_id as post_id |
| 1004 | FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p |
| 1005 | WHERE p.topic_id = $topic_id |
| 1006 | AND p.post_approved = 1 |
| 1007 | AND p.topic_id = a.topic_id";
|
| 1008 | $result = $db->sql_query_limit($sql, 1); |
| 1009 | |
| 1010 | if (!$db->sql_fetchrow($result)) |
| 1011 | {
|
| 1012 | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1013 | SET topic_attachment = 0 |
| 1014 | WHERE topic_id = $topic_id"; |
| 1015 | $db->sql_query($sql); |
| 1016 | } |
| 1017 | } |
| 1018 | else
|
| 1019 | {
|
| 1020 | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1021 | SET topic_attachment = 0 |
| 1022 | WHERE topic_id = $topic_id"; |
| 1023 | $db->sql_query($sql); |
| 1024 | } |
| 1025 | } |
| 1026 | else if ($has_attachments && !$topic_data['topic_attachment']) |
| 1027 | {
|
| 1028 | // Topic has approved attachments but its flag is wrong
|
| 1029 | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1030 | SET topic_attachment = 1 |
| 1031 | WHERE topic_id = $topic_id"; |
| 1032 | $db->sql_query($sql); |
| 1033 | |
| 1034 | $topic_data['topic_attachment'] = 1; |
| 1035 | } |
| 1036 | } |
| 1037 | else
|
| 1038 | {
|
| 1039 | $display_notice = true; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | // Instantiate BBCode if need be
|
| 1044 | if ($bbcode_bitfield) |
| 1045 | {
|
| 1046 | include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 1047 | $bbcode = new bbcode($bbcode_bitfield); |
| 1048 | } |
| 1049 | |
| 1050 | $i_total = sizeof($rowset) - 1; |
| 1051 | $prev_post_id = ''; |
| 1052 | |
| 1053 | $template->assign_vars(array( |
| 1054 | 'S_NUM_POSTS' => sizeof($post_list)) |
| 1055 | ); |
| 1056 | |
| 1057 | // Output the posts
|
| 1058 | //foreach ($rowset as $i => $row)
|
| 1059 | for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) |
| 1060 | {
|
| 1061 | $row =& $rowset[$post_list[$i]]; |
| 1062 | $poster_id = $row['user_id']; |
| 1063 | |
| 1064 | // Three situations can prevent a post being display:
|
| 1065 | // i) The posters karma is below the minimum of the user ... not in 2.2.x
|
| 1066 | // ii) The poster is on the users ignore list
|
| 1067 | // iii) The post was made in a codepage different from the users
|
| 1068 | if (isset($row['foe']) && $row['foe']) |
| 1069 | {
|
| 1070 | $template->assign_block_vars('postrow', array( |
| 1071 | 'S_IGNORE_POST' => true, |
| 1072 | 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['poster'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&p=" . $row['post_id'] . '&view=show#' . $row['post_id'] . '">', '</a>')) |
| 1073 | ); |
| 1074 | |
| 1075 | continue;
|
| 1076 | } |
| 1077 | else if ($row['post_encoding'] != $user->lang['ENCODING']) |
| 1078 | {
|
| 1079 | if ($view == 'encoding' && $post_id == $row['post_id']) |
| 1080 | {
|
| 1081 | $force_encoding = $row['post_encoding']; |
| 1082 | } |
| 1083 | else
|
| 1084 | {
|
| 1085 | $template->assign_block_vars('postrow', array( |
| 1086 | 'S_IGNORE_POST' => true, |
| 1087 | 'L_IGNORE_POST' => sprintf($user->lang['POST_ENCODING'], $row['poster'], '<a href="viewtopic.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&view=encoding#' . $row['post_id'] . '">', '</a>')) |
| 1088 | ); |
| 1089 | |
| 1090 | continue;
|
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | // End signature parsing, only if needed
|
| 1095 | if ($user_cache[$poster_id]['sig'] && empty($user_cache[$poster_id]['sig_parsed'])) |
| 1096 | {
|
| 1097 | if ($user_cache[$poster_id]['sig_bbcode_bitfield']) |
| 1098 | {
|
| 1099 | $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']); |
| 1100 | } |
| 1101 | |
| 1102 | $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']); |
| 1103 | $user_cache[$poster_id]['sig'] = str_replace("\n", '<br />', censor_text($user_cache[$poster_id]['sig'])); |
| 1104 | $user_cache[$poster_id]['sig_parsed'] = TRUE; |
| 1105 | } |
| 1106 | |
| 1107 | // Parse the message and subject
|
| 1108 | $message = $row['post_text']; |
| 1109 | |
| 1110 | // If the board has HTML off but the post has HTML on then we process it, else leave it alone
|
| 1111 | if (!$auth->acl_get('f_html', $forum_id) && $row['enable_html']) |
| 1112 | {
|
| 1113 | $message = preg_replace('#(<!\-\- h \-\-><)([\/]?.*?)(><!\-\- h \-\->)#is', "<\\2>", $message); |
| 1114 | } |
| 1115 | |
| 1116 | // Second parse bbcode here
|
| 1117 | if ($row['bbcode_bitfield']) |
| 1118 | {
|
| 1119 | $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); |
| 1120 | } |
| 1121 | |
| 1122 | // Always process smilies after parsing bbcodes
|
| 1123 | $message = smiley_text($message); |
| 1124 | |
| 1125 | if (isset($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']])) |
| 1126 | {
|
| 1127 | $unset_attachments = parse_inline_attachments($message, $attachments[$row['post_id']], $update_count, $forum_id); |
| 1128 | |
| 1129 | // Needed to let not display the inlined attachments at the end of the post again
|
| 1130 | foreach ($unset_attachments as $index) |
| 1131 | {
|
| 1132 | unset($attachments[$row['post_id']][$index]); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | // Highlight active words (primarily for search)
|
| 1137 | if ($highlight_match) |
| 1138 | {
|
| 1139 | // This was shamelessly 'borrowed' from volker at multiartstudio dot de
|
| 1140 | // via php.net's annotated manual
|
| 1141 | $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . str_replace('\\', '\\\\', addslashes($highlight_match)) . ")\b#i', '<span class=\"posthilit\">\\\\1</span>', '\\0')", '>' . $message . '<'), 1, -1)); |
| 1142 | } |
| 1143 | |
| 1144 | if ($row['enable_html'] && $auth->acl_get('f_html', $forum_id)) |
| 1145 | {
|
| 1146 | // Remove Comments from post content
|
| 1147 | $message = preg_replace('#<!\-\-(.*?)\-\->#is', '', $message); |
| 1148 | } |
| 1149 | |
| 1150 | // Replace naughty words such as farty pants
|
| 1151 | $row['post_subject'] = censor_text($row['post_subject']); |
| 1152 | $message = str_replace("\n", '<br />', censor_text($message)); |
| 1153 | |
| 1154 | // Editing information
|
| 1155 | if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason']) |
| 1156 | {
|
| 1157 | // Get usernames for all following posts if not already stored
|
| 1158 | if (!sizeof($post_edit_list) && $row['post_edit_reason']) |
| 1159 | {
|
| 1160 | // Remove all post_ids already parsed (we do not have to check them)
|
| 1161 | $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i); |
| 1162 | |
| 1163 | $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour |
| 1164 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
| 1165 | WHERE p.post_id IN (' . implode(', ', $post_storage_list) . ") |
| 1166 | AND p.post_edit_count <> 0 |
| 1167 | AND p.post_edit_user <> 0 |
| 1168 | AND p.post_edit_reason <> '' |
| 1169 | AND p.post_edit_user = u.user_id";
|
| 1170 | $result2 = $db->sql_query($sql); |
| 1171 | while ($user_edit_row = $db->sql_fetchrow($result2)) |
| 1172 | {
|
| 1173 | $post_edit_list[$user_edit_row['user_id']] = $user_edit_row; |
| 1174 | } |
| 1175 | $db->sql_freeresult($result2); |
| 1176 | |
| 1177 | unset($post_storage_list); |
| 1178 | } |
| 1179 | |
| 1180 | $l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL']; |
| 1181 | |
| 1182 | if ($row['post_edit_reason']) |
| 1183 | {
|
| 1184 | $user_edit_row = $post_edit_list[$row['post_edit_user']]; |
| 1185 | $l_edited_by = sprintf($l_edit_time_total, (!$row['post_edit_user']) ? $row['poster'] : (($user_edit_row['user_colour']) ? '<span style="color:#' . $user_edit_row['user_colour'] . '">' . $user_edit_row['username'] . '</span>' : $user_edit_row['username']), $user->format_date($row['post_edit_time']), $row['post_edit_count']); |
| 1186 | } |
| 1187 | else
|
| 1188 | {
|
| 1189 | $l_edited_by = sprintf($l_edit_time_total, (!$row['post_edit_user']) ? $row['poster'] : $user_cache[$row['post_edit_user']]['username'], $user->format_date($row['post_edit_time']), $row['post_edit_count']); |
| 1190 | } |
| 1191 | } |
| 1192 | else
|
| 1193 | {
|
| 1194 | $l_edited_by = ''; |
| 1195 | } |
| 1196 | |
| 1197 | // Bump information
|
| 1198 | if ($topic_bumped && $row['post_id'] == $topic_last_post_id) |
| 1199 | {
|
| 1200 | // It is safe to grab the username from the user cache array, we are at the last
|
| 1201 | // post and only the topic poster and last poster are allowed to bump
|
| 1202 | $l_bumped_by = '<br /><br />' . sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_bumper]['username'], $user->format_date($topic_last_post_time)); |
| 1203 | } |
| 1204 | else
|
| 1205 | {
|
| 1206 | $l_bumped_by = ''; |
| 1207 | } |
| 1208 | |
| 1209 | $cp_row = array(); |
| 1210 | |
| 1211 | //
|
| 1212 | if ($config['load_cpf_viewtopic']) |
| 1213 | {
|
| 1214 | $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array(); |
| 1215 | } |
| 1216 | |
| 1217 | //
|
| 1218 | $postrow = array( |
| 1219 | 'POSTER_NAME' => $row['poster'], |
| 1220 | 'POSTER_RANK' => $user_cache[$poster_id]['rank_title'], |
| 1221 | 'RANK_IMAGE' => $user_cache[$poster_id]['rank_image'], |
| 1222 | 'POSTER_JOINED' => $user_cache[$poster_id]['joined'], |
| 1223 | 'POSTER_POSTS' => $user_cache[$poster_id]['posts'], |
| 1224 | 'POSTER_FROM' => $user_cache[$poster_id]['from'], |
| 1225 | 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'], |
| 1226 | |
| 1227 | 'POST_DATE' => $user->format_date($row['post_time']), |
| 1228 | 'POST_SUBJECT' => $row['post_subject'], |
| 1229 | 'MESSAGE' => $message, |
| 1230 | 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '', |
| 1231 | 'EDITED_MESSAGE'=> $l_edited_by, |
| 1232 | 'EDIT_REASON' => $row['post_edit_reason'], |
| 1233 | 'BUMPED_MESSAGE'=> $l_bumped_by, |
| 1234 | |
| 1235 | 'MINI_POST_IMG' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? $user->img('icon_post_new', 'NEW_POST') : $user->img('icon_post', 'POST'), |
| 1236 | 'POST_ICON_IMG' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '', |
| 1237 | 'POST_ICON_IMG_WIDTH' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '', |
| 1238 | 'POST_ICON_IMG_HEIGHT' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '', |
| 1239 | 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'], |
| 1240 | 'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('btn_online', 'ONLINE') : $user->img('btn_offline', 'OFFLINE')), |
| 1241 | |
| 1242 | 'U_EDIT' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? "posting.$phpEx$SID&mode=edit&f=$forum_id&p=" . $row['post_id'] : '', |
| 1243 | 'U_QUOTE' => ($auth->acl_get('f_quote', $forum_id)) ? "posting.$phpEx$SID&mode=quote&f=$forum_id&p=" . $row['post_id'] : '', |
| 1244 | 'U_INFO' => ($auth->acl_get('m_', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', |
| 1245 | 'U_DELETE' => (($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'] || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id)) ? "posting.$phpEx$SID&mode=delete&f=$forum_id&p=" . $row['post_id'] : '', |
| 1246 | |
| 1247 | 'U_PROFILE' => $user_cache[$poster_id]['profile'], |
| 1248 | 'U_SEARCH' => $user_cache[$poster_id]['search'], |
| 1249 | 'U_PM' => ($poster_id != ANONYMOUS) ? "{$phpbb_root_path}ucp.$phpEx$SID&i=pm&mode=compose&action=quotepost&p=" . $row['post_id'] : '', |
| 1250 | 'U_EMAIL' => $user_cache[$poster_id]['email'], |
| 1251 | 'U_WWW' => $user_cache[$poster_id]['www'], |
| 1252 | 'U_ICQ' => $user_cache[$poster_id]['icq'], |
| 1253 | 'U_AIM' => $user_cache[$poster_id]['aim'], |
| 1254 | 'U_MSN' => $user_cache[$poster_id]['msn'], |
| 1255 | 'U_YIM' => $user_cache[$poster_id]['yim'], |
| 1256 | 'U_JABBER' => $user_cache[$poster_id]['jabber'], |
| 1257 | |
| 1258 | 'U_REPORT' => "report.$phpEx$SID&p=" . $row['post_id'], |
| 1259 | 'U_MCP_REPORT' => ($auth->acl_gets('m_', 'a_', 'f_report', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', |
| 1260 | 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? "mcp.$phpEx$SID&i=queue&mode=approve&post_id_list[]=" . $row['post_id'] : '', |
| 1261 | 'U_MINI_POST' => "viewtopic.$phpEx$SID&p=" . $row['post_id'] . '#' . $row['post_id'], |
| 1262 | 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$i + 1])) ? $rowset[$i + 1]['post_id'] : '', |
| 1263 | 'U_PREV_POST_ID' => $prev_post_id, |
| 1264 | |
| 1265 | 'POST_ID' => $row['post_id'], |
| 1266 | |
| 1267 | 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? TRUE : FALSE, |
| 1268 | 'S_POST_UNAPPROVED' => ($row['post_approved']) ? FALSE : TRUE, |
| 1269 | 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE, |
| 1270 | 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], |
| 1271 | 'S_FRIEND' => ($row['friend']) ? true : false, |
| 1272 | 'S_UNREAD_POST' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? true : false, |
| 1273 | 'S_FIRST_UNREAD' => ($unread_post_id == $row['post_id']) ? true : false, |
| 1274 | 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false |
| 1275 | ); |
| 1276 | |
| 1277 | if (isset($cp_row['row']) && sizeof($cp_row['row'])) |
| 1278 | {
|
| 1279 | $postrow = array_merge($postrow, $cp_row['row']); |
| 1280 | } |
| 1281 | |
| 1282 | // Dump vars into template
|
| 1283 | $template->assign_block_vars('postrow', $postrow); |
| 1284 | |
| 1285 | if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow'])) |
| 1286 | {
|
| 1287 | foreach ($cp_row['blockrow'] as $field_data) |
| 1288 | {
|
| 1289 | $template->assign_block_vars('postrow.custom_fields', $field_data); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | // Display not already displayed Attachments for this post, we already parsed them. ;)
|
| 1294 | if (isset($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']])) |
| 1295 | {
|
| 1296 | foreach ($attachments[$row['post_id']] as $attachment) |
| 1297 | {
|
| 1298 | $template->assign_block_vars('postrow.attachment', array( |
| 1299 | 'DISPLAY_ATTACHMENT' => $attachment) |
| 1300 | ); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | $prev_post_id = $row['post_id']; |
| 1305 | |
| 1306 | unset($rowset[$i]); |
| 1307 | unset($attachments[$row['post_id']]); |
| 1308 | } |
| 1309 | unset($rowset); |
| 1310 | unset($user_cache); |
| 1311 | |
| 1312 | // Update topic view and if necessary attachment view counters ... but only
|
| 1313 | // if this is the first 'page view'
|
| 1314 | if (isset($user->data['session_page']) && !preg_match("#&t=$topic_id#", $user->data['session_page'])) |
| 1315 | {
|
| 1316 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 1317 | SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . " |
| 1318 | WHERE topic_id = $topic_id"; |
| 1319 | $db->sql_query($sql); |
| 1320 | |
| 1321 | // Update the attachment download counts
|
| 1322 | if (sizeof($update_count)) |
| 1323 | {
|
| 1324 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' |
| 1325 | SET download_count = download_count + 1 |
| 1326 | WHERE attach_id IN (' . implode(', ', array_unique($update_count)) . ')'; |
| 1327 | $db->sql_query($sql); |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | // Mark topics read
|
| 1332 | $mark_forum_id = ($topic_type == POST_GLOBAL) ? 0 : $forum_id; |
| 1333 | markread('topic', $mark_forum_id, $topic_id, $row['post_time']); |
| 1334 | |
| 1335 | // Change encoding if appropriate
|
| 1336 | if ($force_encoding != '') |
| 1337 | {
|
| 1338 | $user->lang['ENCODING'] = $force_encoding; |
| 1339 | } |
| 1340 | |
| 1341 | // Output the page
|
| 1342 | page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_title); |
| 1343 | |
| 1344 | $template->set_filenames(array( |
| 1345 | 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html') |
| 1346 | ); |
| 1347 | make_jumpbox('viewforum.'.$phpEx, $forum_id); |
| 1348 | |
| 1349 | page_footer(); |
| 1350 | |
| 1351 | |
| 1352 | // FUNCTIONS
|
| 1353 | |
| 1354 | function get_topic_last_read($topic_id, $forum_id) |
| 1355 | {
|
| 1356 | global $config, $user, $db; |
| 1357 | |
| 1358 | $topic_last_read = 0; |
| 1359 | |
| 1360 | if ($config['load_db_lastread']) |
| 1361 | {
|
| 1362 | $sql = 'SELECT mark_time |
| 1363 | FROM ' . TOPICS_TRACK_TABLE . ' |
| 1364 | WHERE user_id = ' . $user->data['user_id'] . " |
| 1365 | AND topic_id = $topic_id"; |
| 1366 | $result = $db->sql_query($sql); |
| 1367 | $row = $db->sql_fetchrow($result); |
| 1368 | $db->sql_freeresult($result); |
| 1369 | |
| 1370 | $topic_last_read = ($row) ? min($row['mark_time'], $user->data['session_last_visit']) : $user->data['session_last_visit']; |
| 1371 | |
| 1372 | if (!$row) |
| 1373 | {
|
| 1374 | $sql = 'SELECT mark_time |
| 1375 | FROM ' . FORUMS_TRACK_TABLE . ' |
| 1376 | WHERE user_id = ' . $user->data['user_id'] . " |
| 1377 | AND forum_id = $forum_id"; |
| 1378 | $result = $db->sql_query($sql); |
| 1379 | $forum_mark_time = (int) $db->sql_fetchfield('mark_time', 0, $result); |
| 1380 | $db->sql_freeresult($result); |
| 1381 | |
| 1382 | $topic_last_read = ($forum_mark_time) ? min($topic_last_read, $forum_mark_time) : $topic_last_read; |
| 1383 | } |
| 1384 | } |
| 1385 | else
|
| 1386 | {
|
| 1387 | $topic_last_read = 0; |
| 1388 | if (isset($_COOKIE[$config['cookie_name'] . '_track'])) |
| 1389 | {
|
| 1390 | $tracking_topics = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])); |
| 1391 | if (isset($tracking_topics[$forum_id])) |
| 1392 | {
|
| 1393 | $topic_last_read = base_convert(max($tracking_topics[$forum_id]), 36, 10); |
| 1394 | $topic_last_read = max($topic_last_read, $user->data['session_last_visit']); |
| 1395 | } |
| 1396 | unset($tracking_topics); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | return $topic_last_read; |
| 1401 | } |
| 1402 | |
| 1403 | ?> |

