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