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