[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/forum/ -> moderation_queue.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: moderation_queue.php 5453 2011-04-21 23:58:33Z jammerx2 $
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  $page->add_breadcrumb_item($lang->moderation_queue, "index.php?module=forum-moderation_queue");
  19  
  20  $sub_tabs['threads'] = array(
  21      'title' => $lang->threads,
  22      'link' => "index.php?module=forum-moderation_queue&amp;type=threads",
  23      'description' => $lang->threads_desc
  24  );
  25  
  26  $sub_tabs['posts'] = array(
  27      'title' => $lang->posts,
  28      'link' => "index.php?module=forum-moderation_queue&amp;type=posts",
  29      'description' => $lang->posts_desc
  30  );
  31  
  32  $sub_tabs['attachments'] = array(
  33      'title' => $lang->attachments,
  34      'link' => "index.php?module=forum-moderation_queue&amp;type=attachments",
  35      'description' => $lang->attachments_desc
  36  );
  37  
  38  $plugins->run_hooks("admin_forum_moderation_queue_begin");
  39  
  40  // Actually performing our moderation choices
  41  if($mybb->request_method == "post")
  42  {
  43      $plugins->run_hooks("admin_forum_moderation_queue_commit");
  44      
  45      require_once  MYBB_ROOT."inc/functions_upload.php";
  46      require_once  MYBB_ROOT."inc/class_moderation.php";
  47      $moderation = new Moderation;
  48  
  49      if(is_array($mybb->input['threads']))
  50      {
  51          // Fetch threads
  52          $query = $db->simple_select("threads", "tid", "tid IN (".implode(",", array_map("intval", array_keys($mybb->input['threads'])))."){$flist}");
  53          while($thread = $db->fetch_array($query))
  54          {
  55              $action = $mybb->input['threads'][$thread['tid']];
  56              if($action == "approve")
  57              {
  58                  $threads_to_approve[] = $thread['tid'];
  59              }
  60              else if($action == "delete")
  61              {
  62                  $moderation->delete_thread($thread['tid']);
  63              }
  64          }
  65          if(is_array($threads_to_approve))
  66          {
  67              $moderation->approve_threads($threads_to_approve);
  68          }
  69          
  70          $plugins->run_hooks("admin_forum_moderation_queue_threads_commit");
  71  
  72          // Log admin action
  73          log_admin_action('threads');
  74  
  75          flash_message($lang->success_threads, 'success');
  76          admin_redirect("index.php?module=forum-moderation_queue&type=threads");
  77      }
  78      else if(is_array($mybb->input['posts']))
  79      {
  80          // Fetch posts
  81          $query = $db->simple_select("posts", "pid", "pid IN (".implode(",", array_map("intval", array_keys($mybb->input['posts'])))."){$flist}");
  82          while($post = $db->fetch_array($query))
  83          {
  84              $action = $mybb->input['posts'][$post['pid']];
  85              if($action == "approve")
  86              {
  87                  $posts_to_approve[] = $post['pid'];
  88              }
  89              else if($action == "delete")
  90              {
  91                  $moderation->delete_post($post['pid']);
  92              }
  93          }
  94          if(is_array($posts_to_approve))
  95          {
  96              $moderation->approve_posts($posts_to_approve);
  97          }
  98          
  99          $plugins->run_hooks("admin_forum_moderation_queue_posts_commit");
 100  
 101          // Log admin action
 102          log_admin_action('posts');
 103  
 104          flash_message($lang->success_posts, 'success');
 105          admin_redirect("index.php?module=forum-moderation_queue&type=posts");
 106  
 107      }
 108      else if(is_array($mybb->input['attachments']))
 109      {
 110          $query = $db->simple_select("attachments", "aid, pid", "aid IN (".implode(",", array_map("intval", array_keys($mybb->input['attachments'])))."){$flist}");
 111          while($attachment = $db->fetch_array($query))
 112          {
 113              $action = $mybb->input['attachments'][$attachment['aid']];
 114              if($action == "approve")
 115              {
 116                  $db->update_query("attachments", array("visible" => 1), "aid='{$attachment['aid']}'");
 117              }
 118              else if($action == "delete")
 119              {
 120                  remove_attachment($attachment['pid'], '', $attachment['aid']);
 121              }
 122          }
 123          
 124          $plugins->run_hooks("admin_forum_moderation_queue_attachments_commit");
 125  
 126          // Log admin action
 127          log_admin_action('attachments');
 128  
 129          flash_message($lang->success_attachments, 'success');
 130          admin_redirect("index.php?module=forum-moderation_queue&type=attachments");
 131      }
 132  }
 133  
 134  $all_options = "<ul class=\"modqueue_mass\">\n";
 135  $all_options .= "<li><a href=\"#\" class=\"mass_ignore\" onclick=\"$$('input.radio_ignore').each(function(e) { e.checked = true; }); return false;\">{$lang->mark_as_ignored}</a></li>\n";
 136  $all_options .= "<li><a href=\"#\" class=\"mass_delete\" onclick=\"$$('input.radio_delete').each(function(e) { e.checked = true; }); return false;\">{$lang->mark_as_deleted}</a></li>\n";
 137  $all_options .= "<li><a href=\"#\" class=\"mass_approve\" onclick=\"$$('input.radio_approve').each(function(e) { e.checked = true; }); return false;\">{$lang->mark_as_approved}</a></li>\n";
 138  $all_options .= "</ul>\n";
 139  
 140  // Threads awaiting moderation
 141  if($mybb->input['type'] == "threads" || !$mybb->input['type'])
 142  {
 143      $plugins->run_hooks("admin_forum_moderation_queue_threads");
 144      
 145      $forum_cache = $cache->read("forums");
 146  
 147      $query = $db->simple_select("threads", "COUNT(tid) AS unapprovedthreads", "visible=0");
 148      $unapproved_threads = $db->fetch_field($query, "unapprovedthreads");
 149  
 150      if($unapproved_threads > 0)
 151      {
 152          // Figure out if we need to display multiple pages.
 153          $per_page = 15;
 154          if($mybb->input['page'] > 0)
 155          {
 156              $current_page = intval($mybb->input['page']);
 157              $start = ($current_page-1)*$per_page;
 158              $pages = $unaproved_threads / $per_page;
 159              $pages = ceil($pages);
 160              if($current_page > $pages)
 161              {
 162                  $start = 0;
 163                  $current_page = 1;
 164              }
 165          }
 166          else
 167          {
 168              $start = 0;
 169              $current_page = 1;
 170          }
 171  
 172          $pagination = draw_admin_pagination($current_page, $per_page, $unaproved_threads, "index.php?module=forum-moderation_queue&amp;page={page}");
 173  
 174          $page->add_breadcrumb_item($lang->threads_awaiting_moderation);
 175          $page->output_header($lang->threads_awaiting_moderation);
 176          $page->output_nav_tabs($sub_tabs, "threads");
 177  
 178          $form = new Form("index.php?module=forum-moderation_queue", "post");
 179  
 180          $table = new Table;
 181          $table->construct_header($lang->subject);
 182          $table->construct_header($lang->author, array("class" => "align_center", "width" => "20%"));
 183          $table->construct_header($lang->posted, array("class" => "align_center", "width" => "20%"));
 184  
 185          $query = $db->query("
 186              SELECT t.tid, t.dateline, t.fid, t.subject, p.message AS postmessage, u.username AS username, t.uid
 187              FROM ".TABLE_PREFIX."threads t
 188              LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=t.firstpost)
 189              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
 190              WHERE t.visible='0'
 191              ORDER BY t.lastpost DESC
 192              LIMIT {$start}, {$per_page}
 193          ");
 194          while($thread = $db->fetch_array($query))
 195          {
 196              $thread['subject'] = htmlspecialchars_uni($thread['subject']);
 197              $thread['threadlink'] = get_thread_link($thread['tid']);
 198              $thread['forumlink'] = get_forum_link($thread['fid']);
 199              $forum_name = $forum_cache[$thread['fid']]['name'];
 200              $threaddate = my_date($mybb->settings['dateformat'], $thread['dateline']);
 201              $threadtime = my_date($mybb->settings['timeformat'], $thread['dateline']);
 202              $profile_link = build_profile_link($thread['username'], $thread['uid'], "_blank");
 203              $thread['postmessage'] = nl2br(htmlspecialchars_uni($thread['postmessage']));
 204  
 205              $table->construct_cell("<a href=\"../{$thread['threadlink']}\" target=\"_blank\">{$thread['subject']}</a>");
 206              $table->construct_cell($profile_link, array("class" => "align_center"));
 207              $table->construct_cell("{$threaddate}, {$threadtime}", array("class" => "align_center"));
 208              $table->construct_row();
 209  
 210              $controls = "<div class=\"modqueue_controls\">\n";
 211              $controls .= $form->generate_radio_button("threads[{$thread['tid']}]", "ignore", $lang->ignore, array('class' => 'radio_ignore', 'checked' => true))." ";
 212              $controls .= $form->generate_radio_button("threads[{$thread['tid']}]", "delete", $lang->delete, array('class' => 'radio_delete', 'checked' => false))." ";
 213              $controls .= $form->generate_radio_button("threads[{$thread['tid']}]", "approve", $lang->approve, array('class' => 'radio_approve', 'checked' => false));
 214              $controls .= "</div>";
 215  
 216              $forum = "<strong>{$lang->forum} <a href=\"../{$thread['forumlink']}\" target=\"_blank\">{$forum_name}</a></strong><br />";
 217  
 218              $table->construct_cell("<div class=\"modqueue_message\">{$controls}<div class=\"modqueue_meta\">{$forum}</div>{$thread['postmessage']}</div>", array("colspan" => 3));
 219              $table->construct_row();
 220          }
 221  
 222          $table->output($lang->threads_awaiting_moderation);
 223          echo $all_options;
 224          echo $pagination;
 225  
 226          $buttons[] = $form->generate_submit_button($lang->perform_action);
 227          $form->output_submit_wrapper($buttons);
 228          $form->end();
 229          $page->output_footer();
 230      }
 231  }
 232  
 233  // Posts awaiting moderation
 234  if($mybb->input['type'] == "posts" || $mybb->input['type'] == "")
 235  {
 236      $plugins->run_hooks("admin_forum_moderation_queue_posts");
 237      
 238      $forum_cache = $cache->read("forums");
 239  
 240      $query = $db->query("
 241          SELECT COUNT(pid) AS unapprovedposts
 242          FROM  ".TABLE_PREFIX."posts p
 243          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 244          WHERE p.visible='0' AND t.firstpost != p.pid
 245      ");
 246      $unapproved_posts = $db->fetch_field($query, "unapprovedposts");
 247  
 248      if($unapproved_posts > 0)
 249      {
 250          // Figure out if we need to display multiple pages.
 251          $per_page = 15;
 252          if($mybb->input['page'] > 0)
 253          {
 254              $current_page = intval($mybb->input['page']);
 255              $start = ($current_page-1)*$per_page;
 256              $pages = $unaproved_posts / $per_page;
 257              $pages = ceil($pages);
 258              if($current_page > $pages)
 259              {
 260                  $start = 0;
 261                  $current_page = 1;
 262              }
 263          }
 264          else
 265          {
 266              $start = 0;
 267              $current_page = 1;
 268          }
 269  
 270          $pagination = draw_admin_pagination($current_page, $per_page, $unaproved_posts, "index.php?module=forum-moderation_queue&amp;type=posts&amp;page={page}");
 271  
 272  
 273          $page->add_breadcrumb_item($lang->posts_awaiting_moderation);
 274          $page->output_header($lang->posts_awaiting_moderation);
 275          $page->output_nav_tabs($sub_tabs, "posts");
 276  
 277          $form = new Form("index.php?module=forum-moderation_queue", "post");
 278  
 279          $table = new Table;
 280          $table->construct_header($lang->subject);
 281          $table->construct_header($lang->author, array("class" => "align_center", "width" => "20%"));
 282          $table->construct_header($lang->posted, array("class" => "align_center", "width" => "20%"));
 283  
 284          $query = $db->query("
 285              SELECT p.pid, p.subject, p.message, t.subject AS threadsubject, t.tid, u.username, p.uid, t.fid
 286              FROM  ".TABLE_PREFIX."posts p
 287              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 288              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 289              WHERE p.visible='0' AND t.firstpost != p.pid
 290              ORDER BY p.dateline DESC
 291              LIMIT {$start}, {$per_page}
 292          ");
 293          while($post = $db->fetch_array($query))
 294          {
 295              $altbg = alt_trow();
 296              $post['threadsubject'] = htmlspecialchars_uni($post['threadsubject']);
 297              $post['subject'] = htmlspecialchars_uni($post['subject']);
 298              
 299              if(!$post['subject'])
 300              {
 301                  $post['subject'] = $lang->re." ".$post['threadsubject'];
 302              }
 303  
 304              $post['postlink'] = get_post_link($post['pid'], $post['tid']);
 305              $post['threadlink'] = get_thread_link($post['tid']);
 306              $post['forumlink'] = get_forum_link($post['fid']);
 307              $forum_name = $forum_cache[$post['fid']]['name'];
 308              $postdate = my_date($mybb->settings['dateformat'], $post['dateline']);
 309              $posttime = my_date($mybb->settings['timeformat'], $post['dateline']);
 310              $profile_link = build_profile_link($post['username'], $post['uid'], "_blank");
 311              $post['message'] = nl2br(htmlspecialchars_uni($post['message']));
 312  
 313              $table->construct_cell("<a href=\"../{$post['postlink']}#pid{$post['pid']}\" target=\"_blank\">{$post['subject']}</a>");
 314              $table->construct_cell($profile_link, array("class" => "align_center"));
 315              $table->construct_cell("{$postdate}, {$posttime}", array("class" => "align_center"));
 316              $table->construct_row();
 317  
 318              $controls = "<div class=\"modqueue_controls\">\n";
 319              $controls .= $form->generate_radio_button("posts[{$post['pid']}]", "ignore", $lang->ignore, array('class' => 'radio_ignore', 'checked' => true))." ";
 320              $controls .= $form->generate_radio_button("posts[{$post['pid']}]", "delete",$lang->delete, array('class' => 'radio_delete', 'checked' => false))." ";
 321              $controls .= $form->generate_radio_button("posts[{$post['pid']}]", "approve", $lang->approve, array('class' => 'radio_approve', 'checked' => false));
 322              $controls .= "</div>";
 323  
 324              $thread = "<strong>{$lang->thread} <a href=\"../{$post['threadlink']}\" target=\"_blank\">{$post['threadsubject']}</a></strong>";
 325              $forum = "<strong>{$lang->forum} <a href=\"../{$post['forumlink']}\" target=\"_blank\">{$forum_name}</a></strong><br />";
 326  
 327              $table->construct_cell("<div class=\"modqueue_message\">{$controls}<div class=\"modqueue_meta\">{$forum}{$thread}</div>{$post['message']}</div>", array("colspan" => 3));
 328              $table->construct_row();
 329          }
 330  
 331          $table->output($lang->posts_awaiting_moderation);
 332          echo $all_options;
 333          echo $pagination;
 334  
 335          $buttons[] = $form->generate_submit_button($lang->perform_action);
 336          $form->output_submit_wrapper($buttons);
 337          $form->end();
 338          $page->output_footer();
 339      }
 340      else if($mybb->input['type'] == "posts")
 341      {
 342          $page->output_header($lang->moderation_queue);
 343          $page->output_nav_tabs($sub_tabs, "posts");
 344          echo "<p class=\"notice\">{$lang->error_no_posts}</p>";
 345          $page->output_footer();
 346      }
 347  }
 348  
 349  // Attachments awaiting moderation
 350  if($mybb->input['type'] == "attachments" || $mybb->input['type'] == "")
 351  {
 352      $plugins->run_hooks("admin_forum_moderation_queue_attachments");
 353      
 354      $query = $db->query("
 355          SELECT COUNT(aid) AS unapprovedattachments
 356          FROM  ".TABLE_PREFIX."attachments a
 357          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
 358          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 359          WHERE a.visible='0'
 360      ");
 361      $unapproved_attachments = $db->fetch_field($query, "unapprovedattachments");
 362  
 363      if($unapproved_attachments > 0)
 364      {
 365          // Figure out if we need to display multiple pages.
 366          $per_page = 15;
 367          if($mybb->input['page'] > 0)
 368          {
 369              $current_page = intval($mybb->input['page']);
 370              $start = ($current_page-1)*$per_page;
 371              $pages = $unapproved_attachments / $per_page;
 372              $pages = ceil($pages);
 373              if($current_page > $pages)
 374              {
 375                  $start = 0;
 376                  $current_page = 1;
 377              }
 378          }
 379          else
 380          {
 381              $start = 0;
 382              $current_page = 1;
 383          }
 384  
 385          $pagination = draw_admin_pagination($current_page, $per_page, $unapproved_attachments, "index.php?module=forum-moderation_queue&amp;type=attachments&amp;page={page}");
 386  
 387          $page->add_breadcrumb_item($lang->attachments_awaiting_moderation);
 388          $page->output_header($lang->attachments_awaiting_moderation);
 389          $page->output_nav_tabs($sub_tabs, "attachments");
 390  
 391          $form = new Form("index.php?module=forum-moderation_queue", "post");
 392  
 393          $table = new Table;
 394          $table->construct_header($lang->filename);
 395          $table->construct_header($lang->uploadedby, array("class" => "align_center", "width" => "20%"));
 396          $table->construct_header($lang->posted, array("class" => "align_center", "width" => "20%"));
 397          $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 3));
 398  
 399          $query = $db->query("
 400              SELECT a.*, p.subject AS postsubject, p.dateline, p.uid, u.username, t.tid, t.subject AS threadsubject
 401              FROM  ".TABLE_PREFIX."attachments a
 402              LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
 403              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 404              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 405              WHERE a.visible='0'
 406              ORDER BY a.dateuploaded DESC
 407              LIMIT {$start}, {$per_page}
 408          ");
 409  
 410          while($attachment = $db->fetch_array($query))
 411          {
 412              if(!$attachment['dateuploaded']) $attachment['dateuploaded'] = $attachment['dateline'];
 413              $attachdate = my_date($mybb->settings['dateformat'], $attachment['dateuploaded']);
 414              $attachtime = my_date($mybb->settings['timeformat'], $attachment['dateuploaded']);
 415  
 416              $attachment['postsubject'] = htmlspecialchars_uni($attachment['postsubject']);
 417              $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
 418              $attachment['threadsubject'] = htmlspecialchars_uni($attachment['threadsubject']);
 419              $attachment['filesize'] = get_friendly_size($attachment['filesize']);
 420  
 421              $link = get_post_link($attachment['pid'], $attachment['tid']) . "#pid{$attachment['pid']}";
 422              $thread_link = get_thread_link($attachment['tid']);
 423              $profile_link = build_profile_link($attachment['username'], $attachment['uid'], "_blank");
 424  
 425              $table->construct_cell("<a href=\"../attachment.php?aid={$attachment['aid']}\" target=\"_blank\">{$attachment['filename']}</a> ({$attachment['filesize']})<br /><small class=\"modqueue_meta\">{$lang->post} <a href=\"{$link}\" target=\"_blank\">{$attachment['postsubject']}</a></small>");
 426              $table->construct_cell($profile_link, array("class" => "align_center"));
 427              $table->construct_cell("{$attachdate}, {$attachtime}", array("class" => "align_center"));
 428  
 429              $table->construct_cell($form->generate_radio_button("attachments[{$attachment['aid']}]", "ignore", $lang->ignore, array('class' => 'radio_ignore', 'checked' => true)), array("class" => "align_center"));
 430              $table->construct_cell($form->generate_radio_button("attachments[{$attachment['aid']}]", "delete", $lang->delete, array('class' => 'radio_delete', 'checked' => false)), array("class" => "align_center"));
 431              $table->construct_cell($form->generate_radio_button("attachments[{$attachment['aid']}]", "approve", $lang->approve, array('class' => 'radio_approve', 'checked' => false)), array("class" => "align_center"));
 432              $table->construct_row();
 433          }
 434          $table->output($lang->attachments_awaiting_moderation);
 435          echo $all_options;
 436          echo $pagination;
 437  
 438          $buttons[] = $form->generate_submit_button($lang->perform_action);
 439          $form->output_submit_wrapper($buttons);
 440          $form->end();
 441          $page->output_footer();
 442      }
 443      else if($mybb->input['type'] == "attachments")
 444      {
 445          $page->output_header($lang->moderation_queue);
 446          $page->output_nav_tabs($sub_tabs, "attachments");
 447          echo "<p class=\"notice\">{$lang->error_no_attachments}</p>";
 448          $page->output_footer();
 449      }
 450  }
 451  
 452  // Still nothing? All queues are empty! :-D
 453  $page->output_header($lang->moderation_queue);
 454  echo "<p class=\"notice\">{$lang->error_no_threads}</p>";
 455  $page->output_footer();
 456  
 457  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1