PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.0
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.0
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
imagify / classes / Bulk / AbstractBulk.php

AbstractBulk.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.0, at classes/Bulk/AbstractBulk.php

127 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\Bulk;
3
4 use Imagify_Filesystem;
5
6 /**
7 * Abstract class to use for bulk.
8 *
9 * @since 1.9
10 */
11 abstract class AbstractBulk implements BulkInterface {
12 /**
13 * Filesystem object.
14 *
15 * @var Imagify_Filesystem
16 * @since 1.9
17 */
18 protected $filesystem;
19
20 /**
21 * The constructor.
22 *
23 * @since 1.9
24 */
25 public function __construct() {
26 $this->filesystem = Imagify_Filesystem::get_instance();
27 }
28
29 /**
30 * Format context data (stats).
31 *
32 * @since 1.9
33 *
34 * @param array $data {
35 * The data to format.
36 *
37 * @type int $count-optimized Number of media optimized.
38 * @type int $count-errors Number of media having an optimization error.
39 * @type int $optimized-size Optimized filesize.
40 * @type int $original-size Original filesize.
41 * @type string $errors_url URL to the page listing the optimization errors.
42 * }
43 * @return array {
44 * The formated data.
45 *
46 * @type string $count-optimized Number of media optimized.
47 * @type string $count-errors Number of media having an optimization error, with a link to the page listing the optimization errors.
48 * @type string $optimized-size Optimized filesize.
49 * @type string $original-size Original filesize.
50 * }
51 */
52 protected function format_context_data( $data ) {
53 $defaults = [
54 'count-optimized' => '',
55 'count-errors' => '',
56 'optimized-size' => '',
57 'original-size' => '',
58 ];
59
60 $data = wp_parse_args( $data, $defaults );
61
62 $data = array_map(
63 function ( $item ) {
64 return empty( $item ) ? '' : $item;
65 },
66 $data
67 );
68
69 if ( ! empty( $data['count-optimized'] ) ) {
70 // translators: %s is a formatted number, dont use %d.
71 $data['count-optimized'] = sprintf( _n( '%s Media File Optimized', '%s Media Files Optimized', $data['count-optimized'], 'imagify' ), '<span>' . number_format_i18n( $data['count-optimized'] ) . '</span>' );
72
73 }
74
75 if ( ! empty( $data['count-errors'] ) ) {
76 /* translators: %s is a formatted number, dont use %d. */
77 $data['count-errors'] = sprintf( _n( '%s Error', '%s Errors', $data['count-errors'], 'imagify' ), '<span>' . number_format_i18n( $data['count-errors'] ) . '</span>' );
78 $data['count-errors'] .= ' <a href="' . esc_url( $data['errors_url'] ) . '">' . __( 'View Errors', 'imagify' ) . '</a>';
79 }
80
81 if ( ! empty( $data['optimized-size'] ) ) {
82 $data['optimized-size'] = '<span class="imagify-cell-label">' . __( 'Optimized Filesize', 'imagify' ) . '</span> ' . imagify_size_format( $data['optimized-size'], 2 );
83 }
84
85 if ( ! empty( $data['original-size'] ) ) {
86 $data['original-size'] = '<span class="imagify-cell-label">' . __( 'Original Filesize', 'imagify' ) . '</span> ' . imagify_size_format( $data['original-size'], 2 );
87 }
88
89 unset( $data['errors_url'] );
90
91 return $data;
92 }
93
94 /**
95 * Attempts to set no limit to the PHP timeout for time intensive processes.
96 *
97 * @return void
98 */
99 protected function set_no_time_limit() {
100 if (
101 function_exists( 'set_time_limit' )
102 &&
103 false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' )
104 && ! ini_get( 'safe_mode' ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
105 ) {
106 @set_time_limit( 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
107 }
108 }
109
110 /**
111 * Tell if there are optimized media without next-gen versions.
112 *
113 * @since 1.9
114 *
115 * @return int The number of media.
116 */
117 public function has_optimized_media_without_nextgen() {
118 $format = get_imagify_option( 'optimization_format' );
119
120 if ( 'off' === $format ) {
121 return 0;
122 }
123
124 return count( $this->get_optimized_media_ids_without_format( $format )['ids'] );
125 }
126 }
127