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

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

397 lines 9.1 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 *
146 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
147 *
148 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
149 */
150 public function optimize( $optimization_level = null ) {
151 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
152 }
153
154 /**
155 * Re-optimize a media files with a different level.
156 *
157 * @since 1.9
158 *
159 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
160 *
161 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
162 */
163 public function reoptimize( $optimization_level = null ) {
164 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
165 }
166
167 /**
168 * Optimize several file sizes by pushing tasks into the queue.
169 *
170 * @since 1.9
171 *
172 * @param array $sizes An array of media sizes (strings). Use "full" for the size of the main file.
173 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
174 *
175 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
176 */
177 public function optimize_sizes( $sizes, $optimization_level = null ) {
178 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
179 }
180
181 /**
182 * Optimize one file with Imagify directly.
183 *
184 * @since 1.9
185 *
186 * @param string $size The media size.
187 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
188 *
189 * @return array|WP_Error The optimization data. A WP_Error instance on failure.
190 */
191 public function optimize_size( $size, $optimization_level = null ) {
192 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
193 }
194
195 /**
196 * Restore the media files from the backup file.
197 *
198 * @since 1.9
199 *
200 * @return bool|WP_Error True on success. A WP_Error instance on failure.
201 */
202 public function restore() {
203 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
204 }
205
206 /**
207 * Get the sizes for this media that have not get through optimization.
208 * No sizes are returned if the file is not optimized, has no backup, or is not an image.
209 * The 'full' size os never returned.
210 *
211 * @since 1.9
212 *
213 * @return array|WP_Error {
214 * A WP_Error object on failure.
215 * An array of data for the thumbnail sizes on success.
216 * Size names are used as array keys.
217 *
218 * @type int $width The image width.
219 * @type int $height The image height.
220 * @type bool $crop True to crop, false to resize.
221 * @type string $name The size name.
222 * @type string $file The name the thumbnail "should" have.
223 * }
224 */
225 public function get_missing_sizes() {
226 return [];
227 }
228
229 /**
230 * Optimize missing thumbnail sizes.
231 *
232 * @since 1.9
233 *
234 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
235 */
236 public function optimize_missing_thumbnails() {
237 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
238 }
239
240 /**
241 * Delete the backup file.
242 *
243 * @since 1.9
244 */
245 public function delete_backup() {}
246
247 /**
248 * Maybe resize an image.
249 *
250 * @since 1.9
251 *
252 * @param string $size The size name.
253 * @param File $file A File instance.
254 *
255 * @return array|WP_Error A WP_Error instance on failure, an array on success as follow: {
256 * @type bool $resized True when the image has been resized.
257 * @type bool $backuped True when the image has been backuped.
258 * @type int $file_size The file size in bytes.
259 * }
260 */
261 public function maybe_resize( $size, $file ) {
262 return [
263 'resized' => false,
264 'backuped' => false,
265 'file_size' => 0,
266 ];
267 }
268
269 /**
270 * Generate Nextgen images if they are missing.
271 *
272 * @since 1.9
273 *
274 * @return bool|WP_Error True if successfully launched. A WP_Error instance on failure.
275 */
276 public function generate_nextgen_versions() {
277 return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
278 }
279
280 /**
281 * Delete the next gen format images.
282 * This doesn't delete the related optimization data.
283 *
284 * @since 2.2
285 *
286 * @param bool $keep_full Set to true to keep the full size.
287 * @return bool|WP_Error True on success. A WP_Error object on failure.
288 */
289 public function delete_nextgen_files( $keep_full = false ) {
290 return false;
291 }
292
293 /**
294 * Tell if a thumbnail size is an "Imagify Next-Gen" size.
295 *
296 * @since 2.2
297 *
298 * @param string $size_name The size name.
299 *
300 * @return string|bool The unsuffixed name of the size if Next-Gen. False if not a Next-Gen.
301 */
302 public function is_size_next_gen( $size_name ) {
303 return false;
304 }
305
306 /**
307 * Tell if the media has all next-gen versions.
308 *
309 * @return bool
310 */
311 public function is_full_next_gen() {
312 return false;
313 }
314
315 /**
316 * Tell if the media has a next-gen format.
317 *
318 * @since 2.2
319 *
320 * @return bool
321 */
322 public function has_next_gen() {
323 return false;
324 }
325
326 /**
327 * Tell if a process is running for this media.
328 *
329 * @since 1.9
330 *
331 * @return bool
332 */
333 public function is_locked() {
334 return false;
335 }
336
337 /**
338 * Set the running status to "running" for a period of time.
339 *
340 * @since 1.9
341 */
342 public function lock() {}
343
344 /**
345 * Delete the running status.
346 *
347 * @since 1.9
348 */
349 public function unlock() {}
350
351 /**
352 * Tell if a size already has optimization data.
353 *
354 * @since 1.9
355 *
356 * @param string $size The size name.
357 *
358 * @return bool
359 */
360 public function size_has_optimization_data( $size ) {
361 return false;
362 }
363
364 /**
365 * Update the optimization data for a size.
366 *
367 * @since 1.9
368 *
369 * @param object $response The API response.
370 * @param string $size The size name.
371 * @param int $level The optimization level (0=normal, 1=aggressive, 2=ultra).
372 *
373 * @return array {
374 * The optimization data.
375 *
376 * @type string $size The size name.
377 * @type int $level The optimization level.
378 * @type string $status The status: 'success', 'already_optimized', 'error'.
379 * @type bool $success True if successfully optimized. False on error or if already optimized.
380 * @type string $error An error message.
381 * @type int $original_size The weight of the file, before optimization.
382 * @type int $optimized_size The weight of the file, once optimized.
383 * }
384 */
385 public function update_size_optimization_data( $response, $size, $level ) {
386 return [
387 'size' => 'noop',
388 'level' => false,
389 'status' => '',
390 'success' => false,
391 'error' => '',
392 'original_size' => 0,
393 'optimized_size' => 0,
394 ];
395 }
396 }
397