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 / Main.php

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

134 lines 3.0 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 use Imagify\Traits\InstanceGetterTrait;
5
6 /**
7 * Imagify NextGen Gallery class.
8 *
9 * @since 1.5
10 * @author Jonathan Buttigieg
11 */
12 class Main {
13 use InstanceGetterTrait;
14
15 /**
16 * Class version.
17 *
18 * @var string
19 */
20 const VERSION = '1.1';
21
22 /**
23 * Launch the hooks.
24 *
25 * @since 1.6.5
26 * @access public
27 * @author Grégory Viguier
28 */
29 public function init() {
30 static $done = false;
31
32 if ( $done ) {
33 return;
34 }
35 $done = true;
36
37 add_filter( 'imagify_register_context', [ $this, 'register_context' ] );
38 add_filter( 'imagify_context_class_name', [ $this, 'add_context_class_name' ], 10, 2 );
39 add_filter( 'imagify_process_class_name', [ $this, 'add_process_class_name' ], 10, 2 );
40 add_filter( 'imagify_bulk_class_name', [ $this, 'add_bulk_class_name' ], 10, 2 );
41 add_action( 'init', [ $this, 'add_mixin' ] );
42 }
43
44 /**
45 * Register the context used for NGG.
46 *
47 * @since 1.9
48 * @access public
49 * @author Grégory Viguier
50 *
51 * @param array $contexts An array of context names.
52 * @return array
53 */
54 public function register_context( $contexts ) {
55 $contexts[] = 'ngg';
56 return $contexts;
57 }
58
59 /**
60 * Filter the name of the class to use to define a context.
61 *
62 * @since 1.9
63 * @access public
64 * @author Grégory Viguier
65 *
66 * @param int $class_name The class name.
67 * @param string $context The context name.
68 * @return string
69 */
70 public function add_context_class_name( $class_name, $context ) {
71 if ( 'ngg' === $context ) {
72 return '\\Imagify\\ThirdParty\\NGG\\Context\\NGG';
73 }
74
75 return $class_name;
76 }
77
78 /**
79 * Filter the name of the class to use for the optimization.
80 *
81 * @since 1.9
82 * @access public
83 * @author Grégory Viguier
84 *
85 * @param int $class_name The class name.
86 * @param string $context The context name.
87 * @return string
88 */
89 public function add_process_class_name( $class_name, $context ) {
90 if ( 'ngg' === $context ) {
91 return '\\Imagify\\ThirdParty\\NGG\\Optimization\\Process\\NGG';
92 }
93
94 return $class_name;
95 }
96
97 /**
98 * Filter the name of the class to use for the bulk optimization.
99 *
100 * @since 1.9
101 * @access public
102 * @author Grégory Viguier
103 *
104 * @param int $class_name The class name.
105 * @param string $context The context name.
106 * @return string
107 */
108 public function add_bulk_class_name( $class_name, $context ) {
109 if ( 'ngg' === $context ) {
110 return '\\Imagify\\ThirdParty\\NGG\\Bulk\\NGG';
111 }
112
113 return $class_name;
114 }
115
116 /**
117 * Add custom NGG mixin to override its functions.
118 * No-op on NGG v4.x where the POPE framework (Mixin / C_Gallery_Storage) is absent.
119 *
120 * @since 1.5
121 * @access public
122 * @author Jonathan Buttigieg
123 */
124 public function add_mixin() {
125 // @codeCoverageIgnoreStart — requires live NGG v3 POPE classes, not available in unit tests.
126 if ( ! imagify_ngg_has_pope_storage() ) {
127 return;
128 }
129
130 \C_Gallery_Storage::get_instance()->get_wrapped_instance()->add_mixin( '\\Imagify\\ThirdParty\\NGG\\NGGStorage' );
131 // @codeCoverageIgnoreEnd
132 }
133 }
134