[ Index ]

PHP Cross Reference of MyBB 1.8.41

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


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