Wordpress 2.8.5-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['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spam2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
21         check_admin_referer('bulk-spam-delete', '_spam_nonce');
22
23         $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
24         if ( current_user_can('moderate_comments')) {
25                 $deleted_spam = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
26         } else {
27                 $deleted_spam = 0;
28         }
29         $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam;
30         if ( $post_id )
31                 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
32         wp_redirect( $redirect_to );
33 } elseif ( isset($_REQUEST['delete_comments']) && isset($_REQUEST['action']) && ( -1 != $_REQUEST['action'] || -1 != $_REQUEST['action2'] ) ) {
34         check_admin_referer('bulk-comments');
35         $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
36
37         $deleted = $approved = $unapproved = $spammed = 0;
38         foreach ( (array) $_REQUEST['delete_comments'] as $comment_id) : // Check the permissions on each
39                 $comment_id = (int) $comment_id;
40                 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
41
42                 if ( !current_user_can('edit_post', $_post_id) )
43                         continue;
44
45                 switch( $doaction ) {
46                         case 'markspam' :
47                                 wp_set_comment_status($comment_id, 'spam');
48                                 $spammed++;
49                                 break;
50                         case 'delete' :
51                                 wp_set_comment_status($comment_id, 'delete');
52                                 $deleted++;
53                                 break;
54                         case 'approve' :
55                                 wp_set_comment_status($comment_id, 'approve');
56                                 $approved++;
57                                 break;
58                         case 'unapprove' :
59                                 wp_set_comment_status($comment_id, 'hold');
60                                 $unapproved++;
61                                 break;
62                 }
63         endforeach;
64
65         $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved;
66         if ( $post_id )
67                 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
68         if ( isset($_REQUEST['apage']) )
69                 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
70         if ( !empty($_REQUEST['mode']) )
71                 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
72         if ( !empty($_REQUEST['comment_status']) )
73                 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
74         if ( !empty($_REQUEST['s']) )
75                 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
76         wp_redirect( $redirect_to );
77 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
78          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
79          exit;
80 }
81
82 if ( $post_id )
83         $title = sprintf(__('Edit Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
84 else
85         $title = __('Edit Comments');
86
87 require_once('admin-header.php');
88
89 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
90
91 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
92 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
93         $comment_status = 'all';
94
95 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
96
97 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
98 $search = esc_attr( $search_dirty ); ?>
99
100 <div class="wrap">
101 <?php screen_icon(); ?>
102 <h2><?php echo esc_html( $title );
103 if ( isset($_GET['s']) && $_GET['s'] )
104         printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
105 </h2>
106
107 <?php
108 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
109         $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
110         $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
111         $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
112
113         if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
114                 echo '<div id="moderated" class="updated fade"><p>';
115
116                 if ( $approved > 0 ) {
117                         printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
118                         echo '<br />';
119                 }
120
121                 if ( $deleted > 0 ) {
122                         printf( _n( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
123                         echo '<br />';
124                 }
125
126                 if ( $spam > 0 ) {
127                         printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
128                         echo '<br />';
129                 }
130
131                 echo '</p></div>';
132         }
133 }
134 ?>
135
136 <form id="comments-form" action="" method="get">
137 <ul class="subsubsub">
138 <?php
139 $status_links = array();
140 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
141 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
142 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
143 $stati = array(
144                 'all' => _n_noop('All', 'All'), // singular not used
145                 'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
146                 'approved' => _n_noop('Approved', 'Approved'), // singular not used
147                 'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
148         );
149 $link = 'edit-comments.php';
150 if ( !empty($comment_type) && 'all' != $comment_type )
151         $link = add_query_arg( 'comment_type', $comment_type, $link );
152 foreach ( $stati as $status => $label ) {
153         $class = '';
154
155         if ( $status == $comment_status )
156                 $class = ' class="current"';
157         if ( !isset( $num_comments->$status ) )
158                 $num_comments->$status = 10;
159         $link = add_query_arg( 'comment_status', $status, $link );
160         if ( $post_id )
161                 $link = add_query_arg( 'p', absint( $post_id ), $link );
162         /*
163         // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
164         if ( !empty( $_GET['s'] ) )
165                 $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
166         */
167         $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
168                 _n( $label[0], $label[1], $num_comments->$status ),
169                 number_format_i18n( $num_comments->$status )
170         ) . '</a>';
171 }
172
173 $status_links = apply_filters( 'comment_status_links', $status_links );
174
175 echo implode( " |</li>\n", $status_links) . '</li>';
176 unset($status_links);
177 ?>
178 </ul>
179
180 <p class="search-box">
181         <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
182         <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
183         <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
184 </p>
185
186 <?php
187 $comments_per_page = get_user_option('edit_comments_per_page');
188 if ( empty($comments_per_page) )
189         $comments_per_page = 20;
190 $comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status);
191
192 if ( isset( $_GET['apage'] ) )
193         $page = abs( (int) $_GET['apage'] );
194 else
195         $page = 1;
196
197 $start = $offset = ( $page - 1 ) * $comments_per_page;
198
199 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
200
201 $_comment_post_ids = array();
202 foreach ( $_comments as $_c ) {
203         $_comment_post_ids[] = $_c->comment_post_ID;
204 }
205 $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
206 foreach ( (array) $_comment_post_ids as $_cpid )
207         $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
208 if ( empty($_comment_pending_count) )
209         $_comment_pending_count = array();
210
211 $comments = array_slice($_comments, 0, $comments_per_page);
212 $extra_comments = array_slice($_comments, $comments_per_page);
213
214 $page_links = paginate_links( array(
215         'base' => add_query_arg( 'apage', '%#%' ),
216         'format' => '',
217         'prev_text' => __('&laquo;'),
218         'next_text' => __('&raquo;'),
219         'total' => ceil($total / $comments_per_page),
220         'current' => $page
221 ));
222
223 ?>
224
225 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
226 <?php if ( $post_id ) : ?>
227 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
228 <?php endif; ?>
229 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
230 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
231
232 <div class="tablenav">
233
234 <?php if ( $page_links ) : ?>
235 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
236         number_format_i18n( $start + 1 ),
237         number_format_i18n( min( $page * $comments_per_page, $total ) ),
238         '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
239         $page_links
240 ); echo $page_links_text; ?></div>
241 <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
242 <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
243 <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
244 <?php endif; ?>
245
246 <div class="alignleft actions">
247 <select name="action">
248 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
249 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
250 <option value="unapprove"><?php _e('Unapprove'); ?></option>
251 <?php endif; ?>
252 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
253 <option value="approve"><?php _e('Approve'); ?></option>
254 <?php endif; ?>
255 <?php if ( 'spam' != $comment_status ): ?>
256 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
257 <?php endif; ?>
258 <option value="delete"><?php _e('Delete'); ?></option>
259 </select>
260 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
261 <?php wp_nonce_field('bulk-comments'); ?>
262
263 <select name="comment_type">
264         <option value="all"><?php _e('Show all comment types'); ?></option>
265 <?php
266         $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
267                 'comment' => __('Comments'),
268                 'pings' => __('Pings'),
269         ) );
270
271         foreach ( $comment_types as $type => $label ) {
272                 echo "  <option value='" . esc_attr($type) . "'";
273                 selected( $comment_type, $type );
274                 echo ">$label</option>\n";
275         }
276 ?>
277 </select>
278 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
279
280 <?php if ( isset($_GET['apage']) ) { ?>
281         <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
282 <?php }
283
284 if ( 'spam' == $comment_status ) {
285         wp_nonce_field('bulk-spam-delete', '_spam_nonce');
286         if ( current_user_can ('moderate_comments')) { ?>
287                 <input type="submit" name="delete_all_spam" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
288 <?php   }
289 } ?>
290 <?php do_action('manage_comments_nav', $comment_status); ?>
291 </div>
292
293 <br class="clear" />
294
295 </div>
296
297 <div class="clear"></div>
298
299 <?php if ( $comments ) { ?>
300 <table class="widefat comments fixed" cellspacing="0">
301 <thead>
302         <tr>
303 <?php print_column_headers('edit-comments'); ?>
304         </tr>
305 </thead>
306
307 <tfoot>
308         <tr>
309 <?php print_column_headers('edit-comments', false); ?>
310         </tr>
311 </tfoot>
312
313 <tbody id="the-comment-list" class="list:comment">
314 <?php
315         foreach ($comments as $comment)
316                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
317 ?>
318 </tbody>
319 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
320 <?php
321         foreach ($extra_comments as $comment)
322                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
323 ?>
324 </tbody>
325 </table>
326
327 <div class="tablenav">
328 <?php
329 if ( $page_links )
330         echo "<div class='tablenav-pages'>$page_links_text</div>";
331 ?>
332
333 <div class="alignleft actions">
334 <select name="action2">
335 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
336 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
337 <option value="unapprove"><?php _e('Unapprove'); ?></option>
338 <?php endif; ?>
339 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
340 <option value="approve"><?php _e('Approve'); ?></option>
341 <?php endif; ?>
342 <?php if ( 'spam' != $comment_status ): ?>
343 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
344 <?php endif; ?>
345 <option value="delete"><?php _e('Delete'); ?></option>
346 </select>
347 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
348
349 <?php if ( 'spam' == $comment_status ) { ?>
350 <input type="submit" name="delete_all_spam2" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
351 <?php } ?>
352 <?php do_action('manage_comments_nav', $comment_status); ?>
353 </div>
354
355 <br class="clear" />
356 </div>
357
358 </form>
359
360 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
361         <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
362         <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
363         <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
364         <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
365         <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
366         <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
367         <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
368         <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
369 </form>
370
371 <div id="ajax-response"></div>
372
373 <?php } elseif ( 'moderated' == $comment_status ) { ?>
374 <p><?php _e('No comments awaiting moderation&hellip; yet.') ?></p>
375 </form>
376
377 <?php } else { ?>
378 <p><?php _e('No results found.') ?></p>
379 </form>
380
381 <?php } ?>
382 </div>
383
384 <?php
385 wp_comment_reply('-1', true, 'detail');
386 include('admin-footer.php'); ?>