[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/ -> moderation.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', 'moderation.php');
  13  
  14  $templatelist = "changeuserbox,loginbox,moderation_delayedmoderation_custommodtool,moderation_delayedmodaction_notes,moderation_delayedmoderation_merge,moderation_delayedmoderation_move,moderation_threadnotes";
  15  $templatelist .= ",moderation_delayedmoderation,moderation_deletethread,moderation_deletepoll,moderation_mergeposts_post,moderation_viewthreadnotes,moderation_confirmation,moderation_purgespammer,forumjump_bit";
  16  $templatelist .= ",moderation_move,moderation_threadnotes_modaction,moderation_threadnotes_delayedmodaction,moderation_getip_modoptions,moderation_getip,moderation_getpmip,moderation_getpmip_modal";
  17  $templatelist .= ",moderation_split_post,moderation_inline_deletethreads,moderation_inline_movethreads,moderation_inline_deleteposts,moderation_inline_mergeposts,moderation_threadnotes_modaction_error";
  18  $templatelist .= ",moderation_inline_splitposts,forumjump_special,forumjump_advanced,forumdisplay_password_wrongpass,forumdisplay_password,moderation_inline_moveposts,moderation_delayedmodaction_error";
  19  $templatelist .= ",moderation_delayedmodaction_notes_thread_single,moderation_delayedmodaction_notes_thread_multiple,moderation_delayedmodaction_notes_forum,moderation_delayedmodaction_notes_new_forum";
  20  $templatelist .= ",moderation_delayedmodaction_notes_redirect,moderation_delayedmodaction_notes_merge,moderation_delayedmoderation_thread,moderation_threadnotes_modaction_thread,moderation_getip_modal";
  21  $templatelist .= ",moderation_delayedmoderation_date_day,moderation_delayedmoderation_date_month,moderation_threadnotes_modaction_post,moderation_merge,moderation_split,moderation_threadnotes_modaction_forum";
  22  $templatelist .= ",moderation_delayedmoderation_openclose,moderation_delayedmoderation_softdeleterestore,moderation_delayedmoderation_delete,moderation_delayedmoderation_stick,moderation_delayedmoderation_approve";
  23  
  24  require_once  "./global.php";
  25  require_once  MYBB_ROOT."inc/functions_post.php";
  26  require_once  MYBB_ROOT."inc/functions_upload.php";
  27  require_once  MYBB_ROOT."inc/class_parser.php";
  28  $parser = new postParser;
  29  require_once  MYBB_ROOT."inc/class_moderation.php";
  30  $moderation = new Moderation;
  31  
  32  // Load global language phrases
  33  $lang->load("moderation");
  34  
  35  $plugins->run_hooks("moderation_start");
  36  
  37  $tid = $mybb->get_input('tid', MyBB::INPUT_INT);
  38  $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
  39  $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
  40  $pmid = $mybb->get_input('pmid', MyBB::INPUT_INT);
  41  $modal = $mybb->get_input('modal', MyBB::INPUT_INT);
  42  
  43  if($mybb->user['uid'] == 0)
  44  {
  45      error_no_permission();
  46  }
  47  
  48  
  49  if($pid)
  50  {
  51      $post = get_post($pid);
  52      if(!$post)
  53      {
  54          error($lang->error_invalidpost, $lang->error);
  55      }
  56      $tid = $post['tid'];
  57  }
  58  
  59  if($tid)
  60  {
  61      $thread = get_thread($tid);
  62      if(!$thread)
  63      {
  64          error($lang->error_invalidthread, $lang->error);
  65      }
  66      $fid = $thread['fid'];
  67  }
  68  
  69  if($fid)
  70  {
  71      $modlogdata['fid'] = $fid;
  72      $forum = get_forum($fid);
  73  
  74      // Make navigation
  75      build_forum_breadcrumb($fid);
  76  
  77      // Get our permissions all nice and setup
  78      $permissions = forum_permissions($fid);
  79  }
  80  
  81  if($pmid > 0)
  82  {
  83      $query = $db->simple_select('privatemessages', 'uid, subject, ipaddress, fromid', "pmid = $pmid");
  84  
  85      $pm = $db->fetch_array($query);
  86  
  87      if(!$pm)
  88      {
  89          error($lang->error_invalidpm, $lang->error);
  90      }
  91  }
  92  
  93  // Get some navigation if we need it
  94  $mybb->input['action'] = $mybb->get_input('action');
  95  switch($mybb->input['action'])
  96  {
  97      case "reports":
  98          add_breadcrumb($lang->reported_posts);
  99          break;
 100      case "allreports":
 101          add_breadcrumb($lang->all_reported_posts);
 102          break;
 103  
 104  }
 105  
 106  if(isset($thread))
 107  {
 108      $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
 109      add_breadcrumb($thread['subject'], get_thread_link($thread['tid']));
 110      $modlogdata['tid'] = $thread['tid'];
 111  }
 112  
 113  if(isset($forum))
 114  {
 115      // Check if this forum is password protected and we have a valid password
 116      check_forum_password($forum['fid']);
 117  }
 118  
 119  $log_multithreads_actions = array("do_multideletethreads", "multiclosethreads", "multiopenthreads", "multiapprovethreads", "multiunapprovethreads", "multirestorethreads", "multisoftdeletethreads","multistickthreads", "multiunstickthreads", "do_multimovethreads");
 120  if(in_array($mybb->input['action'], $log_multithreads_actions))
 121  {
 122      if(!empty($mybb->input['searchid']))
 123      {
 124          $tids = getids($mybb->get_input('searchid'), 'search');
 125      }
 126      else
 127      {
 128          $tids = getids($fid, 'forum');
 129      }
 130  
 131      $modlogdata['tids'] = (array)$tids;
 132  
 133      unset($tids);
 134  }
 135  
 136  $mybb->user['username'] = htmlspecialchars_uni($mybb->user['username']);
 137  eval("\$loginbox = \"".$templates->get("changeuserbox")."\";");
 138  
 139  $allowable_moderation_actions = array("getip", "getpmip", "cancel_delayedmoderation", "delayedmoderation", "threadnotes", "purgespammer", "viewthreadnotes");
 140  
 141  if($mybb->request_method != "post" && !in_array($mybb->input['action'], $allowable_moderation_actions))
 142  {
 143      error_no_permission();
 144  }
 145  
 146  // Begin!
 147  switch($mybb->input['action'])
 148  {
 149      // Delayed Moderation
 150      case "cancel_delayedmoderation":
 151          // Verify incoming POST request
 152          verify_post_check($mybb->get_input('my_post_key'));
 153  
 154          add_breadcrumb($lang->delayed_moderation);
 155          if(!is_moderator($fid, "canmanagethreads"))
 156          {
 157              error_no_permission();
 158          }
 159  
 160          $plugins->run_hooks('moderation_cancel_delayedmoderation');
 161  
 162          $db->delete_query("delayedmoderation", "did='".$mybb->get_input('did', MyBB::INPUT_INT)."'");
 163  
 164          if($tid == 0)
 165          {
 166              moderation_redirect(get_forum_link($fid), $lang->redirect_delayed_moderation_cancelled);
 167          }
 168          else
 169          {
 170              moderation_redirect("moderation.php?action=delayedmoderation&amp;tid={$tid}&amp;my_post_key={$mybb->post_code}", $lang->redirect_delayed_moderation_cancelled);
 171          }
 172          break;
 173      case "do_delayedmoderation":
 174      case "delayedmoderation":
 175          // Verify incoming POST request
 176          verify_post_check($mybb->get_input('my_post_key'));
 177          
 178          $localized_time_offset = $mybb->user['timezone']*3600 + $mybb->user['dst']*3600;
 179  
 180          if(!$mybb->get_input('date_day', MyBB::INPUT_INT))
 181          {
 182              $mybb->input['date_day'] = gmdate('d', TIME_NOW + $localized_time_offset);
 183          }
 184          if(!$mybb->get_input('date_month', MyBB::INPUT_INT))
 185          {
 186              $mybb->input['date_month'] = gmdate('m', TIME_NOW + $localized_time_offset);
 187          }
 188  
 189          // Assume in-line moderation if TID is not set
 190          if(!empty($mybb->input['tid']))
 191          {
 192              $mybb->input['tids'] = $tid;
 193          }
 194          else
 195          {
 196              if($mybb->get_input('inlinetype') == 'search')
 197              {
 198                  $tids = getids($mybb->get_input('searchid'), 'search');
 199              }
 200              else
 201              {
 202                  $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
 203                  $tids = getids($fid, "forum");
 204              }
 205              if(count($tids) < 1)
 206              {
 207                  error($lang->error_inline_nothreadsselected, $lang->error);
 208              }
 209  
 210              $mybb->input['tids'] = $tids;
 211          }
 212  
 213          add_breadcrumb($lang->delayed_moderation);
 214  
 215          if(!is_moderator($fid, "canmanagethreads"))
 216          {
 217              error_no_permission();
 218          }
 219  
 220          $errors = array();
 221          $customthreadtools = "";
 222  
 223          $allowed_types = array('move', 'merge', 'removeredirects', 'removesubscriptions');
 224  
 225          if(is_moderator($fid, "canopenclosethreads"))
 226          {
 227              $allowed_types[] = "openclosethread";
 228          }
 229  
 230          if(is_moderator($fid, "cansoftdeletethreads") || is_moderator($fid, "canrestorethreads"))
 231          {
 232              $allowed_types[] = "softdeleterestorethread";
 233          }
 234  
 235          if(is_moderator($fid, "candeletethreads"))
 236          {
 237              $allowed_types[] = "deletethread";
 238          }
 239  
 240          if(is_moderator($fid, "canstickunstickthreads"))
 241          {
 242              $allowed_types[] = "stick";
 243          }
 244  
 245          if(is_moderator($fid, "canapproveunapprovethreads"))
 246          {
 247              $allowed_types[] = "approveunapprovethread";
 248          }
 249  
 250          $mybb->input['type'] = $mybb->get_input('type');
 251  
 252          if(is_moderator($fid, "canusecustomtools"))
 253          {
 254              switch($db->type)
 255              {
 256                  case "pgsql":
 257                  case "sqlite":
 258                      $query = $db->simple_select("modtools", 'tid, name, `groups`', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND type = 't'");
 259                      break;
 260                  default:
 261                      $query = $db->simple_select("modtools", 'tid, name, `groups`', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'");
 262              }
 263              while($tool = $db->fetch_array($query))
 264              {
 265                  if(is_member($tool['groups']))
 266                  {
 267                      $allowed_types[] = "modtool_".$tool['tid'];
 268  
 269                      $tool['name'] = htmlspecialchars_uni($tool['name']);
 270  
 271                      $checked = "";
 272                      if($mybb->input['type'] == "modtool_".$tool['tid'])
 273                      {
 274                          $checked = "checked=\"checked\"";
 275                      }
 276  
 277                      eval("\$customthreadtools .= \"".$templates->get("moderation_delayedmoderation_custommodtool")."\";");
 278                  }
 279              }
 280          }
 281  
 282          $mybb->input['delayedmoderation'] = $mybb->get_input('delayedmoderation', MyBB::INPUT_ARRAY);
 283  
 284          if($mybb->input['action'] == "do_delayedmoderation" && $mybb->request_method == "post")
 285          {
 286              if(!in_array($mybb->input['type'], $allowed_types))
 287              {
 288                  $mybb->input['type'] = '';
 289                  $errors[] = $lang->error_delayedmoderation_unsupported_type;
 290              }
 291  
 292              if($mybb->input['type'] == 'move' && (!isset($mybb->input['delayedmoderation']['method']) || !in_array($mybb->input['delayedmoderation']['method'], array('move', 'redirect', 'copy'))))
 293              {
 294                  $mybb->input['delayedmoderation']['method'] = '';
 295                  $errors[] = $lang->error_delayedmoderation_unsupported_method;
 296              }
 297  
 298              if($mybb->input['type'] == 'move')
 299              {
 300                  $newfid = (int)$mybb->input['delayedmoderation']['new_forum'];
 301  
 302                  // Make sure moderator has permission to move to the new forum
 303                  $newperms = forum_permissions($newfid);
 304                  if($newperms['canview'] == 0 || !is_moderator($newfid, 'canmovetononmodforum'))
 305                  {
 306                      $errors[] = $lang->error_movetononmodforum;
 307                  }
 308  
 309                  $newforum = get_forum($newfid);
 310                  if(!$newforum || $newforum['type'] != "f" || $newforum['type'] == "f" && $newforum['linkto'] != '')
 311                  {
 312                      $errors[] = $lang->error_invalidforum;
 313                  }
 314  
 315                  $method = $mybb->input['delayedmoderation']['method'];
 316                  if($method != "copy" && $fid == $newfid)
 317                  {
 318                      $errors[] = $lang->error_movetosameforum;
 319                  }
 320              }
 321  
 322              if($mybb->input['date_day'] > 31 || $mybb->input['date_day'] < 1)
 323              {
 324                  $errors[] = $lang->error_delayedmoderation_invalid_date_day;
 325              }
 326  
 327              if($mybb->input['date_month'] > 12 || $mybb->input['date_month'] < 1)
 328              {
 329                  $errors[] = $lang->error_delayedmoderation_invalid_date_month;
 330              }
 331  
 332              if($mybb->input['date_year'] < gmdate('Y', TIME_NOW + $localized_time_offset))
 333              {
 334                  $errors[] = $lang->error_delayedmoderation_invalid_date_year;
 335              }
 336  
 337              $date_time = explode(' ', $mybb->get_input('date_time'));
 338              $date_time = explode(':', (string)$date_time[0]);
 339  
 340              if(stristr($mybb->input['date_time'], 'pm'))
 341              {
 342                  $date_time[0] = 12+$date_time[0];
 343                  if($date_time[0] >= 24)
 344                  {
 345                      $date_time[0] = '00';
 346                  }
 347              }
 348  
 349              $rundate = gmmktime((int)$date_time[0], (int)$date_time[1], date('s', TIME_NOW), $mybb->get_input('date_month', MyBB::INPUT_INT), $mybb->get_input('date_day', MyBB::INPUT_INT), $mybb->get_input('date_year', MyBB::INPUT_INT)) - $localized_time_offset;
 350  
 351              if(!$errors)
 352              {
 353                  if(is_array($mybb->input['tids']))
 354                  {
 355                      $mybb->input['tids'] = implode(',', $mybb->input['tids']);
 356                  }
 357  
 358                  $did = $db->insert_query("delayedmoderation", array(
 359                      'type' => $db->escape_string($mybb->input['type']),
 360                      'delaydateline' => (int)$rundate,
 361                      'uid' => $mybb->user['uid'],
 362                      'tids' => $db->escape_string($mybb->input['tids']),
 363                      'fid' => $fid,
 364                      'dateline' => TIME_NOW,
 365                      'inputs' => $db->escape_string(my_serialize($mybb->input['delayedmoderation']))
 366                  ));
 367  
 368                  $plugins->run_hooks('moderation_do_delayedmoderation');
 369  
 370                  $rundate_format = my_date('relative', $rundate, '', 2);
 371                  $lang->redirect_delayed_moderation_thread = $lang->sprintf($lang->redirect_delayed_moderation_thread, $rundate_format);
 372  
 373                  if(!empty($mybb->input['tid']))
 374                  {
 375                      moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_delayed_moderation_thread);
 376                  }
 377                  else
 378                  {
 379                      if($mybb->get_input('inlinetype') == 'search')
 380                      {
 381                          moderation_redirect(get_forum_link($fid), $lang->sprintf($lang->redirect_delayed_moderation_search, $rundate_format));
 382                      }
 383                      else
 384                      {
 385                          moderation_redirect(get_forum_link($fid), $lang->sprintf($lang->redirect_delayed_moderation_forum, $rundate_format));
 386                      }
 387                  }
 388              }
 389              else
 390              {
 391                  $type_selected = array();
 392                  foreach($allowed_types as $type)
 393                  {
 394                      $type_selected[$type] = '';
 395                  }
 396                  $type_selected[$mybb->get_input('type')] = "checked=\"checked\"";
 397                  $method_selected = array('move' => '', 'redirect' => '', 'copy' => '');
 398                  if(isset($mybb->input['delayedmoderation']['method']))
 399                  {
 400                      $method_selected[$mybb->input['delayedmoderation']['method']] = "checked=\"checked\"";
 401                  }
 402  
 403                  foreach(array('redirect_expire', 'new_forum', 'subject', 'threadurl') as $value)
 404                  {
 405                      if(!isset($mybb->input['delayedmoderation'][$value]))
 406                      {
 407                          $mybb->input['delayedmoderation'][$value] = '';
 408                      }
 409                  }
 410                  $mybb->input['delayedmoderation']['redirect_expire'] = (int)$mybb->input['delayedmoderation']['redirect_expire'];
 411                  $mybb->input['delayedmoderation']['new_forum'] = (int)$mybb->input['delayedmoderation']['new_forum'];
 412                  $mybb->input['delayedmoderation']['subject'] = htmlspecialchars_uni($mybb->input['delayedmoderation']['subject']);
 413                  $mybb->input['delayedmoderation']['threadurl'] = htmlspecialchars_uni($mybb->input['delayedmoderation']['threadurl']);
 414  
 415                  $forumselect = build_forum_jump("", $mybb->input['delayedmoderation']['new_forum'], 1, '', 0, true, '', "delayedmoderation[new_forum]");
 416              }
 417          }
 418          else
 419          {
 420              $type_selected = array();
 421              foreach($allowed_types as $type)
 422              {
 423                  $type_selected[$type] = '';
 424              }
 425              $type_selected['openclosethread'] = "checked=\"checked\"";
 426              $method_selected = array('move' => 'checked="checked"', 'redirect' => '', 'copy' => '');
 427  
 428              $mybb->input['delayedmoderation']['redirect_expire'] = '';
 429              $mybb->input['delayedmoderation']['subject'] = isset($thread['subject']) ? $thread['subject'] : '';
 430              $mybb->input['delayedmoderation']['threadurl'] = '';
 431  
 432              $forumselect = build_forum_jump("", $fid, 1, '', 0, true, '', "delayedmoderation[new_forum]");
 433          }
 434  
 435          if(isset($errors) && count($errors) > 0)
 436          {
 437              $display_errors = inline_error($errors);
 438          }
 439          else
 440          {
 441              $display_errors = '';
 442          }
 443  
 444          $forum_cache = $cache->read("forums");
 445  
 446          $actions = array(
 447              'openclosethread' => $lang->open_close_thread,
 448              'softdeleterestorethread' => $lang->softdelete_restore_thread,
 449              'deletethread' => $lang->delete_thread,
 450              'move' => $lang->move_copy_thread,
 451              'stick' => $lang->stick_unstick_thread,
 452              'merge' => $lang->merge_threads,
 453              'removeredirects' => $lang->remove_redirects,
 454              'removesubscriptions' => $lang->remove_subscriptions,
 455              'approveunapprovethread' => $lang->approve_unapprove_thread
 456          );
 457  
 458          switch($db->type)
 459          {
 460              case "pgsql":
 461              case "sqlite":
 462                  $query = $db->simple_select("modtools", 'tid, name', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND type = 't'");
 463                  break;
 464              default:
 465                  $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'");
 466          }
 467          while($tool = $db->fetch_array($query))
 468          {
 469              $actions['modtool_'.$tool['tid']] = htmlspecialchars_uni($tool['name']);
 470          }
 471  
 472          $delayedmods = '';
 473          $trow = alt_trow(1);
 474          if($tid == 0)
 475          {
 476              // Inline thread moderation is used
 477              if($mybb->get_input('inlinetype') == 'search')
 478              {
 479                  $tids = getids($mybb->get_input('searchid'), 'search');
 480              }
 481              else
 482              {
 483                  $tids = getids($fid, "forum");
 484              }
 485              $where_array = array();
 486              switch($db->type)
 487              {
 488                  case "pgsql":
 489                  case "sqlite":
 490                      foreach($tids as $like)
 491                      {
 492                          $where_array[] = "','||d.tids||',' LIKE '%,".$db->escape_string($like).",%'";
 493                      }
 494                      $where_statement = implode(" OR ", $where_array);
 495                      break;
 496                  default:
 497                      foreach($tids as $like)
 498                      {
 499                          $where_array[] = "CONCAT(',',d.tids,',') LIKE  '%,".$db->escape_string($like).",%'";
 500                      }
 501                      $where_statement = implode(" OR ", $where_array);
 502              }
 503              $query = $db->query("
 504                  SELECT d.*, u.username, f.name AS fname
 505                  FROM ".TABLE_PREFIX."delayedmoderation d
 506                  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
 507                  LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=d.fid)
 508                  WHERE ".$where_statement."
 509                  ORDER BY d.dateline DESC
 510                  LIMIT  0, 20
 511              ");
 512          }
 513          else
 514          {
 515              switch($db->type)
 516              {
 517                  case "pgsql":
 518                  case "sqlite":
 519                      $query = $db->query("
 520                          SELECT d.*, u.username, f.name AS fname
 521                          FROM ".TABLE_PREFIX."delayedmoderation d
 522                          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
 523                          LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=d.fid)
 524                          WHERE ','||d.tids||',' LIKE '%,{$tid},%'
 525                          ORDER BY d.dateline DESC
 526                          LIMIT  0, 20
 527                      ");
 528                      break;
 529                  default:
 530                      $query = $db->query("
 531                          SELECT d.*, u.username, f.name AS fname
 532                          FROM ".TABLE_PREFIX."delayedmoderation d
 533                          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
 534                          LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=d.fid)
 535                          WHERE CONCAT(',',d.tids,',') LIKE '%,{$tid},%'
 536                          ORDER BY d.dateline DESC
 537                          LIMIT  0, 20
 538                      ");
 539              }
 540          }
 541  
 542          while($delayedmod = $db->fetch_array($query))
 543          {
 544              $delayedmod['dateline'] = my_date('normal', $delayedmod['delaydateline'], "", 2);
 545              $delayedmod['username'] = htmlspecialchars_uni($delayedmod['username']);
 546              $delayedmod['profilelink'] = build_profile_link($delayedmod['username'], $delayedmod['uid']);
 547              $delayedmod['action'] = $actions[$delayedmod['type']];
 548              $info = '';
 549              if(strpos($delayedmod['tids'], ',') === false)
 550              {
 551                  $delayed_thread = get_thread($delayedmod['tids']);
 552                  $delayed_thread['link'] = get_thread_link($delayed_thread['tid']);
 553                  $delayed_thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($delayed_thread['subject']));
 554                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_thread_single")."\";");
 555              }
 556              else
 557              {
 558                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_thread_multiple")."\";");
 559              }
 560  
 561              if($delayedmod['fname'])
 562              {
 563                  $delayedmod['link'] = get_forum_link($delayedmod['fid']);
 564                  $delayedmod['fname'] = htmlspecialchars_uni($delayedmod['fname']);
 565                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_forum")."\";");
 566              }
 567              $delayedmod['inputs'] = my_unserialize($delayedmod['inputs']);
 568  
 569              if($delayedmod['type'] == 'move')
 570              {
 571                  $delayedmod['link'] = get_forum_link($delayedmod['inputs']['new_forum']);
 572                  $delayedmod['name'] = htmlspecialchars_uni($forum_cache[$delayedmod['inputs']['new_forum']]['name']);
 573                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_new_forum")."\";");
 574  
 575                  if($delayedmod['inputs']['method'] == "redirect")
 576                  {
 577                      if((int)$delayedmod['inputs']['redirect_expire'] == 0)
 578                      {
 579                          $redirect_expire_bit = $lang->redirect_forever;
 580                      }
 581                      else
 582                      {
 583                          $redirect_expire_bit = (int)$delayedmod['inputs']['redirect_expire']." {$lang->days}";
 584                      }
 585  
 586                      eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_redirect")."\";");
 587                  }
 588              }
 589              elseif($delayedmod['type'] == 'merge')
 590              {
 591                  $delayedmod['subject'] = htmlspecialchars_uni($delayedmod['inputs']['subject']);
 592                  $delayedmod['threadurl'] = htmlspecialchars_uni($delayedmod['inputs']['threadurl']);
 593                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_merge")."\";");
 594              }
 595  
 596              eval("\$delayedmods .= \"".$templates->get("moderation_delayedmodaction_notes")."\";");
 597              $trow = alt_trow();
 598          }
 599          if(!$delayedmods)
 600          {
 601              $cols = 5;
 602              eval("\$delayedmods = \"".$templates->get("moderation_delayedmodaction_error")."\";");
 603          }
 604  
 605          $url = '';
 606          if($mybb->get_input('tid', MyBB::INPUT_INT))
 607          {
 608              $lang->threads = $lang->thread;
 609              $thread['link'] = get_thread_link($tid);
 610              $delayedmoderation_subject = $mybb->input['delayedmoderation']['subject'];
 611              $delayedmoderation_threadurl = $mybb->input['delayedmoderation']['threadurl'];
 612              eval("\$threads = \"".$templates->get("moderation_delayedmoderation_thread")."\";");
 613              eval("\$moderation_delayedmoderation_merge = \"".$templates->get("moderation_delayedmoderation_merge")."\";");
 614          }
 615          else
 616          {
 617              if($mybb->get_input('inlinetype') == 'search')
 618              {
 619                  $tids = getids($mybb->get_input('searchid'), 'search');
 620                  $url = htmlspecialchars_uni($mybb->get_input('url'));
 621              }
 622              else
 623              {
 624                  $tids = getids($fid, "forum");
 625              }
 626              if(count($tids) < 1)
 627              {
 628                  error($lang->error_inline_nothreadsselected, $lang->error);
 629              }
 630  
 631              $threads = $lang->sprintf($lang->threads_selected, count($tids));
 632              $moderation_delayedmoderation_merge = '';
 633          }
 634          $redirect_expire = $mybb->get_input('redirect_expire');
 635          eval("\$moderation_delayedmoderation_move = \"".$templates->get("moderation_delayedmoderation_move")."\";");
 636  
 637          // Generate form elements for date form
 638          $dateday = '';
 639          for($day = 1; $day <= 31; ++$day)
 640          {
 641              $selected = '';
 642              if($mybb->get_input('date_day', MyBB::INPUT_INT) == $day)
 643              {
 644                  $selected = ' selected="selected"';
 645              }
 646              eval('$dateday .= "'.$templates->get('moderation_delayedmoderation_date_day').'";');
 647          }
 648  
 649          $datemonth = array();
 650          foreach(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12') as $month)
 651          {
 652              $datemonth[$month] = '';
 653              if($mybb->get_input('date_month', MyBB::INPUT_INT) == (int)$month)
 654              {
 655                  $datemonth[$month] = ' selected="selected"';
 656              }
 657          }
 658          
 659  
 660          eval('$datemonth = "'.$templates->get('moderation_delayedmoderation_date_month').'";');
 661  
 662          $dateyear = gmdate('Y', TIME_NOW  + $localized_time_offset);
 663          $datetime = gmdate($mybb->settings['timeformat'], TIME_NOW + $localized_time_offset);
 664  
 665          $openclosethread = '';
 666          if(is_moderator($fid, "canopenclosethreads"))
 667          {
 668              eval('$openclosethread = "'.$templates->get('moderation_delayedmoderation_openclose').'";');
 669          }
 670  
 671          $softdeleterestorethread = '';
 672          if(is_moderator($fid, "cansoftdeletethreads") || is_moderator($fid, "canrestorethreads"))
 673          {
 674              eval('$softdeleterestorethread = "'.$templates->get('moderation_delayedmoderation_softdeleterestore').'";');
 675          }
 676  
 677          $deletethread = '';
 678          if(is_moderator($fid, "candeletethreads"))
 679          {
 680              eval('$deletethread = "'.$templates->get('moderation_delayedmoderation_delete').'";');
 681          }
 682  
 683          $stickunstickthread = '';
 684          if(is_moderator($fid, "canstickunstickthreads"))
 685          {
 686              eval('$stickunstickthread = "'.$templates->get('moderation_delayedmoderation_stick').'";');
 687          }
 688  
 689          $approveunapprovethread = '';
 690          if(is_moderator($fid, "canapproveunapprovethreads"))
 691          {
 692              eval('$approveunapprovethread = "'.$templates->get('moderation_delayedmoderation_approve').'";');
 693          } 
 694  
 695          $plugins->run_hooks("moderation_delayedmoderation");
 696  
 697          eval("\$delayedmoderation = \"".$templates->get("moderation_delayedmoderation")."\";");
 698          output_page($delayedmoderation);
 699          break;
 700      // Open or close a thread
 701      case "openclosethread":
 702          // Verify incoming POST request
 703          verify_post_check($mybb->get_input('my_post_key'));
 704  
 705          if(!is_moderator($fid, "canopenclosethreads"))
 706          {
 707              error_no_permission();
 708          }
 709  
 710          if($thread['visible'] == -1)
 711          {
 712              error($lang->error_thread_deleted, $lang->error);
 713          }
 714  
 715          if($thread['closed'] == 1)
 716          {
 717              $openclose = $lang->opened;
 718              $redirect = $lang->redirect_openthread;
 719              $moderation->open_threads($tid);
 720          }
 721          else
 722          {
 723              $openclose = $lang->closed;
 724              $redirect = $lang->redirect_closethread;
 725              $moderation->close_threads($tid);
 726          }
 727  
 728          $lang->mod_process = $lang->sprintf($lang->mod_process, $openclose);
 729  
 730          log_moderator_action($modlogdata, $lang->mod_process);
 731  
 732          moderation_redirect(get_thread_link($thread['tid']), $redirect);
 733          break;
 734  
 735      // Stick or unstick that post to the top bab!
 736      case "stick":
 737          // Verify incoming POST request
 738          verify_post_check($mybb->get_input('my_post_key'));
 739  
 740          if(!is_moderator($fid, "canstickunstickthreads"))
 741          {
 742              error_no_permission();
 743          }
 744  
 745          if($thread['visible'] == -1)
 746          {
 747              error($lang->error_thread_deleted, $lang->error);
 748          }
 749  
 750          $plugins->run_hooks("moderation_stick");
 751  
 752          if($thread['sticky'] == 1)
 753          {
 754              $stuckunstuck = $lang->unstuck;
 755              $redirect = $lang->redirect_unstickthread;
 756              $moderation->unstick_threads($tid);
 757          }
 758          else
 759          {
 760              $stuckunstuck = $lang->stuck;
 761              $redirect = $lang->redirect_stickthread;
 762              $moderation->stick_threads($tid);
 763          }
 764  
 765          $lang->mod_process = $lang->sprintf($lang->mod_process, $stuckunstuck);
 766  
 767          log_moderator_action($modlogdata, $lang->mod_process);
 768  
 769          moderation_redirect(get_thread_link($thread['tid']), $redirect);
 770          break;
 771  
 772      // Remove redirects to a specific thread
 773      case "removeredirects":
 774  
 775          // Verify incoming POST request
 776          verify_post_check($mybb->get_input('my_post_key'));
 777  
 778          if(!is_moderator($fid, "canmanagethreads"))
 779          {
 780              error_no_permission();
 781          }
 782  
 783          if($thread['visible'] == -1)
 784          {
 785              error($lang->error_thread_deleted, $lang->error);
 786          }
 787  
 788          $plugins->run_hooks("moderation_removeredirects");
 789  
 790          $moderation->remove_redirects($tid);
 791  
 792          log_moderator_action($modlogdata, $lang->redirects_removed);
 793          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_redirectsremoved);
 794          break;
 795  
 796      // Delete thread confirmation page
 797      case "deletethread":
 798  
 799          add_breadcrumb($lang->nav_deletethread);
 800  
 801          if(!is_moderator($fid, "candeletethreads"))
 802          {
 803              if($permissions['candeletethreads'] != 1 || $mybb->user['uid'] != $thread['uid'])
 804              {
 805                  error_no_permission();
 806              }
 807          }
 808  
 809          $plugins->run_hooks("moderation_deletethread");
 810  
 811          eval("\$deletethread = \"".$templates->get("moderation_deletethread")."\";");
 812          output_page($deletethread);
 813          break;
 814  
 815      // Delete the actual thread here
 816      case "do_deletethread":
 817  
 818          // Verify incoming POST request
 819          verify_post_check($mybb->get_input('my_post_key'));
 820  
 821          if(!is_moderator($fid, "candeletethreads"))
 822          {
 823              if($permissions['candeletethreads'] != 1 || $mybb->user['uid'] != $thread['uid'])
 824              {
 825                  error_no_permission();
 826              }
 827          }
 828  
 829          $plugins->run_hooks("moderation_do_deletethread");
 830  
 831          // Log the subject of the deleted thread
 832          $modlogdata['thread_subject'] = $thread['subject'];
 833  
 834          $thread['subject'] = $db->escape_string($thread['subject']);
 835          $lang->thread_deleted = $lang->sprintf($lang->thread_deleted, $thread['subject']);
 836          log_moderator_action($modlogdata, $lang->thread_deleted);
 837  
 838          $moderation->delete_thread($tid);
 839  
 840          mark_reports($tid, "thread");
 841          moderation_redirect(get_forum_link($fid), $lang->redirect_threaddeleted);
 842          break;
 843  
 844      // Delete the poll from a thread confirmation page
 845      case "deletepoll":
 846          add_breadcrumb($lang->nav_deletepoll);
 847  
 848          if(!is_moderator($fid, "canmanagepolls"))
 849          {
 850              if($permissions['candeletethreads'] != 1 || $mybb->user['uid'] != $thread['uid'])
 851              {
 852                  error_no_permission();
 853              }
 854          }
 855  
 856          $plugins->run_hooks("moderation_deletepoll");
 857  
 858          $query = $db->simple_select("polls", "pid", "tid='$tid'");
 859          $poll = $db->fetch_array($query);
 860          if(!$poll)
 861          {
 862              error($lang->error_invalidpoll, $lang->error);
 863          }
 864  
 865          eval("\$deletepoll = \"".$templates->get("moderation_deletepoll")."\";");
 866          output_page($deletepoll);
 867          break;
 868  
 869      // Delete the actual poll here!
 870      case "do_deletepoll":
 871  
 872          // Verify incoming POST request
 873          verify_post_check($mybb->get_input('my_post_key'));
 874  
 875          if($thread['visible'] == -1)
 876          {
 877              error($lang->error_thread_deleted, $lang->error);
 878          }
 879  
 880          if(!isset($mybb->input['delete']))
 881          {
 882              error($lang->redirect_pollnotdeleted);
 883          }
 884          if(!is_moderator($fid, "canmanagepolls"))
 885          {
 886              if($permissions['candeletethreads'] != 1 || $mybb->user['uid'] != $thread['uid'])
 887              {
 888                  error_no_permission();
 889              }
 890          }
 891          $query = $db->simple_select("polls", "pid", "tid = $tid");
 892          $poll = $db->fetch_array($query);
 893          if(!$poll)
 894          {
 895              error($lang->error_invalidpoll, $lang->error);
 896          }
 897  
 898          $plugins->run_hooks("moderation_do_deletepoll");
 899  
 900          $lang->poll_deleted = $lang->sprintf($lang->poll_deleted, $thread['subject']);
 901          log_moderator_action($modlogdata, $lang->poll_deleted);
 902  
 903          $moderation->delete_poll($poll['pid']);
 904  
 905          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_polldeleted);
 906          break;
 907  
 908      // Approve a thread
 909      case "approvethread":
 910  
 911          // Verify incoming POST request
 912          verify_post_check($mybb->get_input('my_post_key'));
 913  
 914          if(!is_moderator($fid, "canapproveunapprovethreads"))
 915          {
 916              error_no_permission();
 917          }
 918  
 919          if($thread['visible'] == -1)
 920          {
 921              error($lang->error_thread_deleted, $lang->error);
 922          }
 923  
 924          $thread = get_thread($tid);
 925  
 926          $plugins->run_hooks("moderation_approvethread");
 927  
 928          $lang->thread_approved = $lang->sprintf($lang->thread_approved, $thread['subject']);
 929          log_moderator_action($modlogdata, $lang->thread_approved);
 930  
 931          $moderation->approve_threads($tid, $fid);
 932  
 933          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadapproved);
 934          break;
 935  
 936      // Unapprove a thread
 937      case "unapprovethread":
 938  
 939          // Verify incoming POST request
 940          verify_post_check($mybb->get_input('my_post_key'));
 941  
 942          if(!is_moderator($fid, "canapproveunapprovethreads"))
 943          {
 944              error_no_permission();
 945          }
 946  
 947          if($thread['visible'] == -1)
 948          {
 949              error($lang->error_thread_deleted, $lang->error);
 950          }
 951  
 952          $thread = get_thread($tid);
 953  
 954          $plugins->run_hooks("moderation_unapprovethread");
 955  
 956          $lang->thread_unapproved = $lang->sprintf($lang->thread_unapproved, $thread['subject']);
 957          log_moderator_action($modlogdata, $lang->thread_unapproved);
 958  
 959          $moderation->unapprove_threads($tid);
 960  
 961          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadunapproved);
 962          break;
 963  
 964      // Restore a thread
 965      case "restorethread":
 966  
 967          // Verify incoming POST request
 968          verify_post_check($mybb->get_input('my_post_key'));
 969  
 970          if(!is_moderator($fid, "canrestorethreads"))
 971          {
 972              error_no_permission();
 973          }
 974          $thread = get_thread($tid);
 975  
 976          $plugins->run_hooks("moderation_restorethread");
 977  
 978          $lang->thread_restored = $lang->sprintf($lang->thread_restored, $thread['subject']);
 979          log_moderator_action($modlogdata, $lang->thread_restored);
 980  
 981          $moderation->restore_threads($tid);
 982  
 983          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadrestored);
 984          break;
 985  
 986      // Soft delete a thread
 987      case "softdeletethread":
 988  
 989          // Verify incoming POST request
 990          verify_post_check($mybb->get_input('my_post_key'));
 991  
 992          if(!is_moderator($fid, "cansoftdeletethreads"))
 993          {
 994              error_no_permission();
 995          }
 996          $thread = get_thread($tid);
 997  
 998          $plugins->run_hooks("moderation_softdeletethread");
 999  
