PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | inc/classes/class-imagify-files-list-table.php +195 -230 1.10 → trunk View file →
@@ -1,13 +1,14 @@
1 1 <?php
2 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3 2
3 +if ( ! class_exists( 'WP_List_Table' ) ) {
4 + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5 +}
6 +
4 7 /**
5 8 * Class that display the "custom folders" files.
6 9 *
7 - * @package Imagify
8 - * @since 1.7
9 - * @author Grégory Viguier
10 + * @since 1.7
10 11 */
11 12 class Imagify_Files_List_Table extends WP_List_Table {
12 13
13 14 /**
@@ -12,11 +13,10 @@
12 13
13 14 /**
14 15 * Class version.
15 16 *
16 - * @var string
17 + * @var string
17 18 * @since 1.7
18 - * @author Grégory Viguier
19 19 */
20 20 const VERSION = '1.1';
21 21
22 22 /**
@@ -21,11 +21,10 @@
21 21
22 22 /**
23 23 * Class version.
24 24 *
25 - * @var string
25 + * @var string
26 26 * @since 1.7
27 - * @author Grégory Viguier
28 27 */
29 28 const PER_PAGE_OPTION = 'imagify_files_per_page';
30 29
31 30 /**
@@ -30,22 +29,18 @@
30 29
31 30 /**
32 31 * List of the folders containing the listed files.
33 32 *
34 - * @var array
35 - * @since 1.7
36 - * @access protected
37 - * @author Grégory Viguier
33 + * @var array
34 + * @since 1.7
38 35 */
39 - protected $folders = array();
36 + protected $folders = [];
40 37
41 38 /**
42 39 * Filesystem object.
43 40 *
44 - * @var object Imagify_Filesystem
45 - * @since 1.7.1
46 - * @access protected
47 - * @author Grégory Viguier
41 + * @var Imagify_Filesystem
42 + * @since 1.7.1
48 43 */
49 44 protected $filesystem;
50 45
51 46 /**
@@ -50,12 +45,10 @@
50 45
51 46 /**
52 47 * Views object.
53 48 *
54 - * @var object Imagify_Views
55 - * @since 1.9
56 - * @access protected
57 - * @author Grégory Viguier
49 + * @var Imagify_Views
50 + * @since 1.9
58 51 */
59 52 protected $views;
60 53
61 54 /**
@@ -60,23 +53,23 @@
60 53
61 54 /**
62 55 * Constructor.
63 56 *
64 - * @since 1.7
65 - * @access public
66 - * @author Grégory Viguier
57 + * @since 1.7
67 58 *
68 59 * @param array $args An associative array of arguments.
69 60 */
70 - public function __construct( $args = array() ) {
71 - parent::__construct( array(
72 - 'plural' => 'imagify-files',
73 - 'screen' => isset( $args['screen'] ) ? convert_to_screen( $args['screen'] ) : null,
74 - ) );
61 + public function __construct( $args = [] ) {
62 + parent::__construct(
63 + [
64 + 'plural' => 'imagify-files',
65 + 'screen' => isset( $args['screen'] ) ? convert_to_screen( $args['screen'] ) : null,
66 + ]
67 + );
75 68
76 - $this->modes = array(
69 + $this->modes = [
77 70 'list' => __( 'List View', 'imagify' ),
78 - );
71 + ];
79 72
80 73 $this->filesystem = Imagify_Filesystem::get_instance();
81 74 $this->views = Imagify_Views::get_instance();
82 75 }
@@ -83,20 +76,21 @@
83 76
84 77 /**
85 78 * Prepares the list of items for displaying.
86 79 *
87 - * @since 1.7
88 - * @access public
89 - * @author Grégory Viguier
80 + * @since 1.7
90 81 */
91 82 public function prepare_items() {
92 83 global $wpdb;
93 84
94 - add_screen_option( 'per_page', array(
95 - 'label' => __( 'Number of files per page', 'imagify' ),
96 - 'default' => 20,
97 - 'option' => self::PER_PAGE_OPTION,
98 - ) );
85 + add_screen_option(
86 + 'per_page',
87 + [
88 + 'label' => __( 'Number of files per page', 'imagify' ),
89 + 'default' => 20,
90 + 'option' => self::PER_PAGE_OPTION,
91 + ]
92 + );
99 93
100 94 $files_db = Imagify_Files_DB::get_instance();
101 95 $files_table = $files_db->get_table_name();
102 96 $files_key = $files_db->get_primary_key();
@@ -108,14 +102,14 @@
108 102 $offset = ( $page - 1 ) * $per_page;
109 103 $orderbys = $this->get_sortable_columns();
110 104 $orderby = 'path';
111 105 $order = 'ASC';
112 - $folders = array();
113 - $file_ids = array();
106 + $folders = [];
107 + $file_ids = [];
114 108 $where = '';
115 109
116 - $sent_orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
117 - $sent_order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_STRING );
110 + $sent_orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
111 + $sent_order = isset( $_GET['order'] ) ? sanitize_text_field( wp_unslash( $_GET['order'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
118 112 $folder_filter = self::get_folder_filter();
119 113 $status_filter = self::get_status_filter();
120 114
121 115 if ( ! empty( $sent_orderby ) && isset( $orderbys[ $sent_orderby ] ) ) {
@@ -153,12 +147,14 @@
153 147 }
154 148 }
155 149
156 150 // Pagination.
157 - $this->set_pagination_args( array(
158 - 'total_items' => (int) $wpdb->get_var( "SELECT COUNT($files_key_esc) FROM $files_table $where" ), // WPCS: unprepared SQL ok.
159 - 'per_page' => $per_page,
160 - ) );
151 + $this->set_pagination_args(
152 + [
153 + 'total_items' => (int) $wpdb->get_var( "SELECT COUNT($files_key_esc) FROM $files_table $where" ), // WPCS: unprepared SQL ok.
154 + 'per_page' => $per_page,
155 + ]
156 + );
161 157
162 158 // Get items.
163 159 $this->items = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $files_table $where ORDER BY $orderby $order LIMIT %d, %d", $offset, $per_page ) ); // WPCS: unprepared SQL ok.
164 160
@@ -231,11 +227,9 @@
231 227
232 228 /**
233 229 * Message to be displayed when there are no items.
234 230 *
235 - * @since 1.7
236 - * @access public
237 - * @author Grégory Viguier
231 + * @since 1.7
238 232 */
239 233 public function no_items() {
240 234 if ( self::get_status_filter() ) {
241 235 // Filter by status.
@@ -254,13 +248,13 @@
254 248 return;
255 249 }
256 250 }
257 251
258 - $args = array(
252 + $args = [
259 253 'action' => 'imagify_scan_custom_folders',
260 254 '_wpnonce' => wp_create_nonce( 'imagify_scan_custom_folders' ),
261 255 '_wp_http_referer' => get_imagify_admin_url( 'files-list' ),
262 - );
256 + ];
263 257
264 258 if ( self::get_folder_filter() ) {
265 259 // A specific custom folder (selected or not).
266 260 $args['folder'] = self::get_folder_filter();
@@ -300,11 +294,9 @@
300 294
301 295 /**
302 296 * Display views.
303 297 *
304 - * @since 1.7
305 - * @access public
306 - * @author Grégory Viguier
298 + * @since 1.7
307 299 */
308 300 public function views() {
309 301 global $wpdb;
310 302
@@ -320,9 +312,9 @@
320 312 $files_table = $files_db->get_table_name();
321 313 $files_key_esc = esc_sql( $files_db->get_primary_key() );
322 314
323 315 // Filter files by folder.
324 - $folder_filters = array();
316 + $folder_filters = [];
325 317 $root_id = 0;
326 318 $counts = $wpdb->get_results( "SELECT folder_id, COUNT( $files_key_esc ) AS count FROM $files_table GROUP BY folder_id", OBJECT_K ); // WPCS: unprepared SQL ok.
327 319
328 320 foreach ( $folders as $folder ) {
@@ -327,8 +319,9 @@
327 319
328 320 foreach ( $folders as $folder ) {
329 321 if ( '{{ROOT}}/' === $folder->path ) {
330 322 $root_id = $folder->folder_id;
323 +
331 324 $folder_filters[ $folder->folder_id ] = '/';
332 325 } else {
333 326 $folder_filters[ $folder->folder_id ] = '/' . trim( $this->filesystem->make_path_relative( Imagify_Files_Scan::remove_placeholder( $folder->path ) ), '/' );
334 327 }
@@ -345,13 +338,13 @@
345 338 }
346 339
347 340 // Filter files by status.
348 341 $counts = $wpdb->get_results( "SELECT status, COUNT( $files_key_esc ) AS count FROM $files_table GROUP BY status", OBJECT_K ); // WPCS: unprepared SQL ok.
349 - $status_filters = array(
342 + $status_filters = [
350 343 'optimized' => 0,
351 344 'unoptimized' => 0,
352 345 'errors' => 0,
353 - );
346 + ];
354 347
355 348 if ( isset( $counts['success'] ) ) {
356 349 $status_filters['optimized'] += $counts['success']->count;
357 350 }
@@ -367,14 +360,14 @@
367 360 if ( isset( $counts['error'] ) ) {
368 361 $status_filters['errors'] += $counts['error']->count;
369 362 }
370 363
371 - $status_filters = array(
364 + $status_filters = [
372 365 '' => __( 'All Media Files', 'imagify' ),
373 366 'optimized' => _x( 'Optimized', 'Media Files', 'imagify' ) . ' (' . $status_filters['optimized'] . ')',
374 367 'unoptimized' => _x( 'Unoptimized', 'Media Files', 'imagify' ) . ' (' . $status_filters['unoptimized'] . ')',
375 368 'errors' => _x( 'Errors', 'Media Files', 'imagify' ) . ' (' . $status_filters['errors'] . ')',
376 - );
369 + ];
377 370
378 371 // Get submitted values.
379 372 $folder_filter = self::get_folder_filter();
380 373 $status_filter = self::get_status_filter();
@@ -387,29 +380,29 @@
387 380 ?>
388 381 <div class="wp-filter">
389 382 <div class="filter-items">
390 383
391 - <label for="folder-filter" class="screen-reader-text"><?php _e( 'Filter by folder', 'imagify' ); ?></label>
384 + <label for="folder-filter" class="screen-reader-text"><?php esc_html_e( 'Filter by folder', 'imagify' ); ?></label>
392 385 <select class="folder-filters" name="folder-filter" id="folder-filter">
393 386 <?php
394 387 printf( '<option value="%s"%s>%s</option>', '', selected( $folder_filter, 0, false ), esc_html__( 'All Folders', 'imagify' ) );
395 388
396 389 foreach ( $folder_filters as $folder_id => $label ) {
397 - printf( '<option value="%d"%s>%s</option>', $folder_id, selected( $folder_filter, $folder_id, false ), esc_html( $label ) );
390 + printf( '<option value="%d"%s>%s</option>', esc_attr( $folder_id ), selected( $folder_filter, $folder_id, false ), esc_html( $label ) );
398 391 }
399 392 ?>
400 393 </select>
401 394
402 - <label for="status-filter" class="screen-reader-text"><?php _e( 'Filter by status', 'imagify' ); ?></label>
395 + <label for="status-filter" class="screen-reader-text"><?php esc_html_e( 'Filter by status', 'imagify' ); ?></label>
403 396 <select class="folder-filters" name="status-filter" id="status-filter">
404 397 <?php
405 398 foreach ( $status_filters as $status => $label ) {
406 - printf( '<option value="%s"%s>%s</option>', $status, selected( $status_filter, $status, false ), esc_html( $label ) );
399 + printf( '<option value="%s"%s>%s</option>', esc_attr( $status ), selected( $status_filter, $status, false ), esc_html( $label ) );
407 400 }
408 401 ?>
409 402 </select>
410 403
411 - <?php submit_button( _x( 'Filter', 'verb', 'imagify' ), '', 'filter_action', false, array( 'id' => 'folders-query-submit' ) ); ?>
404 + <?php submit_button( _x( 'Filter', 'verb', 'imagify' ), '', 'filter_action', false, [ 'id' => 'folders-query-submit' ] ); ?>
412 405
413 406 <?php $this->extra_tablenav( 'bar' ); ?>
414 407 </div>
415 408 </div>
@@ -418,18 +411,16 @@
418 411
419 412 /**
420 413 * Get an associative array ( option_name => option_title ) with the list of bulk actions available on this table.
421 414 *
422 - * @since 1.7
423 - * @access public
424 - * @author Grégory Viguier
415 + * @since 1.7
425 416 *
426 417 * @return array
427 418 */
428 419 public function get_bulk_actions() {
429 - return array(
420 + return [
430 421 'imagify-bulk-refresh-status' => __( 'Refresh status', 'imagify' ),
431 - );
422 + ];
432 423 }
433 424
434 425 /**
435 426 * Get a list of columns. The format is:
@@ -434,16 +425,14 @@
434 425 /**
435 426 * Get a list of columns. The format is:
436 427 * 'internal-name' => 'Title'
437 428 *
438 - * @since 1.7
439 - * @access public
440 - * @author Grégory Viguier
429 + * @since 1.7
441 430 *
442 431 * @return array
443 432 */
444 433 public function get_columns() {
445 - return array(
434 + return [
446 435 'cb' => '<input type="checkbox" />',
447 436 'title' => __( 'File', 'imagify' ),
448 437 'folder' => __( 'Folder', 'imagify' ),
449 438 'optimization' => __( 'Optimization', 'imagify' ),
@@ -449,9 +438,9 @@
449 438 'optimization' => __( 'Optimization', 'imagify' ),
450 439 'status' => __( 'Status', 'imagify' ),
451 440 'optimization_level' => __( 'Optimization Level', 'imagify' ),
452 441 'actions' => __( 'Actions', 'imagify' ),
453 - );
442 + ];
454 443 }
455 444
456 445 /**
457 446 * Get a list of sortable columns. The format is:
@@ -460,29 +449,25 @@
460 449 * 'internal-name' => array( 'orderby', true )
461 450 *
462 451 * The second format will make the initial sorting order be descending.
463 452 *
464 - * @since 1.7
465 - * @access public
466 - * @author Grégory Viguier
453 + * @since 1.7
467 454 *
468 455 * @return array
469 456 */
470 457 public function get_sortable_columns() {
471 - return array(
458 + return [
472 459 'folder' => 'folder',
473 - 'optimization' => array( 'optimization', true ),
460 + 'optimization' => [ 'optimization', true ],
474 461 'status' => 'status',
475 - 'optimization_level' => array( 'optimization_level', true ),
476 - );
462 + 'optimization_level' => [ 'optimization_level', true ],
463 + ];
477 464 }
478 465
479 466 /**
480 467 * Get a column contents.
481 468 *
482 - * @since 1.7
483 - * @access public
484 - * @author Grégory Viguier
469 + * @since 1.7
485 470 *
486 471 * @param string $column The column "name": "cb", "title", "optimization_level", etc.
487 472 * @param object $item The current item. It must contain at least a $process property.
488 473 * @return string HTML contents,
@@ -492,9 +477,9 @@
492 477 return '';
493 478 }
494 479
495 480 ob_start();
496 - call_user_func( array( $this, 'column_' . $column ), $item );
481 + call_user_func( [ $this, 'column_' . $column ], $item );
497 482 return ob_get_clean();
498 483 }
499 484
500 485 /**
@@ -499,11 +484,9 @@
499 484
500 485 /**
501 486 * Handles the checkbox column output.
502 487 *
503 - * @since 1.7
504 - * @access public
505 - * @author Grégory Viguier
488 + * @since 1.7
506 489 *
507 490 * @param object $item The current item. It must contain at least a $process property.
508 491 */
509 492 public function column_cb( $item ) {
@@ -508,10 +491,10 @@
508 491 */
509 492 public function column_cb( $item ) {
510 493 $media_id = $item->process->get_media()->get_id();
511 494 ?>
512 - <label class="screen-reader-text" for="cb-select-<?php echo $media_id; ?>"><?php _ex( 'Select file', 'checkbox label', 'imagify' ); ?></label>
513 - <input id="cb-select-<?php echo $media_id; ?>" type="checkbox" name="bulk_select[]" value="<?php echo $media_id; ?>" />
495 + <label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $media_id ); ?>"><?php echo esc_html_x( 'Select file', 'checkbox label', 'imagify' ); ?></label>
496 + <input id="cb-select-<?php echo esc_attr( $media_id ); ?>" type="checkbox" name="bulk_select[]" value="<?php echo esc_attr( $media_id ); ?>" />
514 497 <?php
515 498 }
516 499
517 500 /**
@@ -516,11 +499,9 @@
516 499
517 500 /**
518 501 * Handles the title column output.
519 502 *
520 - * @since 1.7
521 - * @access public
522 - * @author Grégory Viguier
503 + * @since 1.7
523 504 *
524 505 * @param object $item The current item. It must contain at least a $process property.
525 506 */
526 507 public function column_title( $item ) {
@@ -550,11 +531,11 @@
550 531 }
551 532 ?>
552 533 <strong class="has-media-icon">
553 534 <a href="<?php echo esc_url( $url ); ?>" target="_blank">
554 - <span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?><?php echo $orientation; ?>">
535 + <span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?><?php echo esc_attr( $orientation ); ?>">
555 536 <span class="centered">
556 - <?php echo $image_tag; ?>
537 + <?php echo $image_tag; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
557 538 </span>
558 539 </span>
559 540 <?php echo esc_html( $title ); ?>
560 541 </a>
@@ -567,11 +548,9 @@
567 548
568 549 /**
569 550 * Handles the parent folder column output.
570 551 *
571 - * @since 1.7
572 - * @access public
573 - * @author Grégory Viguier
552 + * @since 1.7
574 553 *
575 554 * @param object $item The current item. It must contain at least a $process property.
576 555 */
577 556 public function column_folder( $item ) {
@@ -589,16 +568,16 @@
589 568 }
590 569
591 570 if ( '{{ROOT}}/' === $item->folder_path ) {
592 571 // It's the site's root.
593 - printf( $format, __( 'Site\'s root', 'imagify' ) );
572 + printf( $format, esc_html__( 'Site\'s root', 'imagify' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
594 573 } else {
595 - printf( $format, '<code>/' . trim( $this->filesystem->make_path_relative( Imagify_Files_Scan::remove_placeholder( $item->folder_path ) ), '/' ) . '</code>' );
574 + printf( $format, '<code>/' . trim( $this->filesystem->make_path_relative( Imagify_Files_Scan::remove_placeholder( $item->folder_path ) ), '/' ) . '</code>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
596 575 }
597 576
598 577 if ( ! $item->is_folder_active ) {
599 578 echo '<br/>';
600 - _e( 'This folder is not selected for bulk optimization.', 'imagify' );
579 + esc_html_e( 'This folder is not selected for bulk optimization.', 'imagify' );
601 580 }
602 581 }
603 582
604 583 /**
@@ -603,11 +582,9 @@
603 582
604 583 /**
605 584 * Handles the optimization data column output.
606 585 *
607 - * @since 1.7
608 - * @access public
609 - * @author Grégory Viguier
586 + * @since 1.7
610 587 *
611 588 * @param object $item The current item. It must contain at least a $process property.
612 589 */
613 590 public function column_optimization( $item ) {
@@ -628,24 +605,24 @@
628 605 <span class="data"><?php esc_html_e( 'Original Saving:', 'imagify' ); ?></span>
629 606 <strong class="data-value">
630 607 <span class="imagify-chart">
631 608 <span class="imagify-chart-container">
632 - <canvas class="imagify-consumption-chart imagify-consumption-chart-<?php echo $media_id; ?>" width="15" height="15"></canvas>
609 + <canvas class="imagify-consumption-chart imagify-consumption-chart-<?php echo esc_attr( $media_id ); ?>" width="15" height="15"></canvas>
633 610 <?php if ( wp_doing_ajax() ) { ?>
634 - <script type="text/javascript">jQuery( window ).trigger( "canvasprinted.imagify", [ ".imagify-consumption-chart-<?php echo $media_id; ?>" ] ); </script>
611 + <script type="text/javascript">jQuery( window ).trigger( "canvasprinted.imagify", [ ".imagify-consumption-chart-<?php echo esc_attr( $media_id ); ?>" ] ); </script>
635 612 <?php } ?>
636 613 </span>
637 614 </span>
638 - <span class="imagify-chart-value"><?php echo $data->get_saving_percent(); ?></span>%
615 + <span class="imagify-chart-value"><?php echo esc_html( $data->get_saving_percent() ); ?></span>%
639 616 </strong>
640 617 </li>
641 618 <?php
642 619 if ( $item->process->get_media()->is_image() ) {
643 - $has_webp = $item->process->has_webp() ? __( 'Yes', 'imagify' ) : __( 'No', 'imagify' );
620 + $has_nextgen = $item->process->has_next_gen() ? __( 'Yes', 'imagify' ) : __( 'No', 'imagify' );
644 621 ?>
645 622 <li class="imagify-data-item">
646 - <span class="data"><?php esc_html_e( 'WebP generated:', 'imagify' ); ?></span>
647 - <strong class="data-value"><?php echo esc_html( $has_webp ); ?></strong>
623 + <span class="data"><?php esc_html_e( 'Next-Gen generated:', 'imagify' ); ?></span>
624 + <strong class="data-value"><?php echo esc_html( $has_nextgen ); ?></strong>
648 625 </li>
649 626 <?php
650 627 }
651 628 }
@@ -656,11 +633,9 @@
656 633
657 634 /**
658 635 * Handles the status column output.
659 636 *
660 - * @since 1.7
661 - * @access public
662 - * @author Grégory Viguier
637 + * @since 1.7
663 638 *
664 639 * @param object $item The current item. It must contain at least a $process property.
665 640 */
666 641 public function column_status( $item ) {
@@ -684,9 +659,9 @@
684 659 // The file has changed or is missing.
685 660 $messages[] = '<strong class="imagify-status-changed">' . esc_html__( 'The file has changed', 'imagify' ) . '</strong>';
686 661 }
687 662
688 - echo implode( '<br/>', $messages );
663 + echo implode( '<br/>', $messages ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
689 664
690 665 $this->refresh_status_button( $item );
691 666 }
692 667
@@ -692,11 +667,9 @@
692 667
693 668 /**
694 669 * Handles the optimization level column output.
695 670 *
696 - * @since 1.7
697 - * @access public
698 - * @author Grégory Viguier
671 + * @since 1.7
699 672 *
700 673 * @param object $item The current item. It must contain at least a $process property.
701 674 */
702 675 public function column_optimization_level( $item ) {
@@ -702,9 +675,9 @@
702 675 public function column_optimization_level( $item ) {
703 676 $data = $item->process->get_data();
704 677
705 678 if ( ! $data->is_error() ) {
706 - echo imagify_get_optimization_level_label( $data->get_optimization_level(), '%ICON% %s' );
679 + echo imagify_get_optimization_level_label( $data->get_optimization_level(), '%ICON% %s' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
707 680 }
708 681 }
709 682
710 683 /**
@@ -709,11 +682,9 @@
709 682
710 683 /**
711 684 * Handles the actions column output.
712 685 *
713 - * @since 1.7
714 - * @access public
715 - * @author Grégory Viguier
686 + * @since 1.7
716 687 *
717 688 * @param object $item The current item. It must contain at least a $process property.
718 689 */
719 690 public function column_actions( $item ) {
@@ -724,17 +695,20 @@
724 695 if ( ! $done ) {
725 696 // No need to display this on every row.
726 697 $done = true;
727 698 esc_html_e( 'Invalid API key', 'imagify' );
728 - echo '<br/><a href="' . esc_url( get_imagify_admin_url() ) . '">' . __( 'Check your Settings', 'imagify' ) . '</a>';
699 + echo '<br/><a href="' . esc_url( get_imagify_admin_url() ) . '">' . esc_html__( 'Check your Settings', 'imagify' ) . '</a>';
729 700 }
730 701 return;
731 702 }
732 703
733 704 if ( $item->process->is_locked() ) {
734 - Imagify_Views::get_instance()->print_template( 'button-processing', [
735 - 'label' => __( 'Optimizing...', 'imagify' ),
736 - ] );
705 + Imagify_Views::get_instance()->print_template(
706 + 'button-processing',
707 + [
708 + 'label' => __( 'Optimizing...', 'imagify' ),
709 + ]
710 + );
737 711 return;
738 712 }
739 713
740 714 $this->optimize_button( $item );
@@ -739,10 +713,10 @@
739 713
740 714 $this->optimize_button( $item );
741 715 $this->retry_button( $item );
742 716 $this->reoptimize_buttons( $item );
743 - $this->generate_webp_versions_button( $item );
744 - $this->delete_webp_versions_button( $item );
717 + $this->generate_nextgen_versions_button( $item );
718 + $this->delete_nextgen_versions_button( $item );
745 719 $this->restore_button( $item );
746 720 }
747 721
748 722 /**
@@ -747,11 +721,9 @@
747 721
748 722 /**
749 723 * Prints a button to optimize the file.
750 724 *
751 - * @since 1.7
752 - * @access protected
753 - * @author Grégory Viguier
725 + * @since 1.7
754 726 *
755 727 * @param object $item The current item. It must contain at least a $process property.
756 728 */
757 729 protected function optimize_button( $item ) {
@@ -761,26 +733,30 @@
761 733 }
762 734
763 735 $media = $item->process->get_media();
764 736 $class = $media->has_backup() ? ' file-has-backup' : '';
765 - $url = get_imagify_admin_url( 'optimize-file', [
766 - 'attachment_id' => $media->get_id(),
767 - ] );
737 + $url = get_imagify_admin_url(
738 + 'optimize-file',
739 + [
740 + 'attachment_id' => $media->get_id(),
741 + ]
742 + );
768 743
769 - echo $this->views->get_template( 'button/optimize', [
770 - 'url' => $url,
771 - 'atts' => [
772 - 'class' => 'button-primary button-imagify-optimize' . $class,
773 - ],
774 - ] );
744 + echo $this->views->get_template( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
745 + 'button/optimize',
746 + [
747 + 'url' => $url, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
748 + 'atts' => [
749 + 'class' => 'button-primary button-imagify-optimize' . esc_attr( $class ),
750 + ],
751 + ]
752 + );
775 753 }
776 754
777 755 /**
778 756 * Prints a button to retry to optimize the file.
779 757 *
780 - * @since 1.7
781 - * @access protected
782 - * @author Grégory Viguier
758 + * @since 1.7
783 759 *
784 760 * @param object $item The current item. It must contain at least a $process property.
785 761 */
786 762 protected function retry_button( $item ) {
@@ -792,18 +768,24 @@
792 768 }
793 769
794 770 $media = $item->process->get_media();
795 771 $class = $media->has_backup() ? ' file-has-backup' : '';
796 - $url = get_imagify_admin_url( 'optimize-file', [
797 - 'attachment_id' => $media->get_id(),
798 - ] );
772 + $url = get_imagify_admin_url(
773 + 'optimize-file',
774 + [
775 + 'attachment_id' => $media->get_id(),
776 + ]
777 + );
799 778
800 - echo $this->views->get_template( 'button/retry-optimize', [
801 - 'url' => $url,
802 - 'atts' => [
803 - 'class' => 'button button-imagify-optimize' . $class,
804 - ],
805 - ] );
779 + echo $this->views->get_template( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
780 + 'button/retry-optimize',
781 + [
782 + 'url' => $url, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
783 + 'atts' => [
784 + 'class' => 'button button-imagify-optimize' . esc_attr( $class ),
785 + ],
786 + ]
787 + );
806 788 echo '<br/>';
807 789 }
808 790
809 791 /**
@@ -808,11 +790,9 @@
808 790
809 791 /**
810 792 * Prints buttons to re-optimize the file to other levels.
811 793 *
812 - * @since 1.7
813 - * @access protected
814 - * @author Grégory Viguier
794 + * @since 1.7
815 795 *
816 796 * @param object $item The current item. It must contain at least a $process property.
817 797 */
818 798 protected function reoptimize_buttons( $item ) {
@@ -835,56 +815,50 @@
835 815 $media_level = $data->get_optimization_level();
836 816 $data = [];
837 817 $url_args = [ 'attachment_id' => $media->get_id() ];
838 818
839 - foreach ( [ 2, 1, 0 ] as $level ) {
840 - /**
841 - * Display a link if:
842 - * - the level is lower than the one used to optimize the media,
843 - * - or, the level is higher and the media is not already optimized.
844 - */
845 - if ( $media_level < $level || ( $media_level > $level && ! $is_already_optimized ) ) {
846 - $url_args['optimization_level'] = $level;
847 - $data['optimization_level'] = $level;
848 - $data['url'] = get_imagify_admin_url( 'reoptimize-file', $url_args );
819 + if ( $media_level < 1 ) {
820 + $url_args['optimization_level'] = 2;
821 + $data['optimization_level'] = 2;
822 + $data['url'] = get_imagify_admin_url( 'reoptimize-file', $url_args );
849 823
850 - echo $this->views->get_template( 'button/re-optimize', $data );
851 - echo '<br/>';
852 - }
824 + echo $this->views->get_template( 'button/re-optimize', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
825 + } elseif ( $media_level > 0 ) {
826 + $url_args['optimization_level'] = 0;
827 + $data['optimization_level'] = 0;
828 + $data['url'] = get_imagify_admin_url( 'reoptimize-file', $url_args );
829 +
830 + echo $this->views->get_template( 'button/re-optimize', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
853 831 }
854 832 }
855 833
856 834 /**
857 - * Prints a button to generate WebP versions if they are missing.
835 + * Prints a button to generate Next gen versions if they are missing.
858 836 *
859 - * @since 1.7
860 - * @access protected
861 - * @author Grégory Viguier
837 + * @since 1.7
862 838 *
863 839 * @param object $item The current item. It must contain at least a $process property.
864 840 */
865 - protected function generate_webp_versions_button( $item ) {
866 - $button = get_imagify_attachment_generate_webp_versions_link( $item->process );
841 + protected function generate_nextgen_versions_button( $item ) {
842 + $button = get_imagify_attachment_generate_nextgen_versions_link( $item->process );
867 843
868 844 if ( $button ) {
869 - echo $button . '<br/>';
845 + echo $button . '<br/>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
870 846 }
871 847 }
872 848
873 849 /**
874 - * Prints a button to delete WebP versions when the status is "already_optimized".
850 + * Prints a button to delete next-gen versions when the status is "already_optimized".
875 851 *
876 - * @since 1.9.6
877 - * @access protected
878 - * @author Grégory Viguier
852 + * @since 1.9.6
879 853 *
880 854 * @param object $item The current item. It must contain at least a $process property.
881 855 */
882 - protected function delete_webp_versions_button( $item ) {
883 - $button = get_imagify_attachment_delete_webp_versions_link( $item->process );
856 + protected function delete_nextgen_versions_button( $item ) {
857 + $button = get_imagify_attachment_delete_nextgen_versions_link( $item->process );
884 858
885 859 if ( $button ) {
886 - echo $button . '<br/>';
860 + echo $button . '<br/>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
887 861 }
888 862 }
889 863
890 864 /**
@@ -889,11 +863,9 @@
889 863
890 864 /**
891 865 * Prints a button to restore the file.
892 866 *
893 - * @since 1.7
894 - * @access protected
895 - * @author Grégory Viguier
867 + * @since 1.7
896 868 *
897 869 * @param object $item The current item. It must contain at least a $process property.
898 870 */
899 871 protected function restore_button( $item ) {
@@ -903,39 +875,41 @@
903 875 if ( ! $data->is_optimized() || ! $media->has_backup() ) {
904 876 return;
905 877 }
906 878
907 - $url = get_imagify_admin_url( 'restore-file', array(
908 - 'attachment_id' => $media->get_id(),
909 - ) );
879 + $url = get_imagify_admin_url(
880 + 'restore-file',
881 + [
882 + 'attachment_id' => $media->get_id(),
883 + ]
884 + );
910 885
911 - echo $this->views->get_template( 'button/restore', [ 'url' => $url ] );
886 + echo $this->views->get_template( 'button/restore', [ 'url' => $url ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
912 887 }
913 888
914 889 /**
915 890 * Prints a button to check if the file has been modified or not.
916 891 *
917 - * @since 1.7
918 - * @access protected
919 - * @author Grégory Viguier
892 + * @since 1.7
920 893 *
921 894 * @param object $item The current item. It must contain at least a $process property.
922 895 */
923 896 protected function refresh_status_button( $item ) {
924 - $url = get_imagify_admin_url( 'refresh-file-modified', array(
925 - 'attachment_id' => $item->process->get_media()->get_id(),
926 - ) );
897 + $url = get_imagify_admin_url(
898 + 'refresh-file-modified',
899 + [
900 + 'attachment_id' => $item->process->get_media()->get_id(),
901 + ]
902 + );
927 903
928 904 echo '<br/>';
929 - echo $this->views->get_template( 'button/refresh-status', [ 'url' => $url ] );
905 + echo $this->views->get_template( 'button/refresh-status', [ 'url' => $url ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
930 906 }
931 907
932 908 /**
933 909 * Prints a button for the comparison tool (before / after optimization).
934 910 *
935 - * @since 1.7
936 - * @access protected
937 - * @author Grégory Viguier
911 + * @since 1.7
938 912 *
939 913 * @param object $item The current item. It must contain at least a $process property.
940 914 */
941 915 protected function comparison_tool_button( $item ) {
@@ -959,20 +933,23 @@
959 933 }
960 934
961 935 $backup_url = $media->get_backup_url();
962 936
963 - echo $this->views->get_template( 'button/compare-images', [
964 - 'url' => $backup_url,
965 - 'backup_url' => $backup_url,
966 - 'original_url' => $media->get_fullsize_url(),
967 - 'media_id' => $media->get_id(),
968 - 'width' => $dimensions['width'],
969 - 'height' => $dimensions['height'],
970 - ] );
937 + echo $this->views->get_template( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
938 + 'button/compare-images',
939 + [
940 + 'url' => $backup_url, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
941 + 'backup_url' => $backup_url, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
942 + 'original_url' => $media->get_fullsize_url(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
943 + 'media_id' => $media->get_id(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
944 + 'width' => $dimensions['width'], // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
945 + 'height' => $dimensions['height'], // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
946 + ]
947 + );
971 948
972 949 if ( wp_doing_ajax() ) {
973 950 ?>
974 - <script type="text/javascript">jQuery( window ).trigger( 'comparisonprinted.imagify', [ <?php echo $media->get_id(); ?> ] ); </script>
951 + <script type="text/javascript">jQuery( window ).trigger( 'comparisonprinted.imagify', [ <?php echo esc_js( $media->get_id() ); ?> ] ); </script>
975 952 <?php
976 953 }
977 954 }
978 955
@@ -979,11 +956,9 @@
979 956 /**
980 957 * Add the folder_id and folder_path properties to the $item if not set yet.
981 958 * It may happen if the $item doesn't come from the prepare() method.
982 959 *
983 - * @since 1.7
984 - * @access protected
985 - * @author Grégory Viguier
960 + * @since 1.7
986 961 *
987 962 * @param object $item The current item. It must contain at least a $process property.
988 963 * @return object The current item.
989 964 */
@@ -1016,11 +991,9 @@
1016 991
1017 992 /**
1018 993 * Get the name of the default primary column.
1019 994 *
1020 - * @since 1.7
1021 - * @access protected
1022 - * @author Grégory Viguier
995 + * @since 1.7
1023 996 *
1024 997 * @return string Name of the default primary column, in this case, 'title'.
1025 998 */
1026 999 protected function get_default_primary_column_name() {
@@ -1029,24 +1002,20 @@
1029 1002
1030 1003 /**
1031 1004 * Get a list of CSS classes for the WP_List_Table table tag.
1032 1005 *
1033 - * @since 1.7
1034 - * @access protected
1035 - * @author Grégory Viguier
1006 + * @since 1.7
1036 1007 *
1037 1008 * @return array List of CSS classes for the table tag.
1038 1009 */
1039 1010 protected function get_table_classes() {
1040 - return array( 'widefat', 'fixed', 'striped', 'media', $this->_args['plural'] );
1011 + return [ 'widefat', 'fixed', 'striped', 'media', $this->_args['plural'] ];
1041 1012 }
1042 1013
1043 1014 /**
1044 1015 * Allow to save the screen options when submitted by the user.
1045 1016 *
1046 - * @since 1.7
1047 - * @access public
1048 - * @author Grégory Viguier
1017 + * @since 1.7
1049 1018 *
1050 1019 * @param bool|int $status Screen option value. Default false to skip.
1051 1020 * @param string $option The option name.
1052 1021 * @param int $value The number of rows to use.
@@ -1062,11 +1031,9 @@
1062 1031
1063 1032 /**
1064 1033 * Get the requested folder filter.
1065 1034 *
1066 - * @since 1.7
1067 - * @access public
1068 - * @author Grégory Viguier
1035 + * @since 1.7
1069 1036 *
1070 1037 * @return string
1071 1038 */
1072 1039 public static function get_folder_filter() {
@@ -1082,11 +1049,9 @@
1082 1049
1083 1050 /**
1084 1051 * Get the requested status filter.
1085 1052 *
1086 - * @since 1.7
1087 - * @access public
1088 - * @author Grégory Viguier
1053 + * @since 1.7
1089 1054 *
1090 1055 * @return string
1091 1056 */
1092 1057 public static function get_status_filter() {
@@ -1095,14 +1060,14 @@
1095 1060 if ( isset( $filter ) ) {
1096 1061 return $filter;
1097 1062 }
1098 1063
1099 - $values = array(
1064 + $values = [
1100 1065 'optimized' => 1,
1101 1066 'unoptimized' => 1,
1102 1067 'errors' => 1,
1103 - );
1104 - $filter = trim( filter_input( INPUT_GET, 'status-filter', FILTER_SANITIZE_STRING ) );
1068 + ];
1069 + $filter = isset( $_GET['status-filter'] ) ? trim( sanitize_text_field( wp_unslash( $_GET['status-filter'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
1105 1070 $filter = isset( $values[ $filter ] ) ? $filter : '';
1106 1071
1107 1072 return $filter;
1108 1073 }