[ Index ]

PHP Cross Reference of MyBB 1.8.15

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


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