home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April (DVD) / PCWorld_2008-04_DVD.iso / temadvd / phpbb / phpBB-2.0.22.exe / phpBB2 / viewtopic.php < prev   
Encoding:
PHP Script  |  2006-12-19  |  44.0 KB  |  1,214 lines

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