PageRenderTime 46ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/edit-comments.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 242 lines | 198 code | 37 blank | 7 comment | 49 complexity | 16758c8b31da2aef1fbb564fc34a8d80 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Edit Comments Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( !current_user_can('edit_posts') )
  11. wp_die(__('Cheatin&#8217; uh?'));
  12. $wp_list_table = _get_list_table('WP_Comments_List_Table');
  13. $pagenum = $wp_list_table->get_pagenum();
  14. $doaction = $wp_list_table->current_action();
  15. if ( $doaction ) {
  16. check_admin_referer( 'bulk-comments' );
  17. if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
  18. $comment_status = $wpdb->escape( $_REQUEST['comment_status'] );
  19. $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
  20. $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
  21. $doaction = 'delete';
  22. } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
  23. $comment_ids = $_REQUEST['delete_comments'];
  24. $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
  25. } elseif ( isset( $_REQUEST['ids'] ) ) {
  26. $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
  27. } elseif ( wp_get_referer() ) {
  28. wp_redirect( wp_get_referer() );
  29. exit;
  30. }
  31. $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
  32. $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
  33. $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
  34. foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
  35. if ( !current_user_can( 'edit_comment', $comment_id ) )
  36. continue;
  37. switch ( $doaction ) {
  38. case 'approve' :
  39. wp_set_comment_status( $comment_id, 'approve' );
  40. $approved++;
  41. break;
  42. case 'unapprove' :
  43. wp_set_comment_status( $comment_id, 'hold' );
  44. $unapproved++;
  45. break;
  46. case 'spam' :
  47. wp_spam_comment( $comment_id );
  48. $spammed++;
  49. break;
  50. case 'unspam' :
  51. wp_unspam_comment( $comment_id );
  52. $unspammed++;
  53. break;
  54. case 'trash' :
  55. wp_trash_comment( $comment_id );
  56. $trashed++;
  57. break;
  58. case 'untrash' :
  59. wp_untrash_comment( $comment_id );
  60. $untrashed++;
  61. break;
  62. case 'delete' :
  63. wp_delete_comment( $comment_id );
  64. $deleted++;
  65. break;
  66. }
  67. }
  68. if ( $approved )
  69. $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
  70. if ( $unapproved )
  71. $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
  72. if ( $spammed )
  73. $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
  74. if ( $unspammed )
  75. $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
  76. if ( $trashed )
  77. $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
  78. if ( $untrashed )
  79. $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
  80. if ( $deleted )
  81. $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
  82. if ( $trashed || $spammed )
  83. $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
  84. wp_redirect( $redirect_to );
  85. exit;
  86. } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
  87. wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
  88. exit;
  89. }
  90. $wp_list_table->prepare_items();
  91. wp_enqueue_script('admin-comments');
  92. enqueue_comment_hotkeys_js();
  93. if ( $post_id )
  94. $title = sprintf(__('Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
  95. else
  96. $title = __('Comments');
  97. add_screen_option( 'per_page', array('label' => _x( 'Comments', 'comments per page (screen options)' )) );
  98. add_contextual_help( $current_screen, '<p>' . __( 'You can manage comments made on your site similar to the way you manage Posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the Bulk Actions.' ) . '</p>' .
  99. '<p>' . __( 'A yellow row means the comment is waiting for you to moderate it.' ) . '</p>' .
  100. '<p>' . __( 'In the Author column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
  101. '<p>' . __( 'In the Comment column, above each comment it says &#8220;Submitted on,&#8221; followed by the date and time the comment was left on your site. Clicking on the date/time link will take you to that comment on your live site. Hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
  102. '<p>' . __( 'In the In Response To column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The &#8220;#&#8221; permalink symbol below leads to that post on your live site. The small bubble with the number in it shows how many comments that post has received. If the bubble is gray, you have moderated all comments for that post. If it is blue, there are pending comments. Clicking the bubble will filter the comments screen to show only comments on that post.' ) . '</p>' .
  103. '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link below to learn more.' ) . '</p>' .
  104. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  105. '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
  106. '<p>' . __( '<a href="http://codex.wordpress.org/Comment_Spam" target="_blank">Documentation on Comment Spam</a>' ) . '</p>' .
  107. '<p>' . __( '<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
  108. '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
  109. );
  110. require_once('./admin-header.php');
  111. ?>
  112. <div class="wrap">
  113. <?php screen_icon(); ?>
  114. <h2><?php
  115. if ( $post_id )
  116. echo sprintf(__('Comments on &#8220;%s&#8221;'),
  117. sprintf('<a href="%s">%s</a>',
  118. get_edit_post_link($post_id),
  119. wp_html_excerpt(_draft_or_post_title($post_id), 50)
  120. )
  121. );
  122. else
  123. echo __('Comments');
  124. if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
  125. printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?>
  126. </h2>
  127. <?php
  128. if ( isset( $_REQUEST['error'] ) ) {
  129. $error = (int) $_REQUEST['error'];
  130. $error_msg = '';
  131. switch ( $error ) {
  132. case 1 :
  133. $error_msg = __( 'Oops, no comment with this ID.' );
  134. break;
  135. case 2 :
  136. $error_msg = __( 'You are not allowed to edit comments on this post.' );
  137. break;
  138. }
  139. if ( $error_msg )
  140. echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
  141. }
  142. if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) {
  143. $approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
  144. $deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
  145. $trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
  146. $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
  147. $spammed = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
  148. $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
  149. $same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
  150. if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
  151. if ( $approved > 0 )
  152. $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
  153. if ( $spammed > 0 ) {
  154. $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
  155. $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
  156. }
  157. if ( $unspammed > 0 )
  158. $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
  159. if ( $trashed > 0 ) {
  160. $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
  161. $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
  162. }
  163. if ( $untrashed > 0 )
  164. $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed );
  165. if ( $deleted > 0 )
  166. $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
  167. if ( $same > 0 && $comment = get_comment( $same ) ) {
  168. switch ( $comment->comment_approved ) {
  169. case '1' :
  170. $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
  171. break;
  172. case 'trash' :
  173. $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
  174. break;
  175. case 'spam' :
  176. $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
  177. break;
  178. }
  179. }
  180. echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
  181. }
  182. }
  183. ?>
  184. <?php $wp_list_table->views(); ?>
  185. <form id="comments-form" action="" method="get">
  186. <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?>
  187. <?php if ( $post_id ) : ?>
  188. <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
  189. <?php endif; ?>
  190. <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
  191. <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
  192. <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />
  193. <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" />
  194. <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" />
  195. <?php if ( isset($_REQUEST['paged']) ) { ?>
  196. <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
  197. <?php } ?>
  198. <?php $wp_list_table->display(); ?>
  199. </form>
  200. </div>
  201. <div id="ajax-response"></div>
  202. <?php
  203. wp_comment_reply('-1', true, 'detail');
  204. wp_comment_trashnotice();
  205. include('./admin-footer.php'); ?>