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 | classes/Bulk/AbstractBulk.php +64 -26 1.10 → trunk View file →
@@ -1,24 +1,20 @@
1 1 <?php
2 2 namespace Imagify\Bulk;
3 3
4 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
4 +use Imagify_Filesystem;
5 5
6 6 /**
7 7 * Abstract class to use for bulk.
8 8 *
9 - * @since 1.9
10 - * @author Grégory Viguier
9 + * @since 1.9
11 10 */
12 11 abstract class AbstractBulk implements BulkInterface {
13 -
14 12 /**
15 13 * Filesystem object.
16 14 *
17 - * @var \Imagify_Filesystem
18 - * @since 1.9
19 - * @access protected
20 - * @author Grégory Viguier
15 + * @var Imagify_Filesystem
16 + * @since 1.9
21 17 */
22 18 protected $filesystem;
23 19
24 20 /**
@@ -23,22 +19,18 @@
23 19
24 20 /**
25 21 * The constructor.
26 22 *
27 - * @since 1.9
28 - * @access public
29 - * @author Grégory Viguier
23 + * @since 1.9
30 24 */
31 25 public function __construct() {
32 - $this->filesystem = \Imagify_Filesystem::get_instance();
26 + $this->filesystem = Imagify_Filesystem::get_instance();
33 27 }
34 28
35 29 /**
36 30 * Format context data (stats).
37 31 *
38 - * @since 1.9
39 - * @access protected
40 - * @author Grégory Viguier
32 + * @since 1.9
41 33 *
42 34 * @param array $data {
43 35 * The data to format.
44 36 *
@@ -57,32 +49,78 @@
57 49 * @type string $original-size Original filesize.
58 50 * }
59 51 */
60 52 protected function format_context_data( $data ) {
61 - /* translators: %s is a formatted number, dont use %d. */
62 - $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>' );
53 + $defaults = [
54 + 'count-optimized' => '',
55 + 'count-errors' => '',
56 + 'optimized-size' => '',
57 + 'original-size' => '',
58 + ];
63 59
64 - if ( $data['count-errors'] ) {
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'] ) ) {
65 76 /* translators: %s is a formatted number, dont use %d. */
66 77 $data['count-errors'] = sprintf( _n( '%s Error', '%s Errors', $data['count-errors'], 'imagify' ), '<span>' . number_format_i18n( $data['count-errors'] ) . '</span>' );
67 78 $data['count-errors'] .= ' <a href="' . esc_url( $data['errors_url'] ) . '">' . __( 'View Errors', 'imagify' ) . '</a>';
68 - } else {
69 - $data['count-errors'] = '';
70 79 }
71 80
72 - if ( $data['optimized-size'] ) {
81 + if ( ! empty( $data['optimized-size'] ) ) {
73 82 $data['optimized-size'] = '<span class="imagify-cell-label">' . __( 'Optimized Filesize', 'imagify' ) . '</span> ' . imagify_size_format( $data['optimized-size'], 2 );
74 - } else {
75 - $data['optimized'] = '';
76 83 }
77 84
78 - if ( $data['original-size'] ) {
85 + if ( ! empty( $data['original-size'] ) ) {
79 86 $data['original-size'] = '<span class="imagify-cell-label">' . __( 'Original Filesize', 'imagify' ) . '</span> ' . imagify_size_format( $data['original-size'], 2 );
80 - } else {
81 - $data['original-size'] = '';
82 87 }
83 88
84 89 unset( $data['errors_url'] );
85 90
86 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'] );
87 125 }
88 126 }