XMB PHP Cross Reference Discussion Forums

Source: /post.php - 1519 lines - 68776 bytes - Summary - Text - Print

Description: eXtreme Message Board XMB 1.9.11

   1  <?php
   2  /**
   3   * eXtreme Message Board
   4   * XMB 1.9.11
   5   *
   6   * Developed And Maintained By The XMB Group
   7   * Copyright (c) 2001-2012, The XMB Group
   8   * http://www.xmbforum2.com/
   9   *
  10   * This program is free software; you can redistribute it and/or
  11   * modify it under the terms of the GNU General Public License
  12   * as published by the Free Software Foundation; either version 2
  13   * of the License, or (at your option) any later version.
  14   *
  15   * This program is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22   *
  23   **/
  24  
  25  define('X_SCRIPT', 'post.php');
  26  
  27  require  'header.php';
  28  
  29  header('X-Robots-Tag: noindex');
  30  
  31  loadtemplates(
  32  'post_captcha',
  33  'post_notloggedin',
  34  'post_loggedin',
  35  'post_preview',
  36  'post_attachment_orphan',
  37  'post_attachmentbox',
  38  'post_newthread',
  39  'post_reply_review_toolong',
  40  'post_reply_review_post',
  41  'post_reply',
  42  'post_edit',
  43  'functions_smilieinsert',
  44  'functions_smilieinsert_smilie',
  45  'functions_bbcodeinsert',
  46  'forumdisplay_password',
  47  'functions_bbcode',
  48  'post_newpoll',
  49  'post_edit_attachment',
  50  'viewthread_post_attachmentthumb',
  51  'viewthread_post_attachmentimage',
  52  'viewthread_post_attachment',
  53  'viewthread_post_nosig',
  54  'viewthread_post_sig'
  55  );
  56  
  57  eval('$css = "'.template('css').'";');
  58  
  59  if (X_GUEST) {
  60      eval('$loggedin = "'.template('post_notloggedin').'";');
  61  } else {
  62      eval('$loggedin = "'.template('post_loggedin').'";');
  63  }
  64  
  65  if ($self['ban'] == "posts" || $self['ban'] == "both") {
  66      error($lang['textbanfrompost']);
  67  }
  68  
  69  //Validate $pid, $tid, $fid, and $repquote
  70  $fid = -1;
  71  $tid = -1;
  72  $pid = -1;
  73  $repquote = -1;
  74  if ($action == 'edit') {
  75      $pid = getRequestInt('pid');
  76      $query = $db->query("SELECT f.*, t.tid FROM ".X_PREFIX."posts AS p LEFT JOIN ".X_PREFIX."threads AS t USING (tid) LEFT JOIN ".X_PREFIX."forums AS f ON f.fid=t.fid WHERE p.pid=$pid");
  77      if ($db->num_rows($query) != 1) {
  78          header('HTTP/1.0 404 Not Found');
  79          error($lang['textnothread']);
  80      }
  81      $forum = $db->fetch_array($query);
  82      $db->free_result($query);
  83      $fid = $forum['fid'];
  84      $tid = $forum['tid'];
  85  } else if ($action == 'reply') {
  86      $tid = getRequestInt('tid');
  87      $repquote = getInt('repquote');
  88      $query = $db->query("SELECT f.* FROM ".X_PREFIX."threads AS t LEFT JOIN ".X_PREFIX."forums AS f USING (fid) WHERE t.tid=$tid");
  89      if ($db->num_rows($query) != 1) {
  90          header('HTTP/1.0 404 Not Found');
  91          error($lang['textnothread']);
  92      }
  93      $forum = $db->fetch_array($query);
  94      $db->free_result($query);
  95      $fid = $forum['fid'];
  96  } else if ($action == 'newthread') {
  97      $fid = getRequestInt('fid');
  98      $forum = getForum($fid);
  99      if ($forum === FALSE) {
 100          header('HTTP/1.0 404 Not Found');
 101          error($lang['textnoforum']);
 102      }
 103  } else {
 104      header('HTTP/1.0 404 Not Found');
 105      error($lang['textnoaction']);
 106  }
 107  
 108  if (($forum['type'] != 'forum' && $forum['type'] != 'sub') || $forum['status'] != 'on') {
 109      header('HTTP/1.0 404 Not Found');
 110      error($lang['textnoforum']);
 111  }
 112  
 113  smcwcache();
 114  
 115  if ($tid > 0) {
 116      $query = $db->query("SELECT * FROM ".X_PREFIX."threads WHERE tid=$tid");
 117      if ($db->num_rows($query) != 1) {
 118          header('HTTP/1.0 404 Not Found');
 119          error($lang['textnothread']);
 120      }
 121      $thread = $db->fetch_array($query);
 122      $db->free_result($query);
 123      $threadname = rawHTMLsubject(stripslashes($thread['subject']));
 124  } else {
 125      $thread = array();
 126      $threadname = '';
 127  }
 128  
 129  //Warning! These variables are used for template output.
 130  $attachfile = '';
 131  $attachment = '';
 132  $captchapostcheck = '';
 133  $dissubject = '';
 134  $errors = '';
 135  $imghash = '';
 136  $message = '';
 137  $message1 = '';
 138  $postinfo = array();
 139  $preview = '';
 140  $spelling_lang = '';
 141  $spelling_submit1 = '';
 142  $spelling_submit2 = '';
 143  $subject = '';
 144  $suggestions = '';
 145  if (X_GUEST) {
 146      $username = 'Anonymous';
 147  } else {
 148      $username = $xmbuser;
 149  }
 150  
 151  validatePpp();
 152  
 153  $poll = postedVar('poll', '', FALSE, FALSE, FALSE, 'g');
 154  if ($poll != 'yes') {
 155      $poll = '';
 156  }
 157  
 158  // check permissions on this forum (and top forum if it's a sub?)
 159  $perms = checkForumPermissions($forum);
 160  if (!$perms[X_PERMS_VIEW]) {
 161      if (X_GUEST) {
 162          redirect("{$full_url}misc.php?action=login", 0);
 163          exit;
 164      } else {
 165          error($lang['privforummsg']);
 166      }
 167  } else if (!$perms[X_PERMS_PASSWORD]) {
 168      handlePasswordDialog($fid);
 169  }
 170  
 171  // check posting permissions specifically
 172  if ($action == 'newthread') {
 173      if (($poll == '' && !$perms[X_PERMS_THREAD]) || ($poll == 'yes' && !$perms[X_PERMS_POLL])) {
 174          if (X_GUEST) {
 175              redirect("{$full_url}misc.php?action=login", 0);
 176              exit;
 177          } else {
 178              error($lang['textnoaction']);
 179          }
 180      }
 181  } else if ($action == 'reply') {
 182      if (!$perms[X_PERMS_REPLY]) {
 183          if (X_GUEST) {
 184              redirect("{$full_url}misc.php?action=login", 0);
 185              exit;
 186          } else {
 187              error($lang['textnoaction']);
 188          }
 189      }
 190  } else if ($action == 'edit') {
 191      // let's allow edits for now, we'll check for permissions later on in the script (due to need for $orig['author'])
 192  } else {
 193      error($lang['textnoaction']);
 194  }
 195  
 196  $fup = array();
 197  if ($forum['type'] == 'sub') {
 198      $fup = getForum($forum['fup']);
 199      // prevent access to subforum when upper forum can't be viewed.
 200      $fupPerms = checkForumPermissions($fup);
 201      if (!$fupPerms[X_PERMS_VIEW]) {
 202          if (X_GUEST) {
 203              redirect("{$full_url}misc.php?action=login", 0);
 204              exit;
 205          } else {
 206              error($lang['privforummsg']);
 207          }
 208      } else if (!$fupPerms[X_PERMS_PASSWORD]) {
 209          error($lang['privforummsg']);     // do not show password-dialog here; it makes the situation too complicated
 210      } else if ($fup['fup'] > 0) {
 211          $fupup = getForum($fup['fup']);
 212          nav('<a href="index.php?gid='.$fup['fup'].'">'.fnameOut($fupup['name']).'</a>');
 213          unset($fupup);
 214      }
 215      nav('<a href="forumdisplay.php?fid='.$fup['fid'].'">'.fnameOut($fup['name']).'</a>');
 216  } else if ($forum['fup'] > 0) { // 'forum' in a 'group'
 217      $fup = getForum($forum['fup']);
 218      nav('<a href="index.php?gid='.$fup['fid'].'">'.fnameOut($fup['name']).'</a>');
 219  }
 220  nav('<a href="forumdisplay.php?fid='.$fid.'">'.fnameOut($forum['name']).'</a>');
 221  
 222  // Search-link
 223  $searchlink = makeSearchLink($forum['fid']);
 224  
 225  if (!ini_get('file_uploads')) {
 226      $forum['attachstatus'] = 'off';
 227  } elseif ($forum['attachstatus'] == 'on') {
 228      require  'include/attach.inc.php';
 229      $attachlimits = ' '.$lang['attachmaxsize'].' '.getSizeFormatted($SETTINGS['maxattachsize']).'.  '.$lang['attachmaxdims'].' '.$SETTINGS['max_image_size'].'.';
 230  }
 231  
 232  $posticon = postedVar('posticon', 'javascript', TRUE, TRUE, TRUE);
 233  if (!isValidFilename($posticon)) {
 234      $posticon = '';
 235  } elseif (!file_exists($smdir.'/'.$posticon)) {
 236      $posticon = '';
 237  }
 238  
 239  $listed_icons = 0;
 240  $icons = '<input type="radio" name="posticon" value="" /> <img src="'.$imgdir.'/default_icon.gif" alt="[*]" border="0" />';
 241  $querysmilie = $db->query("SELECT url, code FROM ".X_PREFIX."smilies WHERE type='picon'");
 242  while($smilie = $db->fetch_array($querysmilie)) {
 243      $icons .= ' <input type="radio" name="posticon" value="'.$smilie['url'].'" /><img src="'.$smdir.'/'.$smilie['url'].'" alt="'.$smilie['code'].'" border="0" />';
 244      $listed_icons++;
 245      if ($listed_icons == 9) {
 246          $icons .= '<br />';
 247          $listed_icons = 0;
 248      }
 249  }
 250  $db->free_result($querysmilie);
 251  
 252  if ($action != 'edit') {
 253      $icons = str_replace('<input type="radio" name="posticon" value="'.$posticon.'" />', '<input type="radio" name="posticon" value="'.$posticon.'" checked="checked" />', $icons);
 254  
 255      if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on') {
 256          require  ROOT.'include/captcha.inc.php';
 257      }
 258  }
 259  
 260  $allowimgcode = ($forum['allowimgcode'] == 'yes' And $forum['allowbbcode'] == 'yes') ? $lang['texton'] : $lang['textoff'];
 261  $allowhtml = ($forum['allowhtml'] == 'yes') ? $lang['texton'] : $lang['textoff'];
 262  $allowsmilies = ($forum['allowsmilies'] == 'yes') ? $lang['texton'] : $lang['textoff'];
 263  $allowbbcode = ($forum['allowbbcode'] == 'yes') ? $lang['texton'] : $lang['textoff'];
 264  
 265  $bbcodeoff = formYesNo('bbcodeoff');
 266  $emailnotify = formYesNo('emailnotify');
 267  $smileyoff = formYesNo('smileyoff');
 268  $usesig = formYesNo('usesig');
 269  
 270  $codeoffcheck = ($bbcodeoff == 'yes') ? $cheHTML : '';
 271  $emailnotifycheck = ($emailnotify == 'yes') ? $cheHTML : '';
 272  $smileoffcheck = ($smileyoff == 'yes') ? $cheHTML : '';
 273  
 274  // New bool vars to clear up the confusion about effective settings.
 275  $bBBcodeInserterEnabled = ($SETTINGS['bbinsert'] == 'on' And $forum['allowbbcode'] == 'yes');
 276  $bBBcodeOnForThisPost = ($forum['allowbbcode'] == 'yes' And $bbcodeoff == 'no');
 277  $bIMGcodeOnForThisPost = ($bBBcodeOnForThisPost And $forum['allowimgcode'] == 'yes');
 278  $bSmilieInserterEnabled = ($SETTINGS['smileyinsert'] == 'on' And $forum['allowsmilies'] == 'yes');
 279  $bSmiliesOnForThisPost = ($forum['allowsmilies'] == 'yes' And $smileyoff == 'no');
 280  
 281  if (isset($subaction) && $subaction == 'spellcheck' && (isset($spellchecksubmit) || isset($updates_submit))) {
 282      $sc = TRUE;
 283  } else {
 284      $sc = FALSE;
 285  }
 286  
 287  if ((isset($previewpost) || $sc) && $usesig == 'yes') {
 288      $usesigcheck = $cheHTML;
 289  } else if (isset($previewpost) || $sc) {
 290      $usesigcheck = '';
 291  } else if ($self['sig'] != '') {
 292      $usesigcheck = $cheHTML;
 293  } else {
 294      $usesigcheck = '';
 295  }
 296  
 297  if (X_STAFF) {
 298      if (isset($toptopic) && $toptopic == 'yes') {
 299          $topcheck = $cheHTML;
 300      } else {
 301          $topcheck = '';
 302          $toptopic = 'no';
 303      }
 304  
 305      if (isset($closetopic) && $closetopic == 'yes') {
 306          $closecheck = $cheHTML;
 307      } else {
 308          $closecheck = '';
 309          $closetopic = 'no';
 310      }
 311  } else {
 312      $topcheck = '';
 313      $closecheck = '';
 314  }
 315  
 316  $messageinput = postedVar('message', '', TRUE, FALSE);  //postify() is responsible for DECODING if html is allowed.
 317  $subjectinput = postedVar('subject', 'javascript', TRUE, FALSE, TRUE);
 318  $subjectinput = str_replace(array("\r", "\n"), array('', ''), $subjectinput);
 319  
 320  if ($SETTINGS['spellcheck'] == 'on') {
 321      $spelling_submit1 = '<input type="hidden" name="subaction" value="spellcheck" /><input type="submit" class="submit" name="spellchecksubmit" value="'.$lang['checkspelling'].'" />';
 322      $spelling_lang = '<select name="language"><option value="en" selected="selected">English</option></select>';
 323      if ($sc) {
 324          if (isset($language) && !isset($updates_submit)) {
 325              require  ROOT.'include/spelling.inc.php';
 326              $spelling = new spelling($language);
 327              $problems = $spelling->check_text(postedVar('message', '', FALSE, FALSE));  //Use raw value so we're not checking entity names.
 328              if (count($problems) > 0) {
 329                  $suggest = array();
 330                  foreach($problems as $raworig=>$new) {
 331                      $orig = cdataOut($raworig);
 332                      $mistake = array();
 333                      foreach($new as $rawsuggestion) {
 334                          $suggestion = attrOut($rawsuggestion);
 335                          eval('$mistake[] = "'.template('spelling_suggestion_new').'";');
 336                      }
 337                      $mistake = implode("\n", $mistake);
 338                      eval('$suggest[] = "'.template('spelling_suggestion_row').'";');
 339                  }
 340                  $suggestions = implode("\n", $suggest);
 341                  eval('$suggestions = "'.template('spelling_suggestion').'";');
 342                  $spelling_submit2 = '<input type="submit" class="submit" name="updates_submit" value="'.$lang['replace'].'" />';
 343              } else {
 344                  eval('$suggestions = "'.template('spelling_suggestion_no').'";');
 345              }
 346          } else {
 347              $old_words = postedArray('old_words', 'string', '', TRUE, FALSE);
 348              foreach($old_words as $word) {
 349                  $replacement = postedVar('replace_'.$word, '', TRUE, FALSE);
 350                  $messageinput = str_replace($word, $replacement, $messageinput);
 351              }
 352          }
 353      }
 354  }
 355  
 356  $bbcodeinsert = '';
 357  $bbcodescript = '';
 358  $moresmilies = '';
 359  $smilieinsert = '';
 360  if ($bBBcodeInserterEnabled Or $bSmilieInserterEnabled) {
 361      eval('$bbcodescript = "'.template('functions_bbcode').'";');
 362      if ($bBBcodeInserterEnabled) {
 363          $mode0check = '';
 364          $mode1check = '';
 365          $mode2check = '';
 366          $mode = isset($mode) ? formInt('mode') : 2;
 367          switch($mode) {
 368          case 0:
 369              $mode0check = $cheHTML;
 370              $setbbcodemode = 'advmode=true;normalmode=false;';
 371              break;
 372          case 1:
 373              $mode1check = $cheHTML;
 374              $setbbcodemode = 'helpmode=true;normalmode=false;';
 375              break;
 376          default:
 377              $mode2check = $cheHTML;
 378              $setbbcodemode = '';
 379              break;
 380          }
 381          eval('$bbcodeinsert = "'.template('functions_bbcodeinsert').'";'); // Uses $spelling_lang
 382      }
 383      if ($bSmilieInserterEnabled) {
 384          $smilieinsert = smilieinsert();
 385          $moresmilies = "<a href=\"misc.php?action=smilies\" onclick=\"Popup(this.href, 'Window', 175, 250); return false;\">[{$lang['moresmilies']}]</a>";
 386      }
 387  }
 388  
 389  switch($action) {
 390      case 'reply':
 391          nav('<a href="viewthread.php?tid='.$tid.'">'.$threadname.'</a>');
 392          nav($lang['textreply']);
 393  
 394          if ($SETTINGS['subject_in_title'] == 'on') {
 395              $threadSubject = '- '.$threadname;
 396          }
 397  
 398          eval('$header = "'.template('header').'";');
 399  
 400          $replyvalid = onSubmit('replysubmit'); // This new flag will indicate a message was submitted and successful.
 401  
 402          if ($forum['attachstatus'] == 'on' And $username != 'Anonymous') {
 403              for ($i=1; $i<=$SETTINGS['filesperpost']; $i++) {
 404                  if (isset($_FILES['attach'.$i])) {
 405                      $result = attachUploadedFile('attach'.$i);
 406                      if ($result < 0 And $result != X_EMPTY_UPLOAD) {
 407                          $errors .= softerror($attachmentErrors[$result]);
 408                          $replyvalid = FALSE;
 409                      }
 410                  }
 411              }
 412              $result = doAttachmentEdits($deletes);
 413              if ($result < 0) {
 414                  $errors .= softerror($attachmentErrors[$result]);
 415                  $replyvalid = FALSE;
 416              }
 417              foreach($deletes as $aid) {
 418                  $messageinput = str_replace("[file]{$aid}[/file]", '', $messageinput);
 419              }
 420              if ($SETTINGS['attach_remote_images'] == 'on' And $bIMGcodeOnForThisPost) {
 421                  $result = extractRemoteImages(0, $messageinput);
 422                  if ($result < 0) {
 423                      $errors .= softerror($attachmentErrors[$result]);
 424                      $replyvalid = FALSE;
 425                  }
 426              }
 427              $attachSkipped = FALSE;
 428          } else {
 429              $attachSkipped = TRUE;
 430          }
 431  
 432          //Check all replying permissions for this $tid.
 433          if (!X_SADMIN And $thread['closed'] != '') {
 434              if ($replyvalid) {
 435                  $errors .= softerror($lang['closedmsg']);
 436              } else {
 437                  error($lang['closedmsg']);
 438              }
 439              $replyvalid = FALSE;
 440          }
 441  
 442          if ($replyvalid) {
 443              if (X_GUEST) { // Anonymous posting is allowed, and was checked in forum perms at top of file.
 444                  $password = '';
 445                  if (strlen(postedVar('username')) > 0 And isset($_POST['password'])) {
 446                      if (loginUser(postedVar('username'), md5($_POST['password']))) {
 447                          if ($self['status'] == "Banned") {
 448                              $errors .= softerror($lang['bannedmessage']);
 449                              $replyvalid = FALSE;
 450                          } else if ($self['ban'] == "posts" || $self['ban'] == "both") {
 451                              $errors .= softerror($lang['textbanfrompost']);
 452                              $replyvalid = FALSE;
 453                          } else {
 454                              $username = $xmbuser;
 455  
 456                              // check permissions on this forum (and top forum if it's a sub?)
 457                              $perms = checkForumPermissions($forum);
 458                              if (!$perms[X_PERMS_VIEW]) {
 459                                  $errors .= softerror($lang['privforummsg']);
 460                                  $topicvalid = FALSE;
 461                              } else if (!$perms[X_PERMS_REPLY]) {
 462                                  $errors .= softerror($lang['textnoaction']);
 463                                  $topicvalid = FALSE;
 464                              }
 465  
 466                              if ($forum['type'] == 'sub') {
 467                                  // prevent access to subforum when upper forum can't be viewed.
 468                                  $fupPerms = checkForumPermissions($fup);
 469                                  if (!$fupPerms[X_PERMS_VIEW]) {
 470                                      $errors .= softerror($lang['privforummsg']);
 471                                      $topicvalid = FALSE;
 472                                  }
 473                              }
 474                          }
 475                      } else {
 476                          $errors .= softerror($lang['textpw1']);
 477                          $replyvalid = FALSE;
 478                      }
 479                  } else if ($SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on') {
 480                      $Captcha = new Captcha();
 481                      if ($Captcha->bCompatible !== false) {
 482                          $imgcode = postedVar('imgcode', '', FALSE, FALSE);
 483                          $imghash = postedVar('imghash');
 484                          if ($Captcha->ValidateCode($imgcode, $imghash) !== TRUE) {
 485                              $errors .= softerror($lang['captchaimageinvalid']);
 486                              $replyvalid = FALSE;
 487                          }
 488                      }
 489                      unset($Captcha);
 490                  }
 491              }
 492          }
 493  
 494          if ($replyvalid) {
 495              if (strlen($subjectinput) == 0 && strlen($messageinput) == 0) {
 496                  $errors .= softerror($lang['postnothing']);
 497                  $replyvalid = FALSE;
 498              }
 499          }
 500  
 501          if ($replyvalid) {
 502              if ($posticon != '') {
 503                  $query = $db->query("SELECT id FROM ".X_PREFIX."smilies WHERE type='picon' AND url='$posticon'");
 504                  if ($db->num_rows($query) == 0) {
 505                      $posticon = '';
 506                      $errors .= softerror($lang['error']);
 507                      $replyvalid = FALSE;
 508                  }
 509                  $db->free_result($query);
 510              }
 511          }
 512  
 513          if ($replyvalid) {
 514              if ($forum['lastpost'] != '') {
 515                  $lastpost = explode('|', $forum['lastpost']);
 516                  $rightnow = $onlinetime - $floodctrl;
 517                  if ($rightnow <= $lastpost[0] && $username == $lastpost[1]) {
 518                      $floodlink = "<a href=\"viewthread.php?fid=$fid&tid=$tid\">Click here</a>";
 519                      $errmsg = $lang['floodprotect'].' '.$floodlink.' '.$lang['tocont'];
 520                      $errors .= softerror($errmsg);
 521                      $replyvalid = FALSE;
 522                  }
 523              }
 524          }
 525  
 526          if ($replyvalid) {
 527              $thatime = $onlinetime;
 528              if ($bBBcodeOnForThisPost) {
 529                  postLinkBBcode($messageinput);
 530              }
 531  
 532              $dbmessage = addslashes($messageinput); //The message column is historically double-quoted.
 533              $dbsubject = addslashes($subjectinput);
 534  
 535              if (strlen($dbmessage) > 65535 or strlen($dbsubject) > 255) {
 536                  // Inputs are suspiciously long.  Has the schema been customized?
 537                  $query = $db->query("SELECT message, subject FROM ".X_PREFIX."posts WHERE 1=0");
 538                  $msgmax = $db->field_len($query, 0);
 539                  $submax = $db->field_len($query, 1);
 540                  $db->free_result($query);
 541                  if (strlen($dbmessage) > $msgmax) {
 542                      $dbmessage = substr($dbmessage, 0, $msgmax);
 543                  }
 544                  if (strlen($dbsubject) > $submax) {
 545                      $dbsubject = substr($dbsubject, 0, $submax);
 546                  }
 547              }
 548  
 549              $db->escape_fast($dbmessage);
 550              $db->escape_fast($dbsubject);
 551  
 552              $db->query("INSERT INTO ".X_PREFIX."posts (fid, tid, author, message, subject, dateline, icon, usesig, useip, bbcodeoff, smileyoff) VALUES ($fid, $tid, '$username', '$dbmessage', '$dbsubject', ".$db->time(time()).", '$posticon', '$usesig', '$onlineip', '$bbcodeoff', '$smileyoff')");
 553              $pid = $db->insert_id();
 554  
 555              $moderator = (modcheck($username, $forum['moderator']) == 'Moderator');
 556              if ($moderator && $closetopic == 'yes') {
 557                  $db->query("UPDATE ".X_PREFIX."threads SET closed='yes' WHERE tid='$tid' AND fid='$fid'");
 558              }
 559  
 560              $db->query("UPDATE ".X_PREFIX."threads SET lastpost='$thatime|$username|$pid', replies=replies+1 WHERE tid=$tid");
 561  
 562              $where = "WHERE fid=$fid";
 563              if ($forum['type'] == 'sub') {
 564                  $where .= " OR fid={$forum['fup']}";
 565              }
 566              $db->query("UPDATE ".X_PREFIX."forums SET lastpost='$thatime|$username|$pid', posts=posts+1 $where");
 567              unset($where);
 568  
 569              if ($username != 'Anonymous') {
 570                  $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum+1 WHERE username='$username'");
 571  
 572                  if ($emailnotify == 'yes') {
 573                      $query = $db->query("SELECT tid FROM ".X_PREFIX."favorites WHERE tid='$tid' AND username='$username' AND type='subscription'");
 574                      if ($db->num_rows($query) < 1) {
 575                          $db->query("INSERT INTO ".X_PREFIX."favorites (tid, username, type) VALUES ($tid, '$username', 'subscription')");
 576                      }
 577                      $db->free_result($query);
 578                  }
 579              }
 580  
 581              $query = $db->query("SELECT COUNT(pid) FROM ".X_PREFIX."posts WHERE pid <= $pid AND tid='$tid'");
 582              $posts = $db->result($query,0);
 583              $db->free_result($query);
 584  
 585              $lang2 = loadPhrases(array('charset','textsubsubject','textsubbody'));
 586              $viewperm = getOneForumPerm($forum, X_PERMS_RAWVIEW);
 587  
 588              $query = $db->query("SELECT dateline FROM ".X_PREFIX."posts WHERE tid = $tid AND pid < $pid ORDER BY dateline DESC LIMIT 1");
 589              if ($db->num_rows($query) > 0) {
 590                  $date = $db->result($query, 0);
 591              } else {
 592                  // Replying to a thread that has zero posts.
 593                  $date = '0';
 594              }
 595              $db->free_result($query);
 596  
 597              $subquery = $db->query("SELECT m.email, m.lastvisit, m.ppp, m.status, m.langfile "
 598                                   . "FROM ".X_PREFIX."favorites f "
 599                                   . "INNER JOIN ".X_PREFIX."members m USING (username) "
 600                                   . "WHERE f.type = 'subscription' AND f.tid = $tid AND m.username != '$username' AND m.lastvisit >= $date");
 601              while($subs = $db->fetch_array($subquery)) {
 602                  if ($viewperm < $status_enum[$subs['status']]) {
 603                      continue;
 604                  }
 605  
 606                  if ($subs['ppp'] < 1) {
 607                      $subs['ppp'] = $posts;
 608                  }
 609  
 610                  $translate = $lang2[$subs['langfile']];
 611                  $topicpages = quickpage($posts, $subs['ppp']);
 612                  $topicpages = ($topicpages == 1) ? '' : '&page='.$topicpages;
 613                  $threadurl = $full_url.'viewthread.php?tid='.$tid.$topicpages.'#pid'.$pid;
 614                  $rawsubject = htmlspecialchars_decode($threadname, ENT_QUOTES);
 615                  $rawusername = htmlspecialchars_decode($username, ENT_QUOTES);
 616                  $rawemail = htmlspecialchars_decode($subs['email'], ENT_QUOTES);
 617                  $rawbbname = htmlspecialchars_decode($bbname, ENT_NOQUOTES);
 618                  $headers = array();
 619                  $headers[] = smtpHeaderFrom($rawbbname, $adminemail);
 620                  $headers[] = 'X-Mailer: PHP';
 621                  $headers[] = 'X-AntiAbuse: Board servername - '.$cookiedomain;
 622                  $headers[] = 'X-AntiAbuse: Username - '.$rawusername;
 623                  $headers[] = 'Content-Type: text/plain; charset='.$translate['charset'];
 624                  $headers = implode("\r\n", $headers);
 625                  altMail($rawemail, $rawsubject.' ('.$translate['textsubsubject'].')', $rawusername.' '.$translate['textsubbody']." \n".$threadurl, $headers);
 626              }
 627              $db->free_result($subquery);
 628  
 629              if ($forum['attachstatus'] == 'on') {
 630                  if ($attachSkipped) {
 631                      for ($i=1; $i<=$SETTINGS['filesperpost']; $i++) {
 632                          if (isset($_FILES['attach'.$i])) {
 633                              attachUploadedFile('attach'.$i, $pid);
 634                          }
 635                      }
 636                      if ($SETTINGS['attach_remote_images'] == 'on' And $bIMGcodeOnForThisPost) {
 637                          extractRemoteImages($pid, $messageinput);
 638                          $newdbmessage = addslashes($messageinput);
 639                          $db->escape_fast($newdbmessage);
 640                          if ($newdbmessage != $dbmessage) { // Anonymous message was modified after save, in order to use the pid.
 641                              $db->query("UPDATE ".X_PREFIX."posts SET message='$newdbmessage' WHERE pid=$pid");
 642                          }
 643                      }
 644                  } elseif ($username != 'Anonymous') {
 645                      claimOrphanedAttachments($pid);
 646                  }
 647              }
 648  
 649              $topicpages = quickpage($posts, $ppp);
 650              $topicpages = ($topicpages == 1) ? '' : '&page='.$topicpages;
 651              message($lang['replymsg'], TRUE, '', '', $full_url."viewthread.php?tid={$tid}{$topicpages}#pid{$pid}", true, false, true);
 652          }
 653  
 654          if (!$replyvalid) {
 655              if (isset($repquote) && ($repquote = (int) $repquote)) {
 656                  $query = $db->query("SELECT p.message, p.tid, p.fid, p.author FROM ".X_PREFIX."posts p WHERE p.pid=$repquote");
 657                  $thaquote = $db->fetch_array($query);
 658                  $db->free_result($query);
 659                  $quoteperms = checkForumPermissions(getForum($thaquote['fid']));
 660                  if ($quoteperms[X_PERMS_VIEW] And $quoteperms[X_PERMS_PASSWORD]) {
 661                      $thaquote['message'] = preg_replace('@\\[file\\]\\d*\\[/file\\]@', '', $thaquote['message']); //These codes will not work inside quotes.
 662                      $quoteblock = rawHTMLmessage(stripslashes($thaquote['message'])); //Messages are historically double-quoted.
 663                      if ($bBBcodeOnForThisPost) {
 664                          $messageinput = "[rquote=$repquote&amp;tid={$thaquote['tid']}&amp;author={$thaquote['author']}]{$quoteblock}[/rquote]";
 665                      } else {
 666                          $quotesep = '|| ';
 667                          $quoteblock = $quotesep.str_replace("\n", "\n$quotesep", $quoteblock);
 668                          $messageinput = "{$lang['textquote']} {$lang['origpostedby']} {$thaquote['author']}\r\n$quotesep\r\n$quoteblock\r\n\r\n";
 669                      }
 670                  }
 671              }
 672  
 673              // Fill $attachfile
 674              $files = array();
 675              if ($forum['attachstatus'] == 'on' And $username != 'Anonymous') {
 676                  $attachfile = '';
 677                  $query = $db->query("SELECT a.aid, a.pid, a.filename, a.filetype, a.filesize, a.downloads, a.img_size, thumbs.aid AS thumbid, thumbs.filename AS thumbname, thumbs.img_size AS thumbsize FROM ".X_PREFIX."attachments AS a LEFT JOIN ".X_PREFIX."attachments AS thumbs ON a.aid=thumbs.parentid WHERE a.uid={$self['uid']} AND a.pid=0 AND a.parentid=0");
 678                  $counter = 0;
 679                  while ($postinfo = $db->fetch_array($query)) {
 680                      $files[] = $postinfo;
 681                      $postinfo['filename'] = attrOut($postinfo['filename']);
 682                      $postinfo['filesize'] = number_format($postinfo['filesize'], 0, '.', ',');
 683                      eval('$attachfile .= "'.template('post_attachment_orphan').'";');
 684                      if ($bBBcodeOnForThisPost) {
 685                          $bbcode = "[file]{$postinfo['aid']}[/file]";
 686                          if (strpos($messageinput, $bbcode) === FALSE) {
 687                              if ($counter == 0 Or $postinfo['img_size'] == '' Or $prevsize = '' Or $SETTINGS['attachimgpost'] == 'off') {
 688                                  $messageinput .= "\r\n\r\n";
 689                              }
 690                              $messageinput .= ' '.$bbcode; // Use a leading space to prevent awkward line wraps.
 691                              $counter++;
 692                              $prevsize = $postinfo['img_size'];
 693                          }
 694                      }
 695                  }
 696                  $maxtotal = phpShorthandValue('post_max_size');
 697                  if ($maxtotal > 0) {
 698                      $lang['attachmaxtotal'] .= ' '.getSizeFormatted($maxtotal);
 699                  } else {
 700                      $lang['attachmaxtotal'] = '';
 701                  }
 702                  $maxuploads = $SETTINGS['filesperpost'] - $db->num_rows($query);
 703                  if ($maxuploads > 0) {
 704                      $max_dos_limit = (int) ini_get('max_file_uploads');
 705                      if ($max_dos_limit > 0) $maxuploads = min($maxuploads, $max_dos_limit);
 706                      eval('$attachfile .= "'.template("post_attachmentbox").'";');
 707                  }
 708                  $db->free_result($query);
 709              }
 710  
 711              //Allow sanitized message to pass-through to template in case of: #1 preview, #2 post error
 712              $subject = rawHTMLsubject($subjectinput);
 713              $message = rawHTMLmessage($messageinput);
 714  
 715              if (isset($previewpost)) {
 716                  if ($posticon != '') {
 717                      $thread['icon'] = "<img src=\"$smdir/$posticon\" />";
 718                  } else {
 719                      $thread['icon'] = '';
 720                  }
 721                  $currtime = $onlinetime + ($timeoffset * 3600) + ($addtime * 3600);
 722                  $date = gmdate($dateformat, $currtime);
 723                  $time = gmdate($timecode, $currtime);
 724                  $poston = $lang['textposton'].' '.$date.' '.$lang['textat'].' '.$time;
 725                  if (strlen($subject) > 0) {
 726                      $dissubject = $subject.'<br />';
 727                  }
 728                  if ($bBBcodeOnForThisPost) {
 729                      postLinkBBcode($messageinput);
 730                  }
 731                  if (count($files) > 0) {
 732                      bbcodeFileTags($messageinput, $files, 0, $bBBcodeOnForThisPost);
 733                  }
 734                  $message1 = postify($messageinput, $smileyoff, $bbcodeoff, $forum['allowsmilies'], $forum['allowhtml'], $forum['allowbbcode'], $forum['allowimgcode']);
 735  
 736                  if ($usesig == 'yes') {
 737                      $post['sig'] = postify($self['sig'], 'no', 'no', $forum['allowsmilies'], $SETTINGS['sightml'], $SETTINGS['sigbbcode'], $forum['allowimgcode'], false);
 738                      eval('$message1 .= "'.template('viewthread_post_sig').'";');
 739                  } else {
 740                      eval('$message1 .= "'.template('viewthread_post_nosig').'";');
 741                  }
 742  
 743                  eval('$preview = "'.template('post_preview').'";');
 744              }
 745  
 746              if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on') {
 747                  $Captcha = new Captcha();
 748                  if ($Captcha->bCompatible !== false) {
 749                      $imghash = $Captcha->GenerateCode();
 750                      if ($SETTINGS['captcha_code_casesensitive'] == 'off') {
 751                          $lang['captchacaseon'] = '';
 752                      }
 753                      eval('$captchapostcheck = "'.template('post_captcha').'";');
 754                  }
 755                  unset($Captcha);
 756              }
 757  
 758              $posts = '';
 759  
 760              if (modcheck($username, $forum['moderator']) == 'Moderator') {
 761                  $closeoption = '<br /><input type="checkbox" name="closetopic" value="yes" '.$closecheck.' /> '.$lang['closemsgques'].'<br />';
 762              } else {
 763                  $closeoption = '';
 764              }
 765  
 766              $querytop = $db->query("SELECT COUNT(tid) FROM ".X_PREFIX."posts WHERE tid='$tid'");
 767              $replynum = $db->result($querytop, 0);
 768              if ($replynum >= $ppp) {
 769                  $threadlink = 'viewthread.php?fid='.$fid.'&tid='.$tid;
 770                  eval($lang['evaltrevlt']);
 771                  eval('$posts .= "'.template('post_reply_review_toolong').'";');
 772              } else {
 773                  $thisbg = $altbg1;
 774                  $query = $db->query("SELECT * FROM ".X_PREFIX."posts WHERE tid='$tid' ORDER BY dateline DESC");
 775                  while($post = $db->fetch_array($query)) {
 776                      $currtime = $post['dateline'] + ($timeoffset * 3600) + ($addtime * 3600);
 777                      $date = gmdate($dateformat, $currtime);
 778                      $time = gmdate($timecode, $currtime);
 779                      $poston = $lang['textposton'].' '.$date.' '.$lang['textat'].' '.$time;
 780  
 781                      if ($post['icon'] != '') {
 782                          $post['icon'] = '<img src="'.$smdir.'/'.$post['icon'].'" alt="'.$lang['altpostmood'].'" border="0" />';
 783                      } else {
 784                          $post['icon'] = '<img src="'.$imgdir.'/default_icon.gif" alt="[*]" border="0" />';
 785                      }
 786  
 787                      $post['message'] = preg_replace('@\\[file\\]\\d*\\[/file\\]@', '', $post['message']); //These codes do not work in postify()
 788                      $post['message'] = postify(stripslashes($post['message']), $post['smileyoff'], $post['bbcodeoff'], $forum['allowsmilies'], $forum['allowhtml'], $forum['allowbbcode'], $forum['allowimgcode']);
 789                      eval('$posts .= "'.template('post_reply_review_post').'";');
 790                      if ($thisbg == $altbg2) {
 791                          $thisbg = $altbg1;
 792                      } else {
 793                          $thisbg = $altbg2;
 794                      }
 795                  }
 796                  $db->free_result($query);
 797              }
 798              $db->free_result($querytop);
 799  
 800              if (getOneForumPerm($forum, X_PERMS_RAWREPLY) == $status_enum['Guest']) { // Member posting is not allowed, do not request credentials!
 801                  $loggedin = '';
 802              }
 803  
 804              eval('$postpage = "'.template('post_reply').'";');
 805          }
 806          break;
 807  
 808      case 'newthread':
 809          if ($poll == 'yes') {
 810              nav($lang['textnewpoll']);
 811          } else {
 812              nav($lang['textpostnew']);
 813          }
 814  
 815          if ($SETTINGS['subject_in_title'] == 'on') {
 816              $threadSubject = '- '.$dissubject;
 817          }
 818  
 819          eval('$header = "'.template('header').'";');
 820  
 821          $pollanswers = postedVar('pollanswers', '', TRUE, FALSE);
 822          $topicvalid = onSubmit('topicsubmit'); // This new flag will indicate a message was submitted and successful.
 823  
 824          if ($forum['attachstatus'] == 'on' And $username != 'Anonymous') {
 825              for ($i=1; $i<=$SETTINGS['filesperpost']; $i++) {
 826                  if (isset($_FILES['attach'.$i])) {
 827                      $result = attachUploadedFile('attach'.$i);
 828                      if ($result < 0 And $result != X_EMPTY_UPLOAD) {
 829                          $errors .= softerror($attachmentErrors[$result]);
 830                          $topicvalid = FALSE;
 831                      }
 832                  }
 833              }
 834              $result = doAttachmentEdits($deletes);
 835              if ($result < 0) {
 836                  $errors .= softerror($attachmentErrors[$result]);
 837                  $topicvalid = FALSE;
 838              }
 839              foreach($deletes as $aid) {
 840                  $messageinput = str_replace("[file]{$aid}[/file]", '', $messageinput);
 841              }
 842              if ($SETTINGS['attach_remote_images'] == 'on' And $bIMGcodeOnForThisPost) {
 843                  $result = extractRemoteImages(0, $messageinput);
 844                  if ($result < 0) {
 845                      $errors .= softerror($attachmentErrors[$result]);
 846                      $topicvalid = FALSE;
 847                  }
 848              }
 849              $attachSkipped = FALSE;
 850          } else {
 851              $attachSkipped = TRUE;
 852          }
 853  
 854          if ($topicvalid) {
 855              if (X_GUEST) { // Anonymous posting is allowed, and was checked in forum perms at top of file.
 856                  $password = '';
 857                  if (strlen(postedVar('username')) > 0 And isset($_POST['password'])) {
 858                      if (loginUser(postedVar('username'), md5($_POST['password']))) {
 859                          if ($self['status'] == "Banned") {
 860                              $errors .= softerror($lang['bannedmessage']);
 861                              $topicvalid = FALSE;
 862                          } else if ($self['ban'] == "posts" || $self['ban'] == "both") {
 863                              $errors .= softerror($lang['textbanfrompost']);
 864                              $topicvalid = FALSE;
 865                          } else {
 866                              $username = $xmbuser;
 867  
 868                              // check permissions on this forum (and top forum if it's a sub?)
 869                              $perms = checkForumPermissions($forum);
 870                              if (!$perms[X_PERMS_VIEW]) {
 871                                  $errors .= softerror($lang['privforummsg']);
 872                                  $topicvalid = FALSE;
 873                              } else if (($poll == '' && !$perms[X_PERMS_THREAD]) || ($poll == 'yes' && !$perms[X_PERMS_POLL])) {
 874                                  $errors .= softerror($lang['textnoaction']);
 875                                  $topicvalid = FALSE;
 876                              }
 877  
 878                              if ($forum['type'] == 'sub') {
 879                                  // prevent access to subforum when upper forum can't be viewed.
 880                                  $fupPerms = checkForumPermissions($fup);
 881                                  if (!$fupPerms[X_PERMS_VIEW]) {
 882                                      $errors .= softerror($lang['privforummsg']);
 883                                      $topicvalid = FALSE;
 884                                  }
 885                              }
 886                          }
 887                      } else {
 888                          $errors .= softerror($lang['textpw1']);
 889                          $topicvalid = FALSE;
 890                      }
 891                  } else if ($SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on') {
 892                      $Captcha = new Captcha();
 893                      if ($Captcha->bCompatible !== false) {
 894                          $imgcode = postedVar('imgcode', '', FALSE, FALSE);
 895                          $imghash = postedVar('imghash');
 896                          if ($Captcha->ValidateCode($imgcode, $imghash) !== TRUE) {
 897                              $errors .= softerror($lang['captchaimageinvalid']);
 898                              $topicvalid = FALSE;
 899                          }
 900                      }
 901                      unset($Captcha);
 902                  }
 903              }
 904          }
 905  
 906          if ($topicvalid) {
 907              if (strlen($subjectinput) == 0) {
 908                  $errors .= softerror($lang['textnosubject']);
 909                  $topicvalid = FALSE;
 910              }
 911          }
 912  
 913          if ($topicvalid) {
 914              if ($posticon != '') {
 915                  $query = $db->query("SELECT id FROM ".X_PREFIX."smilies WHERE type='picon' AND url='$posticon'");
 916                  if ($db->num_rows($query) == 0) {
 917                      $posticon = '';
 918                      $errors .= softerror($lang['error']);
 919                      $topicvalid = FALSE;
 920                  }
 921                  $db->free_result($query);
 922              }
 923          }
 924  
 925          if ($topicvalid) {
 926              if ($forum['lastpost'] != '') {
 927                  $lastpost = explode('|', $forum['lastpost']);
 928                  $rightnow = $onlinetime - $floodctrl;
 929                  if ($rightnow <= $lastpost[0] && $username == $lastpost[1]) {
 930                      $errors .= softerror($lang['floodprotect']);
 931                      $topicvalid = FALSE;
 932                  }
 933              }
 934          }
 935  
 936          if ($topicvalid) {
 937              if ($poll == 'yes') {
 938                  $pollopts = array();
 939                  $pollopts2 = explode("\n", $pollanswers);
 940                  foreach($pollopts2 as $value) {
 941                      $value = trim($value);
 942                      if ($value != '') {
 943                          $pollopts[] = $value;
 944                      }
 945                  }
 946                  $pnumnum = count($pollopts);
 947  
 948                  if ($pnumnum < 2) {
 949                      $errors .= softerror($lang['too_few_pollopts']);
 950                      $topicvalid = FALSE;
 951                  }
 952              }
 953          }
 954  
 955          if ($topicvalid) {
 956              $thatime = $onlinetime;
 957  
 958              if ($bBBcodeOnForThisPost) {
 959                  postLinkBBcode($messageinput);
 960              }
 961              $dbmessage = addslashes($messageinput); //The message column is historically double-quoted.
 962              $dbsubject = addslashes($subjectinput);
 963              $dbtsubject = $dbsubject;
 964  
 965              if (strlen($dbmessage) > 65535 or strlen($dbsubject) > 128) {
 966                  // Inputs are suspiciously long.  Has the schema been customized?
 967                  $query = $db->query("SELECT message, subject FROM ".X_PREFIX."posts WHERE 1=0");
 968                  $msgmax = $db->field_len($query, 0);
 969                  $submax = $db->field_len($query, 1);
 970                  $db->free_result($query);
 971                  if (strlen($dbmessage) > $msgmax) {
 972                      $dbmessage = substr($dbmessage, 0, $msgmax);
 973                  }
 974                  if (strlen($dbsubject) > $submax) {
 975                      $dbsubject = substr($dbsubject, 0, $submax);
 976                  }
 977  
 978                  $query = $db->query("SELECT subject FROM ".X_PREFIX."threads WHERE 1=0");
 979                  $tsubmax = $db->field_len($query, 0);
 980                  $db->free_result($query);
 981                  if (strlen($dbtsubject) > $tsubmax) {
 982                      $dbtsubject = substr($dbtsubject, 0, $tsubmax);
 983                  }
 984              }
 985  
 986              $db->escape_fast($dbmessage);
 987              $db->escape_fast($dbsubject);
 988              $db->escape_fast($dbtsubject);
 989  
 990              $db->query("INSERT INTO ".X_PREFIX."threads (fid, subject, icon, lastpost, views, replies, author, closed, topped) VALUES ($fid, '$dbtsubject', '$posticon', '$thatime|$username', 0, 0, '$username', '', 0)");
 991              $tid = $db->insert_id();
 992  
 993              $db->query("INSERT INTO ".X_PREFIX."posts (fid, tid, author, message, subject, dateline, icon, usesig, useip, bbcodeoff, smileyoff) VALUES ($fid, $tid, '$username', '$dbmessage', '$dbsubject', ".$db->time($thatime).", '$posticon', '$usesig', '$onlineip', '$bbcodeoff', '$smileyoff')");
 994              $pid = $db->insert_id();
 995  
 996              $db->query("UPDATE ".X_PREFIX."threads SET lastpost=concat(lastpost, '|".$pid."') WHERE tid='$tid'");
 997  
 998              $where = "WHERE fid=$fid";
 999              if ($forum['type'] == 'sub') {
1000                  $where .= " OR fid={$forum['fup']}";
1001              }
1002              $db->query("UPDATE ".X_PREFIX."forums SET lastpost='$thatime|$username|$pid', threads=threads+1, posts=posts+1 $where");
1003              unset($where);
1004  
1005              if ($poll == 'yes') {
1006                  $query = $db->query("SELECT vote_id, topic_id FROM ".X_PREFIX."vote_desc WHERE topic_id='$tid'");
1007                  if ($query) {
1008                      $vote_id = $db->fetch_array($query);
1009                      $vote_id = $vote_id['vote_id'];
1010                      if ($vote_id > 0) {
1011                          $db->query("DELETE FROM ".X_PREFIX."vote_results WHERE vote_id='$vote_id'");
1012                          $db->query("DELETE FROM ".X_PREFIX."vote_voters WHERE vote_id='$vote_id'");
1013                          $db->query("DELETE FROM ".X_PREFIX."vote_desc WHERE vote_id='$vote_id'");
1014                      }
1015                  }
1016                  $db->free_result($query);
1017  
1018                  $dbsubject = addslashes($subjectinput);
1019                  $db->escape_fast($dbsubject);
1020                  $db->query("INSERT INTO ".X_PREFIX."vote_desc (topic_id, vote_text) VALUES ($tid, '$dbsubject')");
1021                  $vote_id =  $db->insert_id();
1022                  $i = 1;
1023                  foreach($pollopts as $p) {
1024                      $db->escape_fast($p);
1025                      $db->query("INSERT INTO ".X_PREFIX."vote_results (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($vote_id, $i, '$p', 0)");
1026                      $i++;
1027                  }
1028                  $db->query("UPDATE ".X_PREFIX."threads SET pollopts=1 WHERE tid='$tid'");
1029              }
1030  
1031              if ($username != 'Anonymous') {
1032                  if ($emailnotify == 'yes') {
1033                      $query = $db->query("SELECT tid FROM ".X_PREFIX."favorites WHERE tid='$tid' AND username='$username' AND type='subscription'");
1034                      $thread = $db->fetch_array($query);
1035                      $db->free_result($query);
1036                      if (!$thread) {
1037                          $db->query("INSERT INTO ".X_PREFIX."favorites (tid, username, type) VALUES ($tid, '$username', 'subscription')");
1038                      }
1039                  }
1040  
1041                  $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum+1 WHERE username='$username'");
1042  
1043                  $moderator = (modcheck($username, $forum['moderator']) == 'Moderator');
1044                  if ($moderator) {
1045                      if ($toptopic == 'yes') {
1046                          $db->query("UPDATE ".X_PREFIX."threads SET topped='1' WHERE tid='$tid' AND fid='$fid'");
1047                      }
1048                      if ($closetopic == 'yes') {
1049                          $db->query("UPDATE ".X_PREFIX."threads SET closed='yes' WHERE tid='$tid' AND fid='$fid'");
1050                      }
1051                  }
1052              }
1053  
1054              if ($forum['attachstatus'] == 'on') {
1055                  if ($attachSkipped) {
1056                      for ($i=1; $i<=$SETTINGS['filesperpost']; $i++) {
1057                          if (isset($_FILES['attach'.$i])) {
1058                              attachUploadedFile('attach'.$i, $pid);
1059                          }
1060                      }
1061                      if ($SETTINGS['attach_remote_images'] == 'on' And $bIMGcodeOnForThisPost) {
1062                          extractRemoteImages($pid, $messageinput);
1063                          $newdbmessage = addslashes($messageinput);
1064                          $db->escape_fast($newdbmessage);
1065                          if ($newdbmessage != $dbmessage) { // Anonymous message was modified after save, in order to use the pid.
1066                              $db->query("UPDATE ".X_PREFIX."posts SET message='$newdbmessage' WHERE pid=$pid");
1067                          }
1068                      }
1069                  } elseif ($username != 'Anonymous') {
1070                      claimOrphanedAttachments($pid);
1071                  }
1072              }
1073  
1074              $query = $db->query("SELECT COUNT(tid) FROM ".X_PREFIX."posts WHERE tid='$tid'");
1075              $posts = $db->result($query, 0);
1076              $db->free_result($query);
1077  
1078              $topicpages = quickpage($posts, $ppp);
1079              $topicpages = ($topicpages == 1) ? '' : '&page='.$topicpages;
1080              message($lang['postmsg'], TRUE, '', '', $full_url."viewthread.php?tid={$tid}{$topicpages}#pid{$pid}", true, false, true);
1081          }
1082  
1083          if (!$topicvalid) {
1084              // Fill $attachfile
1085              $files = array();
1086              if ($forum['attachstatus'] == 'on' And $username != 'Anonymous') {
1087                  $attachfile = '';
1088                  $query = $db->query("SELECT a.aid, a.pid, a.filename, a.filetype, a.filesize, a.downloads, a.img_size, thumbs.aid AS thumbid, thumbs.filename AS thumbname, thumbs.img_size AS thumbsize FROM ".X_PREFIX."attachments AS a LEFT JOIN ".X_PREFIX."attachments AS thumbs ON a.aid=thumbs.parentid WHERE a.uid={$self['uid']} AND a.pid=0 AND a.parentid=0");
1089                  $counter = 0;
1090                  while ($postinfo = $db->fetch_array($query)) {
1091                      $files[] = $postinfo;
1092                      $postinfo['filename'] = attrOut($postinfo['filename']);
1093                      $postinfo['filesize'] = number_format($postinfo['filesize'], 0, '.', ',');
1094                      eval('$attachfile .= "'.template('post_attachment_orphan').'";');
1095                      if ($bBBcodeOnForThisPost) {
1096                          $bbcode = "[file]{$postinfo['aid']}[/file]";
1097                          if (strpos($messageinput, $bbcode) === FALSE) {
1098                              if ($counter == 0 Or $postinfo['img_size'] == '' Or $prevsize == '' Or $SETTINGS['attachimgpost'] == 'off') {
1099                                  $messageinput .= "\r\n\r\n";
1100                              }
1101                              $messageinput .= ' '.$bbcode; // Use a leading space to prevent awkward line wraps.
1102                              $counter++;
1103                              $prevsize = $postinfo['img_size'];
1104                          }
1105                      }
1106                  }
1107                  $maxtotal = phpShorthandValue('post_max_size');
1108                  if ($maxtotal > 0) {
1109                      $lang['attachmaxtotal'] .= ' '.getSizeFormatted($maxtotal);
1110                  } else {
1111                      $lang['attachmaxtotal'] = '';
1112                  }
1113                  $maxuploads = $SETTINGS['filesperpost'] - $db->num_rows($query);
1114                  if ($maxuploads > 0) {
1115                      $max_dos_limit = (int) ini_get('max_file_uploads');
1116                      if ($max_dos_limit > 0) $maxuploads = min($maxuploads, $max_dos_limit);
1117                      eval('$attachfile .= "'.template("post_attachmentbox").'";');
1118                  }
1119                  $db->free_result($query);
1120              }
1121  
1122              //Allow sanitized message to pass-through to template in case of: #1 preview, #2 post error
1123              $subject = rawHTMLsubject($subjectinput);
1124              $message = rawHTMLmessage($messageinput);
1125  
1126              if (isset($previewpost)) {
1127                  if ($posticon != '') {
1128                      $thread['icon'] = "<img src=\"$smdir/$posticon\" />";
1129                  } else {
1130                      $thread['icon'] = '';
1131                  }
1132                  $currtime = $onlinetime + ($timeoffset * 3600) + ($addtime * 3600);
1133                  $date = gmdate($dateformat, $currtime);
1134                  $time = gmdate($timecode, $currtime);
1135                  $poston = $lang['textposton'].' '.$date.' '.$lang['textat'].' '.$time;
1136                  if (strlen($subject) > 0) {
1137                      $dissubject = $subject.'<br />';
1138                  }
1139                  if ($bBBcodeOnForThisPost) {
1140                      postLinkBBcode($messageinput);
1141                  }
1142                  if (count($files) > 0) {
1143                      bbcodeFileTags($messageinput, $files, 0, $bBBcodeOnForThisPost);
1144                  }
1145                  $message1 = postify($messageinput, $smileyoff, $bbcodeoff, $forum['allowsmilies'], $forum['allowhtml'], $forum['allowbbcode'], $forum['allowimgcode']);
1146  
1147                  if ($usesig == 'yes') {
1148                      $post['sig'] = postify($self['sig'], 'no', 'no', $forum['allowsmilies'], $SETTINGS['sightml'], $SETTINGS['sigbbcode'], $forum['allowimgcode'], false);
1149                      eval('$message1 .= "'.template('viewthread_post_sig').'";');
1150                  } else {
1151                      eval('$message1 .= "'.template('viewthread_post_nosig').'";');
1152                  }
1153  
1154                  eval('$preview = "'.template('post_preview').'";');
1155              }
1156  
1157              if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on') {
1158                  $Captcha = new Captcha();
1159                  if ($Captcha->bCompatible !== false) {
1160                      $imghash = $Captcha->GenerateCode();
1161                      if ($SETTINGS['captcha_code_casesensitive'] == 'off') {
1162                          $lang['captchacaseon'] = '';
1163                      }
1164                      eval('$captchapostcheck = "'.template('post_captcha').'";');
1165                  }
1166                  unset($Captcha);
1167              }
1168  
1169              if (modcheck($username, $forum['moderator']) == 'Moderator') {
1170                  $topoption = '<br /><input type="checkbox" name="toptopic" value="yes" '.$topcheck.' /> '.$lang['topmsgques'];
1171                  $closeoption = '<br /><input type="checkbox" name="closetopic" value="yes" '.$closecheck.' /> '.$lang['closemsgques'].'<br />';
1172              } else {
1173                  $topoption = '';
1174                  $closeoption = '';
1175              }
1176  
1177              if (!isset($spelling_submit2)) {
1178                  $spelling_submit2 = '';
1179              }
1180  
1181              if (getOneForumPerm($forum, X_PERMS_RAWTHREAD) == $status_enum['Guest']) { // Member posting is not allowed, do not request credentials!
1182                  $loggedin = '';
1183              }
1184  
1185              if (isset($poll) && $poll == 'yes') {
1186                  eval('$postpage = "'.template('post_newpoll').'";');
1187              } else {
1188                  eval('$postpage = "'.template('post_newthread').'";');
1189              }
1190          }
1191          break;
1192  
1193      case 'edit':
1194          nav('<a href="viewthread.php?tid='.$tid.'">'.$threadname.'</a>');
1195          nav($lang['texteditpost']);
1196  
1197          if ($SETTINGS['subject_in_title'] == 'on') {
1198              $threadSubject = '- '.$threadname;
1199          }
1200  
1201          eval('$header = "'.template('header').'";');
1202  
1203          $editvalid = TRUE; // This new flag will indicate a message was submitted and successful.
1204  
1205          //Check all editing permissions for this $pid.  Based on viewthread design, forum Moderators can always edit, $orig['author'] can edit open threads only.
1206          $query = $db->query("SELECT p.*, m.status FROM ".X_PREFIX."posts p LEFT JOIN ".X_PREFIX."members m ON p.author=m.username WHERE p.pid=$pid");
1207          $orig = $db->fetch_array($query);
1208          $db->free_result($query);
1209  
1210          $status1 = modcheckPost($self['username'], $forum['moderator'], $orig['status']);
1211  
1212          if ($status1 != 'Moderator' And ($self['username'] != $orig['author'] Or $thread['closed'] != '')) {
1213              $errors .= softerror($lang['noedit']);
1214              $editvalid = FALSE;
1215          }
1216  
1217          if ($editvalid) {
1218              if ($forum['attachstatus'] == 'on') {
1219                  for ($i=1; $i<=$SETTINGS['filesperpost']; $i++) {
1220                      if (isset($_FILES['attach'.$i])) {
1221                          $result = attachUploadedFile('attach'.$i, $pid);
1222                          if ($result < 0 And $result != X_EMPTY_UPLOAD) {
1223                              $errors .= softerror($attachmentErrors[$result]);
1224                              $editvalid = FALSE;
1225                          }
1226                      }
1227                  }
1228                  $result = doAttachmentEdits($deletes, $pid);
1229                  if ($result < 0) {
1230                      $errors .= softerror($attachmentErrors[$result]);
1231                      $editvalid = FALSE;
1232                  }
1233                  foreach($deletes as $aid) {
1234                      $messageinput = str_replace("[file]{$aid}[/file]", '', $messageinput);
1235                  }
1236                  $temp = '';
1237                  if ($SETTINGS['attach_remote_images'] == 'on' And $bIMGcodeOnForThisPost) {
1238                      $result = extractRemoteImages($pid, $messageinput);
1239                      if ($result < 0) {
1240                          $errors .= softerror($attachmentErrors[$result]);
1241                          $editvalid = FALSE;
1242                      }
1243                  }
1244              }
1245          }
1246  
1247          $editvalid &= onSubmit('editsubmit');
1248  
1249          if ($editvalid) {
1250              if ($posticon != '') {
1251                  $query = $db->query("SELECT id FROM ".X_PREFIX."smilies WHERE type='picon' AND url='$posticon'");
1252                  if ($db->num_rows($query) == 0) {
1253                      $posticon = '';
1254                      $errors .= softerror($lang['error']);
1255                      $editvalid = FALSE;
1256                  }
1257                  $db->free_result($query);
1258              }
1259          }
1260  
1261          if ($editvalid) {
1262              $query = $db->query("SELECT pid FROM ".X_PREFIX."posts WHERE tid=$tid ORDER BY dateline LIMIT 1");
1263              $isfirstpost = $db->fetch_array($query);
1264              $db->free_result($query);
1265  
1266              if ((strlen($subjectinput) == 0 && $pid == $isfirstpost['pid']) && !(isset($delete) && $delete == 'yes')) {
1267                  $errors .= softerror($lang['textnosubject']);
1268                  $editvalid = FALSE;
1269              }
1270          }
1271  
1272          if ($editvalid) {
1273              $threaddelete = 'no';
1274  
1275              if (!(isset($delete) && $delete == 'yes')) {
1276                  if ($SETTINGS['editedby'] == 'on') {
1277                      $messageinput .= "\n\n[".$lang['textediton'].' '.gmdate($dateformat).' '.$lang['textby']." $username]";
1278                  }
1279  
1280                  if ($bBBcodeOnForThisPost) {
1281                      postLinkBBcode($messageinput);
1282                  }
1283                  $dbmessage = addslashes($messageinput); //The message column is historically double-quoted.
1284                  $dbsubject = addslashes($subjectinput);
1285  
1286                  if (strlen($dbmessage) > 65535 or strlen($dbsubject) > 255) {
1287                      // Inputs are suspiciously long.  Has the schema been customized?
1288                      $query = $db->query("SELECT message, subject FROM ".X_PREFIX."posts WHERE 1=0");
1289                      $msgmax = $db->field_len($query, 0);
1290                      $submax = $db->field_len($query, 1);
1291                      $db->free_result($query);
1292                      if (strlen($dbmessage) > $msgmax) {
1293                          $dbmessage = substr($dbmessage, 0, $msgmax);
1294                      }
1295                      if (strlen($dbsubject) > $submax) {
1296                          $dbsubject = substr($dbsubject, 0, $submax);
1297                      }
1298                  }
1299  
1300                  $db->escape_fast($dbmessage);
1301                  $db->escape_fast($dbsubject);
1302  
1303                  if ($isfirstpost['pid'] == $pid) {
1304                      $db->query("UPDATE ".X_PREFIX."threads SET icon='$posticon', subject='$dbsubject' WHERE tid=$tid");
1305                  }
1306  
1307                  $db->query("UPDATE ".X_PREFIX."posts SET message='$dbmessage', usesig='$usesig', bbcodeoff='$bbcodeoff', smileyoff='$smileyoff', icon='$posticon', subject='$dbsubject' WHERE pid=$pid");
1308              } else {
1309                  require_once ('include/attach.inc.php');
1310                  $db->query("DELETE FROM ".X_PREFIX."posts WHERE pid=$pid");
1311                  if ($orig['author'] != 'Anonymous') {
1312                      $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum-1 WHERE username='".$db->escape($orig['author'])."'");
1313                  }
1314                  deleteAllAttachments($pid);
1315  
1316                  if ($isfirstpost['pid'] == $pid) {
1317                      $query = $db->query("SELECT COUNT(pid) AS pcount FROM ".X_PREFIX."posts WHERE tid=$tid");
1318                      $numrows = $db->fetch_array($query);
1319                      $numrows = $numrows['pcount'];
1320                      $db->free_result($query);
1321  
1322                      if ($numrows == 0) {
1323                          $threaddelete = 'yes';
1324                          $db->query("DELETE FROM ".X_PREFIX."favorites WHERE tid='$tid'");
1325  
1326                          $db->query("DELETE FROM d, r, v "
1327                                   . "USING ".X_PREFIX."vote_desc AS d "
1328                                   . "LEFT JOIN ".X_PREFIX."vote_results AS r ON r.vote_id = d.vote_id "
1329                                   . "LEFT JOIN ".X_PREFIX."vote_voters AS v  ON v.vote_id = d.vote_id "
1330                                   . "WHERE d.topic_id = $tid");
1331  
1332                          $db->query("DELETE FROM ".X_PREFIX."threads WHERE tid=$tid OR closed='moved|$tid'");
1333                      } else {
1334                          $db->query("UPDATE ".X_PREFIX."posts SET subject='".$db->escape($orig['subject'])."' WHERE tid=$tid ORDER BY dateline LIMIT 1");
1335                      }
1336                  }
1337                  if ($forum['type'] == 'sub') {
1338                      updateforumcount($fup['fid']);
1339                  }
1340                  updatethreadcount($tid);
1341                  updateforumcount($fid);
1342              }
1343  
1344              if ($threaddelete == 'no') {
1345                  $query = $db->query("SELECT COUNT(pid) FROM ".X_PREFIX."posts WHERE dateline <= {$orig['dateline']} AND tid=$tid");
1346                  $posts = $db->result($query,0);
1347                  $db->free_result($query);
1348                  $topicpages = quickpage($posts, $ppp);
1349                  $topicpages = ($topicpages == 1) ? '' : '&page='.$topicpages;
1350                  message($lang['editpostmsg'], TRUE, '', '', $full_url."viewthread.php?tid={$tid}{$topicpages}#pid{$pid}", true, false, true);
1351              } else {
1352                  message($lang['editpostmsg'], TRUE, '', '', $full_url.'forumdisplay.php?fid='.$fid, true, false, true);
1353              }
1354          }
1355  
1356          if (!$editvalid) {
1357              // Fill $postinfo
1358              if (onSubmit('editsubmit') || isset($previewpost) || $sc) {
1359                  $postinfo = array("usesig"=>$usesig, "bbcodeoff"=>$bbcodeoff, "smileyoff"=>$smileyoff, "message"=>$messageinput, "subject"=>$subjectinput, 'icon'=>$posticon, 'dateline'=>$orig['dateline']);
1360              } else {
1361                  $postinfo = $orig;
1362                  $postinfo['message'] = stripslashes($postinfo['message']); //Messages are historically double-quoted.
1363                  $postinfo['subject'] = stripslashes($postinfo['subject']);
1364                  $bBBcodeOnForThisPost = ($forum['allowbbcode'] == 'yes' And $postinfo['bbcodeoff'] == 'no');
1365                  $bIMGcodeOnForThisPost = ($bBBcodeOnForThisPost And $forum['allowimgcode'] == 'yes');
1366                  $bSmiliesOnForThisPost = ($forum['allowsmilies'] == 'yes' And $postinfo['smileyoff'] == 'no');
1367              }
1368  
1369              // Fill $attachment
1370              $attachment = '';
1371              $files = array();
1372              if ($forum['attachstatus'] == 'on') {
1373                  $query = $db->query("SELECT a.aid, a.pid, a.filename, a.filetype, a.filesize, a.downloads, a.img_size, thumbs.aid AS thumbid, thumbs.filename AS thumbname, thumbs.img_size AS thumbsize FROM ".X_PREFIX."attachments AS a LEFT JOIN ".X_PREFIX."attachments AS thumbs ON a.aid=thumbs.parentid WHERE a.pid=$pid AND a.parentid=0");
1374                  $counter = 0;
1375                  while ($attach = $db->fetch_array($query)) {
1376                      $files[] = $attach;
1377                      $postinfo['aid'] = $attach['aid'];
1378                      $postinfo['downloads'] = $attach['downloads'];
1379                      $postinfo['filename'] = attrOut($attach['filename']);
1380                      $postinfo['filesize'] = number_format($attach['filesize'], 0, '.', ',');
1381                      $postinfo['url'] = getAttachmentURL($attach['aid'], $pid, $attach['filename']);
1382                      eval('$attachment .= "'.template('post_edit_attachment').'";');
1383                      if ($bBBcodeOnForThisPost) {
1384                          $bbcode = "[file]{$attach['aid']}[/file]";
1385                          if (strpos($postinfo['message'], $bbcode) === FALSE) {
1386                              if ($counter == 0 Or $attach['img_size'] == '' Or $prevsize = '' Or $SETTINGS['attachimgpost'] == 'off') {
1387                                  $postinfo['message'] .= "\r\n\r\n";
1388                              }
1389                              $postinfo['message'] .= ' '.$bbcode; // Use a leading space to prevent awkward line wraps.
1390                              $counter++;
1391                              $prevsize = $attach['img_size'];
1392                          }
1393                      }
1394                  }
1395                  $maxtotal = phpShorthandValue('post_max_size');
1396                  if ($maxtotal > 0) {
1397                      $lang['attachmaxtotal'] .= ' '.getSizeFormatted($maxtotal);
1398                  } else {
1399                      $lang['attachmaxtotal'] = '';
1400                  }
1401                  $maxuploads = $SETTINGS['filesperpost'] - $db->num_rows($query);
1402                  if ($maxuploads > 0) {
1403                      $max_dos_limit = (int) ini_get('max_file_uploads');
1404                      if ($max_dos_limit > 0) $maxuploads = min($maxuploads, $max_dos_limit);
1405                      eval('$attachment .= "'.template("post_attachmentbox").'";');
1406                  }
1407                  $db->free_result($query);
1408              }
1409  
1410              //Allow sanitized message to pass-through to template in case of: #1 preview, #2 post error
1411              $subject = rawHTMLsubject($postinfo['subject']);
1412              $message = rawHTMLmessage($postinfo['message']);
1413  
1414              if (isset($previewpost)) {
1415                  if ($postinfo['icon'] != '') {
1416                      $thread['icon'] = "<img src=\"$smdir/{$postinfo['icon']}\" />";
1417                  } else {
1418                      $thread['icon'] = '';
1419                  }
1420                  $currtime = $postinfo['dateline'] + ($timeoffset * 3600) + ($addtime * 3600);
1421                  $date = gmdate($dateformat, $currtime);
1422                  $time = gmdate($timecode, $currtime);
1423                  $poston = $lang['textposton'].' '.$date.' '.$lang['textat'].' '.$time;
1424                  if (strlen($subject) > 0) {
1425                      $dissubject = $subject.'<br />';
1426                  }
1427                  $message1 = $postinfo['message'];
1428                  if ($SETTINGS['editedby'] == 'on') {
1429                      $message1 .= "\n\n[".$lang['textediton'].' '.gmdate($dateformat).' '.$lang['textby']." $username]";
1430                  }
1431                  if ($bBBcodeOnForThisPost) {
1432                      postLinkBBcode($message1);
1433                  }
1434                  if (count($files) > 0) {
1435                      bbcodeFileTags($message1, $files, $pid, $bBBcodeOnForThisPost);
1436                  }
1437                  $message1 = postify($message1, $smileyoff, $bbcodeoff, $forum['allowsmilies'], $forum['allowhtml'], $forum['allowbbcode'], $forum['allowimgcode']);
1438  
1439                  if ($usesig == 'yes') {
1440                      $post['sig'] = postify($self['sig'], 'no', 'no', $forum['allowsmilies'], $SETTINGS['sightml'], $SETTINGS['sigbbcode'], $forum['allowimgcode'], false);
1441                      eval('$message1 .= "'.template('viewthread_post_sig').'";');
1442                  } else {
1443                      eval('$message1 .= "'.template('viewthread_post_nosig').'";');
1444                  }
1445  
1446                  eval('$preview = "'.template('post_preview').'";');
1447              }
1448  
1449              if ($postinfo['bbcodeoff'] == 'yes') {
1450                  $offcheck1 = $cheHTML;
1451              } else {
1452                  $offcheck1 = '';
1453              }
1454  
1455              if ($postinfo['smileyoff'] == 'yes') {
1456                  $offcheck2 = $cheHTML;
1457              } else {
1458                  $offcheck2 = '';
1459              }
1460  
1461              if ($postinfo['usesig'] == 'yes') {
1462                  $offcheck3 = $cheHTML;
1463              } else {
1464                  $offcheck3 = '';
1465              }
1466  
1467              $icons = str_replace('<input type="radio" name="posticon" value="'.$postinfo['icon'].'" />', '<input type="radio" name="posticon" value="'.$postinfo['icon'].'" checked="checked" />', $icons);
1468  
1469              $postinfo['message'] = rawHTMLmessage($postinfo['message']);
1470              $postinfo['subject'] = rawHTMLsubject($postinfo['subject']);
1471  
1472              eval('$postpage = "'.template('post_edit').'";');
1473          }
1474          break;
1475  
1476      default:
1477          error($lang['textnoaction']);
1478          break;
1479  }
1480  
1481  end_time();
1482  eval('$footer = "'.template('footer').'";');
1483  echo $header, $errors, $postpage, $footer;
1484  
1485  function postLinkBBcode(&$message) {
1486      global $db;
1487  
1488      $items = array();
1489      $pattern = "@\\[pid](\\d+)\\[/pid]@si";
1490      preg_match_all($pattern, $message, $results, PREG_SET_ORDER);
1491      if (count($results) == 0) {
1492          return TRUE;
1493      }
1494      foreach($results as $result) {
1495          $items[] = $result[1];
1496      }
1497  
1498      $pids = implode(', ', $items);
1499      $query = $db->query("SELECT p.pid, p.tid, p.subject, t.subject AS tsubject, t.fid FROM ".X_PREFIX."posts AS p LEFT JOIN ".X_PREFIX."threads AS t USING (tid) WHERE pid IN ($pids)");
1500      while($row = $db->fetch_array($query)) {
1501          $perms = checkForumPermissions(getForum($row['fid']));
1502          if ($perms[X_PERMS_VIEW] And $perms[X_PERMS_PASSWORD]) {
1503              if ($row['subject'] != '') {
1504                  $subject = stripslashes($row['subject']);
1505              } else {
1506                  $subject = stripslashes($row['tsubject']);
1507              }
1508              $pattern = "[pid]{$row['pid']}[/pid]";
1509              $replacement = "[pid={$row['pid']}&amp;tid={$row['tid']}]{$subject}[/pid]";
1510              $message = str_replace($pattern, $replacement, $message);
1511          }
1512      }
1513      return TRUE;
1514  }
1515  
1516  function softerror(&$msg) {
1517      return error($msg, FALSE, '', '<br />', FALSE, FALSE, TRUE, FALSE);
1518  }
1519  ?>

title

Description

title

Description

title

Description

title

title

Body