PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.4
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.4
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 / Optimization / Data / Noop.php

Noop.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.9.4, at classes/Optimization/Data/Noop.php

273 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\Optimization\Data;
3
4 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
5
6 /**
7 * Fallback class optimization data of "media groups" (aka attachments).
8 *
9 * @since 1.9
10 * @author Grégory Viguier
11 */
12 class Noop implements DataInterface {
13
14 /**
15 * Tell if the given entry can be accepted in the constructor.
16 * For example it can include `is_numeric( $id )` if the constructor accepts integers.
17 *
18 * @since 1.9
19 * @access public
20 * @author Grégory Viguier
21 *
22 * @param mixed $id Whatever.
23 * @return bool
24 */
25 public static function constructor_accepts( $id ) {
26 return false;
27 }
28
29 /**
30 * Get the media instance.
31 *
32 * @since 1.9
33 * @access public
34 * @author Grégory Viguier
35 *
36 * @return MediaInterface|false
37 */
38 public function get_media() {
39 return false;
40 }
41
42 /**
43 * Tell if the current media is valid.
44 *
45 * @since 1.9
46 * @access public
47 * @author Grégory Viguier
48 *
49 * @return bool
50 */
51 public function is_valid() {
52 return false;
53 }
54
55
56 /** ----------------------------------------------------------------------------------------- */
57 /** OPTIMIZATION DATA ======================================================================= */
58 /** ----------------------------------------------------------------------------------------- */
59
60 /**
61 * Check if the main file is optimized (by Imagify).
62 *
63 * @since 1.9
64 * @access public
65 * @author Grégory Viguier
66 *
67 * @return bool True if the media is optimized.
68 */
69 public function is_optimized() {
70 return false;
71 }
72
73 /**
74 * Check if the main file is optimized (NOT by Imagify).
75 *
76 * @since 1.9
77 * @access public
78 * @author Grégory Viguier
79 *
80 * @return bool True if the media is optimized.
81 */
82 public function is_already_optimized() {
83 return false;
84 }
85
86 /**
87 * Check if the main file is optimized (by Imagify).
88 *
89 * @since 1.9
90 * @access public
91 * @author Grégory Viguier
92 *
93 * @return bool True if the media is optimized.
94 */
95 public function is_error() {
96 return false;
97 }
98
99 /**
100 * Get the whole media optimization data.
101 *
102 * @since 1.9
103 * @access public
104 * @author Grégory Viguier
105 *
106 * @return array The data. See parent method for details.
107 */
108 public function get_optimization_data() {
109 return [
110 'status' => '',
111 'level' => false,
112 'sizes' => [],
113 'stats' => [
114 'original_size' => 0,
115 'optimized_size' => 0,
116 'percent' => 0,
117 ],
118 ];
119 }
120
121 /**
122 * Update the optimization data, level, and status for a size.
123 *
124 * @since 1.9
125 * @access public
126 * @author Grégory Viguier
127 *
128 * @param string $size The size name.
129 * @param array $data The optimization data. See parent method for details.
130 */
131 public function update_size_optimization_data( $size, array $data ) {}
132
133 /**
134 * Delete the media optimization data, level, and status.
135 *
136 * @since 1.9
137 * @access public
138 * @author Grégory Viguier
139 */
140 public function delete_optimization_data() {}
141
142 /**
143 * Get the media's optimization level.
144 *
145 * @since 1.9
146 * @access public
147 * @author Grégory Viguier
148 *
149 * @return int|bool The optimization level. False if not optimized.
150 */
151 public function get_optimization_level() {
152 return false;
153 }
154
155 /**
156 * Get the media's optimization status (success or error).
157 *
158 * @since 1.9
159 * @access public
160 * @author Grégory Viguier
161 *
162 * @return string The optimization status. An empty string if there is none.
163 */
164 public function get_optimization_status() {
165 return '';
166 }
167
168 /**
169 * Count number of optimized sizes.
170 *
171 * @since 1.9
172 * @access public
173 * @author Grégory Viguier
174 *
175 * @return int Number of optimized sizes.
176 */
177 public function get_optimized_sizes_count() {
178 return 0;
179 }
180
181 /**
182 * Get the original media's size (weight).
183 *
184 * @since 1.9
185 * @access public
186 * @author Grégory Viguier
187 *
188 * @param bool $human_format True to display the image human format size (1Mb).
189 * @param int $decimals Precision of number of decimal places.
190 * @return string|int
191 */
192 public function get_original_size( $human_format = true, $decimals = 2 ) {
193 return $human_format ? imagify_size_format( 0, $decimals ) : 0;
194 }
195
196 /**
197 * Get the file size of the full size file.
198 * If the webp size is available, it is used.
199 *
200 * @since 1.9
201 * @access public
202 * @author Grégory Viguier
203 *
204 * @param bool $human_format True to display the image human format size (1Mb).
205 * @param int $decimals Precision of number of decimal places.
206 * @param bool $use_webp Use the webp size if available.
207 * @return string|int
208 */
209 public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) {
210 return $human_format ? imagify_size_format( 0, $decimals ) : 0;
211 }
212
213
214 /** ----------------------------------------------------------------------------------------- */
215 /** OPTIMIZATION STATS ====================================================================== */
216 /** ----------------------------------------------------------------------------------------- */
217
218 /**
219 * Get one or all statistics of a specific size.
220 *
221 * @since 1.9
222 * @access public
223 * @author Grégory Viguier
224 *
225 * @param string $size The thumbnail slug.
226 * @param string $key The specific data slug.
227 * @return array|string
228 */
229 public function get_size_data( $size = 'full', $key = '' ) {
230 return $key ? '' : [];
231 }
232
233 /**
234 * Get the overall statistics data or a specific one.
235 *
236 * @since 1.9
237 * @access public
238 * @author Grégory Viguier
239 *
240 * @param string $key The specific data slug.
241 * @return array|string
242 */
243 public function get_stats_data( $key = '' ) {
244 return $key ? '' : [];
245 }
246
247 /**
248 * Get the optimized/original saving of the original image in percent.
249 *
250 * @since 1.9
251 * @access public
252 * @author Grégory Viguier
253 *
254 * @return float A 2-decimals float.
255 */
256 public function get_saving_percent() {
257 return round( (float) 0, 2 );
258 }
259
260 /**
261 * Get the overall optimized/original saving (original image + all thumbnails) in percent.
262 *
263 * @since 1.9
264 * @access public
265 * @author Grégory Viguier
266 *
267 * @return float A 2-decimals float.
268 */
269 public function get_overall_saving_percent() {
270 return round( (float) 0, 2 );
271 }
272 }
273