]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-comments-list-table.php
WordPress 4.3
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-comments-list-table.php
1 <?php
2 /**
3  * Comments and Post Comments List Table classes.
4  *
5  * @package WordPress
6  * @subpackage List_Table
7  * @since 3.1.0
8  */
9
10 /**
11  * Comments List Table class.
12  *
13  * @package WordPress
14  * @subpackage List_Table
15  * @since 3.1.0
16  * @access private
17  */
18 class WP_Comments_List_Table extends WP_List_Table {
19
20         public $checkbox = true;
21
22         public $pending_count = array();
23
24         public $extra_items;
25
26         private $user_can;
27
28         /**
29          * Constructor.
30          *
31          * @since 3.1.0
32          * @access public
33          *
34          * @see WP_List_Table::__construct() for more information on default arguments.
35          *
36          * @global int $post_id
37          *
38          * @param array $args An associative array of arguments.
39          */
40         public function __construct( $args = array() ) {
41                 global $post_id;
42
43                 $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
44
45                 if ( get_option('show_avatars') )
46                         add_filter( 'comment_author', 'floated_admin_avatar' );
47
48                 parent::__construct( array(
49                         'plural' => 'comments',
50                         'singular' => 'comment',
51                         'ajax' => true,
52                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
53                 ) );
54         }
55
56         /**
57          * @return bool
58          */
59         public function ajax_user_can() {
60                 return current_user_can('edit_posts');
61         }
62
63         /**
64          *
65          * @global int    $post_id
66          * @global string $comment_status
67          * @global string $search
68          * @global string $comment_type
69          */
70         public function prepare_items() {
71                 global $post_id, $comment_status, $search, $comment_type;
72
73                 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
74                 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
75                         $comment_status = 'all';
76
77                 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
78
79                 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
80
81                 $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
82
83                 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
84
85                 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
86                 $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
87
88                 $comments_per_page = $this->get_per_page( $comment_status );
89
90                 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
91
92                 if ( isset( $_REQUEST['number'] ) ) {
93                         $number = (int) $_REQUEST['number'];
94                 }
95                 else {
96                         $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
97                 }
98
99                 $page = $this->get_pagenum();
100
101                 if ( isset( $_REQUEST['start'] ) ) {
102                         $start = $_REQUEST['start'];
103                 } else {
104                         $start = ( $page - 1 ) * $comments_per_page;
105                 }
106
107                 if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
108                         $start += $_REQUEST['offset'];
109                 }
110
111                 $status_map = array(
112                         'moderated' => 'hold',
113                         'approved' => 'approve',
114                         'all' => '',
115                 );
116
117                 $args = array(
118                         'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
119                         'search' => $search,
120                         'user_id' => $user_id,
121                         'offset' => $start,
122                         'number' => $number,
123                         'post_id' => $post_id,
124                         'type' => $comment_type,
125                         'orderby' => $orderby,
126                         'order' => $order,
127                         'post_type' => $post_type,
128                 );
129
130                 $_comments = get_comments( $args );
131                 if ( is_array( $_comments ) ) {
132                         update_comment_cache( $_comments );
133
134                         $this->items = array_slice( $_comments, 0, $comments_per_page );
135                         $this->extra_items = array_slice( $_comments, $comments_per_page );
136
137                         $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
138
139                         $this->pending_count = get_pending_comments_num( $_comment_post_ids );
140                 }
141
142                 $total_comments = get_comments( array_merge( $args, array(
143                         'count' => true,
144                         'offset' => 0,
145                         'number' => 0
146                 ) ) );
147
148                 $this->set_pagination_args( array(
149                         'total_items' => $total_comments,
150                         'per_page' => $comments_per_page,
151                 ) );
152         }
153
154         /**
155          *
156          * @param string $comment_status
157          * @return int
158          */
159         public function get_per_page( $comment_status = 'all' ) {
160                 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
161                 /**
162                  * Filter the number of comments listed per page in the comments list table.
163                  *
164                  * @since 2.6.0
165                  *
166                  * @param int    $comments_per_page The number of comments to list per page.
167                  * @param string $comment_status    The comment status name. Default 'All'.
168                  */
169                 return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
170         }
171
172         /**
173          *
174          * @global string $comment_status
175          */
176         public function no_items() {
177                 global $comment_status;
178
179                 if ( 'moderated' == $comment_status )
180                         _e( 'No comments awaiting moderation.' );
181                 else
182                         _e( 'No comments found.' );
183         }
184
185         /**
186          *
187          * @global int $post_id
188          * @global string $comment_status
189          * @global string $comment_type
190          */
191         protected function get_views() {
192                 global $post_id, $comment_status, $comment_type;
193
194                 $status_links = array();
195                 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
196                 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
197                 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
198                 $stati = array(
199                                 'all' => _nx_noop('All', 'All', 'comments'), // singular not used
200                                 '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>'),
201                                 'approved' => _n_noop('Approved', 'Approved'), // singular not used
202                                 '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>'),
203                                 '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>')
204                         );
205
206                 if ( !EMPTY_TRASH_DAYS )
207                         unset($stati['trash']);
208
209                 $link = 'edit-comments.php';
210                 if ( !empty($comment_type) && 'all' != $comment_type )
211                         $link = add_query_arg( 'comment_type', $comment_type, $link );
212
213                 foreach ( $stati as $status => $label ) {
214                         $class = ( $status == $comment_status ) ? ' class="current"' : '';
215
216                         if ( !isset( $num_comments->$status ) )
217                                 $num_comments->$status = 10;
218                         $link = add_query_arg( 'comment_status', $status, $link );
219                         if ( $post_id )
220                                 $link = add_query_arg( 'p', absint( $post_id ), $link );
221                         /*
222                         // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
223                         if ( !empty( $_REQUEST['s'] ) )
224                                 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
225                         */
226                         $status_links[$status] = "<a href='$link'$class>" . sprintf(
227                                 translate_nooped_plural( $label, $num_comments->$status ),
228                                 number_format_i18n( $num_comments->$status )
229                         ) . '</a>';
230                 }
231
232                 /**
233                  * Filter the comment status links.
234                  *
235                  * @since 2.5.0
236                  *
237                  * @param array $status_links An array of fully-formed status links. Default 'All'.
238                  *                            Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
239                  */
240                 return apply_filters( 'comment_status_links', $status_links );
241         }
242
243         /**
244          *
245          * @global string $comment_status
246          *
247          * @return array
248          */
249         protected function get_bulk_actions() {
250                 global $comment_status;
251
252                 $actions = array();
253                 if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
254                         $actions['unapprove'] = __( 'Unapprove' );
255                 if ( in_array( $comment_status, array( 'all', 'moderated' ) ) )
256                         $actions['approve'] = __( 'Approve' );
257                 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) )
258                         $actions['spam'] = _x( 'Mark as Spam', 'comment' );
259
260                 if ( 'trash' == $comment_status )
261                         $actions['untrash'] = __( 'Restore' );
262                 elseif ( 'spam' == $comment_status )
263                         $actions['unspam'] = _x( 'Not Spam', 'comment' );
264
265                 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
266                         $actions['delete'] = __( 'Delete Permanently' );
267                 else
268                         $actions['trash'] = __( 'Move to Trash' );
269
270                 return $actions;
271         }
272
273         /**
274          *
275          * @global string $comment_status
276          * @global string $comment_type
277          *
278          * @param string $which
279          */
280         protected function extra_tablenav( $which ) {
281                 global $comment_status, $comment_type;
282 ?>
283                 <div class="alignleft actions">
284 <?php
285                 if ( 'top' == $which ) {
286 ?>
287                         <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
288                         <select id="filter-by-comment-type" name="comment_type">
289                                 <option value=""><?php _e( 'All comment types' ); ?></option>
290 <?php
291                                 /**
292                                  * Filter the comment types dropdown menu.
293                                  *
294                                  * @since 2.7.0
295                                  *
296                                  * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
297                                  */
298                                 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
299                                         'comment' => __( 'Comments' ),
300                                         'pings' => __( 'Pings' ),
301                                 ) );
302
303                                 foreach ( $comment_types as $type => $label )
304                                         echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
305                         ?>
306                         </select>
307 <?php
308                         /**
309                          * Fires just before the Filter submit button for comment types.
310                          *
311                          * @since 3.5.0
312                          */
313                         do_action( 'restrict_manage_comments' );
314                         submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
315                 }
316
317                 if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) {
318                         wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
319                         $title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
320                         submit_button( $title, 'apply', 'delete_all', false );
321                 }
322                 /**
323                  * Fires after the Filter submit button for comment types.
324                  *
325                  * @since 2.5.0
326                  *
327                  * @param string $comment_status The comment status name. Default 'All'.
328                  */
329                 do_action( 'manage_comments_nav', $comment_status );
330                 echo '</div>';
331         }
332
333         /**
334          * @return string|false
335          */
336         public function current_action() {
337                 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
338                         return 'delete_all';
339
340                 return parent::current_action();
341         }
342
343         /**
344          *
345          * @global int $post_id
346          *
347          * @return array
348          */
349         public function get_columns() {
350                 global $post_id;
351
352                 $columns = array();
353
354                 if ( $this->checkbox )
355                         $columns['cb'] = '<input type="checkbox" />';
356
357                 $columns['author'] = __( 'Author' );
358                 $columns['comment'] = _x( 'Comment', 'column name' );
359
360                 if ( ! $post_id ) {
361                         /* translators: column name or table row header */
362                         $columns['response'] = __( 'In Response To' );
363                 }
364
365                 return $columns;
366         }
367
368         /**
369          *
370          * @return array
371          */
372         protected function get_sortable_columns() {
373                 return array(
374                         'author'   => 'comment_author',
375                         'response' => 'comment_post_ID'
376                 );
377         }
378
379         /**
380          * Get the name of the default primary column.
381          *
382          * @since 4.3.0
383          * @access protected
384          *
385          * @return string Name of the default primary column, in this case, 'comment'.
386          */
387         protected function get_default_primary_column_name() {
388                 return 'comment';
389         }
390
391         /**
392          * @access public
393          */
394         public function display() {
395                 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
396
397                 $this->display_tablenav( 'top' );
398
399 ?>
400 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
401         <thead>
402         <tr>
403                 <?php $this->print_column_headers(); ?>
404         </tr>
405         </thead>
406
407         <tbody id="the-comment-list" data-wp-lists="list:comment">
408                 <?php $this->display_rows_or_placeholder(); ?>
409         </tbody>
410
411         <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
412                 <?php $this->items = $this->extra_items; $this->display_rows(); ?>
413         </tbody>
414
415         <tfoot>
416         <tr>
417                 <?php $this->print_column_headers( false ); ?>
418         </tr>
419         </tfoot>
420
421 </table>
422 <?php
423
424                 $this->display_tablenav( 'bottom' );
425         }
426
427         /**
428          *
429          * @global WP_Post $post
430          * @global object  $comment
431          *
432          * @param object $a_comment
433          */
434         public function single_row( $a_comment ) {
435                 global $post, $comment;
436
437                 $comment = $a_comment;
438                 $the_comment_class = wp_get_comment_status( $comment->comment_ID );
439                 if ( ! $the_comment_class ) {
440                         $the_comment_class = '';
441                 }
442                 $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment->comment_ID, $comment->comment_post_ID ) );
443
444                 $post = get_post( $comment->comment_post_ID );
445
446                 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
447
448                 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
449                 $this->single_row_columns( $comment );
450                 echo "</tr>\n";
451         }
452
453         /**
454          * Generate and display row actions links.
455          *
456          * @since 4.3.0
457          * @access protected
458          *
459          * @param object $comment     Comment being acted upon.
460          * @param string $column_name Current column name.
461          * @param string $primary     Primary column name.
462          * @return string|void Comment row actions output.
463          */
464         protected function handle_row_actions( $comment, $column_name, $primary ) {
465                 global $comment_status;
466
467                 if ( $primary !== $column_name ) {
468                         return '';
469                 }
470
471                 if ( ! $this->user_can ) {
472                         return;
473                 }
474
475                 $the_comment_status = wp_get_comment_status( $comment->comment_ID );
476
477                 $out = '';
478
479                 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
480                 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
481
482                 $url = "comment.php?c=$comment->comment_ID";
483
484                 $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
485                 $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
486                 $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
487                 $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
488                 $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
489                 $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
490                 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
491
492                 // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
493                 $actions = array(
494                         'approve' => '', 'unapprove' => '',
495                         'reply' => '',
496                         'quickedit' => '',
497                         'edit' => '',
498                         'spam' => '', 'unspam' => '',
499                         'trash' => '', 'untrash' => '', 'delete' => ''
500                 );
501
502                 // Not looking at all comments.
503                 if ( $comment_status && 'all' != $comment_status ) {
504                         if ( 'approved' == $the_comment_status ) {
505                                 $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>';
506                         } elseif ( 'unapproved' == $the_comment_status ) {
507                                 $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>';
508                         }
509                 } else {
510                         $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>';
511                         $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>';
512                 }
513
514                 if ( 'spam' != $the_comment_status ) {
515                         $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>';
516                 } elseif ( 'spam' == $the_comment_status ) {
517                         $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>';
518                 }
519
520                 if ( 'trash' == $the_comment_status ) {
521                         $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>';
522                 }
523
524                 if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
525                         $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>';
526                 } else {
527                         $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>';
528                 }
529
530                 if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
531                         $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
532
533                         $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" title="%s" href="#">%s</a>';
534
535                         $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick&nbsp;Edit' ) );
536
537                         $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
538                 }
539
540                 /** This filter is documented in wp-admin/includes/dashboard.php */
541                 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
542
543                 $i = 0;
544                 $out .= '<div class="row-actions">';
545                 foreach ( $actions as $action => $link ) {
546                         ++$i;
547                         ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
548
549                         // Reply and quickedit need a hide-if-no-js span when not added with ajax
550                         if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') )
551                                 $action .= ' hide-if-no-js';
552                         elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
553                                 if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
554                                         $action .= ' approve';
555                                 else
556                                         $action .= ' unapprove';
557                         }
558
559                         $out .= "<span class='$action'>$sep$link</span>";
560                 }
561                 $out .= '</div>';
562
563                 $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
564
565                 return $out;
566         }
567
568         /**
569          *
570          * @param object $comment
571          */
572         public function column_cb( $comment ) {
573                 if ( $this->user_can ) { ?>
574                 <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
575                 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
576                 <?php
577                 }
578         }
579
580         /**
581          * @param object $comment
582          */
583         public function column_comment( $comment ) {
584                 $comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
585
586                 echo '<div class="comment-author">';
587                         $this->column_author( $comment );
588                 echo '</div>';
589
590                 echo '<div class="submitted-on">';
591                 /* translators: 2: comment date, 3: comment time */
592                 printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
593                         /* translators: comment date format. See http://php.net/date */
594                         get_comment_date( __( 'Y/m/d' ) ),
595                         get_comment_date( get_option( 'time_format' ) )
596                 );
597
598                 if ( $comment->comment_parent ) {
599                         $parent = get_comment( $comment->comment_parent );
600                         $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
601                         $name = get_comment_author( $parent->comment_ID );
602                         printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
603                 }
604
605                 echo '</div>';
606                 comment_text();
607                 if ( $this->user_can ) { ?>
608                 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
609                 <textarea class="comment" rows="1" cols="1"><?php
610                         /** This filter is documented in wp-admin/includes/comment.php */
611                         echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
612                 ?></textarea>
613                 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
614                 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
615                 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
616                 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
617                 </div>
618                 <?php
619                 }
620         }
621
622         /**
623          *
624          * @global string $comment_status
625          *
626          * @param object $comment
627          */
628         public function column_author( $comment ) {
629                 global $comment_status;
630
631                 $author_url = get_comment_author_url();
632                 if ( 'http://' == $author_url )
633                         $author_url = '';
634                 $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url );
635                 if ( strlen( $author_url_display ) > 50 )
636                         $author_url_display = substr( $author_url_display, 0, 49 ) . '&hellip;';
637
638                 echo "<strong>"; comment_author(); echo '</strong><br />';
639                 if ( !empty( $author_url ) )
640                         echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
641
642                 if ( $this->user_can ) {
643                         if ( !empty( $comment->comment_author_email ) ) {
644                                 comment_author_email_link();
645                                 echo '<br />';
646                         }
647
648                         $author_ip = get_comment_author_IP();
649                         if ( $author_ip ) {
650                                 $author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), 'edit-comments.php' );
651                                 if ( 'spam' == $comment_status ) {
652                                         $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
653                                 }
654                                 printf( '<a href="%s">%s</a>', esc_url( $author_ip_url ), $author_ip );
655                         }
656                 }
657         }
658
659         /**
660          *
661          * @return string
662          */
663         public function column_date() {
664                 return get_comment_date( __( 'Y/m/d \a\t g:i a' ) );
665         }
666
667         /**
668          * @access public
669          */
670         public function column_response() {
671                 $post = get_post();
672
673                 if ( ! $post ) {
674                         return;
675                 }
676
677                 if ( isset( $this->pending_count[$post->ID] ) ) {
678                         $pending_comments = $this->pending_count[$post->ID];
679                 } else {
680                         $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
681                         $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
682                 }
683
684                 if ( current_user_can( 'edit_post', $post->ID ) ) {
685                         $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
686                         $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
687                 } else {
688                         $post_link = esc_html( get_the_title( $post->ID ) );
689                 }
690
691                 echo '<div class="response-links">';
692                 if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) {
693                         echo $thumb;
694                 }
695                 echo $post_link;
696                 $post_type_object = get_post_type_object( $post->post_type );
697                 echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
698                 echo '<span class="post-com-count-wrapper">';
699                 $this->comments_bubble( $post->ID, $pending_comments );
700                 echo '</span> ';
701                 echo '</div>';
702         }
703
704         /**
705          *
706          * @param object $comment
707          * @param string $column_name
708          */
709         public function column_default( $comment, $column_name ) {
710                 /**
711                  * Fires when the default column output is displayed for a single row.
712                  *
713                  * @since 2.8.0
714                  *
715                  * @param string $column_name         The custom column's name.
716                  * @param int    $comment->comment_ID The custom column's unique ID number.
717                  */
718                 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
719         }
720 }
721
722 /**
723  * Post Comments List Table class.
724  *
725  * @package WordPress
726  * @subpackage List_Table
727  * @since 3.1.0
728  * @access private
729  *
730  * @see WP_Comments_Table
731  */
732 class WP_Post_Comments_List_Table extends WP_Comments_List_Table {
733
734         /**
735          *
736          * @return array
737          */
738         protected function get_column_info() {
739                 return array(
740                         array(
741                                 'author'   => __( 'Author' ),
742                                 'comment'  => _x( 'Comment', 'column name' ),
743                         ),
744                         array(),
745                         array(),
746                         'comment',
747                 );
748         }
749
750         /**
751          *
752          * @return array
753          */
754         protected function get_table_classes() {
755                 $classes = parent::get_table_classes();
756                 $classes[] = 'wp-list-table';
757                 $classes[] = 'comments-box';
758                 return $classes;
759         }
760
761         /**
762          *
763          * @param bool $output_empty
764          */
765         public function display( $output_empty = false ) {
766                 $singular = $this->_args['singular'];
767
768                 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
769 ?>
770 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;">
771         <tbody id="the-comment-list"<?php
772                 if ( $singular ) {
773                         echo " data-wp-lists='list:$singular'";
774                 } ?>>
775                 <?php if ( ! $output_empty ) {
776                         $this->display_rows_or_placeholder();
777                 } ?>
778         </tbody>
779 </table>
780 <?php
781         }
782
783         /**
784          *
785          * @param bool $comment_status
786          * @return int
787          */
788         public function get_per_page( $comment_status = false ) {
789                 return 10;
790         }
791 }