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