[ Index ]

PHP Cross Reference of MyBB 1.8.41

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


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