PluginProbe
Meow Gallery / 4.2.2
Meow Gallery v4.2.2
5.5.5 5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 All 157 releases
← All changes | classes/core.php +7 -126 4.2.9 → 4.2.2 View file →
@@ -3,10 +3,8 @@
3 3 class Meow_MGL_Core {
4 4
5 5 private $gallery_process = false;
6 6 private $is_gallery_used = true; // TODO: Would be nice to detect if the gallery is actually used on the current page.
7 - private static $plugin_option_name = 'mgl_options';
8 - private $option_name = 'mgl_options';
9 7
10 8 public function __construct() {
11 9 load_plugin_textdomain( MGL_DOMAIN, false, MGL_PATH . '/languages' );
12 10
@@ -11,9 +9,9 @@
11 9 load_plugin_textdomain( MGL_DOMAIN, false, MGL_PATH . '/languages' );
12 10
13 11 // Initializes the classes needed
14 12 MeowCommon_Helpers::is_rest() && new Meow_MGL_Rest( $this );
15 - is_admin() && new Meow_MGL_Admin( $this );
13 + is_admin() && new Meow_MGL_Admin();
16 14 class_exists( 'MeowPro_MGL_Core' ) && new MeowPro_MGL_Core();
17 15
18 16 // The gallery build process should only be enabled if the request is non-asynchronous
19 17 if ( !MeowCommon_Helpers::is_asynchronous_request() ) {
@@ -59,31 +57,21 @@
59 57 $atts = apply_filters( 'shortcode_atts_gallery', $atts, null, $atts );
60 58
61 59 // Get the IDs
62 60 $images = array();
63 - if ( isset( $atts['ids'] ) ) {
61 + if ( isset( $atts['ids'] ) )
64 62 $images = $atts['ids'];
65 - }
66 63 if ( isset( $atts['include'] ) ) {
67 64 $images = is_array( $atts['include'] ) ? implode( ',', $atts['include'] ) : $atts['include'];
68 65 $atts['include'] = $images;
69 66 }
70 -
71 - // Filter the IDs
72 - $ids = is_array( $images ) ? $images : explode( ',', $images );
73 - $ids = apply_filters( 'mgl_ids', $ids, $atts );
74 - $images = implode( ',', $ids );
75 -
76 - // Use attached images if still empty
77 67 if ( empty( $images ) ) {
78 68 $attachments = get_attached_media( 'image' );
79 69 $attachmentIds = array_map( function($x) { return $x->ID; }, $attachments );
80 - if ( !empty( $attachmentIds ) ) {
70 + if ( !empty( $attachmentIds ) )
81 71 $images = implode( ',', $attachmentIds );
82 - }
83 - else {
72 + else
84 73 return "<p class='meow-error'><b>Meow Gallery:</b> The gallery is empty.</p>";
85 - }
86 74 }
87 75
88 76 if ( $isPreview ) {
89 77 $check = explode( ',', $images );
@@ -104,9 +92,9 @@
104 92 $layout = $atts['layout'];
105 93 else if ( isset( $atts['mgl-layout'] ) && $atts['mgl-layout'] != 'default' )
106 94 $layout = $atts['mgl-layout'];
107 95 else
108 - $layout = $this->get_option( 'layout', 'tiles' );
96 + $layout = get_option( 'mgl_layout', 'tiles' );
109 97
110 98 // Check the settings
111 99 if ( $layout === 'none' )
112 100 return gallery_shortcode( $atts );
@@ -127,13 +115,10 @@
127 115
128 116 // Start the process of building the gallery
129 117 $this->gallery_process = true;
130 118 $this->gallery_layout = $layout;
131 -
132 - // This should be probably removed.
133 - // wp_enqueue_style( 'mgl-css' );
134 -
135 - $infinite = $this->get_option( 'infinite', false ) && class_exists( 'MeowPro_MGL_Core' );
119 + wp_enqueue_style( 'mgl-css' );
120 + $infinite = get_option( 'mgl_infinite', false ) && class_exists( 'MeowPro_MGL_Core' );
136 121 $gen = new $layoutClass( $atts, !$isPreview && $infinite, $isPreview );
137 122 $result = $gen->build( $images );
138 123 $this->gallery_process = false;
139 124 do_action( 'mgl_' . $layout . '_gallery_created', $layout );
@@ -138,113 +123,9 @@
138 123 $this->gallery_process = false;
139 124 do_action( 'mgl_' . $layout . '_gallery_created', $layout );
140 125 //$result = apply_filters( 'post_gallery', $result, $atts, null );
141 126
142 - do_action( 'mgl_gallery_created' );
143 -
144 127 return $result;
145 128 }
146 -
147 - // #region Options
148 -
149 - static function get_plugin_option_name() {
150 - return self::$plugin_option_name;
151 - }
152 -
153 - static function get_plugin_option( $option_name, $default = null ) {
154 - $options = get_option( self::$plugin_option_name, null );
155 - return $options[ $option_name ] ?? $default;
156 - }
157 -
158 - function get_option( $option_name, $default = null ) {
159 - $options = $this->get_all_options();
160 - return $options[ $option_name ] ?? $default;
161 - }
162 -
163 - function list_options() {
164 - return array(
165 - 'layout' => 'tiles',
166 - 'captions' => 'none',
167 - 'animation' => false,
168 - 'image_size' => 'srcset',
169 - 'infinite' => false,
170 - 'infinite_buffer' => 0,
171 - 'tiles_gutter' => 5,
172 - 'tiles_gutter_tablet' => 5,
173 - 'tiles_gutter_mobile' => 5,
174 - 'tiles_density' => 'high',
175 - 'tiles_density_tablet' => 'medium',
176 - 'tiles_density_mobile' => 'low',
177 - 'masonry_gutter' => 5,
178 - 'masonry_columns' => 3,
179 - 'justified_gutter' => 5,
180 - 'justified_row_height' => 200,
181 - 'square_gutter' => 5,
182 - 'square_columns' => 5,
183 - 'cascade_gutter' => 5,
184 - 'horizontal_gutter' => 5,
185 - 'horizontal_image_height' => 500,
186 - 'horizontal_hide_scrollbar' => false,
187 - 'carousel_gutter' => 5,
188 - 'carousel_image_height' => 500,
189 - 'carousel_arrow_nav_enabled' => true,
190 - 'carousel_dot_nav_enabled' => true,
191 - 'map_engine' => '',
192 - 'map_height' => 400,
193 - 'googlemaps_token' => '',
194 - 'googlemaps_style' => '[]',
195 - 'mapbox_token' => '',
196 - 'mapbox_style' => '{"username":"", "style_id":""}',
197 - 'maptiler_token' => '',
198 - 'right_click' => false
199 - );
200 - }
201 -
202 - function get_all_options() {
203 - $options = get_option( $this->option_name, null );
204 - $options = $this->check_options( $options );
205 - return $options;
206 - }
207 -
208 - // Upgrade from the old way of storing options to the new way.
209 - function check_options( $options = [] ) {
210 - $plugin_options = $this->list_options();
211 - $options = empty( $options ) ? [] : $options;
212 - $hasChanges = false;
213 - foreach ( $plugin_options as $option => $default ) {
214 - // The option already exists
215 - if ( isset( $options[$option] ) ) {
216 - continue;
217 - }
218 - // The option does not exist, so we need to add it.
219 - // Let's use the old value if any, or the default value.
220 - $options[$option] = get_option( 'mgl_' . $option, $default );
221 - delete_option( 'mgl_' . $option );
222 - $hasChanges = true;
223 - }
224 - if ( $hasChanges ) {
225 - update_option( $this->option_name , $options );
226 - }
227 - return $options;
228 - }
229 -
230 - function update_options( $options ) {
231 - if ( !update_option( $this->option_name, $options, false ) ) {
232 - return false;
233 - }
234 - $options = $this->sanitize_options();
235 - return $options;
236 - }
237 -
238 -
239 - // Validate and keep the options clean and logical.
240 - function sanitize_options() {
241 - $options = $this->get_all_options();
242 - // something to do
243 - return $options;
244 - }
245 -
246 - # endregion
247 -
248 129 }
249 130
250 131 ?>