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