PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.3.2
Responsive Lightbox & Gallery v2.3.2
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / responsive-lightbox.php
responsive-lightbox Last commit date
assets 5 years ago css 5 years ago font 8 years ago images 5 years ago includes 5 years ago js 5 years ago languages 5 years ago library 5 years ago index.php 12 years ago readme.txt 5 years ago responsive-lightbox.php 5 years ago wpml-config.xml 8 years ago
responsive-lightbox.php
2141 lines
1 <?php
2 /*
3 Plugin Name: Responsive Lightbox & Gallery
4 Description: Responsive Lightbox & Gallery allows users to create galleries and view larger versions of images, galleries and videos in a lightbox (overlay) effect optimized for mobile devices.
5 Version: 2.3.2
6 Author: dFactory
7 Author URI: http://www.dfactory.eu/
8 Plugin URI: http://www.dfactory.eu/plugins/responsive-lightbox/
9 License: MIT License
10 License URI: http://opensource.org/licenses/MIT
11 Text Domain: responsive-lightbox
12 Domain Path: /languages
13
14 Responsive Lightbox & Gallery
15 Copyright (C) 2013-2021, Digital Factory - info@digitalfactory.pl
16
17 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 // exit if accessed directly
25 if ( ! defined( 'ABSPATH' ) )
26 exit;
27
28 define( 'RESPONSIVE_LIGHTBOX_URL', plugins_url( '', __FILE__ ) );
29 define( 'RESPONSIVE_LIGHTBOX_PATH', plugin_dir_path( __FILE__ ) );
30 define( 'RESPONSIVE_LIGHTBOX_REL_PATH', dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR );
31
32 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-fast-image.php' );
33 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-galleries.php' );
34 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-folders.php' );
35 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-frontend.php' );
36 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-settings.php' );
37 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-tour.php' );
38 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-welcome.php' );
39 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-widgets.php' );
40 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'functions.php' );
41
42 /**
43 * Responsive Lightbox class.
44 *
45 * @class Responsive_Lightbox
46 * @version 2.3.2
47 */
48 class Responsive_Lightbox {
49
50 public $defaults = array(
51 'settings' => array(
52 'tour' => true,
53 'script' => 'swipebox',
54 'selector' => 'lightbox',
55 'default_gallery' => 'default',
56 'builder_gallery' => 'basicgrid',
57 'default_woocommerce_gallery' => 'default',
58 'galleries' => true,
59 'gallery_image_size' => 'full',
60 'gallery_image_title' => 'default',
61 'gallery_image_caption' => 'default',
62 'force_custom_gallery' => false,
63 'woocommerce_gallery_lightbox' => false,
64 'videos' => true,
65 'widgets' => false,
66 'comments' => false,
67 'image_links' => true,
68 'image_title' => 'default',
69 'image_caption' => 'default',
70 'images_as_gallery' => false,
71 'deactivation_delete' => false,
72 'loading_place' => 'header',
73 'conditional_loading' => false,
74 'enable_custom_events' => false,
75 'custom_events' => 'ajaxComplete',
76 'update_version' => 1,
77 'update_notice' => true,
78 'update_delay_date' => 0
79 ),
80 'builder' => array(
81 'gallery_builder' => true,
82 'categories' => true,
83 'tags' => true,
84 'permalink' => 'rl_gallery',
85 'permalink_categories' => 'rl_category',
86 'permalink_tags' => 'rl_tag',
87 'archives' => true,
88 'archives_category' => 'all'
89 ),
90 'configuration' => array(
91 'swipebox' => array(
92 'animation' => 'css',
93 'force_png_icons' => false,
94 'hide_close_mobile' => false,
95 'remove_bars_mobile' => false,
96 'hide_bars' => true,
97 'hide_bars_delay' => 5000,
98 'video_max_width' => 1080,
99 'loop_at_end' => false
100 ),
101 'prettyphoto' => array(
102 'animation_speed' => 'normal',
103 'slideshow' => false,
104 'slideshow_delay' => 5000,
105 'slideshow_autoplay' => false,
106 'opacity' => 75,
107 'show_title' => true,
108 'allow_resize' => true,
109 'allow_expand' => true,
110 'width' => 1080,
111 'height' => 720,
112 'separator' => '/',
113 'theme' => 'pp_default',
114 'horizontal_padding' => 20,
115 'hide_flash' => false,
116 'wmode' => 'opaque',
117 'video_autoplay' => false,
118 'modal' => false,
119 'deeplinking' => false,
120 'overlay_gallery' => true,
121 'keyboard_shortcuts' => true,
122 'social' => false
123 ),
124 'fancybox' => array(
125 'modal' => false,
126 'show_overlay' => true,
127 'show_close_button' => true,
128 'enable_escape_button' => true,
129 'hide_on_overlay_click' => true,
130 'hide_on_content_click' => false,
131 'cyclic' => false,
132 'show_nav_arrows' => true,
133 'auto_scale' => true,
134 'scrolling' => 'yes',
135 'center_on_scroll' => true,
136 'opacity' => true,
137 'overlay_opacity' => 70,
138 'overlay_color' => '#666',
139 'title_show' => true,
140 'title_position' => 'outside',
141 'transitions' => 'fade',
142 'easings' => 'swing',
143 'speeds' => 300,
144 'change_speed' => 300,
145 'change_fade' => 100,
146 'padding' => 5,
147 'margin' => 5,
148 'video_width' => 1080,
149 'video_height' => 720
150 ),
151 'nivo' => array(
152 'effect' => 'fade',
153 'click_overlay_to_close' => true,
154 'keyboard_nav' => true,
155 'error_message' => 'The requested content cannot be loaded. Please try again later.'
156 ),
157 'imagelightbox' => array(
158 'animation_speed' => 250,
159 'preload_next' => true,
160 'enable_keyboard' => true,
161 'quit_on_end' => false,
162 'quit_on_image_click' => false,
163 'quit_on_document_click' => true
164 ),
165 'tosrus' => array(
166 'effect' => 'slide',
167 'infinite' => true,
168 'keys' => false,
169 'autoplay' => true,
170 'pause_on_hover' => false,
171 'timeout' => 4000,
172 'pagination' => true,
173 'pagination_type' => 'thumbnails',
174 'close_on_click' => false
175 ),
176 'featherlight' => array(
177 'open_speed' => 250,
178 'close_speed' => 250,
179 'close_on_click' => 'background',
180 'close_on_esc' => true,
181 'gallery_fade_in' => 100,
182 'gallery_fade_out' => 300
183 ),
184 'magnific' => array(
185 'disable_on' => 0,
186 'mid_click' => true,
187 'preloader' => true,
188 'close_on_content_click' => true,
189 'close_on_background_click' => true,
190 'close_button_inside' => true,
191 'show_close_button' => true,
192 'enable_escape_key' => true,
193 'align_top' => false,
194 'fixed_content_position' => 'auto',
195 'fixed_background_position' => 'auto',
196 'auto_focus_last' => true
197 )
198 ),
199 'folders' => array(
200 'active' => true,
201 'media_taxonomy' => 'rl_media_folder',
202 'media_tags' => false,
203 // 'jstree_style' => 'default',
204 'jstree_wholerow' => true,
205 'show_in_menu' => false,
206 'folders_removal' => true
207 ),
208 'remote_library' => array(
209 'active' => true,
210 'caching' => false,
211 'cache_expiry' => 1,
212 'flickr' => array(
213 'active' => false,
214 'api_key' => ''
215 ),
216 'unsplash' => array(
217 'active' => false,
218 'api_key' => ''
219 ),
220 'wikimedia' => array(
221 'active' => true
222 )
223 ),
224 'capabilities' => array(
225 'active' => false,
226 'roles' => array(
227 'administrator' => array(
228 'publish_galleries',
229 'edit_galleries',
230 'edit_published_galleries',
231 'edit_others_galleries',
232 'edit_private_galleries',
233 'delete_galleries',
234 'delete_published_galleries',
235 'delete_others_galleries',
236 'delete_private_galleries',
237 'read_private_galleries',
238 'manage_gallery_categories',
239 'manage_gallery_tags',
240 'edit_lightbox_settings'
241 ),
242 'editor' => array(
243 'publish_galleries',
244 'edit_galleries',
245 'edit_published_galleries',
246 'edit_others_galleries',
247 'edit_private_galleries',
248 'delete_galleries',
249 'delete_published_galleries',
250 'delete_others_galleries',
251 'delete_private_galleries',
252 'read_private_galleries',
253 'manage_gallery_categories',
254 'manage_gallery_tags'
255 ),
256 'author' => array(
257 'publish_galleries',
258 'edit_galleries',
259 'edit_published_galleries',
260 'delete_galleries',
261 'delete_published_galleries'
262 )
263 )
264 ),
265 'basicgrid_gallery' => array(
266 'columns_lg' => 4,
267 'columns_md' => 3,
268 'columns_sm' => 2,
269 'columns_xs' => 1,
270 'gutter' => 2,
271 'force_height' => false,
272 'row_height' => 150
273 ),
274 'basicslider_gallery' => array(
275 'adaptive_height' => true,
276 'loop' => false,
277 'captions' => 'overlay',
278 'init_single' => true,
279 'responsive' => true,
280 'preload' => 'visible',
281 'pager' => true,
282 'controls' => true,
283 'hide_on_end' => true,
284 'slide_margin' => 0,
285 'transition' => 'fade',
286 'kenburns_zoom' => 120,
287 'speed' => 800,
288 'easing' => 'swing',
289 'continuous' => true,
290 'use_css' => true,
291 'slideshow' => true,
292 'slideshow_direction' => 'next',
293 'slideshow_hover' => true,
294 'slideshow_hover_delay' => 100,
295 'slideshow_delay' => 500,
296 'slideshow_pause' => 3000
297 ),
298 'basicmasonry_gallery' => array(
299 'columns_lg' => 4,
300 'columns_md' => 3,
301 'columns_sm' => 2,
302 'columns_xs' => 2,
303 'gutter' => 20,
304 'margin' => 20,
305 'origin_left' => true,
306 'origin_top' => true
307 ),
308 'version' => '2.3.2',
309 'activation_date' => ''
310 );
311 public $options = array();
312 public $providers = array();
313 public $capabilities = array(
314 'publish_galleries' => '',
315 'edit_galleries' => '',
316 'edit_published_galleries' => '',
317 'edit_others_galleries' => '',
318 'edit_private_galleries' => '',
319 'delete_galleries' => '',
320 'delete_published_galleries' => '',
321 'delete_others_galleries' => '',
322 'delete_private_galleries' => '',
323 'read_private_galleries' => '',
324 'manage_gallery_categories' => '',
325 'manage_gallery_tags' => '',
326 'edit_lightbox_settings' => ''
327 );
328 public $gallery_types = array();
329 private $deactivaion_url = '';
330 private $version = false;
331 private $notices = array();
332 private static $_instance;
333
334 /**
335 * Constructor.
336 *
337 * @return void
338 */
339 public function __construct() {
340 register_activation_hook( __FILE__, array( $this, 'activate_multisite' ) );
341 register_deactivation_hook( __FILE__, array( $this, 'deactivate_multisite' ) );
342
343 // change from older versions
344 $this->version = $db_version = get_option( 'responsive_lightbox_version' );
345
346 // no version?
347 if ( $db_version === false )
348 $this->version = $db_version = '1.0.0';
349
350 // 1.0.5 update
351 if ( version_compare( $db_version, '1.0.5', '<' ) ) {
352 if ( ( $array = get_option( 'rl_settings' ) ) !== false ) {
353 update_option( 'responsive_lightbox_settings', $array );
354 delete_option( 'rl_settings' );
355 }
356
357 if ( ( $array = get_option( 'rl_configuration' ) ) !== false ) {
358 update_option( 'responsive_lightbox_configuration', $array );
359 delete_option( 'rl_configuration' );
360 }
361 }
362
363 $capabilities = get_option( 'responsive_lightbox_capabilities' );
364
365 if ( empty( $capabilities ) )
366 $capabilities = array();
367
368 $this->options['settings'] = array_merge( $this->defaults['settings'], ( ( $array = get_option( 'responsive_lightbox_settings' ) ) === false ? array() : $array ) );
369 $this->options['folders'] = array_merge( $this->defaults['folders'], ( ( $array = get_option( 'responsive_lightbox_folders' ) ) === false ? array() : $array ) );
370 $this->options['builder'] = array_merge( $this->defaults['builder'], ( ( $array = get_option( 'responsive_lightbox_builder' ) ) === false ? array() : $array ) );
371 $this->options['capabilities'] = array_merge( $this->defaults['capabilities'], $capabilities );
372 $this->options['remote_library'] = array_merge( $this->defaults['remote_library'], ( ( $array = get_option( 'responsive_lightbox_remote_library' ) ) === false ? array() : $array ) );
373
374 // for multi arrays we have to merge them separately
375 $db_conf_opts = ( ( $base = get_option( 'responsive_lightbox_configuration' ) ) === false ? array() : $base );
376
377 foreach ( $this->defaults['configuration'] as $script => $settings ) {
378 $this->options['configuration'][$script] = array_merge( $settings, ( isset( $db_conf_opts[$script] ) ? $db_conf_opts[$script] : array() ) );
379 }
380
381 // add default galleries options
382 $this->options['basicgrid_gallery'] = array_merge( $this->defaults['basicgrid_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicgrid_gallery', $this->defaults['basicgrid_gallery'] ) ) == false ? array() : $array ) );
383 $this->options['basicslider_gallery'] = array_merge( $this->defaults['basicslider_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicslider_gallery', $this->defaults['basicslider_gallery'] ) ) == false ? array() : $array ) );
384 $this->options['basicmasonry_gallery'] = array_merge( $this->defaults['basicmasonry_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicmasonry_gallery', $this->defaults['basicmasonry_gallery'] ) ) == false ? array() : $array ) );
385
386 // actions
387 add_action( 'upgrader_process_complete', array( $this, 'update_plugin' ), 10, 2 );
388 add_action( 'plugins_loaded', array( $this, 'plugins_loaded_init' ) );
389 add_action( 'in_admin_header', array( $this, 'display_breadcrumbs' ) );
390 add_action( 'after_setup_theme', array( $this, 'init_remote_libraries' ), 11 );
391 add_action( 'init', array( $this, 'init_galleries' ) );
392 add_action( 'init', array( $this, 'init_folders' ) );
393 add_action( 'init', array( $this, 'init_gutenberg' ) );
394 add_action( 'admin_init', array( $this, 'update_notice' ) );
395 add_action( 'wp_enqueue_scripts', array( $this, 'front_scripts_styles' ) );
396 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_styles' ) );
397 add_action( 'sidebar_admin_setup', array( $this, 'sidebar_admin_setup' ) );
398 add_action( 'admin_footer', array( $this, 'modal_deactivation_template' ) );
399 add_action( 'wp_ajax_rl_dismiss_notice', array( $this, 'dismiss_notice' ) );
400 add_action( 'wp_ajax_rl-deactivate-plugin', array( $this, 'deactivate_plugin' ) );
401
402 // filters
403 add_filter( 'plugin_action_links', array( $this, 'plugin_settings_link' ), 10, 2 );
404 add_filter( 'plugin_row_meta', array( $this, 'plugin_extend_links' ), 10, 2 );
405 }
406
407 /**
408 * Disable object cloning.
409 */
410 public function __clone() {}
411
412 /**
413 * Disable unserializing of the class.
414 */
415 public function __wakeup() {}
416
417 /**
418 * Main Responsive Lightbox instance.
419 *
420 * @return object
421 */
422 public static function instance() {
423 if ( self::$_instance === null )
424 self::$_instance = new self();
425
426 return self::$_instance;
427 }
428
429 /**
430 * Single site activation function.
431 *
432 * @return void
433 */
434 public function activate_single() {
435 // transient for welcome screen
436 if ( get_option( 'responsive_lightbox_activation_date', false ) === false )
437 set_transient( 'rl_activation_redirect', 1, 3600 );
438 elseif ( $this->version !== false ) {
439 // activated from old version
440 if ( version_compare( $this->version, '2.0.0', '<' ) )
441 set_transient( 'rl_activation_redirect', 1, 3600 );
442 } else
443 set_transient( 'rl_activation_redirect', 1, 3600 );
444
445 // grant new capabilities
446 $this->grant_capabilities();
447
448 // add options if needed
449 add_option( 'responsive_lightbox_settings', $this->defaults['settings'], '', false );
450 add_option( 'responsive_lightbox_configuration', $this->defaults['configuration'], '', false );
451 add_option( 'responsive_lightbox_folders', $this->defaults['folders'], '', false );
452 add_option( 'responsive_lightbox_builder', $this->defaults['builder'], '', false );
453 add_option( 'responsive_lightbox_capabilities', $this->defaults['capabilities'], '', false );
454 add_option( 'responsive_lightbox_remote_library', $this->defaults['remote_library'], '', false );
455 add_option( 'responsive_lightbox_version', $this->defaults['version'], '', false );
456
457 // permalinks
458 flush_rewrite_rules();
459 }
460
461 /**
462 * Single site deactivation function.
463 *
464 * @param bool $multi Multisite?
465 * @return void
466 */
467 public function deactivate_single( $multi = false ) {
468 if ( $multi === true ) {
469 $options = get_option( 'responsive_lightbox_settings' );
470 $check = $options['deactivation_delete'];
471 } else
472 $check = $this->options['settings']['deactivation_delete'];
473
474 // delete options if needed
475 if ( $check ) {
476 global $wp_roles;
477
478 // remove all capabilities
479 foreach ( $wp_roles->roles as $role_name => $label ) {
480 $role = $wp_roles->get_role( $role_name );
481
482 foreach ( $this->capabilities as $capability => $label ) {
483 $role->remove_cap( $capability );
484 }
485 }
486
487 delete_option( 'responsive_lightbox_settings' );
488 delete_option( 'responsive_lightbox_configuration' );
489 delete_option( 'responsive_lightbox_folders' );
490 delete_option( 'responsive_lightbox_builder' );
491 delete_option( 'responsive_lightbox_capabilities' );
492 delete_option( 'responsive_lightbox_remote_library' );
493 delete_option( 'responsive_lightbox_version' );
494 }
495
496 // permalinks
497 flush_rewrite_rules();
498 }
499
500 /**
501 * Activation function.
502 *
503 * @param bool $networkwide Multisite?
504 * @return void
505 */
506 public function activate_multisite( $networkwide ) {
507 if ( is_multisite() && $networkwide ) {
508 global $wpdb;
509
510 $activated_blogs = array();
511 $current_blog_id = $wpdb->blogid;
512 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
513
514 foreach ( $blogs_ids as $blog_id ) {
515 switch_to_blog( $blog_id );
516 $this->activate_single();
517 $activated_blogs[] = (int) $blog_id;
518 }
519
520 switch_to_blog( $current_blog_id );
521 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs, array() );
522 } else
523 $this->activate_single();
524 }
525
526 /**
527 * Dectivation function.
528 *
529 * @param bool $networkwide Multisite?
530 * @return void
531 */
532 public function deactivate_multisite( $networkwide ) {
533 if ( is_multisite() && $networkwide ) {
534 global $wpdb;
535
536 $current_blog_id = $wpdb->blogid;
537 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
538
539 if ( ($activated_blogs = get_site_option( 'responsive_lightbox_activated_blogs', false, false )) === false )
540 $activated_blogs = array();
541
542 foreach ( $blogs_ids as $blog_id ) {
543 switch_to_blog( $blog_id );
544 $this->deactivate_single( true );
545
546 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
547 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
548 }
549
550 switch_to_blog( $current_blog_id );
551 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs );
552 } else
553 $this->deactivate_single();
554 }
555
556 /**
557 * Update plugin hook.
558 *
559 * @return void
560 */
561 public function update_plugin( $upgrader_object, $options ) {
562 // plugin update?
563 if ( $options['action'] === 'update' && $options['type'] === 'plugin' ) {
564 // get current plugin name
565 $current_plugin = plugin_basename( __FILE__ );
566
567 // search for a plugin
568 foreach ( $options['plugins'] as $plugin ) {
569 // found?
570 if ( $plugin === $current_plugin ) {
571 // 2.3.1
572 if ( version_compare( $this->version, '2.3.1', '<' ) ) {
573 // grant new capabilities just before the version update
574 $this->grant_capabilities();
575 }
576 }
577 }
578 }
579 }
580
581 /**
582 * Grant new capabilities to user roles.
583 *
584 * @return void
585 */
586 public function grant_capabilities() {
587 // no capabilities?
588 if ( ! $this->options['capabilities']['active'] )
589 return;
590
591 global $wp_roles;
592
593 $user = wp_get_current_user();
594
595 // add new capabilities to roles
596 foreach ( $wp_roles->roles as $role_name => $label ) {
597 // get user role
598 $role = $wp_roles->get_role( $role_name );
599
600 // treat such role as administrator
601 if ( $role->has_cap( 'install_plugins' ) ) {
602 // add every capability
603 foreach ( $this->capabilities as $capability => $label ) {
604 $role->add_cap( $capability );
605 }
606
607 // force capability on the current user
608 if ( is_a( $user, 'WP_User' ) && ! $user->has_cap( 'edit_lightbox_settings' ) )
609 $user->add_cap( 'edit_lightbox_settings' );
610 }
611
612 // role exists?
613 if ( array_key_exists( $role_name, $this->defaults['capabilities']['roles'] ) ) {
614 // add new capabilities to the current roles nevertheless
615 foreach ( $this->capabilities as $capability => $label ) {
616 // capability exists?
617 if ( in_array( $capability, $this->defaults['capabilities']['roles'][$role_name], true ) ) {
618 $role->add_cap( $capability );
619
620 // force capability on the current user
621 if ( $capability === 'edit_lightbox_settings' && is_a( $user, 'WP_User' ) && ! $user->has_cap( 'edit_lightbox_settings' ) && in_array( $role_name, $user->roles, true ) )
622 $user->add_cap( 'edit_lightbox_settings' );
623 }
624 }
625 }
626 }
627 }
628
629 /**
630 * Early plugin initialization.
631 *
632 * @return void
633 */
634 public function plugins_loaded_init() {
635 // load textdomain
636 load_plugin_textdomain( 'responsive-lightbox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
637
638 // set gallery types
639 $this->gallery_types = array(
640 'default' => __( 'Default', 'responsive-lightbox' ),
641 'basicgrid' => __( 'Basic Grid', 'responsive-lightbox' ),
642 'basicslider' => __( 'Basic Slider', 'responsive-lightbox' ),
643 'basicmasonry' => __( 'Basic Masonry', 'responsive-lightbox' )
644 );
645
646 // only for backend
647 if ( is_admin() ) {
648 $galleries = apply_filters( 'rl_gallery_types', $this->gallery_types );
649
650 $update_settings = false;
651
652 // lightbox scipt does not exist?
653 if ( ! array_key_exists( $this->options['settings']['script'], $this->options['configuration'] ) ) {
654 // set default script
655 $this->options['settings']['script'] = $this->defaults['settings']['script'];
656
657 $update_settings = true;
658 }
659
660 // check default WordPress gallery
661 if ( ! array_key_exists( $this->options['settings']['default_gallery'], $galleries ) ) {
662 // set default gallery
663 $this->options['settings']['default_gallery'] = $this->defaults['settings']['default_gallery'];
664
665 $update_settings = true;
666 }
667
668 // check default builder gallery
669 if ( ! array_key_exists( $this->options['settings']['builder_gallery'], $galleries ) ) {
670 // set default gallery
671 $this->options['settings']['builder_gallery'] = $this->defaults['settings']['builder_gallery'];
672
673 $update_settings = true;
674 }
675
676 // check default WooCommerce gallery
677 if ( ! array_key_exists( $this->options['settings']['default_woocommerce_gallery'], $galleries ) ) {
678 // set default gallery
679 $this->options['settings']['default_woocommerce_gallery'] = $this->defaults['settings']['default_woocommerce_gallery'];
680
681 $update_settings = true;
682 }
683
684 // update settings
685 if ( $update_settings )
686 update_option( 'responsive_lightbox_settings', $this->options['settings'], false );
687
688 // set capabilities with labels
689 $this->capabilities = array(
690 'publish_galleries' => __( 'Publish Galleries', 'responsive-lightbox' ),
691 'edit_galleries' => __( 'Edit Galleries', 'responsive-lightbox' ),
692 'edit_published_galleries' => __( 'Edit Published Galleries', 'responsive-lightbox' ),
693 'edit_others_galleries' => __( 'Edit Others Galleries', 'responsive-lightbox' ),
694 'edit_private_galleries' => __( 'Edit Private Galleries', 'responsive-lightbox' ),
695 'delete_galleries' => __( 'Delete Galleries', 'responsive-lightbox' ),
696 'delete_published_galleries' => __( 'Delete Published Galleries', 'responsive-lightbox' ),
697 'delete_others_galleries' => __( 'Delete Others Galleries', 'responsive-lightbox' ),
698 'delete_private_galleries' => __( 'Delete Private Galleries', 'responsive-lightbox' ),
699 'read_private_galleries' => __( 'Read Private Galleries', 'responsive-lightbox' ),
700 'manage_gallery_categories' => __( 'Manage Gallery Categories', 'responsive-lightbox' ),
701 'manage_gallery_tags' => __( 'Manage Gallery Tags', 'responsive-lightbox' ),
702 'edit_lightbox_settings' => __( 'Manage Settings', 'responsive-lightbox' )
703 );
704
705 // 2.3.0 update
706 if ( version_compare( $this->version, '2.3.0', '<' ) ) {
707 // grant new capabilities just before the version update
708 $this->grant_capabilities();
709 }
710
711 // plugin version update
712 if ( version_compare( $this->version, $this->defaults['version'], '<' ) )
713 update_option( 'responsive_lightbox_version', $this->defaults['version'], false );
714 }
715
716 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-multilang.php' );
717 }
718
719 /**
720 * Update notice.
721 *
722 * @return void
723 */
724 public function update_notice() {
725 if ( ! current_user_can( 'install_plugins' ) )
726 return;
727
728 $current_update = 2;
729
730 // get current time
731 $current_time = time();
732
733 if ( $this->options['settings']['update_version'] < $current_update ) {
734 // check version, if update ver is lower than plugin ver, set update notice to true
735 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_version' => $current_update, 'update_notice' => true ) );
736
737 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
738
739 // set activation date
740 $activation_date = get_option( 'responsive_lightbox_activation_date' );
741
742 if ( $activation_date === false )
743 update_option( 'responsive_lightbox_activation_date', $current_time );
744 }
745
746 // display current version notice
747 if ( $this->options['settings']['update_notice'] === true ) {
748 // include notice js, only if needed
749 add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ), 999 );
750
751 // get activation date
752 $activation_date = get_option( 'responsive_lightbox_activation_date' );
753
754 if ( (int) $this->options['settings']['update_delay_date'] === 0 ) {
755 if ( $activation_date + 1209600 > $current_time )
756 $this->options['settings']['update_delay_date'] = $activation_date + 1209600;
757 else
758 $this->options['settings']['update_delay_date'] = $current_time;
759
760 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
761 }
762
763 if ( ( ! empty( $this->options['settings']['update_delay_date'] ) ? (int) $this->options['settings']['update_delay_date'] : $current_time ) <= $current_time )
764 $this->add_notice( sprintf( __( "Hey, you've been using <strong>Responsive Lightbox & Gallery</strong> for more than %s", 'responsive-lightbox' ), human_time_diff( $activation_date, $current_time ) ) . '<br />' . __( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation.', 'responsive-lightbox' ) . '<br /><br />' . __( 'Your help is much appreciated. Thank you very much', 'responsive-lightbox' ) . ' ~ <strong>Bartosz Arendt</strong>, ' . sprintf( __( 'founder of <a href="%s" target="_blank">dFactory</a> plugins.', 'responsive-lightbox' ), 'https://dfactory.eu/' ) . '<br /><br />' . sprintf( __( '<a href="%s" class="rl-dismissible-notice" target="_blank" rel="noopener">Ok, you deserve it</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice rl-delay-notice" rel="noopener">Nope, maybe later</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice" rel="noopener">I already did</a>', 'responsive-lightbox' ), 'https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5#new-post' ), 'notice notice-info is-dismissible rl-notice' );
765 }
766 }
767
768 /**
769 * Dismiss notice.
770 *
771 * @return void
772 */
773 public function dismiss_notice() {
774 if ( ! current_user_can( 'install_plugins' ) )
775 return;
776
777 if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'rl_dismiss_notice' ) ) {
778 $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] );
779
780 switch ( $notice_action ) {
781 // delay notice
782 case 'delay':
783 // set delay period to 1 week from now
784 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => time() + 1209600 ) );
785 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
786 break;
787
788 // hide notice
789 default:
790 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_notice' => false ) );
791 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => 0 ) );
792
793 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
794 }
795 }
796
797 exit;
798 }
799
800 /**
801 * Add admin notices.
802 *
803 * @param string $html Notice HTML
804 * @param string $status Notice status
805 * @param bool $paragraph Whether to use paragraph
806 * @param bool $network
807 * @return void
808 */
809 public function add_notice( $html = '', $status = 'error', $paragraph = true, $network = false ) {
810 $this->notices[] = array(
811 'html' => $html,
812 'status' => $status,
813 'paragraph' => $paragraph
814 );
815
816 add_action( 'admin_notices', array( $this, 'display_notice') );
817
818 if ( $network )
819 add_action( 'network_admin_notices', array( $this, 'display_notice') );
820 }
821
822 /**
823 * Print admin notices.
824 *
825 * @return void
826 */
827 public function display_notice() {
828 foreach( $this->notices as $notice ) {
829 echo '
830 <div class="' . $notice['status'] . '">
831 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
832 ' . $notice['html'] . '
833 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
834 </div>';
835 }
836 }
837
838 /**
839 * Print admin scripts.
840 *
841 * @return void
842 */
843 public function admin_inline_js() {
844 if ( ! current_user_can( 'install_plugins' ) )
845 return;
846 ?>
847 <script type="text/javascript">
848 ( function( $ ) {
849 // ready event
850 $( function() {
851 // save dismiss state
852 $( '.rl-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .rl-dismissible-notice', function( e ) {
853 var notice_action = 'hide';
854
855 if ( $( e.currentTarget ).hasClass( 'rl-delay-notice' ) ) {
856 notice_action = 'delay'
857 }
858
859 $.post( ajaxurl, {
860 action: 'rl_dismiss_notice',
861 notice_action: notice_action,
862 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
863 nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>'
864 } );
865
866 $( e.delegateTarget ).slideUp( 'fast' );
867 } );
868 } );
869 } )( jQuery );
870 </script>
871 <?php
872 }
873
874 /**
875 * Add links to Support Forum.
876 *
877 * @param array $links
878 * @param string $file
879 * @return array
880 */
881 public function plugin_extend_links( $links, $file ) {
882 if ( ! current_user_can( 'install_plugins' ) )
883 return $links;
884
885 $plugin = plugin_basename( __FILE__ );
886
887 if ( $file == $plugin ) {
888 return array_merge(
889 $links, array( sprintf( '<a href="https://dfactory.eu/support/forum/responsive-lightbox/" target="_blank">%s</a>', __( 'Support', 'responsive-lightbox' ) ) )
890 );
891 }
892
893 return $links;
894 }
895
896 /**
897 * Add links to Settings page.
898 *
899 * @param array $links
900 * @param string $file
901 * @return array
902 */
903 public function plugin_settings_link( $links, $file ) {
904 if ( ! is_admin() || ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) )
905 return $links;
906
907 static $plugin;
908
909 $plugin = plugin_basename( __FILE__ );
910
911 if ( $file == $plugin ) {
912 if ( ! empty( $links['deactivate'] ) ) {
913 // link already contains class attribute?
914 if ( preg_match( '/<a.*?class=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 )
915 $links['deactivate'] = preg_replace( '/(<a.*?class=(?:\'|").*?)((?:\'|").*?>)/s', '$1 rl-deactivate-plugin-modal$2', $links['deactivate'] );
916 else
917 $links['deactivate'] = preg_replace( '/(<a.*?)>/s', '$1 class="rl-deactivate-plugin-modal">', $links['deactivate'] );
918
919 // link already contains href attribute?
920 if ( preg_match( '/<a.*?href=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 ) {
921 if ( ! empty( $result[2] ) )
922 $this->deactivaion_url = $result[2];
923 }
924 }
925
926 // put settings link at start
927 array_unshift( $links, sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-settings', __( 'Settings', 'responsive-lightbox' ) ) );
928
929 // add add-ons link
930 $links[] = sprintf( '<a href="%s" style="color: green;">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-addons', __( 'Add-ons', 'responsive-lightbox' ) );
931 }
932
933 return $links;
934 }
935
936 /**
937 * Deactivation modal HTML template.
938 *
939 * @return void
940 */
941 public function modal_deactivation_template() {
942 global $pagenow;
943
944 // display only for plugins page
945 if ( $pagenow !== 'plugins.php' )
946 return;
947
948 echo '
949 <div id="rl-deactivation-modal" style="display: none;">
950 <div id="rl-deactivation-container">
951 <div id="rl-deactivation-body">
952 <div class="rl-deactivation-options">
953 <p><em>' . __( "We're sorry to see you go. Could you please tell us what happened?", 'responsive-lightbox' ) . '</em></p>
954 <ul>';
955
956 foreach ( array(
957 '1' => __( "I couldn't figure out how to make it work.", 'responsive-lightbox' ),
958 '2' => __( 'I found another plugin to use for the same task.', 'responsive-lightbox' ),
959 '3' => __( 'The User Interface is not clear to me.', 'responsive-lightbox' ),
960 '4' => __( 'The plugin is not what I was looking for.', 'responsive-lightbox' ),
961 '5' => __( "Support isn't timely.", 'responsive-lightbox' ),
962 '6' => __( 'Other', 'responsive-lightbox' )
963 ) as $option => $text ) {
964 echo '
965 <li><label><input type="radio" name="rl_deactivation_option" value="' . $option . '" ' . checked( '6', $option, false ) . ' />' . esc_html( $text ) . '</label></li>';
966 }
967
968 echo '
969 </ul>
970 </div>
971 <div class="rl-deactivation-textarea">
972 <textarea name="rl_deactivation_other"></textarea>
973 </div>
974 </div>
975 <div id="rl-deactivation-footer">
976 <a href="" class="button rl-deactivate-plugin-cancel">' . __( 'Cancel', 'responsive-lightbox' ) . '</a>
977 <a href="' . $this->deactivaion_url . '" class="button button-secondary rl-deactivate-plugin-simple">' . __( 'Deactivate', 'responsive-lightbox' ) . '</a>
978 <a href="' . $this->deactivaion_url . '" class="button button-primary right rl-deactivate-plugin-data">' . __( 'Deactivate & Submit', 'responsive-lightbox' ) . '</a>
979 <span class="spinner"></span>
980 </div>
981 </div>
982 </div>';
983 }
984
985 /**
986 * Send data about deactivation of the plugin.
987 *
988 * @return void
989 */
990 public function deactivate_plugin() {
991 // check permissions
992 if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'rl-deactivate-plugin' ) === false )
993 return;
994
995 if ( isset( $_POST['option_id'] ) ) {
996 $option_id = (int) $_POST['option_id'];
997 $other = esc_html( $_POST['other'] );
998
999 // avoid fake submissions
1000 if ( $option_id == 6 && $other == '' )
1001 wp_send_json_success();
1002
1003 wp_remote_post(
1004 'https://dfactory.eu/wp-json/api/v1/forms/', array(
1005 'timeout' => 5,
1006 'blocking' => true,
1007 'headers' => array(),
1008 'body' => array(
1009 'id' => 13,
1010 'option' => $option_id,
1011 'other' => $other
1012 )
1013 )
1014 );
1015
1016 wp_send_json_success();
1017 }
1018
1019 wp_send_json_error();
1020 }
1021
1022 /**
1023 * Initialize remote libraries.
1024 *
1025 * @return void
1026 */
1027 public function init_remote_libraries() {
1028 // include classes
1029 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library.php' );
1030 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library-api.php' );
1031
1032 $this->remote_library = new Responsive_Lightbox_Remote_Library();
1033
1034 // simple html dom
1035 if ( ! function_exists( 'file_get_html' ) )
1036 include_once( RESPONSIVE_LIGHTBOX_PATH . 'library/simplehtmldom/simple_html_dom.php' );
1037
1038 // include providers
1039 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' );
1040 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' );
1041 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-wikimedia.php' );
1042 }
1043
1044 /**
1045 * Initialize galleries.
1046 *
1047 * @return void
1048 */
1049 public function init_galleries() {
1050 // initialize gallery class
1051 new Responsive_Lightbox_Galleries( ! $this->options['builder']['gallery_builder'] );
1052
1053 // end if in read only mode
1054 if ( ! $this->options['builder']['gallery_builder'] )
1055 return;
1056
1057 $taxonomies = array();
1058
1059 if ( $this->options['builder']['categories'] ) {
1060 $taxonomies[] = 'rl_category';
1061
1062 $data = array(
1063 'public' => true,
1064 'hierarchical' => true,
1065 'labels' => array(
1066 'name' => _x( 'Gallery Categories', 'taxonomy general name', 'responsive-lightbox' ),
1067 'singular_name' => _x( 'Gallery Category', 'taxonomy singular name', 'responsive-lightbox' ),
1068 'search_items' => __( 'Search Gallery Categories', 'responsive-lightbox' ),
1069 'all_items' => __( 'All Gallery Categories', 'responsive-lightbox' ),
1070 'parent_item' => __( 'Parent Gallery Category', 'responsive-lightbox' ),
1071 'parent_item_colon' => __( 'Parent Gallery Category:', 'responsive-lightbox' ),
1072 'edit_item' => __( 'Edit Gallery Category', 'responsive-lightbox' ),
1073 'view_item' => __( 'View Gallery Category', 'responsive-lightbox' ),
1074 'update_item' => __( 'Update Gallery Category', 'responsive-lightbox' ),
1075 'add_new_item' => __( 'Add New Gallery Category', 'responsive-lightbox' ),
1076 'new_item_name' => __( 'New Gallery Category Name', 'responsive-lightbox' ),
1077 'menu_name' => __( 'Categories', 'responsive-lightbox' )
1078 ),
1079 'show_ui' => true,
1080 'show_admin_column' => true,
1081 'update_count_callback' => '_update_post_term_count',
1082 'query_var' => true,
1083 'rewrite' => array(
1084 'slug' => $this->options['builder']['permalink_categories'],
1085 'with_front' => false,
1086 'hierarchical' => false
1087 )
1088 );
1089
1090 if ( $this->options['capabilities']['active'] ) {
1091 $data['capabilities'] = array(
1092 'manage_terms' => 'manage_gallery_categories',
1093 'edit_terms' => 'manage_gallery_categories',
1094 'delete_terms' => 'manage_gallery_categories',
1095 'assign_terms' => 'edit_galleries'
1096 );
1097 }
1098
1099 register_taxonomy( 'rl_category', 'rl_gallery', $data );
1100 }
1101
1102 if ( $this->options['builder']['tags'] ) {
1103 $taxonomies[] = 'rl_tag';
1104
1105 $data = array(
1106 'public' => true,
1107 'hierarchical' => false,
1108 'labels' => array(
1109 'name' => _x( 'Gallery Tags', 'taxonomy general name', 'responsive-lightbox' ),
1110 'singular_name' => _x( 'Gallery Tag', 'taxonomy singular name', 'responsive-lightbox' ),
1111 'search_items' => __( 'Search Gallery Tags', 'responsive-lightbox' ),
1112 'popular_items' => __( 'Popular Gallery Tags', 'responsive-lightbox' ),
1113 'all_items' => __( 'All Gallery Tags', 'responsive-lightbox' ),
1114 'parent_item' => null,
1115 'parent_item_colon' => null,
1116 'edit_item' => __( 'Edit Gallery Tag', 'responsive-lightbox' ),
1117 'update_item' => __( 'Update Gallery Tag', 'responsive-lightbox' ),
1118 'add_new_item' => __( 'Add New Gallery Tag', 'responsive-lightbox' ),
1119 'new_item_name' => __( 'New Gallery Tag Name', 'responsive-lightbox' ),
1120 'separate_items_with_commas' => __( 'Separate gallery tags with commas', 'responsive-lightbox' ),
1121 'add_or_remove_items' => __( 'Add or remove gallery tags', 'responsive-lightbox' ),
1122 'choose_from_most_used' => __( 'Choose from the most used gallery tags', 'responsive-lightbox' ),
1123 'menu_name' => __( 'Tags', 'responsive-lightbox' )
1124 ),
1125 'show_ui' => true,
1126 'show_admin_column' => true,
1127 'update_count_callback' => '_update_post_term_count',
1128 'query_var' => true,
1129 'rewrite' => array(
1130 'slug' => $this->options['builder']['permalink_tags'],
1131 'with_front' => false,
1132 'hierarchical' => false
1133 )
1134 );
1135
1136 if ( $this->options['capabilities']['active'] ) {
1137 $data['capabilities'] = array(
1138 'manage_terms' => 'manage_gallery_tags',
1139 'edit_terms' => 'manage_gallery_tags',
1140 'delete_terms' => 'manage_gallery_tags',
1141 'assign_terms' => 'edit_galleries'
1142 );
1143 }
1144
1145 register_taxonomy( 'rl_tag', 'rl_gallery', $data );
1146 }
1147
1148 $data = array(
1149 'labels' => array(
1150 'name' => _x( 'Galleries', 'post type general name', 'responsive-lightbox' ),
1151 'singular_name' => _x( 'Gallery', 'post type singular name', 'responsive-lightbox' ),
1152 'add_new' => __( 'Add New', 'responsive-lightbox' ),
1153 'add_new_item' => __( 'Add New Gallery', 'responsive-lightbox' ),
1154 'edit_item' => __( 'Edit Gallery', 'responsive-lightbox' ),
1155 'new_item' => __( 'New Gallery', 'responsive-lightbox' ),
1156 'view_item' => __( 'View Gallery', 'responsive-lightbox' ),
1157 'view_items' => __( 'View Galleries', 'responsive-lightbox' ),
1158 'search_items' => __( 'Search Galleries', 'responsive-lightbox' ),
1159 'not_found' => __( 'No galleries found', 'responsive-lightbox' ),
1160 'not_found_in_trash' => __( 'No galleries found in trash', 'responsive-lightbox' ),
1161 'all_items' => __( 'All Galleries', 'responsive-lightbox' ),
1162 'menu_name' => __( 'Gallery', 'responsive-lightbox' )
1163 ),
1164 'description' => '',
1165 'public' => true,
1166 'exclude_from_search' => false,
1167 'publicly_queryable' => true,
1168 'show_ui' => true,
1169 'show_in_menu' => true,
1170 'show_in_admin_bar' => true,
1171 'show_in_nav_menus' => true,
1172 'menu_position' => 57,
1173 'menu_icon' => 'dashicons-format-gallery',
1174 'map_meta_cap' => true,
1175 'hierarchical' => false,
1176 'supports' => array( 'title', 'author', 'thumbnail' ),
1177 'has_archive' => $this->options['builder']['archives'],
1178 'query_var' => true,
1179 'can_export' => true,
1180 'taxonomies' => $taxonomies,
1181 'rewrite' => array(
1182 'slug' => $this->options['builder']['permalink'],
1183 'with_front' => false,
1184 'feed' => true,
1185 'pages' => true
1186 )
1187 );
1188
1189 if ( $this->options['capabilities']['active'] ) {
1190 $data['capability_type'] = array( 'gallery', 'galleries' );
1191 $data['capabilities'] = array(
1192 'publish_posts' => 'publish_galleries',
1193 'edit_posts' => 'edit_galleries',
1194 'edit_published_posts' => 'edit_published_galleries',
1195 'edit_others_posts' => 'edit_others_galleries',
1196 'edit_private_posts' => 'edit_private_galleries',
1197 'delete_posts' => 'delete_galleries',
1198 'delete_published_posts' => 'delete_published_galleries',
1199 'delete_others_posts' => 'delete_others_galleries',
1200 'delete_private_posts' => 'delete_private_galleries',
1201 'read_private_posts' => 'read_private_galleries',
1202 'edit_post' => 'edit_gallery',
1203 'delete_post' => 'delete_gallery',
1204 'read_post' => 'read_gallery'
1205 );
1206 }
1207
1208 // register rl_gallery
1209 register_post_type( 'rl_gallery', $data );
1210
1211 if ( $this->options['builder']['archives'] && $this->options['builder']['archives_category'] !== 'all' && ! is_admin() )
1212 add_action( 'pre_get_posts', array( $this, 'gallery_archives' ) );
1213
1214 add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
1215 }
1216
1217 /**
1218 * Create breadcrumbs.
1219 *
1220 * @return void
1221 */
1222 public function display_breadcrumbs() {
1223 global $pagenow, $typenow;
1224
1225 $breadcrumbs = array();
1226
1227 // get settings
1228 $settings = Responsive_Lightbox()->settings;
1229
1230 // settings?
1231 if ( isset( $_GET['page'] ) && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $settings->tabs ) ) . ')$/', $_GET['page'], $tabs ) === 1 ) {
1232 $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
1233 $section_key = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : ( ! empty( $settings->tabs[$tab_key]['default_section'] ) ? $settings->tabs[$tab_key]['default_section'] : '' );
1234
1235 $breadcrumbs[] = array(
1236 'url' => admin_url( 'admin.php?page=responsive-lightbox-settings' ),
1237 'name' => __( 'Settings', 'responsive-lightbox' )
1238 );
1239
1240 if ( $tab_key === 'configuration' ) {
1241 $breadcrumbs[] = array(
1242 'url' => admin_url( 'admin.php?page=responsive-lightbox-configuration' ),
1243 'name' => $settings->tabs[$tab_key]['name']
1244 );
1245
1246 // valid lightbox script?
1247 if ( array_key_exists( $section_key, $settings->scripts ) ) {
1248 $breadcrumbs[] = array(
1249 'url' => '',
1250 'name' => $settings->scripts[$section_key]['name']
1251 );
1252 }
1253 } elseif ( $tab_key === 'gallery' ) {
1254 $breadcrumbs[] = array(
1255 'url' => admin_url( 'admin.php?page=responsive-lightbox-gallery' ),
1256 'name' => $settings->tabs[$tab_key]['name']
1257 );
1258
1259 // valid gallery?
1260 if ( array_key_exists( $section_key, $settings->tabs['gallery']['sections'] ) ) {
1261 $breadcrumbs[] = array(
1262 'url' => '',
1263 'name' => $settings->tabs['gallery']['sections'][$section_key]
1264 );
1265 }
1266 } else {
1267 $breadcrumbs[] = array(
1268 'url' => '',
1269 'name' => $settings->tabs[$tab_key]['name']
1270 );
1271 }
1272 // gallery listing
1273 } elseif ( $pagenow === 'edit.php' && $typenow === 'rl_gallery' ) {
1274 $breadcrumbs[] = array(
1275 'url' => '',
1276 'name' => __( 'Galleries', 'responsive-lightbox' )
1277 );
1278 // single gallery
1279 } elseif ( $pagenow === 'post.php' && get_post_type() === 'rl_gallery' ) {
1280 $breadcrumbs[] = array(
1281 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1282 'name' => __( 'Galleries', 'responsive-lightbox' )
1283 );
1284
1285 $breadcrumbs[] = array(
1286 'url' => '',
1287 'name' => __( 'Edit gallery', 'responsive-lightbox' )
1288 );
1289 // new gallery
1290 } elseif ( $pagenow === 'post-new.php' && get_post_type() === 'rl_gallery' ) {
1291 $breadcrumbs[] = array(
1292 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1293 'name' => __( 'Galleries', 'responsive-lightbox' )
1294 );
1295
1296 $breadcrumbs[] = array(
1297 'url' => '',
1298 'name' => __( 'New gallery', 'responsive-lightbox' )
1299 );
1300 // gallery taxonomies
1301 } elseif ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' ) {
1302 $breadcrumbs[] = array(
1303 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1304 'name' => __( 'Galleries', 'responsive-lightbox' )
1305 );
1306
1307 // categories
1308 if ( $_GET['taxonomy'] === 'rl_category' ) {
1309 // new category
1310 if ( $pagenow === 'term.php' ) {
1311 $breadcrumbs[] = array(
1312 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1313 'name' => __( 'Categories', 'responsive-lightbox' )
1314 );
1315
1316 $breadcrumbs[] = array(
1317 'url' => '',
1318 'name' => __( 'Edit category', 'responsive-lightbox' )
1319 );
1320 // categories listing
1321 } else {
1322 $breadcrumbs[] = array(
1323 'url' => '',
1324 'name' => __( 'Categories', 'responsive-lightbox' )
1325 );
1326 }
1327 // tags
1328 } elseif ( $_GET['taxonomy'] === 'rl_tag' ) {
1329 // new tag
1330 if ( $pagenow === 'term.php' ) {
1331 $breadcrumbs[] = array(
1332 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1333 'name' => __( 'Tags', 'responsive-lightbox' )
1334 );
1335
1336 $breadcrumbs[] = array(
1337 'url' => '',
1338 'name' => __( 'Edit tag', 'responsive-lightbox' )
1339 );
1340 // tags listing
1341 } else {
1342 $breadcrumbs[] = array(
1343 'url' => '',
1344 'name' => __( 'Tags', 'responsive-lightbox' )
1345 );
1346 }
1347 }
1348 }
1349
1350 // any breadcrumbs?
1351 if ( ! empty( $breadcrumbs ) ) {
1352 array_unshift( $breadcrumbs,
1353 array(
1354 'url' => '',
1355 'name' => __( 'Responsive Lightbox & Gallery', 'responsive-lightbox' )
1356 )
1357 );
1358
1359 $html = array();
1360
1361 foreach ( $breadcrumbs as $breadcrumb ) {
1362 if ( ! empty( $breadcrumb['url'] ) )
1363 $html[] = '<a href="' . esc_url( $breadcrumb['url'] ) . '">' . esc_html( $breadcrumb['name'] ) . '</a>';
1364 else
1365 $html[] = '<span>' . esc_html( $breadcrumb['name'] ) . '</span>';
1366 }
1367
1368 echo '
1369 <div class="responsive-lightbox-breadcrumbs-container">
1370 <div class="responsive-lightbox-breadcrumbs">
1371 <p>' . implode( ' / ', $html ) . '</p>
1372 </div>
1373 </div>';
1374 }
1375 }
1376
1377 /**
1378 * Gallery update messages.
1379 *
1380 * @param array $messages
1381 * @return array
1382 */
1383 public function gallery_archives( $query ) {
1384 if ( is_post_type_archive( 'rl_gallery' ) ) {
1385 $query->set(
1386 'tax_query',
1387 array(
1388 'relation' => 'OR',
1389 array(
1390 'taxonomy' => 'rl_category',
1391 'field' => 'slug',
1392 'terms' => $this->options['builder']['archives_category']
1393 )
1394 )
1395 );
1396 }
1397 }
1398
1399 /**
1400 * Gallery update messages.
1401 *
1402 * @param array $messages
1403 * @return array
1404 */
1405 public function post_updated_messages( $messages ) {
1406 $post = get_post();
1407 $post_type = get_post_type( $post );
1408 $post_type_object = get_post_type_object( $post_type );
1409
1410 $messages['rl_gallery'] = array(
1411 1 => __( 'Gallery updated.', 'responsive-lightbox' ),
1412 4 => __( 'Gallery updated.', 'responsive-lightbox' ),
1413 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Gallery restored to revision from %s', 'responsive-lightbox' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
1414 6 => __( 'Gallery published.', 'responsive-lightbox' ),
1415 7 => __( 'Gallery saved.', 'responsive-lightbox' ),
1416 8 => __( 'Gallery submitted.', 'responsive-lightbox' ),
1417 9 => sprintf(
1418 __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'responsive-lightbox' ),
1419 date_i18n( __( 'M j, Y @ G:i', 'responsive-lightbox' ), strtotime( $post->post_date ) )
1420 ),
1421 10 => __( 'Gallery draft updated.', 'responsive-lightbox' )
1422 );
1423
1424 if ( $post_type_object->publicly_queryable && 'rl_gallery' === $post_type ) {
1425 $permalink = get_permalink( $post->ID );
1426
1427 $view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View gallery', 'responsive-lightbox' ) );
1428 $messages[$post_type][1] .= $view_link;
1429 $messages[$post_type][6] .= $view_link;
1430 $messages[$post_type][9] .= $view_link;
1431
1432 $preview_permalink = add_query_arg( 'preview', 'true', $permalink );
1433 $preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview gallery', 'responsive-lightbox' ) );
1434 $messages[$post_type][8] .= $preview_link;
1435 $messages[$post_type][10] .= $preview_link;
1436 }
1437
1438 return $messages;
1439 }
1440
1441 /**
1442 * Initialize folders.
1443 *
1444 * @return void
1445 */
1446 public function init_folders() {
1447 // initialize folder class
1448 new Responsive_Lightbox_Folders( ! $this->options['folders']['active'] );
1449
1450 // end if in read only mode
1451 if ( ! $this->options['folders']['active'] )
1452 return;
1453
1454 // register media taxonomy
1455 $this->register_media_taxonomy( 'rl_media_folder' );
1456
1457 // register media tags
1458 if ( $this->options['folders']['media_tags'] ) {
1459 register_taxonomy(
1460 'rl_media_tag',
1461 'attachment',
1462 array(
1463 'public' => true,
1464 'hierarchical' => false,
1465 'labels' => array(
1466 'name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ),
1467 'singular_name' => _x( 'Tag', 'taxonomy singular name', 'responsive-lightbox' ),
1468 'search_items' => __( 'Search Tags', 'responsive-lightbox' ),
1469 'all_items' => __( 'All Tags', 'responsive-lightbox' ),
1470 'edit_item' => __( 'Edit Tag', 'responsive-lightbox' ),
1471 'update_item' => __( 'Update Tag', 'responsive-lightbox' ),
1472 'add_new_item' => __( 'Add New Tag', 'responsive-lightbox' ),
1473 'new_item_name' => __( 'New Tag Name', 'responsive-lightbox' ),
1474 'not_found' => __( 'No tags found.', 'responsive-lightbox' ),
1475 'menu_name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ),
1476 ),
1477 'show_ui' => true,
1478 'show_in_menu' => $this->options['folders']['show_in_menu'],
1479 'show_in_nav_menus' => false,
1480 'show_in_quick_edit' => true,
1481 'show_tagcloud' => false,
1482 'show_admin_column' => $this->options['folders']['show_in_menu'],
1483 'update_count_callback' => '_update_generic_term_count',
1484 'query_var' => false,
1485 'rewrite' => false
1486 )
1487 );
1488 }
1489
1490 // get non-builtin hierarchical taxonomies
1491 $taxonomies = get_taxonomies(
1492 array(
1493 'object_type' => array( 'attachment' ),
1494 'hierarchical' => true,
1495 '_builtin' => false
1496 ),
1497 'objects',
1498 'and'
1499 );
1500
1501 $media_taxonomies = array();
1502
1503 foreach ( $taxonomies as $taxonomy => $object ) {
1504 $media_taxonomies[$taxonomy] = $taxonomy . ' (' . $object->labels->menu_name . ')';
1505 }
1506
1507 $tax = $this->options['folders']['media_taxonomy'];
1508
1509 // selected hierarchical taxonomy does not exists?
1510 if ( ! in_array( $tax, $media_taxonomies, true ) ) {
1511 // check taxonomy existence
1512 if ( ( $taxonomy = get_taxonomy( $tax ) ) !== false ) {
1513 // update
1514 $media_taxonomies[$tax] = $tax . ' (' . $taxonomy->labels->menu_name . ')';
1515 // is it really old taxonomy?
1516 } elseif ( in_array( $tax, Responsive_Lightbox()->folders->get_taxonomies(), true ) ) {
1517 $this->register_media_taxonomy( $tax );
1518
1519 $media_taxonomies[$tax] = $tax;
1520 // use default taxonomy
1521 } else {
1522 $media_taxonomies[$tax] = $tax;
1523 $this->options['folders']['media_taxonomy'] = $this->defaults['folders']['media_taxonomy'];
1524
1525 update_option( 'responsive_lightbox_folders', $this->options['folders'] );
1526 }
1527 }
1528
1529 $this->settings->settings['folders']['fields']['media_taxonomy']['options'] = $media_taxonomies;
1530 }
1531
1532 /**
1533 * Register media taxonomy.
1534 *
1535 * @return void
1536 */
1537 public function register_media_taxonomy( $taxonomy ) {
1538 $show_in_menu = ( $this->options['folders']['show_in_menu'] && ( ( $taxonomy === 'rl_media_folder' && $this->options['folders']['media_taxonomy'] === 'rl_media_folder' ) || ( $taxonomy !== 'rl_media_folder' && $this->options['folders']['media_taxonomy'] !== 'rl_media_folder' ) ) );
1539
1540 register_taxonomy(
1541 $taxonomy,
1542 'attachment',
1543 array(
1544 'public' => true,
1545 'hierarchical' => true,
1546 'labels' => array(
1547 'name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ),
1548 'singular_name' => _x( 'Folder', 'taxonomy singular name', 'responsive-lightbox' ),
1549 'search_items' => __( 'Search Folders', 'responsive-lightbox' ),
1550 'all_items' => __( 'All Files', 'responsive-lightbox' ),
1551 'parent_item' => __( 'Parent Folder', 'responsive-lightbox' ),
1552 'parent_item_colon' => __( 'Parent Folder:', 'responsive-lightbox' ),
1553 'edit_item' => __( 'Edit Folder', 'responsive-lightbox' ),
1554 'update_item' => __( 'Update Folder', 'responsive-lightbox' ),
1555 'add_new_item' => __( 'Add New Folder', 'responsive-lightbox' ),
1556 'new_item_name' => __( 'New Folder Name', 'responsive-lightbox' ),
1557 'not_found' => __( 'No folders found.', 'responsive-lightbox' ),
1558 'menu_name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ),
1559 ),
1560 'show_ui' => ! ( $taxonomy === 'rl_media_folder' && $this->options['folders']['media_taxonomy'] !== 'rl_media_folder' ),
1561 'show_in_menu' => $show_in_menu,
1562 'show_in_nav_menus' => false,
1563 'show_in_quick_edit' => true,
1564 'show_tagcloud' => false,
1565 'show_admin_column' => $show_in_menu,
1566 'update_count_callback' => '_update_generic_term_count',
1567 'query_var' => false,
1568 'rewrite' => false
1569 )
1570 );
1571 }
1572
1573 /**
1574 * Enqueue admin scripts and styles.
1575 *
1576 * @param string $page
1577 * @return void
1578 */
1579 public function admin_scripts_styles( $page ) {
1580 global $typenow;
1581
1582 // settings?
1583 if ( preg_match( '/^(toplevel|lightbox)_page_responsive-lightbox-(' . implode( '|', array_keys( Responsive_Lightbox()->settings->tabs ) ) . ')$/', $page ) === 1 ) {
1584 wp_enqueue_script( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/js/admin.js', array( 'jquery', 'wp-color-picker' ), $this->defaults['version'] );
1585
1586 wp_localize_script(
1587 'responsive-lightbox-admin',
1588 'rlArgsAdmin',
1589 array(
1590 'resetSettingsToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ),
1591 'tax_nonce' => wp_create_nonce( 'rl-folders-ajax-taxonomies-nonce' )
1592 )
1593 );
1594
1595 wp_enqueue_style( 'wp-color-picker' );
1596
1597 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] );
1598 // galleries?
1599 } elseif ( in_array( $page, array( 'post.php', 'post-new.php' ), true ) && get_post_type() === 'rl_gallery' || ( $page === 'edit.php' && $typenow === 'rl_gallery' ) ) {
1600 wp_enqueue_media();
1601
1602 wp_enqueue_script( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2.full' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ), $this->defaults['version'] );
1603
1604 wp_enqueue_script( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/js/admin-galleries.js', array( 'jquery', 'underscore', 'wp-color-picker' ), $this->defaults['version'] );
1605
1606 wp_localize_script(
1607 'responsive-lightbox-admin-galleries',
1608 'rlArgsGalleries',
1609 array(
1610 'mediaItemTemplate' => $this->galleries->get_media_item_template( $this->galleries->fields['images']['media']['attachments']['preview'] ),
1611 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ),
1612 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ),
1613 'editTitle' => __( 'Edit attachment', 'responsive-lightbox' ),
1614 'buttonEditFile' => __( 'Save attachment', 'responsive-lightbox' ),
1615 'nonce' => wp_create_nonce( 'rl-gallery' ),
1616 'post_id' => get_the_ID()
1617 )
1618 );
1619
1620 wp_enqueue_style( 'wp-color-picker' );
1621
1622 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] );
1623
1624 wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', array(), $this->defaults['version'] );
1625
1626 wp_enqueue_style( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/css/admin-galleries.css', array(), $this->defaults['version'] );
1627 // plugins?
1628 } elseif ( $page === 'plugins.php' ) {
1629 add_thickbox();
1630
1631 wp_enqueue_script( 'responsive-lightbox-admin-plugins', RESPONSIVE_LIGHTBOX_URL . '/js/admin-plugins.js', array( 'jquery' ), $this->defaults['version'] );
1632
1633 wp_enqueue_style( 'responsive-lightbox-admin-plugins', RESPONSIVE_LIGHTBOX_URL . '/css/admin-plugins.css', array(), $this->defaults['version'] );
1634
1635 wp_localize_script(
1636 'responsive-lightbox-admin-plugins',
1637 'rlArgsPlugins',
1638 array(
1639 'deactivate' => __( 'Responsive Lightbox & Gallery - Deactivation survey', 'responsive-lightbox' ),
1640 'nonce' => wp_create_nonce( 'rl-deactivate-plugin' )
1641 )
1642 );
1643 // taxonomies?
1644 } elseif ( in_array( $page, array( 'edit-tags.php', 'term.php' ), true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' )
1645 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] );
1646 }
1647
1648 /**
1649 * Init Gutenberg.
1650 *
1651 * @return void
1652 */
1653 public function init_gutenberg() {
1654 // actions
1655 add_action( 'enqueue_block_editor_assets', array( $this, 'gutenberg_enqueue_scripts' ) );
1656
1657 // filters
1658 add_filter( 'block_categories', array( $this, 'block_category' ) );
1659 }
1660
1661 /**
1662 * Create block category.
1663 *
1664 * @return array
1665 */
1666 function block_category( $categories ) {
1667 return array_merge(
1668 $categories,
1669 array(
1670 array(
1671 'slug' => 'responsive-lightbox',
1672 'title' => 'Responsive Lightbox'
1673 )
1674 )
1675 );
1676 }
1677
1678 /**
1679 * Extend Gutenberg.
1680 *
1681 * @return void
1682 */
1683 public function gutenberg_enqueue_scripts() {
1684 $rl = Responsive_Lightbox();
1685
1686 // enqueue script
1687 wp_enqueue_script( 'responsive-lightbox-block-editor-script', RESPONSIVE_LIGHTBOX_URL . '/js/gutenberg.min.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-components' ), $rl->defaults['version'] );
1688
1689 // enqueue styles
1690 wp_enqueue_style( 'responsive-lightbox-block-editor-styles', RESPONSIVE_LIGHTBOX_URL . '/css/gutenberg.min.css', '', $rl->defaults['version'] );
1691
1692 wp_localize_script(
1693 'responsive-lightbox-block-editor-script',
1694 'rlBlockEditor',
1695 array(
1696 'active' => true
1697 )
1698 );
1699
1700 // enqueue gallery
1701 $rl->galleries->enqueue_gallery_scripts_styles();
1702
1703 // register gallery block
1704 register_block_type(
1705 'responsive-lightbox/gallery',
1706 array(
1707 'editor_script' => 'block-editor-script'
1708 )
1709 );
1710
1711 // register remote library image block
1712 register_block_type(
1713 'responsive-lightbox/remote-library-image',
1714 array(
1715 'editor_script' => 'block-editor-script'
1716 )
1717 );
1718 }
1719
1720 /**
1721 * Enqueue admin widget scripts.
1722 *
1723 * @return void
1724 */
1725 public function sidebar_admin_setup() {
1726 wp_enqueue_media();
1727
1728 wp_enqueue_script( 'responsive-lightbox-admin-widgets', RESPONSIVE_LIGHTBOX_URL . '/js/admin-widgets.js', array( 'jquery', 'underscore' ), $this->defaults['version'] );
1729
1730 wp_localize_script(
1731 'responsive-lightbox-admin-widgets',
1732 'rlArgsWidgets',
1733 array(
1734 'textRemoveImage' => __( 'Remove image', 'responsive-lightbox' ),
1735 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ),
1736 'textSelectImage' => __( 'Select image', 'responsive-lightbox' ),
1737 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ),
1738 'textUseImage' => __( 'Use this image', 'responsive-lightbox' )
1739 )
1740 );
1741
1742 wp_register_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] );
1743 wp_enqueue_style( 'responsive-lightbox-admin' );
1744 }
1745
1746 /**
1747 * Enqueue frontend scripts and styles.
1748 *
1749 * @return void
1750 */
1751 public function front_scripts_styles() {
1752 $args = apply_filters(
1753 'rl_lightbox_args',
1754 array(
1755 'script' => $this->options['settings']['script'],
1756 'selector' => $this->options['settings']['selector'],
1757 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? $this->options['settings']['custom_events'] : '' ),
1758 'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )
1759 )
1760 );
1761
1762 $scripts = array();
1763 $styles = array();
1764
1765 switch ( $args['script'] ) {
1766 case 'prettyphoto':
1767 wp_register_script(
1768 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/jquery.prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1769 );
1770
1771 wp_register_style(
1772 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1773 );
1774
1775 $scripts[] = 'responsive-lightbox-prettyphoto';
1776 $styles[] = 'responsive-lightbox-prettyphoto';
1777
1778 $args = array_merge(
1779 $args,
1780 array(
1781 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'],
1782 'slideshow' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow'] ),
1783 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'],
1784 'slideshowAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow_autoplay'] ),
1785 'opacity' => sprintf( '%.2f', ($this->options['configuration']['prettyphoto']['opacity'] / 100 ) ),
1786 'showTitle' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['show_title'] ),
1787 'allowResize' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_resize'] ),
1788 'allowExpand' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_expand'] ),
1789 'width' => $this->options['configuration']['prettyphoto']['width'],
1790 'height' => $this->options['configuration']['prettyphoto']['height'],
1791 'separator' => $this->options['configuration']['prettyphoto']['separator'],
1792 'theme' => $this->options['configuration']['prettyphoto']['theme'],
1793 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'],
1794 'hideFlash' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['hide_flash'] ),
1795 'wmode' => $this->options['configuration']['prettyphoto']['wmode'],
1796 'videoAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['video_autoplay'] ),
1797 'modal' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['modal'] ),
1798 'deeplinking' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['deeplinking'] ),
1799 'overlayGallery' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['overlay_gallery'] ),
1800 'keyboardShortcuts' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['keyboard_shortcuts'] ),
1801 'social' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['social'] )
1802 )
1803 );
1804 break;
1805
1806 case 'swipebox':
1807 wp_register_script(
1808 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/jquery.swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1809 );
1810
1811 wp_register_style(
1812 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1813 );
1814
1815 $scripts[] = 'responsive-lightbox-swipebox';
1816 $styles[] = 'responsive-lightbox-swipebox';
1817
1818 $args = array_merge(
1819 $args, array(
1820 'animation' => $this->get_boolean_value( ($this->options['configuration']['swipebox']['animation'] === 'css' ? true : false ) ),
1821 'hideCloseButtonOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_close_mobile'] ),
1822 'removeBarsOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['remove_bars_mobile'] ),
1823 'hideBars' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_bars'] ),
1824 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'],
1825 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'],
1826 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'],
1827 'loopAtEnd' => $this->get_boolean_value( $this->options['configuration']['swipebox']['loop_at_end'] )
1828 )
1829 );
1830 break;
1831
1832 case 'fancybox':
1833 wp_register_script(
1834 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1835 );
1836
1837 wp_register_style(
1838 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1839 );
1840
1841 $scripts[] = 'responsive-lightbox-fancybox';
1842 $styles[] = 'responsive-lightbox-fancybox';
1843
1844 $args = array_merge(
1845 $args, array(
1846 'modal' => $this->get_boolean_value( $this->options['configuration']['fancybox']['modal'] ),
1847 'showOverlay' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_overlay'] ),
1848 'showCloseButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_close_button'] ),
1849 'enableEscapeButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['enable_escape_button'] ),
1850 'hideOnOverlayClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_overlay_click'] ),
1851 'hideOnContentClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_content_click'] ),
1852 'cyclic' => $this->get_boolean_value( $this->options['configuration']['fancybox']['cyclic'] ),
1853 'showNavArrows' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_nav_arrows'] ),
1854 'autoScale' => $this->get_boolean_value( $this->options['configuration']['fancybox']['auto_scale'] ),
1855 'scrolling' => $this->options['configuration']['fancybox']['scrolling'],
1856 'centerOnScroll' => $this->get_boolean_value( $this->options['configuration']['fancybox']['center_on_scroll'] ),
1857 'opacity' => $this->get_boolean_value( $this->options['configuration']['fancybox']['opacity'] ),
1858 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'],
1859 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'],
1860 'titleShow' => $this->get_boolean_value( $this->options['configuration']['fancybox']['title_show'] ),
1861 'titlePosition' => $this->options['configuration']['fancybox']['title_position'],
1862 'transitions' => $this->options['configuration']['fancybox']['transitions'],
1863 'easings' => $this->options['configuration']['fancybox']['easings'],
1864 'speeds' => $this->options['configuration']['fancybox']['speeds'],
1865 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'],
1866 'changeFade' => $this->options['configuration']['fancybox']['change_fade'],
1867 'padding' => $this->options['configuration']['fancybox']['padding'],
1868 'margin' => $this->options['configuration']['fancybox']['margin'],
1869 'videoWidth' => $this->options['configuration']['fancybox']['video_width'],
1870 'videoHeight' => $this->options['configuration']['fancybox']['video_height']
1871 )
1872 );
1873 break;
1874
1875 case 'nivo':
1876 wp_register_script(
1877 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ), $this->defaults['version']
1878 );
1879
1880 wp_register_style(
1881 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1882 );
1883
1884 wp_register_style(
1885 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ ), array(), $this->defaults['version']
1886 );
1887
1888 $scripts[] = 'responsive-lightbox-nivo';
1889 $styles[] = 'responsive-lightbox-nivo';
1890 $styles[] = 'responsive-lightbox-nivo-default';
1891
1892 $args = array_merge(
1893 $args, array(
1894 'effect' => $this->options['configuration']['nivo']['effect'],
1895 'clickOverlayToClose' => $this->get_boolean_value( $this->options['configuration']['nivo']['click_overlay_to_close'] ),
1896 'keyboardNav' => $this->get_boolean_value( $this->options['configuration']['nivo']['keyboard_nav'] ),
1897 'errorMessage' => esc_attr( $this->options['configuration']['nivo']['error_message'] )
1898 )
1899 );
1900 break;
1901
1902 case 'imagelightbox':
1903 wp_register_script(
1904 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1905 );
1906
1907 wp_register_style(
1908 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1909 );
1910
1911 $scripts[] = 'responsive-lightbox-imagelightbox';
1912 $styles[] = 'responsive-lightbox-imagelightbox';
1913
1914 $args = array_merge(
1915 $args, array(
1916 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'],
1917 'preloadNext' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['preload_next'] ),
1918 'enableKeyboard' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['enable_keyboard'] ),
1919 'quitOnEnd' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_end'] ),
1920 'quitOnImageClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_image_click'] ),
1921 'quitOnDocumentClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_document_click'] ),
1922 )
1923 );
1924 break;
1925
1926 case 'tosrus':
1927 // swipe support, enqueue Hammer.js on mobile devices only
1928 if ( wp_is_mobile() ) {
1929 wp_register_script(
1930 'responsive-lightbox-hammer-js', plugins_url( 'assets/tosrus/hammer' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array(), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1931 );
1932 $scripts[] = 'responsive-lightbox-hammer-js';
1933 }
1934
1935 wp_register_script(
1936 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1937 );
1938
1939 wp_register_style(
1940 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1941 );
1942
1943 $scripts[] = 'responsive-lightbox-tosrus';
1944 $styles[] = 'responsive-lightbox-tosrus';
1945
1946 $args = array_merge( $args, array(
1947 'effect' => $this->options['configuration']['tosrus']['effect'],
1948 'infinite' => $this->get_boolean_value( $this->options['configuration']['tosrus']['infinite'] ),
1949 'keys' => $this->get_boolean_value( $this->options['configuration']['tosrus']['keys'] ),
1950 'autoplay' => $this->get_boolean_value( $this->options['configuration']['tosrus']['autoplay'] ),
1951 'pauseOnHover' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pause_on_hover'] ),
1952 'timeout' => $this->options['configuration']['tosrus']['timeout'],
1953 'pagination' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pagination'] ),
1954 'paginationType' => $this->options['configuration']['tosrus']['pagination_type'],
1955 'closeOnClick' => $this->get_boolean_value( $this->options['configuration']['tosrus']['close_on_click'] )
1956 )
1957 );
1958 break;
1959
1960 case 'featherlight':
1961 wp_register_script(
1962 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1963 );
1964
1965 wp_register_style(
1966 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1967 );
1968
1969 wp_register_script(
1970 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
1971 );
1972
1973 wp_register_style(
1974 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1975 );
1976
1977 $scripts[] = 'responsive-lightbox-featherlight';
1978 $styles[] = 'responsive-lightbox-featherlight';
1979 $scripts[] = 'responsive-lightbox-featherlight-gallery';
1980 $styles[] = 'responsive-lightbox-featherlight-gallery';
1981
1982 $args = array_merge(
1983 $args,
1984 array(
1985 'openSpeed' => $this->options['configuration']['featherlight']['open_speed'],
1986 'closeSpeed' => $this->options['configuration']['featherlight']['close_speed'],
1987 'closeOnClick' => $this->options['configuration']['featherlight']['close_on_click'],
1988 'closeOnEsc' => $this->get_boolean_value( $this->options['configuration']['featherlight']['close_on_esc'] ),
1989 'galleryFadeIn' => $this->options['configuration']['featherlight']['gallery_fade_in'],
1990 'galleryFadeOut' => $this->options['configuration']['featherlight']['gallery_fade_out']
1991 )
1992 );
1993 break;
1994
1995 case 'magnific':
1996 wp_register_script( 'responsive-lightbox-magnific', plugins_url( 'assets/magnific/jquery.magnific-popup' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ( $this->options['settings']['loading_place'] === 'header' ? false : true ) );
1997
1998 wp_register_style( 'responsive-lightbox-magnific', plugins_url( 'assets/magnific/magnific-popup' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] );
1999
2000 $scripts[] = 'responsive-lightbox-magnific';
2001 $styles[] = 'responsive-lightbox-magnific';
2002
2003 $args = array_merge(
2004 $args,
2005 array(
2006 'disableOn' => $this->options['configuration']['magnific']['disable_on'],
2007 'midClick' => $this->options['configuration']['magnific']['mid_click'],
2008 'preloader' => $this->options['configuration']['magnific']['preloader'],
2009 'closeOnContentClick' => $this->options['configuration']['magnific']['close_on_content_click'],
2010 'closeOnBgClick' => $this->options['configuration']['magnific']['close_on_background_click'],
2011 'closeBtnInside' => $this->options['configuration']['magnific']['close_button_inside'],
2012 'showCloseBtn' => $this->options['configuration']['magnific']['show_close_button'],
2013 'enableEscapeKey' => $this->options['configuration']['magnific']['enable_escape_key'],
2014 'alignTop' => $this->options['configuration']['magnific']['align_top'],
2015 'fixedContentPos' => $this->options['configuration']['magnific']['fixed_content_position'],
2016 'fixedBgPos' => $this->options['configuration']['magnific']['fixed_background_position'],
2017 'autoFocusLast' => $this->options['configuration']['magnific']['auto_focus_last']
2018 )
2019 );
2020 break;
2021
2022 default:
2023 do_action( 'rl_lightbox_enqueue_scripts' );
2024
2025 $scripts = apply_filters( 'rl_lightbox_scripts', $scripts );
2026 $styles = apply_filters( 'rl_lightbox_styles', $styles );
2027 }
2028
2029 // run scripts by default
2030 $contitional_scripts = true;
2031
2032 if ( $this->options['settings']['conditional_loading'] === true ) {
2033 global $post;
2034
2035 if ( is_object( $post ) ) {
2036 // is gallery present in content
2037 $has_gallery = has_shortcode( $post->post_content, 'gallery' ) || has_shortcode( $post->post_content, 'rl_gallery' );
2038
2039 // are images present in content
2040 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $post->post_content, $links );
2041
2042 $has_images = (bool) $links[0];
2043
2044 if ( $has_gallery === false && $has_images === false )
2045 $contitional_scripts = false;
2046 }
2047 }
2048
2049 if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) {
2050 wp_register_script( 'responsive-lightbox-infinite-scroll', RESPONSIVE_LIGHTBOX_URL . '/assets/infinitescroll/infinite-scroll.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) );
2051 wp_register_script( 'responsive-lightbox-images-loaded', RESPONSIVE_LIGHTBOX_URL . '/assets/imagesloaded/imagesloaded.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) );
2052 wp_register_script( 'responsive-lightbox-masonry', RESPONSIVE_LIGHTBOX_URL . '/assets/masonry/masonry.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ), Responsive_Lightbox()->defaults['version'], ( Responsive_Lightbox()->options['settings']['loading_place'] === 'footer' ) );
2053
2054 wp_register_script( 'responsive-lightbox', plugins_url( 'js/front.js', __FILE__ ), array( 'jquery', 'underscore', 'responsive-lightbox-infinite-scroll' ), $this->defaults['version'], ( $this->options['settings']['loading_place'] === 'header' ? false : true ) );
2055
2056 $args['woocommerce_gallery'] = 0;
2057
2058 if ( class_exists( 'WooCommerce' ) ) {
2059 global $woocommerce;
2060
2061 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
2062 if ( version_compare( $woocommerce->version, '3.0', ">=" ) )
2063 $args['woocommerce_gallery'] = 1;
2064 }
2065 }
2066
2067 $scripts[] = 'responsive-lightbox';
2068
2069 $args['ajaxurl'] = admin_url( 'admin-ajax.php' );
2070 $args['nonce'] = wp_create_nonce( 'rl_nonce' );
2071
2072 // enqueue scripts
2073 if ( $scripts && is_array( $scripts ) ) {
2074 foreach ( $scripts as $script ) {
2075 wp_enqueue_script( $script );
2076 }
2077
2078 wp_localize_script( 'responsive-lightbox', 'rlArgs', $args );
2079 }
2080
2081 // enqueue styles
2082 if ( $styles && is_array( $styles ) ) {
2083 foreach ( $styles as $style ) {
2084 wp_enqueue_style( $style );
2085 }
2086 }
2087 }
2088
2089 // gallery style
2090 wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), array(), Responsive_Lightbox()->defaults['version'] );
2091 }
2092
2093 /**
2094 * Helper: convert value to boolean
2095 *
2096 * @param int $option
2097 * @return bool
2098 */
2099 private function get_boolean_value( $option ) {
2100 return ( $option == true ? 1 : 0 );
2101 }
2102
2103 /**
2104 * Helper: convert hex color to rgb color.
2105 *
2106 * @param type $color
2107 * @return array
2108 */
2109 public function hex2rgb( $color ) {
2110 if ( $color[0] == '#' )
2111 $color = substr( $color, 1 );
2112
2113 if ( strlen( $color ) == 6 )
2114 list( $r, $g, $b ) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
2115 elseif ( strlen( $color ) == 3 )
2116 list( $r, $g, $b ) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
2117 else
2118 return false;
2119
2120 $r = hexdec( $r );
2121 $g = hexdec( $g );
2122 $b = hexdec( $b );
2123
2124 return array( $r, $g, $b );
2125 }
2126 }
2127
2128 /**
2129 * Initialize Responsive Lightbox.
2130 */
2131 function Responsive_Lightbox() {
2132 static $instance;
2133
2134 // first call to instance() initializes the plugin
2135 if ( $instance === null || ! ( $instance instanceof Responsive_Lightbox ) )
2136 $instance = Responsive_Lightbox::instance();
2137
2138 return $instance;
2139 }
2140
2141 $responsive_lightbox = Responsive_Lightbox();