]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-comments.php
Wordpress 3.3
[autoinstalls/wordpress.git] / wp-admin / edit-comments.php
1 <?php
2 /**
3  * Edit Comments Administration Screen.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
11 if ( !current_user_can('edit_posts') )
12         wp_die(__('Cheatin&#8217; uh?'));
13
14 $wp_list_table = _get_list_table('WP_Comments_List_Table');
15 $pagenum = $wp_list_table->get_pagenum();
16
17 $doaction = $wp_list_table->current_action();
18
19 if ( $doaction ) {
20         check_admin_referer( 'bulk-comments' );
21
22         if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
23                 $comment_status = $wpdb->escape( $_REQUEST['comment_status'] );
24                 $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
25                 $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
26                 $doaction = 'delete';
27         } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
28                 $comment_ids = $_REQUEST['delete_comments'];
29                 $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
30         } elseif ( isset( $_REQUEST['ids'] ) ) {
31                 $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
32         } elseif ( wp_get_referer() ) {
33                 wp_safe_redirect( wp_get_referer() );
34                 exit;
35         }
36
37         $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
38
39         $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
40         $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
41
42         foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
43                 if ( !current_user_can( 'edit_comment', $comment_id ) )
44                         continue;
45
46                 switch ( $doaction ) {
47                         case 'approve' :
48                                 wp_set_comment_status( $comment_id, 'approve' );
49                                 $approved++;
50                                 break;
51                         case 'unapprove' :
52                                 wp_set_comment_status( $comment_id, 'hold' );
53                                 $unapproved++;
54                                 break;
55                         case 'spam' :
56                                 wp_spam_comment( $comment_id );
57                                 $spammed++;
58                                 break;
59                         case 'unspam' :
60                                 wp_unspam_comment( $comment_id );
61                                 $unspammed++;
62                                 break;
63                         case 'trash' :
64                                 wp_trash_comment( $comment_id );
65                                 $trashed++;
66                                 break;
67                         case 'untrash' :
68                                 wp_untrash_comment( $comment_id );
69                                 $untrashed++;
70                                 break;
71                         case 'delete' :
72                                 wp_delete_comment( $comment_id );
73                                 $deleted++;
74                                 break;
75                 }
76         }
77
78         if ( $approved )
79                 $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
80         if ( $unapproved )
81                 $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
82         if ( $spammed )
83                 $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
84         if ( $unspammed )
85                 $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
86         if ( $trashed )
87                 $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
88         if ( $untrashed )
89                 $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
90         if ( $deleted )
91                 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
92         if ( $trashed || $spammed )
93                 $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
94
95         wp_safe_redirect( $redirect_to );
96         exit;
97 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
98          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
99          exit;
100 }
101
102 $wp_list_table->prepare_items();
103
104 wp_enqueue_script('admin-comments');
105 enqueue_comment_hotkeys_js();
106
107 if ( $post_id )
108         $title = sprintf(__('Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
109 else
110         $title = __('Comments');
111
112 add_screen_option( 'per_page', array('label' => _x( 'Comments', 'comments per page (screen options)' )) );
113
114 get_current_screen()->add_help_tab( array(
115 'id'            => 'overview',
116 'title'         => __('Overview'),
117 'content'       =>
118         '<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>'
119 ) );
120 get_current_screen()->add_help_tab( array(
121 'id'            => 'moderating-comments',
122 'title'         => __('Moderating Comments'),
123 'content'       =>
124         '<ul>' .
125                 '<li>' . __( 'A yellow row means the comment is waiting for you to moderate it.' ) . '</li>' .
126                 '<li>' . __( 'In the <strong>Author</strong> 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.' ) . '</li>' .
127                 '<li>' . __( 'In the <strong>Comment</strong> 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.' ) . '</li>' .
128                 '<li>' . __( 'In the <strong>In Response To</strong> 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 View Post link 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.' ) . '</li>' .
129                 '<li>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</li>' .
130         '</ul>'
131 ) );
132
133 get_current_screen()->set_help_sidebar(
134         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
135         '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
136         '<p>' . __( '<a href="http://codex.wordpress.org/Comment_Spam" target="_blank">Documentation on Comment Spam</a>' ) . '</p>' .
137         '<p>' . __( '<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
138         '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
139 );
140
141 require_once('./admin-header.php');
142 ?>
143
144 <div class="wrap">
145 <?php screen_icon(); ?>
146 <h2><?php
147 if ( $post_id )
148         echo sprintf(__('Comments on &#8220;%s&#8221;'),
149                 sprintf('<a href="%s">%s</a>',
150                         get_edit_post_link($post_id),
151                         wp_html_excerpt(_draft_or_post_title($post_id), 50)
152                 )
153         );
154 else
155         echo __('Comments');
156
157 if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
158         printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?>
159 </h2>
160
161 <?php
162 if ( isset( $_REQUEST['error'] ) ) {
163         $error = (int) $_REQUEST['error'];
164         $error_msg = '';
165         switch ( $error ) {
166                 case 1 :
167                         $error_msg = __( 'Oops, no comment with this ID.' );
168                         break;
169                 case 2 :
170                         $error_msg = __( 'You are not allowed to edit comments on this post.' );
171                         break;
172         }
173         if ( $error_msg )
174                 echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
175 }
176
177 if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) {
178         $approved  = isset( $_REQUEST['approved']  ) ? (int) $_REQUEST['approved']  : 0;
179         $deleted   = isset( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
180         $trashed   = isset( $_REQUEST['trashed']   ) ? (int) $_REQUEST['trashed']   : 0;
181         $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
182         $spammed   = isset( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
183         $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
184         $same      = isset( $_REQUEST['same'] )      ? (int) $_REQUEST['same']      : 0;
185
186         if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
187                 if ( $approved > 0 )
188                         $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
189
190                 if ( $spammed > 0 ) {
191                         $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
192                         $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 />';
193                 }
194
195                 if ( $unspammed > 0 )
196                         $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
197
198                 if ( $trashed > 0 ) {
199                         $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
200                         $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 />';
201                 }
202
203                 if ( $untrashed > 0 )
204                         $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed );
205
206                 if ( $deleted > 0 )
207                         $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
208
209                 if ( $same > 0 && $comment = get_comment( $same ) ) {
210                         switch ( $comment->comment_approved ) {
211                                 case '1' :
212                                         $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
213                                         break;
214                                 case 'trash' :
215                                         $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
216                                         break;
217                                 case 'spam' :
218                                         $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
219                                         break;
220                         }
221                 }
222
223                 echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
224         }
225 }
226 ?>
227
228 <?php $wp_list_table->views(); ?>
229
230 <form id="comments-form" action="" method="get">
231
232 <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?>
233
234 <?php if ( $post_id ) : ?>
235 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
236 <?php endif; ?>
237 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
238 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
239
240 <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />
241 <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" />
242 <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" />
243
244 <?php if ( isset($_REQUEST['paged']) ) { ?>
245         <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
246 <?php } ?>
247
248 <?php $wp_list_table->display(); ?>
249 </form>
250 </div>
251
252 <div id="ajax-response"></div>
253
254 <?php
255 wp_comment_reply('-1', true, 'detail');
256 wp_comment_trashnotice();
257 include('./admin-footer.php'); ?>