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