PluginProbe
Stream – Activity Log & Audit Trail / 3.6.1
Stream – Activity Log & Audit Trail v3.6.1
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-list-table.php +355 -160 3.13.6.1 View file →
@@ -1,10 +1,20 @@
1 1 <?php
2 +/**
3 + * Generates a filterable list of provided records to be displayed HTML Table.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - List_Table
12 + */
4 13 class List_Table extends \WP_List_Table {
14 +
5 15 /**
6 - * Hold Plugin class
16 + * Holds Instance of plugin object
7 17 *
8 18 * @var Plugin
9 19 */
10 20 public $plugin;
@@ -11,12 +21,12 @@
11 21
12 22 /**
13 23 * Class constructor.
14 24 *
15 - * @param Plugin $plugin The main Plugin class.
16 - * @param array $args
25 + * @param Plugin $plugin Instance of plugin object.
26 + * @param array $args Argument to filter rows by.
17 27 */
18 - function __construct( $plugin, $args = array() ) {
28 + public function __construct( $plugin, $args = array() ) {
19 29 $this->plugin = $plugin;
20 30
21 31 $screen_id = isset( $args['screen'] ) ? $args['screen'] : null;
22 32
@@ -43,32 +53,64 @@
43 53 'option' => 'edit_stream_per_page',
44 54 )
45 55 );
46 56
47 - // Check for default hidden columns
57 + // Check for default hidden columns.
48 58 $this->get_hidden_columns();
49 59
50 - add_filter( 'screen_settings', array( $this, 'screen_controls' ), 10, 2 );
51 - add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
60 + add_filter(
61 + 'screen_settings',
62 + array(
63 + $this,
64 + 'screen_controls',
65 + ),
66 + 10,
67 + 2
68 + );
69 + add_filter(
70 + 'set-screen-option',
71 + array(
72 + $this,
73 + 'set_screen_option',
74 + ),
75 + 10,
76 + 3
77 + );
52 78
53 79 set_screen_options();
54 80 }
55 81
56 - function extra_tablenav( $which ) {
82 + /**
83 + * Renders extra from navigation options.
84 + *
85 + * @param string $which Page location.
86 + * @return void
87 + */
88 + public function extra_tablenav( $which ) {
57 89 if ( 'top' === $which ) {
58 - echo $this->filters_form(); // xss ok
90 + echo $this->filters_form(); // xss ok.
59 91 }
60 92 }
61 93
62 - function no_items() {
94 + /**
95 + * Renders "No items found" message.
96 + *
97 + * @return void
98 + */
99 + public function no_items() {
63 100 ?>
64 101 <div class="stream-list-table-no-items">
65 - <p><?php esc_html_e( 'Sorry, no activity records were found.', 'stream' ) ?></p>
102 + <p><?php esc_html_e( 'No activity records were found.', 'stream' ); ?></p>
66 103 </div>
67 104 <?php
68 105 }
69 106
70 - function get_columns() {
107 + /**
108 + * Returns the table columns to be rendered.
109 + *
110 + * @return array
111 + */
112 + public function get_columns() {
71 113 /**
72 114 * Allows devs to add new columns to table
73 115 *
74 116 * @return array
@@ -85,23 +127,34 @@
85 127 )
86 128 );
87 129 }
88 130
89 - function get_sortable_columns() {
131 + /**
132 + * Returns the columns the items can be sort by.
133 + *
134 + * @return array
135 + */
136 + public function get_sortable_columns() {
90 137 return array(
91 138 'date' => array( 'date', false ),
92 139 );
93 140 }
94 141
95 - function get_hidden_columns() {
96 - if ( ! $user = wp_get_current_user() ) {
142 + /**
143 + * Returns columns hidden from all except specific users.
144 + *
145 + * @return array|bool
146 + */
147 + public function get_hidden_columns() {
148 + $user = wp_get_current_user();
149 + if ( ! $user ) {
97 150 return array();
98 151 }
99 152
100 - // Directly checking the user meta; to check whether user has changed screen option or not
153 + // Directly checking the user meta; to check whether user has changed screen option or not.
101 154 $hidden = $this->plugin->admin->get_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', true );
102 155
103 - // If user meta is not found; add the default hidden column 'id'
156 + // If user meta is not found; add the default hidden column 'id'.
104 157 if ( ! $hidden ) {
105 158 $hidden = array( 'id' );
106 159 $this->plugin->admin->update_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', $hidden );
107 160 }
@@ -108,15 +161,25 @@
108 161
109 162 return $hidden;
110 163 }
111 164
112 - function prepare_items() {
165 + /**
166 + * Prepares table columns and data for render
167 + *
168 + * @return void
169 + */
170 + public function prepare_items() {
113 171 $columns = $this->get_columns();
114 172 $sortable = $this->get_sortable_columns();
115 173 $hidden = $this->get_hidden_columns();
116 174 $primary = $columns['summary'];
117 175
118 - $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
176 + $this->_column_headers = array(
177 + $columns,
178 + $hidden,
179 + $sortable,
180 + $primary,
181 + );
119 182
120 183 $this->items = $this->get_records();
121 184
122 185 $total_items = $this->get_total_found_rows();
@@ -128,17 +191,24 @@
128 191 )
129 192 );
130 193 }
131 194
132 - function get_records() {
195 + /**
196 + * Returns records to be displayed
197 + *
198 + * @return array
199 + */
200 + public function get_records() {
133 201 $args = array();
134 202
135 - // Parse sorting params
136 - if ( $order = wp_stream_filter_input( INPUT_GET, 'order' ) ) {
203 + // Parse sorting params.
204 + $order = wp_stream_filter_input( INPUT_GET, 'order' );
205 + if ( $order ) {
137 206 $args['order'] = $order;
138 207 }
139 208
140 - if ( $orderby = wp_stream_filter_input( INPUT_GET, 'orderby' ) ) {
209 + $orderby = wp_stream_filter_input( INPUT_GET, 'orderby' );
210 + if ( $orderby ) {
141 211 $args['orderby'] = $orderby;
142 212 }
143 213
144 214 $params = array(
@@ -157,9 +227,9 @@
157 227 $args[ $param ] = $value;
158 228 }
159 229 }
160 230
161 - // Additional filter properties
231 + // Additional filter properties.
162 232 $properties = array(
163 233 'record',
164 234 'site_id',
165 235 'blog_id',
@@ -171,13 +241,13 @@
171 241 'context',
172 242 'action',
173 243 );
174 244
175 - // Add property fields to defaults, including their __in/__not_in variations
245 + // Add property fields to defaults, including their __in/__not_in variations.
176 246 foreach ( $properties as $property ) {
177 247 $value = wp_stream_filter_input( INPUT_GET, $property );
178 248
179 - // Allow 0 values
249 + // Allow 0 values.
180 250 if ( isset( $value ) && '' !== $value && false !== $value ) {
181 251 $args[ $property ] = $value;
182 252 }
183 253
@@ -205,9 +275,9 @@
205 275 $args['records_per_page'] = $this->get_items_per_page( 'edit_stream_per_page', 20 );
206 276 }
207 277 $args['records_per_page'] = apply_filters( 'stream_records_per_page', $args['records_per_page'] );
208 278
209 - $items = $this->plugin->db->query( $args );
279 + $items = $this->plugin->db->get_records( $args );
210 280
211 281 return $items;
212 282 }
213 283
@@ -216,31 +286,39 @@
216 286 *
217 287 * @return integer
218 288 */
219 289 public function get_total_found_rows() {
220 - return $this->plugin->db->query->found_records;
290 + return $this->plugin->db->get_found_records_count();
221 291 }
222 292
223 - function column_default( $item, $column_name ) {
224 - $out = '';
293 + /**
294 + * Returns the column content for the provided item and column.
295 + *
296 + * @param array $item Record data.
297 + * @param string $column_name Column name.
298 + * @return void
299 + */
300 + public function column_default( $item, $column_name ) {
301 + $out = '';
225 302 $record = new Record( $item );
226 303
227 304 switch ( $column_name ) {
228 - case 'date' :
229 - $created = date( 'Y-m-d H:i:s', strtotime( $record->created ) );
305 + case 'date':
306 + $created = gmdate( 'Y-m-d H:i:s', strtotime( $record->created ) );
230 307 $date_string = sprintf(
231 308 '<time datetime="%s" class="relative-time record-created">%s</time>',
232 309 wp_stream_get_iso_8601_extended_date( strtotime( $record->created ) ),
233 310 get_date_from_gmt( $created, 'Y/m/d' )
234 311 );
235 - $out = $this->column_link( $date_string, 'date', get_date_from_gmt( $created, 'Y/m/d' ) );
236 - $out .= '<br />';
237 - $out .= get_date_from_gmt( $created, 'h:i:s A' );
312 + $out = $this->column_link( $date_string, 'date', get_date_from_gmt( $created, 'Y/m/d' ) );
313 + $out .= '<br />';
314 + $out .= get_date_from_gmt( $created, 'h:i:s A' );
238 315 break;
239 316
240 - case 'summary' :
241 - $out = $record->summary;
242 - $object_title = $record->get_object_title();
317 + case 'summary':
318 + $out = $record->summary;
319 + $object_title = $record->get_object_title();
320 + /* translators: %s: the title of any object, like a Post (e.g. "Hello World") */
243 321 $view_all_text = $object_title ? sprintf( esc_html__( 'View all activity for "%s"', 'stream' ), esc_attr( $object_title ) ) : esc_html__( 'View all activity for this object', 'stream' );
244 322
245 323 if ( $record->object_id ) {
246 324 $out .= $this->column_link(
@@ -255,10 +333,10 @@
255 333 }
256 334 $out .= $this->get_action_links( $record );
257 335 break;
258 336
259 - case 'user_id' :
260 - $user = new Author( (int) $record->user_id, (array) maybe_unserialize( $record->user_meta ) );
337 + case 'user_id':
338 + $user = new Author( (int) $record->user_id, (array) $record->user_meta );
261 339
262 340 $filtered_records_url = add_query_arg(
263 341 array(
264 342 'page' => $this->plugin->admin->records_page_slug,
@@ -301,20 +379,22 @@
301 379 $blog = ( $record->blog_id && is_multisite() ) ? get_blog_details( $record->blog_id ) : $this->plugin->admin->network->get_network_blog();
302 380 $out = $this->column_link( $blog->blogname, 'blog_id', $blog->blog_id );
303 381 break;
304 382
305 - case 'ip' :
383 + case 'ip':
306 384 $out = $this->column_link( $record->{$column_name}, 'ip', $record->{$column_name} );
307 385 break;
308 386
309 - default :
387 + default:
310 388 /**
311 389 * Registers new Columns to be inserted into the table. The cell contents of this column is set
312 390 * below with 'wp_stream_insert_column_default_'
313 391 *
392 + * @param array $new_columns Columns injected in the table.
393 + *
314 394 * @return array
315 395 */
316 - $inserted_columns = apply_filters( 'wp_stream_register_column_defaults', $new_columns = array() );
396 + $inserted_columns = apply_filters( 'wp_stream_register_column_defaults', array() );
317 397
318 398 if ( ! empty( $inserted_columns ) && is_array( $inserted_columns ) ) {
319 399 foreach ( $inserted_columns as $column_title ) {
320 400 /**
@@ -324,33 +404,41 @@
324 404 *
325 405 * Also, note that the action name must include the $column_title registered
326 406 * with wp_stream_register_column_defaults
327 407 */
328 - if ( $column_title === $column_name && has_filter( "wp_stream_insert_column_default_{$column_title}" ) ) {
408 + if ( $column_title === $column_name ) {
329 409 /**
330 410 * Allows for the addition of content under a specified column.
331 411 *
332 - * @param object $record Contents of the row
412 + * @param string $out Column content.
413 + * @param object $record Record with row content.
414 + * @param string $column_name Column name.
333 415 *
334 416 * @return string
335 417 */
336 - $out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $column_name, $record );
337 - } else {
338 - $out = $column_name;
418 + $out = apply_filters( "wp_stream_insert_column_default_{$column_title}", $out, $record, $column_name );
419 + break;
339 420 }
340 421 }
341 - } else {
342 - $out = $column_name;
343 422 }
344 423 }
345 424
346 - $allowed_tags = wp_kses_allowed_html( 'post' );
347 - $allowed_tags['time'] = array( 'datetime' => true, 'class' => true );
425 + $allowed_tags = wp_kses_allowed_html( 'post' );
426 + $allowed_tags['time'] = array(
427 + 'datetime' => true,
428 + 'class' => true,
429 + );
348 430 $allowed_tags['img']['srcset'] = true;
349 431
350 432 echo wp_kses( $out, $allowed_tags );
351 433 }
352 434
435 + /**
436 + * Returns the actions links for the provided record. (Eg. Edit, View)
437 + *
438 + * @param Record $record Record.
439 + * @return string
440 + */
353 441 public function get_action_links( $record ) {
354 442 $out = '';
355 443
356 444 /**
@@ -402,9 +490,18 @@
402 490
403 491 return $out;
404 492 }
405 493
406 - function column_link( $display, $key, $value = null, $title = null ) {
494 + /**
495 + * Returns a link to be display in the table.
496 + *
497 + * @param string $display Text to be displayed in link.
498 + * @param string|array $key Query string variable(s).
499 + * @param string $value Single query string value.
500 + * @param string $title Tooltip value.
501 + * @return string
502 + */
503 + public function column_link( $display, $key, $value = null, $title = null ) {
407 504 $url = add_query_arg(
408 505 array(
409 506 'page' => $this->plugin->admin->records_page_slug,
410 507 ),
@@ -410,9 +507,11 @@
410 507 ),
411 508 self_admin_url( $this->plugin->admin->admin_parent_page )
412 509 );
413 510
414 - $args = ! is_array( $key ) ? array( $key => $value ) : $key;
511 + $args = ! is_array( $key ) ? array(
512 + $key => $value,
513 + ) : $key;
415 514
416 515 foreach ( $args as $k => $v ) {
417 516 $url = add_query_arg( $k, $v, $url );
418 517 }
@@ -424,14 +523,21 @@
424 523 $display
425 524 );
426 525 }
427 526
527 + /**
528 + * Returns the label for a connector term.
529 + *
530 + * @param string $term Connector label type.
531 + * @param string $type Connector term.
532 + * @return string
533 + */
428 534 public function get_term_title( $term, $type ) {
429 - if ( ! isset( $this->plugin->connectors->term_labels[ "stream_$type" ][ $term ] ) ) {
535 + if ( ! isset( $this->plugin->connectors->term_labels[ 'stream_' . $type ][ $term ] ) ) {
430 536 return $term;
431 537 }
432 538
433 - return $this->plugin->connectors->term_labels[ "stream_$type" ][ $term ];
539 + return $this->plugin->connectors->term_labels[ 'stream_' . $type ][ $term ];
434 540 }
435 541
436 542 /**
437 543 * Assembles records for display in search filters
@@ -439,18 +545,18 @@
439 545 * Gathers list of all users/connectors, then compares it to
440 546 * results of existing records. All items that do not exist in records
441 547 * get assigned a disabled value of "true".
442 548 *
443 - * @param string $column List table column name
549 + * @param string $column List table column name.
444 550 *
445 551 * @return array Options to be displayed in search filters
446 552 */
447 - function assemble_records( $column ) {
553 + public function assemble_records( $column ) {
448 554 // @todo eliminate special condition for authors, especially using a WP_User object as the value; should use string or stringifiable object
449 555 if ( 'user_id' === $column ) {
450 556 $all_records = array();
451 557
452 - // If the number of users exceeds the max users constant value then return an empty array and use AJAX instead
558 + // If the number of users exceeds the max users constant value then return an empty array and use AJAX instead.
453 559 $user_count = count_users();
454 560 $total_users = $user_count['total_users'];
455 561
456 562 if ( $total_users > $this->plugin->admin->preload_users_max ) {
@@ -456,9 +562,12 @@
456 562 if ( $total_users > $this->plugin->admin->preload_users_max ) {
457 563 $selected_user = wp_stream_filter_input( INPUT_GET, 'user_id' );
458 564 if ( $selected_user ) {
459 565 $user = new Author( $selected_user );
460 - return array( $selected_user => $user->get_display_name() );
566 +
567 + return array(
568 + $selected_user => $user->get_display_name(),
569 + );
461 570 } else {
462 571 return array();
463 572 }
464 573 }
@@ -463,26 +572,36 @@
463 572 }
464 573 }
465 574
466 575 $users = array_map(
467 - function( $user_id ) {
576 + function ( $user_id ) {
468 577 return new Author( $user_id );
469 578 },
470 - get_users( array( 'fields' => 'ID' ) )
579 + get_users(
580 + array(
581 + 'fields' => 'ID',
582 + )
583 + )
471 584 );
472 585
473 586 if ( is_multisite() && is_super_admin() ) {
474 587 $super_admins = array_map(
475 - function( $login ) {
588 + function ( $login ) {
476 589 $user = get_user_by( 'login', $login );
590 +
477 591 return new Author( $user->ID );
478 592 },
479 593 get_super_admins()
480 594 );
481 - $users = array_unique( array_merge( $users, $super_admins ) );
595 + $users = array_unique( array_merge( $users, $super_admins ) );
482 596 }
483 597
484 - $users[] = new Author( 0, array( 'is_wp_cli' => true ) );
598 + $users[] = new Author(
599 + 0,
600 + array(
601 + 'is_wp_cli' => true,
602 + )
603 + );
485 604
486 605 foreach ( $users as $user ) {
487 606 $all_records[ $user->id ] = $user->get_display_name();
488 607 }
@@ -496,20 +615,26 @@
496 615 $disabled_records = array();
497 616
498 617 foreach ( $all_records as $record => $label ) {
499 618 if ( array_key_exists( $record, $existing_records ) ) {
500 - $active_records[ $record ] = array( 'label' => $label, 'disabled' => '' );
619 + $active_records[ $record ] = array(
620 + 'label' => $label,
621 + 'disabled' => '',
622 + );
501 623 } else {
502 - $disabled_records[ $record ] = array( 'label' => $label, 'disabled' => 'disabled="disabled"' );
624 + $disabled_records[ $record ] = array(
625 + 'label' => $label,
626 + 'disabled' => 'disabled="disabled"',
627 + );
503 628 }
504 629 }
505 630
506 - // Remove WP-CLI pseudo user if no records with user=0 exist
631 + // Remove WP-CLI pseudo user if no records with user=0 exist.
507 632 if ( isset( $disabled_records[0] ) ) {
508 633 unset( $disabled_records[0] );
509 634 }
510 635
511 - $sort = function( $a, $b ) use ( $column ) {
636 + $sort = function ( $a, $b ) use ( $column ) {
512 637 $label_a = (string) $a['label'];
513 638 $label_b = (string) $b['label'];
514 639
515 640 if ( $label_a === $label_b ) {
@@ -515,20 +640,25 @@
515 640 if ( $label_a === $label_b ) {
516 641 return 0;
517 642 }
518 643
519 - return ( strtolower( $label_a ) < strtolower( $label_b ) ) ? -1 : 1;
644 + return ( strtolower( $label_a ) < strtolower( $label_b ) ) ? - 1 : 1;
520 645 };
521 646
522 647 uasort( $active_records, $sort );
523 648 uasort( $disabled_records, $sort );
524 649
525 - // Not using array_merge() in order to preserve the array index for the users dropdown which uses the user_id as the key
650 + // Not using array_merge() in order to preserve the array index for the users dropdown which uses the user_id as the key.
526 651 $all_records = $active_records + $disabled_records;
527 652
528 653 return $all_records;
529 654 }
530 655
656 + /**
657 + * Returns list filters.
658 + *
659 + * @return array
660 + */
531 661 public function get_filters() {
532 662 $filters = array();
533 663
534 664 $date_interval = new Date_Interval();
@@ -567,9 +697,14 @@
567 697 */
568 698 return apply_filters( 'wp_stream_list_table_filters', $filters );
569 699 }
570 700
571 - function filters_form() {
701 + /**
702 + * Returns table filters form.
703 + *
704 + * @return string
705 + */
706 + public function filters_form() {
572 707 $filters = $this->get_filters();
573 708
574 709 $filters_string = sprintf( '<input type="hidden" name="page" value="%s" />', 'wp_stream' );
575 710 $filters_string .= sprintf( '<span class="filter_info hidden">%s</span>', esc_html__( 'Show filter controls via the screen options tab above.', 'stream' ) );
@@ -575,19 +710,22 @@
575 710 $filters_string .= sprintf( '<span class="filter_info hidden">%s</span>', esc_html__( 'Show filter controls via the screen options tab above.', 'stream' ) );
576 711
577 712 foreach ( $filters as $name => $data ) {
578 713
579 - $data = wp_parse_args( $data, array(
580 - 'title' => '',
581 - 'items' => array(),
582 - 'ajax' => false,
583 - ) );
714 + $data = wp_parse_args(
715 + $data,
716 + array(
717 + 'title' => '',
718 + 'items' => array(),
719 + 'ajax' => false,
720 + )
721 + );
584 722
585 723 if ( 'date' === $name ) {
586 724 $filters_string .= $this->filter_date( $data['items'] );
587 725 } else {
588 726 if ( 'context' === $name ) {
589 - // Add Connectors as parents, and apply the Contexts as children
727 + // Add Connectors as parents, and apply the Contexts as children.
590 728 $connectors = $this->assemble_records( 'connector' );
591 729 $context_items = array();
592 730
593 731 foreach ( $connectors as $connector => $item ) {
@@ -601,9 +739,9 @@
601 739
602 740 if ( isset( $context_items[ $connector ]['children'] ) ) {
603 741 $labels = wp_list_pluck( $context_items[ $connector ]['children'], 'label' );
604 742
605 - // Sort child items by label
743 + // Sort child items by label.
606 744 array_multisort( $labels, SORT_ASC, $context_items[ $connector ]['children'] );
607 745 }
608 746 }
609 747
@@ -616,12 +754,12 @@
616 754 $data['items'] = $context_items;
617 755
618 756 $labels = wp_list_pluck( $data['items'], 'label' );
619 757
620 - // Sort top-level items by label
758 + // Sort top-level items by label.
621 759 array_multisort( $labels, SORT_ASC, $data['items'] );
622 760
623 - // Output a hidden input to handle the connector value
761 + // Output a hidden input to handle the connector value.
624 762 $filters_string .= sprintf(
625 763 '<input type="hidden" name="connector" class="record-filter-connector" value="%s" />',
626 764 esc_attr( wp_stream_filter_input( INPUT_GET, 'connector' ) )
627 765 );
@@ -632,9 +770,9 @@
632 770 }
633 771
634 772 $filters_string .= sprintf( '<input type="submit" id="record-query-submit" class="button" value="%s" />', __( 'Filter', 'stream' ) );
635 773
636 - // Parse all query vars into an array
774 + // Parse all query vars into an array.
637 775 $query_vars = array();
638 776
639 777 if ( isset( $_SERVER['QUERY_STRING'] ) ) {
640 778 parse_str( urldecode( $_SERVER['QUERY_STRING'] ), $query_vars );
@@ -639,9 +777,9 @@
639 777 if ( isset( $_SERVER['QUERY_STRING'] ) ) {
640 778 parse_str( urldecode( $_SERVER['QUERY_STRING'] ), $query_vars );
641 779 }
642 780
643 - // Ignore certain query vars and query vars that are empty
781 + // Ignore certain query vars and query vars that are empty.
644 782 foreach ( $query_vars as $query_var => $value ) {
645 783 if ( '' === $value || 'page' === $query_var || 'paged' === $query_var ) {
646 784 unset( $query_vars[ $query_var ] );
647 785 }
@@ -653,70 +791,77 @@
653 791 ),
654 792 self_admin_url( $this->plugin->admin->admin_parent_page )
655 793 );
656 794
657 - // Display reset action if records are being filtered
795 + // Display reset action if records are being filtered.
658 796 if ( ! empty( $query_vars ) ) {
659 797 $filters_string .= sprintf( '<a href="%s" id="record-query-reset"><span class="dashicons dashicons-dismiss"></span> <span class="record-query-reset-text">%s</span></a>', esc_url( $url ), __( 'Reset filters', 'stream' ) );
660 798 }
661 799
662 - return sprintf( '<div class="alignleft actions">%s</div>', $filters_string ); // xss ok
800 + return sprintf( '<div class="alignleft actions">%s</div>', $filters_string ); // xss ok.
663 801 }
664 802
665 - function filter_select( $name, $title, $items, $ajax = false ) {
666 - if ( $ajax ) {
667 - $out = sprintf(
668 - '<input type="hidden" name="%s" class="chosen-select" value="%s" data-placeholder="%s" />',
669 - esc_attr( $name ),
670 - esc_attr( wp_stream_filter_input( INPUT_GET, $name ) ),
671 - esc_attr( $title )
803 + /**
804 + * Returns HTML string of filterable select control with filtered items.
805 + *
806 + * @param string $name Search input.
807 + * @param string $title Name of the control.
808 + * @param array $items Items to be filtered.
809 + * @param boolean $ajax Whether is an ajax request or not.
810 + * @return string
811 + */
812 + public function filter_select( $name, $title, $items, $ajax = false ) {
813 + $options = array( '<option value=""></option>' );
814 + $selected = wp_stream_filter_input( INPUT_GET, $name );
815 +
816 + foreach ( $items as $key => $item ) {
817 + $value = isset( $item['children'] ) ? 'group-' . $key : $key;
818 + $option_args = array(
819 + 'value' => $value,
820 + 'selected' => selected( $value, $selected, false ),
821 + 'disabled' => isset( $item['disabled'] ) ? $item['disabled'] : null,
822 + 'icon' => isset( $item['icon'] ) ? $item['icon'] : null,
823 + 'group' => isset( $item['children'] ) ? $key : null,
824 + 'tooltip' => isset( $item['tooltip'] ) ? $item['tooltip'] : null,
825 + 'class' => isset( $item['children'] ) ? 'level-1' : null,
826 + 'label' => isset( $item['label'] ) ? $item['label'] : null,
672 827 );
673 - } else {
674 - $options = array( '<option value=""></option>' );
675 - $selected = wp_stream_filter_input( INPUT_GET, $name );
828 + $options[] = $this->filter_option( $option_args );
676 829
677 - foreach ( $items as $key => $item ) {
678 - $value = isset( $item['children'] ) ? 'group-' . $key : $key;
679 - $option_args = array(
680 - 'value' => $value,
681 - 'selected' => selected( $value, $selected, false ),
682 - 'disabled' => isset( $item['disabled'] ) ? $item['disabled'] : null,
683 - 'icon' => isset( $item['icon'] ) ? $item['icon'] : null,
684 - 'group' => isset( $item['children'] ) ? $key : null,
685 - 'tooltip' => isset( $item['tooltip'] ) ? $item['tooltip'] : null,
686 - 'class' => isset( $item['children'] ) ? 'level-1' : null,
687 - 'label' => isset( $item['label'] ) ? $item['label'] : null,
688 - );
689 - $options[] = $this->filter_option( $option_args );
690 -
691 - if ( isset( $item['children'] ) ) {
692 - foreach ( $item['children'] as $child_value => $child_item ) {
693 - $option_args = array(
694 - 'value' => $child_value,
695 - 'selected' => selected( $child_value, $selected, false ),
696 - 'disabled' => isset( $child_item['disabled'] ) ? $child_item['disabled'] : null,
697 - 'icon' => isset( $child_item['icon'] ) ? $child_item['icon'] : null,
698 - 'group' => $key,
699 - 'tooltip' => isset( $child_item['tooltip'] ) ? $child_item['tooltip'] : null,
700 - 'class' => 'level-2',
701 - 'label' => isset( $child_item['label'] ) ? '- ' . $child_item['label'] : null,
702 - );
703 - $options[] = $this->filter_option( $option_args );
704 - }
830 + if ( isset( $item['children'] ) ) {
831 + foreach ( $item['children'] as $child_value => $child_item ) {
832 + $option_args = array(
833 + 'value' => $child_value,
834 + 'selected' => selected( $child_value, $selected, false ),
835 + 'disabled' => isset( $child_item['disabled'] ) ? $child_item['disabled'] : null,
836 + 'icon' => isset( $child_item['icon'] ) ? $child_item['icon'] : null,
837 + 'group' => $key,
838 + 'tooltip' => isset( $child_item['tooltip'] ) ? $child_item['tooltip'] : null,
839 + 'class' => 'level-2',
840 + 'label' => isset( $child_item['label'] ) ? '- ' . $child_item['label'] : null,
841 + );
842 + $options[] = $this->filter_option( $option_args );
705 843 }
706 844 }
707 - $out = sprintf(
708 - '<select name="%s" class="chosen-select" data-placeholder="%s">%s</select>',
709 - esc_attr( $name ),
710 - sprintf( esc_attr__( 'Show all %s', 'stream' ), $title ),
711 - implode( '', $options )
712 - );
713 845 }
846 + $out = sprintf(
847 + '<select name="%s" class="chosen-select" data-placeholder="%s">%s</select>',
848 + esc_attr( $name ),
849 + /* translators: %s: the title of the dropdown menu (e.g. "users") */
850 + sprintf( esc_attr__( 'Show all %s', 'stream' ), $title ),
851 + implode( '', $options )
852 + );
714 853
715 854 return $out;
716 855 }
717 856
718 - function filter_option( $args ) {
857 + /**
858 + * Return HTML string of a filterable select option.
859 + *
860 + * @param array $args Option attributes.
861 + * @return string
862 + */
863 + public function filter_option( $args ) {
719 864 $defaults = array(
720 865 'value' => null,
721 866 'selected' => null,
722 867 'disabled' => null,
@@ -740,13 +885,17 @@
740 885 esc_html( $args['label'] )
741 886 );
742 887 }
743 888
744 - function filter_search() {
889 + /**
890 + * Return HTML string of a filter search box.
891 + *
892 + * @return string
893 + */
894 + public function filter_search() {
745 895 $search = null;
746 - if ( isset( $_GET['search'] ) ) {
747 - // @TODO: Make this pass phpcs
748 - $search = esc_attr( wp_unslash( $_GET['search'] ) ); // input var okay
896 + if ( isset( $_GET['search'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
897 + $search = sanitize_key( wp_unslash( $_GET['search'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
749 898 }
750 899 $out = sprintf(
751 900 '<p class="search-box">
752 901 <label class="screen-reader-text" for="record-search-input">%1$s:</label>
@@ -759,9 +908,15 @@
759 908
760 909 return $out;
761 910 }
762 911
763 - function filter_date( $items ) {
912 + /**
913 + * Return HTML string of a filter select box based upon date.
914 + *
915 + * @param array $items Records.
916 + * @return string
917 + */
918 + public function filter_date( $items ) {
764 919 wp_enqueue_style( 'jquery-ui' );
765 920 wp_enqueue_style( 'wp-stream-datepicker' );
766 921 wp_enqueue_script( 'jquery-ui-datepicker' );
767 922
@@ -772,11 +927,11 @@
772 927 ob_start();
773 928 ?>
774 929 <div class="date-interval">
775 930
776 - <select class="field-predefined hide-if-no-js" name="date_predefined" data-placeholder="<?php esc_attr_e( 'All Time', 'stream' ) ?>">
931 + <select class="field-predefined hide-if-no-js chosen-select" name="date_predefined" data-placeholder="<?php esc_attr_e( 'All Time', 'stream' ); ?>">
777 932 <option></option>
778 - <option value="custom" <?php selected( 'custom' === $date_predefined ); ?>><?php esc_attr_e( 'Custom', 'stream' ) ?></option>
933 + <option value="custom" <?php selected( 'custom' === $date_predefined ); ?>><?php esc_attr_e( 'Custom', 'stream' ); ?></option>
779 934 <?php
780 935 foreach ( $items as $key => $interval ) {
781 936 $end = isset( $interval['end'] ) ? $interval['end']->format( 'Y/m/d' ) : null;
782 937
@@ -794,15 +949,15 @@
794 949
795 950 <div class="date-inputs">
796 951 <div class="box">
797 952 <i class="date-remove dashicons"></i>
798 - <input type="text" name="date_from" class="date-picker field-from" placeholder="<?php esc_attr_e( 'Start Date', 'stream' ) ?>" value="<?php echo esc_attr( $date_from ) ?>" />
953 + <input type="text" name="date_from" class="date-picker field-from" placeholder="<?php esc_attr_e( 'Start Date', 'stream' ); ?>" value="<?php echo esc_attr( $date_from ); ?>"/>
799 954 </div>
800 955 <span class="connector dashicons"></span>
801 956
802 957 <div class="box">
803 958 <i class="date-remove dashicons"></i>
804 - <input type="text" name="date_to" class="date-picker field-to" placeholder="<?php esc_attr_e( 'End Date', 'stream' ) ?>" value="<?php echo esc_attr( $date_to ) ?>" />
959 + <input type="text" name="date_to" class="date-picker field-to" placeholder="<?php esc_attr_e( 'End Date', 'stream' ); ?>" value="<?php echo esc_attr( $date_to ); ?>"/>
805 960 </div>
806 961 </div>
807 962
808 963 </div>
@@ -815,9 +970,9 @@
815 970 * Output a Select dropdown of actions relating to the Stream records
816 971 *
817 972 * @return string
818 973 */
819 - function record_actions_form() {
974 + public function record_actions_form() {
820 975 /**
821 976 * Filter the records screen actions dropdown menu
822 977 *
823 978 * @return array Should be in the format of action_slug => 'Action Name'
@@ -839,8 +994,9 @@
839 994 );
840 995 }
841 996 echo '</select></div>';
842 997 wp_nonce_field( 'stream_record_actions_nonce', 'stream_record_actions_nonce' );
998 + wp_nonce_field( 'stream_filters_user_search_nonce', 'stream_filters_user_search_nonce' );
843 999
844 1000 printf( '<input type="hidden" name="page" value="%s">', esc_attr( wp_stream_filter_input( INPUT_GET, 'page' ) ) );
845 1001 printf( '<input type="hidden" name="date_predefined" value="%s">', esc_attr( wp_stream_filter_input( INPUT_GET, 'date_predefined' ) ) );
846 1002 printf( '<input type="hidden" name="date_from" value="%s">', esc_attr( wp_stream_filter_input( INPUT_GET, 'date_from' ) ) );
@@ -855,22 +1011,30 @@
855 1011
856 1012 return ob_get_clean();
857 1013 }
858 1014
859 - function display() {
1015 + /**
1016 + * Renders record filter forms.
1017 + */
1018 + public function display() {
860 1019 $url = self_admin_url( $this->plugin->admin->admin_parent_page );
861 1020
862 1021 echo '<form method="get" action="' . esc_url( $url ) . '" id="record-filter-form">';
863 - echo $this->filter_search(); // xss ok
1022 + echo $this->filter_search(); // xss ok.
864 1023 parent::display();
865 1024 echo '</form>';
866 1025
867 1026 echo '<form method="get" action="' . esc_url( $url ) . '" id="record-actions-form">';
868 - echo $this->record_actions_form(); // xss ok
1027 + echo $this->record_actions_form(); // xss ok.
869 1028 echo '</form>';
870 1029 }
871 1030
872 - function single_row( $item ) {
1031 + /**
1032 + * Renders a single record
1033 + *
1034 + * @param array $item Record data.
1035 + */
1036 + public function single_row( $item ) {
873 1037 $classes = apply_filters( 'wp_stream_record_classes', array(), $item );
874 1038 $class_string = '';
875 1039 if ( ! empty( $classes ) ) {
876 1040 $class_string = ' class="' . esc_attr( join( ' ', $classes ) ) . '"';
@@ -875,15 +1039,21 @@
875 1039 if ( ! empty( $classes ) ) {
876 1040 $class_string = ' class="' . esc_attr( join( ' ', $classes ) ) . '"';
877 1041 }
878 1042
879 - echo sprintf( '<tr%s>', $class_string ); // xss ok
1043 + echo sprintf( '<tr%s>', $class_string ); // xss ok.
880 1044 $this->single_row_columns( $item );
881 1045 echo '</tr>';
882 1046 }
883 1047
884 - function display_tablenav( $which ) {
885 - if ( 'top' === $which ) : ?>
1048 + /**
1049 + * Renders table navigation controls
1050 + *
1051 + * @param string $which Location controls.
1052 + */
1053 + public function display_tablenav( $which ) {
1054 + if ( 'top' === $which ) :
1055 + ?>
886 1056 <div class="tablenav <?php echo esc_attr( $which ); ?>">
887 1057 <?php
888 1058 $this->pagination( $which );
889 1059 $this->extra_tablenav( $which );
@@ -888,9 +1058,9 @@
888 1058 $this->pagination( $which );
889 1059 $this->extra_tablenav( $which );
890 1060 ?>
891 1061
892 - <br class="clear" />
1062 + <br class="clear"/>
893 1063 </div>
894 1064 <?php else : ?>
895 1065 <div class="tablenav <?php echo esc_attr( $which ); ?>">
896 1066 <?php
@@ -901,15 +1071,23 @@
901 1071 $this->pagination( $which );
902 1072 $this->extra_tablenav( $which );
903 1073 ?>
904 1074
905 - <br class="clear" />
1075 + <br class="clear"/>
906 1076 </div>
907 - <?php
1077 + <?php
908 1078 endif;
909 1079 }
910 1080
911 - function set_screen_option( $dummy, $option, $value ) {
1081 + /**
1082 + * Sets the screen options.
1083 + *
1084 + * @param string $dummy Unused.
1085 + * @param string $option Screen option name.
1086 + * @param string $value Screen option value.
1087 + * @return string
1088 + */
1089 + public function set_screen_option( $dummy, $option, $value ) {
912 1090 if ( 'edit_stream_per_page' === $option ) {
913 1091 return $value;
914 1092 } else {
915 1093 return $dummy;
@@ -915,9 +1093,17 @@
915 1093 return $dummy;
916 1094 }
917 1095 }
918 1096
919 - function set_live_update_option( $dummy, $option, $value ) {
1097 + /**
1098 + * Sets the live update options.
1099 + *
1100 + * @param string $dummy Unused.
1101 + * @param string $option Screen option name.
1102 + * @param string $value Screen option value.
1103 + * @return string
1104 + */
1105 + public function set_live_update_option( $dummy, $option, $value ) {
920 1106 unset( $value );
921 1107
922 1108 // @codingStandardsIgnoreStart
923 1109 if (
@@ -928,13 +1114,21 @@
928 1114 $value = esc_attr( $_POST[ $this->plugin->admin->live_update->user_meta_key ] ); //input var okay
929 1115
930 1116 return $value;
931 1117 }
1118 +
932 1119 // @codingStandardsIgnoreEnd
933 1120
934 1121 return $dummy;
935 1122 }
936 1123
1124 + /**
1125 + * Return HTML string of the "Live updates" screen option.
1126 + *
1127 + * @param string $status Unused.
1128 + * @param array $args Unused.
1129 + * @return string
1130 + */
937 1131 public function screen_controls( $status, $args ) {
938 1132 unset( $status );
939 1133 unset( $args );
940 1134
@@ -952,20 +1146,21 @@
952 1146
953 1147 ob_start();
954 1148 ?>
955 1149 <fieldset>
956 - <h5><?php esc_html_e( 'Live updates', 'stream' ) ?></h5>
1150 + <h5><?php esc_html_e( 'Live updates', 'stream' ); ?></h5>
957 1151
958 1152 <div>
959 - <input type="hidden" name="stream_live_update_nonce" id="stream_live_update_nonce" value="<?php echo esc_attr( $nonce ) ?>" />
1153 + <input type="hidden" name="stream_live_update_nonce" id="stream_live_update_nonce" value="<?php echo esc_attr( $nonce ); ?>"/>
960 1154 </div>
961 1155 <div>
962 - <input type="hidden" name="enable_live_update_user" id="enable_live_update_user" value="<?php echo absint( $user_id ) ?>" />
1156 + <input type="hidden" name="enable_live_update_user" id="enable_live_update_user" value="<?php echo absint( $user_id ); ?>"/>
963 1157 </div>
964 1158 <div class="metabox-prefs stream-live-update-checkbox">
965 1159 <label for="enable_live_update">
966 - <input type="checkbox" value="on" name="enable_live_update" id="enable_live_update" data-heartbeat="<?php echo esc_attr( $heartbeat ) ?>" <?php checked( $option, 'on' ) ?> />
967 - <?php esc_html_e( 'Enabled', 'stream' ) ?><span class="spinner"></span>
1160 + <input type="checkbox" value="on" name="enable_live_update" id="enable_live_update" data-heartbeat="<?php echo esc_attr( $heartbeat ); ?>" <?php checked( $option, 'on' ); ?> />
1161 + <?php esc_html_e( 'Enabled', 'stream' ); ?>
1162 + <span class="spinner"></span>
968 1163 </label>
969 1164 </div>
970 1165 </fieldset>
971 1166 <?php
@@ -974,13 +1169,13 @@
974 1169
975 1170 /**
976 1171 * This function is use to map List table column name with excluded setting keys
977 1172 *
978 - * @param string $column List table column name
1173 + * @param string $column List table column name.
979 1174 *
980 1175 * @return string setting name for that column
981 1176 */
982 - function get_column_excluded_setting_key( $column ) {
1177 + public function get_column_excluded_setting_key( $column ) {
983 1178 switch ( $column ) {
984 1179 case 'connector':
985 1180 $output = 'connectors';
986 1181 break;
@@ -1005,9 +1200,9 @@
1005 1200
1006 1201 /**
1007 1202 * Get users as dropdown items
1008 1203 *
1009 - * @param array $users
1204 + * @param array $users Users.
1010 1205 *
1011 1206 * @return array
1012 1207 */
1013 1208 public function get_users_dropdown_items( $users ) {