[ Index ]

PHP Cross Reference of MyBB 1.8.17

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


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