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