]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-comments.php
Wordpress 2.9.2-scripts
[autoinstalls/wordpress.git] / wp-admin / edit-comments.php
1 <?php
2 /**
3  * Edit Comments Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
12 if ( !current_user_can('edit_posts') )
13         wp_die(__('Cheatin&#8217; uh?'));
14
15 wp_enqueue_script('admin-comments');
16 enqueue_comment_hotkeys_js();
17
18 $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
19
20 if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
21         check_admin_referer('bulk-comments');
22
23         if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) {
24                 $comment_status = $wpdb->escape($_REQUEST['comment_status']);
25                 $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']);
26                 $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
27                 $doaction = 'delete';
28         } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) {
29                 $comment_ids = $_REQUEST['delete_comments'];
30                 $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
31         } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) {
32                 $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) );
33                 $doaction = $_REQUEST['action'];
34         } else {
35                 wp_redirect($_SERVER['HTTP_REFERER']);
36         }
37
38         $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
39
40         foreach ($comment_ids as $comment_id) { // Check the permissions on each
41                 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
42
43                 if ( !current_user_can('edit_post', $_post_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         $redirect_to = 'edit-comments.php';
79
80         if ( $approved )
81                 $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
82         if ( $unapproved )
83                 $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
84         if ( $spammed )
85                 $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
86         if ( $unspammed )
87                 $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
88         if ( $trashed )
89                 $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
90         if ( $untrashed )
91                 $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
92         if ( $deleted )
93                 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
94         if ( $trashed || $spammed )
95                 $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to );
96
97         if ( $post_id )
98                 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
99         if ( isset($_REQUEST['apage']) )
100                 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
101         if ( !empty($_REQUEST['mode']) )
102                 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
103         if ( !empty($_REQUEST['comment_status']) )
104                 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
105         if ( !empty($_REQUEST['s']) )
106                 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
107         wp_redirect( $redirect_to );
108 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
109          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
110          exit;
111 }
112
113 if ( $post_id )
114         $title = sprintf(__('Edit Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
115 else
116         $title = __('Edit Comments');
117
118 require_once('admin-header.php');
119
120 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
121
122 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
123 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash')) )
124         $comment_status = 'all';
125
126 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
127
128 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
129 $search = esc_attr( $search_dirty ); ?>
130
131 <div class="wrap">
132 <?php screen_icon(); ?>
133 <h2><?php echo esc_html( $title );
134 if ( isset($_GET['s']) && $_GET['s'] )
135         printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
136 </h2>
137
138 <?php
139 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) ) {
140         $approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
141         $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
142         $trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
143         $untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
144         $spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
145         $unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
146
147         if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 ) {
148                 echo '<div id="moderated" class="updated fade"><p>';
149
150                 if ( $approved > 0 ) {
151                         printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
152                         echo '<br />';
153                 }
154                 if ( $spammed > 0 ) {
155                         printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
156                         $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
157                         echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
158                 }
159                 if ( $unspammed > 0 ) {
160                         printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
161                         echo '<br />';
162                 }
163                 if ( $trashed > 0 ) {
164                         printf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed ), $trashed );
165                         $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
166                         echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
167                 }
168                 if ( $untrashed > 0 ) {
169                         printf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed );
170                         echo '<br />';
171                 }
172                 if ( $deleted > 0 ) {
173                         printf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
174                         echo '<br />';
175                 }
176
177                 echo '</p></div>';
178         }
179 }
180 ?>
181
182 <form id="comments-form" action="" method="get">
183 <ul class="subsubsub">
184 <?php
185 $status_links = array();
186 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
187 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
188 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
189 $stati = array(
190                 'all' => _n_noop('All', 'All'), // singular not used
191                 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
192                 'approved' => _n_noop('Approved', 'Approved'), // singular not used
193                 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
194                 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
195         );
196
197 if ( !EMPTY_TRASH_DAYS )
198         unset($stati['trash']);
199
200 $link = 'edit-comments.php';
201 if ( !empty($comment_type) && 'all' != $comment_type )
202         $link = add_query_arg( 'comment_type', $comment_type, $link );
203
204 foreach ( $stati as $status => $label ) {
205         $class = '';
206
207         if ( $status == $comment_status )
208                 $class = ' class="current"';
209         if ( !isset( $num_comments->$status ) )
210                 $num_comments->$status = 10;
211         $link = add_query_arg( 'comment_status', $status, $link );
212         if ( $post_id )
213                 $link = add_query_arg( 'p', absint( $post_id ), $link );
214         /*
215         // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
216         if ( !empty( $_GET['s'] ) )
217                 $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
218         */
219         $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
220                 _n( $label[0], $label[1], $num_comments->$status ),
221                 number_format_i18n( $num_comments->$status )
222         ) . '</a>';
223 }
224
225 $status_links = apply_filters( 'comment_status_links', $status_links );
226
227 echo implode( " |</li>\n", $status_links) . '</li>';
228 unset($status_links);
229 ?>
230 </ul>
231
232 <p class="search-box">
233         <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
234         <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
235         <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
236 </p>
237
238 <?php
239 $comments_per_page = (int) get_user_option( 'edit_comments_per_page', 0, false );
240 if ( empty( $comments_per_page ) || $comments_per_page < 1 )
241         $comments_per_page = 20;
242 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
243
244 if ( isset( $_GET['apage'] ) )
245         $page = abs( (int) $_GET['apage'] );
246 else
247         $page = 1;
248
249 $start = $offset = ( $page - 1 ) * $comments_per_page;
250
251 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
252
253 $_comment_post_ids = array();
254 foreach ( $_comments as $_c ) {
255         $_comment_post_ids[] = $_c->comment_post_ID;
256 }
257 $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
258 foreach ( (array) $_comment_post_ids as $_cpid )
259         $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
260 if ( empty($_comment_pending_count) )
261         $_comment_pending_count = array();
262
263 $comments = array_slice($_comments, 0, $comments_per_page);
264 $extra_comments = array_slice($_comments, $comments_per_page);
265
266 $page_links = paginate_links( array(
267         'base' => add_query_arg( 'apage', '%#%' ),
268         'format' => '',
269         'prev_text' => __('&laquo;'),
270         'next_text' => __('&raquo;'),
271         'total' => ceil($total / $comments_per_page),
272         'current' => $page
273 ));
274
275 ?>
276
277 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
278 <?php if ( $post_id ) : ?>
279 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
280 <?php endif; ?>
281 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
282 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
283
284 <div class="tablenav">
285
286 <?php if ( $page_links ) : ?>
287 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
288         number_format_i18n( $start + 1 ),
289         number_format_i18n( min( $page * $comments_per_page, $total ) ),
290         '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
291         $page_links
292 ); echo $page_links_text; ?></div>
293 <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
294 <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
295 <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
296 <?php endif; ?>
297
298 <div class="alignleft actions">
299 <select name="action">
300 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
301 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
302 <option value="unapprove"><?php _e('Unapprove'); ?></option>
303 <?php endif; ?>
304 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
305 <option value="approve"><?php _e('Approve'); ?></option>
306 <?php endif; ?>
307 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
308 <option value="spam"><?php _e('Mark as Spam'); ?></option>
309 <?php endif; ?>
310 <?php if ( 'trash' == $comment_status ): ?>
311 <option value="untrash"><?php _e('Restore'); ?></option>
312 <?php elseif ( 'spam' == $comment_status ): ?>
313 <option value="unspam"><?php _e('Not Spam'); ?></option>
314 <?php endif; ?>
315 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
316 <option value="delete"><?php _e('Delete Permanently'); ?></option>
317 <?php else: ?>
318 <option value="trash"><?php _e('Move to Trash'); ?></option>
319 <?php endif; ?>
320 </select>
321 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
322 <?php wp_nonce_field('bulk-comments'); ?>
323
324 <select name="comment_type">
325         <option value="all"><?php _e('Show all comment types'); ?></option>
326 <?php
327         $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
328                 'comment' => __('Comments'),
329                 'pings' => __('Pings'),
330         ) );
331
332         foreach ( $comment_types as $type => $label ) {
333                 echo "  <option value='" . esc_attr($type) . "'";
334                 selected( $comment_type, $type );
335                 echo ">$label</option>\n";
336         }
337 ?>
338 </select>
339 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
340
341 <?php if ( isset($_GET['apage']) ) { ?>
342         <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
343 <?php }
344
345 if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) {
346         wp_nonce_field('bulk-destroy', '_destroy_nonce');
347     if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
348                 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
349 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
350                 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
351 <?php }
352 } ?>
353 <?php do_action('manage_comments_nav', $comment_status); ?>
354 </div>
355
356 <br class="clear" />
357
358 </div>
359
360 <div class="clear"></div>
361
362 <?php if ( $comments ) { ?>
363 <table class="widefat comments fixed" cellspacing="0">
364 <thead>
365         <tr>
366 <?php print_column_headers('edit-comments'); ?>
367         </tr>
368 </thead>
369
370 <tfoot>
371         <tr>
372 <?php print_column_headers('edit-comments', false); ?>
373         </tr>
374 </tfoot>
375
376 <tbody id="the-comment-list" class="list:comment">
377 <?php
378         foreach ($comments as $comment)
379                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
380 ?>
381 </tbody>
382 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
383 <?php
384         foreach ($extra_comments as $comment)
385                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
386 ?>
387 </tbody>
388 </table>
389
390 <div class="tablenav">
391 <?php
392 if ( $page_links )
393         echo "<div class='tablenav-pages'>$page_links_text</div>";
394 ?>
395
396 <div class="alignleft actions">
397 <select name="action2">
398 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
399 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
400 <option value="unapprove"><?php _e('Unapprove'); ?></option>
401 <?php endif; ?>
402 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
403 <option value="approve"><?php _e('Approve'); ?></option>
404 <?php endif; ?>
405 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
406 <option value="spam"><?php _e('Mark as Spam'); ?></option>
407 <?php endif; ?>
408 <?php if ( 'trash' == $comment_status ): ?>
409 <option value="untrash"><?php _e('Restore'); ?></option>
410 <?php endif; ?>
411 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
412 <option value="delete"><?php _e('Delete Permanently'); ?></option>
413 <?php elseif ( 'spam' == $comment_status ): ?>
414 <option value="unspam"><?php _e('Not Spam'); ?></option>
415 <?php else: ?>
416 <option value="trash"><?php _e('Move to Trash'); ?></option>
417 <?php endif; ?>
418 </select>
419 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
420
421 <?php if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
422 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
423 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
424 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
425 <?php } ?>
426 <?php do_action('manage_comments_nav', $comment_status); ?>
427 </div>
428
429 <br class="clear" />
430 </div>
431
432 </form>
433
434 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
435         <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
436         <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
437         <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
438         <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
439         <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
440         <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
441         <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
442         <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
443 </form>
444
445 <div id="ajax-response"></div>
446
447 <?php } elseif ( 'moderated' == $comment_status ) { ?>
448 <p><?php _e('No comments awaiting moderation&hellip; yet.') ?></p>
449 </form>
450
451 <?php } else { ?>
452 <p><?php _e('No results found.') ?></p>
453 </form>
454
455 <?php } ?>
456 </div>
457
458 <?php
459 wp_comment_reply('-1', true, 'detail');
460 wp_comment_trashnotice();
461 include('admin-footer.php'); ?>