PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / trunk
Responsive Lightbox & Gallery vtrunk
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / includes / settings / class-settings-galleries.php
responsive-lightbox / includes / settings Last commit date
class-settings-addons.php 4 months ago class-settings-base.php 5 months ago class-settings-builder.php 5 months ago class-settings-capabilities.php 5 months ago class-settings-folders.php 4 months ago class-settings-galleries.php 5 months ago class-settings-general.php 5 months ago class-settings-licenses.php 4 months ago class-settings-lightboxes.php 4 months ago class-settings-remote-library.php 5 months ago
class-settings-galleries.php
449 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Responsive_Lightbox_Settings_Galleries class.
8 *
9 * Settings page class for Galleries tab migration to new Settings API.
10 *
11 * @class Responsive_Lightbox_Settings_Galleries
12 */
13 class Responsive_Lightbox_Settings_Galleries extends Responsive_Lightbox_Settings_Base {
14
15 /**
16 * Tab key identifier.
17 *
18 * @var string
19 */
20 const TAB_KEY = 'gallery';
21
22 /**
23 * Register this tab as migrated to new API.
24 *
25 * Override - registers main gallery tab and all gallery type sub-tabs.
26 *
27 * @param array $tabs Migrated tabs.
28 * @return array
29 */
30 public function register_migrated_tab( $tabs ) {
31 $rl = Responsive_Lightbox();
32
33 // register the main gallery tab for new Settings API wrapper
34 $tabs[] = self::TAB_KEY;
35
36 // get gallery types
37 $gallery_types = apply_filters( 'rl_gallery_types', $rl->get_data( 'gallery_types' ) );
38
39 // remove default gallery
40 unset( $gallery_types['default'] );
41
42 // register gallery types that have complete legacy definitions
43 foreach ( array_keys( $gallery_types ) as $gallery_type ) {
44 $settings_key = $gallery_type . '_gallery';
45 if ( $rl->settings->has_setting_tab( $settings_key ) ) {
46 // get full settings definition to check required metadata
47 $gallery_settings = $rl->settings->get_setting_definition( $settings_key );
48 if ( $gallery_settings && ! empty( $gallery_settings['option_name'] ) && ! empty( $gallery_settings['option_group'] ) ) {
49 $tabs[] = $settings_key;
50 }
51 }
52 }
53
54 return $tabs;
55 }
56
57 /**
58 * Validate settings for gallery tabs.
59 *
60 * Resolves settings key from option_page to apply correct defaults.
61 * Handles core gallery types and add-on gallery types.
62 *
63 * @param array $input Input data from form submission.
64 * @return array Validated data.
65 */
66 public function validate( $input ) {
67 $rl = Responsive_Lightbox();
68
69 // determine which gallery type is being saved from option_page
70 $option_page = isset( $_POST['option_page'] ) ? sanitize_key( $_POST['option_page'] ) : '';
71 $settings_key = '';
72
73 // map option_page to settings key using helper method
74 $settings_key = $rl->settings->get_settings_key_by_option( $option_page );
75
76 // fallback to a valid gallery type settings key (never "gallery")
77 if ( $settings_key === null || $settings_key === '' ) {
78 $gallery_types = apply_filters( 'rl_gallery_types', $rl->get_data( 'gallery_types' ) );
79 if ( ! is_array( $gallery_types ) )
80 $gallery_types = [];
81
82 unset( $gallery_types['default'] );
83 $fallback_type = $rl->options['settings']['builder_gallery'];
84
85 if ( empty( $fallback_type ) || ! array_key_exists( $fallback_type, $gallery_types ) ) {
86 reset( $gallery_types );
87 $fallback_type = key( $gallery_types );
88 }
89
90 if ( empty( $fallback_type ) )
91 $fallback_type = $rl->defaults['settings']['builder_gallery'];
92
93 $settings_key = $fallback_type !== '' ? $fallback_type . '_gallery' : '';
94 }
95
96 // check if this is a reset operation
97 if ( $this->is_reset_request( $option_page ) ) {
98 if ( isset( $rl->defaults[$settings_key] ) )
99 $input = $rl->defaults[$settings_key];
100 else
101 $input = [];
102 add_settings_error( 'reset_rl_gallery', 'settings_restored', esc_html__( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
103 return $input;
104 }
105
106 // sanitize fields using the detected settings key
107 $input = $this->sanitize_fields( $input, $settings_key );
108
109 return $input;
110 }
111
112 /**
113 * Provide settings data for migrated gallery types.
114 *
115 * @param array $data Settings data.
116 * @return array
117 */
118 public function settings_data( $data ) {
119 $rl = Responsive_Lightbox();
120
121 // provide data for the main gallery tab (dynamic routing to gallery types)
122 if ( ! isset( $data[self::TAB_KEY] ) ) {
123 $data[self::TAB_KEY] = [
124 'option_name' => 'responsive_lightbox_gallery', // placeholder, actual option_name determined by section
125 'option_group' => 'responsive_lightbox_gallery_group',
126 'validate' => [ $this, 'validate' ],
127 'sections' => [],
128 'fields' => []
129 ];
130 }
131
132 // define core gallery types settings
133 $data['basicgrid_gallery'] = $this->get_basicgrid_settings();
134 $data['basicslider_gallery'] = $this->get_basicslider_settings();
135 $data['basicmasonry_gallery'] = $this->get_basicmasonry_settings();
136
137 // get gallery types
138 $gallery_types = apply_filters( 'rl_gallery_types', $rl->get_data( 'gallery_types' ) );
139
140 // remove default gallery
141 unset( $gallery_types['default'] );
142
143 // handle add-on gallery types that still use legacy definitions
144 $core_galleries = [ 'basicgrid', 'basicslider', 'basicmasonry' ];
145 foreach ( array_keys( $gallery_types ) as $gallery_type ) {
146 // skip core galleries (already defined above)
147 if ( in_array( $gallery_type, $core_galleries, true ) ) {
148 continue;
149 }
150
151 $settings_key = $gallery_type . '_gallery';
152 if ( $rl->settings->has_setting_tab( $settings_key ) ) {
153 // get full settings definition to extract configuration
154 $gallery_settings = $rl->settings->get_setting_definition( $settings_key );
155 if ( $gallery_settings && ! empty( $gallery_settings['option_name'] ) && ! empty( $gallery_settings['option_group'] ) ) {
156 $data[$settings_key] = [
157 'option_name' => $gallery_settings['option_name'],
158 'option_group' => $gallery_settings['option_group'],
159 'validate' => [ $this, 'validate' ],
160 'sections' => $gallery_settings['sections'],
161 'fields' => $gallery_settings['fields']
162 ];
163 }
164 }
165 }
166
167 return $data;
168 }
169
170 /**
171 * Get Basic Grid gallery settings.
172 *
173 * @return array
174 */
175 private function get_basicgrid_settings() {
176 return [
177 'option_group' => 'responsive_lightbox_basicgrid_gallery',
178 'option_name' => 'responsive_lightbox_basicgrid_gallery',
179 'validate' => [ $this, 'validate' ],
180 'sections' => [
181 'responsive_lightbox_basicgrid_gallery' => [
182 'title' => __( 'Basic Grid Gallery Settings', 'responsive-lightbox' )
183 ]
184 ],
185 'fields' => [
186 'screen_size_columns' => [
187 'title' => __( 'Screen Sizes', 'responsive-lightbox' ),
188 'section' => 'responsive_lightbox_basicgrid_gallery',
189 'type' => 'multiple',
190 'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
191 'fields' => [
192 'columns_lg' => [
193 'type' => 'number',
194 'min' => 0,
195 'max' => 6,
196 'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
197 ],
198 'columns_md' => [
199 'type' => 'number',
200 'min' => 0,
201 'max' => 6,
202 'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
203 ],
204 'columns_sm' => [
205 'type' => 'number',
206 'min' => 0,
207 'max' => 6,
208 'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
209 ],
210 'columns_xs' => [
211 'type' => 'number',
212 'min' => 0,
213 'max' => 6,
214 'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
215 ]
216 ]
217 ],
218 'gutter' => [
219 'title' => __( 'Gutter', 'responsive-lightbox' ),
220 'section' => 'responsive_lightbox_basicgrid_gallery',
221 'type' => 'number',
222 'min' => 0,
223 'description' => __( 'Set the pixel width between the columns and rows.', 'responsive-lightbox' ),
224 'append' => 'px'
225 ],
226 'force_height' => [
227 'title' => __( 'Force Height', 'responsive-lightbox' ),
228 'section' => 'responsive_lightbox_basicgrid_gallery',
229 'type' => 'boolean',
230 'label' => __( 'Enable to force the thumbnail row height.', 'responsive-lightbox' )
231 ],
232 'row_height' => [
233 'title' => __( 'Row Height', 'responsive-lightbox' ),
234 'section' => 'responsive_lightbox_basicgrid_gallery',
235 'type' => 'number',
236 'min' => 50,
237 'description' => __( 'Enter the thumbnail row height in pixels (used if Force height is enabled). Defaults to 150px.', 'responsive-lightbox' ),
238 'append' => 'px'
239 ]
240 ]
241 ];
242 }
243
244 /**
245 * Get Basic Slider gallery settings.
246 *
247 * @return array
248 */
249 private function get_basicslider_settings() {
250 return [
251 'option_group' => 'responsive_lightbox_basicslider_gallery',
252 'option_name' => 'responsive_lightbox_basicslider_gallery',
253 'validate' => [ $this, 'validate' ],
254 'sections' => [
255 'responsive_lightbox_basicslider_gallery' => [
256 'title' => __( 'Basic Slider Gallery Settings', 'responsive-lightbox' )
257 ]
258 ],
259 'fields' => [
260 'slider_type' => [
261 'title' => __( 'Slider Type', 'responsive-lightbox' ),
262 'section' => 'responsive_lightbox_basicslider_gallery',
263 'type' => 'select',
264 'label' => __( 'The type of the slider.', 'responsive-lightbox' ),
265 'options' => [
266 'slide' => __( 'Slide', 'responsive-lightbox' ),
267 'loop' => __( 'Loop', 'responsive-lightbox' ),
268 'fade' => __( 'Fade', 'responsive-lightbox' )
269 ]
270 ],
271 'height' => [
272 'title' => __( 'Height', 'responsive-lightbox' ),
273 'section' => 'responsive_lightbox_basicslider_gallery',
274 'type' => 'number',
275 'min' => 0,
276 'description' => __( 'Defines the carousel max width in percentage. If set to 0 slider will adapt to slides width.', 'responsive-lightbox' ),
277 'append' => 'px'
278 ],
279 'width' => [
280 'title' => __( 'Width', 'responsive-lightbox' ),
281 'section' => 'responsive_lightbox_basicslider_gallery',
282 'type' => 'number',
283 'min' => 0,
284 'description' => __( 'Defines the slide height in pixels. If set to 0, slider height will adapt to slides height.', 'responsive-lightbox' ),
285 'append' => '%'
286 ],
287 'speed' => [
288 'title' => __( 'Animation Speed', 'responsive-lightbox' ),
289 'section' => 'responsive_lightbox_basicslider_gallery',
290 'type' => 'number',
291 'min' => 400,
292 'description' => __( 'The transition speed in milliseconds.', 'responsive-lightbox' ),
293 'append' => 'ms'
294 ],
295 'gap' => [
296 'title' => __( 'Slides Gap', 'responsive-lightbox' ),
297 'section' => 'responsive_lightbox_basicslider_gallery',
298 'type' => 'number',
299 'min' => 20,
300 'description' => __( 'The gap between slides.', 'responsive-lightbox' ),
301 'append' => 'px'
302 ],
303 'arrows_navigation' => [
304 'title' => __( 'Arrows Navigtion', 'responsive-lightbox' ),
305 'section' => 'responsive_lightbox_basicslider_gallery',
306 'type' => 'boolean',
307 'label' => __( 'Determines whether to create arrows or not.', 'responsive-lightbox' )
308 ],
309 'dots_navigation' => [
310 'title' => __( 'Dots Navigtion', 'responsive-lightbox' ),
311 'section' => 'responsive_lightbox_basicslider_gallery',
312 'type' => 'boolean',
313 'label' => __( 'Determines whether to create pagination (indicator dots) or not.', 'responsive-lightbox' )
314 ],
315 'drag' => [
316 'title' => __( 'Drag', 'responsive-lightbox' ),
317 'section' => 'responsive_lightbox_basicslider_gallery',
318 'type' => 'boolean',
319 'label' => __( 'Determines whether to allow the user to drag the carousel or not.', 'responsive-lightbox' )
320 ],
321 'autoplay' => [
322 'title' => __( 'Autoplay', 'responsive-lightbox' ),
323 'section' => 'responsive_lightbox_basicslider_gallery',
324 'type' => 'boolean',
325 'label' => __( 'Determines whether to enable autoplay or not.', 'responsive-lightbox' )
326 ],
327 'interval' => [
328 'title' => __( 'Interval', 'responsive-lightbox' ),
329 'section' => 'responsive_lightbox_basicslider_gallery',
330 'type' => 'number',
331 'min' => 1000,
332 'description' => __( 'The autoplay interval duration in milliseconds.', 'responsive-lightbox' ),
333 'append' => 'ms'
334 ],
335 'wheel' => [
336 'title' => __( 'Mouse Wheel', 'responsive-lightbox' ),
337 'section' => 'responsive_lightbox_basicslider_gallery',
338 'type' => 'boolean',
339 'label' => __( 'Determines whether to enable navigation by the mouse wheel.', 'responsive-lightbox' )
340 ],
341 'slides_per_page' => [
342 'title' => __( 'Per Page', 'responsive-lightbox' ),
343 'section' => 'responsive_lightbox_basicslider_gallery',
344 'type' => 'number',
345 'min' => 1,
346 'description' => __( 'Determines the number of slides to display in a page.', 'responsive-lightbox' )
347 ],
348 'slides_per_move' => [
349 'title' => __( 'Per Move', 'responsive-lightbox' ),
350 'section' => 'responsive_lightbox_basicslider_gallery',
351 'type' => 'number',
352 'min' => 1,
353 'description' => __( 'Determines the number of slides to move at once.', 'responsive-lightbox' )
354 ],
355 'slides_start' => [
356 'title' => __( 'Start', 'responsive-lightbox' ),
357 'section' => 'responsive_lightbox_basicslider_gallery',
358 'type' => 'number',
359 'min' => 0,
360 'description' => __( 'Defines the start index.', 'responsive-lightbox' )
361 ]
362 ]
363 ];
364 }
365
366 /**
367 * Get Basic Masonry gallery settings.
368 *
369 * @return array
370 */
371 private function get_basicmasonry_settings() {
372 return [
373 'option_group' => 'responsive_lightbox_basicmasonry_gallery',
374 'option_name' => 'responsive_lightbox_basicmasonry_gallery',
375 'validate' => [ $this, 'validate' ],
376 'sections' => [
377 'responsive_lightbox_basicmasonry_gallery' => [
378 'title' => __( 'Basic Masonry Gallery Settings', 'responsive-lightbox' )
379 ]
380 ],
381 'fields' => [
382 'screen_size_columns' => [
383 'title' => __( 'Screen Sizes', 'responsive-lightbox' ),
384 'section' => 'responsive_lightbox_basicmasonry_gallery',
385 'type' => 'multiple',
386 'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
387 'fields' => [
388 'columns_lg' => [
389 'type' => 'number',
390 'min' => 0,
391 'max' => 6,
392 'default' => 4,
393 'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
394 ],
395 'columns_md' => [
396 'type' => 'number',
397 'min' => 0,
398 'max' => 6,
399 'default' => 3,
400 'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
401 ],
402 'columns_sm' => [
403 'type' => 'number',
404 'min' => 0,
405 'max' => 6,
406 'default' => 2,
407 'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
408 ],
409 'columns_xs' => [
410 'type' => 'number',
411 'min' => 0,
412 'max' => 6,
413 'default' => 2,
414 'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
415 ]
416 ]
417 ],
418 'gutter' => [
419 'title' => __( 'Gutter', 'responsive-lightbox' ),
420 'section' => 'responsive_lightbox_basicmasonry_gallery',
421 'type' => 'number',
422 'description' => __( 'Horizontal space between gallery items.', 'responsive-lightbox' ),
423 'append' => 'px'
424 ],
425 'margin' => [
426 'title' => __( 'Margin', 'responsive-lightbox' ),
427 'section' => 'responsive_lightbox_basicmasonry_gallery',
428 'type' => 'number',
429 'description' => __( 'Vertical space between gallery items.', 'responsive-lightbox' ),
430 'append' => 'px'
431 ],
432 'origin_left' => [
433 'title' => __( 'Origin Left', 'responsive-lightbox' ),
434 'section' => 'responsive_lightbox_basicmasonry_gallery',
435 'type' => 'boolean',
436 'label' => __( 'Enable left-to-right layouts.', 'responsive-lightbox' ),
437 'description' => __( 'Controls the horizontal flow of the layout. By default, item elements start positioning at the left. Uncheck it for right-to-left layouts.', 'responsive-lightbox' )
438 ],
439 'origin_top' => [
440 'title' => __( 'Origin Top', 'responsive-lightbox' ),
441 'section' => 'responsive_lightbox_basicmasonry_gallery',
442 'type' => 'boolean',
443 'label' => __( 'Enable top-to-bottom layouts.', 'responsive-lightbox' ),
444 'description' => __( 'Controls the vertical flow of the layout. By default, item elements start positioning at the top. Uncheck it for bottom-up layouts.', 'responsive-lightbox' )
445 ]
446 ]
447 ];
448 }
449 }