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