[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> newreply.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'newreply.php');
  13  
  14  $templatelist = "newreply,previewpost,loginbox,changeuserbox,posticons,newreply_threadreview,newreply_threadreview_post,forumdisplay_rules_link,newreply_multiquote_external,post_attachments_add,post_subscription_method";
  15  $templatelist .= ",codebuttons,post_attachments_new,post_attachments,post_savedraftbutton,newreply_modoptions,newreply_threadreview_more,postbit_online,postbit_pm,newreply_disablesmilies_hidden,post_attachments_update,postbit_icon";
  16  $templatelist .= ",postbit_email,postbit_warninglevel,postbit_author_user,postbit_edit,postbit_quickdelete,postbit_inlinecheck,postbit_posturl,postbit_quote,postbit_multiquote,newreply_modoptions_close,newreply_modoptions_stick";
  17  $templatelist .= ",post_attachments_attachment_postinsert,post_attachments_attachment_remove,post_attachments_attachment_unapproved,post_attachments_attachment,postbit_attachments_attachment,newreply_signature,postbit_report";
  18  $templatelist .= ",member_register_regimage,member_register_regimage_recaptcha,post_captcha_hidden,post_captcha,post_captcha_recaptcha,post_captcha_nocaptcha,postbit_groupimage,postbit_attachments,newreply_postoptions,postbit_reputation";
  19  $templatelist .= ",postbit_rep_button,postbit_warn,postbit_author_guest,postbit_signature,postbit_classic,postbit_attachments_thumbnails_thumbnailpostbit_attachments_images_image,postbit_attachments_attachment_unapproved,postbit_www";
  20  $templatelist .= ",postbit_attachments_thumbnails,postbit_attachments_images,postbit_gotopost,forumdisplay_password_wrongpass,forumdisplay_password,posticons_icon,attachment_icon,postbit_reputation_formatted_link,postbit_away";
  21  $templatelist .= ",global_moderation_notice,newreply_disablesmilies,postbit_userstar,newreply_draftinput,postbit_avatar,forumdisplay_rules,postbit_offline,postbit_find,postbit_warninglevel_formatted,postbit_ignored,postbit";
  22  
  23  require_once  "./global.php";
  24  require_once  MYBB_ROOT."inc/functions_post.php";
  25  require_once  MYBB_ROOT."inc/functions_user.php";
  26  require_once  MYBB_ROOT."inc/class_parser.php";
  27  $parser = new postParser;
  28  
  29  // Load global language phrases
  30  $lang->load("newreply");
  31  
  32  // Get the pid and tid and replyto from the input.
  33  $tid = $mybb->get_input('tid', MyBB::INPUT_INT);
  34  $replyto = $mybb->get_input('replyto', MyBB::INPUT_INT);
  35  
  36  // AJAX quick reply?
  37  if(!empty($mybb->input['ajax']))
  38  {
  39      unset($mybb->input['previewpost']);
  40  }
  41  
  42  // Edit a draft post.
  43  $pid = 0;
  44  $editdraftpid = '';
  45  $mybb->input['action'] = $mybb->get_input('action');
  46  if(($mybb->input['action'] == "editdraft" || $mybb->input['action'] == "do_newreply") && $mybb->get_input('pid', MyBB::INPUT_INT))
  47  {
  48      $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
  49      $post = get_post($pid);
  50      if(!$post)
  51      {
  52          error($lang->error_invalidpost);
  53      }
  54      else if($mybb->user['uid'] != $post['uid'])
  55      {
  56          error($lang->error_post_noperms);
  57      }
  58      $pid = $post['pid'];
  59      $tid = $post['tid'];
  60      eval("\$editdraftpid = \"".$templates->get("newreply_draftinput")."\";");
  61  }
  62  
  63  // Set up $thread and $forum for later use.
  64  $thread = get_thread($tid);
  65  if(!$thread)
  66  {
  67      error($lang->error_invalidthread);
  68  }
  69  $fid = $thread['fid'];
  70  
  71  // Get forum info
  72  $forum = get_forum($fid);
  73  if(!$forum)
  74  {
  75      error($lang->error_invalidforum);
  76  }
  77  
  78  // Make navigation
  79  build_forum_breadcrumb($fid);
  80  $thread_subject = $thread['subject'];
  81  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  82  add_breadcrumb($thread['subject'], get_thread_link($thread['tid']));
  83  add_breadcrumb($lang->nav_newreply);
  84  
  85  $forumpermissions = forum_permissions($fid);
  86  
  87  // See if everything is valid up to here.
  88  if(isset($post) && (($post['visible'] == 0 && !is_moderator($fid, "canviewunapprove")) || ($post['visible'] < 0 && $post['uid'] != $mybb->user['uid'])))
  89  {
  90      error($lang->error_invalidpost);
  91  }
  92  if(($thread['visible'] == 0 && !is_moderator($fid, "canviewunapprove")) || $thread['visible'] < 0)
  93  {
  94      error($lang->error_invalidthread);
  95  }
  96  if($forum['open'] == 0 || $forum['type'] != "f")
  97  {
  98      error($lang->error_closedinvalidforum);
  99  }
 100  if($forumpermissions['canview'] == 0 || $forumpermissions['canpostreplys'] == 0)
 101  {
 102      error_no_permission();
 103  }
 104  
 105  if($mybb->user['suspendposting'] == 1)
 106  {
 107      $suspendedpostingtype = $lang->error_suspendedposting_permanent;
 108      if($mybb->user['suspensiontime'])
 109      {
 110          $suspendedpostingtype = $lang->sprintf($lang->error_suspendedposting_temporal, my_date($mybb->settings['dateformat'], $mybb->user['suspensiontime']));
 111      }
 112  
 113      $lang->error_suspendedposting = $lang->sprintf($lang->error_suspendedposting, $suspendedpostingtype, my_date($mybb->settings['timeformat'], $mybb->user['suspensiontime']));
 114  
 115      error($lang->error_suspendedposting);
 116  }
 117  
 118  if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 119  {
 120      error_no_permission();
 121  }
 122  
 123  if(isset($forumpermissions['canonlyreplyownthreads']) && $forumpermissions['canonlyreplyownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 124  {
 125      error_no_permission();
 126  }
 127  
 128  // Coming from quick reply? Set some defaults
 129  if($mybb->get_input('method') == "quickreply")
 130  {
 131      if($mybb->user['subscriptionmethod'] == 1)
 132      {
 133          $mybb->input['postoptions']['subscriptionmethod'] = "none";
 134      }
 135      else if($mybb->user['subscriptionmethod'] == 2)
 136      {
 137          $mybb->input['postoptions']['subscriptionmethod'] = "email";
 138      }
 139      else if($mybb->user['subscriptionmethod'] == 3)
 140      {
 141          $mybb->input['postoptions']['subscriptionmethod'] = "pm";
 142      }
 143  }
 144  
 145  // Check if this forum is password protected and we have a valid password
 146  check_forum_password($forum['fid']);
 147  
 148  if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
 149  {
 150      $codebuttons = build_mycode_inserter("message", $forum['allowsmilies']);
 151      if($forum['allowsmilies'] != 0)
 152      {
 153          $smilieinserter = build_clickable_smilies();
 154      }
 155  }
 156  
 157  // Display a login box or change user box?
 158  if($mybb->user['uid'] != 0)
 159  {
 160      $mybb->user['username'] = htmlspecialchars_uni($mybb->user['username']);
 161      eval("\$loginbox = \"".$templates->get("changeuserbox")."\";");
 162  }
 163  else
 164  {
 165      if(empty($mybb->input['previewpost']) && $mybb->input['action'] != "do_newreply")
 166      {
 167          $username = '';
 168      }
 169      else
 170      {
 171          $username = htmlspecialchars_uni($mybb->get_input('username'));
 172      }
 173      eval("\$loginbox = \"".$templates->get("loginbox")."\";");
 174  }
 175  
 176  // Check to see if the thread is closed, and if the user is a mod.
 177  if(!is_moderator($fid, "canpostclosedthreads"))
 178  {
 179      if($thread['closed'] == 1)
 180      {
 181          error($lang->redirect_threadclosed);
 182      }
 183  }
 184  
 185  // No weird actions allowed, show new reply form if no regular action.
 186  if($mybb->input['action'] != "do_newreply" && $mybb->input['action'] != "editdraft")
 187  {
 188      $mybb->input['action'] = "newreply";
 189  }
 190  
 191  // Even if we are previewing, still show the new reply form.
 192  if(!empty($mybb->input['previewpost']))
 193  {
 194      $mybb->input['action'] = "newreply";
 195  }
 196  
 197  // Setup a unique posthash for attachment management
 198  if(!$mybb->get_input('posthash') && !$pid)
 199  {
 200      $mybb->input['posthash'] = md5($thread['tid'].$mybb->user['uid'].random_str());
 201  }
 202  
 203  if((empty($_POST) && empty($_FILES)) && $mybb->get_input('processed', MyBB::INPUT_INT) == 1)
 204  {
 205      error($lang->error_cannot_upload_php_post);
 206  }
 207  
 208  $errors = array();
 209  $maximageserror = $attacherror = '';
 210  if($mybb->settings['enableattachments'] == 1 && !$mybb->get_input('attachmentaid', MyBB::INPUT_INT) && ($mybb->get_input('newattachment') || $mybb->get_input('updateattachment') || ($mybb->input['action'] == "do_newreply" && $mybb->get_input('submit') && $_FILES['attachment'])))
 211  {
 212      // Verify incoming POST request
 213      verify_post_check($mybb->get_input('my_post_key'));
 214  
 215      if($pid)
 216      {
 217          $attachwhere = "pid='{$pid}'";
 218      }
 219      else
 220      {
 221          $attachwhere = "posthash='".$db->escape_string($mybb->get_input('posthash'))."'";
 222      }
 223  
 224      // If there's an attachment, check it and upload it
 225      if($forumpermissions['canpostattachments'] != 0)
 226      {
 227          // If attachment exists..
 228          if(!empty($_FILES['attachment']['name']) && !empty($_FILES['attachment']['type']))
 229          {
 230              if($_FILES['attachment']['size'] > 0)
 231              {
 232                  $query = $db->simple_select("attachments", "aid", "filename='".$db->escape_string($_FILES['attachment']['name'])."' AND {$attachwhere}");
 233                  $updateattach = $db->fetch_field($query, "aid");
 234  
 235                  require_once  MYBB_ROOT."inc/functions_upload.php";
 236  
 237                  $update_attachment = false;
 238                  if($updateattach > 0 && $mybb->get_input('updateattachment'))
 239                  {
 240                      $update_attachment = true;
 241                  }
 242                  $attachedfile = upload_attachment($_FILES['attachment'], $update_attachment);
 243              }
 244              else
 245              {
 246                  $errors[] = $lang->error_uploadempty;
 247                  $mybb->input['action'] = "newreply";
 248              }
 249          }
 250      }
 251  
 252      if(!empty($attachedfile['error']))
 253      {
 254          $errors[] = $attachedfile['error'];
 255          $mybb->input['action'] = "newreply";
 256      }
 257  
 258      if(!$mybb->get_input('submit'))
 259      {
 260          eval("\$editdraftpid = \"".$templates->get("newreply_draftinput")."\";");
 261          $mybb->input['action'] = "newreply";
 262      }
 263  }
 264  
 265  // Remove an attachment.
 266  if($mybb->settings['enableattachments'] == 1 && $mybb->get_input('attachmentaid', MyBB::INPUT_INT) && $mybb->get_input('attachmentact') == "remove")
 267  {
 268      // Verify incoming POST request
 269      verify_post_check($mybb->get_input('my_post_key'));
 270  
 271      require_once  MYBB_ROOT."inc/functions_upload.php";
 272      remove_attachment($pid, $mybb->get_input('posthash'), $mybb->get_input('attachmentaid', MyBB::INPUT_INT));
 273      if(!$mybb->get_input('submit'))
 274      {
 275          eval("\$editdraftpid = \"".$templates->get("newreply_draftinput")."\";");
 276          $mybb->input['action'] = "newreply";
 277      }
 278  }
 279  
 280  $reply_errors = '';
 281  $quoted_ids = array();
 282  $hide_captcha = false;
 283  
 284  // Check the maximum posts per day for this user
 285  if($mybb->usergroup['maxposts'] > 0 && $mybb->usergroup['cancp'] != 1)
 286  {
 287      $daycut = TIME_NOW-60*60*24;
 288      $query = $db->simple_select("posts", "COUNT(*) AS posts_today", "uid='{$mybb->user['uid']}' AND visible='1' AND dateline>{$daycut}");
 289      $post_count = $db->fetch_field($query, "posts_today");
 290      if($post_count >= $mybb->usergroup['maxposts'])
 291      {
 292          $lang->error_maxposts = $lang->sprintf($lang->error_maxposts, $mybb->usergroup['maxposts']);
 293          error($lang->error_maxposts);
 294      }
 295  }
 296  
 297  if($mybb->input['action'] == "do_newreply" && $mybb->request_method == "post")
 298  {
 299      // Verify incoming POST request
 300      verify_post_check($mybb->get_input('my_post_key'));
 301  
 302      $plugins->run_hooks("newreply_do_newreply_start");
 303  
 304      // If this isn't a logged in user, then we need to do some special validation.
 305      if($mybb->user['uid'] == 0)
 306      {
 307          // If they didn't specify a username then give them "Guest"
 308          if(!$mybb->get_input('username'))
 309          {
 310              $username = $lang->guest;
 311          }
 312          // Otherwise use the name they specified.
 313          else
 314          {
 315              $username = $mybb->get_input('username');
 316          }
 317          $uid = 0;
 318  
 319  
 320          if($mybb->settings['stopforumspam_on_newreply'])
 321          {
 322              require_once  MYBB_ROOT . '/inc/class_stopforumspamchecker.php';
 323  
 324              $stop_forum_spam_checker = new StopForumSpamChecker(
 325                  $plugins,
 326                  $mybb->settings['stopforumspam_min_weighting_before_spam'],
 327                  $mybb->settings['stopforumspam_check_usernames'],
 328                  $mybb->settings['stopforumspam_check_emails'],
 329                  $mybb->settings['stopforumspam_check_ips'],
 330                  $mybb->settings['stopforumspam_log_blocks']
 331              );
 332  
 333              try {
 334                  if($stop_forum_spam_checker->is_user_a_spammer($mybb->get_input('username'), '', get_ip()))
 335                  {
 336                      error($lang->sprintf($lang->error_stop_forum_spam_spammer,
 337                          $stop_forum_spam_checker->getErrorText(array(
 338                              'stopforumspam_check_usernames',
 339                              'stopforumspam_check_ips'
 340                              ))));
 341                  }
 342              }
 343              catch (Exception $e)
 344              {
 345                  if($mybb->settings['stopforumspam_block_on_error'])
 346                  {
 347                      error($lang->error_stop_forum_spam_fetching);
 348                  }
 349              }
 350          }
 351      }
 352      // This user is logged in.
 353      else
 354      {
 355          $username = $mybb->user['username'];
 356          $uid = $mybb->user['uid'];
 357      }
 358  
 359      // Attempt to see if this post is a duplicate or not
 360      if($uid > 0)
 361      {
 362          $user_check = "p.uid='{$uid}'";
 363      }
 364      else
 365      {
 366          $user_check = "p.ipaddress=".$db->escape_binary($session->packedip);
 367      }
 368      if(!$mybb->get_input('savedraft'))
 369      {
 370          $query = $db->simple_select("posts p", "p.pid, p.visible", "{$user_check} AND p.tid='{$thread['tid']}' AND p.subject='".$db->escape_string($mybb->get_input('subject'))."' AND p.message='".$db->escape_string($mybb->get_input('message'))."' AND p.visible != '-2' AND p.dateline>".(TIME_NOW-600));
 371          $duplicate_check = $db->fetch_field($query, "pid");
 372          if($duplicate_check)
 373          {
 374              error($lang->error_post_already_submitted);
 375          }
 376      }
 377  
 378      // Set up posthandler.
 379      require_once  MYBB_ROOT."inc/datahandlers/post.php";
 380      $posthandler = new PostDataHandler("insert");
 381  
 382      // Set the post data that came from the input to the $post array.
 383      $post = array(
 384          "tid" => $mybb->get_input('tid', MyBB::INPUT_INT),
 385          "replyto" => $mybb->get_input('replyto', MyBB::INPUT_INT),
 386          "fid" => $thread['fid'],
 387          "subject" => $mybb->get_input('subject'),
 388          "icon" => $mybb->get_input('icon', MyBB::INPUT_INT),
 389          "uid" => $uid,
 390          "username" => $username,
 391          "message" => $mybb->get_input('message'),
 392          "ipaddress" => $session->packedip,
 393          "posthash" => $mybb->get_input('posthash')
 394      );
 395  
 396      if(isset($mybb->input['pid']))
 397      {
 398          $post['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 399      }
 400  
 401      // Are we saving a draft post?
 402      if($mybb->get_input('savedraft') && $mybb->user['uid'])
 403      {
 404          $post['savedraft'] = 1;
 405      }
 406      else
 407      {
 408          $post['savedraft'] = 0;
 409      }
 410  
 411      $postoptions = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
 412      if(!isset($postoptions['signature']))
 413      {
 414          $postoptions['signature'] = 0;
 415      }
 416      if(!isset($postoptions['subscriptionmethod']))
 417      {
 418          $postoptions['subscriptionmethod'] = 0;
 419      }
 420      if(!isset($postoptions['disablesmilies']))
 421      {
 422          $postoptions['disablesmilies'] = 0;
 423      }
 424  
 425      // Set up the post options from the input.
 426      $post['options'] = array(
 427          "signature" => $postoptions['signature'],
 428          "subscriptionmethod" => $postoptions['subscriptionmethod'],
 429          "disablesmilies" => $postoptions['disablesmilies']
 430      );
 431  
 432      // Apply moderation options if we have them
 433      $post['modoptions'] = $mybb->get_input('modoptions', MyBB::INPUT_ARRAY);
 434  
 435      $posthandler->set_data($post);
 436  
 437      // Now let the post handler do all the hard work.
 438      $valid_post = $posthandler->validate_post();
 439  
 440      $post_errors = array();
 441      // Fetch friendly error messages if this is an invalid post
 442      if(!$valid_post)
 443      {
 444          $post_errors = $posthandler->get_friendly_errors();
 445      }
 446  
 447      // Mark thread as read
 448      require_once  MYBB_ROOT."inc/functions_indicators.php";
 449      mark_thread_read($tid, $fid);
 450  
 451      // Check captcha image
 452      if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
 453      {
 454          require_once  MYBB_ROOT.'inc/class_captcha.php';
 455          $post_captcha = new captcha(false, "post_captcha");
 456  
 457          if($post_captcha->validate_captcha() == false)
 458          {
 459              // CAPTCHA validation failed
 460              foreach($post_captcha->get_errors() as $error)
 461              {
 462                  $post_errors[] = $error;
 463              }
 464          }
 465          else
 466          {
 467              $hide_captcha = true;
 468          }
 469  
 470          if($mybb->get_input('ajax', MyBB::INPUT_INT))
 471          {
 472              if($post_captcha->type == 1)
 473              {
 474                  $randomstr = random_str(5);
 475                  $imagehash = md5(random_str(12));
 476  
 477                  $imagearray = array(
 478                      "imagehash" => $imagehash,
 479                      "imagestring" => $randomstr,
 480                      "dateline" => TIME_NOW
 481                  );
 482  
 483                  $db->insert_query("captcha", $imagearray);
 484  
 485                  //header("Content-type: text/html; charset={$lang->settings['charset']}");
 486                  $data = '';
 487                  $data .= "<captcha>$imagehash";
 488  
 489                  if($hide_captcha)
 490                  {
 491                      $data .= "|$randomstr";
 492                  }
 493  
 494                  $data .= "</captcha>";
 495  
 496                  //header("Content-type: application/json; charset={$lang->settings['charset']}");
 497                  $json_data = array("data" => $data);
 498              }
 499              else if($post_captcha->type == 2)
 500              {
 501                  //header("Content-type: text/html; charset={$lang->settings['charset']}");
 502                  $data = "<captcha>reload</captcha>";
 503  
 504                  //header("Content-type: application/json; charset={$lang->settings['charset']}");
 505                  $json_data = array("data" => $data);
 506              }
 507          }
 508      }
 509  
 510      // One or more errors returned, fetch error list and throw to newreply page
 511      if(count($post_errors) > 0)
 512      {
 513          $reply_errors = inline_error($post_errors, '', $json_data);
 514          $mybb->input['action'] = "newreply";
 515      }
 516      else
 517      {
 518          $postinfo = $posthandler->insert_post();
 519          $pid = $postinfo['pid'];
 520          $visible = $postinfo['visible'];
 521          $closed = $postinfo['closed'];
 522  
 523          // Invalidate solved captcha
 524          if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
 525          {
 526              $post_captcha->invalidate_captcha();
 527          }
 528  
 529          $force_redirect = false;
 530  
 531          // Deciding the fate
 532          if($visible == -2)
 533          {
 534              // Draft post
 535              $lang->redirect_newreply = $lang->draft_saved;
 536              $url = "usercp.php?action=drafts";
 537          }
 538          elseif($visible == 1)
 539          {
 540              // Visible post
 541              $lang->redirect_newreply .= $lang->redirect_newreply_post;
 542              $url = get_post_link($pid, $tid)."#pid{$pid}";
 543          }
 544          else
 545          {
 546              // Moderated post
 547              $lang->redirect_newreply .= '<br />'.$lang->redirect_newreply_moderation;
 548              $url = get_thread_link($tid);
 549  
 550              // User must see moderation notice, regardless of redirect settings
 551              $force_redirect = true;
 552          }
 553  
 554          // Mark any quoted posts so they're no longer selected - attempts to maintain those which weren't selected
 555          if(isset($mybb->input['quoted_ids']) && isset($mybb->cookies['multiquote']) && $mybb->settings['multiquote'] != 0)
 556          {
 557              // We quoted all posts - remove the entire cookie
 558              if($mybb->get_input('quoted_ids') == "all")
 559              {
 560                  my_unsetcookie("multiquote");
 561              }
 562              // Only quoted a few - attempt to remove them from the cookie
 563              else
 564              {
 565                  $quoted_ids = explode("|", $mybb->get_input('quoted_ids'));
 566                  $multiquote = explode("|", $mybb->cookies['multiquote']);
 567                  if(is_array($multiquote) && is_array($quoted_ids))
 568                  {
 569                      foreach($multiquote as $key => $quoteid)
 570                      {
 571                          // If this ID was quoted, remove it from the multiquote list
 572                          if(in_array($quoteid, $quoted_ids))
 573                          {
 574                              unset($multiquote[$key]);
 575                          }
 576                      }
 577                      // Still have an array - set the new cookie
 578                      if(is_array($multiquote))
 579                      {
 580                          $new_multiquote = implode(",", $multiquote);
 581                          my_setcookie("multiquote", $new_multiquote);
 582                      }
 583                      // Otherwise, unset it
 584                      else
 585                      {
 586                          my_unsetcookie("multiquote");
 587                      }
 588                  }
 589              }
 590          }
 591  
 592          $plugins->run_hooks("newreply_do_newreply_end");
 593  
 594          // This was a post made via the ajax quick reply - we need to do some special things here
 595          if($mybb->get_input('ajax', MyBB::INPUT_INT))
 596          {
 597              // Visible post
 598              if($visible == 1)
 599              {
 600                  // Set post counter
 601                  $postcounter = $thread['replies'] + 1;
 602  
 603                  if(is_moderator($fid, "canviewunapprove"))
 604                  {
 605                      $postcounter += $thread['unapprovedposts'];
 606                  }
 607                  if(is_moderator($fid, "canviewdeleted"))
 608                  {
 609                      $postcounter += $thread['deletedposts'];
 610                  }
 611  
 612                  // Was there a new post since we hit the quick reply button?
 613                  if($mybb->get_input('lastpid', MyBB::INPUT_INT))
 614                  {
 615                      $query = $db->simple_select("posts", "pid", "tid = '{$tid}' AND pid != '{$pid}'", array("order_by" => "pid", "order_dir" => "desc"));
 616                      $new_post = $db->fetch_array($query);
 617                      if($new_post['pid'] != $mybb->get_input('lastpid', MyBB::INPUT_INT))
 618                      {
 619                          redirect(get_thread_link($tid, 0, "lastpost"));
 620                      }
 621                  }
 622  
 623                  if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
 624                  {
 625                      $mybb->settings['postsperpage'] = 20;
 626                  }
 627  
 628                  // Lets see if this post is on the same page as the one we're viewing or not
 629                  // if it isn't, redirect us
 630                  if($perpage > 0 && (($postcounter) % $perpage) == 0)
 631                  {
 632                      $post_page = ($postcounter) / $mybb->settings['postsperpage'];
 633                  }
 634                  else
 635                  {
 636                      $post_page = (int)($postcounter / $mybb->settings['postsperpage']) + 1;
 637                  }
 638  
 639                  if($post_page > $mybb->get_input('from_page', MyBB::INPUT_INT))
 640                  {
 641                      redirect(get_thread_link($tid, 0, "lastpost"));
 642                      exit;
 643                  }
 644  
 645                  // Return the post HTML and display it inline
 646                  $query = $db->query("
 647                      SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
 648                      FROM ".TABLE_PREFIX."posts p
 649                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 650                      LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 651                      LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 652                      WHERE p.pid='{$pid}'
 653                  ");
 654                  $post = $db->fetch_array($query);
 655  
 656                  // Now lets fetch all of the attachments for this post
 657                  $query = $db->simple_select("attachments", "*", "pid='{$pid}'");
 658                  while($attachment = $db->fetch_array($query))
 659                  {
 660                      $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 661                  }
 662  
 663                  // Establish altbg - may seem like this is backwards, but build_postbit reverses it
 664                  if(($postcounter - $mybb->settings['postsperpage']) % 2 != 0)
 665                  {
 666                      $altbg = "trow1";
 667                  }
 668                  else
 669                  {
 670                      $altbg = "trow2";
 671                  }
 672  
 673                  $charset = "UTF-8";
 674                  if($lang->settings['charset'])
 675                  {
 676                      $charset = $lang->settings['charset'];
 677                  }
 678  
 679                  require_once  MYBB_ROOT."inc/functions_post.php";
 680                  $pid = $post['pid'];
 681                  $post = build_postbit($post);
 682  
 683                  $data = '';
 684                  $data .= $post;
 685  
 686                  // Build a new posthash incase the user wishes to quick reply again
 687                  $new_posthash = md5($mybb->user['uid'].random_str());
 688                  $data .= "<script type=\"text/javascript\">\n";
 689                  $data .= "var hash = document.getElementById('posthash'); if(hash) { hash.value = '{$new_posthash}'; }\n";
 690                  $data .= "if(typeof(inlineModeration) != 'undefined') {
 691                      $('#inlinemod_{$pid}').bind(\"click\", function(e) {
 692                          inlineModeration.checkItem();
 693                      });
 694                  }\n";
 695  
 696                  if($closed == 1)
 697                  {
 698                      $data .= "$('#quick_reply_form .trow1').removeClass('trow1 trow2').addClass('trow_shaded');\n";
 699                  }
 700                  else
 701                  {
 702                      $data .= "$('#quick_reply_form .trow_shaded').removeClass('trow_shaded').addClass('trow1');\n";
 703                  }
 704  
 705                  $data .= "</script>\n";
 706  
 707                  header("Content-type: application/json; charset={$lang->settings['charset']}");
 708                  echo json_encode(array("data" => $data));
 709  
 710                  exit;
 711              }
 712              // Post is in the moderation queue
 713              else
 714              {
 715                  redirect(get_thread_link($tid, 0, "lastpost"), $lang->redirect_newreply_moderation, "", true);
 716                  exit;
 717              }
 718          }
 719          else
 720          {
 721              $lang->redirect_newreply .= $lang->sprintf($lang->redirect_return_forum, get_forum_link($fid));
 722              redirect($url, $lang->redirect_newreply, "", $force_redirect);
 723              exit;
 724          }
 725      }
 726  }
 727  
 728  // Show the newreply form.
 729  if($mybb->input['action'] == "newreply" || $mybb->input['action'] == "editdraft")
 730  {
 731      $plugins->run_hooks("newreply_start");
 732  
 733      $quote_ids = $multiquote_external = '';
 734      // If this isn't a preview and we're not editing a draft, then handle quoted posts
 735      if(empty($mybb->input['previewpost']) && !$reply_errors && $mybb->input['action'] != "editdraft" && !$mybb->get_input('attachmentaid', MyBB::INPUT_INT) && !$mybb->get_input('newattachment') && !$mybb->get_input('updateattachment') && !$mybb->get_input('rem'))
 736      {
 737          $message = '';
 738          $quoted_posts = array();
 739          // Handle multiquote
 740          if(isset($mybb->cookies['multiquote']) && $mybb->settings['multiquote'] != 0)
 741          {
 742              $multiquoted = explode("|", $mybb->cookies['multiquote']);
 743              foreach($multiquoted as $post)
 744              {
 745                  $quoted_posts[$post] = (int)$post;
 746              }
 747          }
 748          // Handle incoming 'quote' button
 749          if($replyto)
 750          {
 751              $quoted_posts[$replyto] = $replyto;
 752          }
 753  
 754          // Quoting more than one post - fetch them
 755          if(count($quoted_posts) > 0)
 756          {
 757              $external_quotes = 0;
 758              $quoted_posts = implode(",", $quoted_posts);
 759              $unviewable_forums = get_unviewable_forums();
 760              $inactiveforums = get_inactive_forums();
 761              if($unviewable_forums)
 762              {
 763                  $unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})";
 764              }
 765              if($inactiveforums)
 766              {
 767                  $inactiveforums = "AND t.fid NOT IN ({$inactiveforums})";
 768              }
 769  
 770              // Check group permissions if we can't view threads not started by us
 771              $group_permissions = forum_permissions();
 772              $onlyusfids = array();
 773              $onlyusforums = '';
 774              foreach($group_permissions as $gpfid => $forum_permissions)
 775              {
 776                  if(isset($forum_permissions['canonlyviewownthreads']) && $forum_permissions['canonlyviewownthreads'] == 1)
 777                  {
 778                      $onlyusfids[] = $gpfid;
 779                  }
 780              }
 781              if(!empty($onlyusfids))
 782              {
 783                  $onlyusforums = "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
 784              }
 785  
 786              if(is_moderator($fid, 'canviewunapprove') && is_moderator($fid, 'canviewdeleted'))
 787              {
 788                  $visible_where = "AND p.visible IN (-1,0,1)";
 789              }
 790              elseif(is_moderator($fid, 'canviewunapprove') && !is_moderator($fid, 'canviewdeleted'))
 791              {
 792                  $visible_where = "AND p.visible IN (0,1)";
 793              }
 794              elseif(!is_moderator($fid, 'canviewunapprove') && is_moderator($fid, 'canviewdeleted'))
 795              {
 796                  $visible_where = "AND p.visible IN (-1,1)";
 797              }
 798              else
 799              {
 800                  $visible_where = "AND p.visible=1";
 801              }
 802  
 803              require_once  MYBB_ROOT."inc/functions_posting.php";
 804              $query = $db->query("
 805                  SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, u.username AS userusername
 806                  FROM ".TABLE_PREFIX."posts p
 807                  LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 808                  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 809                  WHERE p.pid IN ({$quoted_posts}) {$unviewable_forums} {$inactiveforums} {$onlyusforums} {$visible_where}
 810              ");
 811              $load_all = $mybb->get_input('load_all_quotes', MyBB::INPUT_INT);
 812              while($quoted_post = $db->fetch_array($query))
 813              {
 814                  // Only show messages for the current thread
 815                  if($quoted_post['tid'] == $tid || $load_all == 1)
 816                  {
 817                      // If this post was the post for which a quote button was clicked, set the subject
 818                      if($replyto == $quoted_post['pid'])
 819                      {
 820                          $subject = preg_replace('#^RE:\s?#i', '', $quoted_post['subject']);
 821                          // Subject too long? Shorten it to avoid error message
 822                          if(my_strlen($subject) > 85)
 823                          {
 824                              $subject = my_substr($subject, 0, 82).'...';
 825                          }
 826                          $subject = "RE: ".$subject;
 827                      }
 828                      $message .= parse_quoted_message($quoted_post);
 829                      $quoted_ids[] = $quoted_post['pid'];
 830                  }
 831                  // Count the rest
 832                  else
 833                  {
 834                      ++$external_quotes;
 835                  }
 836              }
 837              if($mybb->settings['maxquotedepth'] != '0')
 838              {
 839                  $message = remove_message_quotes($message);
 840              }
 841              if($external_quotes > 0)
 842              {
 843                  if($external_quotes == 1)
 844                  {
 845                      $multiquote_text = $lang->multiquote_external_one;
 846                      $multiquote_deselect = $lang->multiquote_external_one_deselect;
 847                      $multiquote_quote = $lang->multiquote_external_one_quote;
 848                  }
 849                  else
 850                  {
 851                      $multiquote_text = $lang->sprintf($lang->multiquote_external, $external_quotes);
 852                      $multiquote_deselect = $lang->multiquote_external_deselect;
 853                      $multiquote_quote = $lang->multiquote_external_quote;
 854                  }
 855                  eval("\$multiquote_external = \"".$templates->get("newreply_multiquote_external")."\";");
 856              }
 857              if(is_array($quoted_ids) && count($quoted_ids) > 0)
 858              {
 859                  $quoted_ids = implode("|", $quoted_ids);
 860              }
 861          }
 862      }
 863  
 864      if(isset($mybb->input['quoted_ids']))
 865      {
 866          $quoted_ids = htmlspecialchars_uni($mybb->get_input('quoted_ids', MyBB::INPUT_INT));
 867      }
 868  
 869      if(isset($mybb->input['previewpost']))
 870      {
 871          $previewmessage = $mybb->get_input('message');
 872      }
 873      if(empty($message))
 874      {
 875          $message = $mybb->get_input('message');
 876      }
 877      $message = htmlspecialchars_uni($message);
 878  
 879      $postoptionschecked = array('signature' => '', 'disablesmilies' => '');
 880      $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_email = $postoptions_subscriptionmethod_pm = '';
 881  
 882      // Set up the post options.
 883      if(!empty($mybb->input['previewpost']) || $reply_errors != '')
 884      {
 885          $postoptions = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
 886  
 887          if(isset($postoptions['signature']) && $postoptions['signature'] == 1)
 888          {
 889              $postoptionschecked['signature'] = " checked=\"checked\"";
 890          }
 891          if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "none")
 892          {
 893              $postoptions_subscriptionmethod_none = "checked=\"checked\"";
 894          }
 895          else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "email")
 896          {
 897              $postoptions_subscriptionmethod_email = "checked=\"checked\"";
 898          }
 899          else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "pm")
 900          {
 901              $postoptions_subscriptionmethod_pm = "checked=\"checked\"";
 902          }
 903          else
 904          {
 905              $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
 906          }
 907          if(isset($postoptions['disablesmilies']) && $postoptions['disablesmilies'] == 1)
 908          {
 909              $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
 910          }
 911          $subject = $mybb->input['subject'];
 912      }
 913      elseif($mybb->input['action'] == "editdraft" && $mybb->user['uid'])
 914      {
 915          $message = htmlspecialchars_uni($post['message']);
 916          $subject = $post['subject'];
 917          if($post['includesig'] != 0)
 918          {
 919              $postoptionschecked['signature'] = " checked=\"checked\"";
 920          }
 921          if($post['smilieoff'] == 1)
 922          {
 923              $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
 924          }
 925          if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "none")
 926          {
 927              $postoptions_subscriptionmethod_none = "checked=\"checked\"";
 928          }
 929          else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "email")
 930          {
 931              $postoptions_subscriptionmethod_email = "checked=\"checked\"";
 932          }
 933          else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "pm")
 934          {
 935              $postoptions_subscriptionmethod_pm = "checked=\"checked\"";
 936          }
 937          else
 938          {
 939              $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
 940          }
 941          $mybb->input['icon'] = $post['icon'];
 942      }
 943      else
 944      {
 945          if($mybb->user['signature'] != '')
 946          {
 947              $postoptionschecked['signature'] = " checked=\"checked\"";
 948          }
 949          if($mybb->user['subscriptionmethod'] ==  1)
 950          {
 951              $postoptions_subscriptionmethod_none = "checked=\"checked\"";
 952          }
 953          else if($mybb->user['subscriptionmethod'] == 2)
 954          {
 955              $postoptions_subscriptionmethod_email = "checked=\"checked\"";
 956          }
 957          else if($mybb->user['subscriptionmethod'] == 3)
 958          {
 959              $postoptions_subscriptionmethod_pm = "checked=\"checked\"";
 960          }
 961          else
 962          {
 963              $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
 964          }
 965      }
 966  
 967      if($forum['allowpicons'] != 0)
 968      {
 969          $posticons = get_post_icons();
 970      }
 971  
 972      // No subject?
 973      if(!isset($subject))
 974      {
 975          if(!empty($mybb->input['subject']))
 976          {
 977              $subject = $mybb->get_input('subject');
 978          }
 979          else
 980          {
 981              $subject = $thread_subject;
 982              // Subject too long? Shorten it to avoid error message
 983              if(my_strlen($subject) > 85)
 984              {
 985                  $subject = my_substr($subject, 0, 82).'...';
 986              }
 987              $subject = "RE: ".$subject;
 988          }
 989      }
 990  
 991      // Preview a post that was written.
 992      $preview = '';
 993      if(!empty($mybb->input['previewpost']))
 994      {
 995          // If this isn't a logged in user, then we need to do some special validation.
 996          if($mybb->user['uid'] == 0)
 997          {
 998              // If they didn't specify a username then give them "Guest"
 999              if(!$mybb->get_input('username'))
1000              {
1001                  $username = $lang->guest;
1002              }
1003              // Otherwise use the name they specified.
1004              else
1005              {
1006                  $username = $mybb->get_input('username');
1007              }
1008              $uid = 0;
1009          }
1010          // This user is logged in.
1011          else
1012          {
1013              $username = $mybb->user['username'];
1014              $uid = $mybb->user['uid'];
1015          }
1016  
1017          // Set up posthandler.
1018          require_once  MYBB_ROOT."inc/datahandlers/post.php";
1019          $posthandler = new PostDataHandler("insert");
1020          $posthandler->action = "post";
1021  
1022          // Set the post data that came from the input to the $post array.
1023          $post = array(
1024              "tid" => $mybb->get_input('tid', MyBB::INPUT_INT),
1025              "replyto" => $mybb->get_input('replyto', MyBB::INPUT_INT),
1026              "fid" => $thread['fid'],
1027              "subject" => $mybb->get_input('subject'),
1028              "icon" => $mybb->get_input('icon', MyBB::INPUT_INT),
1029              "uid" => $uid,
1030              "username" => $username,
1031              "message" => $mybb->get_input('message'),
1032              "ipaddress" => $session->packedip,
1033              "posthash" => $mybb->get_input('posthash')
1034          );
1035  
1036          if(isset($mybb->input['pid']))
1037          {
1038              $post['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
1039          }
1040  
1041          $posthandler->set_data($post);
1042  
1043          // Now let the post handler do all the hard work.
1044          $valid_post = $posthandler->verify_message();
1045          $valid_subject = $posthandler->verify_subject();
1046  
1047          // guest post --> verify author
1048          if($post['uid'] == 0)
1049          {
1050              $valid_username = $posthandler->verify_author();
1051          }
1052          else
1053          {
1054              $valid_username = true;
1055          }
1056  
1057          $post_errors = array();
1058          // Fetch friendly error messages if this is an invalid post
1059          if(!$valid_post || !$valid_subject || !$valid_username)
1060          {
1061              $post_errors = $posthandler->get_friendly_errors();
1062          }
1063  
1064          // One or more errors returned, fetch error list and throw to newreply page
1065          if(count($post_errors) > 0)
1066          {
1067              $reply_errors = inline_error($post_errors);
1068          }
1069          else
1070          {
1071              $quote_ids = htmlspecialchars_uni($mybb->get_input('quote_ids'));
1072              if(!isset($mybb->input['username']))
1073              {
1074                  $mybb->input['username'] = $lang->guest;
1075              }
1076              $mybb->input['icon'] = $mybb->get_input('icon', MyBB::INPUT_INT);
1077              $query = $db->query("
1078                  SELECT u.*, f.*
1079                  FROM ".TABLE_PREFIX."users u
1080                  LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
1081                  WHERE u.uid='".$mybb->user['uid']."'
1082              ");
1083              $post = $db->fetch_array($query);
1084              if(!$mybb->user['uid'] || !$post['username'])
1085              {
1086                  $post['username'] = $mybb->get_input('username');
1087              }
1088              else
1089              {
1090                  $post['userusername'] = $mybb->user['username'];
1091                  $post['username'] = $mybb->user['username'];
1092              }
1093              $post['message'] = $previewmessage;
1094              $post['subject'] = $subject;
1095              $post['icon'] = $mybb->get_input('icon', MyBB::INPUT_INT);
1096              $mybb->input['postoptions'] = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
1097              if(isset($mybb->input['postoptions']['disablesmilies']))
1098              {
1099                  $post['smilieoff'] = $mybb->input['postoptions']['disablesmilies'];
1100              }
1101              $post['dateline'] = TIME_NOW;
1102              if(isset($mybb->input['postoptions']['signature']))
1103              {
1104                  $post['includesig'] = $mybb->input['postoptions']['signature'];
1105              }
1106              if(!isset($post['includesig']) || $post['includesig'] != 1)
1107              {
1108                  $post['includesig'] = 0;
1109              }
1110  
1111              // Fetch attachments assigned to this post.
1112              if($mybb->get_input('pid', MyBB::INPUT_INT))
1113              {
1114                  $attachwhere = "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'";
1115              }
1116              else
1117              {
1118                  $attachwhere = "posthash='".$db->escape_string($mybb->get_input('posthash'))."'";
1119              }
1120  
1121              $query = $db->simple_select("attachments", "*", $attachwhere);
1122              while($attachment = $db->fetch_array($query))
1123              {
1124                  $attachcache[0][$attachment['aid']] = $attachment;
1125              }
1126  
1127              $postbit = build_postbit($post, 1);
1128              eval("\$preview = \"".$templates->get("previewpost")."\";");
1129          }
1130      }
1131  
1132      $subject = htmlspecialchars_uni($parser->parse_badwords($subject));
1133  
1134      $posthash = htmlspecialchars_uni($mybb->get_input('posthash'));
1135  
1136      // Do we have attachment errors?
1137      if(count($errors) > 0)
1138      {
1139          $reply_errors = inline_error($errors);
1140      }
1141  
1142      // Get a listing of the current attachments.
1143      if($mybb->settings['enableattachments'] != 0 && $forumpermissions['canpostattachments'] != 0)
1144      {
1145          $attachcount = 0;
1146          if($pid)
1147          {
1148              $attachwhere = "pid='$pid'";
1149          }
1150          else
1151          {
1152              $attachwhere = "posthash='".$db->escape_string($posthash)."'";
1153          }
1154          $attachments = '';
1155          $query = $db->simple_select("attachments", "*", $attachwhere);
1156          while($attachment = $db->fetch_array($query))
1157          {
1158              $attachment['size'] = get_friendly_size($attachment['filesize']);
1159              $attachment['icon'] = get_attachment_icon(get_extension($attachment['filename']));
1160              $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
1161  
1162              if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
1163              {
1164                  eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";");
1165              }
1166  
1167              $attach_mod_options = '';
1168              eval("\$attach_rem_options = \"".$templates->get("post_attachments_attachment_remove")."\";");
1169  
1170              if($attachment['visible'] != 1)
1171              {
1172                  eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";");
1173              }
1174              else
1175              {
1176                  eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";");
1177              }
1178              $attachcount++;
1179          }
1180  
1181          $noshowattach = '';
1182          $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
1183          $usage = $db->fetch_array($query);
1184  
1185          if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0)
1186          {
1187              $noshowattach = 1;
1188          }
1189  
1190          if($mybb->usergroup['attachquota'] == 0)
1191          {
1192              $friendlyquota = $lang->unlimited;
1193          }
1194          else
1195          {
1196              $friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
1197          }
1198  
1199          $friendlyusage = get_friendly_size($usage['ausage']);
1200          $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
1201  
1202          if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach)
1203          {
1204              eval("\$attach_add_options = \"".$templates->get("post_attachments_add")."\";");
1205          }
1206  
1207          if(($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']) && $attachcount > 0)
1208          {
1209              eval("\$attach_update_options = \"".$templates->get("post_attachments_update")."\";");
1210          }
1211  
1212          if($attach_add_options || $attach_update_options)
1213          {
1214              eval("\$newattach = \"".$templates->get("post_attachments_new")."\";");
1215          }
1216  
1217          eval("\$attachbox = \"".$templates->get("post_attachments")."\";");
1218      }
1219  
1220      // If the user is logged in, provide a save draft button.
1221      if($mybb->user['uid'])
1222      {
1223          eval("\$savedraftbutton = \"".$templates->get("post_savedraftbutton", 1, 0)."\";");
1224      }
1225  
1226      // Show captcha image for guests if enabled
1227      $captcha = '';
1228      if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
1229      {
1230          $correct = false;
1231          require_once  MYBB_ROOT.'inc/class_captcha.php';
1232          $post_captcha = new captcha(false, "post_captcha");
1233  
1234          if((!empty($mybb->input['previewpost']) || $hide_captcha == true) && $post_captcha->type == 1)
1235          {
1236              // If previewing a post - check their current captcha input - if correct, hide the captcha input area
1237              // ... but only if it's a default one, reCAPTCHA and Are You a Human must be filled in every time due to draconian limits
1238              if($post_captcha->validate_captcha() == true)
1239              {
1240                  $correct = true;
1241  
1242                  // Generate a hidden list of items for our captcha
1243                  $captcha = $post_captcha->build_hidden_captcha();
1244              }
1245          }
1246  
1247          if(!$correct)
1248          {
1249              if($post_captcha->type == 1)
1250              {
1251                  $post_captcha->build_captcha();
1252              }
1253              elseif($post_captcha->type == 2 || $post_captcha->type == 4)
1254              {
1255                  $post_captcha->build_recaptcha();
1256              }
1257  
1258              if($post_captcha->html)
1259              {
1260                  $captcha = $post_captcha->html;
1261              }
1262          }
1263          else if($correct && ($post_captcha->type == 2 || $post_captcha->type == 4))
1264          {
1265              $post_captcha->build_recaptcha();
1266  
1267              if($post_captcha->html)
1268              {
1269                  $captcha = $post_captcha->html;
1270              }
1271          }
1272      }
1273  
1274      $reviewmore = '';
1275      if($mybb->settings['threadreview'] != 0)
1276      {
1277          if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
1278          {
1279              $mybb->settings['postsperpage'] = 20;
1280          }
1281  
1282          if(is_moderator($fid, "canviewunapprove"))
1283          {
1284              $visibility = "(visible='1' OR visible='0')";
1285          }
1286          else
1287          {
1288              $visibility = "visible='1'";
1289          }
1290          $query = $db->simple_select("posts", "COUNT(pid) AS post_count", "tid='{$tid}' AND {$visibility}");
1291          $numposts = $db->fetch_field($query, "post_count");
1292  
1293          if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
1294          {
1295              $mybb->settings['postsperpage'] = 20;
1296          }
1297  
1298          if($numposts > $mybb->settings['postsperpage'])
1299          {
1300              $numposts = $mybb->settings['postsperpage'];
1301              $lang->thread_review_more = $lang->sprintf($lang->thread_review_more, $mybb->settings['postsperpage'], get_thread_link($tid));
1302              eval("\$reviewmore = \"".$templates->get("newreply_threadreview_more")."\";");
1303          }
1304  
1305          $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND {$visibility}", array("order_by" => "dateline", "order_dir" => "desc", "limit" => $mybb->settings['postsperpage']));
1306          while($post = $db->fetch_array($query))
1307          {
1308              $pidin[] = $post['pid'];
1309          }
1310  
1311          $pidin = implode(",", $pidin);
1312  
1313          // Fetch attachments
1314          $query = $db->simple_select("attachments", "*", "pid IN ($pidin)");
1315          while($attachment = $db->fetch_array($query))
1316          {
1317              $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
1318          }
1319          $query = $db->query("
1320              SELECT p.*, u.username AS userusername
1321              FROM ".TABLE_PREFIX."posts p
1322              LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
1323              WHERE pid IN ($pidin)
1324              ORDER BY dateline DESC
1325          ");
1326          $postsdone = 0;
1327          $altbg = "trow1";
1328          $reviewbits = '';
1329          while($post = $db->fetch_array($query))
1330          {
1331              if($post['userusername'])
1332              {
1333                  $post['username'] = $post['userusername'];
1334              }
1335              $reviewpostdate = my_date('relative', $post['dateline']);
1336              $parser_options = array(
1337                  "allow_html" => $forum['allowhtml'],
1338                  "allow_mycode" => $forum['allowmycode'],
1339                  "allow_smilies" => $forum['allowsmilies'],
1340                  "allow_imgcode" => $forum['allowimgcode'],
1341                  "allow_videocode" => $forum['allowvideocode'],
1342                  "me_username" => $post['username'],
1343                  "filter_badwords" => 1
1344              );
1345              if($post['smilieoff'] == 1)
1346              {
1347                  $parser_options['allow_smilies'] = 0;
1348              }
1349  
1350              if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
1351              {
1352                  $parser_options['allow_imgcode'] = 0;
1353              }
1354  
1355              if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
1356              {
1357                  $parser_options['allow_videocode'] = 0;
1358              }
1359  
1360              $post['username'] = htmlspecialchars_uni($post['username']);
1361  
1362              if($post['visible'] != 1)
1363              {
1364                  $altbg = "trow_shaded";
1365              }
1366  
1367              $post['message'] = $parser->parse_message($post['message'], $parser_options);
1368              get_post_attachments($post['pid'], $post);
1369              $reviewmessage = $post['message'];
1370              eval("\$reviewbits .= \"".$templates->get("newreply_threadreview_post")."\";");
1371              if($altbg == "trow1")
1372              {
1373                  $altbg = "trow2";
1374              }
1375              else
1376              {
1377                  $altbg = "trow1";
1378              }
1379          }
1380          eval("\$threadreview = \"".$templates->get("newreply_threadreview")."\";");
1381      }
1382  
1383      // Hide signature option if no permission
1384      $signature = '';
1385      if($mybb->usergroup['canusesig'] == 1 && !$mybb->user['suspendsignature'])
1386      {
1387          eval("\$signature = \"".$templates->get('newreply_signature')."\";");
1388      }
1389  
1390      // Can we disable smilies or are they disabled already?
1391      $disablesmilies = '';
1392      if($forum['allowsmilies'] != 0)
1393      {
1394          eval("\$disablesmilies = \"".$templates->get("newreply_disablesmilies")."\";");
1395      }
1396  
1397      $postoptions = '';
1398      if(!empty($signature) || !empty($disablesmilies))
1399      {
1400          eval("\$postoptions = \"".$templates->get("newreply_postoptions")."\";");
1401          $bgcolor = "trow2";
1402      }
1403      else
1404      {
1405          $bgcolor = "trow1";
1406      }
1407  
1408      $modoptions = '';
1409      // Show the moderator options.
1410      if(is_moderator($fid))
1411      {
1412          if($mybb->get_input('processed', MyBB::INPUT_INT))
1413          {
1414              $mybb->input['modoptions'] = $mybb->get_input('modoptions', MyBB::INPUT_ARRAY);
1415              if(!isset($mybb->input['modoptions']['closethread']))
1416              {
1417                  $mybb->input['modoptions']['closethread'] = 0;
1418              }
1419              $closed = (int)$mybb->input['modoptions']['closethread'];
1420              if(!isset($mybb->input['modoptions']['stickthread']))
1421              {
1422                  $mybb->input['modoptions']['stickthread'] = 0;
1423              }
1424              $stuck = (int)$mybb->input['modoptions']['stickthread'];
1425          }
1426          else
1427          {
1428              $closed = $thread['closed'];
1429              $stuck = $thread['sticky'];
1430          }
1431  
1432          if($closed)
1433          {
1434              $closecheck = ' checked="checked"';
1435          }
1436          else
1437          {
1438              $closecheck = '';
1439          }
1440  
1441          if($stuck)
1442          {
1443              $stickycheck = ' checked="checked"';
1444          }
1445          else
1446          {
1447              $stickycheck = '';
1448          }
1449  
1450          $closeoption = '';
1451          if(is_moderator($thread['fid'], "canopenclosethreads"))
1452          {
1453              eval("\$closeoption = \"".$templates->get("newreply_modoptions_close")."\";");
1454          }
1455  
1456          $stickoption = '';
1457          if(is_moderator($thread['fid'], "canstickunstickthreads"))
1458          {
1459              eval("\$stickoption = \"".$templates->get("newreply_modoptions_stick")."\";");
1460          }
1461  
1462          if(!empty($closeoption) || !empty($stickoption))
1463          {
1464              eval("\$modoptions = \"".$templates->get("newreply_modoptions")."\";");
1465              $bgcolor = "trow1";
1466          }
1467          else
1468          {
1469              $bgcolor = "trow2";
1470          }
1471      }
1472      else
1473      {
1474          $bgcolor = "trow2";
1475      }
1476  
1477      // Fetch subscription select box
1478      eval("\$subscriptionmethod = \"".$templates->get("post_subscription_method")."\";");
1479  
1480      $lang->post_reply_to = $lang->sprintf($lang->post_reply_to, $thread['subject']);
1481      $lang->reply_to = $lang->sprintf($lang->reply_to, $thread['subject']);
1482  
1483      // Do we have any forum rules to show for this forum?
1484      $forumrules = '';
1485      if($forum['rulestype'] >= 2 && $forum['rules'])
1486      {
1487          if(!$forum['rulestitle'])
1488          {
1489              $forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
1490          }
1491  
1492          if(!$parser)
1493          {
1494              require_once  MYBB_ROOT.'inc/class_parser.php';
1495              $parser = new postParser;
1496          }
1497  
1498          $rules_parser = array(
1499              "allow_html" => 1,
1500              "allow_mycode" => 1,
1501              "allow_smilies" => 1,
1502              "allow_imgcode" => 1
1503          );
1504  
1505          $forum['rules'] = $parser->parse_message($forum['rules'], $rules_parser);
1506          $foruminfo = $forum;
1507  
1508          if($forum['rulestype'] == 3)
1509          {
1510              eval("\$forumrules = \"".$templates->get("forumdisplay_rules")."\";");
1511          }
1512          else if($forum['rulestype'] == 2)
1513          {
1514              eval("\$forumrules = \"".$templates->get("forumdisplay_rules_link")."\";");
1515          }
1516      }
1517  
1518      $moderation_notice = '';
1519      if(!is_moderator($forum['fid'], "canapproveunapproveattachs"))
1520      {
1521          if($forumpermissions['modattachments'] == 1  && $forumpermissions['canpostattachments'] != 0)
1522          {
1523              $moderation_text = $lang->moderation_forum_attachments;
1524              eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1525          }
1526      }
1527      if(!is_moderator($forum['fid'], "canapproveunapproveposts"))
1528      {
1529          if($forumpermissions['modposts'] == 1)
1530          {
1531              $moderation_text = $lang->moderation_forum_posts;
1532              eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1533          }
1534  
1535          if($mybb->user['moderateposts'] == 1)
1536          {
1537              $moderation_text = $lang->moderation_user_posts;
1538              eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1539          }
1540      }
1541  
1542      $plugins->run_hooks("newreply_end");
1543  
1544      $forum['name'] = strip_tags($forum['name']);
1545  
1546      eval("\$newreply = \"".$templates->get("newreply")."\";");
1547      output_page($newreply);
1548  }


2005 - 2016 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1