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

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

394 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\Media;
3
4 use Imagify\CDN\PushCDNInterface;
5 use Imagify\Context\ContextInterface;
6 use Imagify\Deprecated\Traits\Media\NoopDeprecatedTrait;
7 use WP_Error;
8
9 /**
10 * Fallback class for "media groups" (aka attachments).
11 *
12 * @since 1.9
13 * @author Grégory Viguier
14 */
15 class Noop implements MediaInterface {
16 use NoopDeprecatedTrait;
17
18 /**
19 * Tell if the given entry can be accepted in the constructor.
20 * For example it can include `is_numeric( $id )` if the constructor accepts integers.
21 *
22 * @since 1.9
23 * @access public
24 * @author Grégory Viguier
25 *
26 * @param mixed $id Whatever.
27 * @return bool
28 */
29 public static function constructor_accepts( $id ) {
30 return false;
31 }
32
33 /**
34 * Get the media ID.
35 *
36 * @since 1.9
37 * @access public
38 * @author Grégory Viguier
39 *
40 * @return int
41 */
42 public function get_id() {
43 return 0;
44 }
45
46 /**
47 * Tell if the current media is valid.
48 *
49 * @since 1.9
50 * @access public
51 * @author Grégory Viguier
52 *
53 * @return bool
54 */
55 public function is_valid() {
56 return false;
57 }
58
59 /**
60 * Get the media context name.
61 *
62 * @since 1.9
63 * @access public
64 * @author Grégory Viguier
65 *
66 * @return string
67 */
68 public function get_context() {
69 return 'noop';
70 }
71
72 /**
73 * Get the media context instance.
74 *
75 * @since 1.9
76 * @access public
77 * @author Grégory Viguier
78 *
79 * @return ContextInterface
80 */
81 public function get_context_instance() {
82 return \Imagify\Context\Noop::get_instance();
83 }
84
85 /**
86 * Get the CDN instance.
87 *
88 * @since 1.9
89 * @access public
90 * @author Grégory Viguier
91 *
92 * @return bool|PushCDNInterface A PushCDNInterface instance. False if no CDN is used.
93 */
94 public function get_cdn() {
95 return false;
96 }
97
98
99 /** ----------------------------------------------------------------------------------------- */
100 /** ORIGINAL FILE =========================================================================== */
101 /** ----------------------------------------------------------------------------------------- */
102
103 /**
104 * Get the original file path, even if the file doesn't exist.
105 *
106 * @since 1.9
107 * @access public
108 * @author Grégory Viguier
109 *
110 * @return string|bool The file path. False on failure.
111 */
112 public function get_raw_original_path() {
113 return false;
114 }
115
116 /**
117 * Get the original media's path if the file exists.
118 *
119 * @since 1.9
120 * @access public
121 * @author Grégory Viguier
122 *
123 * @return string|bool The file path. False if it doesn't exist.
124 */
125 public function get_original_path() {
126 return false;
127 }
128
129
130 /** ----------------------------------------------------------------------------------------- */
131 /** FULL SIZE FILE ========================================================================== */
132 /** ----------------------------------------------------------------------------------------- */
133
134 /**
135 * Get the URL of the media’s full size file.
136 *
137 * @since 1.9.8
138 * @access public
139 * @author Grégory Viguier
140 *
141 * @return string|bool The file URL. False on failure.
142 */
143 public function get_fullsize_url() {
144 return false;
145 }
146
147 /**
148 * Get the path to the media’s full size file, even if the file doesn't exist.
149 *
150 * @since 1.9.8
151 * @access public
152 * @author Grégory Viguier
153 *
154 * @return string|bool The file path. False on failure.
155 */
156 public function get_raw_fullsize_path() {
157 return false;
158 }
159
160 /**
161 * Get the path to the media’s full size file if the file exists.
162 *
163 * @since 1.9.8
164 * @access public
165 * @author Grégory Viguier
166 *
167 * @return string|bool The file path. False if it doesn't exist.
168 */
169 public function get_fullsize_path() {
170 return false;
171 }
172
173
174 /** ----------------------------------------------------------------------------------------- */
175 /** BACKUP FILE ============================================================================= */
176 /** ----------------------------------------------------------------------------------------- */
177
178 /**
179 * Get the backup URL, even if the file doesn't exist.
180 *
181 * @since 1.9
182 * @access public
183 * @author Grégory Viguier
184 *
185 * @return string|bool The file URL. False on failure.
186 */
187 public function get_backup_url() {
188 return false;
189 }
190
191 /**
192 * Get the backup file path, even if the file doesn't exist.
193 *
194 * @since 1.9
195 * @access public
196 * @author Grégory Viguier
197 *
198 * @return string|bool The file path. False on failure.
199 */
200 public function get_raw_backup_path() {
201 return false;
202 }
203
204 /**
205 * Get the backup file path if the file exists.
206 *
207 * @since 1.9
208 * @access public
209 * @author Grégory Viguier
210 *
211 * @return string|bool The file path. False if it doesn't exist.
212 */
213 public function get_backup_path() {
214 return false;
215 }
216
217 /**
218 * Check if the media has a backup of the original file.
219 *
220 * @since 1.9
221 * @access public
222 * @author Grégory Viguier
223 *
224 * @return bool True if the media has a backup.
225 */
226 public function has_backup() {
227 return false;
228 }
229
230
231 /** ----------------------------------------------------------------------------------------- */
232 /** THUMBNAILS ============================================================================== */
233 /** ----------------------------------------------------------------------------------------- */
234
235 /**
236 * Create the media thumbnails.
237 *
238 * @since 1.9
239 * @access public
240 * @author Grégory Viguier
241 *
242 * @return bool|WP_Error True on success. A \WP_Error instance on failure.
243 */
244 public function generate_thumbnails() {
245 return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
246 }
247
248
249 /** ----------------------------------------------------------------------------------------- */
250 /** MEDIA DATA ============================================================================== */
251 /** ----------------------------------------------------------------------------------------- */
252
253 /**
254 * Tell if the current media type is supported.
255 *
256 * @since 1.9
257 * @access public
258 * @author Grégory Viguier
259 *
260 * @return bool
261 */
262 public function is_supported() {
263 return false;
264 }
265
266 /**
267 * Tell if the current media refers to an image, based on file extension.
268 *
269 * @since 1.9
270 * @access public
271 * @author Grégory Viguier
272 *
273 * @return bool Returns false in case it's an image but not in a supported format (bmp for example).
274 */
275 public function is_image() {
276 return false;
277 }
278
279 /**
280 * Tell if the current media refers to a pdf, based on file extension.
281 *
282 * @since 1.9
283 * @access public
284 * @author Grégory Viguier
285 *
286 * @return bool
287 */
288 public function is_pdf() {
289 return false;
290 }
291
292 /**
293 * Get the original file extension (if supported by Imagify).
294 *
295 * @since 1.9
296 * @access public
297 * @author Grégory Viguier
298 *
299 * @return string|null
300 */
301 public function get_extension() {
302 return '';
303 }
304
305 /**
306 * Get the original file mime type (if supported by Imagify).
307 *
308 * @since 1.9
309 * @access public
310 * @author Grégory Viguier
311 *
312 * @return string
313 */
314 public function get_mime_type() {
315 return '';
316 }
317
318 /**
319 * Get the file mime type + file extension (if the file is supported by Imagify).
320 * This test is ran against the original file.
321 *
322 * @since 1.9
323 * @access public
324 * @author Grégory Viguier
325 *
326 * @return array
327 */
328 public function get_allowed_mime_types() {
329 return imagify_get_mime_types( 'all' );
330 }
331
332 /**
333 * Tell if the current media has the required data (the data containing the file paths and thumbnails).
334 *
335 * @since 1.9
336 * @access public
337 * @author Grégory Viguier
338 *
339 * @return bool
340 */
341 public function has_required_media_data() {
342 return false;
343 }
344
345 /**
346 * Get the list of the files of this media, including the original file.
347 *
348 * @since 1.9
349 * @access public
350 * @author Grégory Viguier
351 *
352 * @return array {
353 * An array with the size names as keys ('full' is used for the original file), and arrays of data as values:
354 *
355 * @type string $path Absolute path to the file.
356 * @type int $width The file width.
357 * @type int $height The file height.
358 * @type string $mime-type The file mime type.
359 * }
360 */
361 public function get_media_files() {
362 return [];
363 }
364
365 /**
366 * If the media is an image, get its width and height.
367 *
368 * @since 1.9
369 * @access public
370 * @author Grégory Viguier
371 *
372 * @return array
373 */
374 public function get_dimensions() {
375 return [
376 'width' => 0,
377 'height' => 0,
378 ];
379 }
380
381 /**
382 * If the media is an image, update the dimensions in the database with the current file dimensions.
383 *
384 * @since 1.9
385 * @access public
386 * @author Grégory Viguier
387 *
388 * @return bool True on success. False on failure.
389 */
390 public function update_dimensions() {
391 return false;
392 }
393 }
394