[ Index ]
 

Code source de PHP NUKE 7.9

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Forums/ -> viewtopic.php (source)

   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  if ( !defined('MODULE_FILE') )
  23  {
  24      die("You can't access this file directly...");
  25  }
  26  if (!(isset($popup)) OR ($popup != "1"))
  27      {
  28          $module_name = basename(dirname(__FILE__));
  29          require("modules/".$module_name."/nukebb.php");
  30      }
  31      else
  32      {
  33          $phpbb_root_path = 'modules/Forums/';
  34      }
  35  
  36  define('IN_PHPBB', true);
  37  include ($phpbb_root_path . 'extension.inc');
  38  include($phpbb_root_path . 'common.'.$phpEx);
  39  include_once ("includes/bbcode.php");
  40  
  41  //

  42  // Start initial var setup

  43  //

  44  $topic_id = $post_id = 0;
  45  if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
  46  {
  47          $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
  48  }
  49  else if ( isset($HTTP_GET_VARS['topic']) )
  50  {
  51          $topic_id = intval($HTTP_GET_VARS['topic']);
  52  }
  53  
  54  if ( isset($HTTP_GET_VARS[POST_POST_URL]))
  55  {
  56          $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
  57  }
  58  
  59  $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  60  
  61  if ( !isset($topic_id) && !isset($post_id) )
  62  {
  63          message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
  64  }
  65  
  66  //

  67  // Find topic id if user requested a newer

  68  // or older topic

  69  //

  70  if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
  71  {
  72          if ( $HTTP_GET_VARS['view'] == 'newest' )
  73          {
  74                  $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', $_SERVER['SERVER_SOFTWARE']) ) ? 'Refresh: 0; URL=' : 'Location: ';
  75  
  76                  if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
  77                  {
  78                          $session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];
  79                          if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
  80                          {
  81                          $session_id = '';
  82                          }
  83                          if ( $session_id )
  84                          {
  85                                  $sql = "SELECT p.post_id
  86                                          FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
  87                                          WHERE s.session_id = '$session_id'
  88                                                  AND u.user_id = s.session_user_id
  89                                                  AND p.topic_id = '$topic_id'
  90                                                  AND p.post_time >= u.user_lastvisit
  91                                          ORDER BY p.post_time ASC
  92                                          LIMIT 1";
  93                                  if ( !($result = $db->sql_query($sql)) )
  94                                  {
  95                                          message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
  96                                  }
  97  
  98                                  if ( !($row = $db->sql_fetchrow($result)) )
  99                                  {
 100                                          message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
 101                                  }
 102  
 103                                  $post_id = $row['post_id'];
 104                                  header($header_location . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
 105                                  exit;
 106                          }
 107                  }
 108  
 109                  header($header_location . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
 110                  exit;
 111          }
 112          else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
 113          {
 114                  $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
 115                  $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
 116  
 117                  $sql = "SELECT t.topic_id
 118              FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
 119              WHERE
 120                  t2.topic_id = '$topic_id'
 121                  AND t.forum_id = t2.forum_id
 122                  AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
 123              ORDER BY t.topic_last_post_id $sql_ordering
 124                          LIMIT 1";
 125                  if ( !($result = $db->sql_query($sql)) )
 126                  {
 127                          message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
 128                  }
 129  
 130                  if ( $row = $db->sql_fetchrow($result) )
 131                  {
 132                          $topic_id = intval($row['topic_id']);
 133                  }
 134                  else
 135                  {
 136                          $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
 137                          message_die(GENERAL_MESSAGE, $message);
 138                  }
 139          }
 140  }
 141  
 142  //

 143  // This rather complex gaggle of code handles querying for topics but

 144  // also allows for direct linking to a post (and the calculation of which

 145  // page the post is on and the correct display of viewtopic)

 146  //

 147  $join_sql_table = ( empty($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
 148  $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'";
 149  $count_sql = ( empty($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
 150  
 151  $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";
 152  
 153  $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 . "
 154          FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
 155          WHERE $join_sql
 156                  AND f.forum_id = t.forum_id
 157                  $order_sql";
 158  if ( !($result = $db->sql_query($sql)) )
 159  {
 160          message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
 161  }
 162  
 163  if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
 164  {
 165          message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
 166  }
 167  
 168  $forum_id = intval($forum_topic_data['forum_id']);
 169  
 170  //

 171  // Start session management

 172  //

 173  $userdata = session_pagestart($user_ip, $forum_id, $nukeuser);
 174  init_userprefs($userdata);
 175  //

 176  // End session management

 177  //

 178  
 179  //

 180  // Start auth check

 181  //

 182  $is_auth = array();
 183  $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
 184  
 185  if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
 186  {
 187          if ( !$userdata['session_logged_in'] )
 188          {
 189                  $redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
 190                  $redirect .= ( isset($start) ) ? "&start=$start" : '';
 191                  $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", $_SERVER["SERVER_SOFTWARE"]) ) ? "Refresh: 0; URL=" : "Location: ";
 192                  header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
 193                  exit;
 194          }
 195  
 196          $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
 197  
 198          message_die(GENERAL_MESSAGE, $message);
 199  }
 200  //

 201  // End auth check

 202  //

 203  
 204  $forum_name = $forum_topic_data['forum_name'];
 205  $topic_title = $forum_topic_data['topic_title'];
 206  $topic_id = intval($forum_topic_data['topic_id']);
 207  $topic_time = $forum_topic_data['topic_time'];
 208  
 209  if ( !empty($post_id) )
 210  {
 211          $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
 212  }
 213  
 214  //

 215  // Is user watching this thread?

 216  //

 217  if( $userdata['session_logged_in'] )
 218  {
 219          $can_watch_topic = TRUE;
 220  
 221          $sql = "SELECT notify_status
 222                  FROM " . TOPICS_WATCH_TABLE . "
 223                  WHERE topic_id = '$topic_id'
 224                          AND user_id = " . $userdata['user_id'];
 225          if ( !($result = $db->sql_query($sql)) )
 226          {
 227                  message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
 228          }
 229  
 230          if ( $row = $db->sql_fetchrow($result) )
 231          {
 232                  if ( isset($HTTP_GET_VARS['unwatch']) )
 233                  {
 234                          if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
 235                          {
 236                                  $is_watching_topic = 0;
 237  
 238                                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
 239                                  $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
 240                                          WHERE topic_id = '$topic_id'
 241                                                  AND user_id = " . $userdata['user_id'];
 242                                  if ( !($result = $db->sql_query($sql)) )
 243                                  {
 244                                          message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
 245                                  }
 246                          }
 247  
 248                          $template->assign_vars(array(
 249                                  'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
 250                          );
 251  
 252                          $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>');
 253                          message_die(GENERAL_MESSAGE, $message);
 254                  }
 255                  else
 256                  {
 257                          $is_watching_topic = TRUE;
 258  
 259                          if ( $row['notify_status'] )
 260                          {
 261                                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
 262                                  $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
 263                                          SET notify_status = '0'
 264                                          WHERE topic_id = '$topic_id'
 265                                                  AND user_id = " . $userdata['user_id'];
 266                                  if ( !($result = $db->sql_query($sql)) )
 267                                  {
 268                                          message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
 269                                  }
 270                          }
 271                  }
 272          }
 273          else
 274          {
 275                  if ( isset($HTTP_GET_VARS['watch']) )
 276                  {
 277                          if ( $HTTP_GET_VARS['watch'] == 'topic' )
 278                          {
 279                                  $is_watching_topic = TRUE;
 280  
 281                                  $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
 282                                  $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
 283                                          VALUES (" . $userdata['user_id'] . ", '$topic_id', '0')";
 284                                  if ( !($result = $db->sql_query($sql)) )
 285                                  {
 286                                          message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
 287                                  }
 288                          }
 289  
 290                          $template->assign_vars(array(
 291                                  'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
 292                          );
 293  
 294                          $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>');
 295                          message_die(GENERAL_MESSAGE, $message);
 296                  }
 297                  else
 298                  {
 299                          $is_watching_topic = 0;
 300                  }
 301          }
 302  }
 303  else
 304  {
 305          if ( isset($HTTP_GET_VARS['unwatch']) )
 306          {
 307                  if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
 308                  {
 309                          $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", $_SERVER["SERVER_SOFTWARE"]) ) ? "Refresh: 0; URL=" : "Location: ";
 310                          header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
 311                          exit;
 312                  }
 313          }
 314          else
 315          {
 316                  $can_watch_topic = 0;
 317                  $is_watching_topic = 0;
 318          }
 319  }
 320  
 321  //

 322  // Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed

 323  // then get it's value, find the number of topics with dates newer than it (to properly

 324  // handle pagination) and alter the main query

 325  //

 326  $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
 327  $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']);
 328  
 329  if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
 330  {
 331          $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? intval($HTTP_POST_VARS['postdays']) : intval($HTTP_GET_VARS['postdays']);
 332          $min_post_time = time() - (intval($post_days) * 86400);
 333  
 334          $sql = "SELECT COUNT(p.post_id) AS num_posts
 335                  FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
 336                  WHERE t.topic_id = '$topic_id'
 337                          AND p.topic_id = t.topic_id
 338                          AND p.post_time >= '$min_post_time'";
 339          if ( !($result = $db->sql_query($sql)) )
 340          {
 341                  message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
 342          }
 343  
 344          $total_replies = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;
 345  
 346          $limit_posts_time = "AND p.post_time >= $min_post_time ";
 347  
 348          if ( !empty($HTTP_POST_VARS['postdays']))
 349          {
 350                  $start = 0;
 351          }
 352  }
 353  else
 354  {
 355          $total_replies = intval($forum_topic_data['topic_replies']) + 1;
 356  
 357          $limit_posts_time = '';
 358          $post_days = 0;
 359  }
 360  
 361  $select_post_days = '<select name="postdays">';
 362  for($i = 0; $i < count($previous_days); $i++)
 363  {
 364          $selected = ($post_days == $previous_days[$i]) ? ' selected="selected"' : '';
 365          $select_post_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
 366  }
 367  $select_post_days .= '</select>';
 368  
 369  //

 370  // Decide how to order the post display

 371  //

 372  if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
 373  {
 374      $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? htmlspecialchars($HTTP_POST_VARS['postorder']) : htmlspecialchars($HTTP_GET_VARS['postorder']);
 375  if (!eregi("^((asc)|(desc))$",$post_order) )
 376  {
 377          message_die(GENERAL_ERROR, 'Selected post order is not valid');
 378  }
 379          $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
 380  }
 381  else
 382  {
 383          $post_order = 'asc';
 384          $post_time_order = 'ASC';
 385  }
 386  
 387  $select_post_order = '<select name="postorder">';
 388  if ( $post_time_order == 'ASC' )
 389  {
 390          $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
 391  }
 392  else
 393  {
 394          $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
 395  }
 396  $select_post_order .= '</select>';
 397  
 398  //

 399  // Go ahead and pull all data for this topic

 400  //

 401  $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
 402          FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
 403          WHERE p.topic_id = '$topic_id'
 404                  $limit_posts_time
 405                  AND pt.post_id = p.post_id
 406                  AND u.user_id = p.poster_id
 407          ORDER BY p.post_time $post_time_order
 408          LIMIT $start, ".$board_config['posts_per_page'];
 409  if ( !($result = $db->sql_query($sql)) )
 410  {
 411          message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
 412  }
 413  
 414  $postrow = array();
 415  if ($row = $db->sql_fetchrow($result))
 416  {
 417          do
 418          {
 419                  $postrow[] = $row;
 420          }
 421          while ($row = $db->sql_fetchrow($result));
 422          $db->sql_freeresult($result);
 423  
 424          $total_posts = count($postrow);
 425  }
 426  else
 427  {
 428     include ("includes/functions_admin.php");
 429     sync('topic', $topic_id);
 430  
 431     message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
 432  }
 433  
 434  $resync = FALSE;
 435  if ($forum_topic_data['topic_replies'] + 1 < $start + count($postrow))
 436  {
 437     $resync = TRUE;
 438  }
 439  elseif ($start + $board_config['posts_per_page'] > $forum_topic_data['topic_replies'])
 440  {
 441     $row_id = intval($forum_topic_data['topic_replies']) % intval($board_config['posts_per_page']);
 442     if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + count($postrow) < $forum_topic_data['topic_replies'])
 443     {
 444        $resync = TRUE;
 445     }
 446  }
 447  elseif (count($postrow) < $board_config['posts_per_page'])
 448  {
 449     $resync = TRUE;
 450  }
 451  
 452  if ($resync)
 453  {
 454     include ("includes/functions_admin.php");
 455     sync('topic', $topic_id);
 456  
 457     $result = $db->sql_query('SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id);
 458     $row = $db->sql_fetchrow($result);
 459     $total_replies = $row['total'];
 460  }
 461  
 462  $sql = "SELECT *
 463          FROM " . RANKS_TABLE . "
 464          ORDER BY rank_special, rank_min";
 465  if ( !($result = $db->sql_query($sql)) )
 466  {
 467          message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
 468  }
 469  
 470  $ranksrow = array();
 471  while ( $row = $db->sql_fetchrow($result) )
 472  {
 473          $ranksrow[] = $row;
 474  }
 475  $db->sql_freeresult($result);
 476  
 477  //

 478  // Define censored word matches

 479  //

 480  $orig_word = array();
 481  $replacement_word = array();
 482  obtain_word_list($orig_word, $replacement_word);
 483  
 484  //

 485  // Censor topic title

 486  //

 487  if ( count($orig_word) )
 488  {
 489          $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
 490  }
 491  
 492  //

 493  // Was a highlight request part of the URI?

 494  //

 495  $highlight_match = $highlight = '';
 496  if (isset($HTTP_GET_VARS['highlight']))
 497  {
 498          // Split words and phrases

 499          $words = explode(' ', trim(htmlspecialchars($HTTP_GET_VARS['highlight'])));
 500  
 501          for($i = 0; $i < sizeof($words); $i++)
 502          {
 503                  if (trim($words[$i]) != '')
 504                  {
 505                          $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', phpbb_preg_quote($words[$i], '#'));
 506                  }
 507          }
 508          unset($words);
 509  
 510      $highlight = urlencode($HTTP_GET_VARS['highlight']);
 511          $highlight_match = phpbb_rtrim($highlight_match, "\\");
 512  }
 513  
 514  //

 515  // Post, reply and other URL generation for

 516  // templating vars

 517  //

 518  $new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
 519  $reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
 520  $view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
 521  $view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
 522  $view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");
 523  
 524  //

 525  // Mozilla navigation bar

 526  //

 527  $nav_links['prev'] = array(
 528          'url' => $view_prev_topic_url,
 529          'title' => $lang['View_previous_topic']
 530  );
 531  $nav_links['next'] = array(
 532          'url' => $view_next_topic_url,
 533          'title' => $lang['View_next_topic']
 534  );
 535  $nav_links['up'] = array(
 536          'url' => $view_forum_url,
 537          'title' => $forum_name
 538  );
 539  
 540  $reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
 541  $reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
 542  $post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
 543  $post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
 544  
 545  //

 546  // Set a cookie for this topic

 547  //

 548  if ( $userdata['session_logged_in'] )
 549  {
 550          $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
 551          $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
 552  
 553          if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
 554          {
 555                  $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
 556          }
 557          else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
 558          {
 559                  $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
 560          }
 561          else
 562          {
 563                  $topic_last_read = $userdata['user_lastvisit'];
 564          }
 565  
 566          if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
 567          {
 568                  asort($tracking_topics);
 569                  unset($tracking_topics[key($tracking_topics)]);
 570          }
 571  
 572          $tracking_topics[$topic_id] = time();
 573  
 574          setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
 575  }
 576  
 577  //

 578  // Load templates

 579  //

 580  $template->set_filenames(array(
 581          'body' => 'viewtopic_body.tpl')
 582  );
 583  make_jumpbox('viewforum.'.$phpEx, $forum_id);
 584  
 585  //

 586  // Output page header

 587  //

 588  $page_title = $lang['View_topic'] .' - ' . $topic_title;
 589  include ("includes/page_header.php");
 590  
 591  //

 592  // User authorisation levels output

 593  //

 594  $s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
 595  $s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
 596  $s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
 597  $s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
 598  $s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
 599  
 600  $topic_mod = '';
 601  
 602  if ( $is_auth['auth_mod'] )
 603  {
 604          $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
 605  
 606          $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=delete") . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';
 607  
 608          $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=move"). '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';
 609  
 610          $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=lock") . '"><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") . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';
 611  
 612          $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=split") . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
 613  }
 614  
 615  //

 616  // Topic watch information

 617  //

 618  $s_watching_topic = '';
 619  if ( $can_watch_topic )
 620  {
 621          if ( $is_watching_topic )
 622          {
 623                  $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '">' . $lang['Stop_watching_topic'] . '</a>';
 624                  $s_watching_topic_img = ( isset($images['Topic_un_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '"><img src="' . $images['Topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
 625          }
 626          else
 627          {
 628                  $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '">' . $lang['Start_watching_topic'] . '</a>';
 629                  $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
 630          }
 631  }
 632  
 633  //

 634  // If we've got a hightlight set pass it on to pagination,

 635  // I get annoyed when I lose my highlight after the first page.

 636  //

 637  $pagination = ( !empty($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);
 638  
 639  //

 640  // Send vars to template

 641  //

 642  $template->assign_vars(array(
 643          'FORUM_ID' => $forum_id,
 644      'FORUM_NAME' => $forum_name,
 645      'TOPIC_ID' => $topic_id,
 646      'TOPIC_TITLE' => $topic_title,
 647          'PAGINATION' => $pagination,
 648          'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / intval($board_config['posts_per_page']) ) + 1 ), ceil( $total_replies / intval($board_config['posts_per_page']) )),
 649  
 650          'POST_IMG' => $post_img,
 651          'REPLY_IMG' => $reply_img,
 652  
 653          'L_AUTHOR' => $lang['Author'],
 654          'L_MESSAGE' => $lang['Message'],
 655          'L_POSTED' => $lang['Posted'],
 656          'L_POST_SUBJECT' => $lang['Post_subject'],
 657          'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
 658          'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
 659          'L_POST_NEW_TOPIC' => $post_alt,
 660          'L_POST_REPLY_TOPIC' => $reply_alt,
 661          'L_BACK_TO_TOP' => $lang['Back_to_top'],
 662          'L_DISPLAY_POSTS' => $lang['Display_posts'],
 663          'L_LOCK_TOPIC' => $lang['Lock_topic'],
 664          'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
 665          'L_MOVE_TOPIC' => $lang['Move_topic'],
 666          'L_SPLIT_TOPIC' => $lang['Split_topic'],
 667          'L_DELETE_TOPIC' => $lang['Delete_topic'],
 668          'L_GOTO_PAGE' => $lang['Goto_page'],
 669  
 670          'S_TOPIC_LINK' => POST_TOPIC_URL,
 671          'S_SELECT_POST_DAYS' => $select_post_days,
 672          'S_SELECT_POST_ORDER' => $select_post_order,
 673          'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
 674          'S_AUTH_LIST' => $s_auth_can,
 675          'S_TOPIC_ADMIN' => $topic_mod,
 676          'S_WATCH_TOPIC' => $s_watching_topic,
 677          'S_WATCH_TOPIC_IMG' => $s_watching_topic_img,
 678  
 679          '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"),
 680          'U_VIEW_FORUM' => $view_forum_url,
 681          'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
 682          'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
 683          'U_POST_NEW_TOPIC' => $new_topic_url,
 684          'U_POST_REPLY_TOPIC' => $reply_topic_url)
 685  );
 686  
 687  //

 688  // Does this topic contain a poll?

 689  //

 690  if ( !empty($forum_topic_data['topic_vote']) )
 691  {
 692          $s_hidden_fields = '';
 693  
 694          $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
 695                  FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
 696                  WHERE vd.topic_id = '$topic_id'
 697                          AND vr.vote_id = vd.vote_id
 698                  ORDER BY vr.vote_option_id ASC";
 699          if ( !($result = $db->sql_query($sql)) )
 700          {
 701                  message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
 702          }
 703  
 704          if ( $vote_info = $db->sql_fetchrowset($result) )
 705          {
 706                  $db->sql_freeresult($result);
 707                  $vote_options = count($vote_info);
 708  
 709                  $vote_id = $vote_info[0]['vote_id'];
 710                  $vote_title = $vote_info[0]['vote_text'];
 711  
 712                  $sql = "SELECT vote_id
 713                          FROM " . VOTE_USERS_TABLE . "
 714                          WHERE vote_id = '$vote_id'
 715                                  AND vote_user_id = " . intval($userdata['user_id']);
 716                  if ( !($result = $db->sql_query($sql)) )
 717                  {
 718                          message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
 719                  }
 720  
 721                  $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
 722                  $db->sql_freeresult($result);
 723  
 724                  if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
 725                  {
 726                          $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
 727                  }
 728                  else
 729                  {
 730                          $view_result = 0;
 731                  }
 732  
 733                  $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
 734  
 735                  if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
 736                  {
 737                          $template->set_filenames(array(
 738                                  'pollbox' => 'viewtopic_poll_result.tpl')
 739                          );
 740  
 741                          $vote_results_sum = 0;
 742  
 743                          for($i = 0; $i < $vote_options; $i++)
 744                          {
 745                                  $vote_results_sum += $vote_info[$i]['vote_result'];
 746                          }
 747  
 748                          $vote_graphic = 0;
 749                          $vote_graphic_max = count($images['voting_graphic']);
 750  
 751                          for($i = 0; $i < $vote_options; $i++)
 752                          {
 753                                  $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
 754                                  $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
 755  
 756                                  $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
 757                                  $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
 758  
 759                                  if ( count($orig_word) )
 760                                  {
 761                                          $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
 762                                  }
 763  
 764                                  $template->assign_block_vars("poll_option", array(
 765                                          'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
 766                                          'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
 767                                          'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
 768  
 769                                          'POLL_OPTION_IMG' => $vote_graphic_img,
 770                                          'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
 771                                  );
 772                          }
 773  
 774                          $template->assign_vars(array(
 775                                  'L_TOTAL_VOTES' => $lang['Total_votes'],
 776                                  'TOTAL_VOTES' => $vote_results_sum)
 777                          );
 778  
 779                  }
 780                  else
 781                  {
 782                          $template->set_filenames(array(
 783                                  'pollbox' => 'viewtopic_poll_ballot.tpl')
 784                          );
 785  
 786                          for($i = 0; $i < $vote_options; $i++)
 787                          {
 788                                  if ( count($orig_word) )
 789                                  {
 790                                          $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
 791                                  }
 792  
 793                                  $template->assign_block_vars("poll_option", array(
 794                                          'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
 795                                          'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
 796                                  );
 797                          }
 798  
 799                          $template->assign_vars(array(
 800                                  'L_SUBMIT_VOTE' => $lang['Submit_vote'],
 801                                  'L_VIEW_RESULTS' => $lang['View_results'],
 802  
 803                                  'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
 804                          );
 805  
 806                          $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
 807                  }
 808  
 809                  if ( count($orig_word) )
 810                  {
 811                          $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
 812                  }
 813  
 814                  $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
 815  
 816                  $template->assign_vars(array(
 817                          'POLL_QUESTION' => $vote_title,
 818  
 819                          'S_HIDDEN_FIELDS' => $s_hidden_fields,
 820                          'S_POLL_ACTION' => append_sid("posting.$phpEx?mode=vote&amp;" . POST_TOPIC_URL . "=$topic_id"))
 821                  );
 822  
 823                  $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
 824          }
 825  }
 826  
 827  //

 828  // Update the topic view counter

 829  //

 830  $sql = "UPDATE " . TOPICS_TABLE . "
 831          SET topic_views = topic_views + 1
 832          WHERE topic_id = '$topic_id'";
 833  if ( !$db->sql_query($sql) )
 834  {
 835          message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
 836  }
 837  
 838  //

 839  // Okay, let's do the loop, yeah come on baby let's do the loop

 840  // and it goes like this ...

 841  //

 842  for($i = 0; $i < $total_posts; $i++)
 843  {
 844          $poster_id = $postrow[$i]['user_id'];
 845          $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
 846  
 847          $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
 848  
 849          $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
 850  
 851          $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
 852          $poster_from = ereg_replace(".gif", "", $poster_from);
 853          $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . $postrow[$i]['user_regdate'] : '';
 854  
 855      $poster_avatar = '';
 856      if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
 857      {
 858          switch( $postrow[$i]['user_avatar_type'] )
 859          {
 860              case USER_AVATAR_UPLOAD:
 861                  $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
 862                  break;
 863              case USER_AVATAR_REMOTE:
 864                  $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
 865                  break;
 866              case USER_AVATAR_GALLERY:
 867                  $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
 868                  break;
 869          }
 870      }
 871          $images['default_avatar'] = "modules/Forums/images/avatars/gallery/blank.gif";
 872          $images['guest_avatar'] = "modules/Forums/images/avatars/gallery/blank.gif";
 873          //

 874          // Default Avatar MOD - Begin

 875          //

 876          if ( empty($poster_avatar) && $poster_id != ANONYMOUS)
 877          {
 878                  $poster_avatar = '<img src="'.  $images['default_avatar'] .'" alt="" border="0" />';
 879          }
 880          if ( $poster_id == ANONYMOUS )
 881          {
 882                  $poster_avatar = '<img src="'.  $images['guest_avatar'] .'" alt="" border="0" />';
 883          }
 884          //

 885          // Default Avatar MOD - End

 886          //

 887          //

 888          // Define the little post icon

 889          //

 890          if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
 891          {
 892                  $mini_post_img = $images['icon_minipost_new'];
 893                  $mini_post_alt = $lang['New_post'];
 894          }
 895          else
 896          {
 897                  $mini_post_img = $images['icon_minipost'];
 898                  $mini_post_alt = $lang['Post'];
 899          }
 900  
 901          $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
 902  
 903          //

 904          // Generate ranks, set them to empty string initially.

 905          //

 906          $poster_rank = '';
 907          $rank_image = '';
 908          if ( $postrow[$i]['user_id'] == ANONYMOUS )
 909          {
 910          }
 911          else if ( $postrow[$i]['user_rank'] )
 912          {
 913                  for($j = 0; $j < count($ranksrow); $j++)
 914                  {
 915                          if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
 916                          {
 917                                  $poster_rank = $ranksrow[$j]['rank_title'];
 918                                  $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
 919                          }
 920                  }
 921          }
 922          else
 923          {
 924                  for($j = 0; $j < count($ranksrow); $j++)
 925                  {
 926                          if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
 927                          {
 928                                  $poster_rank = $ranksrow[$j]['rank_title'];
 929                                  $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
 930                          }
 931                  }
 932          }
 933  
 934          //

 935          // Handle anon users posting with usernames

 936          //

 937          if ( $poster_id == ANONYMOUS && !empty($postrow[$i]['post_username']) )
 938          {
 939                  $poster = $postrow[$i]['post_username'];
 940                  $poster_rank = $lang['Guest'];
 941          }
 942  
 943          $temp_url = '';
 944  
 945          if ( $poster_id != ANONYMOUS )
 946          {
 947                  $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
 948                  $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
 949                  $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
 950  
 951                  $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
 952                  if (is_active("Private_Messages")) {
 953                  $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
 954                  $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
 955                  }
 956  
 957                  if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
 958                  {
 959                          $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];
 960  
 961                          $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
 962                          $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
 963                  }
 964                  else
 965                  {
 966                          $email_img = '';
 967                          $email = '';
 968                  }
 969                  if (( $postrow[$i]['user_website'] == "http:///") || ( $postrow[$i]['user_website'] == "http://")){
 970                      $postrow[$i]['user_website'] =  "";
 971                  }
 972                  if (($postrow[$i]['user_website'] != "" ) && (substr($postrow[$i]['user_website'],0, 7) != "http://")) {
 973                      $postrow[$i]['user_website'] = "http://".$postrow[$i]['user_website'];
 974                  }
 975  
 976                  $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>' : '';
 977                  $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
 978  
 979                  if ( !empty($postrow[$i]['user_icq']) )
 980                  {
 981                          $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>';
 982                          $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>';
 983                          $icq =  '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
 984                  }
 985                  else
 986                  {
 987                          $icq_status_img = '';
 988                          $icq_img = '';
 989                          $icq = '';
 990                  }
 991  
 992                  $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>' : '';
 993                  $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
 994  
 995                  $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
 996                  $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
 997                  $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
 998  
 999                  $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>' : '';
1000                  $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>' : '';
1001          }
1002          else
1003          {
1004                  $profile_img = '';
1005                  $profile = '';
1006                  $pm_img = '';
1007                  $pm = '';
1008                  $email_img = '';
1009                  $email = '';
1010                  $www_img = '';
1011                  $www = '';
1012                  $icq_status_img = '';
1013                  $icq_img = '';
1014                  $icq = '';
1015                  $aim_img = '';
1016                  $aim = '';
1017                  $msn_img = '';
1018                  $msn = '';
1019                  $yim_img = '';
1020                  $yim = '';
1021          }
1022  
1023          $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
1024          $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
1025          $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';
1026  
1027          $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
1028      $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>';
1029      $search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $postrow[$i]['username']) . '</a>';
1030  
1031          if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
1032          {
1033                  $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
1034                  $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
1035                  $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
1036          }
1037          else
1038          {
1039                  $edit_img = '';
1040                  $edit = '';
1041          }
1042  
1043          if ( $is_auth['auth_mod'] )
1044          {
1045                  $temp_url = append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id);
1046                  $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
1047                  $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';
1048  
1049                  $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
1050                  $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
1051                  $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
1052          }
1053          else
1054          {
1055                  $ip_img = '';
1056                  $ip = '';
1057  
1058                  if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
1059                  {
1060                          $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
1061                          $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
1062                          $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
1063                  }
1064                  else
1065                  {
1066                          $delpost_img = '';
1067                          $delpost = '';
1068                  }
1069          }
1070  
1071          $post_subject = ( !empty($postrow[$i]['post_subject']) ) ? $postrow[$i]['post_subject'] : '';
1072  
1073          $message = $postrow[$i]['post_text'];
1074          $bbcode_uid = $postrow[$i]['bbcode_uid'];
1075  
1076          $user_sig = ( $postrow[$i]['enable_sig'] && !empty($postrow[$i]['user_sig']) && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
1077          $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];
1078  
1079          //

1080          // Note! The order used for parsing the message _is_ important, moving things around could break any

1081          // output

1082          //

1083  
1084          //

1085          // If the board has HTML off but the post has HTML

1086          // on then we process it, else leave it alone

1087          //

1088      if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
1089          {
1090                  if ( !empty($user_sig) )
1091                  {
1092                          $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
1093                  }
1094  
1095                  if ( $postrow[$i]['enable_html'] )
1096                  {
1097                          $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
1098                  }
1099          }
1100  
1101          //

1102          // Parse message and/or sig for BBCode if reqd

1103          //

1104          if ( $board_config['allow_bbcode'] )
1105          {
1106                  if ( !empty($user_sig) && !empty($user_sig_bbcode_uid) )
1107                  {
1108                          $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
1109                  }
1110  
1111                  if ( !empty($bbcode_uid) )
1112                  {
1113                          $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
1114                  }
1115          }
1116  
1117          if ( !empty($user_sig) )
1118          {
1119                  $user_sig = make_clickable($user_sig);
1120          }
1121          $message = make_clickable($message);
1122  
1123          //

1124          // Parse smilies

1125          //

1126          if ( $board_config['allow_smilies'] )
1127          {
1128                  if ( $postrow[$i]['user_allowsmile'] && !empty($user_sig) )
1129                  {
1130                          $user_sig = smilies_pass($user_sig);
1131                  }
1132  
1133                  if ( $postrow[$i]['enable_smilies'] )
1134                  {
1135                          $message = smilies_pass($message);
1136                  }
1137          }
1138  
1139          //

1140          // Highlight active words (primarily for search)

1141          //

1142          if ($highlight_match)
1143          {
1144                  // This was shamelessly 'borrowed' from volker at multiartstudio dot de

1145                  // via php.net's annotated manual

1146          $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));
1147          }
1148  
1149          //

1150          // Replace naughty words

1151          //

1152          if (count($orig_word))
1153          {
1154                  $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
1155  
1156                  if (!empty($user_sig))
1157                  {
1158              $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
1159                  }
1160  
1161          $message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
1162          }
1163  
1164          //

1165          // Replace newlines (we use this rather than nl2br because

1166          // till recently it wasn't XHTML compliant)

1167          //

1168          if ( !empty($user_sig) )
1169          {
1170                  $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
1171          }
1172  
1173          $message = str_replace("\n", "\n<br />\n", $message);
1174  
1175          //

1176          // Editing information

1177          //

1178          if ( $postrow[$i]['post_edit_count'] )
1179          {
1180                  $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
1181  
1182                  $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']);
1183          }
1184          else
1185          {
1186                  $l_edited_by = '';
1187          }
1188  
1189          //

1190          // Again this will be handled by the templating

1191          // code at some point

1192          //

1193          $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1194          $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1195  
1196          $template->assign_block_vars('postrow', array(
1197                  'ROW_COLOR' => '#' . $row_color,
1198                  'ROW_CLASS' => $row_class,
1199                  'POSTER_NAME' => $poster,
1200                  'POSTER_RANK' => $poster_rank,
1201                  'RANK_IMAGE' => $rank_image,
1202                  'POSTER_JOINED' => $poster_joined,
1203                  'POSTER_POSTS' => $poster_posts,
1204                  'POSTER_FROM' => $poster_from,
1205                  'POSTER_AVATAR' => $poster_avatar,
1206                  'POST_DATE' => $post_date,
1207                  'POST_SUBJECT' => $post_subject,
1208                  'MESSAGE' => $message,
1209                  'SIGNATURE' => $user_sig,
1210                  'EDITED_MESSAGE' => $l_edited_by,
1211  
1212                  'MINI_POST_IMG' => $mini_post_img,
1213                  'PROFILE_IMG' => $profile_img,
1214                  'PROFILE' => $profile,
1215                  'SEARCH_IMG' => $search_img,
1216                  'SEARCH' => $search,
1217                  'PM_IMG' => $pm_img,
1218                  'PM' => $pm,
1219                  'EMAIL_IMG' => $email_img,
1220                  'EMAIL' => $email,
1221                  'WWW_IMG' => $www_img,
1222                  'WWW' => $www,
1223                  'ICQ_STATUS_IMG' => $icq_status_img,
1224                  'ICQ_IMG' => $icq_img,
1225                  'ICQ' => $icq,
1226                  'AIM_IMG' => $aim_img,
1227                  'AIM' => $aim,
1228                  'MSN_IMG' => $msn_img,
1229                  'MSN' => $msn,
1230                  'YIM_IMG' => $yim_img,
1231                  'YIM' => $yim,
1232                  'EDIT_IMG' => $edit_img,
1233                  'EDIT' => $edit,
1234                  'QUOTE_IMG' => $quote_img,
1235                  'QUOTE' => $quote,
1236                  'IP_IMG' => $ip_img,
1237                  'IP' => $ip,
1238                  'DELETE_IMG' => $delpost_img,
1239                  'DELETE' => $delpost,
1240  
1241                  'L_MINI_POST_ALT' => $mini_post_alt,
1242  
1243                  'U_MINI_POST' => $mini_post_url,
1244                  'U_POST_ID' => $postrow[$i]['post_id'])
1245          );
1246  }
1247  
1248  $template->pparse('body');
1249  
1250  include ("includes/page_tail.php");
1251  
1252  ?>


Généré le : Sun Apr 1 11:11:59 2007 par Balluche grâce à PHPXref 0.7