1000          $lang->thread_soft_deleted = $lang->sprintf($lang->thread_soft_deleted, $thread['subject']);
1001          log_moderator_action($modlogdata, $lang->thread_soft_deleted);
1002  
1003          $moderation->soft_delete_threads($tid);
1004  
1005          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadsoftdeleted);
1006          break;
1007  
1008      // Move a thread
1009      case "move":
1010          add_breadcrumb($lang->nav_move);
1011          if(!is_moderator($fid, "canmanagethreads"))
1012          {
1013              error_no_permission();
1014          }
1015  
1016          if($thread['visible'] == -1)
1017          {
1018              error($lang->error_thread_deleted, $lang->error);
1019          }
1020  
1021          $plugins->run_hooks("moderation_move");
1022  
1023          $forumselect = build_forum_jump("", $fid, 1, '', 0, true, '', "moveto");
1024          eval("\$movethread = \"".$templates->get("moderation_move")."\";");
1025          output_page($movethread);
1026          break;
1027  
1028      // Let's get this thing moving!
1029      case "do_move":
1030  
1031          // Verify incoming POST request
1032          verify_post_check($mybb->get_input('my_post_key'));
1033  
1034          $moveto = $mybb->get_input('moveto', MyBB::INPUT_INT);
1035          $method = $mybb->get_input('method');
1036  
1037          if(!is_moderator($fid, "canmanagethreads"))
1038          {
1039              error_no_permission();
1040          }
1041  
1042          // Check if user has moderator permission to move to destination
1043          if(!is_moderator($moveto, "canmanagethreads") && !is_moderator($fid, "canmovetononmodforum"))
1044          {
1045              error_no_permission();
1046          }
1047  
1048          if($thread['visible'] == -1)
1049          {
1050              error($lang->error_thread_deleted, $lang->error);
1051          }
1052          
1053          $newperms = forum_permissions($moveto);
1054          if($newperms['canview'] == 0 && !is_moderator($fid, "canmovetononmodforum"))
1055          {
1056              error($lang->error_movetononmodforum, $lang->error);
1057          }
1058  
1059          $newforum = get_forum($moveto);
1060          if(!$newforum || $newforum['type'] != "f" || $newforum['type'] == "f" && $newforum['linkto'] != '')
1061          {
1062              error($lang->error_invalidforum, $lang->error);
1063          }
1064          if($method != "copy" && $thread['fid'] == $moveto)
1065          {
1066              error($lang->error_movetosameforum, $lang->error);
1067          }
1068  
1069          $plugins->run_hooks('moderation_do_move');
1070  
1071          $expire = 0;
1072          if($mybb->get_input('redirect_expire', MyBB::INPUT_INT) > 0)
1073          {
1074              $expire = TIME_NOW + ($mybb->get_input('redirect_expire', MyBB::INPUT_INT) * 86400);
1075          }
1076  
1077          $the_thread = $tid;
1078  
1079          $newtid = $moderation->move_thread($tid, $moveto, $method, $expire);
1080  
1081          switch($method)
1082          {
1083              case "copy":
1084                  log_moderator_action($modlogdata, $lang->thread_copied);
1085                  break;
1086              default:
1087              case "move":
1088              case "redirect":
1089                  log_moderator_action($modlogdata, $lang->thread_moved);
1090                  break;
1091          }
1092  
1093          moderation_redirect(get_thread_link($newtid), $lang->redirect_threadmoved);
1094          break;
1095  
1096      // Viewing thread notes
1097      case "viewthreadnotes":
1098          if(!is_moderator($fid))
1099          {
1100              error_no_permission();
1101          }
1102  
1103          // Make sure we are looking at a real thread here.
1104          if(!$thread)
1105          {
1106              error($lang->error_nomember, $lang->error);
1107          }
1108  
1109          $plugins->run_hooks('moderation_viewthreadnotes');
1110  
1111          $lang->view_notes_for = $lang->sprintf($lang->view_notes_for, $thread['subject']);
1112  
1113          $thread['notes'] = nl2br(htmlspecialchars_uni($thread['notes']));
1114  
1115          eval("\$viewthreadnotes = \"".$templates->get("moderation_viewthreadnotes", 1, 0)."\";");
1116          echo $viewthreadnotes;
1117          break;
1118  
1119      // Thread notes editor
1120      case "threadnotes":
1121          add_breadcrumb($lang->nav_threadnotes);
1122          if(!is_moderator($fid, "canmanagethreads"))
1123          {
1124              error_no_permission();
1125          }
1126          $thread['notes'] = htmlspecialchars_uni($parser->parse_badwords($thread['notes']));
1127          $trow = alt_trow(1);
1128  
1129          if(is_moderator($fid, "canviewmodlog"))
1130          {
1131              $query = $db->query("
1132                  SELECT l.*, u.username, t.subject AS tsubject, f.name AS fname, p.subject AS psubject
1133                  FROM ".TABLE_PREFIX."moderatorlog l
1134                  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
1135                  LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
1136                  LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid)
1137                  LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid)
1138                  WHERE t.tid='$tid'
1139                  ORDER BY l.dateline DESC
1140                  LIMIT  0, 20
1141              ");
1142              $modactions = '';
1143              while($modaction = $db->fetch_array($query))
1144              {
1145                  $modaction['dateline'] = my_date('relative', $modaction['dateline']);
1146                  $modaction['username'] = htmlspecialchars_uni($modaction['username']);
1147                  $modaction['profilelink'] = build_profile_link($modaction['username'], $modaction['uid']);
1148                  $modaction['action'] = htmlspecialchars_uni($modaction['action']);
1149                  $info = '';
1150                  if($modaction['tsubject'])
1151                  {
1152                      $modaction['tsubject'] = htmlspecialchars_uni($parser->parse_badwords($modaction['tsubject']));
1153                      $modaction['threadlink'] = get_thread_link($modaction['tid']);
1154                      eval("\$info .= \"".$templates->get("moderation_threadnotes_modaction_thread")."\";");
1155                  }
1156                  if($modaction['fname'])
1157                  {
1158                      $modaction['fname'] = htmlspecialchars_uni($modaction['fname']);
1159                      $modaction['forumlink'] = get_forum_link($modaction['fid']);
1160                      eval("\$info .= \"".$templates->get("moderation_threadnotes_modaction_forum")."\";");
1161                  }
1162                  if($modaction['psubject'])
1163                  {
1164  
1165                      $modaction['psubject'] = htmlspecialchars_uni($parser->parse_badwords($modaction['psubject']));
1166                      $modaction['postlink'] = get_post_link($modaction['pid']);
1167                      eval("\$info .= \"".$templates->get("moderation_threadnotes_modaction_post")."\";");
1168                  }
1169  
1170                  eval("\$modactions .= \"".$templates->get("moderation_threadnotes_modaction")."\";");
1171                  $trow = alt_trow();
1172              }
1173              if(!$modactions)
1174              {
1175                  eval("\$modactions = \"".$templates->get("moderation_threadnotes_modaction_error")."\";");
1176              }
1177          }
1178  
1179          $actions = array(
1180              'openclosethread' => $lang->open_close_thread,
1181              'deletethread' => $lang->delete_thread,
1182              'move' => $lang->move_copy_thread,
1183              'stick' => $lang->stick_unstick_thread,
1184              'merge' => $lang->merge_threads,
1185              'removeredirects' => $lang->remove_redirects,
1186              'removesubscriptions' => $lang->remove_subscriptions,
1187              'approveunapprovethread' => $lang->approve_unapprove_thread
1188          );
1189  
1190          switch($db->type)
1191          {
1192              case "pgsql":
1193              case "sqlite":
1194                  $query = $db->simple_select("modtools", 'tid, name', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND type = 't'");
1195                  break;
1196              default:
1197                  $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'");
1198          }
1199          while($tool = $db->fetch_array($query))
1200          {
1201              $actions['modtool_'.$tool['tid']] = htmlspecialchars_uni($tool['name']);
1202          }
1203  
1204          $forum_cache = $cache->read("forums");
1205  
1206          $trow = alt_trow(1);
1207          switch($db->type)
1208          {
1209              case "pgsql":
1210              case "sqlite":
1211                  $query = $db->query("
1212                      SELECT d.*, u.username, f.name AS fname
1213                      FROM ".TABLE_PREFIX."delayedmoderation d
1214                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
1215                      LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=d.fid)
1216                      WHERE ','||d.tids||',' LIKE '%,{$tid},%'
1217                      ORDER BY d.dateline DESC
1218                      LIMIT  0, 20
1219                  ");
1220                  break;
1221              default:
1222                  $query = $db->query("
1223                      SELECT d.*, u.username, f.name AS fname
1224                      FROM ".TABLE_PREFIX."delayedmoderation d
1225                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
1226                      LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=d.fid)
1227                      WHERE CONCAT(',',d.tids,',') LIKE '%,{$tid},%'
1228                      ORDER BY d.dateline DESC
1229                      LIMIT  0, 20
1230                  ");
1231          }
1232          $delayedmods = '';
1233          while($delayedmod = $db->fetch_array($query))
1234          {
1235              $delayedmod['dateline'] = my_date('normal', $delayedmod['delaydateline'], "", 2);
1236              $delayedmod['username'] = htmlspecialchars_uni($delayedmod['username']);
1237              $delayedmod['profilelink'] = build_profile_link($delayedmod['username'], $delayedmod['uid']);
1238              $delayedmod['action'] = $actions[$delayedmod['type']];
1239              $info = '';
1240              if(strpos($delayedmod['tids'], ',') === false)
1241              {
1242                  $delayed_thread['link'] = get_thread_link($delayedmod['tids']);
1243                  $delayed_thread['subject'] = htmlspecialchars_uni($thread['subject']);
1244                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_thread_single")."\";");
1245              }
1246              else
1247              {
1248                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_thread_multiple")."\";");
1249              }
1250  
1251              if($delayedmod['fname'])
1252              {
1253                  $delayedmod['link'] = get_forum_link($delayedmod['fid']);
1254                  $delayedmod['fname'] = htmlspecialchars_uni($delayedmod['fname']);
1255                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_forum")."\";");
1256              }
1257              $delayedmod['inputs'] = my_unserialize($delayedmod['inputs']);
1258  
1259              if($delayedmod['type'] == 'move')
1260              {
1261                  $delayedmod['link'] = get_forum_link($delayedmod['inputs']['new_forum']);
1262                  $delayedmod['name'] = htmlspecialchars_uni($forum_cache[$delayedmod['inputs']['new_forum']]['name']);
1263                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_new_forum")."\";");
1264  
1265                  if($delayedmod['inputs']['method'] == "redirect")
1266                  {
1267                      if((int)$delayedmod['inputs']['redirect_expire'] == 0)
1268                      {
1269                          $redirect_expire_bit = $lang->redirect_forever;
1270                      }
1271                      else
1272                      {
1273                          $redirect_expire_bit = (int)$delayedmod['inputs']['redirect_expire']." {$lang->days}";
1274                      }
1275  
1276                      eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_redirect")."\";");
1277                  }
1278              }
1279              elseif($delayedmod['type'] == 'merge')
1280              {
1281                  $delayedmod['subject'] = htmlspecialchars_uni($delayedmod['inputs']['subject']);
1282                  $delayedmod['threadurl'] = htmlspecialchars_uni($delayedmod['inputs']['threadurl']);
1283                  eval("\$info .= \"".$templates->get("moderation_delayedmodaction_notes_merge")."\";");
1284              }
1285  
1286              eval("\$delayedmods .= \"".$templates->get("moderation_threadnotes_delayedmodaction")."\";");
1287              $trow = alt_trow();
1288          }
1289          if(!$delayedmods)
1290          {
1291              $cols = 4;
1292              eval("\$delayedmods = \"".$templates->get("moderation_delayedmodaction_error")."\";");
1293          }
1294  
1295          $plugins->run_hooks("moderation_threadnotes");
1296  
1297          eval("\$threadnotes = \"".$templates->get("moderation_threadnotes")."\";");
1298          output_page($threadnotes);
1299          break;
1300  
1301      // Update the thread notes!
1302      case "do_threadnotes":
1303  
1304          // Verify incoming POST request
1305          verify_post_check($mybb->get_input('my_post_key'));
1306  
1307          if(!is_moderator($fid, "canmanagethreads"))
1308          {
1309              error_no_permission();
1310          }
1311  
1312          $plugins->run_hooks("moderation_do_threadnotes");
1313  
1314          log_moderator_action($modlogdata, $lang->thread_notes_edited);
1315          $sqlarray = array(
1316              "notes" => $db->escape_string($mybb->get_input('threadnotes')),
1317          );
1318          $db->update_query("threads", $sqlarray, "tid='$tid'");
1319          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadnotesupdated);
1320          break;
1321  
1322      // Let's look up the ip address of a post
1323      case "getip":
1324          add_breadcrumb($lang->nav_getip);
1325          if(!is_moderator($fid, "canviewips"))
1326          {
1327              error_no_permission();
1328          }
1329  
1330          $post['ipaddress'] = my_inet_ntop($db->unescape_binary($post['ipaddress']));
1331          $hostname = @gethostbyaddr($post['ipaddress']);
1332          if(!$hostname || $hostname == $post['ipaddress'])
1333          {
1334              $hostname = $lang->resolve_fail;
1335          }
1336  
1337          $post['username'] = htmlspecialchars_uni($post['username']);
1338          $username = build_profile_link($post['username'], $post['uid']);
1339  
1340          // Moderator options
1341          $modoptions = "";
1342          if($mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canuseipsearch'] == 1)
1343          {
1344              $ipaddress = $post['ipaddress'];
1345              eval("\$modoptions = \"".$templates->get("moderation_getip_modoptions")."\";");
1346          }
1347  
1348          $plugins->run_hooks('moderation_getip');
1349  
1350          if($modal)
1351          {
1352              eval("\$getip = \"".$templates->get("moderation_getip_modal", 1, 0)."\";");
1353              echo $getip;
1354              exit;
1355          }
1356          else
1357          {
1358              eval("\$getip = \"".$templates->get("moderation_getip")."\";");
1359              output_page($getip);
1360              break;
1361          }
1362  
1363      // Let's look up the ip address of a PM
1364      case "getpmip":
1365          if($pmid <= 0)
1366          {
1367              error($lang->error_invalidpm, $lang->error);
1368          }
1369          add_breadcrumb($lang->nav_pms, "private.php");
1370          $pm['subject'] = htmlspecialchars_uni($parser->parse_badwords($pm['subject']));
1371          add_breadcrumb($pm['subject'], "private.php?action=read&amp;pmid={$pmid}");
1372          add_breadcrumb($lang->nav_getpmip);
1373          if(!$mybb->usergroup['issupermod'])
1374          {
1375              error_no_permission();
1376          }
1377  
1378          $pm['ipaddress'] = my_inet_ntop($db->unescape_binary($pm['ipaddress']));
1379          $hostname = @gethostbyaddr($pm['ipaddress']);
1380          if(!$hostname || $hostname == $pm['ipaddress'])
1381          {
1382              $hostname = $lang->resolve_fail;
1383          }
1384  
1385          $name = $db->fetch_field($db->simple_select('users', 'username', "uid = {$pm['fromid']}"), 'username');
1386          $username = build_profile_link($name, $pm['fromid']);
1387  
1388          // Moderator options
1389          $modoptions = "";
1390          if($mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canuseipsearch'] == 1)
1391          {
1392              $ipaddress = $pm['ipaddress'];
1393              eval("\$modoptions = \"".$templates->get("moderation_getip_modoptions")."\";");
1394          }
1395  
1396          $plugins->run_hooks('moderation_getpmip');
1397  
1398          if($modal)
1399          {
1400              eval("\$getpmip = \"".$templates->get("moderation_getpmip_modal", 1, 0)."\";");
1401              echo $getpmip;
1402              exit;
1403          }
1404          else
1405          {
1406              eval("\$getpmip = \"".$templates->get("moderation_getpmip")."\";");
1407              output_page($getpmip);
1408              break;
1409          }
1410  
1411      // Merge threads
1412      case "merge":
1413          add_breadcrumb($lang->nav_merge);
1414          if(!is_moderator($fid, "canmanagethreads"))
1415          {
1416              error_no_permission();
1417          }
1418  
1419          if($thread['visible'] == -1)
1420          {
1421              error($lang->error_thread_deleted, $lang->error);
1422          }
1423  
1424          $plugins->run_hooks("moderation_merge");
1425  
1426          eval("\$merge = \"".$templates->get("moderation_merge")."\";");
1427          output_page($merge);
1428          break;
1429  
1430      // Let's get those threads together baby! (Merge threads)
1431      case "do_merge":
1432  
1433          // Verify incoming POST request
1434          verify_post_check($mybb->get_input('my_post_key'));
1435  
1436          if(!is_moderator($fid, "canmanagethreads"))
1437          {
1438              error_no_permission();
1439          }
1440  
1441          if($thread['visible'] == -1)
1442          {
1443              error($lang->error_thread_deleted, $lang->error);
1444          }
1445  
1446          $plugins->run_hooks("moderation_do_merge");
1447  
1448          // explode at # sign in a url (indicates a name reference) and reassign to the url
1449          $realurl = explode("#", $mybb->get_input('threadurl'));
1450          $mybb->input['threadurl'] = $realurl[0];
1451  
1452          // Are we using an SEO URL?
1453          if(substr($mybb->input['threadurl'], -4) == "html")
1454          {
1455              // Get thread to merge's tid the SEO way
1456              preg_match("#thread-([0-9]+)?#i", $mybb->input['threadurl'], $threadmatch);
1457              preg_match("#post-([0-9]+)?#i", $mybb->input['threadurl'], $postmatch);
1458  
1459              if($threadmatch[1])
1460              {
1461                  $parameters['tid'] = $threadmatch[1];
1462              }
1463  
1464              if($postmatch[1])
1465              {
1466                  $parameters['pid'] = $postmatch[1];
1467              }
1468          }
1469          else
1470          {
1471              // Get thread to merge's tid the normal way
1472              $splitloc = explode(".php", $mybb->input['threadurl']);
1473              $temp = explode("&", my_substr($splitloc[1], 1));
1474  
1475              if(!empty($temp))
1476              {
1477                  for($i = 0; $i < count($temp); $i++)
1478                  {
1479                      $temp2 = explode("=", $temp[$i], 2);
1480                      $parameters[$temp2[0]] = $temp2[1];
1481                  }
1482              }
1483              else
1484              {
1485                  $temp2 = explode("=", $splitloc[1], 2);
1486                  $parameters[$temp2[0]] = $temp2[1];
1487              }
1488          }
1489  
1490          if(!empty($parameters['pid']) && empty($parameters['tid']))
1491          {
1492              $post = get_post($parameters['pid']);
1493              $mergetid = (int)$post['tid'];
1494          }
1495          elseif(!empty($parameters['tid']))
1496          {
1497              $mergetid = (int)$parameters['tid'];
1498          }
1499          else
1500          {
1501              $mergetid = 0;
1502          }
1503          $mergethread = get_thread($mergetid);
1504          if(!$mergethread)
1505          {
1506              error($lang->error_badmergeurl, $lang->error);
1507          }
1508          if($mergetid == $tid)
1509          { // sanity check
1510              error($lang->error_mergewithself, $lang->error);
1511          }
1512          if(!is_moderator($mergethread['fid'], "canmanagethreads"))
1513          {
1514              error_no_permission();
1515          }
1516          if(isset($mybb->input['subject']))
1517          {
1518              $subject = $mybb->get_input('subject');
1519          }
1520          else
1521          {
1522              $subject = $thread['subject'];
1523          }
1524  
1525          $moderation->merge_threads($mergetid, $tid, $subject);
1526  
1527          log_moderator_action($modlogdata, $lang->thread_merged);
1528  
1529          moderation_redirect(get_thread_link($tid), $lang->redirect_threadsmerged);
1530          break;
1531  
1532      // Divorce the posts in this thread (Split!)
1533      case "split":
1534          add_breadcrumb($lang->nav_split);
1535          if(!is_moderator($fid, "canmanagethreads"))
1536          {
1537              error_no_permission();
1538          }
1539  
1540          if($thread['visible'] == -1)
1541          {
1542              error($lang->error_thread_deleted, $lang->error);
1543          }
1544  
1545          $query = $db->query("
1546              SELECT p.*, u.*
1547              FROM ".TABLE_PREFIX."posts p
1548              LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
1549              WHERE tid='$tid'
1550              ORDER BY dateline ASC, pid ASC
1551          ");
1552  
1553          $numposts = $db->num_rows($query);
1554          if($numposts <= 1)
1555          {
1556              error($lang->error_cantsplitonepost, $lang->error);
1557          }
1558  
1559          $altbg = "trow1";
1560          $posts = '';
1561          while($post = $db->fetch_array($query))
1562          {
1563              $postdate = my_date('relative', $post['dateline']);
1564              $post['username'] = htmlspecialchars_uni($post['username']);
1565  
1566              $parser_options = array(
1567                  "allow_html" => $forum['allowhtml'],
1568                  "allow_mycode" => $forum['allowmycode'],
1569                  "allow_smilies" => $forum['allowsmilies'],
1570                  "allow_imgcode" => $forum['allowimgcode'],
1571                  "allow_videocode" => $forum['allowvideocode'],
1572                  "filter_badwords" => 1
1573              );
1574              if($post['smilieoff'] == 1)
1575              {
1576                  $parser_options['allow_smilies'] = 0;
1577              }
1578  
1579              $message = $parser->parse_message($post['message'], $parser_options);
1580              eval("\$posts .= \"".$templates->get("moderation_split_post")."\";");
1581              $altbg = alt_trow();
1582          }
1583  
1584          clearinline($tid, 'thread');
1585          $forumselect = build_forum_jump("", $fid, 1, '', 0, true, '', "moveto");
1586  
1587          $plugins->run_hooks("moderation_split");
1588  
1589          eval("\$split = \"".$templates->get("moderation_split")."\";");
1590          output_page($split);
1591          break;
1592  
1593      // Let's break them up buddy! (Do the split)
1594      case "do_split":
1595  
1596          // Verify incoming POST request
1597          verify_post_check($mybb->get_input('my_post_key'));
1598  
1599          if(!is_moderator($fid, "canmanagethreads"))
1600          {
1601              error_no_permission();
1602          }
1603  
1604          if($thread['visible'] == -1)
1605          {
1606              error($lang->error_thread_deleted, $lang->error);
1607          }
1608  
1609          $plugins->run_hooks("moderation_do_split");
1610  
1611          $mybb->input['splitpost'] = $mybb->get_input('splitpost', MyBB::INPUT_ARRAY);
1612          if(empty($mybb->input['splitpost']))
1613          {
1614              error($lang->error_nosplitposts, $lang->error);
1615          }
1616          $query = $db->simple_select("posts", "COUNT(*) AS totalposts", "tid='{$tid}'");
1617          $count = $db->fetch_array($query);
1618  
1619          if($count['totalposts'] == 1)
1620          {
1621              error($lang->error_cantsplitonepost, $lang->error);
1622          }
1623  
1624          if($count['totalposts'] == count($mybb->input['splitpost']))
1625          {
1626              error($lang->error_cantsplitall, $lang->error);
1627          }
1628  
1629          if(!empty($mybb->input['moveto']))
1630          {
1631              $moveto = $mybb->get_input('moveto', MyBB::INPUT_INT);
1632          }
1633          else
1634          {
1635              $moveto = $fid;
1636          }
1637  
1638          $newforum = get_forum($moveto);
1639          if(!$newforum || $newforum['type'] != "f" || $newforum['type'] == "f" && $newforum['linkto'] != '')
1640          {
1641              error($lang->error_invalidforum, $lang->error);
1642          }
1643  
1644          $pids = array();
1645  
1646          // move the selected posts over
1647          $query = $db->simple_select("posts", "pid", "tid='$tid'");
1648          while($post = $db->fetch_array($query))
1649          {
1650              if(isset($mybb->input['splitpost'][$post['pid']]) && $mybb->input['splitpost'][$post['pid']] == 1)
1651              {
1652                  $pids[] = $post['pid'];
1653              }
1654              mark_reports($post['pid'], "post");
1655          }
1656  
1657          $newtid = $moderation->split_posts($pids, $tid, $moveto, $mybb->get_input('newsubject'));
1658  
1659          log_moderator_action($modlogdata, $lang->thread_split);
1660  
1661          moderation_redirect(get_thread_link($newtid), $lang->redirect_threadsplit);
1662          break;
1663  
1664      // Delete Thread Subscriptions
1665      case "removesubscriptions":
1666  
1667          // Verify incoming POST request
1668          verify_post_check($mybb->get_input('my_post_key'));
1669  
1670          if(!is_moderator($fid, "canmanagethreads"))
1671          {
1672              error_no_permission();
1673          }
1674  
1675          if($thread['visible'] == -1)
1676          {
1677              error($lang->error_thread_deleted, $lang->error);
1678          }
1679  
1680          $plugins->run_hooks("moderation_removesubscriptions");
1681  
1682          $moderation->remove_thread_subscriptions($tid, true);
1683  
1684          log_moderator_action($modlogdata, $lang->removed_subscriptions);
1685  
1686          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_removed_subscriptions);
1687          break;
1688  
1689      // Delete Threads - Inline moderation
1690      case "multideletethreads":
1691          add_breadcrumb($lang->nav_multi_deletethreads);
1692  
1693          if(!empty($mybb->input['searchid']))
1694          {
1695              // From search page
1696              $threads = getids($mybb->get_input('searchid'), 'search');
1697              if(!is_moderator_by_tids($threads, 'candeletethreads'))
1698              {
1699                  error_no_permission();
1700              }
1701          }
1702          else
1703          {
1704              $threads = getids($fid, 'forum');
1705              if(!is_moderator($fid, 'candeletethreads'))
1706              {
1707                  error_no_permission();
1708              }
1709          }
1710          if(count($threads) < 1)
1711          {
1712              error($lang->error_inline_nothreadsselected, $lang->error);
1713          }
1714  
1715          $inlineids = implode("|", $threads);
1716          if($mybb->get_input('inlinetype') == 'search')
1717          {
1718              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1719          }
1720          else
1721          {
1722              clearinline($fid, 'forum');
1723          }
1724          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
1725          eval("\$multidelete = \"".$templates->get("moderation_inline_deletethreads")."\";");
1726          output_page($multidelete);
1727          break;
1728  
1729      // Actually delete the threads - Inline moderation
1730      case "do_multideletethreads":
1731  
1732          // Verify incoming POST request
1733          verify_post_check($mybb->get_input('my_post_key'));
1734  
1735          $threadlist = explode("|", $mybb->get_input('threads'));
1736          if(!is_moderator_by_tids($threadlist, "candeletethreads"))
1737          {
1738              error_no_permission();
1739          }
1740          foreach($threadlist as $tid)
1741          {
1742              $tid = (int)$tid;
1743              $moderation->delete_thread($tid);
1744              $tlist[] = $tid;
1745          }
1746          log_moderator_action($modlogdata, $lang->multi_deleted_threads);
1747          if($mybb->get_input('inlinetype') == 'search')
1748          {
1749              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1750          }
1751          else
1752          {
1753              clearinline($fid, 'forum');
1754          }
1755          mark_reports($tlist, "threads");
1756          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsdeleted);
1757          break;
1758  
1759      // Open threads - Inline moderation
1760      case "multiopenthreads":
1761  
1762          // Verify incoming POST request
1763          verify_post_check($mybb->get_input('my_post_key'));
1764  
1765          if(!empty($mybb->input['searchid']))
1766          {
1767              // From search page
1768              $threads = getids($mybb->get_input('searchid'), 'search');
1769              if(!is_moderator_by_tids($threads, 'canopenclosethreads'))
1770              {
1771                  error_no_permission();
1772              }
1773          }
1774          else
1775          {
1776              $threads = getids($fid, 'forum');
1777              if(!is_moderator($fid, 'canopenclosethreads'))
1778              {
1779                  error_no_permission();
1780              }
1781          }
1782  
1783          if(count($threads) < 1)
1784          {
1785              error($lang->error_inline_nothreadsselected, $lang->error);
1786          }
1787  
1788          $moderation->open_threads($threads);
1789  
1790          log_moderator_action($modlogdata, $lang->multi_opened_threads);
1791          if($mybb->get_input('inlinetype') == 'search')
1792          {
1793              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1794          }
1795          else
1796          {
1797              clearinline($fid, 'forum');
1798          }
1799          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsopened);
1800          break;
1801  
1802      // Close threads - Inline moderation
1803      case "multiclosethreads":
1804  
1805          // Verify incoming POST request
1806          verify_post_check($mybb->get_input('my_post_key'));
1807  
1808          if(!empty($mybb->input['searchid']))
1809          {
1810              // From search page
1811              $threads = getids($mybb->get_input('searchid'), 'search');
1812              if(!is_moderator_by_tids($threads, 'canopenclosethreads'))
1813              {
1814                  error_no_permission();
1815              }
1816          }
1817          else
1818          {
1819              $threads = getids($fid, 'forum');
1820              if(!is_moderator($fid, 'canopenclosethreads'))
1821              {
1822                  error_no_permission();
1823              }
1824          }
1825          if(count($threads) < 1)
1826          {
1827              error($lang->error_inline_nothreadsselected, $lang->error);
1828          }
1829  
1830          $moderation->close_threads($threads);
1831  
1832          log_moderator_action($modlogdata, $lang->multi_closed_threads);
1833          if($mybb->get_input('inlinetype') == 'search')
1834          {
1835              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1836          }
1837          else
1838          {
1839              clearinline($fid, 'forum');
1840          }
1841          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsclosed);
1842          break;
1843  
1844      // Approve threads - Inline moderation
1845      case "multiapprovethreads":
1846  
1847          // Verify incoming POST request
1848          verify_post_check($mybb->get_input('my_post_key'));
1849  
1850          if(!empty($mybb->input['searchid']))
1851          {
1852              // From search page
1853              $threads = getids($mybb->get_input('searchid'), 'search');
1854              if(!is_moderator_by_tids($threads, 'canapproveunapprovethreads'))
1855              {
1856                  error_no_permission();
1857              }
1858          }
1859          else
1860          {
1861              $threads = getids($fid, 'forum');
1862              if(!is_moderator($fid, 'canapproveunapprovethreads'))
1863              {
1864                  error_no_permission();
1865              }
1866          }
1867          if(count($threads) < 1)
1868          {
1869              error($lang->error_inline_nothreadsselected, $lang->error);
1870          }
1871  
1872          $moderation->approve_threads($threads, $fid);
1873  
1874          log_moderator_action($modlogdata, $lang->multi_approved_threads);
1875          if($mybb->get_input('inlinetype') == 'search')
1876          {
1877              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1878          }
1879          else
1880          {
1881              clearinline($fid, 'forum');
1882          }
1883          $cache->update_stats();
1884          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsapproved);
1885          break;
1886  
1887      // Unapprove threads - Inline moderation
1888      case "multiunapprovethreads":
1889  
1890          // Verify incoming POST request
1891          verify_post_check($mybb->get_input('my_post_key'));
1892  
1893          if(!empty($mybb->input['searchid']))
1894          {
1895              // From search page
1896              $threads = getids($mybb->get_input('searchid'), 'search');
1897              if(!is_moderator_by_tids($threads, 'canapproveunapprovethreads'))
1898              {
1899                  error_no_permission();
1900              }
1901          }
1902          else
1903          {
1904              $threads = getids($fid, 'forum');
1905              if(!is_moderator($fid, 'canapproveunapprovethreads'))
1906              {
1907                  error_no_permission();
1908              }
1909          }
1910          if(count($threads) < 1)
1911          {
1912              error($lang->error_inline_nothreadsselected, $lang->error);
1913          }
1914  
1915          $moderation->unapprove_threads($threads, $fid);
1916  
1917          log_moderator_action($modlogdata, $lang->multi_unapproved_threads);
1918          if($mybb->get_input('inlinetype') == 'search')
1919          {
1920              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1921          }
1922          else
1923          {
1924              clearinline($fid, 'forum');
1925          }
1926          $cache->update_stats();
1927          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsunapproved);
1928          break;
1929  
1930      // Restore threads - Inline moderation
1931      case "multirestorethreads":
1932  
1933          // Verify incoming POST request
1934          verify_post_check($mybb->get_input('my_post_key'));
1935  
1936          if(!empty($mybb->input['searchid']))
1937          {
1938              // From search page
1939              $threads = getids($mybb->get_input('searchid'), 'search');
1940              if(!is_moderator_by_tids($threads, 'canrestorethreads'))
1941              {
1942                  error_no_permission();
1943              }
1944          }
1945          else
1946          {
1947              $threads = getids($fid, 'forum');
1948              if(!is_moderator($fid, 'canrestorethreads'))
1949              {
1950                  error_no_permission();
1951              }
1952          }
1953          if(count($threads) < 1)
1954          {
1955              error($lang->error_inline_nothreadsselected, $lang->error);
1956          }
1957  
1958          $moderation->restore_threads($threads);
1959  
1960          log_moderator_action($modlogdata, $lang->multi_restored_threads);
1961          if($mybb->get_input('inlinetype') == 'search')
1962          {
1963              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
1964          }
1965          else
1966          {
1967              clearinline($fid, 'forum');
1968          }
1969          $cache->update_stats();
1970          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsrestored);
1971          break;
1972  
1973      // Soft delete threads - Inline moderation
1974      case "multisoftdeletethreads":
1975  
1976          // Verify incoming POST request
1977          verify_post_check($mybb->get_input('my_post_key'));
1978  
1979          if(!empty($mybb->input['searchid']))
1980          {
1981              // From search page
1982              $threads = getids($mybb->get_input('searchid'), 'search');
1983              if(!is_moderator_by_tids($threads, 'cansoftdeletethreads'))
1984              {
1985                  error_no_permission();
1986              }
1987          }
1988          else
1989          {
1990              $threads = getids($fid, 'forum');
1991              if(!is_moderator($fid, 'cansoftdeletethreads'))
1992              {
1993                  error_no_permission();
1994              }
1995          }
1996          if(count($threads) < 1)
1997          {
1998              error($lang->error_inline_nothreadsselected, $lang->error);
1999          }
2000  
2001          $moderation->soft_delete_threads($threads);
2002  
2003          log_moderator_action($modlogdata, $lang->multi_soft_deleted_threads);
2004          if($mybb->get_input('inlinetype') == 'search')
2005          {
2006              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2007          }
2008          else
2009          {
2010              clearinline($fid, 'forum');
2011          }
2012          $cache->update_stats();
2013          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadssoftdeleted);
2014          break;
2015  
2016      // Stick threads - Inline moderation
2017      case "multistickthreads":
2018  
2019          // Verify incoming POST request
2020          verify_post_check($mybb->get_input('my_post_key'));
2021  
2022          if(!empty($mybb->input['searchid']))
2023          {
2024              // From search page
2025              $threads = getids($mybb->get_input('searchid'), 'search');
2026              if(!is_moderator_by_tids($threads, 'canstickunstickthreads'))
2027              {
2028                  error_no_permission();
2029              }
2030          }
2031          else
2032          {
2033              $threads = getids($fid, 'forum');
2034              if(!is_moderator($fid, 'canstickunstickthreads'))
2035              {
2036                  error_no_permission();
2037              }
2038          }
2039          if(count($threads) < 1)
2040          {
2041              error($lang->error_inline_nothreadsselected, $lang->error);
2042          }
2043  
2044          $moderation->stick_threads($threads);
2045  
2046          log_moderator_action($modlogdata, $lang->multi_stuck_threads);
2047          if($mybb->get_input('inlinetype') == 'search')
2048          {
2049              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2050          }
2051          else
2052          {
2053              clearinline($fid, 'forum');
2054          }
2055          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsstuck);
2056          break;
2057  
2058      // Unstick threads - Inline moderaton
2059      case "multiunstickthreads":
2060  
2061          // Verify incoming POST request
2062          verify_post_check($mybb->get_input('my_post_key'));
2063  
2064          if(!empty($mybb->input['searchid']))
2065          {
2066              // From search page
2067              $threads = getids($mybb->get_input('searchid'), 'search');
2068              if(!is_moderator_by_tids($threads, 'canstickunstickthreads'))
2069              {
2070                  error_no_permission();
2071              }
2072          }
2073          else
2074          {
2075              $threads = getids($fid, 'forum');
2076              if(!is_moderator($fid, 'canstickunstickthreads'))
2077              {
2078                  error_no_permission();
2079              }
2080          }
2081          if(count($threads) < 1)
2082          {
2083              error($lang->error_inline_nothreadsselected, $lang->error);
2084          }
2085  
2086          $moderation->unstick_threads($threads);
2087  
2088          log_moderator_action($modlogdata, $lang->multi_unstuck_threads);
2089          if($mybb->get_input('inlinetype') == 'search')
2090          {
2091              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2092          }
2093          else
2094          {
2095              clearinline($fid, 'forum');
2096          }
2097          moderation_redirect(get_forum_link($fid), $lang->redirect_inline_threadsunstuck);
2098          break;
2099  
2100      // Move threads - Inline moderation
2101      case "multimovethreads":
2102          add_breadcrumb($lang->nav_multi_movethreads);
2103  
2104          if(!empty($mybb->input['searchid']))
2105          {
2106              // From search page
2107              $threads = getids($mybb->get_input('searchid'), 'search');
2108              if(!is_moderator_by_tids($threads, 'canmanagethreads'))
2109              {
2110                  error_no_permission();
2111              }
2112          }
2113          else
2114          {
2115              $threads = getids($fid, 'forum');
2116              if(!is_moderator($fid, 'canmanagethreads'))
2117              {
2118                  error_no_permission();
2119              }
2120          }
2121  
2122          if(count($threads) < 1)
2123          {
2124              error($lang->error_inline_nothreadsselected, $lang->error);
2125          }
2126          $inlineids = implode("|", $threads);
2127          if($mybb->get_input('inlinetype') == 'search')
2128          {
2129              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2130          }
2131          else
2132          {
2133              clearinline($fid, 'forum');
2134          }
2135          $forumselect = build_forum_jump("", '', 1, '', 0, true, '', "moveto");
2136          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
2137          eval("\$movethread = \"".$templates->get("moderation_inline_movethreads")."\";");
2138          output_page($movethread);
2139          break;
2140  
2141      // Actually move the threads in Inline moderation
2142      case "do_multimovethreads":
2143  
2144          // Verify incoming POST request
2145          verify_post_check($mybb->get_input('my_post_key'));
2146  
2147          $moveto = $mybb->get_input('moveto', MyBB::INPUT_INT);
2148          $method = $mybb->get_input('method');
2149  
2150          $threadlist = explode("|", $mybb->get_input('threads'));
2151          if(!is_moderator_by_tids($threadlist, 'canmanagethreads'))
2152          {
2153              error_no_permission();
2154          }
2155          foreach($threadlist as $tid)
2156          {
2157              $tids[] = (int)$tid;
2158          }
2159          // Make sure moderator has permission to move to the new forum
2160          $newperms = forum_permissions($moveto);
2161          if(($newperms['canview'] == 0 || !is_moderator($moveto, 'canmanagethreads')) && !is_moderator_by_tids($tids, 'canmovetononmodforum'))
2162          {
2163              error($lang->error_movetononmodforum, $lang->error);
2164          }
2165  
2166          $newforum = get_forum($moveto);
2167          if(!$newforum || $newforum['type'] != "f" || $newforum['type'] == "f" && $newforum['linkto'] != '')
2168          {
2169              error($lang->error_invalidforum, $lang->error);
2170          }
2171  
2172          $plugins->run_hooks('moderation_do_multimovethreads');
2173  
2174          log_moderator_action($modlogdata, $lang->multi_moved_threads);
2175          $expire = 0;
2176          if($mybb->get_input('redirect_expire', MyBB::INPUT_INT) > 0)
2177          {
2178              $expire = TIME_NOW + ($mybb->get_input('redirect_expire', MyBB::INPUT_INT) * 86400);
2179          }
2180  
2181          foreach($tids as $tid) {
2182              $moderation->move_thread($tid, $moveto, $method, $expire);
2183          }
2184  
2185          moderation_redirect(get_forum_link($moveto), $lang->redirect_inline_threadsmoved);
2186          break;
2187  
2188      // Delete posts - Inline moderation
2189      case "multideleteposts":
2190          add_breadcrumb($lang->nav_multi_deleteposts);
2191  
2192          if($mybb->get_input('inlinetype') == 'search')
2193          {
2194              $posts = getids($mybb->get_input('searchid'), 'search');
2195          }
2196          else
2197          {
2198              $posts = getids($tid, 'thread');
2199          }
2200  
2201          if(count($posts) < 1)
2202          {
2203              error($lang->error_inline_nopostsselected, $lang->error);
2204          }
2205          if(!is_moderator_by_pids($posts, "candeleteposts"))
2206          {
2207              error_no_permission();
2208          }
2209          $inlineids = implode("|", $posts);
2210          if($mybb->get_input('inlinetype') == 'search')
2211          {
2212              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2213          }
2214          else
2215          {
2216              clearinline($tid, 'thread');
2217          }
2218  
2219          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
2220  
2221          eval("\$multidelete = \"".$templates->get("moderation_inline_deleteposts")."\";");
2222          output_page($multidelete);
2223          break;
2224  
2225      // Actually delete the posts in inline moderation
2226      case "do_multideleteposts":
2227  
2228          // Verify incoming POST request
2229          verify_post_check($mybb->get_input('my_post_key'));
2230  
2231          $postlist = explode("|", $mybb->get_input('posts'));
2232          if(!is_moderator_by_pids($postlist, "candeleteposts"))
2233          {
2234              error_no_permission();
2235          }
2236          $postlist = array_map('intval', $postlist);
2237          $pids = implode(',', $postlist);
2238  
2239          $tids = array();
2240          if($pids)
2241          {
2242              $query = $db->simple_select("threads", "tid", "firstpost IN({$pids})");
2243              while($threadid = $db->fetch_field($query, "tid"))
2244              {
2245                  $tids[] = $threadid;
2246              }
2247          }
2248  
2249          $deletecount = 0;
2250          foreach($postlist as $pid)
2251          {
2252              $pid = (int)$pid;
2253              $moderation->delete_post($pid);
2254              $plist[] = $pid;
2255              $deletecount++;
2256          }
2257  
2258          // If we have multiple threads, we must be coming from the search
2259          if(!empty($tids))
2260          {
2261              foreach($tids as $tid)
2262              {
2263                  $moderation->delete_thread($tid);
2264                  mark_reports($tid, "thread");
2265                  $url = get_forum_link($fid);
2266              }
2267          }
2268          // Otherwise we're just deleting from showthread.php
2269          else
2270          {
2271              $query = $db->simple_select("posts", "pid", "tid = $tid");
2272              $numposts = $db->num_rows($query);
2273              if(!$numposts)
2274              {
2275                  $moderation->delete_thread($tid);
2276                  mark_reports($tid, "thread");
2277                  $url = get_forum_link($fid);
2278              }
2279              else
2280              {
2281                  mark_reports($plist, "posts");
2282                  $url = get_thread_link($thread['tid']);
2283              }
2284          }
2285  
2286          $lang->deleted_selective_posts = $lang->sprintf($lang->deleted_selective_posts, $deletecount);
2287          log_moderator_action($modlogdata, $lang->deleted_selective_posts);
2288          moderation_redirect($url, $lang->redirect_postsdeleted);
2289          break;
2290  
2291      // Merge posts - Inline moderation
2292      case "multimergeposts":
2293          add_breadcrumb($lang->nav_multi_mergeposts);
2294  
2295          if($mybb->get_input('inlinetype') == 'search')
2296          {
2297              $posts = getids($mybb->get_input('searchid'), 'search');
2298          }
2299          else
2300          {
2301              $posts = getids($tid, 'thread');
2302          }
2303  
2304          // Add the selected posts from other threads
2305          foreach($mybb->cookies as $key => $value)
2306          {
2307              if(strpos($key, "inlinemod_thread") !== false && $key != "inlinemod_thread$tid")
2308              {
2309                  $inlinepostlist = explode("|", $mybb->cookies[$key]);
2310                  foreach($inlinepostlist as $p)
2311                  {
2312                      $p = (int)$p;
2313  
2314                      if(!empty($p))
2315                      {
2316                          $posts[] = (int)$p;
2317                      }
2318                  }
2319                  // Remove the cookie once its data is retrieved
2320                  my_unsetcookie($key);
2321              }
2322          }
2323  
2324          if(count($posts) < 2)
2325          {
2326              if(empty($posts))
2327              {
2328                  error($lang->error_inline_nopostsselected, $lang->error);
2329              }            
2330              error($lang->error_nomergeposts, $lang->error);
2331          }
2332  
2333          if(!is_moderator_by_pids($posts, "canmanagethreads"))
2334          {
2335              error_no_permission();
2336          }
2337  
2338          $postlist = "";
2339          $query = $db->query("
2340              SELECT p.*, u.*
2341              FROM ".TABLE_PREFIX."posts p
2342              LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
2343              WHERE pid IN (".implode(",", $posts).")
2344              ORDER BY dateline ASC, pid ASC
2345          ");
2346          $altbg = "trow1";
2347          while($post = $db->fetch_array($query))
2348          {
2349              $postdate = my_date('relative', $post['dateline']);
2350  
2351              $parser_options = array(
2352                  "allow_html" => $forum['allowhtml'],
2353                  "allow_mycode" => $forum['allowmycode'],
2354                  "allow_smilies" => $forum['allowsmilies'],
2355                  "allow_imgcode" => $forum['allowimgcode'],
2356                  "allow_videocode" => $forum['allowvideocode'],
2357                  "filter_badwords" => 1
2358              );
2359              if($post['smilieoff'] == 1)
2360              {
2361                  $parser_options['allow_smilies'] = 0;
2362              }
2363  
2364              $message = $parser->parse_message($post['message'], $parser_options);
2365              eval("\$postlist .= \"".$templates->get("moderation_mergeposts_post")."\";");
2366              $altbg = alt_trow();
2367          }
2368  
2369          $inlineids = implode("|", $posts);
2370          if($mybb->get_input('inlinetype') == 'search')
2371          {
2372              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2373          }
2374          else
2375          {
2376              clearinline($tid, 'thread');
2377          }
2378  
2379          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
2380  
2381          eval("\$multimerge = \"".$templates->get("moderation_inline_mergeposts")."\";");
2382          output_page($multimerge);
2383          break;
2384  
2385      // Actually merge the posts - Inline moderation
2386      case "do_multimergeposts":
2387  
2388          // Verify incoming POST request
2389          verify_post_check($mybb->get_input('my_post_key'));
2390  
2391          $mergepost = $mybb->get_input('mergepost', MyBB::INPUT_ARRAY);
2392          if(count($mergepost) < 2)
2393          {
2394              error($lang->error_nomergeposts, $lang->error);
2395          }
2396  
2397          foreach($mergepost as $pid => $yes)
2398          {
2399              $postlist[] = (int)$pid;
2400          }
2401  
2402          if(!is_moderator_by_pids($postlist, "canmanagethreads"))
2403          {
2404              error_no_permission();
2405          }
2406  
2407          $masterpid = $moderation->merge_posts($postlist, $tid, $mybb->input['sep']);
2408  
2409          mark_reports($postlist, "posts");
2410          log_moderator_action($modlogdata, $lang->merged_selective_posts);
2411          moderation_redirect(get_post_link($masterpid)."#pid$masterpid", $lang->redirect_inline_postsmerged);
2412          break;
2413  
2414      // Split posts - Inline moderation
2415      case "multisplitposts":
2416          add_breadcrumb($lang->nav_multi_splitposts);
2417  
2418          if($mybb->get_input('inlinetype') == 'search')
2419          {
2420              $posts = getids($mybb->get_input('searchid'), 'search');
2421          }
2422          else
2423          {
2424              $posts = getids($tid, 'thread');
2425          }
2426  
2427          if(count($posts) < 1)
2428          {
2429              error($lang->error_inline_nopostsselected, $lang->error);
2430          }
2431  
2432          if(!is_moderator_by_pids($posts, "canmanagethreads"))
2433          {
2434              error_no_permission();
2435          }
2436          $posts = array_map('intval', $posts);
2437          $pidin = implode(',', $posts);
2438  
2439          // Make sure that we are not splitting a thread with one post
2440          // Select number of posts in each thread that the splitted post is in
2441          $query = $db->query("
2442              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2443              FROM ".TABLE_PREFIX."posts p
2444              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2445              WHERE p.pid IN ($pidin)
2446              GROUP BY p.tid, p.pid
2447          ");
2448          $threads = $pcheck = array();
2449          while($tcheck = $db->fetch_array($query))
2450          {
2451              if((int)$tcheck['count'] <= 1)
2452              {
2453                  error($lang->error_cantsplitonepost, $lang->error);
2454              }
2455              $threads[] = $pcheck[] = $tcheck['tid']; // Save tids for below
2456          }
2457  
2458          // Make sure that we are not splitting all posts in the thread
2459          // The query does not return a row when the count is 0, so find if some threads are missing (i.e. 0 posts after removal)
2460          $query = $db->query("
2461              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2462              FROM ".TABLE_PREFIX."posts p
2463              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2464              WHERE p.pid IN ($pidin) AND q.pid NOT IN ($pidin)
2465              GROUP BY p.tid, p.pid
2466          ");
2467          $pcheck2 = array();
2468          while($tcheck = $db->fetch_array($query))
2469          {
2470              if($tcheck['count'] > 0)
2471              {
2472                  $pcheck2[] = $tcheck['tid'];
2473              }
2474          }
2475          if(count($pcheck2) != count($pcheck))
2476          {
2477              // One or more threads do not have posts after splitting
2478              error($lang->error_cantsplitall, $lang->error);
2479          }
2480  
2481          $inlineids = implode("|", $posts);
2482          if($mybb->get_input('inlinetype') == 'search')
2483          {
2484              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2485          }
2486          else
2487          {
2488              clearinline($tid, 'thread');
2489          }
2490          $forumselect = build_forum_jump("", $fid, 1, '', 0, true, '', "moveto");
2491  
2492          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
2493  
2494          eval("\$splitposts = \"".$templates->get("moderation_inline_splitposts")."\";");
2495          output_page($splitposts);
2496          break;
2497  
2498      // Actually split the posts - Inline moderation
2499      case "do_multisplitposts":
2500  
2501          // Verify incoming POST request
2502          verify_post_check($mybb->get_input('my_post_key'));
2503  
2504          $plist = array();
2505          $postlist = explode("|", $mybb->get_input('posts'));
2506          foreach($postlist as $pid)
2507          {
2508              $pid = (int)$pid;
2509              $plist[] = $pid;
2510          }
2511  
2512          if(!is_moderator_by_pids($plist, "canmanagethreads"))
2513          {
2514              error_no_permission();
2515          }
2516  
2517          // Ensure all posts exist
2518          $posts = array();
2519          if(!empty($plist))
2520          {
2521              $query = $db->simple_select('posts', 'pid', 'pid IN ('.implode(',', $plist).')');
2522              while($pid = $db->fetch_field($query, 'pid'))
2523              {
2524                  $posts[] = $pid;
2525              }
2526          }
2527  
2528          if(empty($posts))
2529          {
2530              error($lang->error_inline_nopostsselected, $lang->error);
2531          }
2532  
2533          $pidin = implode(',', $posts);
2534  
2535          // Make sure that we are not splitting a thread with one post
2536          // Select number of posts in each thread that the splitted post is in
2537          $query = $db->query("
2538              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2539              FROM ".TABLE_PREFIX."posts p
2540              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2541              WHERE p.pid IN ($pidin)
2542              GROUP BY p.tid, p.pid
2543          ");
2544          $pcheck = array();
2545          while($tcheck = $db->fetch_array($query))
2546          {
2547              if((int)$tcheck['count'] <= 1)
2548              {
2549                  error($lang->error_cantsplitonepost, $lang->error);
2550              }
2551              $pcheck[] = $tcheck['tid']; // Save tids for below
2552          }
2553  
2554          // Make sure that we are not splitting all posts in the thread
2555          // The query does not return a row when the count is 0, so find if some threads are missing (i.e. 0 posts after removal)
2556          $query = $db->query("
2557              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2558              FROM ".TABLE_PREFIX."posts p
2559              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2560              WHERE p.pid IN ($pidin) AND q.pid NOT IN ($pidin)
2561              GROUP BY p.tid, p.pid
2562          ");
2563          $pcheck2 = array();
2564          while($tcheck = $db->fetch_array($query))
2565          {
2566              if($tcheck['count'] > 0)
2567              {
2568                  $pcheck2[] = $tcheck['tid'];
2569              }
2570          }
2571          if(count($pcheck2) != count($pcheck))
2572          {
2573              // One or more threads do not have posts after splitting
2574              error($lang->error_cantsplitall, $lang->error);
2575          }
2576  
2577          if(isset($mybb->input['moveto']))
2578          {
2579              $moveto = $mybb->get_input('moveto', MyBB::INPUT_INT);
2580          }
2581          else
2582          {
2583              $moveto = $fid;
2584          }
2585  
2586          $newforum = get_forum($moveto);
2587          if(!$newforum || $newforum['type'] != "f" || $newforum['type'] == "f" && $newforum['linkto'] != '')
2588          {
2589              error($lang->error_invalidforum, $lang->error);
2590          }
2591  
2592          $newsubject = $mybb->get_input('newsubject');
2593          $newtid = $moderation->split_posts($posts, $tid, $moveto, $newsubject);
2594  
2595          $pid_list = implode(', ', $posts);
2596          $lang->split_selective_posts = $lang->sprintf($lang->split_selective_posts, $pid_list, $newtid);
2597          log_moderator_action($modlogdata, $lang->split_selective_posts);
2598  
2599          moderation_redirect(get_thread_link($newtid), $lang->redirect_threadsplit);
2600          break;
2601  
2602      // Move posts - Inline moderation
2603      case "multimoveposts":
2604          add_breadcrumb($lang->nav_multi_moveposts);
2605  
2606          if($mybb->get_input('inlinetype') == 'search')
2607          {
2608              $posts = getids($mybb->get_input('searchid'), 'search');
2609          }
2610          else
2611          {
2612              $posts = getids($tid, 'thread');
2613          }
2614  
2615          if(count($posts) < 1)
2616          {
2617              error($lang->error_inline_nopostsselected, $lang->error);
2618          }
2619  
2620          if(!is_moderator_by_pids($posts, "canmanagethreads"))
2621          {
2622              error_no_permission();
2623          }
2624          $posts = array_map('intval', $posts);
2625          $pidin = implode(',', $posts);
2626  
2627          // Make sure that we are not moving posts in a thread with one post
2628          // Select number of posts in each thread that the moved post is in
2629          $query = $db->query("
2630              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2631              FROM ".TABLE_PREFIX."posts p
2632              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2633              WHERE p.pid IN ($pidin)
2634              GROUP BY p.tid, p.pid
2635          ");
2636          $threads = $pcheck = array();
2637          while($tcheck = $db->fetch_array($query))
2638          {
2639              if((int)$tcheck['count'] <= 1)
2640              {
2641                  error($lang->error_cantsplitonepost, $lang->error);
2642              }
2643              $threads[] = $pcheck[] = $tcheck['tid']; // Save tids for below
2644          }
2645  
2646          // Make sure that we are not moving all posts in the thread
2647          // The query does not return a row when the count is 0, so find if some threads are missing (i.e. 0 posts after removal)
2648          $query = $db->query("
2649              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2650              FROM ".TABLE_PREFIX."posts p
2651              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2652              WHERE p.pid IN ($pidin) AND q.pid NOT IN ($pidin)
2653              GROUP BY p.tid, p.pid
2654          ");
2655          $pcheck2 = array();
2656          while($tcheck = $db->fetch_array($query))
2657          {
2658              if($tcheck['count'] > 0)
2659              {
2660                  $pcheck2[] = $tcheck['tid'];
2661              }
2662          }
2663          if(count($pcheck2) != count($pcheck))
2664          {
2665              // One or more threads do not have posts after splitting
2666              error($lang->error_cantmoveall, $lang->error);
2667          }
2668  
2669          $inlineids = implode("|", $posts);
2670          if($mybb->get_input('inlinetype') == 'search')
2671          {
2672              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2673          }
2674          else
2675          {
2676              clearinline($tid, 'thread');
2677          }
2678          $forumselect = build_forum_jump("", $fid, 1, '', 0, true, '', "moveto");
2679  
2680          $return_url = htmlspecialchars_uni($mybb->get_input('url'));
2681  
2682          eval("\$moveposts = \"".$templates->get("moderation_inline_moveposts")."\";");
2683          output_page($moveposts);
2684          break;
2685  
2686      // Actually split the posts - Inline moderation
2687      case "do_multimoveposts":
2688  
2689          // Verify incoming POST request
2690          verify_post_check($mybb->get_input('my_post_key'));
2691  
2692          $plugins->run_hooks("moderation_do_multimoveposts");
2693  
2694          // explode at # sign in a url (indicates a name reference) and reassign to the url
2695          $realurl = explode("#", $mybb->get_input('threadurl'));
2696          $mybb->input['threadurl'] = $realurl[0];
2697  
2698          // Are we using an SEO URL?
2699          if(substr($mybb->input['threadurl'], -4) == "html")
2700          {
2701              // Get thread to merge's tid the SEO way
2702              preg_match("#thread-([0-9]+)?#i", $mybb->input['threadurl'], $threadmatch);
2703              preg_match("#post-([0-9]+)?#i", $mybb->input['threadurl'], $postmatch);
2704  
2705              if(!empty($threadmatch[1]))
2706              {
2707                  $parameters['tid'] = $threadmatch[1];
2708              }
2709  
2710              if(!empty($postmatch[1]))
2711              {
2712                  $parameters['pid'] = $postmatch[1];
2713              }
2714          }
2715          else
2716          {
2717              // Get thread to merge's tid the normal way
2718              $splitloc = explode(".php", $mybb->input['threadurl']);
2719              $temp = explode("&", my_substr($splitloc[1], 1));
2720  
2721              if(!empty($temp))
2722              {
2723                  for($i = 0; $i < count($temp); $i++)
2724                  {
2725                      $temp2 = explode("=", $temp[$i], 2);
2726                      $parameters[$temp2[0]] = $temp2[1];
2727                  }
2728              }
2729              else
2730              {
2731                  $temp2 = explode("=", $splitloc[1], 2);
2732                  $parameters[$temp2[0]] = $temp2[1];
2733              }
2734          }
2735  
2736          if(!empty($parameters['pid']) && empty($parameters['tid']))
2737          {
2738              $query = $db->simple_select("posts", "tid", "pid='".(int)$parameters['pid']."'");
2739              $post = $db->fetch_array($query);
2740              $newtid = $post['tid'];
2741          }
2742          elseif(!empty($parameters['tid']))
2743          {
2744              $newtid = $parameters['tid'];
2745          }
2746          else
2747          {
2748              $newtid = 0;
2749          }
2750          $newtid = (int)$newtid;
2751          $newthread = get_thread($newtid);
2752          if(!$newthread)
2753          {
2754              error($lang->error_badmovepostsurl, $lang->error);
2755          }
2756          if($newtid == $tid)
2757          { // sanity check
2758              error($lang->error_movetoself, $lang->error);
2759          }
2760  
2761          $postlist = explode("|", $mybb->get_input('posts'));
2762          $plist = array();
2763          foreach($postlist as $pid)
2764          {
2765              $pid = (int)$pid;
2766              $plist[] = $pid;
2767          }
2768  
2769          if(!is_moderator_by_pids($plist, "canmanagethreads"))
2770          {
2771              error_no_permission();
2772          }
2773  
2774          // Ensure all posts exist
2775          $posts = array();
2776          if(!empty($plist))
2777          {
2778              $query = $db->simple_select('posts', 'pid', 'pid IN ('.implode(',', $plist).')');
2779              while($pid = $db->fetch_field($query, 'pid'))
2780              {
2781                  $posts[] = $pid;
2782              }
2783          }
2784  
2785          if(empty($posts))
2786          {
2787              error($lang->error_inline_nopostsselected, $lang->error);
2788          }
2789  
2790          $pidin = implode(',', $posts);
2791  
2792          // Make sure that we are not moving posts in a thread with one post
2793          // Select number of posts in each thread that the moved post is in
2794          $query = $db->query("
2795              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2796              FROM ".TABLE_PREFIX."posts p
2797              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2798              WHERE p.pid IN ($pidin)
2799              GROUP BY p.tid, p.pid
2800          ");
2801          $threads = $pcheck = array();
2802          while($tcheck = $db->fetch_array($query))
2803          {
2804              if((int)$tcheck['count'] <= 1)
2805              {
2806                  error($lang->error_cantsplitonepost, $lang->error);
2807              }
2808              $threads[] = $pcheck[] = $tcheck['tid']; // Save tids for below
2809          }
2810  
2811          // Make sure that we are not moving all posts in the thread
2812          // The query does not return a row when the count is 0, so find if some threads are missing (i.e. 0 posts after removal)
2813          $query = $db->query("
2814              SELECT DISTINCT p.tid, COUNT(q.pid) as count
2815              FROM ".TABLE_PREFIX."posts p
2816              LEFT JOIN ".TABLE_PREFIX."posts q ON (p.tid=q.tid)
2817              WHERE p.pid IN ($pidin) AND q.pid NOT IN ($pidin)
2818              GROUP BY p.tid, p.pid
2819          ");
2820          $pcheck2 = array();
2821          while($tcheck = $db->fetch_array($query))
2822          {
2823              if($tcheck['count'] > 0)
2824              {
2825                  $pcheck2[] = $tcheck['tid'];
2826              }
2827          }
2828          if(count($pcheck2) != count($pcheck))
2829          {
2830              // One or more threads do not have posts after splitting
2831              error($lang->error_cantmoveall, $lang->error);
2832          }
2833  
2834          $newtid = $moderation->split_posts($posts, $tid, $newthread['fid'], $db->escape_string($newthread['subject']), $newtid);
2835  
2836          $pid_list = implode(', ', $posts);
2837          $lang->move_selective_posts = $lang->sprintf($lang->move_selective_posts, $pid_list, $newtid);
2838          log_moderator_action($modlogdata, $lang->move_selective_posts);
2839  
2840          moderation_redirect(get_thread_link($newtid), $lang->redirect_moveposts);
2841          break;
2842  
2843      // Approve posts - Inline moderation
2844      case "multiapproveposts":
2845  
2846          // Verify incoming POST request
2847          verify_post_check($mybb->get_input('my_post_key'));
2848  
2849          if($mybb->get_input('inlinetype') == 'search')
2850          {
2851              $posts = getids($mybb->get_input('searchid'), 'search');
2852          }
2853          else
2854          {
2855              $posts = getids($tid, 'thread');
2856          }
2857          if(count($posts) < 1)
2858          {
2859              error($lang->error_inline_nopostsselected, $lang->error);
2860          }
2861  
2862          if(!is_moderator_by_pids($posts, "canapproveunapproveposts"))
2863          {
2864              error_no_permission();
2865          }
2866  
2867          $pids = array();
2868          foreach($posts as $pid)
2869          {
2870              $pids[] = (int)$pid;
2871          }
2872  
2873          $moderation->approve_posts($pids);
2874  
2875          log_moderator_action($modlogdata, $lang->multi_approve_posts);
2876          if($mybb->get_input('inlinetype') == 'search')
2877          {
2878              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2879          }
2880          else
2881          {
2882              clearinline($tid, 'thread');
2883          }
2884          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_inline_postsapproved);
2885          break;
2886  
2887      // Unapprove posts - Inline moderation
2888      case "multiunapproveposts":
2889  
2890          // Verify incoming POST request
2891          verify_post_check($mybb->get_input('my_post_key'));
2892  
2893          if($mybb->get_input('inlinetype') == 'search')
2894          {
2895              $posts = getids($mybb->get_input('searchid'), 'search');
2896          }
2897          else
2898          {
2899              $posts = getids($tid, 'thread');
2900          }
2901  
2902          if(count($posts) < 1)
2903          {
2904              error($lang->error_inline_nopostsselected, $lang->error);
2905          }
2906          $pids = array();
2907  
2908          if(!is_moderator_by_pids($posts, "canapproveunapproveposts"))
2909          {
2910              error_no_permission();
2911          }
2912          foreach($posts as $pid)
2913          {
2914              $pids[] = (int)$pid;
2915          }
2916  
2917          $moderation->unapprove_posts($pids);
2918  
2919          log_moderator_action($modlogdata, $lang->multi_unapprove_posts);
2920          if($mybb->get_input('inlinetype') == 'search')
2921          {
2922              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2923          }
2924          else
2925          {
2926              clearinline($tid, 'thread');
2927          }
2928          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_inline_postsunapproved);
2929          break;
2930  
2931      // Restore posts - Inline moderation
2932      case "multirestoreposts":
2933  
2934          // Verify incoming POST request
2935          verify_post_check($mybb->get_input('my_post_key'));
2936  
2937          if($mybb->get_input('inlinetype') == 'search')
2938          {
2939              $posts = getids($mybb->get_input('searchid'), 'search');
2940          }
2941          else
2942          {
2943              $posts = getids($tid, 'thread');
2944          }
2945          if(count($posts) < 1)
2946          {
2947              error($lang->error_inline_nopostsselected, $lang->error);
2948          }
2949  
2950          if(!is_moderator_by_pids($posts, "canrestoreposts"))
2951          {
2952              error_no_permission();
2953          }
2954  
2955          $pids = array();
2956          foreach($posts as $pid)
2957          {
2958              $pids[] = (int)$pid;
2959          }
2960  
2961          $moderation->restore_posts($pids);
2962  
2963          log_moderator_action($modlogdata, $lang->multi_restore_posts);
2964          if($mybb->get_input('inlinetype') == 'search')
2965          {
2966              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
2967          }
2968          else
2969          {
2970              clearinline($tid, 'thread');
2971          }
2972          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_inline_postsrestored);
2973          break;
2974  
2975      // Soft delete posts - Inline moderation
2976      case "multisoftdeleteposts":
2977          // Verify incoming POST request
2978          verify_post_check($mybb->get_input('my_post_key'));
2979  
2980          if($mybb->get_input('inlinetype') == 'search')
2981          {
2982              $posts = getids($mybb->get_input('searchid'), 'search');
2983          }
2984          else
2985          {
2986              $posts = getids($tid, 'thread');
2987          }
2988  
2989          if(count($posts) < 1)
2990          {
2991              error($lang->error_inline_nopostsselected, $lang->error);
2992          }
2993          $pids = array();
2994  
2995          if(!is_moderator_by_pids($posts, "cansoftdeleteposts"))
2996          {
2997              error_no_permission();
2998          }
2999          foreach($posts as $pid)
3000          {
3001              $pids[] = (int)$pid;
3002          }
3003  
3004          $moderation->soft_delete_posts($pids);
3005          log_moderator_action($modlogdata, $lang->multi_soft_delete_posts);
3006  
3007          if($mybb->get_input('inlinetype') == 'search')
3008          {
3009              clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
3010          }
3011          else
3012          {
3013              clearinline($tid, 'thread');
3014          }
3015          moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_inline_postssoftdeleted);
3016          break;
3017      case "do_purgespammer":
3018      case "purgespammer":
3019          require_once  MYBB_ROOT."inc/functions_user.php";
3020  
3021          $groups = explode(",", $mybb->settings['purgespammergroups']);
3022          if(!is_member($groups))
3023          {
3024              error_no_permission();
3025          }
3026  
3027          $uid = $mybb->get_input('uid', MyBB::INPUT_INT);
3028          $user = get_user($uid);
3029          if(!$user || !purgespammer_show($user['postnum'], $user['usergroup'], $user['uid']))
3030          {
3031              error($lang->purgespammer_invalid_user);
3032          }
3033  
3034          if($mybb->input['action'] == "do_purgespammer")
3035          {
3036              verify_post_check($mybb->get_input('my_post_key'));
3037  
3038              $user_deleted = false;
3039  
3040              // Run the hooks first to avoid any issues when we delete the user
3041              $plugins->run_hooks("moderation_purgespammer_purge");
3042  
3043              require_once  MYBB_ROOT.'inc/datahandlers/user.php';
3044              $userhandler = new UserDataHandler('delete');
3045  
3046              if($mybb->settings['purgespammerbandelete'] == "ban")
3047              {
3048                  // First delete everything
3049                  $userhandler->delete_content($uid);
3050                  $userhandler->delete_posts($uid);
3051                  
3052                  // Next ban him (or update the banned reason, shouldn't happen)
3053                  $query = $db->simple_select("banned", "uid", "uid = '{$uid}'");
3054                  if($db->num_rows($query) > 0)
3055                  {
3056                      $banupdate = array(
3057                          "reason" => $db->escape_string($mybb->settings['purgespammerbanreason'])
3058                      );
3059                      $db->update_query('banned', $banupdate, "uid = '{$uid}'");
3060                  }
3061                  else
3062                  {
3063                      $insert = array(
3064                          "uid" => $uid,
3065                          "gid" => (int)$mybb->settings['purgespammerbangroup'],
3066                          "oldgroup" => 2,
3067                          "oldadditionalgroups" => "",
3068                          "olddisplaygroup" => 0,
3069                          "admin" => (int)$mybb->user['uid'],
3070                          "dateline" => TIME_NOW,
3071                          "bantime" => "---",
3072                          "lifted" => 0,
3073                          "reason" => $db->escape_string($mybb->settings['purgespammerbanreason'])
3074                      );
3075                      $db->insert_query('banned', $insert);
3076                  }
3077  
3078                  // Add the IP's to the banfilters
3079                  if($mybb->settings['purgespammerbanip'] == 1)
3080                  {
3081                      foreach(array($user['regip'], $user['lastip']) as $ip)
3082                      {
3083                          $ip = my_inet_ntop($db->unescape_binary($ip));
3084                          $query = $db->simple_select("banfilters", "type", "type = 1 AND filter = '".$db->escape_string($ip)."'");
3085                          if($db->num_rows($query) == 0)
3086                          {
3087                              $insert = array(
3088                                  "filter" => $db->escape_string($ip),
3089                                  "type" => 1,
3090                                  "dateline" => TIME_NOW
3091                              );
3092                              $db->insert_query("banfilters", $insert);
3093                          }
3094                      }
3095                  }
3096  
3097                  // Clear the profile
3098                  $userhandler->clear_profile($uid, $mybb->settings['purgespammerbangroup']);
3099  
3100                  $cache->update_bannedips();
3101                  $cache->update_awaitingactivation();
3102  
3103                  // Update reports cache
3104                  $cache->update_reportedcontent();
3105              }
3106              elseif($mybb->settings['purgespammerbandelete'] == "delete")
3107              {
3108                  $user_deleted = $userhandler->delete_user($uid, 1);
3109              }
3110  
3111              // Submit the user to stop forum spam
3112              if(!empty($mybb->settings['purgespammerapikey']))
3113              {
3114                  $sfs = @fetch_remote_file("http://stopforumspam.com/add.php?username=" . urlencode($user['username']) . "&ip_addr=" . urlencode(my_inet_ntop($db->unescape_binary($user['lastip']))) . "&email=" . urlencode($user['email']) . "&api_key=" . urlencode($mybb->settings['purgespammerapikey']));
3115              }
3116  
3117              log_moderator_action(array('uid' => $uid, 'username' => $user['username']), $lang->purgespammer_modlog);
3118  
3119              if($user_deleted)
3120              {
3121                  redirect($mybb->settings['bburl'], $lang->purgespammer_success);
3122              }
3123              else
3124              {
3125                  redirect(get_profile_link($uid), $lang->purgespammer_success);
3126              }
3127          }
3128          elseif($mybb->input['action'] == "purgespammer")
3129          {
3130              $plugins->run_hooks("moderation_purgespammer_show");
3131  
3132              add_breadcrumb($lang->purgespammer);
3133              $lang->purgespammer_purge = $lang->sprintf($lang->purgespammer_purge, htmlspecialchars_uni($user['username']));
3134              if($mybb->settings['purgespammerbandelete'] == "ban")
3135              {
3136                  $lang->purgespammer_purge_desc = $lang->sprintf($lang->purgespammer_purge_desc, $lang->purgespammer_ban);
3137              }
3138              else
3139              {
3140                  $lang->purgespammer_purge_desc = $lang->sprintf($lang->purgespammer_purge_desc, $lang->purgespammer_delete);                
3141              }
3142              eval("\$purgespammer = \"".$templates->get('moderation_purgespammer')."\";");
3143              output_page($purgespammer);
3144          }
3145          break;
3146      default:
3147          require_once  MYBB_ROOT."inc/class_custommoderation.php";
3148          $custommod = new CustomModeration;
3149          $tool = $custommod->tool_info($mybb->get_input('action', MyBB::INPUT_INT));
3150          if($tool !== false)
3151          {
3152              // Verify incoming POST request
3153              verify_post_check($mybb->get_input('my_post_key'));
3154  
3155              $options = my_unserialize($tool['threadoptions']);
3156  
3157              if(!is_member($tool['groups']))
3158              {
3159                  error_no_permission();
3160              }
3161              
3162              if($thread['visible'] == -1)
3163              {
3164                  error($lang->error_thread_deleted, $lang->error);
3165              }
3166  
3167              if(!empty($options['confirmation']) && empty($mybb->input['confirm']))
3168              {
3169                  add_breadcrumb($lang->confirm_execute_tool);
3170  
3171                  $lang->confirm_execute_tool_desc = $lang->sprintf($lang->confirm_execute_tool_desc, htmlspecialchars_uni($tool['name']));
3172  
3173                  $action = $mybb->get_input('action', MyBB::INPUT_INT);
3174                  $modtype = htmlspecialchars_uni($mybb->get_input('modtype'));
3175                  $inlinetype = htmlspecialchars_uni($mybb->get_input('inlinetype'));
3176                  $searchid = htmlspecialchars_uni($mybb->get_input('searchid'));
3177                  $url = htmlspecialchars_uni($mybb->get_input('url'));
3178                  $plugins->run_hooks('moderation_confirmation');
3179  
3180                  eval('$page = "'.$templates->get('moderation_confirmation').'";');
3181  
3182                  output_page($page);
3183                  exit;
3184              }
3185  
3186              $tool['name'] = htmlspecialchars_uni($tool['name']);
3187  
3188              if($tool['type'] == 't' && $mybb->get_input('modtype') == 'inlinethread')
3189              {
3190                  if($mybb->get_input('inlinetype') == 'search')
3191                  {
3192                      $tids = getids($mybb->get_input('searchid'), 'search');
3193                  }
3194                  else
3195                  {
3196                      $tids = getids($fid, "forum");
3197                  }
3198                  if(count($tids) < 1)
3199                  {
3200                      error($lang->error_inline_nopostsselected, $lang->error);
3201                  }
3202                  if(!is_moderator_by_tids($tids, "canusecustomtools"))
3203                  {
3204                      error_no_permission();
3205                  }
3206  
3207                  $thread_options = my_unserialize($tool['threadoptions']);
3208                  if($thread_options['movethread'] && $forum_cache[$thread_options['movethread']]['type'] != "f")
3209                  {
3210                      error($lang->error_movetocategory, $lang->error);
3211                  }
3212  
3213                  $custommod->execute($mybb->get_input('action', MyBB::INPUT_INT), $tids);
3214                   $lang->custom_tool = $lang->sprintf($lang->custom_tool, $tool['name']);
3215                  log_moderator_action($modlogdata, $lang->custom_tool);
3216                  if($mybb->get_input('inlinetype') == 'search')
3217                  {
3218                      clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
3219                      $lang->redirect_customtool_search = $lang->sprintf($lang->redirect_customtool_search, $tool['name']);
3220                      $return_url = htmlspecialchars_uni($mybb->get_input('url'));
3221                      moderation_redirect($return_url, $lang->redirect_customtool_search);
3222                  }
3223                  else
3224                  {
3225                      clearinline($fid, "forum");
3226                      $lang->redirect_customtool_forum = $lang->sprintf($lang->redirect_customtool_forum, $tool['name']);
3227                      redirect(get_forum_link($fid), $lang->redirect_customtool_forum);
3228                  }
3229                  break;
3230              }
3231              elseif($tool['type'] == 't' && $mybb->get_input('modtype') == 'thread')
3232              {
3233                  if(!is_moderator_by_tids($tid, "canusecustomtools"))
3234                  {
3235                      error_no_permission();
3236                  }
3237  
3238                  $thread_options = my_unserialize($tool['threadoptions']);
3239                  if($thread_options['movethread'] && $forum_cache[$thread_options['movethread']]['type'] != "f")
3240                  {
3241                      error($lang->error_movetocategory, $lang->error);
3242                  }
3243  
3244                  $ret = $custommod->execute($mybb->get_input('action', MyBB::INPUT_INT), $tid);
3245                   $lang->custom_tool = $lang->sprintf($lang->custom_tool, $tool['name']);
3246                  log_moderator_action($modlogdata, $lang->custom_tool);
3247                  if($ret == 'forum')
3248                  {
3249                      $lang->redirect_customtool_forum = $lang->sprintf($lang->redirect_customtool_forum, $tool['name']);
3250                      moderation_redirect(get_forum_link($fid), $lang->redirect_customtool_forum);
3251                  }
3252                  else
3253                  {
3254                      $lang->redirect_customtool_thread = $lang->sprintf($lang->redirect_customtool_thread, $tool['name']);
3255                      moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_customtool_thread);
3256                  }
3257                  break;
3258              }
3259              elseif($tool['type'] == 'p' && $mybb->get_input('modtype') == 'inlinepost')
3260              {
3261                  if($mybb->get_input('inlinetype') == 'search')
3262                  {
3263                      $pids = getids($mybb->get_input('searchid'), 'search');
3264                  }
3265                  else
3266                  {
3267                      $pids = getids($tid, 'thread');
3268                  }
3269  
3270                  if(count($pids) < 1)
3271                  {
3272                      error($lang->error_inline_nopostsselected, $lang->error);
3273                  }
3274                  if(!is_moderator_by_pids($pids, "canusecustomtools"))
3275                  {
3276                      error_no_permission();
3277                  }
3278  
3279                  // Get threads which are associated with the posts
3280                  $tids = array();
3281                  $options = array(
3282                      'order_by' => 'dateline, pid',
3283                  );
3284                  $query = $db->simple_select("posts", "DISTINCT tid, dateline", "pid IN (".implode(',',$pids).")", $options);
3285                  while($row = $db->fetch_array($query))
3286                  {
3287                      $tids[] = $row['tid'];
3288                  }
3289  
3290                  $ret = $custommod->execute($mybb->get_input('action', MyBB::INPUT_INT), $tids, $pids);
3291                   $lang->custom_tool = $lang->sprintf($lang->custom_tool, $tool['name']);
3292                  log_moderator_action($modlogdata, $lang->custom_tool);
3293                  if($mybb->get_input('inlinetype') == 'search')
3294                  {
3295                      clearinline($mybb->get_input('searchid', MyBB::INPUT_INT), 'search');
3296                      $lang->redirect_customtool_search = $lang->sprintf($lang->redirect_customtool_search, $tool['name']);
3297                      $return_url = htmlspecialchars_uni($mybb->get_input('url'));
3298                      moderation_redirect($return_url, $lang->redirect_customtool_search);
3299                  }
3300                  else
3301                  {
3302                      clearinline($tid, 'thread');
3303                      if($ret == 'forum')
3304                      {
3305                          $lang->redirect_customtool_forum = $lang->sprintf($lang->redirect_customtool_forum, $tool['name']);
3306                          moderation_redirect(get_forum_link($fid), $lang->redirect_customtool_forum);
3307                      }
3308                      else
3309                      {
3310                          $lang->redirect_customtool_thread = $lang->sprintf($lang->redirect_customtool_thread, $tool['name']);
3311                          moderation_redirect(get_thread_link($tid), $lang->redirect_customtool_thread);
3312                      }
3313                  }
3314  
3315                  break;
3316              }
3317          }
3318          error_no_permission();
3319          break;
3320  }
3321  
3322  /**
3323   * Some little handy functions for our inline moderation
3324   *
3325   * @param int $id
3326   * @param string $type
3327   *
3328   * @return array
3329   */
3330  function getids($id, $type)
3331  {
3332      global $mybb;
3333  
3334      $newids = array();
3335      $cookie = "inlinemod_".$type.$id;
3336      if(isset($mybb->cookies[$cookie]))
3337      {
3338          $cookie_ids = explode("|", $mybb->cookies[$cookie]);
3339  
3340          foreach($cookie_ids as $cookie_id)
3341          {
3342              if(empty($cookie_id))
3343              {
3344                  continue;
3345              }
3346  
3347              if($cookie_id == 'ALL')
3348              {
3349                  $newids += getallids($id, $type);
3350              }
3351              else
3352              {
3353                  $newids[] = (int)$cookie_id;
3354              }
3355          }
3356      }
3357  
3358      return $newids;
3359  }
3360  
3361  /**
3362   * @param int $id
3363   * @param string $type
3364   *
3365   * @return array
3366   */
3367  function getallids($id, $type)
3368  {
3369      global $db, $mybb;
3370  
3371      $ids = array();
3372  
3373      // Get any removed threads (after our user hit 'all')
3374      $removed_ids = array();
3375      $cookie = "inlinemod_".$type.$id."_removed";
3376      if(isset($mybb->cookies[$cookie]))
3377      {
3378          $removed_ids = explode("|", $mybb->cookies[$cookie]);
3379  
3380          if(!is_array($removed_ids))
3381          {
3382              $removed_ids = array();
3383          }
3384      }
3385  
3386      // "Select all Threads in this forum" only supported by forumdisplay and search
3387      if($type == 'forum')
3388      {
3389          $query = $db->simple_select("threads", "tid", "fid='".(int)$id."'");
3390          while($tid = $db->fetch_field($query, "tid"))
3391          {
3392              if(in_array($tid, $removed_ids))
3393              {
3394                  continue;
3395              }
3396  
3397              $ids[] = $tid;
3398          }
3399      }
3400      elseif($type == 'search')
3401      {
3402          $query = $db->simple_select("searchlog", "resulttype, posts, threads", "sid='".$db->escape_string($id)."' AND uid='{$mybb->user['uid']}'", 1);
3403          $searchlog = $db->fetch_array($query);
3404          if($searchlog['resulttype'] == 'posts')
3405          {
3406              $ids = explode(',', $searchlog['posts']);
3407          }
3408          else
3409          {
3410              $ids = explode(',', $searchlog['threads']);
3411          }
3412  
3413          if(is_array($ids))
3414          {
3415              foreach($ids as $key => $tid)
3416              {
3417                  if(in_array($tid, $removed_ids))
3418                  {
3419                      unset($ids[$key]);
3420                  }
3421              }
3422          }
3423      }
3424  
3425      return $ids;
3426  }
3427  
3428  /**
3429   * @param int $id
3430   * @param string $type
3431   */
3432  function clearinline($id, $type)
3433  {
3434      my_unsetcookie("inlinemod_".$type.$id);
3435      my_unsetcookie("inlinemod_{$type}{$id}_removed");
3436  }
3437  
3438  /**
3439   * @param int $id
3440   * @param string $type
3441   */
3442  function extendinline($id, $type)
3443  {
3444      my_setcookie("inlinemod_{$type}{$id}", '', TIME_NOW+3600);
3445      my_setcookie("inlinemod_{$type}{$id}_removed", '', TIME_NOW+3600);
3446  }
3447  
3448  /**
3449   * Checks if the current user is a moderator of all the posts specified
3450   *
3451   * Note: If no posts are specified, this function will return true.  It is the
3452   * responsibility of the calling script to error-check this case if necessary.
3453   *
3454   * @param array $posts Array of post IDs
3455   * @param string $permission Permission to check
3456   * @return bool True if moderator of all; false otherwise
3457   */
3458  function is_moderator_by_pids($posts, $permission='')
3459  {
3460      global $db, $mybb;
3461  
3462      // Speedy determination for supermods/admins and guests
3463      if($mybb->usergroup['issupermod'])
3464      {
3465          return true;
3466      }
3467      elseif(!$mybb->user['uid'])
3468      {
3469          return false;
3470      }
3471      // Make an array of threads if not an array
3472      if(!is_array($posts))
3473      {
3474          $posts = array($posts);
3475      }
3476      // Validate input
3477      $posts = array_map('intval', $posts);
3478      $posts[] = 0;
3479      // Get forums
3480      $posts_string = implode(',', $posts);
3481      $query = $db->simple_select("posts", "DISTINCT fid", "pid IN ($posts_string)");
3482      while($forum = $db->fetch_array($query))
3483      {
3484          if(!is_moderator($forum['fid'], $permission))
3485          {
3486              return false;
3487          }
3488      }
3489      return true;
3490  }
3491  
3492  /**
3493   * Checks if the current user is a moderator of all the threads specified
3494   *
3495   * Note: If no threads are specified, this function will return true.  It is the
3496   * responsibility of the calling script to error-check this case if necessary.
3497   *
3498   * @param array $threads Array of thread IDs
3499   * @param string $permission Permission to check
3500   * @return bool True if moderator of all; false otherwise
3501   */
3502  function is_moderator_by_tids($threads, $permission='')
3503  {
3504      global $db, $mybb;
3505  
3506      // Speedy determination for supermods/admins and guests
3507      if($mybb->usergroup['issupermod'])
3508      {
3509          return true;
3510      }
3511      elseif(!$mybb->user['uid'])
3512      {
3513          return false;
3514      }
3515      // Make an array of threads if not an array
3516      if(!is_array($threads))
3517      {
3518          $threads = array($threads);
3519      }
3520      // Validate input
3521      $threads = array_map('intval', $threads);
3522      $threads[] = 0;
3523      // Get forums
3524      $threads_string = implode(',', $threads);
3525      $query = $db->simple_select("threads", "DISTINCT fid", "tid IN ($threads_string)");
3526      while($forum = $db->fetch_array($query))
3527      {
3528          if(!is_moderator($forum['fid'], $permission))
3529          {
3530              return false;
3531          }
3532      }
3533      return true;
3534  }
3535  
3536  /**
3537   * Special redirect that takes a return URL into account
3538   * @param string $url URL
3539   * @param string $message Message
3540   * @param string $title Title
3541   */
3542  function moderation_redirect($url, $message="", $title="")
3543  {
3544      global $mybb;
3545      if(!empty($mybb->input['url']))
3546      {
3547          $url = htmlentities($mybb->input['url']);
3548      }
3549  
3550      if(my_strpos($url, $mybb->settings['bburl'].'/') !== 0)
3551      {
3552          if(my_strpos($url, '/') === 0)
3553          {
3554              $url = my_substr($url, 1);
3555          }
3556          $url_segments = explode('/', $url);
3557          $url = $mybb->settings['bburl'].'/'.end($url_segments);
3558      }
3559  
3560      redirect($url, $message, $title);
3561  }


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