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

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