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