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