PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.8
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.8
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 1.9.8, at classes/Optimization/Process/Noop.php

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