Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

viewtopic.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 44.12 KiB


0001  <?php
0002  /***************************************************************************
0003   *                               viewtopic.php
0004   *                            -------------------
0005   *   begin                : Saturday, Feb 13, 2001
0006   *   copyright            : (C) 2001 The phpBB Group
0007   *   email                : support@phpbb.com
0008   *
0009   *   $Id$
0010   *
0011   *
0012   ***************************************************************************/
0013   
0014  /***************************************************************************
0015   *
0016   *   This program is free software; you can redistribute it and/or modify
0017   *   it under the terms of the GNU General Public License as published by
0018   *   the Free Software Foundation; either version 2 of the License, or
0019   *   (at your option) any later version.
0020   *
0021   ***************************************************************************/
0022   
0023  define('IN_PHPBB', true);
0024  $phpbb_root_path = './';
0025  include($phpbb_root_path . 'extension.inc');
0026  include($phpbb_root_path . 'common.'.$phpEx);
0027  include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
0028   
0029  //
0030  // Start initial var setup
0031  //
0032  $topic_id = $post_id = 0;
0033  if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
0034  {
0035      $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
0036  }
0037  else if ( isset($HTTP_GET_VARS['topic']) )
0038  {
0039      $topic_id = intval($HTTP_GET_VARS['topic']);
0040  }
0041   
0042  if ( isset($HTTP_GET_VARS[POST_POST_URL]))
0043  {
0044      $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
0045  }
0046   
0047   
0048  $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
0049  $start = ($start < 0) ? 0 : $start;
0050   
0051  if (!$topic_id && !$post_id)
0052  {
0053      message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
0054  }
0055   
0056  //
0057  // Find topic id if user requested a newer
0058  // or older topic
0059  //
0060  if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
0061  {
0062      if ( $HTTP_GET_VARS['view'] == 'newest' )
0063      {
0064          if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
0065          {
0066              $session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];
0067   
0068              if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
0069              {
0070                  $session_id = '';
0071              }
0072   
0073              if ( $session_id )
0074              {
0075                  $sql = "SELECT p.post_id
0076                      FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
0077                      WHERE s.session_id = '$session_id'
0078                          AND u.user_id = s.session_user_id
0079                          AND p.topic_id = $topic_id
0080                          AND p.post_time >= u.user_lastvisit
0081                      ORDER BY p.post_time ASC
0082                      LIMIT 1";
0083                  if ( !($result = $db->sql_query($sql)) )
0084                  {
0085                      message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
0086                  }
0087   
0088                  if ( !($row = $db->sql_fetchrow($result)) )
0089                  {
0090                      message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
0091                  }
0092   
0093                  $post_id = $row['post_id'];
0094   
0095                  if (isset($HTTP_GET_VARS['sid']))
0096                  {
0097                      redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
0098                  }
0099                  else
0100                  {
0101                      redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
0102                  }
0103              }
0104          }
0105   
0106          redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
0107      }
0108      else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
0109      {
0110          $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
0111          $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
0112   
0113          $sql = "SELECT t.topic_id
0114              FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
0115              WHERE
0116                  t2.topic_id = $topic_id
0117                  AND t.forum_id = t2.forum_id
0118                  AND t.topic_moved_id = 0
0119                  AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
0120              ORDER BY t.topic_last_post_id $sql_ordering
0121              LIMIT 1";
0122          if ( !($result = $db->sql_query($sql)) )
0123          {
0124              message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
0125          }
0126   
0127          if ( $row = $db->sql_fetchrow($result) )
0128          {
0129              $topic_id = intval($row['topic_id']);
0130          }
0131          else
0132          {
0133              $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
0134              message_die(GENERAL_MESSAGE, $message);
0135          }
0136      }
0137  }
0138   
0139  //
0140  // This rather complex gaggle of code handles querying for topics but
0141  // also allows for direct linking to a post (and the calculation of which
0142  // page the post is on and the correct display of viewtopic)
0143  //
0144  $join_sql_table = (!$post_id) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
0145  $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";
0146  $count_sql = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts";
0147   
0148  $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";
0149   
0150  $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 . "
0151      FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
0152      WHERE $join_sql
0153          AND f.forum_id = t.forum_id
0154          $order_sql";
0155  if ( !($result = $db->sql_query($sql)) )
0156  {
0157      message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
0158  }
0159   
0160  if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
0161  {
0162      message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
0163  }
0164   
0165  $forum_id = intval($forum_topic_data['forum_id']);
0166   
0167  //
0168  // Start session management
0169  //
0170  $userdata = session_pagestart($user_ip, $forum_id);
0171  init_userprefs($userdata);
0172  //
0173  // End session management
0174  //
0175   
0176  //
0177  // Start auth check
0178  //
0179  $is_auth = array();
0180  $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
0181   
0182  if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
0183  {
0184      if ( !$userdata['session_logged_in'] )
0185      {
0186          $redirect = ($post_id) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
0187          $redirect .= ($start) ? "&start=$start" : '';
0188          redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
0189      }
0190   
0191      $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
0192   
0193      message_die(GENERAL_MESSAGE, $message);
0194  }
0195  //
0196  // End auth check
0197  //
0198   
0199  $forum_name = $forum_topic_data['forum_name'];
0200  $topic_title = $forum_topic_data['topic_title'];
0201  $topic_id = intval($forum_topic_data['topic_id']);
0202  $topic_time = $forum_topic_data['topic_time'];
0203   
0204  if ($post_id)
0205  {
0206      $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
0207  }
0208   
0209  //
0210  // Is user watching this thread?
0211  //
0212  if( $userdata['session_logged_in'] )
0213  {
0214      $can_watch_topic = TRUE;
0215   
0216      $sql = "SELECT notify_status
0217          FROM " . TOPICS_WATCH_TABLE . "
0218          WHERE topic_id = $topic_id
0219              AND user_id = " . $userdata['user_id'];
0220      if ( !($result = $db->sql_query($sql)) )
0221      {
0222          message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
0223      }
0224   
0225      if ( $row = $db->sql_fetchrow($result) )
0226      {
0227          if ( isset($HTTP_GET_VARS['unwatch']) )
0228          {
0229              if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
0230              {
0231                  $is_watching_topic = 0;
0232   
0233                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
0234                  $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
0235                      WHERE topic_id = $topic_id
0236                          AND user_id = " . $userdata['user_id'];
0237                  if ( !($result = $db->sql_query($sql)) )
0238                  {
0239                      message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
0240                  }
0241              }
0242   
0243              $template->assign_vars(array(
0244                  'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
0245              );
0246   
0247              $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
0248              message_die(GENERAL_MESSAGE, $message);
0249          }
0250          else
0251          {
0252              $is_watching_topic = TRUE;
0253   
0254              if ( $row['notify_status'] )
0255              {
0256                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
0257                  $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
0258                      SET notify_status = 0
0259                      WHERE topic_id = $topic_id
0260                          AND user_id = " . $userdata['user_id'];
0261                  if ( !($result = $db->sql_query($sql)) )
0262                  {
0263                      message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
0264                  }
0265              }
0266          }
0267      }
0268      else
0269      {
0270          if ( isset($HTTP_GET_VARS['watch']) )
0271          {
0272              if ( $HTTP_GET_VARS['watch'] == 'topic' )
0273              {
0274                  $is_watching_topic = TRUE;
0275   
0276                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
0277                  $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
0278                      VALUES (" . $userdata['user_id'] . "$topic_id, 0)";
0279                  if ( !($result = $db->sql_query($sql)) )
0280                  {
0281                      message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
0282                  }
0283              }
0284   
0285              $template->assign_vars(array(
0286                  'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
0287              );
0288   
0289              $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
0290              message_die(GENERAL_MESSAGE, $message);
0291          }
0292          else
0293          {
0294              $is_watching_topic = 0;
0295          }
0296      }
0297  }
0298  else
0299  {
0300      if ( isset($HTTP_GET_VARS['unwatch']) )
0301      {
0302          if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
0303          {
0304              redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
0305          }
0306      }
0307      else
0308      {
0309          $can_watch_topic = 0;
0310          $is_watching_topic = 0;
0311      }
0312  }
0313   
0314  //
0315  // Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed
0316  // then get it's value, find the number of topics with dates newer than it (to properly
0317  // handle pagination) and alter the main query
0318  //
0319  $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
0320  $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']);
0321   
0322  if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
0323  {
0324      $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? intval($HTTP_POST_VARS['postdays']) : intval($HTTP_GET_VARS['postdays']);
0325      $min_post_time = time() - (intval($post_days) * 86400);
0326   
0327      $sql = "SELECT COUNT(p.post_id) AS num_posts
0328          FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
0329          WHERE t.topic_id = $topic_id
0330              AND p.topic_id = t.topic_id
0331              AND p.post_time >= $min_post_time";
0332      if ( !($result = $db->sql_query($sql)) )
0333      {
0334          message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
0335      }
0336   
0337      $total_replies = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;
0338   
0339      $limit_posts_time = "AND p.post_time >= $min_post_time ";
0340   
0341      if ( !empty($HTTP_POST_VARS['postdays']))
0342      {
0343          $start = 0;
0344      }
0345  }
0346  else
0347  {
0348      $total_replies = intval($forum_topic_data['topic_replies']) + 1;
0349   
0350      $limit_posts_time = '';
0351      $post_days = 0;
0352  }
0353   
0354  $select_post_days = '<select name="postdays">';
0355  for($i = 0; $i < count($previous_days); $i++)
0356  {
0357      $selected = ($post_days == $previous_days[$i]) ? ' selected="selected"' : '';
0358      $select_post_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
0359  }
0360  $select_post_days .= '</select>';
0361   
0362  //
0363  // Decide how to order the post display
0364  //
0365  if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
0366  {
0367      $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? htmlspecialchars($HTTP_POST_VARS['postorder']) : htmlspecialchars($HTTP_GET_VARS['postorder']);
0368      $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
0369  }
0370  else
0371  {
0372      $post_order = 'asc';
0373      $post_time_order = 'ASC';
0374  }
0375   
0376  $select_post_order = '<select name="postorder">';
0377  if ( $post_time_order == 'ASC' )
0378  {
0379      $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
0380  }
0381  else
0382  {
0383      $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
0384  }
0385  $select_post_order .= '</select>';
0386   
0387  //
0388  // Go ahead and pull all data for this topic
0389  //
0390  $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
0391      FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
0392      WHERE p.topic_id = $topic_id
0393          $limit_posts_time
0394          AND pt.post_id = p.post_id
0395          AND u.user_id = p.poster_id
0396      ORDER BY p.post_time $post_time_order
0397      LIMIT $start".$board_config['posts_per_page'];
0398  if ( !($result = $db->sql_query($sql)) )
0399  {
0400      message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
0401  }
0402   
0403  $postrow = array();
0404  if ($row = $db->sql_fetchrow($result))
0405  {
0406      do
0407      {
0408          $postrow[] = $row;
0409      }
0410      while ($row = $db->sql_fetchrow($result));
0411      $db->sql_freeresult($result);
0412   
0413      $total_posts = count($postrow);
0414  }
0415  else 
0416  { 
0417     include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 
0418     sync('topic', $topic_id); 
0419   
0420     message_die(GENERAL_MESSAGE, $lang['No_posts_topic']); 
0421  } 
0422   
0423  $resync = FALSE; 
0424  if ($forum_topic_data['topic_replies'] + 1 < $start + count($postrow)) 
0425  { 
0426     $resync = TRUE; 
0427  } 
0428  elseif ($start + $board_config['posts_per_page'] > $forum_topic_data['topic_replies']) 
0429  { 
0430     $row_id = intval($forum_topic_data['topic_replies']) % intval($board_config['posts_per_page']); 
0431     if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + count($postrow) < $forum_topic_data['topic_replies']) 
0432     { 
0433        $resync = TRUE; 
0434     } 
0435  } 
0436  elseif (count($postrow) < $board_config['posts_per_page']) 
0437  { 
0438     $resync = TRUE; 
0439  } 
0440   
0441  if ($resync) 
0442  { 
0443     include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 
0444     sync('topic', $topic_id); 
0445   
0446     $result = $db->sql_query('SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id); 
0447     $row = $db->sql_fetchrow($result); 
0448     $total_replies = $row['total']; 
0449  }
0450   
0451  $sql = "SELECT *
0452      FROM " . RANKS_TABLE . "
0453      ORDER BY rank_special, rank_min";
0454  if ( !($result = $db->sql_query($sql)) )
0455  {
0456      message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
0457  }
0458   
0459  $ranksrow = array();
0460  while ( $row = $db->sql_fetchrow($result) )
0461  {
0462      $ranksrow[] = $row;
0463  }
0464  $db->sql_freeresult($result);
0465   
0466  //
0467  // Define censored word matches
0468  //
0469  $orig_word = array();
0470  $replacement_word = array();
0471  obtain_word_list($orig_word, $replacement_word);
0472   
0473  //
0474  // Censor topic title
0475  //
0476  if ( count($orig_word) )
0477  {
0478      $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
0479  }
0480   
0481  //
0482  // Was a highlight request part of the URI?
0483  //
0484  $highlight_match = $highlight = '';
0485  if (isset($HTTP_GET_VARS['highlight']))
0486  {
0487      // Split words and phrases
0488      $words = explode(' ', trim(htmlspecialchars($HTTP_GET_VARS['highlight'])));
0489   
0490      for($i = 0; $i < sizeof($words); $i++)
0491      {
0492          if (trim($words[$i]) != '')
0493          {
0494              $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', preg_quote($words[$i], '#'));
0495          }
0496      }
0497      unset($words);
0498   
0499      $highlight = urlencode($HTTP_GET_VARS['highlight']);
0500      $highlight_match = phpbb_rtrim($highlight_match, "\\");
0501  }
0502   
0503  //
0504  // Post, reply and other URL generation for
0505  // templating vars
0506  //
0507  $new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
0508  $reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
0509  $view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
0510  $view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
0511  $view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");
0512   
0513  //
0514  // Mozilla navigation bar
0515  //
0516  $nav_links['prev'] = array(
0517      'url' => $view_prev_topic_url,
0518      'title' => $lang['View_previous_topic']
0519  );
0520  $nav_links['next'] = array(
0521      'url' => $view_next_topic_url,
0522      'title' => $lang['View_next_topic']
0523  );
0524  $nav_links['up'] = array(
0525      'url' => $view_forum_url,
0526      'title' => $forum_name
0527  );
0528   
0529  $reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
0530  $reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
0531  $post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
0532  $post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
0533   
0534  //
0535  // Set a cookie for this topic
0536  //
0537  if ( $userdata['session_logged_in'] )
0538  {
0539      $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
0540      $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
0541   
0542      if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
0543      {
0544          $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
0545      }
0546      else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
0547      {
0548          $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
0549      }
0550      else
0551      {
0552          $topic_last_read = $userdata['user_lastvisit'];
0553      }
0554   
0555      if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
0556      {
0557          asort($tracking_topics);
0558          unset($tracking_topics[key($tracking_topics)]);
0559      }
0560   
0561      $tracking_topics[$topic_id] = time();
0562   
0563      setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
0564  }
0565   
0566  //
0567  // Load templates
0568  //
0569  $template->set_filenames(array(
0570      'body' => 'viewtopic_body.tpl')
0571  );
0572  make_jumpbox('viewforum.'.$phpEx, $forum_id);
0573   
0574  //
0575  // Output page header
0576  //
0577  $page_title = $lang['View_topic'] .' - ' . $topic_title;
0578  include($phpbb_root_path . 'includes/page_header.'.$phpEx);
0579   
0580  //
0581  // User authorisation levels output
0582  //
0583  $s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
0584  $s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
0585  $s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
0586  $s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
0587  $s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
0588   
0589  $topic_mod = '';
0590   
0591  if ( $is_auth['auth_mod'] )
0592  {
0593      $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;p_sid=" . $userdata['priv_session_id']) . '">', '</a>');
0594   
0595      $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=delete&amp;p_sid=" . $userdata['priv_session_id']) . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';
0596   
0597      $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=move&amp;p_sid=" . $userdata['priv_session_id']) . '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';
0598   
0599      $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=lock&amp;p_sid=" . $userdata['priv_session_id']) . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" border="0" /></a>&nbsp;' : '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=unlock&amp;p_sid=" . $userdata['priv_session_id']) . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';
0600   
0601      $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=split&amp;p_sid=" . $userdata['priv_session_id']) . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
0602  }
0603   
0604  //
0605  // Topic watch information
0606  //
0607  $s_watching_topic = '';
0608  if ( $can_watch_topic )
0609  {
0610      if ( $is_watching_topic )
0611      {
0612          $s_watching_topic = "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '">' . $lang['Stop_watching_topic'] . '</a>';
0613          $s_watching_topic_img = ( isset($images['topic_un_watch']) ) ? "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
0614      }
0615      else
0616      {
0617          $s_watching_topic = "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '">' . $lang['Start_watching_topic'] . '</a>';
0618          $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Start_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
0619      }
0620  }
0621   
0622  //
0623  // If we've got a hightlight set pass it on to pagination,
0624  // I get annoyed when I lose my highlight after the first page.
0625  //
0626  $pagination = ( $highlight != '' ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight", $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
0627   
0628  //
0629  // Send vars to template
0630  //
0631  $template->assign_vars(array(
0632      'FORUM_ID' => $forum_id,
0633      'FORUM_NAME' => $forum_name,
0634      'TOPIC_ID' => $topic_id,
0635      'TOPIC_TITLE' => $topic_title,
0636      'PAGINATION' => $pagination,
0637      'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / intval($board_config['posts_per_page']) ) + 1 ), ceil( $total_replies / intval($board_config['posts_per_page']) )),
0638   
0639      'POST_IMG' => $post_img,
0640      'REPLY_IMG' => $reply_img,
0641   
0642      'L_AUTHOR' => $lang['Author'],
0643      'L_MESSAGE' => $lang['Message'],
0644      'L_POSTED' => $lang['Posted'],
0645      'L_POST_SUBJECT' => $lang['Post_subject'],
0646      'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
0647      'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
0648      'L_POST_NEW_TOPIC' => $post_alt,
0649      'L_POST_REPLY_TOPIC' => $reply_alt,
0650      'L_BACK_TO_TOP' => $lang['Back_to_top'],
0651      'L_DISPLAY_POSTS' => $lang['Display_posts'],
0652      'L_LOCK_TOPIC' => $lang['Lock_topic'],
0653      'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
0654      'L_MOVE_TOPIC' => $lang['Move_topic'],
0655      'L_SPLIT_TOPIC' => $lang['Split_topic'],
0656      'L_DELETE_TOPIC' => $lang['Delete_topic'],
0657      'L_GOTO_PAGE' => $lang['Goto_page'],
0658   
0659      'S_TOPIC_LINK' => POST_TOPIC_URL,
0660      'S_SELECT_POST_DAYS' => $select_post_days,
0661      'S_SELECT_POST_ORDER' => $select_post_order,
0662      'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
0663      'S_AUTH_LIST' => $s_auth_can,
0664      'S_TOPIC_ADMIN' => $topic_mod,
0665      'S_WATCH_TOPIC' => $s_watching_topic,
0666      'S_WATCH_TOPIC_IMG' => $s_watching_topic_img,
0667   
0668      'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=$highlight"),
0669      'U_VIEW_FORUM' => $view_forum_url,
0670      'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
0671      'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
0672      'U_POST_NEW_TOPIC' => $new_topic_url,
0673      'U_POST_REPLY_TOPIC' => $reply_topic_url)
0674  );
0675   
0676  //
0677  // Does this topic contain a poll?
0678  //
0679  if ( !empty($forum_topic_data['topic_vote']) )
0680  {
0681      $s_hidden_fields = '';
0682   
0683      $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
0684          FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
0685          WHERE vd.topic_id = $topic_id
0686              AND vr.vote_id = vd.vote_id
0687          ORDER BY vr.vote_option_id ASC";
0688      if ( !($result = $db->sql_query($sql)) )
0689      {
0690          message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
0691      }
0692   
0693      if ( $vote_info = $db->sql_fetchrowset($result) )
0694      {
0695          $db->sql_freeresult($result);
0696          $vote_options = count($vote_info);
0697   
0698          $vote_id = $vote_info[0]['vote_id'];
0699          $vote_title = $vote_info[0]['vote_text'];
0700   
0701          $sql = "SELECT vote_id
0702              FROM " . VOTE_USERS_TABLE . "
0703              WHERE vote_id = $vote_id
0704                  AND vote_user_id = " . intval($userdata['user_id']);
0705          if ( !($result = $db->sql_query($sql)) )
0706          {
0707              message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
0708          }
0709   
0710          $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
0711          $db->sql_freeresult($result);
0712   
0713          if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
0714          {
0715              $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
0716          }
0717          else
0718          {
0719              $view_result = 0;
0720          }
0721   
0722          $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
0723   
0724          if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
0725          {
0726              $template->set_filenames(array(
0727                  'pollbox' => 'viewtopic_poll_result.tpl')
0728              );
0729   
0730              $vote_results_sum = 0;
0731   
0732              for($i = 0; $i < $vote_options; $i++)
0733              {
0734                  $vote_results_sum += $vote_info[$i]['vote_result'];
0735              }
0736   
0737              $vote_graphic = 0;
0738              $vote_graphic_max = count($images['voting_graphic']);
0739   
0740              for($i = 0; $i < $vote_options; $i++)
0741              {
0742                  $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
0743                  $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
0744   
0745                  $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
0746                  $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
0747   
0748                  if ( count($orig_word) )
0749                  {
0750                      $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
0751                  }
0752   
0753                  $template->assign_block_vars("poll_option", array(
0754                      'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
0755                      'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
0756                      'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
0757   
0758                      'POLL_OPTION_IMG' => $vote_graphic_img,
0759                      'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
0760                  );
0761              }
0762   
0763              $template->assign_vars(array(
0764                  'L_TOTAL_VOTES' => $lang['Total_votes'],
0765                  'TOTAL_VOTES' => $vote_results_sum)
0766              );
0767   
0768          }
0769          else
0770          {
0771              $template->set_filenames(array(
0772                  'pollbox' => 'viewtopic_poll_ballot.tpl')
0773              );
0774   
0775              for($i = 0; $i < $vote_options; $i++)
0776              {
0777                  if ( count($orig_word) )
0778                  {
0779                      $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
0780                  }
0781   
0782                  $template->assign_block_vars("poll_option", array(
0783                      'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
0784                      'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
0785                  );
0786              }
0787   
0788              $template->assign_vars(array(
0789                  'L_SUBMIT_VOTE' => $lang['Submit_vote'],
0790                  'L_VIEW_RESULTS' => $lang['View_results'],
0791   
0792                  'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
0793              );
0794   
0795              $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
0796          }
0797   
0798          if ( count($orig_word) )
0799          {
0800              $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
0801          }
0802   
0803          $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
0804   
0805          $template->assign_vars(array(
0806              'POLL_QUESTION' => $vote_title,
0807   
0808              'S_HIDDEN_FIELDS' => $s_hidden_fields,
0809              'S_POLL_ACTION' => append_sid("posting.$phpEx?mode=vote&amp;" . POST_TOPIC_URL . "=$topic_id"))
0810          );
0811   
0812          $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
0813      }
0814  }
0815   
0816  //
0817  // Update the topic view counter
0818  //
0819  $sql = "UPDATE " . TOPICS_TABLE . "
0820      SET topic_views = topic_views + 1
0821      WHERE topic_id = $topic_id";
0822  if ( !$db->sql_query($sql) )
0823  {
0824      message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
0825  }
0826   
0827  //
0828  // Okay, let's do the loop, yeah come on baby let's do the loop
0829  // and it goes like this ...
0830  //
0831  for($i = 0; $i < $total_posts; $i++)
0832  {
0833      $poster_id = $postrow[$i]['user_id'];
0834      $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
0835   
0836      $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
0837   
0838      $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
0839   
0840      $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
0841   
0842      $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . create_date($lang['DATE_FORMAT'], $postrow[$i]['user_regdate'], $board_config['board_timezone']) : '';
0843   
0844      $poster_avatar = '';
0845      if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
0846      {
0847          switch( $postrow[$i]['user_avatar_type'] )
0848          {
0849              case USER_AVATAR_UPLOAD:
0850                  $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
0851                  break;
0852              case USER_AVATAR_REMOTE:
0853                  $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
0854                  break;
0855              case USER_AVATAR_GALLERY:
0856                  $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
0857                  break;
0858          }
0859      }
0860   
0861      //
0862      // Define the little post icon
0863      //
0864      if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
0865      {
0866          $mini_post_img = $images['icon_minipost_new'];
0867          $mini_post_alt = $lang['New_post'];
0868      }
0869      else
0870      {
0871          $mini_post_img = $images['icon_minipost'];
0872          $mini_post_alt = $lang['Post'];
0873      }
0874   
0875      $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
0876   
0877      //
0878      // Generate ranks, set them to empty string initially.
0879      //
0880      $poster_rank = '';
0881      $rank_image = '';
0882      if ( $postrow[$i]['user_id'] == ANONYMOUS )
0883      {
0884      }
0885      else if ( $postrow[$i]['user_rank'] )
0886      {
0887          for($j = 0; $j < count($ranksrow); $j++)
0888          {
0889              if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
0890              {
0891                  $poster_rank = $ranksrow[$j]['rank_title'];
0892                  $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
0893              }
0894          }
0895      }
0896      else
0897      {
0898          for($j = 0; $j < count($ranksrow); $j++)
0899          {
0900              if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
0901              {
0902                  $poster_rank = $ranksrow[$j]['rank_title'];
0903                  $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
0904              }
0905          }
0906      }
0907   
0908      //
0909      // Handle anon users posting with usernames
0910      //
0911      if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
0912      {
0913          $poster = $postrow[$i]['post_username'];
0914          $poster_rank = $lang['Guest'];
0915      }
0916   
0917      $temp_url = '';
0918   
0919      if ( $poster_id != ANONYMOUS )
0920      {
0921          $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
0922          $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
0923          $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
0924   
0925          $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
0926          $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
0927          $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
0928   
0929          if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
0930          {
0931              $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];
0932   
0933              $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
0934              $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
0935          }
0936          else
0937          {
0938              $email_img = '';
0939              $email = '';
0940          }
0941   
0942          $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>' : '';
0943          $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
0944   
0945          if ( !empty($postrow[$i]['user_icq']) )
0946          {
0947              $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>';
0948              $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>';
0949              $icq =  '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
0950          }
0951          else
0952          {
0953              $icq_status_img = '';
0954              $icq_img = '';
0955              $icq = '';
0956          }
0957   
0958          $aim_img = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
0959          $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
0960   
0961          $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
0962          $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
0963          $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
0964   
0965          $yim_img = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
0966          $yim = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg">' . $lang['YIM'] . '</a>' : '';
0967      }
0968      else
0969      {
0970          $profile_img = '';
0971          $profile = '';
0972          $pm_img = '';
0973          $pm = '';
0974          $email_img = '';
0975          $email = '';
0976          $www_img = '';
0977          $www = '';
0978          $icq_status_img = '';
0979          $icq_img = '';
0980          $icq = '';
0981          $aim_img = '';
0982          $aim = '';
0983          $msn_img = '';
0984          $msn = '';
0985          $yim_img = '';
0986          $yim = '';
0987      }
0988   
0989      $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
0990      $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
0991      $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';
0992   
0993      $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
0994      $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>';
0995      $search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '</a>';
0996   
0997      if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
0998      {
0999          $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
1000          $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
1001          $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
1002      }
1003      else
1004      {
1005          $edit_img = '';
1006          $edit = '';
1007      }
1008   
1009      if ( $is_auth['auth_mod'] )
1010      {
1011          $temp_url = "modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id . "&amp;p_sid=" . $userdata['priv_session_id'];
1012          $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
1013          $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';
1014   
1015          $temp_url = "posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;p_sid=" . $userdata['priv_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="' . append_sid($temp_url) . '">' . $lang['Delete_post'] . '</a>';
1018      }
1019      else
1020      {
1021          $ip_img = '';
1022          $ip = '';
1023   
1024          if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
1025          {
1026              $temp_url = "posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;p_sid=" . $userdata['priv_session_id'];
1027              $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
1028              $delpost = '<a href="' . append_sid($temp_url) . '">' . $lang['Delete_post'] . '</a>';
1029          }
1030          else
1031          {
1032              $delpost_img = '';
1033              $delpost = '';
1034          }
1035      }
1036   
1037      $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
1038   
1039      $message = $postrow[$i]['post_text'];
1040      $bbcode_uid = $postrow[$i]['bbcode_uid'];
1041   
1042      $user_sig = ( $postrow[$i]['enable_sig'] && $postrow[$i]['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
1043      $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];
1044   
1045      //
1046      // Note! The order used for parsing the message _is_ important, moving things around could break any
1047      // output
1048      //
1049   
1050      //
1051      // If the board has HTML off but the post has HTML
1052      // on then we process it, else leave it alone
1053      //
1054      if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
1055      {
1056          if ( $user_sig != '' )
1057          {
1058              $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
1059          }
1060   
1061          if ( $postrow[$i]['enable_html'] )
1062          {
1063              $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
1064          }
1065      }
1066   
1067      //
1068      // Parse message and/or sig for BBCode if reqd
1069      //
1070      if ($user_sig != '' && $user_sig_bbcode_uid != '')
1071      {
1072          $user_sig = ($board_config['allow_bbcode']) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace("/\:$user_sig_bbcode_uid/si", '', $user_sig);
1073      }
1074   
1075      if ($bbcode_uid != '')
1076      {
1077          $message = ($board_config['allow_bbcode']) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $message);
1078      }
1079   
1080      if ( $user_sig != '' )
1081      {
1082          $user_sig = make_clickable($user_sig);
1083      }
1084      $message = make_clickable($message);
1085   
1086      //
1087      // Parse smilies
1088      //
1089      if ( $board_config['allow_smilies'] )
1090      {
1091          if ( $postrow[$i]['user_allowsmile'] && $user_sig != '' )
1092          {
1093              $user_sig = smilies_pass($user_sig);
1094          }
1095   
1096          if ( $postrow[$i]['enable_smilies'] )
1097          {
1098              $message = smilies_pass($message);
1099          }
1100      }
1101   
1102      //
1103      // Highlight active words (primarily for search)
1104      //
1105      if ($highlight_match)
1106      {
1107          // This has been back-ported from 3.0 CVS
1108          $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*>)#i', '<b style="color:#'.$theme['fontcolor3'].'">\1</b>', $message);
1109      }
1110   
1111      //
1112      // Replace naughty words
1113      //
1114      if (count($orig_word))
1115      {
1116          $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
1117   
1118          if ($user_sig != '')
1119          {
1120              $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
1121          }
1122   
1123          $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
1124      }
1125   
1126      //
1127      // Replace newlines (we use this rather than nl2br because
1128      // till recently it wasn't XHTML compliant)
1129      //
1130      if ( $user_sig != '' )
1131      {
1132          $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
1133      }
1134   
1135      $message = str_replace("\n", "\n<br />\n", $message);
1136   
1137      //
1138      // Editing information
1139      //
1140      if ( $postrow[$i]['post_edit_count'] )
1141      {
1142          $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
1143   
1144          $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']);
1145      }
1146      else
1147      {
1148          $l_edited_by = '';
1149      }
1150   
1151      //
1152      // Again this will be handled by the templating
1153      // code at some point
1154      //
1155      $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1156      $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1157   
1158      $template->assign_block_vars('postrow', array(
1159          'ROW_COLOR' => '#' . $row_color,
1160          'ROW_CLASS' => $row_class,
1161          'POSTER_NAME' => $poster,
1162          'POSTER_RANK' => $poster_rank,
1163          'RANK_IMAGE' => $rank_image,
1164          'POSTER_JOINED' => $poster_joined,
1165          'POSTER_POSTS' => $poster_posts,
1166          'POSTER_FROM' => $poster_from,
1167          'POSTER_AVATAR' => $poster_avatar,
1168          'POST_DATE' => $post_date,
1169          'POST_SUBJECT' => $post_subject,
1170          'MESSAGE' => $message,
1171          'SIGNATURE' => $user_sig,
1172          'EDITED_MESSAGE' => $l_edited_by,
1173   
1174          'MINI_POST_IMG' => $mini_post_img,
1175          'PROFILE_IMG' => $profile_img,
1176          'PROFILE' => $profile,
1177          'SEARCH_IMG' => $search_img,
1178          'SEARCH' => $search,
1179          'PM_IMG' => $pm_img,
1180          'PM' => $pm,
1181          'EMAIL_IMG' => $email_img,
1182          'EMAIL' => $email,
1183          'WWW_IMG' => $www_img,
1184          'WWW' => $www,
1185          'ICQ_STATUS_IMG' => $icq_status_img,
1186          'ICQ_IMG' => $icq_img,
1187          'ICQ' => $icq,
1188          'AIM_IMG' => $aim_img,
1189          'AIM' => $aim,
1190          'MSN_IMG' => $msn_img,
1191          'MSN' => $msn,
1192          'YIM_IMG' => $yim_img,
1193          'YIM' => $yim,
1194          'EDIT_IMG' => $edit_img,
1195          'EDIT' => $edit,
1196          'QUOTE_IMG' => $quote_img,
1197          'QUOTE' => $quote,
1198          'IP_IMG' => $ip_img,
1199          'IP' => $ip,
1200          'DELETE_IMG' => $delpost_img,
1201          'DELETE' => $delpost,
1202   
1203          'L_MINI_POST_ALT' => $mini_post_alt,
1204   
1205          'U_MINI_POST' => $mini_post_url,
1206          'U_POST_ID' => $postrow[$i]['post_id'])
1207      );
1208  }
1209   
1210  $template->pparse('body');
1211   
1212  include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1213   
1214  ?>