PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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 / NGGStorage.php

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

107 lines 3.1 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;
3
4 defined( 'ABSPATH' ) || die( "Cheatin' uh?" );
5
6 /**
7 * Imagify NextGen Gallery storage class.
8 *
9 * @since 1.5
10 * @author Jonathan Buttigieg
11 */
12 class NGGStorage extends \Mixin {
13
14 /**
15 * Class version.
16 *
17 * @var string
18 */
19 const VERSION = '1.1';
20
21 /**
22 * Delete a gallery AND all the pictures associated to this gallery!
23 *
24 * @since 1.5
25 * @author Jonathan Buttigieg
26 *
27 * @param int|object $gallery A gallery ID or object.
28 * @return bool Whetther tha gallery was been deleted or not.
29 */
30 public function delete_gallery( $gallery ) {
31 $gallery_id = is_numeric( $gallery ) ? $gallery : $gallery->{$gallery->id_field};
32 $images_id = \nggdb::get_ids_from_gallery( $gallery_id );
33
34 foreach ( $images_id as $pid ) {
35 $process = imagify_get_optimization_process( $pid, 'ngg' );
36
37 if ( $process->is_valid() && $process->get_data()->is_optimized() ) {
38 $process->get_data()->delete_optimization_data();
39 }
40 }
41
42 return $this->call_parent( 'delete_gallery', $gallery );
43 }
44
45 /**
46 * Generates a specific size for an image.
47 *
48 * @since 1.5
49 * @author Jonathan Buttigieg
50 *
51 * @param int|object $image An image ID or NGG object.
52 * @param string $size An image size.
53 * @param array $params An array of parameters.
54 * @param bool $skip_defaults Whatever NGG does with default settings.
55 * @return bool|object An object on success. False on failure.
56 */
57 public function generate_image_size( $image, $size, $params = null, $skip_defaults = false ) {
58 // $image could be an object or an (int) image ID.
59 if ( is_numeric( $image ) ) {
60 $image = $this->object->_image_mapper->find( $image );
61 }
62
63 // If a user adds a watermark, rotates or resizes an image, we restore it.
64 // TO DO - waiting for a hook to be able to re-optimize the original size after restoring.
65 if ( isset( $image->pid ) && ( true === $params['watermark'] || ( isset( $params['rotation'] ) || isset( $params['flip'] ) ) || ( ! empty( $params['width'] ) || ! empty( $params['height'] ) ) ) ) {
66 $process = imagify_get_optimization_process( $image->pid, 'ngg' );
67
68 if ( $process->is_valid() && $process->get_data()->is_optimized() ) {
69 $process->get_data()->delete_optimization_data();
70 }
71 }
72
73 return $this->call_parent( 'generate_image_size', $image, $size, $params, $skip_defaults );
74 }
75
76 /**
77 * Recover image from backup.
78 *
79 * @since 1.5
80 * @author Jonathan Buttigieg
81 *
82 * @param int|object $image An image ID or NGG object.
83 * @return string|bool Result code on success. False on failure.
84 */
85 public function recover_image( $image ) {
86 // $image could be an object or an (int) image ID.
87 if ( is_numeric( $image ) ) {
88 $image = $this->object->_image_mapper->find( $image );
89 }
90
91 if ( ! $image ) {
92 return false;
93 }
94
95 // Remove Imagify data.
96 if ( isset( $image->pid ) ) {
97 $process = imagify_get_optimization_process( $image->pid, 'ngg' );
98
99 if ( $process->is_valid() && $process->get_data()->is_optimized() ) {
100 $process->get_data()->delete_optimization_data();
101 }
102 }
103
104 return $this->call_parent( 'recover_image', $image );
105 }
106 }
107