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