]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/viewtopic.php
Update header - remove Tech section and add Projects.
[www.vanrenterghem.biz.git] / phpBB2_old / viewtopic.php
1 <?php
2 /***************************************************************************
3  *                               viewtopic.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 13, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: viewtopic.php,v 1.186.2.37 2004/11/18 17:49:39 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
14 /***************************************************************************
15  *
16  *   This program is free software; you can redistribute it and/or modify
17  *   it under the terms of the GNU General Public License as published by
18  *   the Free Software Foundation; either version 2 of the License, or
19  *   (at your option) any later version.
20  *
21  ***************************************************************************/
23 define('IN_PHPBB', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
27 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
29 //
30 // Start initial var setup
31 //
32 $topic_id = $post_id = 0;
33 if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
34 {
35         $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
36 }
37 else if ( isset($HTTP_GET_VARS['topic']) )
38 {
39         $topic_id = intval($HTTP_GET_VARS['topic']);
40 }
42 if ( isset($HTTP_GET_VARS[POST_POST_URL]))
43 {
44         $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
45 }
48 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
50 if ( !isset($topic_id) && !isset($post_id) )
51 {
52         message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
53 }
55 //
56 // Find topic id if user requested a newer
57 // or older topic
58 //
59 if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
60 {
61         if ( $HTTP_GET_VARS['view'] == 'newest' )
62         {
63                 if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
64                 {
65                         $session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];
67                         if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
68                         {
69                                 $session_id = '';
70                         }
72                         if ( $session_id )
73                         {
74                                 $sql = "SELECT p.post_id
75                                         FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
76                                         WHERE s.session_id = '$session_id'
77                                                 AND u.user_id = s.session_user_id
78                                                 AND p.topic_id = $topic_id
79                                                 AND p.post_time >= u.user_lastvisit
80                                         ORDER BY p.post_time ASC
81                                         LIMIT 1";
82                                 if ( !($result = $db->sql_query($sql)) )
83                                 {
84                                         message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
85                                 }
87                                 if ( !($row = $db->sql_fetchrow($result)) )
88                                 {
89                                         message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
90                                 }
92                                 $post_id = $row['post_id'];
94                                 if (isset($HTTP_GET_VARS['sid']))
95                                 {
96                                         redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
97                                 }
98                                 else
99                                 {
100                                         redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
101                                 }
102                         }
103                 }
105                 redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
106         }
107         else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
108         {
109                 $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
110                 $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
112                 $sql = "SELECT t.topic_id
113                         FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
114                         WHERE
115                                 t2.topic_id = $topic_id
116                                 AND t.forum_id = t2.forum_id
117                                 AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
118                         ORDER BY t.topic_last_post_id $sql_ordering
119                         LIMIT 1";
120                 if ( !($result = $db->sql_query($sql)) )
121                 {
122                         message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
123                 }
125                 if ( $row = $db->sql_fetchrow($result) )
126                 {
127                         $topic_id = intval($row['topic_id']);
128                 }
129                 else
130                 {
131                         $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
132                         message_die(GENERAL_MESSAGE, $message);
133                 }
134         }
137 //
138 // This rather complex gaggle of code handles querying for topics but
139 // also allows for direct linking to a post (and the calculation of which
140 // page the post is on and the correct display of viewtopic)
141 //
142 $join_sql_table = ( empty($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
143 $join_sql = ( empty($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id";
144 $count_sql = ( empty($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
146 $order_sql = ( empty($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
148 $sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
149         FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
150         WHERE $join_sql
151                 AND f.forum_id = t.forum_id
152                 $order_sql";
153 if ( !($result = $db->sql_query($sql)) )
155         message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
158 if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
160         message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
163 $forum_id = intval($forum_topic_data['forum_id']);
165 //
166 // Start session management
167 //
168 $userdata = session_pagestart($user_ip, $forum_id);
169 init_userprefs($userdata);
170 //
171 // End session management
172 //
174 //
175 // Start auth check
176 //
177 $is_auth = array();
178 $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
180 if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
182         if ( !$userdata['session_logged_in'] )
183         {
184                 $redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
185                 $redirect .= ( isset($start) ) ? "&start=$start" : '';
186                 redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
187         }
189         $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
191         message_die(GENERAL_MESSAGE, $message);
193 //
194 // End auth check
195 //
197 $forum_name = $forum_topic_data['forum_name'];
198 $topic_title = $forum_topic_data['topic_title'];
199 $topic_id = intval($forum_topic_data['topic_id']);
200 $topic_time = $forum_topic_data['topic_time'];
202 if ( !empty($post_id) )
204         $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
207 //
208 // Is user watching this thread?
209 //
210 if( $userdata['session_logged_in'] )
212         $can_watch_topic = TRUE;
214         $sql = "SELECT notify_status
215                 FROM " . TOPICS_WATCH_TABLE . "
216                 WHERE topic_id = $topic_id
217                         AND user_id = " . $userdata['user_id'];
218         if ( !($result = $db->sql_query($sql)) )
219         {
220                 message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
221         }
223         if ( $row = $db->sql_fetchrow($result) )
224         {
225                 if ( isset($HTTP_GET_VARS['unwatch']) )
226                 {
227                         if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
228                         {
229                                 $is_watching_topic = 0;
231                                 $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
232                                 $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
233                                         WHERE topic_id = $topic_id
234                                                 AND user_id = " . $userdata['user_id'];
235                                 if ( !($result = $db->sql_query($sql)) )
236                                 {
237                                         message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
238                                 }
239                         }
241                         $template->assign_vars(array(
242                                 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
243                         );
245                         $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
246                         message_die(GENERAL_MESSAGE, $message);
247                 }
248                 else
249                 {
250                         $is_watching_topic = TRUE;
252                         if ( $row['notify_status'] )
253                         {
254                                 $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
255                                 $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
256                                         SET notify_status = 0
257                                         WHERE topic_id = $topic_id
258                                                 AND user_id = " . $userdata['user_id'];
259                                 if ( !($result = $db->sql_query($sql)) )
260                                 {
261                                         message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
262                                 }
263                         }
264                 }
265         }
266         else
267         {
268                 if ( isset($HTTP_GET_VARS['watch']) )
269                 {
270                         if ( $HTTP_GET_VARS['watch'] == 'topic' )
271                         {
272                                 $is_watching_topic = TRUE;
274                                 $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
275                                 $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
276                                         VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
277                                 if ( !($result = $db->sql_query($sql)) )
278                                 {
279                                         message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
280                                 }
281                         }
283                         $template->assign_vars(array(
284                                 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
285                         );
287                         $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
288                         message_die(GENERAL_MESSAGE, $message);
289                 }
290                 else
291                 {
292                         $is_watching_topic = 0;
293                 }
294         }
296 else
298         if ( isset($HTTP_GET_VARS['unwatch']) )
299         {
300                 if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
301                 {
302                         redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
303                 }
304         }
305         else
306         {
307                 $can_watch_topic = 0;
308                 $is_watching_topic = 0;
309         }
312 //
313 // Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed
314 // then get it's value, find the number of topics with dates newer than it (to properly
315 // handle pagination) and alter the main query
316 //
317 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
318 $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
320 if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
322         $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? intval($HTTP_POST_VARS['postdays']) : intval($HTTP_GET_VARS['postdays']);
323         $min_post_time = time() - (intval($post_days) * 86400);
325         $sql = "SELECT COUNT(p.post_id) AS num_posts
326                 FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
327                 WHERE t.topic_id = $topic_id
328                         AND p.topic_id = t.topic_id
329                         AND p.post_time >= $min_post_time";
330         if ( !($result = $db->sql_query($sql)) )
331         {
332                 message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
333         }
335         $total_replies = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;
337         $limit_posts_time = "AND p.post_time >= $min_post_time ";
339         if ( !empty($HTTP_POST_VARS['postdays']))
340         {
341                 $start = 0;
342         }
344 else
346         $total_replies = intval($forum_topic_data['topic_replies']) + 1;
348         $limit_posts_time = '';
349         $post_days = 0;
352 $select_post_days = '<select name="postdays">';
353 for($i = 0; $i < count($previous_days); $i++)
355         $selected = ($post_days == $previous_days[$i]) ? ' selected="selected"' : '';
356         $select_post_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
358 $select_post_days .= '</select>';
360 //
361 // Decide how to order the post display
362 //
363 if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
365         $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? htmlspecialchars($HTTP_POST_VARS['postorder']) : htmlspecialchars($HTTP_GET_VARS['postorder']);
366         $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
368 else
370         $post_order = 'asc';
371         $post_time_order = 'ASC';
374 $select_post_order = '<select name="postorder">';
375 if ( $post_time_order == 'ASC' )
377         $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
379 else
381         $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
383 $select_post_order .= '</select>';
385 //
386 // Go ahead and pull all data for this topic
387 //
388 $sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*,  pt.post_text, pt.post_subject, pt.bbcode_uid
389         FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
390         WHERE p.topic_id = $topic_id
391                 $limit_posts_time
392                 AND pt.post_id = p.post_id
393                 AND u.user_id = p.poster_id
394         ORDER BY p.post_time $post_time_order
395         LIMIT $start, ".$board_config['posts_per_page'];
396 if ( !($result = $db->sql_query($sql)) )
398         message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
401 $postrow = array();
402 if ($row = $db->sql_fetchrow($result))
404         do
405         {
406                 $postrow[] = $row;
407         }
408         while ($row = $db->sql_fetchrow($result));
409         $db->sql_freeresult($result);
411         $total_posts = count($postrow);
413 else 
414
415    include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 
416    sync('topic', $topic_id); 
418    message_die(GENERAL_MESSAGE, $lang['No_posts_topic']); 
419
421 $resync = FALSE; 
422 if ($forum_topic_data['topic_replies'] + 1 < $start + count($postrow)) 
423
424    $resync = TRUE; 
425
426 elseif ($start + $board_config['posts_per_page'] > $forum_topic_data['topic_replies']) 
427
428    $row_id = intval($forum_topic_data['topic_replies']) % intval($board_config['posts_per_page']); 
429    if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + count($postrow) < $forum_topic_data['topic_replies']) 
430    { 
431       $resync = TRUE; 
432    } 
433
434 elseif (count($postrow) < $board_config['posts_per_page']) 
435
436    $resync = TRUE; 
437
439 if ($resync) 
440
441    include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 
442    sync('topic', $topic_id); 
444    $result = $db->sql_query('SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id); 
445    $row = $db->sql_fetchrow($result); 
446    $total_replies = $row['total']; 
449 $sql = "SELECT *
450         FROM " . RANKS_TABLE . "
451         ORDER BY rank_special, rank_min";
452 if ( !($result = $db->sql_query($sql)) )
454         message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
457 $ranksrow = array();
458 while ( $row = $db->sql_fetchrow($result) )
460         $ranksrow[] = $row;
462 $db->sql_freeresult($result);
464 //
465 // Define censored word matches
466 //
467 $orig_word = array();
468 $replacement_word = array();
469 obtain_word_list($orig_word, $replacement_word);
471 //
472 // Censor topic title
473 //
474 if ( count($orig_word) )
476         $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
479 //
480 // Was a highlight request part of the URI?
481 //
482 $highlight_match = $highlight = '';
483 if (isset($HTTP_GET_VARS['highlight']))
485         // Split words and phrases
486         $words = explode(' ', trim(htmlspecialchars($HTTP_GET_VARS['highlight'])));
488         for($i = 0; $i < sizeof($words); $i++)
489         {
490                 if (trim($words[$i]) != '')
491                 {
492                         $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', phpbb_preg_quote($words[$i], '#'));
493                 }
494         }
495         unset($words);
497         $highlight = urlencode($HTTP_GET_VARS['highlight']);
500 //
501 // Post, reply and other URL generation for
502 // templating vars
503 //
504 $new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
505 $reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
506 $view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
507 $view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
508 $view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");
510 //
511 // Mozilla navigation bar
512 //
513 $nav_links['prev'] = array(
514         'url' => $view_prev_topic_url,
515         'title' => $lang['View_previous_topic']
516 );
517 $nav_links['next'] = array(
518         'url' => $view_next_topic_url,
519         'title' => $lang['View_next_topic']
520 );
521 $nav_links['up'] = array(
522         'url' => $view_forum_url,
523         'title' => $forum_name
524 );
526 $reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
527 $reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
528 $post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
529 $post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
531 //
532 // Set a cookie for this topic
533 //
534 if ( $userdata['session_logged_in'] )
536         $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
537         $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
539         if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
540         {
541                 $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
542         }
543         else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
544         {
545                 $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
546         }
547         else
548         {
549                 $topic_last_read = $userdata['user_lastvisit'];
550         }
552         if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
553         {
554                 asort($tracking_topics);
555                 unset($tracking_topics[key($tracking_topics)]);
556         }
558         $tracking_topics[$topic_id] = time();
560         setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
563 //
564 // Load templates
565 //
566 $template->set_filenames(array(
567         'body' => 'viewtopic_body.tpl')
568 );
569 make_jumpbox('viewforum.'.$phpEx, $forum_id);
571 //
572 // Output page header
573 //
574 $page_title = $lang['View_topic'] .' - ' . $topic_title;
575 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
577 //
578 // User authorisation levels output
579 //
580 $s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
581 $s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
582 $s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
583 $s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
584 $s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
586 $topic_mod = '';
588 if ( $is_auth['auth_mod'] )
590         $s_auth_can .= sprintf($lang['Rules_moderate'], "<a href=\"modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
592         $topic_mod .= "<a href=\"modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=delete&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';
594         $topic_mod .= "<a href=\"modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=move&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';
596         $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? "<a href=\"modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=lock&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" border="0" /></a>&nbsp;' : "<a href=\"modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=unlock&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';
598         $topic_mod .= "<a href=\"modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=split&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
601 //
602 // Topic watch information
603 //
604 $s_watching_topic = '';
605 if ( $can_watch_topic )
607         if ( $is_watching_topic )
608         {
609                 $s_watching_topic = "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '">' . $lang['Stop_watching_topic'] . '</a>';
610                 $s_watching_topic_img = ( isset($images['topic_un_watch']) ) ? "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
611         }
612         else
613         {
614                 $s_watching_topic = "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '">' . $lang['Start_watching_topic'] . '</a>';
615                 $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Start_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
616         }
619 //
620 // If we've got a hightlight set pass it on to pagination,
621 // I get annoyed when I lose my highlight after the first page.
622 //
623 $pagination = ( $highlight != '' ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight", $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
625 //
626 // Send vars to template
627 //
628 $template->assign_vars(array(
629         'FORUM_ID' => $forum_id,
630     'FORUM_NAME' => $forum_name,
631     'TOPIC_ID' => $topic_id,
632     'TOPIC_TITLE' => $topic_title,
633         'PAGINATION' => $pagination,
634         'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / intval($board_config['posts_per_page']) ) + 1 ), ceil( $total_replies / intval($board_config['posts_per_page']) )),
636         'POST_IMG' => $post_img,
637         'REPLY_IMG' => $reply_img,
639         'L_AUTHOR' => $lang['Author'],
640         'L_MESSAGE' => $lang['Message'],
641         'L_POSTED' => $lang['Posted'],
642         'L_POST_SUBJECT' => $lang['Post_subject'],
643         'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
644         'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
645         'L_POST_NEW_TOPIC' => $post_alt,
646         'L_POST_REPLY_TOPIC' => $reply_alt,
647         'L_BACK_TO_TOP' => $lang['Back_to_top'],
648         'L_DISPLAY_POSTS' => $lang['Display_posts'],
649         'L_LOCK_TOPIC' => $lang['Lock_topic'],
650         'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
651         'L_MOVE_TOPIC' => $lang['Move_topic'],
652         'L_SPLIT_TOPIC' => $lang['Split_topic'],
653         'L_DELETE_TOPIC' => $lang['Delete_topic'],
654         'L_GOTO_PAGE' => $lang['Goto_page'],
656         'S_TOPIC_LINK' => POST_TOPIC_URL,
657         'S_SELECT_POST_DAYS' => $select_post_days,
658         'S_SELECT_POST_ORDER' => $select_post_order,
659         'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
660         'S_AUTH_LIST' => $s_auth_can,
661         'S_TOPIC_ADMIN' => $topic_mod,
662         'S_WATCH_TOPIC' => $s_watching_topic,
663         'S_WATCH_TOPIC_IMG' => $s_watching_topic_img,
665         'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight"),
666         'U_VIEW_FORUM' => $view_forum_url,
667         'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
668         'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
669         'U_POST_NEW_TOPIC' => $new_topic_url,
670         'U_POST_REPLY_TOPIC' => $reply_topic_url)
671 );
673 //
674 // Does this topic contain a poll?
675 //
676 if ( !empty($forum_topic_data['topic_vote']) )
678         $s_hidden_fields = '';
680         $sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result
681                 FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
682                 WHERE vd.topic_id = $topic_id
683                         AND vr.vote_id = vd.vote_id
684                 ORDER BY vr.vote_option_id ASC";
685         if ( !($result = $db->sql_query($sql)) )
686         {
687                 message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
688         }
690         if ( $vote_info = $db->sql_fetchrowset($result) )
691         {
692                 $db->sql_freeresult($result);
693                 $vote_options = count($vote_info);
695                 $vote_id = $vote_info[0]['vote_id'];
696                 $vote_title = $vote_info[0]['vote_text'];
698                 $sql = "SELECT vote_id
699                         FROM " . VOTE_USERS_TABLE . "
700                         WHERE vote_id = $vote_id
701                                 AND vote_user_id = " . intval($userdata['user_id']);
702                 if ( !($result = $db->sql_query($sql)) )
703                 {
704                         message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
705                 }
707                 $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
708                 $db->sql_freeresult($result);
710                 if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
711                 {
712                         $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
713                 }
714                 else
715                 {
716                         $view_result = 0;
717                 }
719                 $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
721                 if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
722                 {
723                         $template->set_filenames(array(
724                                 'pollbox' => 'viewtopic_poll_result.tpl')
725                         );
727                         $vote_results_sum = 0;
729                         for($i = 0; $i < $vote_options; $i++)
730                         {
731                                 $vote_results_sum += $vote_info[$i]['vote_result'];
732                         }
734                         $vote_graphic = 0;
735                         $vote_graphic_max = count($images['voting_graphic']);
737                         for($i = 0; $i < $vote_options; $i++)
738                         {
739                                 $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
740                                 $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
742                                 $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
743                                 $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
745                                 if ( count($orig_word) )
746                                 {
747                                         $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
748                                 }
750                                 $template->assign_block_vars("poll_option", array(
751                                         'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
752                                         'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
753                                         'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
755                                         'POLL_OPTION_IMG' => $vote_graphic_img,
756                                         'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
757                                 );
758                         }
760                         $template->assign_vars(array(
761                                 'L_TOTAL_VOTES' => $lang['Total_votes'],
762                                 'TOTAL_VOTES' => $vote_results_sum)
763                         );
765                 }
766                 else
767                 {
768                         $template->set_filenames(array(
769                                 'pollbox' => 'viewtopic_poll_ballot.tpl')
770                         );
772                         for($i = 0; $i < $vote_options; $i++)
773                         {
774                                 if ( count($orig_word) )
775                                 {
776                                         $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
777                                 }
779                                 $template->assign_block_vars("poll_option", array(
780                                         'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
781                                         'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
782                                 );
783                         }
785                         $template->assign_vars(array(
786                                 'L_SUBMIT_VOTE' => $lang['Submit_vote'],
787                                 'L_VIEW_RESULTS' => $lang['View_results'],
789                                 'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
790                         );
792                         $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
793                 }
795                 if ( count($orig_word) )
796                 {
797                         $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
798                 }
800                 $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
802                 $template->assign_vars(array(
803                         'POLL_QUESTION' => $vote_title,
805                         'S_HIDDEN_FIELDS' => $s_hidden_fields,
806                         'S_POLL_ACTION' => append_sid("posting.$phpEx?mode=vote&amp;" . POST_TOPIC_URL . "=$topic_id"))
807                 );
809                 $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
810         }
813 //
814 // Update the topic view counter
815 //
816 $sql = "UPDATE " . TOPICS_TABLE . "
817         SET topic_views = topic_views + 1
818         WHERE topic_id = $topic_id";
819 if ( !$db->sql_query($sql) )
821         message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
824 //
825 // Okay, let's do the loop, yeah come on baby let's do the loop
826 // and it goes like this ...
827 //
828 for($i = 0; $i < $total_posts; $i++)
830         $poster_id = $postrow[$i]['user_id'];
831         $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
833         $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
835         $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
837         $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
839         $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . create_date($lang['DATE_FORMAT'], $postrow[$i]['user_regdate'], $board_config['board_timezone']) : '';
841         $poster_avatar = '';
842         if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
843         {
844                 switch( $postrow[$i]['user_avatar_type'] )
845                 {
846                         case USER_AVATAR_UPLOAD:
847                                 $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
848                                 break;
849                         case USER_AVATAR_REMOTE:
850                                 $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
851                                 break;
852                         case USER_AVATAR_GALLERY:
853                                 $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
854                                 break;
855                 }
856         }
858         //
859         // Define the little post icon
860         //
861         if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
862         {
863                 $mini_post_img = $images['icon_minipost_new'];
864                 $mini_post_alt = $lang['New_post'];
865         }
866         else
867         {
868                 $mini_post_img = $images['icon_minipost'];
869                 $mini_post_alt = $lang['Post'];
870         }
872         $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
874         //
875         // Generate ranks, set them to empty string initially.
876         //
877         $poster_rank = '';
878         $rank_image = '';
879         if ( $postrow[$i]['user_id'] == ANONYMOUS )
880         {
881         }
882         else if ( $postrow[$i]['user_rank'] )
883         {
884                 for($j = 0; $j < count($ranksrow); $j++)
885                 {
886                         if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
887                         {
888                                 $poster_rank = $ranksrow[$j]['rank_title'];
889                                 $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
890                         }
891                 }
892         }
893         else
894         {
895                 for($j = 0; $j < count($ranksrow); $j++)
896                 {
897                         if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
898                         {
899                                 $poster_rank = $ranksrow[$j]['rank_title'];
900                                 $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
901                         }
902                 }
903         }
905         //
906         // Handle anon users posting with usernames
907         //
908         if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
909         {
910                 $poster = $postrow[$i]['post_username'];
911                 $poster_rank = $lang['Guest'];
912         }
914         $temp_url = '';
916         if ( $poster_id != ANONYMOUS )
917         {
918                 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
919                 $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
920                 $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
922                 $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
923                 $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
924                 $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
926                 if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
927                 {
928                         $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];
930                         $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
931                         $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
932                 }
933                 else
934                 {
935                         $email_img = '';
936                         $email = '';
937                 }
939                 $www_img = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww"><img src="' . $images['icon_www'] . '" alt="' . $lang['Visit_website'] . '" title="' . $lang['Visit_website'] . '" border="0" /></a>' : '';
940                 $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
942                 if ( !empty($postrow[$i]['user_icq']) )
943                 {
944                         $icq_status_img = '<a href="http://wwp.icq.com/' . $postrow[$i]['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $postrow[$i]['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>';
945                         $icq_img = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '"><img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ'] . '" title="' . $lang['ICQ'] . '" border="0" /></a>';
946                         $icq =  '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
947                 }
948                 else
949                 {
950                         $icq_status_img = '';
951                         $icq_img = '';
952                         $icq = '';
953                 }
955                 $aim_img = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
956                 $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
958                 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
959                 $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
960                 $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
962                 $yim_img = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
963                 $yim = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg">' . $lang['YIM'] . '</a>' : '';
964         }
965         else
966         {
967                 $profile_img = '';
968                 $profile = '';
969                 $pm_img = '';
970                 $pm = '';
971                 $email_img = '';
972                 $email = '';
973                 $www_img = '';
974                 $www = '';
975                 $icq_status_img = '';
976                 $icq_img = '';
977                 $icq = '';
978                 $aim_img = '';
979                 $aim = '';
980                 $msn_img = '';
981                 $msn = '';
982                 $yim_img = '';
983                 $yim = '';
984         }
986         $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
987         $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
988         $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';
990         $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
991         $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>';
992         $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>';
994         if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
995         {
996                 $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
997                 $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
998                 $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
999         }
1000         else
1001         {
1002                 $edit_img = '';
1003                 $edit = '';
1004         }
1006         if ( $is_auth['auth_mod'] )
1007         {
1008                 $temp_url = "modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id . "&amp;sid=" . $userdata['session_id'];
1009                 $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
1010                 $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';
1012                 $temp_url = "posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id'];
1013                 $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
1014                 $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
1015         }
1016         else
1017         {
1018                 $ip_img = '';
1019                 $ip = '';
1021                 if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
1022                 {
1023                         $temp_url = "posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;sid=" . $userdata['session_id'];
1024                         $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
1025                         $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
1026                 }
1027                 else
1028                 {
1029                         $delpost_img = '';
1030                         $delpost = '';
1031                 }
1032         }
1034         $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
1036         $message = $postrow[$i]['post_text'];
1037         $bbcode_uid = $postrow[$i]['bbcode_uid'];
1039         $user_sig = ( $postrow[$i]['enable_sig'] && $postrow[$i]['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
1040         $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];
1042         //
1043         // Note! The order used for parsing the message _is_ important, moving things around could break any
1044         // output
1045         //
1047         //
1048         // If the board has HTML off but the post has HTML
1049         // on then we process it, else leave it alone
1050         //
1051         if ( !$board_config['allow_html'] )
1052         {
1053                 if ( $user_sig != '' && $userdata['user_allowhtml'] )
1054                 {
1055                         $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
1056                 }
1058                 if ( $postrow[$i]['enable_html'] )
1059                 {
1060                         $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
1061                 }
1062         }
1064         //
1065         // Parse message and/or sig for BBCode if reqd
1066         //
1067         if ( $board_config['allow_bbcode'] )
1068         {
1069                 if ( $user_sig != '' && $user_sig_bbcode_uid != '' )
1070                 {
1071                         $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
1072                 }
1074                 if ( $bbcode_uid != '' )
1075                 {
1076                         $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
1077                 }
1078         }
1080         if ( $user_sig != '' )
1081         {
1082                 $user_sig = make_clickable($user_sig);
1083         }
1084         $message = make_clickable($message);
1086         //
1087         // Parse smilies
1088         //
1089         if ( $board_config['allow_smilies'] )
1090         {
1091                 if ( $postrow[$i]['user_allowsmile'] && $user_sig != '' )
1092                 {
1093                         $user_sig = smilies_pass($user_sig);
1094                 }
1096                 if ( $postrow[$i]['enable_smilies'] )
1097                 {
1098                         $message = smilies_pass($message);
1099                 }
1100         }
1102         //
1103         // Highlight active words (primarily for search)
1104         //
1105         if ($highlight_match)
1106         {
1107                 // This was shamelessly 'borrowed' from volker at multiartstudio dot de
1108                 // via php.net's annotated manual
1109                 $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '<span style=\"color:#" . $theme['fontcolor3'] . "\"><b>\\\\1</b></span>', '\\0')", '>' . $message . '<'), 1, -1));
1110         }
1112         //
1113         // Replace naughty words
1114         //
1115         if (count($orig_word))
1116         {
1117                 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
1119                 if ($user_sig != '')
1120                 {
1121                         $user_sig = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
1122                 }
1124                 $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
1125         }
1127         //
1128         // Replace newlines (we use this rather than nl2br because
1129         // till recently it wasn't XHTML compliant)
1130         //
1131         if ( $user_sig != '' )
1132         {
1133                 $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
1134         }
1136         $message = str_replace("\n", "\n<br />\n", $message);
1138         //
1139         // Editing information
1140         //
1141         if ( $postrow[$i]['post_edit_count'] )
1142         {
1143                 $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
1145                 $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, $poster, create_date($board_config['default_dateformat'], $postrow[$i]['post_edit_time'], $board_config['board_timezone']), $postrow[$i]['post_edit_count']);
1146         }
1147         else
1148         {
1149                 $l_edited_by = '';
1150         }
1152         //
1153         // Again this will be handled by the templating
1154         // code at some point
1155         //
1156         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1157         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1159         $template->assign_block_vars('postrow', array(
1160                 'ROW_COLOR' => '#' . $row_color,
1161                 'ROW_CLASS' => $row_class,
1162                 'POSTER_NAME' => $poster,
1163                 'POSTER_RANK' => $poster_rank,
1164                 'RANK_IMAGE' => $rank_image,
1165                 'POSTER_JOINED' => $poster_joined,
1166                 'POSTER_POSTS' => $poster_posts,
1167                 'POSTER_FROM' => $poster_from,
1168                 'POSTER_AVATAR' => $poster_avatar,
1169                 'POST_DATE' => $post_date,
1170                 'POST_SUBJECT' => $post_subject,
1171                 'MESSAGE' => $message,
1172                 'SIGNATURE' => $user_sig,
1173                 'EDITED_MESSAGE' => $l_edited_by,
1175                 'MINI_POST_IMG' => $mini_post_img,
1176                 'PROFILE_IMG' => $profile_img,
1177                 'PROFILE' => $profile,
1178                 'SEARCH_IMG' => $search_img,
1179                 'SEARCH' => $search,
1180                 'PM_IMG' => $pm_img,
1181                 'PM' => $pm,
1182                 'EMAIL_IMG' => $email_img,
1183                 'EMAIL' => $email,
1184                 'WWW_IMG' => $www_img,
1185                 'WWW' => $www,
1186                 'ICQ_STATUS_IMG' => $icq_status_img,
1187                 'ICQ_IMG' => $icq_img,
1188                 'ICQ' => $icq,
1189                 'AIM_IMG' => $aim_img,
1190                 'AIM' => $aim,
1191                 'MSN_IMG' => $msn_img,
1192                 'MSN' => $msn,
1193                 'YIM_IMG' => $yim_img,
1194                 'YIM' => $yim,
1195                 'EDIT_IMG' => $edit_img,
1196                 'EDIT' => $edit,
1197                 'QUOTE_IMG' => $quote_img,
1198                 'QUOTE' => $quote,
1199                 'IP_IMG' => $ip_img,
1200                 'IP' => $ip,
1201                 'DELETE_IMG' => $delpost_img,
1202                 'DELETE' => $delpost,
1204                 'L_MINI_POST_ALT' => $mini_post_alt,
1206                 'U_MINI_POST' => $mini_post_url,
1207                 'U_POST_ID' => $postrow[$i]['post_id'])
1208         );
1211 $template->pparse('body');
1213 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1215 ?>