PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.10
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.10
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 / inc / 3rd-party / nextgen-gallery / classes / Optimization / Process / NGG.php

NGG.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.10, at inc/3rd-party/nextgen-gallery/classes/Optimization/Process/NGG.php

89 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\ThirdParty\NGG\Optimization\Process;
3
4 use Imagify\Optimization\File;
5
6 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
7
8 /**
9 * Optimization class for NextGen Gallery.
10 * This class constructor accepts:
11 * - A NGG image ID (int).
12 * - A \nggImage object.
13 * - A \nggdb object.
14 * - An anonym object containing a pid property (and everything else).
15 * - A \Imagify\Media\MediaInterface object.
16 *
17 * @since 1.9
18 * @see Imagify\ThirdParty\NGG\Media\NGG
19 * @author Grégory Viguier
20 */
21 class NGG extends \Imagify\Optimization\Process\AbstractProcess {
22
23 /** ----------------------------------------------------------------------------------------- */
24 /** MISSING THUMBNAILS ====================================================================== */
25 /** ----------------------------------------------------------------------------------------- */
26
27 /**
28 * Get the sizes for this media that have not get through optimization.
29 * Since this context doesn't handle this feature, this will always return an empty array, unless an error is triggered.
30 *
31 * @since 1.9
32 * @access public
33 * @author Grégory Viguier
34 *
35 * @return array|WP_Error A WP_Error object on failure. An empty array on success: this context has no thumbnails.
36 * The tests are kept for consistency.
37 */
38 public function get_missing_sizes() {
39 // The media must have been optimized once and have a backup.
40 if ( ! $this->is_valid() ) {
41 return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
42 }
43
44 $media = $this->get_media();
45
46 if ( ! $media->is_supported() ) {
47 return new \WP_Error( 'media_not_supported', __( 'This media is not supported.', 'imagify' ) );
48 }
49
50 $data = $this->get_data();
51
52 if ( ! $data->is_optimized() ) {
53 return new \WP_Error( 'media_not_optimized', __( 'This media is not optimized yet.', 'imagify' ) );
54 }
55
56 if ( ! $media->has_backup() ) {
57 return new \WP_Error( 'no_backup', __( 'This file has no backup file.', 'imagify' ) );
58 }
59
60 if ( ! $media->is_image() ) {
61 return new \WP_Error( 'media_not_an_image', __( 'This media is not an image.', 'imagify' ) );
62 }
63
64 return [];
65 }
66
67 /**
68 * Optimize missing thumbnail sizes.
69 * Since this context doesn't handle this feature, this will always return a \WP_Error object.
70 *
71 * @since 1.9
72 * @access public
73 * @author Grégory Viguier
74 *
75 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
76 */
77 public function optimize_missing_thumbnails() {
78 if ( ! $this->is_valid() ) {
79 return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
80 }
81
82 if ( ! $this->get_media()->is_supported() ) {
83 return new \WP_Error( 'media_not_supported', __( 'This media is not supported.', 'imagify' ) );
84 }
85
86 return new \WP_Error( 'no_sizes', __( 'No thumbnails seem to be missing.', 'imagify' ) );
87 }
88 }
89