PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 1.7.1
Responsive Lightbox & Gallery v1.7.1
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 9 years ago class-settings.php 9 years ago class-widgets.php 9 years ago
class-settings.php
1749 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 new Responsive_Lightbox_Settings();
7
8 /**
9 * Responsive Lightbox settings class.
10 *
11 * @class Responsive_Lightbox_Settings
12 */
13 class Responsive_Lightbox_Settings {
14
15 public $settings = array();
16 private $scripts = array();
17 private $tabs = array();
18 private $choices = array();
19 private $loading_places = array();
20 private $api_url = 'http://dfactory.eu';
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 = apply_filters( 'rl_settings_scripts', array(
41 'swipebox' => array(
42 'name' => __( 'SwipeBox', 'responsive-lightbox' ),
43 'animations' => array(
44 'css' => __( 'CSS', 'responsive-lightbox' ),
45 'jquery' => __( 'jQuery', 'responsive-lightbox' )
46 )
47 ),
48 'prettyphoto' => array(
49 'name' => __( 'prettyPhoto', 'responsive-lightbox' ),
50 'animation_speeds' => array(
51 'slow' => __( 'slow', 'responsive-lightbox' ),
52 'normal' => __( 'normal', 'responsive-lightbox' ),
53 'fast' => __( 'fast', 'responsive-lightbox' )
54 ),
55 'themes' => array(
56 'pp_default' => __( 'default', 'responsive-lightbox' ),
57 'light_rounded' => __( 'light rounded', 'responsive-lightbox' ),
58 'dark_rounded' => __( 'dark rounded', 'responsive-lightbox' ),
59 'light_square' => __( 'light square', 'responsive-lightbox' ),
60 'dark_square' => __( 'dark square', 'responsive-lightbox' ),
61 'facebook' => __( 'facebook', 'responsive-lightbox' )
62 ),
63 'wmodes' => array(
64 'window' => __( 'window', 'responsive-lightbox' ),
65 'transparent' => __( 'transparent', 'responsive-lightbox' ),
66 'opaque' => __( 'opaque', 'responsive-lightbox' ),
67 'direct' => __( 'direct', 'responsive-lightbox' ),
68 'gpu' => __( 'gpu', '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 'featherlight' => array(
112 'name' => __( 'Featherlight', 'responsive-lightbox' ),
113 ),
114 ) );
115
116 $this->image_titles = array(
117 'default' => __( 'None (default)', 'responsive-lightbox' ),
118 'title' => __( 'Image Title', 'responsive-lightbox' ),
119 'caption' => __( 'Image Caption', 'responsive-lightbox' ),
120 'alt' => __( 'Image Alt Text', 'responsive-lightbox' ),
121 'description' => __( 'Image Description', 'responsive-lightbox' )
122 );
123
124 $this->loading_places = array(
125 'header' => __( 'Header', 'responsive-lightbox' ),
126 'footer' => __( 'Footer', 'responsive-lightbox' )
127 );
128
129 // get scripts
130 foreach ( $this->scripts as $key => $value ) {
131 $scripts[$key] = $value['name'];
132 }
133
134 // get image sizes
135 $sizes = apply_filters( 'image_size_names_choose', array(
136 'thumbnail' => __( 'Thumbnail', 'responsive-lightbox' ),
137 'medium' => __( 'Medium', 'responsive-lightbox' ),
138 'large' => __( 'Large', 'responsive-lightbox' ),
139 'full' => __( 'Full Size (default)', 'responsive-lightbox' ),
140 ) );
141
142 $this->settings = array(
143 'settings' => array(
144 'option_group' => 'responsive_lightbox_settings',
145 'option_name' => 'responsive_lightbox_settings',
146 // 'callback' => array( $this, 'validate_options' ),
147 'sections' => array(
148 'responsive_lightbox_settings' => array(
149 'title' => __( 'General settings', 'responsive-lightbox' ),
150 // 'callback' => '',
151 // 'page' => '',
152 ),
153 ),
154 'prefix' => 'rl',
155 'fields' => array(
156 'script' => array(
157 // 'name' => '',
158 'title' => __( 'Default lightbox', 'responsive-lightbox' ),
159 // 'callback' => '',
160 // 'page' => '',
161 'section' => 'responsive_lightbox_settings',
162 'type' => 'radio',
163 'label' => '',
164 'description' => sprintf(__( 'Select your preffered ligthbox effect script or get our <a href="%s">premium extensions</a>.', 'responsive-lightbox' ), wp_nonce_url( add_query_arg( array( 'action' => 'rl-hide-notice' ), admin_url( 'options-general.php?page=responsive-lightbox&tab=addons' ) ), 'rl_action', 'rl_nonce' ) ),
165 'options' => $scripts,
166 // 'options_cb' => '',
167 // 'id' => '',
168 // 'class' => array(),
169 ),
170 'selector' => array(
171 'title' => __( 'Selector', 'responsive-lightbox' ),
172 'section' => 'responsive_lightbox_settings',
173 'type' => 'text',
174 'description' => __( 'Enter the rel selector lightbox effect will be applied to.', 'responsive-lightbox' ),
175 ),
176 'image_links' => array(
177 'title' => __( 'Images', 'responsive-lightbox' ),
178 'section' => 'responsive_lightbox_settings',
179 'type' => 'boolean',
180 'label' => __( 'Enable lightbox for WordPress image links.', 'responsive-lightbox' ),
181 ),
182 'image_title' => array(
183 'title' => __( 'Single image title', 'responsive-lightbox' ),
184 'section' => 'responsive_lightbox_settings',
185 'type' => 'select',
186 'description' => __( 'Select title for single images.', 'responsive-lightbox' ),
187 'options' => $this->image_titles,
188 ),
189 'images_as_gallery' => array(
190 'title' => __( 'Single images as gallery', 'responsive-lightbox' ),
191 'section' => 'responsive_lightbox_settings',
192 'type' => 'boolean',
193 'label' => __( 'Display single post images as a gallery.', 'responsive-lightbox' ),
194 ),
195 'galleries' => array(
196 'title' => __( 'Galleries', 'responsive-lightbox' ),
197 'section' => 'responsive_lightbox_settings',
198 'type' => 'boolean',
199 'label' => __( 'Enable lightbox foor WordPress image galleries.', 'responsive-lightbox' ),
200 ),
201 'gallery_image_size' => array(
202 'title' => __( 'Gallery image size', 'responsive-lightbox' ),
203 'section' => 'responsive_lightbox_settings',
204 'type' => 'select',
205 'description' => __( 'Select image size for gallery image links.', 'responsive-lightbox' ),
206 'options' => $sizes,
207 ),
208 'gallery_image_title' => array(
209 'title' => __( 'Gallery image title', 'responsive-lightbox' ),
210 'section' => 'responsive_lightbox_settings',
211 'type' => 'select',
212 'description' => __( 'Select title for images in native WordPress galleries.', 'responsive-lightbox' ),
213 'options' => $this->image_titles,
214 ),
215 'videos' => array(
216 'title' => __( 'Videos', 'responsive-lightbox' ),
217 'section' => 'responsive_lightbox_settings',
218 'type' => 'boolean',
219 'label' => __( 'Enable lightbox for YouTube and Vimeo video links.', 'responsive-lightbox' ),
220 ),
221 'widgets' => array(
222 'title' => __( 'Widgets', 'responsive-lightbox' ),
223 'section' => 'responsive_lightbox_settings',
224 'type' => 'boolean',
225 'label' => __( 'Enable lightbox for widgets content.', 'responsive-lightbox' ),
226 ),
227 'comments' => array(
228 'title' => __( 'Comments', 'responsive-lightbox' ),
229 'section' => 'responsive_lightbox_settings',
230 'type' => 'boolean',
231 'label' => __( 'Enable lightbox for comments content.', 'responsive-lightbox' ),
232 ),
233 'force_custom_gallery' => array(
234 'title' => __( 'Force lightbox', 'responsive-lightbox' ),
235 'section' => 'responsive_lightbox_settings',
236 'type' => 'boolean',
237 'label' => __( 'Try to force lightbox for custom WP gallery replacements, like Jetpack or Visual Composer galleries.', 'responsive-lightbox' ),
238 ),
239 'woocommerce_gallery_lightbox' => array(
240 'title' => __( 'WooCommerce lightbox', 'responsive-lightbox' ),
241 'section' => 'responsive_lightbox_settings',
242 'type' => 'boolean',
243 'label' => __( 'Replace WooCommerce product gallery lightbox.', 'responsive-lightbox' ),
244 'disabled' => ! class_exists( 'WooCommerce' )
245 ),
246 'enable_custom_events' => array(
247 'title' => __( 'Custom events', 'responsive-lightbox' ),
248 'section' => 'responsive_lightbox_settings',
249 'type' => 'multiple',
250 'fields' => array(
251 'enable_custom_events' => array(
252 'type' => 'boolean',
253 'label' => __( 'Enable triggering lightbox on custom jQuery events.', 'responsive-lightbox' ),
254 ),
255 'custom_events' => array(
256 'type' => 'text',
257 'description' => __( 'Enter a space separated list of events.', 'responsive-lightbox' ),
258 )
259 ),
260 ),
261 'loading_place' => array(
262 'title' => __( 'Loading place', 'responsive-lightbox' ),
263 'section' => 'responsive_lightbox_settings',
264 'type' => 'radio',
265 'description' => __( 'Select where all the lightbox scripts should be placed.', 'responsive-lightbox' ),
266 'options' => $this->loading_places,
267 ),
268 'conditional_loading' => array(
269 'title' => __( 'Conditional loading', 'responsive-lightbox' ),
270 'section' => 'responsive_lightbox_settings',
271 'type' => 'boolean',
272 'label' => __( 'Enable to load scripts and styles only on pages that have images or galleries in post content.', 'responsive-lightbox' ),
273 ),
274 'deactivation_delete' => array(
275 'title' => __( 'Delete data', 'responsive-lightbox' ),
276 'section' => 'responsive_lightbox_settings',
277 'type' => 'boolean',
278 'label' => __( 'Delete all plugin settings on deactivation.', 'responsive-lightbox' ),
279 ),
280 ),
281 ),
282 'configuration' => array(
283 'option_group' => 'responsive_lightbox_configuration',
284 'option_name' => 'responsive_lightbox_configuration',
285 // 'callback' => array( $this, 'validate_options' ),
286 'sections' => array(
287 'responsive_lightbox_configuration' => array(
288 'title' => sprintf( __( '%s settings', 'responsive-lightbox' ), ( isset( $this->scripts[Responsive_Lightbox()->options['settings']['script']]['name'] ) ? $this->scripts[Responsive_Lightbox()->options['settings']['script']]['name'] : $this->scripts[Responsive_Lightbox()->defaults['settings']['script']]['name'] ) ),
289 // 'callback' => '',
290 // 'page' => ''
291 ),
292 ),
293 'prefix' => 'rl',
294 'fields' => array(
295 )
296 )
297 );
298
299 $this->tabs = apply_filters( 'rl_settings_tabs', array(
300 'settings' => array(
301 'name' => __( 'General', 'responsive-lightbox' ),
302 'key' => 'responsive_lightbox_settings',
303 'submit' => 'save_rl_settings',
304 'reset' => 'reset_rl_settings',
305 ),
306 'configuration' => array(
307 'name' => __( 'Lightbox', 'responsive-lightbox' ),
308 'key' => 'responsive_lightbox_configuration',
309 'submit' => 'save_' . $this->settings['configuration']['prefix'] . '_configuration',
310 'reset' => 'reset_' . $this->settings['configuration']['prefix'] . '_configuration',
311 'sections' => $scripts,
312 'default_section' => Responsive_Lightbox()->options['settings']['script']
313 )
314 ) );
315
316 $tabs_copy = $this->tabs;
317 $tab_key = '';
318 $section_key = '';
319
320 // set current tab and section
321 if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
322 global $pagenow;
323
324 if ( $pagenow == 'options-general.php' || $pagenow == 'options.php' ) {
325 $tab_key = isset( $_GET['tab'] ) ? $_GET['tab'] : 'settings';
326 $section_key = isset( $_REQUEST['section'] ) ? esc_attr( $_REQUEST['section'] ) : ( ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '' );
327 }
328 }
329
330 // get available galleries
331 $gallery_types = apply_filters( 'rl_gallery_types', array() );
332
333 if ( $gallery_types ) {
334 foreach ( $gallery_types as $key => $name ) {
335 unset( $gallery_types[$key] );
336 $gallery_types[$key . '_gallery'] = $name;
337 }
338 }
339
340 // backward compatibility, remove from tabs
341 $gallery_tabs = array_intersect( array_keys( $this->tabs ), array_keys( $gallery_types ) );
342 $galleries = array();
343
344 if ( ! empty( $gallery_tabs ) ) {
345 // unset tabs if exist
346 foreach ( $gallery_tabs as $gallery_tab ) {
347 $galleries[$gallery_tab] = $this->tabs[$gallery_tab];
348 unset( $this->tabs[$gallery_tab] );
349 }
350
351 foreach ( $galleries as $key => $gallery ) {
352 $gallery_sections[$key] = $gallery['name'];
353 }
354
355 if ( $tab_key == 'gallery' ) {
356 $section_key = isset( $_REQUEST['section'] ) ? esc_attr( $_REQUEST['section'] ) : ( in_array( Responsive_Lightbox()->options['settings']['default_gallery'], array_keys( $gallery_sections ) ) ? Responsive_Lightbox()->options['settings']['default_gallery'] : key( $gallery_sections ) );
357 }
358
359 $this->tabs['gallery'] = array(
360 'name' => __( 'Gallery', 'responsive-lightbox' ),
361 'key' => 'responsive_lightbox_' . $section_key,
362 'submit' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['submit'] : 'save_' . $section_key . '_configuration',
363 'reset' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['reset'] : 'reset_rl_' . $section_key,
364 'sections' => $gallery_sections,
365 'default_section' => $section_key
366 );
367 }
368
369 // push licenses just beofre the addons
370 if ( isset( $this->tabs['licenses'] ) ) {
371 unset( $this->tabs['licenses'] );
372
373 $this->tabs['licenses'] = array(
374 'name' => __( 'Licenses', 'responsive-lightbox' ),
375 'key' => 'responsive_lightbox_licenses',
376 'submit' => 'save_rl_licenses',
377 'reset' => 'reset_rl_licenses',
378 );
379 }
380
381 $this->tabs['addons'] = array(
382 'name' => __( 'Add-ons', 'responsive-lightbox' ),
383 'key' => 'responsive_lightbox_configuration',
384 'callback' => array( $this, 'addons_tab_cb' )
385 );
386
387 if ( ! empty( $this->tabs[$tab_key]['sections'] ) && isset( $this->tabs[$tab_key]['sections'][$section_key] ) ) {
388 $this->settings[$tab_key]['sections']['responsive_lightbox_' . $tab_key]['title'] = sprintf( __( '%s settings', 'responsive-lightbox' ), $this->tabs[$tab_key]['sections'][$section_key] );
389 }
390
391 switch ( ! empty( $section_key ) ? $section_key : Responsive_Lightbox()->options['settings']['script'] ) {
392
393 case ( 'swipebox' ) :
394
395 $this->settings['configuration']['prefix'] = 'rl_sb';
396 $this->settings['configuration']['fields'] = array(
397 'animation' => array(
398 'title' => __( 'Animation type', 'responsive-lightbox' ),
399 'section' => 'responsive_lightbox_configuration',
400 'type' => 'radio',
401 'label' => '',
402 'description' => __( 'Select a method of applying a lightbox effect.', 'responsive-lightbox' ),
403 'options' => $this->scripts['swipebox']['animations'],
404 'parent' => 'swipebox'
405 ),
406 'force_png_icons' => array(
407 'title' => __( 'Force PNG icons', 'responsive-lightbox' ),
408 'section' => 'responsive_lightbox_configuration',
409 'type' => 'boolean',
410 'label' => __( 'Enable this if you\'re having problems with navigation icons not visible on some devices.', 'responsive-lightbox' ),
411 'parent' => 'swipebox'
412 ),
413 'hide_close_mobile' => array(
414 'title' => __( 'Hide close on mobile', 'responsive-lightbox' ),
415 'section' => 'responsive_lightbox_configuration',
416 'type' => 'boolean',
417 'label' => __( 'Hide the close button on mobile devices.', 'responsive-lightbox' ),
418 'parent' => 'swipebox'
419 ),
420 'remove_bars_mobile' => array(
421 'title' => __( 'Remove bars on mobile', 'responsive-lightbox' ),
422 'section' => 'responsive_lightbox_configuration',
423 'type' => 'boolean',
424 'label' => __( 'Hide the top and bottom bars on mobile devices.', 'responsive-lightbox' ),
425 'parent' => 'swipebox'
426 ),
427 'hide_bars' => array(
428 'title' => __( 'Top and bottom bars', 'responsive-lightbox' ),
429 'section' => 'responsive_lightbox_configuration',
430 'type' => 'multiple',
431 'fields' => array(
432 'hide_bars' => array(
433 'type' => 'boolean',
434 'label' => __( 'Hide top and bottom bars after a period of time.', 'responsive-lightbox' ),
435 'parent' => 'swipebox'
436 ),
437 'hide_bars_delay' => array(
438 'type' => 'number',
439 'description' => __( 'Enter the time after which the top and bottom bars will be hidden (when hiding is enabled).', 'responsive-lightbox' ),
440 'append' => 'ms',
441 'parent' => 'swipebox'
442 )
443 )
444 ),
445 'video_max_width' => array(
446 'title' => __( 'Video max width', 'responsive-lightbox' ),
447 'section' => 'responsive_lightbox_configuration',
448 'type' => 'number',
449 'description' => __( 'Enter the max video width in a lightbox.', 'responsive-lightbox' ),
450 'append' => 'px',
451 'parent' => 'swipebox'
452 ),
453 'loop_at_end' => array(
454 'title' => __( 'Loop at end', 'responsive-lightbox' ),
455 'section' => 'responsive_lightbox_configuration',
456 'type' => 'boolean',
457 'label' => __( 'True will return to the first image after the last image is reached.', 'responsive-lightbox' ),
458 'parent' => 'swipebox'
459 ),
460 );
461
462 break;
463
464 case ( 'prettyphoto' ) :
465
466 $this->settings['configuration']['prefix'] = 'rl_pp';
467 $this->settings['configuration']['fields'] = array(
468 'animation_speed' => array(
469 'title' => __( 'Animation speed', 'responsive-lightbox' ),
470 'section' => 'responsive_lightbox_configuration',
471 'type' => 'radio',
472 'label' => '',
473 'description' => __( 'Select animation speed for lightbox effect.', 'responsive-lightbox' ),
474 'options' => $this->scripts['prettyphoto']['animation_speeds'],
475 'parent' => 'prettyphoto'
476 ),
477 'slideshow' => array(
478 'title' => __( 'Slideshow', 'responsive-lightbox' ),
479 'section' => 'responsive_lightbox_configuration',
480 'type' => 'multiple',
481 'fields' => array(
482 'slideshow' => array(
483 'type' => 'boolean',
484 'label' => __( 'Display images as slideshow', 'responsive-lightbox' ),
485 'parent' => 'prettyphoto'
486 ),
487 'slideshow_delay' => array(
488 'type' => 'number',
489 'description' => __( 'Enter time (in miliseconds).', 'responsive-lightbox' ),
490 'append' => 'ms',
491 'parent' => 'prettyphoto'
492 )
493 )
494 ),
495 'slideshow_autoplay' => array(
496 'title' => __( 'Slideshow autoplay', 'responsive-lightbox' ),
497 'section' => 'responsive_lightbox_configuration',
498 'type' => 'boolean',
499 'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
500 'parent' => 'prettyphoto'
501 ),
502 'opacity' => array(
503 'title' => __( 'Opacity', 'responsive-lightbox' ),
504 'section' => 'responsive_lightbox_configuration',
505 'type' => 'range',
506 'description' => __( 'Value between 0 and 100, 100 for no opacity.', 'responsive-lightbox' ),
507 'min' => 0,
508 'max' => 100,
509 'parent' => 'prettyphoto'
510 ),
511 'show_title' => array(
512 'title' => __( 'Show title', 'responsive-lightbox' ),
513 'section' => 'responsive_lightbox_configuration',
514 'type' => 'boolean',
515 'label' => __( 'Display image title.', 'responsive-lightbox' ),
516 'parent' => 'prettyphoto'
517 ),
518 'allow_resize' => array(
519 'title' => __( 'Allow resize big images', 'responsive-lightbox' ),
520 'section' => 'responsive_lightbox_configuration',
521 'type' => 'boolean',
522 'label' => __( 'Resize the photos bigger than viewport.', 'responsive-lightbox' ),
523 'parent' => 'prettyphoto'
524 ),
525 'allow_expand' => array(
526 'title' => __( 'Allow expand', 'responsive-lightbox' ),
527 'section' => 'responsive_lightbox_configuration',
528 'type' => 'boolean',
529 'label' => __( 'Allow expanding images.', 'responsive-lightbox' ),
530 'parent' => 'prettyphoto'
531 ),
532 'width' => array(
533 'title' => __( 'Video width', 'responsive-lightbox' ),
534 'section' => 'responsive_lightbox_configuration',
535 'type' => 'number',
536 'append' => 'px',
537 'parent' => 'prettyphoto'
538 ),
539 'height' => array(
540 'title' => __( 'Video height', 'responsive-lightbox' ),
541 'section' => 'responsive_lightbox_configuration',
542 'type' => 'number',
543 'append' => 'px',
544 'parent' => 'prettyphoto'
545 ),
546 'theme' => array(
547 'title' => __( 'Theme', 'responsive-lightbox' ),
548 'section' => 'responsive_lightbox_configuration',
549 'type' => 'radio',
550 'description' => __( 'Select the theme for lightbox effect.', 'responsive-lightbox' ),
551 'options' => $this->scripts['prettyphoto']['themes'],
552 'parent' => 'prettyphoto'
553 ),
554 'horizontal_padding' => array(
555 'title' => __( 'Horizontal padding', 'responsive-lightbox' ),
556 'section' => 'responsive_lightbox_configuration',
557 'type' => 'number',
558 'append' => 'px',
559 'parent' => 'prettyphoto'
560 ),
561 'hide_flash' => array(
562 'title' => __( 'Hide Flash', 'responsive-lightbox' ),
563 'section' => 'responsive_lightbox_configuration',
564 'type' => 'boolean',
565 'label' => __( 'Hide all the flash objects on a page. Enable this if flash appears over prettyPhoto.', 'responsive-lightbox' ),
566 'parent' => 'prettyphoto'
567 ),
568 'wmode' => array(
569 'title' => __( 'Flash Window Mode (wmode)', 'responsive-lightbox' ),
570 'section' => 'responsive_lightbox_configuration',
571 'type' => 'radio',
572 'description' => __( 'Select flash window mode.', 'responsive-lightbox' ),
573 'options' => $this->scripts['prettyphoto']['wmodes'],
574 'parent' => 'prettyphoto'
575 ),
576 'video_autoplay' => array(
577 'title' => __( 'Video autoplay', 'responsive-lightbox' ),
578 'section' => 'responsive_lightbox_configuration',
579 'type' => 'boolean',
580 'label' => __( 'Automatically start videos.', 'responsive-lightbox' ),
581 'parent' => 'prettyphoto'
582 ),
583 'modal' => array(
584 'title' => __( 'Modal', 'responsive-lightbox' ),
585 'section' => 'responsive_lightbox_configuration',
586 'type' => 'boolean',
587 'label' => __( 'If set to true, only the close button will close the window.', 'responsive-lightbox' ),
588 'parent' => 'prettyphoto'
589 ),
590 'deeplinking' => array(
591 'title' => __( 'Deeplinking', 'responsive-lightbox' ),
592 'section' => 'responsive_lightbox_configuration',
593 'type' => 'boolean',
594 'label' => __( 'Allow prettyPhoto to update the url to enable deeplinking.', 'responsive-lightbox' ),
595 'parent' => 'prettyphoto'
596 ),
597 'overlay_gallery' => array(
598 'title' => __( 'Overlay gallery', 'responsive-lightbox' ),
599 'section' => 'responsive_lightbox_configuration',
600 'type' => 'boolean',
601 'label' => __( 'If enabled, a gallery will overlay the fullscreen image on mouse over.', 'responsive-lightbox' ),
602 'parent' => 'prettyphoto'
603 ),
604 'keyboard_shortcuts' => array(
605 'title' => __( 'Keyboard shortcuts', 'responsive-lightbox' ),
606 'section' => 'responsive_lightbox_configuration',
607 'type' => 'boolean',
608 'label' => __( 'Set to false if you open forms inside prettyPhoto.', 'responsive-lightbox' ),
609 'parent' => 'prettyphoto'
610 ),
611 'social' => array(
612 'title' => __( 'Social (Twitter, Facebook)', 'responsive-lightbox' ),
613 'section' => 'responsive_lightbox_configuration',
614 'type' => 'boolean',
615 'label' => __( 'Display links to Facebook and Twitter.', 'responsive-lightbox' ),
616 'parent' => 'prettyphoto'
617 ),
618 );
619
620 break;
621
622 case ( 'fancybox' ) :
623
624 $this->settings['configuration']['prefix'] = 'rl_fb';
625 $this->settings['configuration']['fields'] = array(
626 'modal' => array(
627 'title' => __( 'Modal', 'responsive-lightbox' ),
628 'section' => 'responsive_lightbox_configuration',
629 'type' => 'boolean',
630 'label' => __( 'When true, "overlayShow" is set to true and "hideOnOverlayClick", "hideOnContentClick", "enableEscapeButton", "showCloseButton" are set to false.', 'responsive-lightbox' ),
631 'parent' => 'fancybox'
632 ),
633 'show_overlay' => array(
634 'title' => __( 'Show overlay', 'responsive-lightbox' ),
635 'section' => 'responsive_lightbox_configuration',
636 'type' => 'boolean',
637 'label' => __( 'Toggle overlay.', 'responsive-lightbox' ),
638 'parent' => 'fancybox'
639 ),
640 'show_close_button' => array(
641 'title' => __( 'Show close button', 'responsive-lightbox' ),
642 'section' => 'responsive_lightbox_configuration',
643 'type' => 'boolean',
644 'label' => __( 'Toggle close button.', 'responsive-lightbox' ),
645 'parent' => 'fancybox'
646 ),
647 'enable_escape_button' => array(
648 'title' => __( 'Enable escape button', 'responsive-lightbox' ),
649 'section' => 'responsive_lightbox_configuration',
650 'type' => 'boolean',
651 'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
652 'parent' => 'fancybox'
653 ),
654 'hide_on_overlay_click' => array(
655 'title' => __( 'Hide on overlay click', 'responsive-lightbox' ),
656 'section' => 'responsive_lightbox_configuration',
657 'type' => 'boolean',
658 'label' => __( 'Toggle if clicking the overlay should close FancyBox.', 'responsive-lightbox' ),
659 'parent' => 'fancybox'
660 ),
661 'hide_on_content_click' => array(
662 'title' => __( 'Hide on content click', 'responsive-lightbox' ),
663 'section' => 'responsive_lightbox_configuration',
664 'type' => 'boolean',
665 'label' => __( 'Toggle if clicking the content should close FancyBox.', 'responsive-lightbox' ),
666 'parent' => 'fancybox'
667 ),
668 'cyclic' => array(
669 'title' => __( 'Cyclic', 'responsive-lightbox' ),
670 'section' => 'responsive_lightbox_configuration',
671 'type' => 'boolean',
672 'label' => __( 'When true, galleries will be cyclic, allowing you to keep pressing next/back.', 'responsive-lightbox' ),
673 'parent' => 'fancybox'
674 ),
675 'show_nav_arrows' => array(
676 'title' => __( 'Show nav arrows', 'responsive-lightbox' ),
677 'section' => 'responsive_lightbox_configuration',
678 'type' => 'boolean',
679 'label' => __( 'Toggle navigation arrows.', 'responsive-lightbox' ),
680 'parent' => 'fancybox'
681 ),
682 'auto_scale' => array(
683 'title' => __( 'Auto scale', 'responsive-lightbox' ),
684 'section' => 'responsive_lightbox_configuration',
685 'type' => 'boolean',
686 'label' => __( 'If true, FancyBox is scaled to fit in viewport.', 'responsive-lightbox' ),
687 'parent' => 'fancybox'
688 ),
689 'scrolling' => array(
690 'title' => __( 'Scrolling (in/out)', 'responsive-lightbox' ),
691 'section' => 'responsive_lightbox_configuration',
692 'type' => 'radio',
693 'description' => __( 'Set the overflow CSS property to create or hide scrollbars.', 'responsive-lightbox' ),
694 'options' => $this->scripts['fancybox']['scrollings'],
695 'parent' => 'fancybox'
696 ),
697 'center_on_scroll' => array(
698 'title' => __( 'Center on scroll', 'responsive-lightbox' ),
699 'section' => 'responsive_lightbox_configuration',
700 'type' => 'boolean',
701 'label' => __( 'When true, FancyBox is centered while scrolling page.', 'responsive-lightbox' ),
702 'parent' => 'fancybox'
703 ),
704 'opacity' => array(
705 'title' => __( 'Opacity', 'responsive-lightbox' ),
706 'section' => 'responsive_lightbox_configuration',
707 'type' => 'boolean',
708 'label' => __( 'When true, transparency of content is changed for elastic transitions.', 'responsive-lightbox' ),
709 'parent' => 'fancybox'
710 ),
711 'overlay_opacity' => array(
712 'title' => __( 'Overlay opacity', 'responsive-lightbox' ),
713 'section' => 'responsive_lightbox_configuration',
714 'type' => 'range',
715 'description' => __( 'Opacity of the overlay.', 'responsive-lightbox' ),
716 'min' => 0,
717 'max' => 100,
718 'parent' => 'fancybox'
719 ),
720 'overlay_color' => array(
721 'title' => __( 'Overlay color', 'responsive-lightbox' ),
722 'section' => 'responsive_lightbox_configuration',
723 'type' => 'color_picker',
724 'label' => __( 'Color of the overlay.', 'responsive-lightbox' ),
725 'parent' => 'fancybox'
726 ),
727 'title_show' => array(
728 'title' => __( 'Title show', 'responsive-lightbox' ),
729 'section' => 'responsive_lightbox_configuration',
730 'type' => 'boolean',
731 'label' => __( 'Toggle title.', 'responsive-lightbox' ),
732 'parent' => 'fancybox'
733 ),
734 'title_position' => array(
735 'title' => __( 'Title position', 'responsive-lightbox' ),
736 'section' => 'responsive_lightbox_configuration',
737 'type' => 'radio',
738 'description' => __( 'The position of title.', 'responsive-lightbox' ),
739 'options' => $this->scripts['fancybox']['positions'],
740 'parent' => 'fancybox'
741 ),
742 'transitions' => array(
743 'title' => __( 'Transition (in/out)', 'responsive-lightbox' ),
744 'section' => 'responsive_lightbox_configuration',
745 'type' => 'radio',
746 'description' => __( 'The transition type.', 'responsive-lightbox' ),
747 'options' => $this->scripts['fancybox']['transitions'],
748 'parent' => 'fancybox'
749 ),
750 'easings' => array(
751 'title' => __( 'Easings (in/out)', 'responsive-lightbox' ),
752 'section' => 'responsive_lightbox_configuration',
753 'type' => 'radio',
754 'description' => __( 'Easing used for elastic animations.', 'responsive-lightbox' ),
755 'options' => $this->scripts['fancybox']['easings'],
756 'parent' => 'fancybox'
757 ),
758 'speeds' => array(
759 'title' => __( 'Speed (in/out)', 'responsive-lightbox' ),
760 'section' => 'responsive_lightbox_configuration',
761 'type' => 'number',
762 'description' => __( 'Speed of the fade and elastic transitions, in milliseconds.', 'responsive-lightbox' ),
763 'append' => 'ms',
764 'parent' => 'fancybox'
765 ),
766 'change_speed' => array(
767 'title' => __( 'Change speed', 'responsive-lightbox' ),
768 'section' => 'responsive_lightbox_configuration',
769 'type' => 'number',
770 'description' => __( 'Speed of resizing when changing gallery items, in milliseconds.', 'responsive-lightbox' ),
771 'append' => 'ms',
772 'parent' => 'fancybox'
773 ),
774 'change_fade' => array(
775 'title' => __( 'Change fade', 'responsive-lightbox' ),
776 'section' => 'responsive_lightbox_configuration',
777 'type' => 'number',
778 'description' => __( 'Speed of the content fading while changing gallery items.', 'responsive-lightbox' ),
779 'append' => 'ms',
780 'parent' => 'fancybox'
781 ),
782 'padding' => array(
783 'title' => __( 'Padding', 'responsive-lightbox' ),
784 'section' => 'responsive_lightbox_configuration',
785 'type' => 'number',
786 'description' => __( 'Space between FancyBox wrapper and content.', 'responsive-lightbox' ),
787 'append' => 'px',
788 'parent' => 'fancybox'
789 ),
790 'margin' => array(
791 'title' => __( 'Margin', 'responsive-lightbox' ),
792 'section' => 'responsive_lightbox_configuration',
793 'type' => 'number',
794 'description' => __( 'Space between viewport and FancyBox wrapper.', 'responsive-lightbox' ),
795 'append' => 'px',
796 'parent' => 'fancybox'
797 ),
798 'video_width' => array(
799 'title' => __( 'Video width', 'responsive-lightbox' ),
800 'section' => 'responsive_lightbox_configuration',
801 'type' => 'number',
802 'description' => __( 'Width of the video.', 'responsive-lightbox' ),
803 'append' => 'px',
804 'parent' => 'fancybox'
805 ),
806 'video_height' => array(
807 'title' => __( 'Video height', 'responsive-lightbox' ),
808 'section' => 'responsive_lightbox_configuration',
809 'type' => 'number',
810 'description' => __( 'Height of the video.', 'responsive-lightbox' ),
811 'append' => 'px',
812 'parent' => 'fancybox'
813 ),
814 );
815
816 break;
817
818 case ( 'nivo' ) :
819
820 $this->settings['configuration']['prefix'] = 'rl_nv';
821 $this->settings['configuration']['fields'] = array(
822 'effect' => array(
823 'title' => __( 'Effect', 'responsive-lightbox' ),
824 'section' => 'responsive_lightbox_configuration',
825 'type' => 'radio',
826 'description' => __( 'The effect to use when showing the lightbox.', 'responsive-lightbox' ),
827 'options' => $this->scripts['nivo']['effects'],
828 'parent' => 'nivo'
829 ),
830 'keyboard_nav' => array(
831 'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
832 'section' => 'responsive_lightbox_configuration',
833 'type' => 'boolean',
834 'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
835 'parent' => 'nivo'
836 ),
837 'click_overlay_to_close' => array(
838 'title' => __( 'Click overlay to close', 'responsive-lightbox' ),
839 'section' => 'responsive_lightbox_configuration',
840 'type' => 'boolean',
841 'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
842 'parent' => 'nivo'
843 ),
844 'error_message' => array(
845 'title' => __( 'Error message', 'responsive-lightbox' ),
846 'section' => 'responsive_lightbox_configuration',
847 'type' => 'text',
848 'class' => 'large-text',
849 'label' => __( 'Error message if the content cannot be loaded.', 'responsive-lightbox' ),
850 'parent' => 'nivo'
851 ),
852 );
853
854 break;
855
856 case ( 'imagelightbox' ) :
857
858 $this->settings['configuration']['prefix'] = 'rl_il';
859 $this->settings['configuration']['fields'] = array(
860 'animation_speed' => array(
861 'title' => __( 'Animation speed', 'responsive-lightbox' ),
862 'section' => 'responsive_lightbox_configuration',
863 'type' => 'number',
864 'description' => __( 'Animation speed.', 'responsive-lightbox' ),
865 'append' => 'ms',
866 'parent' => 'imagelightbox'
867 ),
868 'preload_next' => array(
869 'title' => __( 'Preload next image', 'responsive-lightbox' ),
870 'section' => 'responsive_lightbox_configuration',
871 'type' => 'boolean',
872 'label' => __( 'Silently preload the next image.', 'responsive-lightbox' ),
873 'parent' => 'imagelightbox'
874 ),
875 'enable_keyboard' => array(
876 'title' => __( 'Enable keyboard keys', 'responsive-lightbox' ),
877 'section' => 'responsive_lightbox_configuration',
878 'type' => 'boolean',
879 'label' => __( 'Enable keyboard shortcuts (arrows Left/Right and Esc).', 'responsive-lightbox' ),
880 'parent' => 'imagelightbox'
881 ),
882 'quit_on_end' => array(
883 'title' => __( 'Quit after last image', 'responsive-lightbox' ),
884 'section' => 'responsive_lightbox_configuration',
885 'type' => 'boolean',
886 'label' => __( 'Quit after viewing the last image.', 'responsive-lightbox' ),
887 'parent' => 'imagelightbox'
888 ),
889 'quit_on_image_click' => array(
890 'title' => __( 'Quit on image click', 'responsive-lightbox' ),
891 'section' => 'responsive_lightbox_configuration',
892 'type' => 'boolean',
893 'label' => __( 'Quit when the viewed image is clicked.', 'responsive-lightbox' ),
894 'parent' => 'imagelightbox'
895 ),
896 'quit_on_document_click' => array(
897 'title' => __( 'Quit on anything click', 'responsive-lightbox' ),
898 'section' => 'responsive_lightbox_configuration',
899 'type' => 'boolean',
900 'label' => __( 'Quit when anything but the viewed image is clicked.', 'responsive-lightbox' ),
901 'parent' => 'imagelightbox'
902 ),
903 );
904
905 break;
906
907 case ( 'tosrus' ) :
908
909 $this->settings['configuration']['prefix'] = 'rl_tr';
910 $this->settings['configuration']['fields'] = array(
911 'effect' => array(
912 'title' => __( 'Transition effect', 'responsive-lightbox' ),
913 'section' => 'responsive_lightbox_configuration',
914 'type' => 'radio',
915 'description' => __( 'What effect to use for the transition.', 'responsive-lightbox' ),
916 'options' => array(
917 'slide' => __( 'slide', 'responsive-lightbox' ),
918 'fade' => __( 'fade', 'responsive-lightbox' )
919 ),
920 'parent' => 'tosrus'
921 ),
922 'infinite' => array(
923 'title' => __( 'Infinite loop', 'responsive-lightbox' ),
924 'section' => 'responsive_lightbox_configuration',
925 'type' => 'boolean',
926 'label' => __( 'Whether or not to slide back to the first slide when the last has been reached.', 'responsive-lightbox' ),
927 'parent' => 'tosrus'
928 ),
929 'keys' => array(
930 'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
931 'section' => 'responsive_lightbox_configuration',
932 'type' => 'boolean',
933 'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
934 'parent' => 'tosrus'
935 ),
936 'autoplay' => array(
937 'title' => __( 'Autoplay', 'responsive-lightbox' ),
938 'section' => 'responsive_lightbox_configuration',
939 'type' => 'multiple',
940 'fields' => array(
941 'autoplay' => array(
942 'type' => 'boolean',
943 'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
944 'parent' => 'tosrus'
945 ),
946 'timeout' => array(
947 'type' => 'number',
948 'description' => __( 'The timeout between sliding to the next slide in milliseconds.', 'responsive-lightbox' ),
949 'append' => 'ms',
950 'parent' => 'tosrus'
951 )
952 )
953 ),
954 'pause_on_hover' => array(
955 'title' => __( 'Pause on hover', 'responsive-lightbox' ),
956 'section' => 'responsive_lightbox_configuration',
957 'type' => 'boolean',
958 'label' => __( 'Whether or not to pause on hover.', 'responsive-lightbox' ),
959 'parent' => 'tosrus'
960 ),
961 'pagination' => array(
962 'title' => __( 'Pagination', 'responsive-lightbox' ),
963 'section' => 'responsive_lightbox_configuration',
964 'type' => 'multiple',
965 'fields' => array(
966 'pagination' => array(
967 'type' => 'boolean',
968 'label' => __( 'Whether or not to add a pagination.', 'responsive-lightbox' ),
969 'parent' => 'tosrus'
970 ),
971 'pagination_type' => array(
972 'type' => 'radio',
973 'description' => __( 'What type of pagination to use.', 'responsive-lightbox' ),
974 'options' => array(
975 'bullets' => __( 'Bullets', 'responsive-lightbox' ),
976 'thumbnails' => __( 'Thumbnails', 'responsive-lightbox' )
977 ),
978 'parent' => 'tosrus'
979 )
980 )
981 ),
982 'close_on_click' => array(
983 'title' => __( 'Overlay close', 'responsive-lightbox' ),
984 'section' => 'responsive_lightbox_configuration',
985 'type' => 'boolean',
986 'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
987 'parent' => 'tosrus'
988 )
989 );
990
991 break;
992
993 case ( 'featherlight' ) :
994
995 $this->settings['configuration']['prefix'] = 'rl_fl';
996 $this->settings['configuration']['fields'] = array(
997 'open_speed' => array(
998 'title' => __( 'Opening speed', 'responsive-lightbox' ),
999 'section' => 'responsive_lightbox_configuration',
1000 'type' => 'number',
1001 'description' => __( 'Duration of opening animation.', 'responsive-lightbox' ),
1002 'append' => 'ms',
1003 'parent' => 'featherlight'
1004 ),
1005 'close_speed' => array(
1006 'title' => __( 'Closing speed', 'responsive-lightbox' ),
1007 'section' => 'responsive_lightbox_configuration',
1008 'type' => 'number',
1009 'description' => __( 'Duration of closing animation.', 'responsive-lightbox' ),
1010 'append' => 'ms',
1011 'parent' => 'featherlight'
1012 ),
1013 'close_on_click' => array(
1014 'title' => __( 'Close on click', 'responsive-lightbox' ),
1015 'section' => 'responsive_lightbox_configuration',
1016 'type' => 'radio',
1017 'label' => __( 'Select how to close lightbox.', 'responsive-lightbox' ),
1018 'options' => array(
1019 'background' => __( 'background', 'responsive-lightbox' ),
1020 'anywhere' => __( 'anywhere', 'responsive-lightbox' ),
1021 'false' => __( 'false', 'responsive-lightbox' )
1022 ),
1023 'parent' => 'featherlight'
1024 ),
1025 'close_on_esc' => array(
1026 'title' => __( 'Close on Esc', 'responsive-lightbox' ),
1027 'section' => 'responsive_lightbox_configuration',
1028 'type' => 'boolean',
1029 'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
1030 'parent' => 'featherlight'
1031 ),
1032 'gallery_fade_in' => array(
1033 'title' => __( 'Gallery fade in', 'responsive-lightbox' ),
1034 'section' => 'responsive_lightbox_configuration',
1035 'type' => 'number',
1036 'description' => __( 'Animation speed when image is loaded.', 'responsive-lightbox' ),
1037 'append' => 'ms',
1038 'parent' => 'featherlight'
1039 ),
1040 'gallery_fade_out' => array(
1041 'title' => __( 'Gallery fade out', 'responsive-lightbox' ),
1042 'section' => 'responsive_lightbox_configuration',
1043 'type' => 'number',
1044 'description' => __( 'Animation speed before image is loaded.', 'responsive-lightbox' ),
1045 'append' => 'ms',
1046 'parent' => 'featherlight'
1047 )
1048 );
1049
1050 break;
1051
1052 default :
1053
1054 $this->settings['configuration'] = apply_filters( 'rl_settings_' . ( ! empty( $section_key ) ? $section_key : Responsive_Lightbox()->options['settings']['script'] ) . '_script_configuration', $this->settings['configuration'] );
1055
1056 break;
1057 }
1058
1059 if ( isset( $this->tabs[$tab_key]['submit'], $this->tabs[$tab_key]['reset'] ) && ! empty( $this->settings[$tab_key]['prefix'] ) ) {
1060 $this->tabs[$tab_key]['submit'] = 'save_' . $this->settings[$tab_key]['prefix'] . '_' . $tab_key;
1061 $this->tabs[$tab_key]['reset'] = 'reset_' . $this->settings[$tab_key]['prefix'] . '_' . $tab_key;
1062 }
1063
1064 }
1065
1066 /**
1067 * Register options page
1068 *
1069 * @return void
1070 */
1071 public function admin_menu_options() {
1072 add_options_page(
1073 __( 'Responsive Lightbox', 'responsive-lightbox' ), __( 'Responsive Lightbox', 'responsive-lightbox' ), apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ), 'responsive-lightbox', array( $this, 'options_page' )
1074 );
1075 }
1076
1077 /**
1078 * Render options page
1079 *
1080 * @return void
1081 */
1082 public function options_page() {
1083 $tab_key = isset( $_GET['tab'] ) ? $_GET['tab'] : 'settings';
1084 $section_key = isset( $_GET['section'] ) ? $_GET['section'] : ( ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '' );
1085
1086 echo '
1087 <div class="wrap">' . screen_icon() . '
1088 <h2>' . __( 'Responsive Lightbox', 'responsive-lightbox' ) . '</h2>
1089 <h2 class="nav-tab-wrapper">';
1090
1091 foreach ( $this->tabs as $key => $options ) {
1092 echo '
1093 <a class="nav-tab ' . ($tab_key == $key ? 'nav-tab-active' : '') . '" href="' . esc_url( admin_url( 'options-general.php?page=responsive-lightbox&tab=' . $key ) ) . '">' . $options['name'] . '</a>';
1094 }
1095
1096 echo '
1097 </h2>
1098 <div class="responsive-lightbox-settings">
1099
1100 <div class="df-credits">
1101 <h3 class="hndle">' . __( 'Responsive Lightbox', 'responsive-lightbox' ) . ' ' . Responsive_Lightbox()->defaults['version'] . '</h3>
1102 <div class="inside">
1103 <h4 class="inner">' . __( 'Need support?', 'responsive-lightbox' ) . '</h4>
1104 <p class="inner">' . sprintf( __( 'If you are having problems with this plugin, please browse it\'s <a href="%s" target="_blank">Documentation</a> or talk about them in the <a href="%s" target="_blank">Support forum</a>', 'responsive-lightbox' ), 'https://www.dfactory.eu/docs/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=docs', 'https://www.dfactory.eu/support/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=support' ) . '</p>
1105 <hr />
1106 <h4 class="inner">' . __( 'Do you like this plugin?', 'responsive-lightbox' ) . '</h4>
1107 <p class="inner">' . sprintf( __( '<a href="%s" target="_blank">Rate it 5</a> on WordPress.org', 'responsive-lightbox' ), 'https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5' ) . '<br />' .
1108 sprintf( __( 'Blog about it & link to the <a href="%s" target="_blank">plugin page</a>.', 'responsive-lightbox' ), 'https://dfactory.eu/plugins/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=blog-about' ) . '<br />' .
1109 sprintf( __( 'Check out our other <a href="%s" target="_blank">WordPress plugins</a>.', 'responsive-lightbox' ), 'https://dfactory.eu/plugins/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=other-plugins' ) . '
1110 </p>
1111 <hr />
1112 <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>
1113 </div>
1114 </div>
1115
1116 <form action="options.php" method="post">';
1117
1118 // views
1119 if ( ! empty( $this->tabs[$tab_key]['sections'] ) ) {
1120 $views = $this->tabs[$tab_key]['sections'];
1121
1122 echo '<ul class="subsubsub">';
1123
1124 foreach ( $views as $key => $name ) {
1125 $view = '<a href="' . esc_url( admin_url( 'options-general.php?page=responsive-lightbox&tab=' . $tab_key . '&section=' . $key ) ) . '" class="' . ( $key == $section_key ? 'current' : '' ) . '">' . $name . '</a>';
1126 $views[$key] = "\t<li class='$key'>$view";
1127 }
1128
1129 echo implode( " |</li>\n", $views ) . "</li>\n";
1130 echo '</ul><input type="hidden" name="section" value="' . $section_key . '" /><br class="clear">';
1131 }
1132
1133 // tab content callback
1134 if ( ! empty( $this->tabs[$tab_key]['callback'] ) )
1135 call_user_func( $this->tabs[$tab_key]['callback'] );
1136 else {
1137 wp_nonce_field( 'update-options' );
1138 settings_fields( $this->tabs[$tab_key]['key'] );
1139 do_settings_sections( $this->tabs[$tab_key]['key'] );
1140 }
1141
1142 if ( ! empty( $this->tabs[$tab_key]['submit'] ) || ! empty( $this->tabs[$tab_key]['reset'] ) ) {
1143 echo '<p class="submit">';
1144
1145 if ( ! empty( $this->tabs[$tab_key]['submit'] ) ) {
1146 submit_button( '', array( 'primary', 'save-' . $tab_key ), $this->tabs[$tab_key]['submit'], false );
1147 echo ' ';
1148 }
1149
1150 if ( ! empty( $this->tabs[$tab_key]['reset'] ) )
1151 submit_button( __( 'Reset to defaults', 'responsive-lightbox' ), array( 'secondary', 'reset-' . $tab_key ), $this->tabs[$tab_key]['reset'], false );
1152
1153 echo '</p>';
1154 }
1155
1156 echo '
1157 </form>
1158 </div>
1159 <div class="clear"></div>
1160 </div>';
1161 }
1162
1163 /**
1164 * Render settings function
1165 *
1166 * @return void
1167 */
1168 public function register_settings() {
1169
1170 foreach ( $this->settings as $setting_id => $setting ) {
1171
1172 // set key
1173 $setting_key = $setting_id;
1174 $setting_id = 'responsive_lightbox_' . $setting_id;
1175
1176 // register setting
1177 register_setting(
1178 esc_attr( $setting_id ),
1179 ! empty( $setting['option_name'] ) ? esc_attr( $setting['option_name'] ) : $setting_id,
1180 ! empty( $setting['callback'] ) ? $setting['callback'] : array( $this, 'validate_settings' )
1181 );
1182
1183 // register sections
1184 if ( ! empty( $setting['sections'] ) && is_array( $setting['sections'] ) ) {
1185
1186 foreach ( $setting['sections'] as $section_id => $section ) {
1187
1188 add_settings_section(
1189 esc_attr( $section_id ),
1190 ! empty( $section['title'] ) ? esc_html( $section['title'] ) : '',
1191 ! empty( $section['callback'] ) ? $section['callback'] : '',
1192 ! empty( $section['page'] ) ? esc_attr( $section['page'] ) : $section_id
1193 );
1194 }
1195
1196 }
1197
1198 // register fields
1199 if ( ! empty( $setting['fields'] ) && is_array( $setting['fields'] ) ) {
1200
1201 foreach ( $setting['fields'] as $field_id => $field ) {
1202
1203 // prefix field id?
1204 $field_key = $field_id;
1205 $field_id = ( ! empty( $setting['prefix'] ) ? $setting['prefix'] . '_' : '' ) . $field_id;
1206
1207 // field args
1208 $args = array(
1209 'id' => ! empty( $field['id'] ) ? $field['id'] : $field_id,
1210 'class' => ! empty( $field['class'] ) ? $field['class'] : '',
1211 'name' => $setting['option_name'] . ( ! empty( $field['parent'] ) ? '[' . $field['parent'] . ']' : '' ) . '[' . $field_key . ']',
1212 'type' => ! empty( $field['type'] ) ? $field['type'] : 'text',
1213 'label' => ! empty( $field['label'] ) ? $field['label'] : '',
1214 'description' => ! empty( $field['description'] ) ? $field['description'] : '',
1215 'disabled' => isset( $field['disabled'] ) ? (bool) $field['disabled'] : false,
1216 'append' => ! empty( $field['append'] ) ? esc_html( $field['append'] ) : '',
1217 'prepend' => ! empty( $field['prepend'] ) ? esc_html( $field['prepend'] ) : '',
1218 'min' => ! empty( $field['min'] ) ? (int) $field['min'] : '',
1219 'max' => ! empty( $field['max'] ) ? (int) $field['max'] : '',
1220 'options' => ! empty( $field['options'] ) ? $field['options'] : '',
1221 'fields' => ! empty( $field['fields'] ) ? $field['fields'] : '',
1222 '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'] ) ),
1223 'value' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? Responsive_Lightbox()->options[$setting_key][$field['parent']][$field_key] : ( isset( Responsive_Lightbox()->options[$setting_key][$field_key] ) ? Responsive_Lightbox()->options[$setting_key][$field_key] : Responsive_Lightbox()->defaults[$setting_key][$field_key] ), $field['type'] ) ),
1224 'label_for' => $field_id,
1225 'return' => false
1226 );
1227
1228 if ( $args['type'] === 'multiple' ) {
1229 foreach ( $args['fields'] as $subfield_id => $subfield ) {
1230 $args['fields'][$subfield_id] = wp_parse_args( $subfield, array(
1231 'id' => $field_id . '-' . $subfield_id,
1232 'class' => ! empty( $subfield['class'] ) ? $subfield['class'] : '',
1233 'name' => $setting['option_name'] . ( ! empty( $subfield['parent'] ) ? '[' . $subfield['parent'] . ']' : '' ) . '[' . $subfield_id . ']',
1234 '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'] ),
1235 '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'] ),
1236 'return' => true
1237 ) );
1238 }
1239 }
1240
1241 add_settings_field(
1242 esc_attr( $field_id ),
1243 ! empty( $field['title'] ) ? esc_html( $field['title'] ) : '',
1244 array( $this, 'render_field' ),
1245 ! empty( $field['page'] ) ? esc_attr( $field['page'] ) : $setting_id,
1246 ! empty( $field['section'] ) ? esc_attr( $field['section'] ) : '',
1247 $args
1248 );
1249
1250 }
1251
1252 }
1253
1254 }
1255
1256 // licenses
1257 $extensions = apply_filters( 'rl_settings_licenses', array() );
1258
1259 if ( $extensions ) {
1260 // register setting
1261 register_setting(
1262 'responsive_lightbox_licenses',
1263 'responsive_lightbox_licenses',
1264 array( $this, 'validate_licenses' )
1265 );
1266
1267 add_settings_section(
1268 'responsive_lightbox_licenses',
1269 __( 'Licenses', 'responsive-lightbox' ),
1270 array( $this, 'licenses_section_cb' ),
1271 'responsive_lightbox_licenses'
1272 );
1273
1274 foreach ( $extensions as $id => $extension ) {
1275 add_settings_field(
1276 esc_attr( $id ),
1277 $extension['name'],
1278 array( $this, 'license_field_cb' ),
1279 'responsive_lightbox_licenses',
1280 'responsive_lightbox_licenses',
1281 $extension
1282 );
1283 }
1284 }
1285
1286 }
1287
1288 /**
1289 * Render settings field function
1290 *
1291 * @param array $args
1292 * @return mixed
1293 */
1294 public function render_field( $args ) {
1295
1296 if ( empty( $args ) || ! is_array( $args ) )
1297 return;
1298
1299 $html = '';
1300
1301 switch ( $args['type'] ) {
1302
1303 case ( 'boolean' ) :
1304
1305 $html .= '<label class="cb-checkbox"><input id="' . $args['id'] . '" type="checkbox" name="' . $args['name'] . '" value="1" ' . checked( (bool) $args['value'], true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $args['label'] . '</label>';
1306 break;
1307
1308 case ( 'radio' ) :
1309
1310 foreach ( $args['options'] as $key => $name ) {
1311 $html .= '<label class="cb-radio"><input id="' . $args['id'] . '-' . $key . '" type="radio" name="' . $args['name'] . '" value="' . $key . '" ' . checked( $key, $args['value'], false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $name . '</label> ';
1312 }
1313 break;
1314
1315 case ( 'checkbox' ) :
1316
1317 foreach ( $args['options'] as $key => $name ) {
1318 $html .= '<label class="cb-checkbox"><input id="' . $args['id'] . '-' . $key . '" type="checkbox" name="' . $args['name'] . '[' . $key . ']" value="1" ' . checked( in_array( $key, $args['value'] ), true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $name . '</label> ';
1319 }
1320 break;
1321
1322 case ( 'select' ) :
1323
1324 $html .= '<select id="' . $args['id'] . '" name="' . $args['name'] . '" value="' . $args['value'] . '" />';
1325
1326 foreach ( $args['options'] as $key => $name ) {
1327 $html .= '<option value="' . $key . '" ' . selected( $args['value'], $key, false ) . '>' . $name . '</option>';
1328 }
1329
1330 $html .= '</select>';
1331 break;
1332
1333 case ( 'multiple' ) :
1334
1335 $html .= '<fieldset>';
1336
1337 if ( $args['fields'] ) {
1338
1339 $count = 1;
1340 $count_fields = count( $args['fields'] );
1341
1342 foreach ( $args['fields'] as $subfield_id => $subfield_args ) {
1343 $html .= $this->render_field( $subfield_args ) . ( $count < $count_fields ? '<br />' : '' );
1344 $count++;
1345 }
1346
1347 }
1348
1349 $html .= '</fieldset>';
1350 break;
1351
1352 case ( 'range' ) :
1353 $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" />';
1354 $html .= '<output name="' . $args['id'] . '_range">' . esc_attr( Responsive_Lightbox()->options['configuration']['prettyphoto']['opacity'] ) . '</output>';
1355 break;
1356
1357 case ( 'color_picker' ) :
1358 $html .= '<input id="' . $args['id'] . '" class="color-picker" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" data-default-color="' . $args['default'] . '" />';
1359 break;
1360
1361 case ( 'number' ) :
1362 $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
1363 $html .= '<input id="' . $args['id'] . '" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" />';
1364 $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
1365 break;
1366
1367 case ( 'text' ) :
1368 default :
1369 $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
1370 $html .= '<input id="' . $args['id'] . '" class="' . $args['class'] . '" type="text" value="' . $args['value'] . '" name="' . $args['name'] . '" />';
1371 $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
1372 break;
1373
1374 }
1375
1376 if ( ! empty ( $args['description'] ) ) {
1377 $html .= '<p class="description">' . $args['description'] . '</p>';
1378 }
1379
1380 if ( ! empty( $args['return'] ) ) {
1381 return $html;
1382 } else {
1383 echo $html;
1384 }
1385 }
1386
1387 /**
1388 * Sanitize field function
1389 *
1390 * @param mixed
1391 * @param string
1392 * @return mixed
1393 */
1394 public function sanitize_field( $value = null, $type = '', $args = array() ) {
1395 if ( is_null( $value ) )
1396 return null;
1397
1398 switch ( $type ) {
1399
1400 case 'boolean':
1401 $value = empty( $value ) ? false : true;
1402 break;
1403
1404 case 'checkbox':
1405 $value = is_array( $value ) && ! empty( $value ) ? array_map( 'sanitize_text_field', $value ) : array();
1406 break;
1407
1408 case 'radio':
1409 $value = is_array( $value ) ? false : sanitize_text_field( $value );
1410 break;
1411
1412 case 'textarea':
1413 case 'wysiwyg':
1414 $value = wp_kses_post( $value );
1415 break;
1416
1417 case 'color_picker':
1418 $value = ! $value || '#' == $value ? '' : esc_attr( $value );
1419 break;
1420
1421 case 'number':
1422 $value = ! $value || is_array( $value ) ? '' : str_replace( ',', '', $value );
1423
1424 if ( ! empty( $args['type'] ) ) {
1425 switch ( $args['type'] ) {
1426 case 'int':
1427 $value = (int) $value;
1428 break;
1429
1430 case 'absint':
1431 $value = absint( $value );
1432 break;
1433
1434 case 'float':
1435 default:
1436 $value = floatval( $value );
1437 break;
1438 }
1439 } else {
1440 $value = floatval( $value );
1441 }
1442 break;
1443
1444 case 'text':
1445 case 'select':
1446 default:
1447 $value = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value );
1448 break;
1449 }
1450
1451 return stripslashes_deep( $value );
1452 }
1453
1454 /**
1455 * Validate settings function
1456 *
1457 * @param array $input
1458 * @return array
1459 */
1460 public function validate_settings( $input ) {
1461 // check cap
1462 if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) )
1463 return $input;
1464
1465 // check page
1466 if ( ! ( $option_page = esc_attr( $_POST['option_page'] ) ) )
1467 return $input;
1468
1469 foreach ( $this->settings as $id => $setting ) {
1470 $key = array_search( $option_page, $setting );
1471
1472 if ( $key ) {
1473 // set key
1474 $setting_id = $id;
1475 break;
1476 }
1477 }
1478
1479 // check setting id
1480 if ( ! $setting_id )
1481 return $input;
1482
1483 // save settings
1484 if ( isset( $_POST['save' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
1485 if ( $this->settings[$setting_id]['fields'] ) {
1486 foreach ( $this->settings[$setting_id]['fields'] as $field_id => $field ) {
1487 if ( $field['type'] === 'multiple' ) {
1488 if ( $field['fields'] ) {
1489 foreach ( $field['fields'] as $subfield_id => $subfield ) {
1490 // if subfield has parent
1491 if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['fields'][$subfield_id]['parent'] ) ) {
1492 $field_parent = $this->settings[$setting_id]['fields'][$field_id]['fields'][$subfield_id]['parent'];
1493
1494 $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] );
1495 } else {
1496 $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] );
1497 }
1498 }
1499 }
1500 } else {
1501 // if field has parent
1502 if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['parent'] ) ) {
1503 $field_parent = $this->settings[$setting_id]['fields'][$field_id]['parent'];
1504
1505 $input[$field_parent][$field_id] = isset( $input[$field_parent][$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_parent][$field_id], $field['type'] ) ) : $this->sanitize_field( $input[$field_parent][$field_id], $field['type'] ) ) : ( in_array( $field['type'], array( 'boolean', 'checkbox' ) ) ? false : Responsive_Lightbox()->defaults[$setting_id][$field_parent][$field_id] );
1506 } else {
1507 $input[$field_id] = isset( $input[$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_id], $field['type'] ) ) : $this->sanitize_field( $input[$field_id], $field['type'] ) ) : ( in_array( $field['type'], array( 'boolean', 'checkbox' ) ) ? false : Responsive_Lightbox()->defaults[$setting_id][$field_id] );
1508 }
1509 }
1510 }
1511 }
1512
1513 if ( $setting_id === 'settings' ) {
1514 // merge scripts settings
1515 $input = array_merge( Responsive_Lightbox()->options['settings'], $input );
1516 }
1517
1518 if ( $setting_id === 'configuration' ) {
1519 // merge scripts settings
1520 $input = array_merge( Responsive_Lightbox()->options['configuration'], $input );
1521 }
1522
1523 } elseif ( isset( $_POST['reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
1524
1525 if ( $setting_id === 'configuration' ) {
1526 $script = key( $input );
1527
1528 // merge scripts settings
1529 $input[$script] = Responsive_Lightbox()->defaults['configuration'][$script];
1530 $input = array_merge( Responsive_Lightbox()->options['configuration'], $input );
1531 } elseif ( $setting_id === 'settings' ) {
1532 $input = Responsive_Lightbox()->defaults[$setting_id];
1533 $input['update_version'] = Responsive_Lightbox()->options['settings']['update_version'];
1534 $input['update_notice'] = Responsive_Lightbox()->options['settings']['update_notice'];
1535 } else {
1536 $input = Responsive_Lightbox()->defaults[$setting_id];
1537 }
1538
1539 add_settings_error( 'reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id, 'settings_restored', __( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
1540 }
1541
1542 return $input;
1543 }
1544
1545 /**
1546 * Add-ons tab callback
1547 *
1548 * @return mixed
1549 */
1550 private function addons_tab_cb() {
1551 ?>
1552 <h3><?php _e( 'Add-ons / Extensions', 'responsive-lightbox' ); ?></h3>
1553 <p class="description"><?php _e( 'Enhance your website with these beautiful, easy to use extensions, designed with Responsive Lightbox integration in mind.', 'responsive-lightbox' ); ?></p>
1554 <br />
1555 <?php
1556 if ( ( $cache = get_transient( 'responsive_lightbox_addons_feed' ) ) === false ) {
1557 $url = 'https://dfactory.eu/?feed=addons&product=responsive-lightbox';
1558
1559 $feed = wp_remote_get( esc_url_raw( $url ), array( 'sslverify' => false ) );
1560
1561 if ( ! is_wp_error( $feed ) ) {
1562 if ( isset( $feed['body'] ) && strlen( $feed['body'] ) > 0 ) {
1563 $cache = wp_remote_retrieve_body( $feed );
1564 // set_transient( 'responsive_lightbox_addons_feed', $cache, 3600 );
1565 }
1566 } else {
1567 $cache = '<div class="error"><p>' . __( 'There was an error retrieving the extensions list from the server. Please try again later.', 'responsive-lightbox' ) . '</div>';
1568 }
1569 }
1570
1571 echo $cache;
1572 }
1573
1574 /**
1575 * Licenses section callback.
1576 *
1577 * @return mixed
1578 */
1579 public function licenses_section_cb() {
1580 ?><p class="description"><?php _e( 'A list of licenses for your Responsive Lightbox extensions.', 'responsive-lightbox' ); ?></p><?php
1581 }
1582
1583 /**
1584 * License field callback.
1585 *
1586 * @return mixed
1587 */
1588 public function license_field_cb( $args ) {
1589 $licenses = get_option( 'responsive_lightbox_licenses' );
1590
1591 $license = ! empty( $licenses ) && isset( $licenses[$args['id']]['license'] ) ? esc_attr( $licenses[$args['id']]['license'] ) : '';
1592 $status = ! empty( $licenses ) && ! empty( $licenses[$args['id']]['status'] ) ? true : false;
1593 ?>
1594 <fieldset class="rl_license rl_license-<?php echo esc_attr( $args['id'] ); ?>">
1595 <input type="text" class="regular-text" name="responsive_lightbox_licenses[<?php echo esc_attr( $args['id'] ); ?>][license]" value="<?php echo $license; ?>"><span class="dashicons <?php echo ! empty( $status ) ? 'dashicons-yes' : 'dashicons-no'; ?>"></span>
1596 <p class="description"><?php printf( __( 'Enter your license key to activate %s extension and enable automatic upgrade notices.', 'responsive-lightbox' ), $args['name'] ); ?></p>
1597 </fieldset>
1598 <?php
1599 }
1600
1601 /**
1602 * Validate licenses function.
1603 *
1604 * @param array $input
1605 * @return array
1606 */
1607 public function validate_licenses( $input ) {
1608
1609 // check cap
1610 if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) ) {
1611 return $input;
1612 }
1613
1614 // check page
1615 if ( ! isset( $_POST['option_page'] ) || ! ( $option_page = esc_attr( $_POST['option_page'] ) ) )
1616 return $input;
1617
1618 // check data
1619 if ( ! isset( $_POST['responsive_lightbox_licenses'] ) || ! is_array( $_POST['responsive_lightbox_licenses'] ))
1620 return $input;
1621
1622 $extensions = apply_filters( 'rl_settings_licenses', array() );
1623
1624 if ( empty( $extensions ) )
1625 return $input;
1626
1627 // save settings
1628 if ( isset( $_POST['save_rl_licenses'] ) ) {
1629 $licenses = get_option( 'responsive_lightbox_licenses' );
1630 $statuses = array( 'updated' => 0, 'error' => 0 );
1631
1632 foreach ( $extensions as $extension ) {
1633 if ( ! isset( $_POST['responsive_lightbox_licenses'][$extension['id']] ) )
1634 continue;
1635
1636 $license = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['responsive_lightbox_licenses'][$extension['id']]['license'] );
1637 $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] ) ? true : false;
1638
1639 // request data
1640 $request_args = array(
1641 'action' => 'activate_license',
1642 'license' => trim( $license ),
1643 'item_name' => $extension['item_name']
1644 );
1645 // request
1646 $response = $this->license_request( $request_args );
1647
1648 // validate request
1649 if ( is_wp_error( $response ) ) {
1650 $input[$extension['id']['status']] = false;
1651 $statuses['error']++;
1652 } else {
1653 // decode the license data
1654 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
1655
1656 // assign the data
1657 if ( $license_data->license == 'valid' ) {
1658 $input[$extension['id']]['status'] = true;
1659
1660 if ( $status === false ) {
1661 $statuses['updated']++;
1662 }
1663 } else {
1664 $input[$extension['id']]['status'] = false;
1665 $statuses['error']++;
1666 }
1667 }
1668 }
1669
1670 // success notice
1671 if ( $statuses['updated'] > 0 )
1672 add_settings_error( 'rl_licenses_settings', 'license_activated', sprintf( _n( '%s license successfully activated.', '%s licenses successfully activated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ), 'updated' );
1673 // failed notice
1674 if ( $statuses['error'] > 0 )
1675 add_settings_error( 'rl_licenses_settings', 'license_activation_failed', sprintf( _n( '%s license activation failed.', '%s licenses activation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ), 'error' );
1676
1677 } elseif ( isset( $_POST['reset_rl_licenses'] ) ) {
1678 $licenses = get_option( 'responsive_lightbox_licenses' );
1679 $statuses = array( 'updated' => 0, 'error' => 0 );
1680
1681 foreach ( $extensions as $extension ) {
1682 $license = ! empty( $licenses ) && isset( $licenses[$extension['id']]['license'] ) ? $licenses[$extension['id']]['license'] : '';
1683 $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] ) ? true : false;
1684
1685 if ( $status === true || ( $status === false && ! empty( $license ) ) ) {
1686 // request data
1687 $request_args = array(
1688 'action' => 'deactivate_license',
1689 'license' => trim( $license ),
1690 'item_name' => $extension['item_name']
1691 );
1692 // request
1693 $response = $this->license_request( $request_args );
1694
1695 // validate request
1696 if ( is_wp_error( $response ) ) {
1697 $statuses['error']++;
1698 } else {
1699 // decode the license data
1700 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
1701
1702 // assign the data
1703 if ( $license_data->license == 'deactivated' ) {
1704 $input[$extension['id']]['license'] = '';
1705 $input[$extension['id']]['status'] = false;
1706 $statuses['updated']++;
1707 } else {
1708 $statuses['error']++;
1709 }
1710 }
1711 }
1712 }
1713
1714 // success notice
1715 if ( $statuses['updated'] > 0 )
1716 add_settings_error( 'rl_licenses_settings', 'license_deactivated', sprintf( _n( '%s license successfully deactivated.', '%s licenses successfully deactivated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ), 'updated' );
1717 // failed notice
1718 if ( $statuses['error'] > 0 )
1719 add_settings_error( 'rl_licenses_settings', 'license_deactivation_failed', sprintf( _n( '%s license deactivation failed.', '%s licenses deactivation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ), 'error' );
1720
1721 }
1722
1723 return $input;
1724 }
1725
1726 /**
1727 * License request function.
1728 *
1729 * @param array $args
1730 * @return mixed
1731 */
1732 private function license_request( $args ) {
1733 // data to send in our API request
1734 $api_params = array(
1735 'edd_action' => $args['action'],
1736 'license' => $args['license'],
1737 'item_name' => urlencode( $args['item_name'] ),
1738 // 'item_id' => $args['item_id'],
1739 'url' => home_url(),
1740 'timeout' => 60,
1741 'sslverify' => false
1742 );
1743 // call the custom API.
1744 $response = wp_remote_get( add_query_arg( $api_params, $this->api_url ) );
1745
1746 return $response;
1747 }
1748 }
1749