WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
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’ 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( wp_get_referer() ); 36 } 37 38 $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; 39 $redirect_to = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids'), wp_get_referer() ); 40 41 foreach ($comment_ids as $comment_id) { // Check the permissions on each 42 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); 43 44 if ( !current_user_can('edit_post', $_post_id) ) 45 continue; 46 47 switch( $doaction ) { 48 case 'approve' : 49 wp_set_comment_status($comment_id, 'approve'); 50 $approved++; 51 break; 52 case 'unapprove' : 53 wp_set_comment_status($comment_id, 'hold'); 54 $unapproved++; 55 break; 56 case 'spam' : 57 wp_spam_comment($comment_id); 58 $spammed++; 59 break; 60 case 'unspam' : 61 wp_unspam_comment($comment_id); 62 $unspammed++; 63 break; 64 case 'trash' : 65 wp_trash_comment($comment_id); 66 $trashed++; 67 break; 68 case 'untrash' : 69 wp_untrash_comment($comment_id); 70 $untrashed++; 71 break; 72 case 'delete' : 73 wp_delete_comment($comment_id); 74 $deleted++; 75 break; 76 } 77 } 78 79 if ( $approved ) 80 $redirect_to = add_query_arg( 'approved', $approved, $redirect_to ); 81 if ( $unapproved ) 82 $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to ); 83 if ( $spammed ) 84 $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); 85 if ( $unspammed ) 86 $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); 87 if ( $trashed ) 88 $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to ); 89 if ( $untrashed ) 90 $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to ); 91 if ( $deleted ) 92 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); 93 if ( $trashed || $spammed ) 94 $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to ); 95 96 wp_redirect( $redirect_to ); 97 exit; 98 } elseif ( ! empty($_GET['_wp_http_referer']) ) { 99 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); 100 exit; 101 } 102 103 if ( $post_id ) 104 $title = sprintf(__('Edit Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50)); 105 else 106 $title = __('Edit Comments'); 107 108 require_once ('admin-header.php'); 109 110 $mode = ( empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']); 111 112 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all'; 113 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash')) ) 114 $comment_status = 'all'; 115 116 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : ''; 117 118 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : ''; 119 $search = esc_attr( $search_dirty ); ?> 120 121 <div class="wrap"> 122 <?php screen_icon(); ?> 123 <h2><?php echo esc_html( $title ); 124 if ( isset($_GET['s']) && $_GET['s'] ) 125 printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?> 126 </h2> 127 128 <?php 129 if ( isset( $_GET['error'] ) ) { 130 $error = (int) $_GET['error']; 131 $error_msg = ''; 132 switch ( $error ) { 133 case 1 : 134 $error_msg = __( 'Oops, no comment with this ID.' ); 135 break; 136 case 2 : 137 $error_msg = __( 'You are not allowed to edit comments on this post.' ); 138 break; 139 } 140 if ( $error_msg ) 141 echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>'; 142 } 143 144 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) || isset($_GET['same']) ) { 145 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0; 146 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0; 147 $trashed = isset( $_GET['trashed'] ) ? (int) $_GET['trashed'] : 0; 148 $untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0; 149 $spammed = isset( $_GET['spammed'] ) ? (int) $_GET['spammed'] : 0; 150 $unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0; 151 $same = isset( $_GET['same'] ) ? (int) $_GET['same'] : 0; 152 153 if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) { 154 if ( $approved > 0 ) 155 $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved ); 156 157 if ( $spammed > 0 ) { 158 $ids = isset($_GET['ids']) ? $_GET['ids'] : 0; 159 $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 />'; 160 } 161 162 if ( $unspammed > 0 ) 163 $messages = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed ); 164 165 if ( $trashed > 0 ) { 166 $ids = isset($_GET['ids']) ? $_GET['ids'] : 0; 167 $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 />'; 168 } 169 170 if ( $untrashed > 0 ) 171 $messages[] = sprintf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed ); 172 173 if ( $deleted > 0 ) 174 $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted ); 175 176 if ( $same > 0 && $comment = get_comment( $same ) ) { 177 switch ( $comment->comment_approved ) { 178 case '1' : 179 $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; 180 break; 181 case 'trash' : 182 $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>'; 183 break; 184 case 'spam' : 185 $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; 186 break; 187 } 188 } 189 190 echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>'; 191 } 192 } 193 ?> 194 195 <form id="comments-form" action="" method="get"> 196 <ul class="subsubsub"> 197 <?php 198 $status_links = array(); 199 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); 200 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 201 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>") 202 $stati = array( 203 'all' => _nx_noop('All', 'All', 'comments'), // singular not used 204 '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>'), 205 'approved' => _n_noop('Approved', 'Approved'), // singular not used 206 '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>'), 207 '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>') 208 ); 209 210 if ( !EMPTY_TRASH_DAYS ) 211 unset($stati['trash']); 212 213 $link = 'edit-comments.php'; 214 if ( !empty($comment_type) && 'all' != $comment_type ) 215 $link = add_query_arg( 'comment_type', $comment_type, $link ); 216 217 foreach ( $stati as $status => $label ) { 218 $class = ( $status == $comment_status ) ? ' class="current"' : ''; 219 220 if ( !isset( $num_comments->$status ) ) 221 $num_comments->$status = 10; 222 if ( empty( $num_comments->$status ) ) 223 continue; 224 $link = add_query_arg( 'comment_status', $status, $link ); 225 if ( $post_id ) 226 $link = add_query_arg( 'p', absint( $post_id ), $link ); 227 /* 228 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark 229 if ( !empty( $_GET['s'] ) ) 230 $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link ); 231 */ 232 $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf( 233 _n( $label[0], $label[1], $num_comments->$status ), 234 number_format_i18n( $num_comments->$status ) 235 ) . '</a>'; 236 } 237 238 $status_links = apply_filters( 'comment_status_links', $status_links ); 239 240 echo implode( " |</li>\n", $status_links) . '</li>'; 241 unset($status_links); 242 ?> 243 </ul> 244 245 <p class="search-box"> 246 <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label> 247 <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" /> 248 <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" /> 249 </p> 250 251 <?php 252 $comments_per_page = (int) get_user_option( 'edit_comments_per_page' ); 253 if ( empty( $comments_per_page ) || $comments_per_page < 1 ) 254 $comments_per_page = 20; 255 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); 256 257 if ( isset( $_GET['apage'] ) ) 258 $page = abs( (int) $_GET['apage'] ); 259 else 260 $page = 1; 261 262 $start = $offset = ( $page - 1 ) * $comments_per_page; 263 264 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra 265 266 $_comment_post_ids = array(); 267 foreach ( $_comments as $_c ) { 268 $_comment_post_ids[] = $_c->comment_post_ID; 269 } 270 271 $_comment_pending_count = get_pending_comments_num($_comment_post_ids); 272 273 $comments = array_slice($_comments, 0, $comments_per_page); 274 $extra_comments = array_slice($_comments, $comments_per_page); 275 276 $page_links = paginate_links( array( 277 'base' => add_query_arg( 'apage', '%#%' ), 278 'format' => '', 279 'prev_text' => __('«'), 280 'next_text' => __('»'), 281 'total' => ceil($total / $comments_per_page), 282 'current' => $page 283 )); 284 285 ?> 286 287 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" /> 288 <?php if ( $post_id ) : ?> 289 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" /> 290 <?php endif; ?> 291 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" /> 292 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" /> 293 294 <div class="tablenav"> 295 296 <?php if ( $comments ) { ?> 297 <?php if ( $page_links ) : ?> 298 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s', 299 number_format_i18n( $start + 1 ), 300 number_format_i18n( min( $page * $comments_per_page, $total ) ), 301 '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>', 302 $page_links 303 ); echo $page_links_text; ?></div> 304 <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" /> 305 <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" /> 306 <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" /> 307 <?php endif; ?> 308 309 <div class="alignleft actions"> 310 <select name="action"> 311 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option> 312 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 313 <option value="unapprove"><?php _e('Unapprove'); ?></option> 314 <?php endif; ?> 315 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 316 <option value="approve"><?php _e('Approve'); ?></option> 317 <?php endif; ?> 318 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?> 319 <option value="spam"><?php _e('Mark as Spam'); ?></option> 320 <?php endif; ?> 321 <?php if ( 'trash' == $comment_status ): ?> 322 <option value="untrash"><?php _e('Restore'); ?></option> 323 <?php elseif ( 'spam' == $comment_status ): ?> 324 <option value="unspam"><?php _e('Not Spam'); ?></option> 325 <?php endif; ?> 326 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?> 327 <option value="delete"><?php _e('Delete Permanently'); ?></option> 328 <?php else: ?> 329 <option value="trash"><?php _e('Move to Trash'); ?></option> 330 <?php endif; ?> 331 </select> 332 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 333 <?php wp_nonce_field('bulk-comments'); ?> 334 335 <select name="comment_type"> 336 <option value="all"><?php _e('Show all comment types'); ?></option> 337 <?php 338 $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 339 'comment' => __('Comments'), 340 'pings' => __('Pings'), 341 ) ); 342 343 foreach ( $comment_types as $type => $label ) { 344 echo " <option value='" . esc_attr($type) . "'"; 345 selected( $comment_type, $type ); 346 echo ">$label</option>\n"; 347 } 348 ?> 349 </select> 350 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" /> 351 352 <?php if ( isset($_GET['apage']) ) { ?> 353 <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" /> 354 <?php } 355 356 if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) { 357 wp_nonce_field('bulk-destroy', '_destroy_nonce'); 358 if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?> 359 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" /> 360 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?> 361 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" /> 362 <?php } 363 } ?> 364 <?php do_action('manage_comments_nav', $comment_status); ?> 365 </div> 366 367 <br class="clear" /> 368 369 </div> 370 371 <div class="clear"></div> 372 373 <table class="widefat comments fixed" cellspacing="0"> 374 <thead> 375 <tr> 376 <?php print_column_headers('edit-comments'); ?> 377 </tr> 378 </thead> 379 380 <tfoot> 381 <tr> 382 <?php print_column_headers('edit-comments', false); ?> 383 </tr> 384 </tfoot> 385 386 <tbody id="the-comment-list" class="list:comment"> 387 <?php 388 foreach ($comments as $comment) 389 _wp_comment_row( $comment->comment_ID, $mode, $comment_status ); 390 ?> 391 </tbody> 392 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;"> 393 <?php 394 foreach ($extra_comments as $comment) 395 _wp_comment_row( $comment->comment_ID, $mode, $comment_status ); 396 ?> 397 </tbody> 398 </table> 399 400 <div class="tablenav"> 401 <?php 402 if ( $page_links ) 403 echo "<div class='tablenav-pages'>$page_links_text</div>"; 404 ?> 405 406 <div class="alignleft actions"> 407 <select name="action2"> 408 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option> 409 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 410 <option value="unapprove"><?php _e('Unapprove'); ?></option> 411 <?php endif; ?> 412 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 413 <option value="approve"><?php _e('Approve'); ?></option> 414 <?php endif; ?> 415 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?> 416 <option value="spam"><?php _e('Mark as Spam'); ?></option> 417 <?php endif; ?> 418 <?php if ( 'trash' == $comment_status ): ?> 419 <option value="untrash"><?php _e('Restore'); ?></option> 420 <?php endif; ?> 421 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?> 422 <option value="delete"><?php _e('Delete Permanently'); ?></option> 423 <?php elseif ( 'spam' == $comment_status ): ?> 424 <option value="unspam"><?php _e('Not Spam'); ?></option> 425 <?php else: ?> 426 <option value="trash"><?php _e('Move to Trash'); ?></option> 427 <?php endif; ?> 428 </select> 429 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 430 431 <?php if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?> 432 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" /> 433 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?> 434 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" /> 435 <?php } ?> 436 <?php do_action('manage_comments_nav', $comment_status); ?> 437 </div> 438 439 <br class="clear" /> 440 </div> 441 442 </form> 443 444 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;"> 445 <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" /> 446 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" /> 447 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" /> 448 <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" /> 449 <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" /> 450 <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" /> 451 <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" /> 452 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?> 453 </form> 454 455 <div id="ajax-response"></div> 456 457 <?php } elseif ( 'moderated' == $comment_status ) { ?> 458 <p><?php _e('No comments awaiting moderation… yet.') ?></p> 459 </form> 460 461 <?php } else { ?> 462 <p><?php _e('No comments found.') ?></p> 463 </form> 464 465 <?php } ?> 466 </div> 467 468 <?php 469 wp_comment_reply('-1', true, 'detail'); 470 wp_comment_trashnotice(); 471 include ('admin-footer.php'); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |