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
imagify / classes / Optimization / Process / Noop.php

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

403 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Imagify\Optimization\Process;
5
6 use Imagify\Optimization\Data\DataInterface;
7 use Imagify\Media\MediaInterface;
8 use Imagify\Optimization\File;
9 use WP_Error;
10
11 /**
12 * Fallback class to optimize medias.
13 */
14 class Noop implements ProcessInterface {
15 /**
16 * The suffix used in the thumbnail size name.
17 *
18 * @var string
19 * @since 1.9
20 */
21 const WEBP_SUFFIX = '@imagify-webp';
22
23 /**
24 * The suffix used in the thumbnail size name.
25 *
26 * @var string
27 * @since 2.2
28 */
29 const AVIF_SUFFIX = '@imagify-avif';
30
31 /**
32 * The suffix used in file name to create a temporary copy of the full size.
33 *
34 * @var string
35 * @since 1.9
36 */
37 const TMP_SUFFIX = '@imagify-tmp';
38
39 /**
40 * Used for the name of the transient telling if a media is locked.
41 * %1$s is the context, %2$s is the media ID.
42 *
43 * @var string
44 * @since 1.9
45 */
46 const LOCK_NAME = 'imagify_%1$s_%2$s_process_locked';
47
48 /**
49 * Tell if the given entry can be accepted in the constructor.
50 * For example it can include `is_numeric( $id )` if the constructor accepts integers.
51 *
52 * @since 1.9
53 *
54 * @param mixed $id Whatever.
55 *
56 * @return bool
57 */
58 public static function constructor_accepts( $id ) {
59 return false;
60 }
61
62 /**
63 * Get the data instance.
64 *
65 * @since 1.9
66 *
67 * @return DataInterface|false
68 */
69 public function get_data() {
70 return false;
71 }
72
73 /**
74 * Get the media instance.
75 *
76 * @since 1.9
77 *
78 * @return MediaInterface|false
79 */
80 public function get_media() {
81 return false;
82 }
83
84 /**
85 * Get the File instance of the original file.
86 *
87 * @since 1.9.8
88 *
89 * @return File|false
90 */
91 public function get_original_file() {
92 return false;
93 }
94
95 /**
96 * Get the File instance of the full size file.
97 *
98 * @since 1.9.8
99 *
100 * @return File|false
101 */
102 public function get_fullsize_file() {
103 return false;
104 }
105
106 /**
107 * Get the File instance.
108 *
109 * @since 1.9
110 *
111 * @return File|false
112 */
113 public function get_file() {
114 return false;
115 }
116
117 /**
118 * Tell if the current media is valid.
119 *
120 * @since 1.9
121 *
122 * @return bool
123 */
124 public function is_valid() {
125 return false;
126 }
127
128 /**
129 * Tell if the current user is allowed to operate Imagify in this context.
130 *
131 * @since 1.9
132 *
133 * @param string $describer Capacity describer. See \Imagify\Context\ContextInterface->get_capacity() for possible values. Can also be a "real" user capacity.
134 *
135 * @return bool
136 */
137 public function current_user_can( $describer ) {
138 return false;
139 }
140
141 /**
142 * Optimize a media files by pushing tasks into the queue.
143 *
144 * @since 1.9
145 * @since 2.3.2 Added the $args parameter.
146 *
147 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
148 * @param array $args An array of optionnal arguments.
149 *
150 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
151 */
152 public function optimize( $optimization_level = null, $args = [] ) {
153 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
154 }
155
156 /**
157 * Re-optimize a media files with a different level.
158 *
159 * @since 1.9
160 * @since 2.3.2 Added the $args parameter.
161 *
162 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
163 * @param array $args An array of optionnal arguments.
164 *
165 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
166 */
167 public function reoptimize( $optimization_level = null, $args = [] ) {
168 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
169 }
170
171 /**
172 * Optimize several file sizes by pushing tasks into the queue.
173 *
174 * @since 1.9
175 * @since 2.3.2 Added the $args parameter.
176 *
177 * @param array $sizes An array of media sizes (strings). Use "full" for the size of the main file.
178 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
179 * @param array $args An array of optionnal arguments.
180 *
181 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
182 */
183 public function optimize_sizes( $sizes, $optimization_level = null, $args = [] ) {
184 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
185 }
186
187 /**
188 * Optimize one file with Imagify directly.
189 *
190 * @since 1.9
191 *
192 * @param string $size The media size.
193 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
194 *
195 * @return array|WP_Error The optimization data. A WP_Error instance on failure.
196 */
197 public function optimize_size( $size, $optimization_level = null ) {
198 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
199 }
200
201 /**
202 * Restore the media files from the backup file.
203 *
204 * @since 1.9
205 *
206 * @return bool|WP_Error True on success. A WP_Error instance on failure.
207 */
208 public function restore() {
209 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
210 }
211
212 /**
213 * Get the sizes for this media that have not get through optimization.
214 * No sizes are returned if the file is not optimized, has no backup, or is not an image.
215 * The 'full' size os never returned.
216 *
217 * @since 1.9
218 *
219 * @return array|WP_Error {
220 * A WP_Error object on failure.
221 * An array of data for the thumbnail sizes on success.
222 * Size names are used as array keys.
223 *
224 * @type int $width The image width.
225 * @type int $height The image height.
226 * @type bool $crop True to crop, false to resize.
227 * @type string $name The size name.
228 * @type string $file The name the thumbnail "should" have.
229 * }
230 */
231 public function get_missing_sizes() {
232 return [];
233 }
234
235 /**
236 * Optimize missing thumbnail sizes.
237 *
238 * @since 1.9
239 *
240 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
241 */
242 public function optimize_missing_thumbnails() {
243 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
244 }
245
246 /**
247 * Delete the backup file.
248 *
249 * @since 1.9
250 */
251 public function delete_backup() {}
252
253 /**
254 * Maybe resize an image.
255 *
256 * @since 1.9
257 *
258 * @param string $size The size name.
259 * @param File $file A File instance.
260 *
261 * @return array|WP_Error A WP_Error instance on failure, an array on success as follow: {
262 * @type bool $resized True when the image has been resized.
263 * @type bool $backuped True when the image has been backuped.
264 * @type int $file_size The file size in bytes.
265 * }
266 */
267 public function maybe_resize( $size, $file ) {
268 return [
269 'resized' => false,
270 'backuped' => false,
271 'file_size' => 0,
272 ];
273 }
274
275 /**
276 * Generate Nextgen images if they are missing.
277 *
278 * @since 1.9
279 *
280 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
281 */
282 public function generate_nextgen_versions() {
283 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
284 }
285
286 /**
287 * Delete the next gen format images.
288 * This doesn't delete the related optimization data.
289 *
290 * @since 2.2
291 *
292 * @param bool $keep_full Set to true to keep the full size.
293 * @return bool|WP_Error True on success. A WP_Error object on failure.
294 */
295 public function delete_nextgen_files( $keep_full = false ) {
296 return false;
297 }
298
299 /**
300 * Tell if a thumbnail size is an "Imagify Next-Gen" size.
301 *
302 * @since 2.2
303 *
304 * @param string $size_name The size name.
305 *
306 * @return string|bool The unsuffixed name of the size if Next-Gen. False if not a Next-Gen.
307 */
308 public function is_size_next_gen( $size_name ) {
309 return false;
310 }
311
312 /**
313 * Tell if the media has all next-gen versions.
314 *
315 * @return bool
316 */
317 public function is_full_next_gen() {
318 return false;
319 }
320
321 /**
322 * Tell if the media has a next-gen format.
323 *
324 * @since 2.2
325 *
326 * @return bool
327 */
328 public function has_next_gen() {
329 return false;
330 }
331
332 /**
333 * Tell if a process is running for this media.
334 *
335 * @since 1.9
336 *
337 * @return bool
338 */
339 public function is_locked() {
340 return false;
341 }
342
343 /**
344 * Set the running status to "running" for a period of time.
345 *
346 * @since 1.9
347 */
348 public function lock() {}
349
350 /**
351 * Delete the running status.
352 *
353 * @since 1.9
354 */
355 public function unlock() {}
356
357 /**
358 * Tell if a size already has optimization data.
359 *
360 * @since 1.9
361 *
362 * @param string $size The size name.
363 *
364 * @return bool
365 */
366 public function size_has_optimization_data( $size ) {
367 return false;
368 }
369
370 /**
371 * Update the optimization data for a size.
372 *
373 * @since 1.9
374 *
375 * @param object $response The API response.
376 * @param string $size The size name.
377 * @param int $level The optimization level (0=normal, 1=aggressive, 2=ultra).
378 *
379 * @return array {
380 * The optimization data.
381 *
382 * @type string $size The size name.
383 * @type int $level The optimization level.
384 * @type string $status The status: 'success', 'already_optimized', 'error'.
385 * @type bool $success True if successfully optimized. False on error or if already optimized.
386 * @type string $error An error message.
387 * @type int $original_size The weight of the file, before optimization.
388 * @type int $optimized_size The weight of the file, once optimized.
389 * }
390 */
391 public function update_size_optimization_data( $response, $size, $level ) {
392 return [
393 'size' => 'noop',
394 'level' => false,
395 'status' => '',
396 'success' => false,
397 'error' => '',
398 'original_size' => 0,
399 'optimized_size' => 0,
400 ];
401 }
402 }
403