~canonical-sysadmins/wordpress/4.2.2

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-comments-list-table.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

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