web/wp-admin/includes/class-wp-comments-list-table.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    19 
    19 
    20 	var $checkbox = true;
    20 	var $checkbox = true;
    21 
    21 
    22 	var $pending_count = array();
    22 	var $pending_count = array();
    23 
    23 
    24 	function __construct() {
    24 	function __construct( $args = array() ) {
    25 		global $post_id;
    25 		global $post_id;
    26 
    26 
    27 		$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
    27 		$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
    28 
    28 
    29 		if ( get_option('show_avatars') )
    29 		if ( get_option('show_avatars') )
    31 
    31 
    32 		parent::__construct( array(
    32 		parent::__construct( array(
    33 			'plural' => 'comments',
    33 			'plural' => 'comments',
    34 			'singular' => 'comment',
    34 			'singular' => 'comment',
    35 			'ajax' => true,
    35 			'ajax' => true,
       
    36 			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    36 		) );
    37 		) );
    37 	}
    38 	}
    38 
    39 
    39 	function ajax_user_can() {
    40 	function ajax_user_can() {
    40 		return current_user_can('edit_posts');
    41 		return current_user_can('edit_posts');
    79 			$start += $_REQUEST['offset'];
    80 			$start += $_REQUEST['offset'];
    80 		}
    81 		}
    81 
    82 
    82 		$status_map = array(
    83 		$status_map = array(
    83 			'moderated' => 'hold',
    84 			'moderated' => 'hold',
    84 			'approved' => 'approve'
    85 			'approved' => 'approve',
       
    86 			'all' => '',
    85 		);
    87 		);
    86 
    88 
    87 		$args = array(
    89 		$args = array(
    88 			'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
    90 			'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
    89 			'search' => $search,
    91 			'search' => $search,
   222 				foreach ( $comment_types as $type => $label )
   224 				foreach ( $comment_types as $type => $label )
   223 					echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n";
   225 					echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n";
   224 			?>
   226 			?>
   225 			</select>
   227 			</select>
   226 <?php
   228 <?php
   227 			submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
   229 			do_action( 'restrict_manage_comments' );
       
   230 			submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
   228 		}
   231 		}
   229 
   232 
   230 		if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) {
   233 		if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) {
   231 			wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
   234 			wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
   232 			$title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
   235 			$title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
   233 			submit_button( $title, 'button-secondary apply', 'delete_all', false );
   236 			submit_button( $title, 'apply', 'delete_all', false );
   234 		}
   237 		}
   235 		do_action( 'manage_comments_nav', $comment_status );
   238 		do_action( 'manage_comments_nav', $comment_status );
   236 		echo '</div>';
   239 		echo '</div>';
   237 	}
   240 	}
   238 
   241 
   286 	<tr>
   289 	<tr>
   287 		<?php $this->print_column_headers( false ); ?>
   290 		<?php $this->print_column_headers( false ); ?>
   288 	</tr>
   291 	</tr>
   289 	</tfoot>
   292 	</tfoot>
   290 
   293 
   291 	<tbody id="the-comment-list" class="list:comment">
   294 	<tbody id="the-comment-list" data-wp-lists="list:comment">
   292 		<?php $this->display_rows_or_placeholder(); ?>
   295 		<?php $this->display_rows_or_placeholder(); ?>
   293 	</tbody>
   296 	</tbody>
   294 
   297 
   295 	<tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
   298 	<tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
   296 		<?php $this->items = $this->extra_items; $this->display_rows(); ?>
   299 		<?php $this->items = $this->extra_items; $this->display_rows(); ?>
   297 	</tbody>
   300 	</tbody>
   298 </table>
   301 </table>
   299 <?php
   302 <?php
   300 
   303 
   315 		echo $this->single_row_columns( $comment );
   318 		echo $this->single_row_columns( $comment );
   316 		echo "</tr>\n";
   319 		echo "</tr>\n";
   317 	}
   320 	}
   318 
   321 
   319 	function column_cb( $comment ) {
   322 	function column_cb( $comment ) {
   320 		if ( $this->user_can )
   323 		if ( $this->user_can ) { ?>
   321 			echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
   324 		<label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
       
   325 		<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
       
   326 		<?php
       
   327 		}
   322 	}
   328 	}
   323 
   329 
   324 	function column_comment( $comment ) {
   330 	function column_comment( $comment ) {
   325 		global $post, $comment_status;
   331 		global $comment_status;
       
   332 		$post = get_post();
   326 
   333 
   327 		$user_can = $this->user_can;
   334 		$user_can = $this->user_can;
   328 
   335 
   329 		$comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
   336 		$comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
   330 		$the_comment_status = wp_get_comment_status( $comment->comment_ID );
   337 		$the_comment_status = wp_get_comment_status( $comment->comment_ID );
   331 
   338 
   332 		$ptime = date( 'G', strtotime( $comment->comment_date ) );
   339 		$ptime = date( 'G', strtotime( $comment->comment_date ) );
   333 		if ( ( abs( time() - $ptime ) ) < 86400 )
   340 		if ( ( abs( time() - $ptime ) ) < DAY_IN_SECONDS )
   334 			$ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) );
   341 			$ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) );
   335 		else
   342 		else
   336 			$ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date );
   343 			$ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date );
   337 
   344 
   338 		if ( $user_can ) {
   345 		if ( $user_can ) {
   387 				'trash' => '', 'untrash' => '', 'delete' => ''
   394 				'trash' => '', 'untrash' => '', 'delete' => ''
   388 			);
   395 			);
   389 
   396 
   390 			if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
   397 			if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
   391 				if ( 'approved' == $the_comment_status )
   398 				if ( 'approved' == $the_comment_status )
   392 					$actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
   399 					$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
   393 				else if ( 'unapproved' == $the_comment_status )
   400 				else if ( 'unapproved' == $the_comment_status )
   394 					$actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
   401 					$actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
   395 			} else {
   402 			} else {
   396 				$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
   403 				$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
   397 				$actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
   404 				$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
   398 			}
   405 			}
   399 
   406 
   400 			if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
   407 			if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
   401 				$actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
   408 				$actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
   402 			} elseif ( 'spam' == $the_comment_status ) {
   409 			} elseif ( 'spam' == $the_comment_status ) {
   403 				$actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
   410 				$actions['unspam'] = "<a href='$unspam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' class='vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
   404 			} elseif ( 'trash' == $the_comment_status ) {
   411 			} elseif ( 'trash' == $the_comment_status ) {
   405 				$actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
   412 				$actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
   406 			}
   413 			}
   407 
   414 
   408 			if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
   415 			if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
   409 				$actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
   416 				$actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
   410 			} else {
   417 			} else {
   411 				$actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
   418 				$actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
   412 			}
   419 			}
   413 
   420 
   414 			if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
   421 			if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
   415 				$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
   422 				$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
   416 				$actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
   423 				$actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
   474 	function column_date( $comment ) {
   481 	function column_date( $comment ) {
   475 		return get_comment_date( __( 'Y/m/d \a\t g:ia' ) );
   482 		return get_comment_date( __( 'Y/m/d \a\t g:ia' ) );
   476 	}
   483 	}
   477 
   484 
   478 	function column_response( $comment ) {
   485 	function column_response( $comment ) {
   479 		global $post;
   486 		$post = get_post();
   480 
   487 
   481 		if ( isset( $this->pending_count[$post->ID] ) ) {
   488 		if ( isset( $this->pending_count[$post->ID] ) ) {
   482 			$pending_comments = $this->pending_count[$post->ID];
   489 			$pending_comments = $this->pending_count[$post->ID];
   483 		} else {
   490 		} else {
   484 			$_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
   491 			$_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
   543 		extract( $this->_args );
   550 		extract( $this->_args );
   544 
   551 
   545 		wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
   552 		wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
   546 ?>
   553 ?>
   547 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0" style="display:none;">
   554 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0" style="display:none;">
   548 	<tbody id="the-comment-list"<?php if ( $singular ) echo " class='list:$singular'"; ?>>
   555 	<tbody id="the-comment-list"<?php if ( $singular ) echo " data-wp-lists='list:$singular'"; ?>>
   549 		<?php if ( ! $output_empty ) $this->display_rows_or_placeholder(); ?>
   556 		<?php if ( ! $output_empty ) $this->display_rows_or_placeholder(); ?>
   550 	</tbody>
   557 	</tbody>
   551 </table>
   558 </table>
   552 <?php
   559 <?php
   553 	}
   560 	}