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

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