PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/2.5/wp-admin/edit-comments.php

#
PHP | 245 lines | 205 code | 39 blank | 1 comment | 34 complexity | 582991fab90fd251f00735d0b656aab5 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. require_once('admin.php');
  3. $title = __('Edit Comments');
  4. $parent_file = 'edit-comments.php';
  5. wp_enqueue_script( 'admin-comments' );
  6. wp_enqueue_script('admin-forms');
  7. if ( !empty( $_REQUEST['delete_comments'] ) ) {
  8. check_admin_referer('bulk-comments');
  9. $comments_deleted = $comments_approved = $comments_unapproved = $comments_spammed = 0;
  10. foreach ($_REQUEST['delete_comments'] as $comment) : // Check the permissions on each
  11. $comment = (int) $comment;
  12. $post_id = (int) $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
  13. // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
  14. if ( !current_user_can('edit_post', $post_id) )
  15. continue;
  16. if ( !empty( $_REQUEST['spamit'] ) ) {
  17. wp_set_comment_status($comment, 'spam');
  18. $comments_spammed++;
  19. } elseif ( !empty( $_REQUEST['deleteit'] ) ) {
  20. wp_set_comment_status($comment, 'delete');
  21. $comments_deleted++;
  22. } elseif ( !empty( $_REQUEST['approveit'] ) ) {
  23. wp_set_comment_status($comment, 'approve');
  24. $comments_approved++;
  25. } elseif ( !empty( $_REQUEST['unapproveit'] ) ) {
  26. wp_set_comment_status($comment, 'hold');
  27. $comments_unapproved++;
  28. }
  29. endforeach;
  30. $redirect_to = basename( __FILE__ ) . '?deleted=' . $comments_deleted . '&approved=' . $comments_approved . '&spam=' . $comments_spammed . '&unapproved=' . $comments_unapproved;
  31. if ( !empty($_REQUEST['mode']) )
  32. $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
  33. if ( !empty($_REQUEST['comment_status']) )
  34. $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
  35. if ( !empty($_REQUEST['s']) )
  36. $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
  37. wp_redirect( $redirect_to );
  38. } elseif ( !empty($_GET['_wp_http_referer']) ) {
  39. wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
  40. exit;
  41. }
  42. require_once('admin-header.php');
  43. if ( empty($_GET['mode']) )
  44. $mode = 'detail';
  45. else
  46. $mode = attribute_escape($_GET['mode']);
  47. if ( isset($_GET['comment_status']) )
  48. $comment_status = attribute_escape($_GET['comment_status']);
  49. else
  50. $comment_status = '';
  51. if ( isset($_GET['s']) )
  52. $search_dirty = $_GET['s'];
  53. else
  54. $search_dirty = '';
  55. $search = attribute_escape( $search_dirty );
  56. ?>
  57. <?php
  58. if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
  59. $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
  60. $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
  61. $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
  62. if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
  63. echo '<div id="moderated" class="updated fade"><p>';
  64. if ( $approved > 0 ) {
  65. printf( __ngettext( '%s comment approved', '%s comments approved', $approved ), $approved );
  66. echo '<br />';
  67. }
  68. if ( $deleted > 0 ) {
  69. printf( __ngettext( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
  70. echo '<br />';
  71. }
  72. if ( $spam > 0 ) {
  73. printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
  74. echo '<br />';
  75. }
  76. echo '</p></div>';
  77. }
  78. }
  79. ?>
  80. <div class="wrap">
  81. <form id="posts-filter" action="" method="get">
  82. <h2><?php _e('Manage Comments'); ?></h2>
  83. <ul class="subsubsub">
  84. <?php
  85. $status_links = array();
  86. $num_comments = wp_count_comments();
  87. $stati = array('moderated' => sprintf(__ngettext('Awaiting Moderation (%s)', 'Awaiting Moderation (%s)', number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 'approved' => _c('Approved|plural'));
  88. $class = ( '' === $comment_status ) ? ' class="current"' : '';
  89. $status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>";
  90. foreach ( $stati as $status => $label ) {
  91. $class = '';
  92. if ( $status == $comment_status )
  93. $class = ' class="current"';
  94. $status_links[] = "<li><a href=\"edit-comments.php?comment_status=$status\"$class>" . $label . '</a>';
  95. }
  96. $status_links = apply_filters( 'comment_status_links', $status_links );
  97. echo implode(' | </li>', $status_links) . '</li>';
  98. unset($status_links);
  99. ?>
  100. </ul>
  101. <p id="post-search">
  102. <input type="text" id="post-search-input" name="s" value="<?php echo $search; ?>" />
  103. <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" />
  104. </p>
  105. <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
  106. <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
  107. </form>
  108. <ul class="view-switch">
  109. <li <?php if ( 'detail' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'detail', $_SERVER['REQUEST_URI'])) ?>"><?php _e('Detail View') ?></a></li>
  110. <li <?php if ( 'list' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'list', $_SERVER['REQUEST_URI'])) ?>"><?php _e('List View') ?></a></li>
  111. </ul>
  112. <?php
  113. if ( isset( $_GET['apage'] ) )
  114. $page = abs( (int) $_GET['apage'] );
  115. else
  116. $page = 1;
  117. $start = $offset = ( $page - 1 ) * 20;
  118. list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, 25 ); // Grab a few extra
  119. $comments = array_slice($_comments, 0, 20);
  120. $extra_comments = array_slice($_comments, 20);
  121. $page_links = paginate_links( array(
  122. 'base' => add_query_arg( 'apage', '%#%' ),
  123. 'format' => '',
  124. 'total' => ceil($total / 20),
  125. 'current' => $page
  126. ));
  127. ?>
  128. <form id="comments-form" action="" method="post">
  129. <div class="tablenav">
  130. <?php
  131. if ( $page_links )
  132. echo "<div class='tablenav-pages'>$page_links</div>";
  133. ?>
  134. <div class="alignleft">
  135. <?php if ( 'approved' != $comment_status ): ?>
  136. <input type="submit" value="<?php _e('Approve'); ?>" name="approveit" class="button-secondary" />
  137. <?php endif; ?>
  138. <input type="submit" value="<?php _e('Mark as Spam'); ?>" name="spamit" class="button-secondary" />
  139. <?php if ( 'moderated' != $comment_status ): ?>
  140. <input type="submit" value="<?php _e('Unapprove'); ?>" name="unapproveit" class="button-secondary" />
  141. <?php endif; ?>
  142. <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
  143. <?php do_action('manage_comments_nav', $comment_status); ?>
  144. <?php wp_nonce_field('bulk-comments'); ?>
  145. </div>
  146. <br class="clear" />
  147. </div>
  148. <br class="clear" />
  149. <?php
  150. if ($comments) {
  151. ?>
  152. <table class="widefat">
  153. <thead>
  154. <tr>
  155. <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('comments-form'));" /></th>
  156. <th scope="col"><?php _e('Comment') ?></th>
  157. <th scope="col"><?php _e('Date') ?></th>
  158. <th scope="col" class="action-links"><?php _e('Actions') ?></th>
  159. </tr>
  160. </thead>
  161. <tbody id="the-comment-list" class="list:comment">
  162. <?php
  163. foreach ($comments as $comment)
  164. _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
  165. ?>
  166. </tbody>
  167. <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
  168. <?php
  169. foreach ($extra_comments as $comment)
  170. _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
  171. ?>
  172. </tbody>
  173. </table>
  174. </form>
  175. <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
  176. <input type="hidden" name="s" value="<?php echo $search; ?>" />
  177. <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
  178. <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
  179. <input type="hidden" name="page" value="<?php echo isset($_REQUEST['page']) ? absint( $_REQUEST['page'] ) : 1; ?>" />
  180. <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
  181. </form>
  182. <div id="ajax-response"></div>
  183. <?php
  184. } elseif ( 'moderated' == $_GET['comment_status'] ) {
  185. ?>
  186. <p>
  187. <?php _e('No comments awaiting moderation&hellip; yet.') ?>
  188. </p>
  189. <?php
  190. } else {
  191. ?>
  192. <p>
  193. <?php _e('No results found.') ?>
  194. </p>
  195. <?php
  196. }
  197. ?>
  198. <div class="tablenav">
  199. <?php
  200. if ( $page_links )
  201. echo "<div class='tablenav-pages'>$page_links</div>";
  202. ?>
  203. <br class="clear" />
  204. </div>
  205. </div>
  206. <?php include('admin-footer.php'); ?>