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