PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 1.5.2
Responsive Lightbox & Gallery v1.5.2
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 / class-settings.php
responsive-lightbox / includes Last commit date
class-frontend.php 11 years ago class-settings.php 11 years ago
class-settings.php
1320 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4
5 new Responsive_Lightbox_Settings();
6
7 /**
8 * Responsive Lightbox settings class.
9 *
10 * @class Responsive_Lightbox_Settings
11 */
12 class Responsive_Lightbox_Settings {
13
14 private $settings = array();
15 private $scripts = array();
16 private $options = array();
17 private $defaults = array();
18 private $tabs = array();
19 private $choices = array();
20 private $loading_places = array();
21
22 public function __construct() {
23
24 // set instance
25 Responsive_Lightbox()->settings = $this;
26
27 // set vars
28 $this->defaults = Responsive_Lightbox()->defaults;
29 $this->options = Responsive_Lightbox()->options;
30
31 // actions
32 add_action( 'admin_init', array( &$this, 'register_settings' ) );
33 add_action( 'admin_menu', array( &$this, 'admin_menu_options' ) );
34 add_action( 'after_setup_theme', array( &$this, 'load_defaults' ) );
35 }
36
37 /**
38 * Load default settings.
39 *
40 * @return void
41 */
42 public function load_defaults() {
43
44 $this->scripts = array(
45 'prettyphoto' => array(
46 'name' => __( 'prettyPhoto', 'responsive-lightbox' ),
47 'animation_speeds' => array(
48 'slow' => __( 'slow', 'responsive-lightbox' ),
49 'normal' => __( 'normal', 'responsive-lightbox' ),
50 'fast' => __( 'fast', 'responsive-lightbox' )
51 ),
52 'themes' => array(
53 'pp_default' => __( 'default', 'responsive-lightbox' ),
54 'light_rounded' => __( 'light rounded', 'responsive-lightbox' ),
55 'dark_rounded' => __( 'dark rounded', 'responsive-lightbox' ),
56 'light_square' => __( 'light square', 'responsive-lightbox' ),
57 'dark_square' => __( 'dark square', 'responsive-lightbox' ),
58 'facebook' => __( 'facebook', 'responsive-lightbox' )
59 ),
60 'wmodes' => array(
61 'window' => __( 'window', 'responsive-lightbox' ),
62 'transparent' => __( 'transparent', 'responsive-lightbox' ),
63 'opaque' => __( 'opaque', 'responsive-lightbox' ),
64 'direct' => __( 'direct', 'responsive-lightbox' ),
65 'gpu' => __( 'gpu', 'responsive-lightbox' )
66 )
67 ),
68 'swipebox' => array(
69 'name' => __( 'SwipeBox', 'responsive-lightbox' ),
70 'animations' => array(
71 'css' => __( 'CSS', 'responsive-lightbox' ),
72 'jquery' => __( 'jQuery', 'responsive-lightbox' )
73 )
74 ),
75 'fancybox' => array(
76 'name' => __( 'FancyBox', 'responsive-lightbox' ),
77 'transitions' => array(
78 'elastic' => __( 'elastic', 'responsive-lightbox' ),
79 'fade' => __( 'fade', 'responsive-lightbox' ),
80 'none' => __( 'none', 'responsive-lightbox' )
81 ),
82 'scrollings' => array(
83 'auto' => __( 'auto', 'responsive-lightbox' ),
84 'yes' => __( 'yes', 'responsive-lightbox' ),
85 'no' => __( 'no', 'responsive-lightbox' )
86 ),
87 'easings' => array(
88 'swing' => __( 'swing', 'responsive-lightbox' ),
89 'linear' => __( 'linear', 'responsive-lightbox' )
90 ),
91 'positions' => array(
92 'outside' => __( 'outside', 'responsive-lightbox' ),
93 'inside' => __( 'inside', 'responsive-lightbox' ),
94 'over' => __( 'over', 'responsive-lightbox' )
95 )
96 ),
97 'nivo' => array(
98 'name' => __( 'Nivo Lightbox', 'responsive-lightbox' ),
99 'effects' => array(
100 'fade' => __( 'fade', 'responsive-lightbox' ),
101 'fadeScale' => __( 'fade scale', 'responsive-lightbox' ),
102 'slideLeft' => __( 'slide left', 'responsive-lightbox' ),
103 'slideRight' => __( 'slide right', 'responsive-lightbox' ),
104 'slideUp' => __( 'slide up', 'responsive-lightbox' ),
105 'slideDown' => __( 'slide down', 'responsive-lightbox' ),
106 'fall' => __( 'fall', 'responsive-lightbox' )
107 )
108 ),
109 'imagelightbox' => array(
110 'name' => __( 'Image Lightbox', 'responsive-lightbox' )
111 ),
112 'tosrus' => array(
113 'name' => __( 'TosRUs', 'responsive-lightbox' ),
114 ),
115 );
116
117 $this->gallery_image_titles = array(
118 'default' => __( 'None (default)', 'responsive-lightbox' ),
119 'title' => __( 'Image Title', 'responsive-lightbox' ),
120 'caption' => __( 'Image Caption', 'responsive-lightbox' ),
121 'alt' => __( 'Image Alt Text', 'responsive-lightbox' ),
122 'description' => __( 'Image Description', 'responsive-lightbox' )
123 );
124
125 $this->loading_places = array(
126 'header' => __( 'Header', 'responsive-lightbox' ),
127 'footer' => __( 'Footer', 'responsive-lightbox' )
128 );
129
130 // get scripts
131 foreach ( $this->scripts as $key => $value ) {
132 $scripts[$key] = $value['name'];
133 }
134
135 // get image sizes
136 $sizes = apply_filters( 'image_size_names_choose', array(
137 'thumbnail' => __( 'Thumbnail', 'responsive-lightbox' ),
138 'medium' => __( 'Medium', 'responsive-lightbox' ),
139 'large' => __( 'Large', 'responsive-lightbox' ),
140 'full' => __( 'Full Size (default)', 'responsive-lightbox' ),
141 ) );
142
143 $this->settings = array(
144 'settings' => array(
145 'option_group' => 'responsive_lightbox_settings',
146 'option_name' => 'responsive_lightbox_settings',
147 // 'callback' => array( &$this, 'validate_options' ),
148 'sections' => array(
149 'responsive_lightbox_settings' => array(
150 'title' => __( 'General settings', 'responsive-lightbox' ),
151 // 'callback' => '',
152 // 'page' => '',
153 ),
154 ),
155 'prefix' => 'rl',
156 'fields' => array(
157 'script' => array(
158 // 'name' => '',
159 'title' => __( 'Lightbox script', 'responsive-lightbox' ),
160 // 'callback' => '',
161 // 'page' => '',
162 'section' => 'responsive_lightbox_settings',
163 'type' => 'radio',
164 'label' => '',
165 'description' => __( 'Select your preffered ligthbox effect script.', 'responsive-lightbox' ),
166 'options' => $scripts,
167 // 'options_cb' => '',
168 // 'id' => '',
169 // 'class' => array(),
170 ),
171 'selector' => array(
172 'title' => __( 'Selector', 'responsive-lightbox' ),
173 'section' => 'responsive_lightbox_settings',
174 'type' => 'text',
175 'description' => __( 'Enter the rel selector lightbox effect will be applied to.', 'responsive-lightbox' ),
176 ),
177 'image_links' => array(
178 'title' => __( 'Image links', 'responsive-lightbox' ),
179 'section' => 'responsive_lightbox_settings',
180 'type' => 'boolean',
181 'label' => __( 'Add lightbox to WordPress image links by default.', 'responsive-lightbox' ),
182 ),
183 'images_as_gallery' => array(
184 'title' => __( 'Single images as gallery', 'responsive-lightbox' ),
185 'section' => 'responsive_lightbox_settings',
186 'type' => 'boolean',
187 'label' => __( 'Display single post images as a gallery.', 'responsive-lightbox' ),
188 ),
189 'galleries' => array(
190 'title' => __( 'Galleries', 'responsive-lightbox' ),
191 'section' => 'responsive_lightbox_settings',
192 'type' => 'boolean',
193 'label' => __( 'Add lightbox to WordPress image galleries by default.', 'responsive-lightbox' ),
194 ),
195 'gallery_image_size' => array(
196 'title' => __( 'Gallery image size', 'responsive-lightbox' ),
197 'section' => 'responsive_lightbox_settings',
198 'type' => 'select',
199 'description' => __( 'Select image size for gallery image links.', 'responsive-lightbox' ),
200 'options' => $sizes,
201 ),
202 'gallery_image_title' => array(
203 'title' => __( 'Gallery image title', 'responsive-lightbox' ),
204 'section' => 'responsive_lightbox_settings',
205 'type' => 'select',
206 'description' => __( 'Select title for images in native WordPress galleries.', 'responsive-lightbox' ),
207 'options' => $this->gallery_image_titles,
208 ),
209 'force_custom_gallery' => array(
210 'title' => __( 'Force gallery lightbox', 'responsive-lightbox' ),
211 'section' => 'responsive_lightbox_settings',
212 'type' => 'boolean',
213 'label' => __( 'Try to force lightbox for custom WP gallery replacements, like Jetpack tiled galleries.', 'responsive-lightbox' ),
214 ),
215 'videos' => array(
216 'title' => __( 'Video links', 'responsive-lightbox' ),
217 'section' => 'responsive_lightbox_settings',
218 'type' => 'boolean',
219 'label' => __( 'Add lightbox to YouTube and Vimeo video links by default.', 'responsive-lightbox' ),
220 ),
221 'enable_custom_events' => array(
222 'title' => __( 'Custom events', 'responsive-lightbox' ),
223 'section' => 'responsive_lightbox_settings',
224 'type' => 'multiple',
225 'fields' => array(
226 'enable_custom_events' => array(
227 'type' => 'boolean',
228 'label' => __( 'Enable triggering lightbox on custom jQuery events.', 'responsive-lightbox' ),
229 ),
230 'custom_events' => array(
231 'type' => 'text',
232 'description' => __( 'Enter a space separated list of events.', 'responsive-lightbox' ),
233 )
234 ),
235 ),
236 'loading_place' => array(
237 'title' => __( 'Loading place', 'responsive-lightbox' ),
238 'section' => 'responsive_lightbox_settings',
239 'type' => 'radio',
240 'description' => __( 'Select where all the lightbox scripts should be placed.', 'responsive-lightbox' ),
241 'options' => $this->loading_places,
242 ),
243 'deactivation_delete' => array(
244 'title' => __( 'Delete data', 'responsive-lightbox' ),
245 'section' => 'responsive_lightbox_settings',
246 'type' => 'boolean',
247 'label' => __( 'Delete all plugin settings on deactivation.', 'responsive-lightbox' ),
248 ),
249 ),
250 ),
251 'configuration' => array(
252 'option_group' => 'responsive_lightbox_configuration',
253 'option_name' => 'responsive_lightbox_configuration',
254 // 'callback' => array( &$this, 'validate_options' ),
255 'sections' => array(
256 'responsive_lightbox_configuration' => array(
257 'title' => __( 'Lightbox settings', 'responsive-lightbox' ) . ': ' . $this->scripts[$this->options['settings']['script']]['name'],
258 // 'callback' => '',
259 // 'page' => '',
260 ),
261 ),
262 'prefix' => 'rl',
263 'fields' => array(
264 )
265 )
266 );
267
268 switch ( $this->options['settings']['script'] ) {
269
270 case ( 'swipebox' ) :
271
272 $this->settings['configuration']['prefix'] = 'rl_sb';
273 $this->settings['configuration']['fields'] = array(
274 'animation' => array(
275 'title' => __( 'Animation type', 'responsive-lightbox' ),
276 'section' => 'responsive_lightbox_configuration',
277 'type' => 'radio',
278 'label' => '',
279 'description' => __( 'Select a method of applying a lightbox effect.', 'responsive-lightbox' ),
280 'options' => $this->scripts['swipebox']['animations'],
281 'parent' => 'swipebox'
282 ),
283 'force_png_icons' => array(
284 'title' => __( 'Force PNG icons', 'responsive-lightbox' ),
285 'section' => 'responsive_lightbox_configuration',
286 'type' => 'boolean',
287 'label' => __( 'Enable this if you\'re having problems with navigation icons not visible on some devices.', 'responsive-lightbox' ),
288 'parent' => 'swipebox'
289 ),
290 'hide_close_mobile' => array(
291 'title' => __( 'Hide close on mobile', 'responsive-lightbox' ),
292 'section' => 'responsive_lightbox_configuration',
293 'type' => 'boolean',
294 'label' => __( 'Hide the close button on mobile devices.', 'responsive-lightbox' ),
295 'parent' => 'swipebox'
296 ),
297 'hide_bars' => array(
298 'title' => __( 'Top and bottom bars', 'responsive-lightbox' ),
299 'section' => 'responsive_lightbox_configuration',
300 'type' => 'multiple',
301 'fields' => array(
302 'hide_bars' => array(
303 'type' => 'boolean',
304 'label' => __( 'Hide top and bottom bars after a period of time.', 'responsive-lightbox' ),
305 'parent' => 'swipebox'
306 ),
307 'hide_bars_delay' => array(
308 'type' => 'number',
309 'description' => __( 'Enter the time after which the top and bottom bars will be hidden (when hiding is enabled).', 'responsive-lightbox' ),
310 'append' => 'ms',
311 'parent' => 'swipebox'
312 )
313 )
314 ),
315 'video_max_width' => array(
316 'title' => __( 'Video max width', 'responsive-lightbox' ),
317 'section' => 'responsive_lightbox_configuration',
318 'type' => 'number',
319 'description' => __( 'Enter the max video width in a lightbox.', 'responsive-lightbox' ),
320 'append' => 'px',
321 'parent' => 'swipebox'
322 ),
323 'loop_at_end' => array(
324 'title' => __( 'Loop at end', 'responsive-lightbox' ),
325 'section' => 'responsive_lightbox_configuration',
326 'type' => 'boolean',
327 'label' => __( 'True will return to the first image after the last image is reached.', 'responsive-lightbox' ),
328 'parent' => 'swipebox'
329 ),
330 );
331
332 break;
333
334 case ( 'prettyphoto' ) :
335
336 $this->settings['configuration']['prefix'] = 'rl_pp';
337 $this->settings['configuration']['fields'] = array(
338 'animation_speed' => array(
339 'title' => __( 'Animation speed', 'responsive-lightbox' ),
340 'section' => 'responsive_lightbox_configuration',
341 'type' => 'radio',
342 'label' => '',
343 'description' => __( 'Select animation speed for lightbox effect.', 'responsive-lightbox' ),
344 'options' => $this->scripts['prettyphoto']['animation_speeds'],
345 'parent' => 'prettyphoto'
346 ),
347 'slideshow' => array(
348 'title' => __( 'Slideshow', 'responsive-lightbox' ),
349 'section' => 'responsive_lightbox_configuration',
350 'type' => 'multiple',
351 'fields' => array(
352 'slideshow' => array(
353 'type' => 'boolean',
354 'label' => __( 'Display images as slideshow', 'responsive-lightbox' ),
355 'parent' => 'prettyphoto'
356 ),
357 'slideshow_delay' => array(
358 'type' => 'number',
359 'description' => __( 'Enter time (in miliseconds).', 'responsive-lightbox' ),
360 'append' => 'ms',
361 'parent' => 'prettyphoto'
362 )
363 )
364 ),
365 'slideshow_autoplay' => array(
366 'title' => __( 'Slideshow autoplay', 'responsive-lightbox' ),
367 'section' => 'responsive_lightbox_configuration',
368 'type' => 'boolean',
369 'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
370 'parent' => 'prettyphoto'
371 ),
372 'opacity' => array(
373 'title' => __( 'Opacity', 'responsive-lightbox' ),
374 'section' => 'responsive_lightbox_configuration',
375 'type' => 'range',
376 'description' => __( 'Value between 0 and 100, 100 for no opacity.', 'responsive-lightbox' ),
377 'min' => 0,
378 'max' => 100,
379 'parent' => 'prettyphoto'
380 ),
381 'show_title' => array(
382 'title' => __( 'Show title', 'responsive-lightbox' ),
383 'section' => 'responsive_lightbox_configuration',
384 'type' => 'boolean',
385 'label' => __( 'Display image title.', 'responsive-lightbox' ),
386 'parent' => 'prettyphoto'
387 ),
388 'allow_resize' => array(
389 'title' => __( 'Allow resize big images', 'responsive-lightbox' ),
390 'section' => 'responsive_lightbox_configuration',
391 'type' => 'boolean',
392 'label' => __( 'Resize the photos bigger than viewport.', 'responsive-lightbox' ),
393 'parent' => 'prettyphoto'
394 ),
395 'allow_expand' => array(
396 'title' => __( 'Allow expand', 'responsive-lightbox' ),
397 'section' => 'responsive_lightbox_configuration',
398 'type' => 'boolean',
399 'label' => __( 'Allow expanding images.', 'responsive-lightbox' ),
400 'parent' => 'prettyphoto'
401 ),
402 'width' => array(
403 'title' => __( 'Video width', 'responsive-lightbox' ),
404 'section' => 'responsive_lightbox_configuration',
405 'type' => 'number',
406 'append' => 'px',
407 'parent' => 'prettyphoto'
408 ),
409 'height' => array(
410 'title' => __( 'Video height', 'responsive-lightbox' ),
411 'section' => 'responsive_lightbox_configuration',
412 'type' => 'number',
413 'append' => 'px',
414 'parent' => 'prettyphoto'
415 ),
416 'theme' => array(
417 'title' => __( 'Theme', 'responsive-lightbox' ),
418 'section' => 'responsive_lightbox_configuration',
419 'type' => 'radio',
420 'description' => __( 'Select the theme for lightbox effect.', 'responsive-lightbox' ),
421 'options' => $this->scripts['prettyphoto']['themes'],
422 'parent' => 'prettyphoto'
423 ),
424 'horizontal_padding' => array(
425 'title' => __( 'Horizontal padding', 'responsive-lightbox' ),
426 'section' => 'responsive_lightbox_configuration',
427 'type' => 'number',
428 'append' => 'px',
429 'parent' => 'prettyphoto'
430 ),
431 'hide_flash' => array(
432 'title' => __( 'Hide Flash', 'responsive-lightbox' ),
433 'section' => 'responsive_lightbox_configuration',
434 'type' => 'boolean',
435 'label' => __( 'Hide all the flash objects on a page. Enable this if flash appears over prettyPhoto.', 'responsive-lightbox' ),
436 'parent' => 'prettyphoto'
437 ),
438 'wmode' => array(
439 'title' => __( 'Flash Window Mode (wmode)', 'responsive-lightbox' ),
440 'section' => 'responsive_lightbox_configuration',
441 'type' => 'radio',
442 'description' => __( 'Select flash window mode.', 'responsive-lightbox' ),
443 'options' => $this->scripts['prettyphoto']['wmodes'],
444 'parent' => 'prettyphoto'
445 ),
446 'video_autoplay' => array(
447 'title' => __( 'Video autoplay', 'responsive-lightbox' ),
448 'section' => 'responsive_lightbox_configuration',
449 'type' => 'boolean',
450 'label' => __( 'Automatically start videos.', 'responsive-lightbox' ),
451 'parent' => 'prettyphoto'
452 ),
453 'modal' => array(
454 'title' => __( 'Modal', 'responsive-lightbox' ),
455 'section' => 'responsive_lightbox_configuration',
456 'type' => 'boolean',
457 'label' => __( 'If set to true, only the close button will close the window.', 'responsive-lightbox' ),
458 'parent' => 'prettyphoto'
459 ),
460 'deeplinking' => array(
461 'title' => __( 'Deeplinking', 'responsive-lightbox' ),
462 'section' => 'responsive_lightbox_configuration',
463 'type' => 'boolean',
464 'label' => __( 'Allow prettyPhoto to update the url to enable deeplinking.', 'responsive-lightbox' ),
465 'parent' => 'prettyphoto'
466 ),
467 'overlay_gallery' => array(
468 'title' => __( 'Overlay gallery', 'responsive-lightbox' ),
469 'section' => 'responsive_lightbox_configuration',
470 'type' => 'boolean',
471 'label' => __( 'If enabled, a gallery will overlay the fullscreen image on mouse over.', 'responsive-lightbox' ),
472 'parent' => 'prettyphoto'
473 ),
474 'keyboard_shortcuts' => array(
475 'title' => __( 'Keyboard shortcuts', 'responsive-lightbox' ),
476 'section' => 'responsive_lightbox_configuration',
477 'type' => 'boolean',
478 'label' => __( 'Set to false if you open forms inside prettyPhoto.', 'responsive-lightbox' ),
479 'parent' => 'prettyphoto'
480 ),
481 'social' => array(
482 'title' => __( 'Social (Twitter, Facebook)', 'responsive-lightbox' ),
483 'section' => 'responsive_lightbox_configuration',
484 'type' => 'boolean',
485 'label' => __( 'Display links to Facebook and Twitter.', 'responsive-lightbox' ),
486 'parent' => 'prettyphoto'
487 ),
488 );
489
490 break;
491
492 case ( 'fancybox' ) :
493
494 $this->settings['configuration']['prefix'] = 'rl_fb';
495 $this->settings['configuration']['fields'] = array(
496 'modal' => array(
497 'title' => __( 'Modal', 'responsive-lightbox' ),
498 'section' => 'responsive_lightbox_configuration',
499 'type' => 'boolean',
500 'label' => __( 'When true, "overlayShow" is set to true and "hideOnOverlayClick", "hideOnContentClick", "enableEscapeButton", "showCloseButton" are set to false.', 'responsive-lightbox' ),
501 'parent' => 'fancybox'
502 ),
503 'show_overlay' => array(
504 'title' => __( 'Show overlay', 'responsive-lightbox' ),
505 'section' => 'responsive_lightbox_configuration',
506 'type' => 'boolean',
507 'label' => __( 'Toggle overlay.', 'responsive-lightbox' ),
508 'parent' => 'fancybox'
509 ),
510 'show_close_button' => array(
511 'title' => __( 'Show close button', 'responsive-lightbox' ),
512 'section' => 'responsive_lightbox_configuration',
513 'type' => 'boolean',
514 'label' => __( 'Toggle close button.', 'responsive-lightbox' ),
515 'parent' => 'fancybox'
516 ),
517 'enable_escape_button' => array(
518 'title' => __( 'Enable escape button', 'responsive-lightbox' ),
519 'section' => 'responsive_lightbox_configuration',
520 'type' => 'boolean',
521 'label' => __( 'Toggle if pressing Esc button closes FancyBox.', 'responsive-lightbox' ),
522 'parent' => 'fancybox'
523 ),
524 'hide_on_overlay_click' => array(
525 'title' => __( 'Hide on overlay click', 'responsive-lightbox' ),
526 'section' => 'responsive_lightbox_configuration',
527 'type' => 'boolean',
528 'label' => __( 'Toggle if clicking the overlay should close FancyBox.', 'responsive-lightbox' ),
529 'parent' => 'fancybox'
530 ),
531 'hide_on_content_click' => array(
532 'title' => __( 'Hide on content click', 'responsive-lightbox' ),
533 'section' => 'responsive_lightbox_configuration',
534 'type' => 'boolean',
535 'label' => __( 'Toggle if clicking the content should close FancyBox.', 'responsive-lightbox' ),
536 'parent' => 'fancybox'
537 ),
538 'cyclic' => array(
539 'title' => __( 'Cyclic', 'responsive-lightbox' ),
540 'section' => 'responsive_lightbox_configuration',
541 'type' => 'boolean',
542 'label' => __( 'When true, galleries will be cyclic, allowing you to keep pressing next/back.', 'responsive-lightbox' ),
543 'parent' => 'fancybox'
544 ),
545 'show_nav_arrows' => array(
546 'title' => __( 'Show nav arrows', 'responsive-lightbox' ),
547 'section' => 'responsive_lightbox_configuration',
548 'type' => 'boolean',
549 'label' => __( 'Toggle navigation arrows.', 'responsive-lightbox' ),
550 'parent' => 'fancybox'
551 ),
552 'auto_scale' => array(
553 'title' => __( 'Auto scale', 'responsive-lightbox' ),
554 'section' => 'responsive_lightbox_configuration',
555 'type' => 'boolean',
556 'label' => __( 'If true, FancyBox is scaled to fit in viewport.', 'responsive-lightbox' ),
557 'parent' => 'fancybox'
558 ),
559 'scrolling' => array(
560 'title' => __( 'Scrolling (in/out)', 'responsive-lightbox' ),
561 'section' => 'responsive_lightbox_configuration',
562 'type' => 'radio',
563 'description' => __( 'Set the overflow CSS property to create or hide scrollbars.', 'responsive-lightbox' ),
564 'options' => $this->scripts['fancybox']['scrollings'],
565 'parent' => 'fancybox'
566 ),
567 'center_on_scroll' => array(
568 'title' => __( 'Center on scroll', 'responsive-lightbox' ),
569 'section' => 'responsive_lightbox_configuration',
570 'type' => 'boolean',
571 'label' => __( 'When true, FancyBox is centered while scrolling page.', 'responsive-lightbox' ),
572 'parent' => 'fancybox'
573 ),
574 'opacity' => array(
575 'title' => __( 'Opacity', 'responsive-lightbox' ),
576 'section' => 'responsive_lightbox_configuration',
577 'type' => 'boolean',
578 'label' => __( 'When true, transparency of content is changed for elastic transitions.', 'responsive-lightbox' ),
579 'parent' => 'fancybox'
580 ),
581 'overlay_opacity' => array(
582 'title' => __( 'Overlay opacity', 'responsive-lightbox' ),
583 'section' => 'responsive_lightbox_configuration',
584 'type' => 'range',
585 'description' => __( 'Opacity of the overlay.', 'responsive-lightbox' ),
586 'min' => 0,
587 'max' => 100,
588 'parent' => 'fancybox'
589 ),
590 'overlay_color' => array(
591 'title' => __( 'Overlay color', 'responsive-lightbox' ),
592 'section' => 'responsive_lightbox_configuration',
593 'type' => 'color_picker',
594 'label' => __( 'Color of the overlay.', 'responsive-lightbox' ),
595 'parent' => 'fancybox'
596 ),
597 'title_show' => array(
598 'title' => __( 'Title show', 'responsive-lightbox' ),
599 'section' => 'responsive_lightbox_configuration',
600 'type' => 'boolean',
601 'label' => __( 'Toggle title.', 'responsive-lightbox' ),
602 'parent' => 'fancybox'
603 ),
604 'title_position' => array(
605 'title' => __( 'Title position', 'responsive-lightbox' ),
606 'section' => 'responsive_lightbox_configuration',
607 'type' => 'radio',
608 'description' => __( 'The position of title.', 'responsive-lightbox' ),
609 'options' => $this->scripts['fancybox']['positions'],
610 'parent' => 'fancybox'
611 ),
612 'transitions' => array(
613 'title' => __( 'Transition (in/out)', 'responsive-lightbox' ),
614 'section' => 'responsive_lightbox_configuration',
615 'type' => 'radio',
616 'description' => __( 'The transition type.', 'responsive-lightbox' ),
617 'options' => $this->scripts['fancybox']['transitions'],
618 'parent' => 'fancybox'
619 ),
620 'easings' => array(
621 'title' => __( 'Easings (in/out)', 'responsive-lightbox' ),
622 'section' => 'responsive_lightbox_configuration',
623 'type' => 'radio',
624 'description' => __( 'Easing used for elastic animations.', 'responsive-lightbox' ),
625 'options' => $this->scripts['fancybox']['easings'],
626 'parent' => 'fancybox'
627 ),
628 'speeds' => array(
629 'title' => __( 'Speed (in/out)', 'responsive-lightbox' ),
630 'section' => 'responsive_lightbox_configuration',
631 'type' => 'number',
632 'description' => __( 'Speed of the fade and elastic transitions, in milliseconds.', 'responsive-lightbox' ),
633 'append' => 'ms',
634 'parent' => 'fancybox'
635 ),
636 'change_speed' => array(
637 'title' => __( 'Change speed', 'responsive-lightbox' ),
638 'section' => 'responsive_lightbox_configuration',
639 'type' => 'number',
640 'description' => __( 'Speed of resizing when changing gallery items, in milliseconds.', 'responsive-lightbox' ),
641 'append' => 'ms',
642 'parent' => 'fancybox'
643 ),
644 'change_fade' => array(
645 'title' => __( 'Change fade', 'responsive-lightbox' ),
646 'section' => 'responsive_lightbox_configuration',
647 'type' => 'number',
648 'description' => __( 'Speed of the content fading while changing gallery items.', 'responsive-lightbox' ),
649 'append' => 'ms',
650 'parent' => 'fancybox'
651 ),
652 'padding' => array(
653 'title' => __( 'Padding', 'responsive-lightbox' ),
654 'section' => 'responsive_lightbox_configuration',
655 'type' => 'number',
656 'description' => __( 'Space between FancyBox wrapper and content.', 'responsive-lightbox' ),
657 'append' => 'px',
658 'parent' => 'fancybox'
659 ),
660 'margin' => array(
661 'title' => __( 'Margin', 'responsive-lightbox' ),
662 'section' => 'responsive_lightbox_configuration',
663 'type' => 'number',
664 'description' => __( 'Space between viewport and FancyBox wrapper.', 'responsive-lightbox' ),
665 'append' => 'px',
666 'parent' => 'fancybox'
667 ),
668 'video_width' => array(
669 'title' => __( 'Video width', 'responsive-lightbox' ),
670 'section' => 'responsive_lightbox_configuration',
671 'type' => 'number',
672 'description' => __( 'Width of the video.', 'responsive-lightbox' ),
673 'append' => 'px',
674 'parent' => 'fancybox'
675 ),
676 'video_height' => array(
677 'title' => __( 'Video height', 'responsive-lightbox' ),
678 'section' => 'responsive_lightbox_configuration',
679 'type' => 'number',
680 'description' => __( 'Height of the video.', 'responsive-lightbox' ),
681 'append' => 'px',
682 'parent' => 'fancybox'
683 ),
684 );
685
686 break;
687
688 case ( 'nivo' ) :
689
690 $this->settings['configuration']['prefix'] = 'rl_nv';
691 $this->settings['configuration']['fields'] = array(
692 'effect' => array(
693 'title' => __( 'Effect', 'responsive-lightbox' ),
694 'section' => 'responsive_lightbox_configuration',
695 'type' => 'radio',
696 'description' => __( 'The effect to use when showing the lightbox.', 'responsive-lightbox' ),
697 'options' => $this->scripts['nivo']['effects'],
698 'parent' => 'nivo'
699 ),
700 'keyboard_nav' => array(
701 'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
702 'section' => 'responsive_lightbox_configuration',
703 'type' => 'boolean',
704 'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
705 'parent' => 'nivo'
706 ),
707 'click_overlay_to_close' => array(
708 'title' => __( 'Click overlay to close', 'responsive-lightbox' ),
709 'section' => 'responsive_lightbox_configuration',
710 'type' => 'boolean',
711 'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
712 'parent' => 'nivo'
713 ),
714 'error_message' => array(
715 'title' => __( 'Error message', 'responsive-lightbox' ),
716 'section' => 'responsive_lightbox_configuration',
717 'type' => 'text',
718 'class' => 'large-text',
719 'label' => __( 'Error message if the content cannot be loaded.', 'responsive-lightbox' ),
720 'parent' => 'nivo'
721 ),
722 );
723
724 break;
725
726 case ( 'imagelightbox' ) :
727
728 $this->settings['configuration']['prefix'] = 'rl_il';
729 $this->settings['configuration']['fields'] = array(
730 'animation_speed' => array(
731 'title' => __( 'Animation speed', 'responsive-lightbox' ),
732 'section' => 'responsive_lightbox_configuration',
733 'type' => 'number',
734 'description' => __( 'Animation speed.', 'responsive-lightbox' ),
735 'append' => 'ms',
736 'parent' => 'imagelightbox'
737 ),
738 'preload_next' => array(
739 'title' => __( 'Preload next image', 'responsive-lightbox' ),
740 'section' => 'responsive_lightbox_configuration',
741 'type' => 'boolean',
742 'label' => __( 'Silently preload the next image.', 'responsive-lightbox' ),
743 'parent' => 'imagelightbox'
744 ),
745 'enable_keyboard' => array(
746 'title' => __( 'Enable keyboard keys', 'responsive-lightbox' ),
747 'section' => 'responsive_lightbox_configuration',
748 'type' => 'boolean',
749 'label' => __( 'Enable keyboard shortcuts (arrows Left/Right and Esc).', 'responsive-lightbox' ),
750 'parent' => 'imagelightbox'
751 ),
752 'quit_on_end' => array(
753 'title' => __( 'Quit after last image', 'responsive-lightbox' ),
754 'section' => 'responsive_lightbox_configuration',
755 'type' => 'boolean',
756 'label' => __( 'Quit after viewing the last image.', 'responsive-lightbox' ),
757 'parent' => 'imagelightbox'
758 ),
759 'quit_on_image_click' => array(
760 'title' => __( 'Quit on image click', 'responsive-lightbox' ),
761 'section' => 'responsive_lightbox_configuration',
762 'type' => 'boolean',
763 'label' => __( 'Quit when the viewed image is clicked.', 'responsive-lightbox' ),
764 'parent' => 'imagelightbox'
765 ),
766 'quit_on_document_click' => array(
767 'title' => __( 'Quit on anything click', 'responsive-lightbox' ),
768 'section' => 'responsive_lightbox_configuration',
769 'type' => 'boolean',
770 'label' => __( 'Quit when anything but the viewed image is clicked.', 'responsive-lightbox' ),
771 'parent' => 'imagelightbox'
772 ),
773 );
774
775 break;
776
777 case ( 'tosrus' ) :
778
779 $this->settings['configuration']['prefix'] = 'rl_tr';
780 $this->settings['configuration']['fields'] = array(
781 'effect' => array(
782 'title' => __( 'Transition effect', 'responsive-lightbox' ),
783 'section' => 'responsive_lightbox_configuration',
784 'type' => 'radio',
785 'description' => __( 'What effect to use for the transition.', 'responsive-lightbox' ),
786 'options' => array(
787 'slide' => __( 'slide', 'responsive-lightbox' ),
788 'fade' => __( 'fade', 'responsive-lightbox' )
789 ),
790 'parent' => 'tosrus'
791 ),
792 'infinite' => array(
793 'title' => __( 'Infinite loop', 'responsive-lightbox' ),
794 'section' => 'responsive_lightbox_configuration',
795 'type' => 'boolean',
796 'label' => __( 'Whether or not to slide back to the first slide when the last has been reached.', 'responsive-lightbox' ),
797 'parent' => 'tosrus'
798 ),
799 'keys' => array(
800 'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
801 'section' => 'responsive_lightbox_configuration',
802 'type' => 'boolean',
803 'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
804 'parent' => 'tosrus'
805 ),
806 'autoplay' => array(
807 'title' => __( 'Autoplay', 'responsive-lightbox' ),
808 'section' => 'responsive_lightbox_configuration',
809 'type' => 'multiple',
810 'fields' => array(
811 'autoplay' => array(
812 'type' => 'boolean',
813 'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
814 'parent' => 'tosrus'
815 ),
816 'timeout' => array(
817 'type' => 'number',
818 'description' => __( 'The timeout between sliding to the next slide in milliseconds.', 'responsive-lightbox' ),
819 'append' => 'ms',
820 'parent' => 'tosrus'
821 )
822 )
823 ),
824 'pause_on_hover' => array(
825 'title' => __( 'Pause on hover', 'responsive-lightbox' ),
826 'section' => 'responsive_lightbox_configuration',
827 'type' => 'boolean',
828 'label' => __( 'Whether or not to pause on hover.', 'responsive-lightbox' ),
829 'parent' => 'tosrus'
830 ),
831 'pagination' => array(
832 'title' => __( 'Pagination', 'responsive-lightbox' ),
833 'section' => 'responsive_lightbox_configuration',
834 'type' => 'multiple',
835 'fields' => array(
836 'pagination' => array(
837 'type' => 'boolean',
838 'label' => __( 'Whether or not to add a pagination.', 'responsive-lightbox' ),
839 'parent' => 'tosrus'
840 ),
841 'pagination_type' => array(
842 'type' => 'radio',
843 'description' => __( 'What type of pagination to use.', 'responsive-lightbox' ),
844 'options' => array(
845 'bullets' => __( 'Bullets', 'responsive-lightbox' ),
846 'thumbnails' => __( 'Thumbnails', 'responsive-lightbox' )
847 ),
848 'parent' => 'tosrus'
849 )
850 )
851 )
852 );
853
854 break;
855
856 default :
857 break;
858 }
859
860 $this->tabs = array(
861 'settings' => array(
862 'name' => __( 'General settings', 'responsive-lightbox' ),
863 'key' => 'responsive_lightbox_settings',
864 'submit' => 'save_rl_settings',
865 'reset' => 'reset_rl_settings',
866 ),
867 'configuration' => array(
868 'name' => __( 'Lightbox settings', 'responsive-lightbox' ),
869 'key' => 'responsive_lightbox_configuration',
870 'submit' => 'save_' . $this->settings['configuration']['prefix'] . '_configuration',
871 'reset' => 'reset_' . $this->settings['configuration']['prefix'] . '_configuration'
872 )
873 );
874
875 }
876
877 /**
878 * Register options page
879 *
880 * @return void
881 */
882 public function admin_menu_options() {
883 add_options_page(
884 __( 'Responsive Lightbox', 'responsive-lightbox' ), __( 'Responsive Lightbox', 'responsive-lightbox' ), 'manage_options', 'responsive-lightbox', array( &$this, 'options_page' )
885 );
886 }
887
888 /**
889 * Render options page
890 *
891 * @return void
892 */
893 public function options_page() {
894 $tab_key = (isset( $_GET['tab'] ) ? $_GET['tab'] : 'settings');
895
896 echo '
897 <div class="wrap">' . screen_icon() . '
898 <h2>' . __( 'Responsive Lightbox', 'responsive-lightbox' ) . '</h2>
899 <h2 class="nav-tab-wrapper">';
900
901 foreach ( $this->tabs as $key => $name ) {
902 echo '
903 <a class="nav-tab ' . ($tab_key == $key ? 'nav-tab-active' : '') . '" href="' . esc_url( admin_url( 'options-general.php?page=responsive-lightbox&tab=' . $key ) ) . '">' . $name['name'] . '</a>';
904 }
905
906 echo '
907 </h2>
908 <div class="responsive-lightbox-settings">
909
910 <div class="df-credits">
911 <h3 class="hndle">' . __( 'Responsive Lightbox', 'responsive-lightbox' ) . ' ' . $this->defaults['version'] . '</h3>
912 <div class="inside">
913 <h4 class="inner">' . __( 'Need support?', 'responsive-lightbox' ) . '</h4>
914 <p class="inner">' . __( 'If you are having problems with this plugin, please talk about them in the', 'responsive-lightbox' ) . ' <a href="http://www.dfactory.eu/support/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=support" target="_blank" title="' . __( 'Support forum', 'responsive-lightbox' ) . '">' . __( 'Support forum', 'responsive-lightbox' ) . '</a></p>
915 <hr />
916 <h4 class="inner">' . __( 'Do you like this plugin?', 'responsive-lightbox' ) . '</h4>
917 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" class="inner">
918 <input type="hidden" name="cmd" value="_s-xclick">
919 <input type="hidden" name="hosted_button_id" value="8AL8ULUN9R76U">
920 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
921 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
922 </form>
923 <p class="inner"><a href="http://wordpress.org/support/view/plugin-reviews/responsive-lightbox" target="_blank" title="' . __( 'Rate it 5', 'responsive-lightbox' ) . '">' . __( 'Rate it 5', 'responsive-lightbox' ) . '</a> ' . __( 'on WordPress.org', 'responsive-lightbox' ) . '<br />' .
924 __( 'Blog about it & link to the', 'responsive-lightbox' ) . ' <a href="http://www.dfactory.eu/plugins/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=blog-about" target="_blank" title="' . __( 'plugin page', 'responsive-lightbox' ) . '">' . __( 'plugin page', 'responsive-lightbox' ) . '</a><br />' .
925 __( 'Check out our other', 'responsive-lightbox' ) . ' <a href="http://www.dfactory.eu/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=other-plugins" target="_blank" title="' . __( 'WordPress plugins', 'responsive-lightbox' ) . '">' . __( 'WordPress plugins', 'responsive-lightbox' ) . '</a>
926 </p>
927 <hr />
928 <p class="df-link inner">Created by <a href="http://www.dfactory.eu/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="dFactory - Quality plugins for WordPress"><img src="' . RESPONSIVE_LIGHTBOX_URL . '/images/logo-dfactory.png' . '" title="dFactory - Quality plugins for WordPress" alt="dFactory - Quality plugins for WordPress" /></a></p>
929 </div>
930 </div>
931
932 <form action="options.php" method="post">
933 <input type="hidden" name="script_r" value="' . esc_attr( $this->options['settings']['script'] ) . '" />';
934
935 wp_nonce_field( 'update-options' );
936 settings_fields( $this->tabs[$tab_key]['key'] );
937 do_settings_sections( $this->tabs[$tab_key]['key'] );
938
939 echo '
940 <p class="submit">';
941
942 submit_button( '', array( 'primary', 'save-' . $tab_key ), $this->tabs[$tab_key]['submit'], false );
943
944 echo ' ';
945 echo submit_button( __( 'Reset to defaults', 'responsive-lightbox' ), array( 'secondary', 'reset-' . $tab_key ), $this->tabs[$tab_key]['reset'], false );
946
947 echo '
948 </p>
949 </form>
950 </div>
951 <div class="clear"></div>
952 </div>';
953 }
954
955 /**
956 * Render settings function
957 *
958 * @return void
959 */
960 public function register_settings() {
961
962 foreach ( $this->settings as $setting_id => $setting ) {
963
964 // set key
965 $setting_key = $setting_id;
966 $setting_id = 'responsive_lightbox_' . $setting_id;
967
968 // register setting
969 register_setting(
970 esc_attr( $setting_id ),
971 ! empty( $setting['option_name'] ) ? esc_attr( $setting['option_name'] ) : $setting_id,
972 ! empty( $setting['callback'] ) ? $setting['callback'] : array( &$this, 'validate_settings' )
973 );
974
975 // register sections
976 if ( ! empty( $setting['sections'] ) && is_array( $setting['sections'] ) ) {
977
978 foreach ( $setting['sections'] as $section_id => $section ) {
979
980 add_settings_section(
981 esc_attr( $section_id ),
982 ! empty( $section['title'] ) ? esc_html( $section['title'] ) : '',
983 ! empty( $section['callback'] ) ? $section['callback'] : '',
984 ! empty( $section['page'] ) ? esc_attr( $section['page'] ) : $section_id
985 );
986 }
987
988 }
989
990 // register fields
991 if ( ! empty( $setting['fields'] ) && is_array( $setting['fields'] ) ) {
992
993 foreach ( $setting['fields'] as $field_id => $field ) {
994
995 // prefix field id?
996 $field_key = $field_id;
997 $field_id = ( ! empty( $setting['prefix'] ) ? $setting['prefix'] . '_' : '' ) . $field_id;
998
999 // field args
1000 $args = array(
1001 'id' => ! empty( $field['id'] ) ? $field['id'] : $field_id,
1002 'class' => ! empty( $field['class'] ) ? $field['class'] : '',
1003 'name' => $setting['option_name'] . ( ! empty( $field['parent'] ) ? '[' . $field['parent'] . ']' : '' ) . '[' . $field_key . ']',
1004 'type' => ! empty( $field['type'] ) ? $field['type'] : 'text',
1005 'label' => ! empty( $field['label'] ) ? $field['label'] : '',
1006 'description' => ! empty( $field['description'] ) ? $field['description'] : '',
1007 'append' => ! empty( $field['append'] ) ? esc_html( $field['append'] ) : '',
1008 'prepend' => ! empty( $field['prepend'] ) ? esc_html( $field['prepend'] ) : '',
1009 'min' => ! empty( $field['min'] ) ? (int) $field['min'] : '',
1010 'max' => ! empty( $field['max'] ) ? (int) $field['max'] : '',
1011 'options' => ! empty( $field['options'] ) ? $field['options'] : '',
1012 'fields' => ! empty( $field['fields'] ) ? $field['fields'] : '',
1013 'default' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $this->defaults[$setting_key][$field['parent']][$field_key] : $this->defaults[$setting_key][$field_key], $field['type'] ) ),
1014 'value' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $this->options[$setting_key][$field['parent']][$field_key] : $this->options[$setting_key][$field_key], $field['type'] ) ),
1015 'label_for' => $field_id,
1016 'return' => false
1017 );
1018
1019 if ( $args['type'] === 'multiple' ) {
1020 foreach ( $args['fields'] as $subfield_id => $subfield ) {
1021 $args['fields'][$subfield_id] = wp_parse_args( $subfield, array(
1022 'id' => $field_id . '-' . $subfield_id,
1023 'class' => ! empty( $subfield['class'] ) ? $subfield['class'] : '',
1024 'name' => $setting['option_name'] . ( ! empty( $subfield['parent'] ) ? '[' . $subfield['parent'] . ']' : '' ) . '[' . $subfield_id . ']',
1025 'default' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $this->defaults[$setting_key][$subfield['parent']][$subfield_id] : $this->defaults[$setting_key][$subfield_id], $subfield['type'] ),
1026 'value' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $this->options[$setting_key][$subfield['parent']][$subfield_id] : $this->options[$setting_key][$subfield_id], $subfield['type'] ),
1027 'return' => true
1028 ) );
1029 }
1030 }
1031
1032 add_settings_field(
1033 esc_attr( $field_id ),
1034 ! empty( $field['title'] ) ? esc_html( $field['title'] ) : '',
1035 array( &$this, 'render_field' ),
1036 ! empty( $field['page'] ) ? esc_attr( $field['page'] ) : $setting_id,
1037 ! empty( $field['section'] ) ? esc_attr( $field['section'] ) : '',
1038 $args
1039 );
1040
1041 }
1042
1043 }
1044
1045 }
1046
1047 }
1048
1049 /**
1050 * Render settings field function
1051 *
1052 * @param array $args
1053 * @return mixed
1054 */
1055 public function render_field( $args ) {
1056
1057 if ( empty( $args ) || ! is_array( $args ) )
1058 return;
1059
1060 $html = '';
1061
1062 switch ( $args['type'] ) {
1063
1064 case ( 'boolean' ) :
1065
1066 $html .= '<label class="cb-checkbox"><input id="' . $args['id'] . '" type="checkbox" name="' . $args['name'] . '" value="1" ' . checked( (bool) $args['value'], true, false ) . ' />' . $args['label'] . '</label>';
1067 break;
1068
1069 case ( 'radio' ) :
1070
1071 foreach ( $args['options'] as $key => $name ) {
1072 $html .= '<label class="cb-radio"><input id="' . $args['id'] . '-' . $key . '" type="radio" name="' . $args['name'] . '" value="' . $key . '" ' . checked( $key, $args['value'], false ) . ' />' . $name . '</label> ';
1073 }
1074 break;
1075
1076 case ( 'checkbox' ) :
1077
1078 foreach ( $args['options'] as $key => $name ) {
1079 $html .= '<label class="cb-checkbox"><input id="' . $args['id'] . '-' . $key . '" type="checkbox" name="' . $args['name'] . '" value="' . $key . '" ' . checked( $key, $args['value'], false ) . ' />' . $name . '</label> ';
1080 }
1081 break;
1082
1083 case ( 'select' ) :
1084
1085 $html .= '<select id="' . $args['id'] . '" name="' . $args['name'] . '" value="' . $args['value'] . '" />';
1086
1087 foreach ( $args['options'] as $key => $name ) {
1088 $html .= '<option value="' . $key . '" ' . selected( $args['value'], $key, false ) . '>' . $name . '</option>';
1089 }
1090
1091 $html .= '</select>';
1092 break;
1093
1094 case ( 'multiple' ) :
1095
1096 $html .= '<fieldset>';
1097
1098 if ( $args['fields'] ) {
1099
1100 $count = 1;
1101 $count_fields = count( $args['fields'] );
1102
1103 foreach ( $args['fields'] as $subfield_id => $subfield_args ) {
1104 $html .= $this->render_field( $subfield_args ) . ( $count < $count_fields ? '<br />' : '' );
1105 $count++;
1106 }
1107
1108 }
1109
1110 $html .= '</fieldset>';
1111 break;
1112
1113 case ( 'range' ) :
1114 $html .= '<input id="' . $args['id'] . '" type="range" name="' . $args['name'] . '" value="' . $args['value'] . '" min="' . $args['min'] . '" max="' . $args['max'] . '" oninput="this.form.' . $args['id'] . '_range.value=this.value" />';
1115 $html .= '<output name="' . $args['id'] . '_range">' . esc_attr( $this->options['configuration']['prettyphoto']['opacity'] ) . '</output>';
1116 break;
1117
1118 case ( 'color_picker' ) :
1119 $html .= '<input id="' . $args['id'] . '" class="color-picker" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" data-default-color="' . $args['default'] . '" />';
1120 break;
1121
1122 case ( 'number' ) :
1123 $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
1124 $html .= '<input id="' . $args['id'] . '" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" />';
1125 $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
1126 break;
1127
1128 case ( 'text' ) :
1129 default :
1130 $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
1131 $html .= '<input id="' . $args['id'] . '" class="' . $args['class'] . '" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" />';
1132 $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
1133 break;
1134
1135 }
1136
1137 if ( ! empty ( $args['description'] ) ) {
1138 $html .= '<p class="description">' . $args['description'] . '</p>';
1139 }
1140
1141 if ( ! empty( $args['return'] ) ) {
1142 return $html;
1143 } else {
1144 echo $html;
1145 }
1146 }
1147
1148 /**
1149 * Sanitize field function
1150 *
1151 * @param mixed
1152 * @param string
1153 * @return mixed
1154 */
1155 public function sanitize_field( $value = null, $type = '', $args = array() ) {
1156 if ( is_null( $value ) )
1157 return null;
1158
1159 switch ( $type ) {
1160
1161 case 'boolean':
1162 $value = empty( $value ) ? false : true;
1163 break;
1164
1165 case 'checkbox':
1166 $value = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : false;
1167 break;
1168
1169 case 'radio':
1170 $value = is_array( $value ) ? false : sanitize_text_field( $value );
1171 break;
1172
1173 case 'textarea':
1174 case 'wysiwyg':
1175 $value = wp_kses_post( $value );
1176 break;
1177
1178 case 'color_picker':
1179 $value = ! $value || '#' == $value ? '' : esc_attr( $value );
1180 break;
1181
1182 case 'number':
1183 $value = ! $value || is_array( $value ) ? '' : str_replace( ',', '', $value );
1184
1185 if ( ! empty( $args['type'] ) ) {
1186 switch ( $args['type'] ) {
1187 case 'int':
1188 $value = (int) $value;
1189 break;
1190
1191 case 'absint':
1192 $value = absint( $value );
1193 break;
1194
1195 case 'float':
1196 default:
1197 $value = floatval( $value );
1198 break;
1199 }
1200 } else {
1201 $value = floatval( $value );
1202 }
1203 break;
1204
1205 case 'text':
1206 case 'select':
1207 default:
1208 $value = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value );
1209 break;
1210 }
1211
1212 return stripslashes_deep( $value );
1213 }
1214
1215 /**
1216 * Validate settings function
1217 *
1218 * @param array $input
1219 * @return array
1220 */
1221 public function validate_settings( $input ) {
1222 // check cap
1223 if ( ! current_user_can( 'manage_options') ) {
1224 return $input;
1225 }
1226
1227 // check page
1228 if ( ! ( $option_page = esc_attr( $_POST['option_page'] ) ) )
1229 return $input;
1230
1231 foreach ( $this->settings as $id => $setting ) {
1232
1233 $key = array_search( $option_page, $setting );
1234
1235 if ( $key ) {
1236 // set key
1237 $setting_id = $id;
1238 continue;
1239 }
1240 }
1241
1242 // check setting id
1243 if ( ! $setting_id )
1244 return $input;
1245
1246 // save settings
1247 if ( isset( $_POST['save' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
1248
1249 if ( $this->settings[$setting_id]['fields'] ) {
1250
1251 foreach ( $this->settings[$setting_id]['fields'] as $field_id => $field ) {
1252
1253 if ( $field['type'] === 'multiple' ) {
1254
1255 if ( $field['fields'] ) {
1256
1257 foreach ( $field['fields'] as $subfield_id => $subfield ) {
1258
1259 // if subfield has parent
1260 if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['fields'][$subfield_id]['parent'] ) ) {
1261
1262 $field_parent = $this->settings[$setting_id]['fields'][$field_id]['fields'][$subfield_id]['parent'];
1263
1264 $input[$field_parent][$subfield_id] = isset( $input[$field_parent][$subfield_id] ) ? $this->sanitize_field( $input[$field_parent][$subfield_id], $subfield['type'] ) : ( $subfield['type'] === 'boolean' ? false : $this->defaults[$setting_id][$field_parent][$subfield_id] );
1265
1266 } else {
1267
1268 $input[$subfield_id] = isset( $input[$subfield_id] ) ? $this->sanitize_field( $input[$subfield_id], $subfield['type'] ) : ( $subfield['type'] === 'boolean' ? false : $this->defaults[$setting_id][$field_id][$subfield_id] );
1269
1270 }
1271
1272 }
1273
1274 }
1275
1276 } else {
1277
1278 // if field has parent
1279 if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['parent'] ) ) {
1280
1281 $field_parent = $this->settings[$setting_id]['fields'][$field_id]['parent'];
1282
1283 $input[$field_parent][$field_id] = isset( $input[$field_parent][$field_id] ) ? $this->sanitize_field( $input[$field_parent][$field_id], $field['type'] ) : ( $field['type'] === 'boolean' ? false : $this->defaults[$setting_id][$field_parent][$field_id] );
1284
1285 } else {
1286
1287 $input[$field_id] = isset( $input[$field_id] ) ? $this->sanitize_field( $input[$field_id], $field['type'] ) : ( $field['type'] === 'boolean' ? false : $this->defaults[$setting_id][$field_id] );
1288
1289 }
1290
1291 }
1292
1293 }
1294
1295 }
1296
1297 if ( $setting_id === 'configuration' ) {
1298 // merge scripts settings
1299 $input = array_merge( $this->options['configuration'], $input );
1300 }
1301
1302 } elseif ( isset( $_POST['reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
1303
1304 if ( $setting_id === 'configuration' ) {
1305 // merge scripts settings
1306 $input[$this->options['settings']['script']] = $this->defaults['configuration'][$this->options['settings']['script']];
1307 $input = array_merge( $this->options['configuration'], $input );
1308 } else {
1309 $input = $this->defaults[$setting_id];
1310 }
1311
1312 add_settings_error( 'reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id, 'settings_restored', __( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
1313
1314 }
1315
1316 return $input;
1317 }
1318
1319 }
1320