[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> editpost.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', 'editpost.php');
  13  
  14  $templatelist = "editpost,previewpost,changeuserbox,codebuttons,post_attachments_attachment_postinsert,post_attachments_attachment_mod_unapprove,postbit_attachments_thumbnails,posticons";
  15  $templatelist .= ",editpost_delete,forumdisplay_password_wrongpass,forumdisplay_password,editpost_reason,post_attachments_attachment_remove,post_attachments_update,post_subscription_method";
  16  $templatelist .= ",postbit_avatar,postbit_find,postbit_pm,postbit_rep_button,postbit_www,postbit_email,postbit_reputation,postbit_warn,postbit_warninglevel,postbit_author_user,error_attacherror";
  17  $templatelist .= ",postbit_signature,postbit_classic,postbit,postbit_attachments_thumbnails_thumbnail,postbit_attachments_images_image,postbit_attachments_attachment,postbit_attachments_attachment_unapproved";
  18  $templatelist .= ",posticons_icon,post_prefixselect_prefix,post_prefixselect_single,newthread_postpoll,editpost_disablesmilies,post_attachments_attachment_mod_approve,post_attachments_attachment_unapproved";
  19  $templatelist .= ",postbit_warninglevel_formatted,postbit_reputation_formatted_link,editpost_signature,attachment_icon,post_attachments_attachment,post_attachments_add,post_attachments,editpost_postoptions";
  20  $templatelist .= ",postbit_attachments_images,global_moderation_notice,post_attachments_new,postbit_attachments,postbit_online,postbit_away,postbit_offline,postbit_gotopost,postbit_userstar,postbit_icon";
  21  
  22  require_once  "./global.php";
  23  require_once  MYBB_ROOT."inc/functions_post.php";
  24  require_once  MYBB_ROOT."inc/functions_upload.php";
  25  require_once  MYBB_ROOT."inc/class_parser.php";
  26  $parser = new postParser;
  27  
  28  // Load global language phrases
  29  $lang->load("editpost");
  30  
  31  $plugins->run_hooks("editpost_start");
  32  
  33  // No permission for guests
  34  if(!$mybb->user['uid'])
  35  {
  36      error_no_permission();
  37  }
  38  
  39  // Get post info
  40  $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
  41  
  42  // if we already have the post information...
  43  if(isset($style) && $style['pid'] == $pid && $style['type'] != 'f')
  44  {
  45      $post = &$style;
  46  }
  47  else
  48  {
  49      $post = get_post($pid);
  50  }
  51  
  52  if(!$post)
  53  {
  54      error($lang->error_invalidpost);
  55  }
  56  
  57  // Get thread info
  58  $tid = $post['tid'];
  59  $thread = get_thread($tid);
  60  
  61  if(!$thread)
  62  {
  63      error($lang->error_invalidthread);
  64  }
  65  
  66  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  67  
  68  // Get forum info
  69  $fid = $post['fid'];
  70  $forum = get_forum($fid);
  71  
  72  if($thread['visible'] == 0 && !is_moderator($fid, "canviewunapprove") || $thread['visible'] == -1 && !is_moderator($fid, "canviewdeleted") || ($thread['visible'] < -1 && $thread['uid'] != $mybb->user['uid']))
  73  {
  74      error($lang->error_invalidthread);
  75  }
  76  if(!$forum || $forum['type'] != "f")
  77  {
  78      error($lang->error_closedinvalidforum);
  79  }
  80  if(($forum['open'] == 0 && !is_moderator($fid, "caneditposts")) || $mybb->user['suspendposting'] == 1)
  81  {
  82      error_no_permission();
  83  }
  84  
  85  // Add prefix to breadcrumb
  86  $breadcrumbprefix = '';
  87  if($thread['prefix'])
  88  {
  89      $threadprefixes = build_prefixes();
  90      if(!empty($threadprefixes[$thread['prefix']]))
  91      {
  92          $breadcrumbprefix = $threadprefixes[$thread['prefix']]['displaystyle'].'&nbsp;';
  93      }
  94  }
  95  
  96  // Make navigation
  97  build_forum_breadcrumb($fid);
  98  add_breadcrumb($breadcrumbprefix.$thread['subject'], get_thread_link($thread['tid']));
  99  add_breadcrumb($lang->nav_editpost);
 100  
 101  $forumpermissions = forum_permissions($fid);
 102  
 103  if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && $mybb->user['showcodebuttons'] != 0)
 104  {
 105      $codebuttons = build_mycode_inserter("message", $mybb->settings['smilieinserter']);
 106  }
 107  if($mybb->settings['smilieinserter'] != 0)
 108  {
 109      $smilieinserter = build_clickable_smilies();
 110  }
 111  
 112  $mybb->input['action'] = $mybb->get_input('action');
 113  if(!$mybb->input['action'] || isset($mybb->input['previewpost']))
 114  {
 115      $mybb->input['action'] = "editpost";
 116  }
 117  
 118  if($mybb->input['action'] == "deletepost" && $mybb->request_method == "post")
 119  {
 120      if(!is_moderator($fid, "candeleteposts") && !is_moderator($fid, "cansoftdeleteposts") && $pid != $thread['firstpost'] || !is_moderator($fid, "candeletethreads") && !is_moderator($fid, "cansoftdeletethreads") && $pid == $thread['firstpost'])
 121      {
 122          if($thread['closed'] == 1)
 123          {
 124              error($lang->redirect_threadclosed);
 125          }
 126          if($forumpermissions['candeleteposts'] == 0 && $pid != $thread['firstpost'] || $forumpermissions['candeletethreads'] == 0 && $pid == $thread['firstpost'])
 127          {
 128              error_no_permission();
 129          }
 130          if($mybb->user['uid'] != $post['uid'])
 131          {
 132              error_no_permission();
 133          }
 134          // User can't delete unapproved post
 135          if($post['visible'] == 0)
 136          {
 137              error_no_permission();
 138          }
 139      }
 140      if($post['visible'] == -1 && $mybb->settings['soft_delete'] == 1)
 141      {
 142          error($lang->error_already_deleted);
 143      }
 144  }
 145  elseif($mybb->input['action'] == "restorepost" && $mybb->request_method == "post")
 146  {
 147      if(!is_moderator($fid, "canrestoreposts") && $pid != $thread['firstpost'] || !is_moderator($fid, "canrestorethreads") && $pid == $thread['firstpost'] || $post['visible'] != -1)
 148      {
 149          error_no_permission();
 150      }
 151  }
 152  else
 153  {
 154      if(!is_moderator($fid, "caneditposts"))
 155      {
 156          if($thread['closed'] == 1)
 157          {
 158              error($lang->redirect_threadclosed);
 159          }
 160          if($forumpermissions['caneditposts'] == 0)
 161          {
 162              error_no_permission();
 163          }
 164          if($mybb->user['uid'] != $post['uid'])
 165          {
 166              error_no_permission();
 167          }
 168          // Edit time limit
 169          $time = TIME_NOW;
 170          if($mybb->usergroup['edittimelimit'] != 0 && $post['dateline'] < ($time-($mybb->usergroup['edittimelimit']*60)))
 171          {
 172              $lang->edit_time_limit = $lang->sprintf($lang->edit_time_limit, $mybb->usergroup['edittimelimit']);
 173              error($lang->edit_time_limit);
 174          }
 175          // User can't edit unapproved post
 176          if($post['visible'] == 0 || $post['visible'] == -1)
 177          {
 178              error_no_permission();
 179          }
 180      }
 181  }
 182  
 183  // Check if this forum is password protected and we have a valid password
 184  check_forum_password($forum['fid']);
 185  
 186  if((empty($_POST) && empty($_FILES)) && $mybb->get_input('processed', MyBB::INPUT_INT) == '1')
 187  {
 188      error($lang->error_cannot_upload_php_post);
 189  }
 190  
 191  $attacherror = '';
 192  if($mybb->settings['enableattachments'] == 1 && !$mybb->get_input('attachmentaid', MyBB::INPUT_INT) && ($mybb->get_input('newattachment') || $mybb->get_input('updateattachment') || ($mybb->input['action'] == "do_editpost" && isset($mybb->input['submit']) && $_FILES['attachment'])))
 193  {
 194      // Verify incoming POST request
 195      verify_post_check($mybb->get_input('my_post_key'));
 196  
 197      // If there's an attachment, check it and upload it
 198      if($_FILES['attachment']['size'] > 0 && $forumpermissions['canpostattachments'] != 0)
 199      {
 200          $query = $db->simple_select("attachments", "aid", "filename='".$db->escape_string($_FILES['attachment']['name'])."' AND pid='{$pid}'");
 201          $updateattach = $db->fetch_field($query, "aid");
 202  
 203          $update_attachment = false;
 204          if($updateattach > 0 && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
 205          {
 206              $update_attachment = true;
 207          }
 208          $attachedfile = upload_attachment($_FILES['attachment'], $update_attachment);
 209      }
 210      if(!empty($attachedfile['error']))
 211      {
 212          eval("\$attacherror = \"".$templates->get("error_attacherror")."\";");
 213          $mybb->input['action'] = "editpost";
 214      }
 215      if(!isset($mybb->input['submit']))
 216      {
 217          $mybb->input['action'] = "editpost";
 218      }
 219  }
 220  
 221  if($mybb->settings['enableattachments'] == 1 && $mybb->get_input('attachmentaid', MyBB::INPUT_INT) && isset($mybb->input['attachmentact']) && $mybb->input['action'] == "do_editpost" && $mybb->request_method == "post") // Lets remove/approve/unapprove the attachment
 222  {
 223      // Verify incoming POST request
 224      verify_post_check($mybb->get_input('my_post_key'));
 225  
 226      $mybb->input['attachmentaid'] = $mybb->get_input('attachmentaid', MyBB::INPUT_INT);
 227      if($mybb->input['attachmentact'] == "remove")
 228      {
 229          remove_attachment($pid, "", $mybb->input['attachmentaid']);
 230      }
 231      elseif($mybb->get_input('attachmentact') == "approve" && is_moderator($fid, 'canapproveunapproveattachs'))
 232      {
 233          $update_sql = array("visible" => 1);
 234          $db->update_query("attachments", $update_sql, "aid='{$mybb->input['attachmentaid']}'");
 235          update_thread_counters($post['tid'], array('attachmentcount' => "+1"));
 236      }
 237      elseif($mybb->get_input('attachmentact') == "unapprove" && is_moderator($fid, 'canapproveunapproveattachs'))
 238      {
 239          $update_sql = array("visible" => 0);
 240          $db->update_query("attachments", $update_sql, "aid='{$mybb->input['attachmentaid']}'");
 241          update_thread_counters($post['tid'], array('attachmentcount' => "-1"));
 242      }
 243      if(!isset($mybb->input['submit']))
 244      {
 245          $mybb->input['action'] = "editpost";
 246      }
 247  }
 248  
 249  if($mybb->input['action'] == "deletepost" && $mybb->request_method == "post")
 250  {
 251      // Verify incoming POST request
 252      verify_post_check($mybb->get_input('my_post_key'));
 253  
 254      $plugins->run_hooks("editpost_deletepost");
 255  
 256      if($mybb->get_input('delete', MyBB::INPUT_INT) == 1)
 257      {
 258          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "asc"));
 259          $firstcheck = $db->fetch_array($query);
 260          if($firstcheck['pid'] == $pid)
 261          {
 262              $firstpost = 1;
 263          }
 264          else
 265          {
 266              $firstpost = 0;
 267          }
 268  
 269          $modlogdata['fid'] = $fid;
 270          $modlogdata['tid'] = $tid;
 271          if($firstpost)
 272          {
 273              if($forumpermissions['candeletethreads'] == 1 || is_moderator($fid, "candeletethreads") || is_moderator($fid, "cansoftdeletethreads"))
 274              {
 275                  require_once  MYBB_ROOT."inc/class_moderation.php";
 276                  $moderation = new Moderation;
 277  
 278                  if($mybb->settings['soft_delete'] == 1 || is_moderator($fid, "cansoftdeletethreads"))
 279                  {
 280                      $modlogdata['pid'] = $pid;
 281  
 282                      $moderation->soft_delete_threads(array($tid));
 283                      log_moderator_action($modlogdata, $lang->thread_soft_deleted);
 284                  }
 285                  else
 286                  {
 287                      $moderation->delete_thread($tid);
 288                      mark_reports($tid, "thread");
 289                      log_moderator_action($modlogdata, $lang->thread_deleted);
 290                  }
 291  
 292                  if($mybb->input['ajax'] == 1)
 293                  {
 294                      header("Content-type: application/json; charset={$lang->settings['charset']}");
 295                      if(is_moderator($fid, "canviewdeleted"))
 296                      {
 297                          echo json_encode(array("data" => '1'));
 298                      }
 299                      else
 300                      {
 301                          echo json_encode(array("data" => '3', "url" => get_forum_link($fid)));
 302                      }
 303                  }
 304                  else
 305                  {
 306                      redirect(get_forum_link($fid), $lang->redirect_threaddeleted);
 307                  }
 308              }
 309              else
 310              {
 311                  error_no_permission();
 312              }
 313          }
 314          else
 315          {
 316              if($forumpermissions['candeleteposts'] == 1 || is_moderator($fid, "candeleteposts") || is_moderator($fid, "cansoftdeleteposts"))
 317              {
 318                  // Select the first post before this
 319                  require_once  MYBB_ROOT."inc/class_moderation.php";
 320                  $moderation = new Moderation;
 321  
 322                  if($mybb->settings['soft_delete'] == 1 || is_moderator($fid, "cansoftdeleteposts"))
 323                  {
 324                      $modlogdata['pid'] = $pid;
 325  
 326                      $moderation->soft_delete_posts(array($pid));
 327                      log_moderator_action($modlogdata, $lang->post_soft_deleted);
 328                  }
 329                  else
 330                  {
 331                      $moderation->delete_post($pid);
 332                      mark_reports($pid, "post");
 333                      log_moderator_action($modlogdata, $lang->post_deleted);
 334                  }
 335  
 336                  $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline <= '{$post['dateline']}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "desc"));
 337                  $next_post = $db->fetch_array($query);
 338                  if($next_post['pid'])
 339                  {
 340                      $redirect = get_post_link($next_post['pid'], $tid)."#pid{$next_post['pid']}";
 341                  }
 342                  else
 343                  {
 344                      $redirect = get_thread_link($tid);
 345                  }
 346  
 347                  if($mybb->input['ajax'] == 1)
 348                  {
 349                      header("Content-type: application/json; charset={$lang->settings['charset']}");
 350                      if(is_moderator($fid, "canviewdeleted"))
 351                      {
 352                          echo json_encode(array("data" => '1'));
 353                      }
 354                      else
 355                      {
 356                          echo json_encode(array("data" => '2'));
 357                      }
 358                  }
 359                  else
 360                  {
 361                      redirect($redirect, $lang->redirect_postdeleted);
 362                  }
 363              }
 364              else
 365              {
 366                  error_no_permission();
 367              }
 368          }
 369      }
 370      else
 371      {
 372          error($lang->redirect_nodelete);
 373      }
 374  }
 375  
 376  if($mybb->input['action'] == "restorepost" && $mybb->request_method == "post")
 377  {
 378      // Verify incoming POST request
 379      verify_post_check($mybb->get_input('my_post_key'));
 380  
 381      $plugins->run_hooks("editpost_restorepost");
 382  
 383      if($mybb->get_input('restore', MyBB::INPUT_INT) == 1)
 384      {
 385          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "asc"));
 386          $firstcheck = $db->fetch_array($query);
 387          if($firstcheck['pid'] == $pid)
 388          {
 389              $firstpost = 1;
 390          }
 391          else
 392          {
 393              $firstpost = 0;
 394          }
 395  
 396          $modlogdata['fid'] = $fid;
 397          $modlogdata['tid'] = $tid;
 398          $modlogdata['pid'] = $pid;
 399          if($firstpost)
 400          {
 401              if(is_moderator($fid, "canrestorethreads"))
 402              {
 403                  require_once  MYBB_ROOT."inc/class_moderation.php";
 404                  $moderation = new Moderation;
 405                  $moderation->restore_threads(array($tid));
 406                  log_moderator_action($modlogdata, $lang->thread_restored);
 407                  if($mybb->input['ajax'] == 1)
 408                  {
 409                      header("Content-type: application/json; charset={$lang->settings['charset']}");
 410                      echo json_encode(array("data" => '1'));
 411                  }
 412                  else
 413                  {
 414                      redirect(get_forum_link($fid), $lang->redirect_threadrestored);
 415                  }
 416              }
 417              else
 418              {
 419                  error_no_permission();
 420              }
 421          }
 422          else
 423          {
 424              if(is_moderator($fid, "canrestoreposts"))
 425              {
 426                  // Select the first post before this
 427                  require_once  MYBB_ROOT."inc/class_moderation.php";
 428                  $moderation = new Moderation;
 429                  $moderation->restore_posts(array($pid));
 430                  log_moderator_action($modlogdata, $lang->post_restored);
 431                  $redirect = get_post_link($pid, $tid)."#pid{$pid}";
 432  
 433                  if($mybb->input['ajax'] == 1)
 434                  {
 435                      header("Content-type: application/json; charset={$lang->settings['charset']}");
 436                      echo json_encode(array("data" => '1'));
 437                  }
 438                  else
 439                  {
 440                      redirect($redirect, $lang->redirect_postrestored);
 441                  }
 442              }
 443              else
 444              {
 445                  error_no_permission();
 446              }
 447          }
 448      }
 449      else
 450      {
 451          error($lang->redirect_norestore);
 452      }
 453  }
 454  
 455  if($mybb->input['action'] == "do_editpost" && $mybb->request_method == "post")
 456  {
 457      // Verify incoming POST request
 458      verify_post_check($mybb->get_input('my_post_key'));
 459  
 460      $plugins->run_hooks("editpost_do_editpost_start");
 461  
 462      // Set up posthandler.
 463      require_once  MYBB_ROOT."inc/datahandlers/post.php";
 464      $posthandler = new PostDataHandler("update");
 465      $posthandler->action = "post";
 466  
 467      // Set the post data that came from the input to the $post array.
 468      $post = array(
 469          "pid" => $mybb->input['pid'],
 470          "prefix" => $mybb->get_input('threadprefix', MyBB::INPUT_INT),
 471          "subject" => $mybb->get_input('subject'),
 472          "icon" => $mybb->get_input('icon', MyBB::INPUT_INT),
 473          "uid" => $post['uid'],
 474          "username" => $post['username'],
 475          "edit_uid" => $mybb->user['uid'],
 476          "message" => $mybb->get_input('message'),
 477          "editreason" => $mybb->get_input('editreason'),
 478      );
 479  
 480      $postoptions = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
 481      if(!isset($postoptions['signature']))
 482      {
 483          $postoptions['signature'] = 0;
 484      }
 485      if(!isset($postoptions['subscriptionmethod']))
 486      {
 487          $postoptions['subscriptionmethod'] = 0;
 488      }
 489      if(!isset($postoptions['disablesmilies']))
 490      {
 491          $postoptions['disablesmilies'] = 0;
 492      }
 493  
 494      // Set up the post options from the input.
 495      $post['options'] = array(
 496          "signature" => $postoptions['signature'],
 497          "subscriptionmethod" => $postoptions['subscriptionmethod'],
 498          "disablesmilies" => $postoptions['disablesmilies']
 499      );
 500  
 501      $posthandler->set_data($post);
 502  
 503      // Now let the post handler do all the hard work.
 504      if(!$posthandler->validate_post())
 505      {
 506          $post_errors = $posthandler->get_friendly_errors();
 507          $post_errors = inline_error($post_errors);
 508          $mybb->input['action'] = "editpost";
 509      }
 510      // No errors were found, we can call the update method.
 511      else
 512      {
 513          $postinfo = $posthandler->update_post();
 514          $visible = $postinfo['visible'];
 515          $first_post = $postinfo['first_post'];
 516  
 517          // Help keep our attachments table clean.
 518          $db->delete_query("attachments", "filename='' OR filesize<1");
 519  
 520          // Did the user choose to post a poll? Redirect them to the poll posting page.
 521          if($mybb->get_input('postpoll', MyBB::INPUT_INT) && $forumpermissions['canpostpolls'])
 522          {
 523              $url = "polls.php?action=newpoll&tid=$tid&polloptions=".$mybb->get_input('numpolloptions', MyBB::INPUT_INT);
 524              $lang->redirect_postedited = $lang->redirect_postedited_poll;
 525          }
 526          else if($visible == 0 && $first_post && !is_moderator($fid, "canviewunapprove", $mybb->user['uid']))
 527          {
 528              // Moderated post
 529              $lang->redirect_postedited .= $lang->redirect_thread_moderation;
 530              $url = get_forum_link($fid);
 531          }
 532          else if($visible == 0 && !is_moderator($fid, "canviewunapprove", $mybb->user['uid']))
 533          {
 534              $lang->redirect_postedited .= $lang->redirect_post_moderation;
 535              $url = get_thread_link($tid);
 536          }
 537          // Otherwise, send them back to their post
 538          else
 539          {
 540              $lang->redirect_postedited .= $lang->redirect_postedited_redirect;
 541              $url = get_post_link($pid, $tid)."#pid{$pid}";
 542          }
 543          $plugins->run_hooks("editpost_do_editpost_end");
 544  
 545          redirect($url, $lang->redirect_postedited);
 546      }
 547  }
 548  
 549  if(!$mybb->input['action'] || $mybb->input['action'] == "editpost")
 550  {
 551      $plugins->run_hooks("editpost_action_start");
 552  
 553      if(!isset($mybb->input['previewpost']))
 554      {
 555          $icon = $post['icon'];
 556      }
 557  
 558      if($forum['allowpicons'] != 0)
 559      {
 560          $posticons = get_post_icons();
 561      }
 562  
 563      $mybb->user['username'] = htmlspecialchars_uni($mybb->user['username']);
 564      eval("\$loginbox = \"".$templates->get("changeuserbox")."\";");
 565  
 566      $deletebox = '';
 567      // Can we delete posts?
 568      if($post['visible'] != -1 && (is_moderator($fid, "candeleteposts") || $forumpermissions['candeleteposts'] == 1 && $mybb->user['uid'] == $post['uid']))
 569      {
 570          eval("\$deletebox = \"".$templates->get("editpost_delete")."\";");
 571      }
 572  
 573      $bgcolor = "trow1";
 574      if($mybb->settings['enableattachments'] != 0 && $forumpermissions['canpostattachments'] != 0)
 575      { // Get a listing of the current attachments, if there are any
 576          $attachcount = 0;
 577          $query = $db->simple_select("attachments", "*", "pid='{$pid}'");
 578          $attachments = '';
 579          while($attachment = $db->fetch_array($query))
 580          {
 581              $attachment['size'] = get_friendly_size($attachment['filesize']);
 582              $attachment['icon'] = get_attachment_icon(get_extension($attachment['filename']));
 583              $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
 584  
 585              if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && $mybb->user['showcodebuttons'] != 0)
 586              {
 587                  eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";");
 588              }
 589              // Moderating options
 590              $attach_mod_options = '';
 591              if(is_moderator($fid))
 592              {
 593                  if($attachment['visible'] == 1)
 594                  {
 595                      eval("\$attach_mod_options = \"".$templates->get("post_attachments_attachment_mod_unapprove")."\";");
 596                  }
 597                  else
 598                  {
 599                      eval("\$attach_mod_options = \"".$templates->get("post_attachments_attachment_mod_approve")."\";");
 600                  }
 601              }
 602  
 603              // Remove Attachment
 604              eval("\$attach_rem_options = \"".$templates->get("post_attachments_attachment_remove")."\";");
 605  
 606              if($attachment['visible'] != 1)
 607              {
 608                  eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";");
 609              }
 610              else
 611              {
 612                  eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";");
 613              }
 614              $attachcount++;
 615          }
 616          $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
 617          $usage = $db->fetch_array($query);
 618          if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0)
 619          {
 620              $noshowattach = 1;
 621          }
 622          else
 623          {
 624              $noshowattach = 0;
 625          }
 626          if($mybb->usergroup['attachquota'] == 0)
 627          {
 628              $friendlyquota = $lang->unlimited;
 629          }
 630          else
 631          {
 632              $friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
 633          }
 634          $friendlyusage = get_friendly_size($usage['ausage']);
 635          $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
 636          if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach)
 637          {
 638              eval("\$attach_add_options = \"".$templates->get("post_attachments_add")."\";");
 639          }
 640  
 641          if(($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']) && $attachcount > 0)
 642          {
 643              eval("\$attach_update_options = \"".$templates->get("post_attachments_update")."\";");
 644          }
 645  
 646          if($attach_add_options || $attach_update_options)
 647          {
 648              eval("\$newattach = \"".$templates->get("post_attachments_new")."\";");
 649          }
 650          eval("\$attachbox = \"".$templates->get("post_attachments")."\";");
 651      }
 652      if(!$mybb->get_input('attachmentaid', MyBB::INPUT_INT) && !$mybb->get_input('newattachment') && !$mybb->get_input('updateattachment') && !isset($mybb->input['previewpost']))
 653      {
 654          $message = $post['message'];
 655          $subject = $post['subject'];
 656          $reason = htmlspecialchars_uni($post['editreason']);
 657      }
 658      else
 659      {
 660          $message = $mybb->get_input('message');
 661          $subject = $mybb->get_input('subject');
 662          $reason = htmlspecialchars_uni($mybb->get_input('editreason'));
 663      }
 664  
 665      if(!isset($post_errors))
 666      {
 667          $post_errors = '';
 668      }
 669  
 670      $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_email = $postoptions_subscriptionmethod_pm = '';
 671      $postoptionschecked = array('signature' => '', 'disablesmilies' => '');
 672  
 673      if(!empty($mybb->input['previewpost']) || $post_errors)
 674      {
 675          // Set up posthandler.
 676          require_once  MYBB_ROOT."inc/datahandlers/post.php";
 677          $posthandler = new PostDataHandler("update");
 678          $posthandler->action = "post";
 679  
 680          // Set the post data that came from the input to the $post array.
 681          $post = array(
 682              "pid" => $mybb->input['pid'],
 683              "prefix" => $mybb->get_input('threadprefix', MyBB::INPUT_INT),
 684              "subject" => $mybb->get_input('subject'),
 685              "icon" => $mybb->get_input('icon', MyBB::INPUT_INT),
 686              "uid" => $post['uid'],
 687              "username" => $post['username'],
 688              "edit_uid" => $mybb->user['uid'],
 689              "message" => $mybb->get_input('message'),
 690          );
 691  
 692          $postoptions = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
 693          if(!isset($postoptions['signature']))
 694          {
 695              $postoptions['signature'] = 0;
 696          }
 697          if(!isset($postoptions['emailnotify']))
 698          {
 699              $postoptions['emailnotify'] = 0;
 700          }
 701          if(!isset($postoptions['disablesmilies']))
 702          {
 703              $postoptions['disablesmilies'] = 0;
 704          }
 705  
 706          // Set up the post options from the input.
 707          $post['options'] = array(
 708              "signature" => $postoptions['signature'],
 709              "emailnotify" => $postoptions['emailnotify'],
 710              "disablesmilies" => $postoptions['disablesmilies']
 711          );
 712  
 713          $posthandler->set_data($post);
 714  
 715          // Now let the post handler do all the hard work.
 716          if(!$posthandler->validate_post())
 717          {
 718              $post_errors = $posthandler->get_friendly_errors();
 719              $post_errors = inline_error($post_errors);
 720              $mybb->input['action'] = "editpost";
 721              $mybb->input['previewpost'] = 0;
 722          }
 723          else
 724          {
 725              $previewmessage = $message;
 726              $previewsubject = $subject;
 727              $message = htmlspecialchars_uni($message);
 728              $subject = htmlspecialchars_uni($subject);
 729  
 730              $postoptions = $mybb->get_input('postoptions', MyBB::INPUT_ARRAY);
 731  
 732              if(isset($postoptions['signature']) && $postoptions['signature'] == 1)
 733              {
 734                  $postoptionschecked['signature'] = " checked=\"checked\"";
 735              }
 736  
 737              if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "none")
 738              {
 739                  $postoptions_subscriptionmethod_none = "checked=\"checked\"";
 740              }
 741              else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "email")
 742              {
 743                  $postoptions_subscriptionmethod_email = "checked=\"checked\"";
 744              }
 745              else if(isset($postoptions['subscriptionmethod']) && $postoptions['subscriptionmethod'] == "pm")
 746              {
 747                  $postoptions_subscriptionmethod_pm = "checked=\"checked\"";
 748              }
 749              else
 750              {
 751                  $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
 752              }
 753  
 754              if(isset($postoptions['disablesmilies']) && $postoptions['disablesmilies'] == 1)
 755              {
 756                  $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
 757              }
 758          }
 759      }
 760  
 761      if(!empty($mybb->input['previewpost']))
 762      {
 763          if(!$post['uid'])
 764          {
 765              $query = $db->simple_select('posts', 'username, dateline', "pid='{$pid}'");
 766              $postinfo = $db->fetch_array($query);
 767          }
 768          else
 769          {
 770              // Figure out the poster's other information.
 771              $query = $db->query("
 772                  SELECT u.*, f.*, p.dateline
 773                  FROM ".TABLE_PREFIX."users u
 774                  LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 775                  LEFT JOIN ".TABLE_PREFIX."posts p ON (p.uid=u.uid)
 776                  WHERE u.uid='{$post['uid']}' AND p.pid='{$pid}'
 777                  LIMIT 1
 778              ");
 779              $postinfo = $db->fetch_array($query);
 780              $postinfo['userusername'] = $postinfo['username'];
 781          }
 782  
 783          $query = $db->simple_select("attachments", "*", "pid='{$pid}'");
 784          while($attachment = $db->fetch_array($query))
 785          {
 786              $attachcache[0][$attachment['aid']] = $attachment;
 787          }
 788  
 789          if(!isset($postoptions['disablesmilies']))
 790          {
 791              $postoptions['disablesmilies'] = 0;
 792          }
 793  
 794          // Set the values of the post info array.
 795          $postinfo['message'] = $previewmessage;
 796          $postinfo['subject'] = $previewsubject;
 797          $postinfo['icon'] = $icon;
 798          $postinfo['smilieoff'] = $postoptions['disablesmilies'];
 799  
 800          $postbit = build_postbit($postinfo, 1);
 801          eval("\$preview = \"".$templates->get("previewpost")."\";");
 802      }
 803      else if(!$post_errors)
 804      {
 805          $message = htmlspecialchars_uni($message);
 806          $subject = htmlspecialchars_uni($subject);
 807  
 808          $preview = '';
 809  
 810          if($post['includesig'] != 0)
 811          {
 812              $postoptionschecked['signature'] = " checked=\"checked\"";
 813          }
 814  
 815          if($post['smilieoff'] == 1)
 816          {
 817              $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
 818          }
 819  
 820          $query = $db->simple_select("threadsubscriptions", "notification", "tid='{$tid}' AND uid='{$mybb->user['uid']}'");
 821          if($db->num_rows($query) > 0)
 822          {
 823              $notification = $db->fetch_field($query, 'notification');
 824  
 825              if($notification ==  0)
 826              {
 827                  $postoptions_subscriptionmethod_none = "checked=\"checked\"";
 828              }
 829              else if($notification == 1)
 830              {
 831                  $postoptions_subscriptionmethod_email = "checked=\"checked\"";
 832              }
 833              else if($notification == 2)
 834              {
 835                  $postoptions_subscriptionmethod_pm = "checked=\"checked\"";
 836              }
 837              else
 838              {
 839                  $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
 840              }
 841          }
 842      }
 843  
 844      // Generate thread prefix selector if this is the first post of the thread
 845      if($thread['firstpost'] == $pid)
 846      {
 847          if(!$mybb->get_input('threadprefix', MyBB::INPUT_INT))
 848          {
 849              $mybb->input['threadprefix'] = $thread['prefix'];
 850          }
 851  
 852          $prefixselect = build_prefix_select($forum['fid'], $mybb->get_input('threadprefix', MyBB::INPUT_INT), 0, $thread['prefix']);
 853      }
 854      else
 855      {
 856          $prefixselect = "";
 857      }
 858  
 859      $editreason = '';
 860      if($mybb->settings['alloweditreason'] == 1)
 861      {
 862          eval("\$editreason = \"".$templates->get("editpost_reason")."\";");
 863          $bgcolor = "trow2";
 864          $bgcolor2 = "trow1";
 865      }
 866      else
 867      {
 868          $bgcolor = "trow1";
 869          $bgcolor2 = "trow2";
 870      }
 871  
 872      // Fetch subscription select box
 873      eval("\$subscriptionmethod = \"".$templates->get("post_subscription_method")."\";");
 874  
 875      $query = $db->simple_select("posts", "*", "tid='{$tid}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "asc"));
 876      $firstcheck = $db->fetch_array($query);
 877  
 878      $time = TIME_NOW;
 879      if($firstcheck['pid'] == $pid && $forumpermissions['canpostpolls'] != 0 && $thread['poll'] < 1 && (is_moderator($fid, "canmanagepolls") || $thread['dateline'] > ($time-($mybb->settings['polltimelimit']*60*60)) || $mybb->settings['polltimelimit'] == 0))
 880      {
 881          $lang->max_options = $lang->sprintf($lang->max_options, $mybb->settings['maxpolloptions']);
 882          $numpolloptions = $mybb->get_input('numpolloptions', MyBB::INPUT_INT);
 883          $postpollchecked = '';
 884          
 885          if($numpolloptions < 1)
 886          {
 887              $numpolloptions = 2;
 888          }
 889          
 890          if($mybb->get_input('postpoll', MyBB::INPUT_INT) == 1)
 891          {
 892              $postpollchecked = 'checked="checked"';
 893          }
 894          
 895          eval("\$pollbox = \"".$templates->get("newthread_postpoll")."\";");
 896      }
 897      else
 898      {
 899          $pollbox = '';
 900      }
 901  
 902      // Hide signature option if no permission
 903      $signature = '';
 904      if($mybb->usergroup['canusesig'] == 1 && !$mybb->user['suspendsignature'])
 905      {
 906          eval("\$signature = \"".$templates->get('editpost_signature')."\";");
 907      }
 908  
 909      // Can we disable smilies or are they disabled already?
 910      $disablesmilies = '';
 911      if($forum['allowsmilies'] != 0)
 912      {
 913          eval("\$disablesmilies = \"".$templates->get("editpost_disablesmilies")."\";");
 914      }
 915  
 916      $postoptions = '';
 917      if(!empty($signature) || !empty($disablesmilies))
 918      {
 919          eval("\$postoptions = \"".$templates->get("editpost_postoptions")."\";");
 920      }
 921  
 922      $moderation_notice = '';
 923      if(!is_moderator($forum['fid'], "canapproveunapproveattachs"))
 924      {
 925          if($forumpermissions['modattachments'] == 1  && $forumpermissions['canpostattachments'] != 0)
 926          {
 927              $moderation_text = $lang->moderation_forum_attachments;
 928              eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
 929          }
 930      }
 931  
 932      if(!is_moderator($forum['fid'], "canapproveunapproveposts"))
 933      {
 934          if($forumpermissions['mod_edit_posts'] == 1)
 935          {
 936              $moderation_text = $lang->moderation_forum_edits;
 937              eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
 938          }
 939      }
 940  
 941      $plugins->run_hooks("editpost_end");
 942  
 943      $forum['name'] = strip_tags($forum['name']);
 944  
 945      eval("\$editpost = \"".$templates->get("editpost")."\";");
 946      output_page($editpost);
 947  }


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