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