PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.4.5
Responsive Lightbox & Gallery v2.4.5
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 3 years ago css 3 years ago font 8 years ago images 3 years ago includes 3 years ago js 3 years ago languages 3 years ago index.php 12 years ago readme.txt 3 years ago responsive-lightbox.php 3 years ago wpml-config.xml 8 years ago
responsive-lightbox.php
2223 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.5
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.5
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.5',
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 /**
807 * Dismiss notice.
808 *
809 * @return void
810 */
811 public function dismiss_notice() {
812 if ( ! current_user_can( 'install_plugins' ) )
813 return;
814
815 if ( isset( $_REQUEST['nonce'] ) && ctype_alnum( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], 'rl_dismiss_notice' ) ) {
816 $notice_action = isset( $_REQUEST['notice_action'] ) ? sanitize_key( $_REQUEST['notice_action'] ) : '';
817
818 if ( empty( $notice_action ) || $notice_action === 'hide' )
819 $notice_action = 'hide';
820
821 switch ( $notice_action ) {
822 // delay notice
823 case 'delay':
824 // set delay period to 1 week from now
825 $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_delay_date' => time() + 2 * WEEK_IN_SECONDS ] );
826 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
827 break;
828
829 // hide notice
830 default:
831 $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_notice' => false ] );
832 $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_delay_date' => 0 ] );
833
834 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
835 }
836 }
837
838 exit;
839 }
840
841 /**
842 * Add admin notices.
843 *
844 * @param string $html Notice HTML
845 * @param string $status Notice status
846 * @param bool $paragraph Whether to use paragraph
847 * @param bool $network
848 * @return void
849 */
850 public function add_notice( $html = '', $status = 'error', $paragraph = true, $network = false ) {
851 $this->notices[] = [
852 'html' => $html,
853 'status' => $status,
854 'paragraph' => $paragraph
855 ];
856
857 add_action( 'admin_notices', [ $this, 'display_notice' ] );
858
859 if ( $network )
860 add_action( 'network_admin_notices', [ $this, 'display_notice' ] );
861 }
862
863 /**
864 * Print admin notices.
865 *
866 * @return void
867 */
868 public function display_notice() {
869 foreach( $this->notices as $notice ) {
870 echo '
871 <div class="' . esc_attr( $notice['status'] ) . '">
872 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
873 ' . wp_kses_post( $notice['html'] ) . '
874 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
875 </div>';
876 }
877 }
878
879 /**
880 * Print admin scripts.
881 *
882 * @return void
883 */
884 public function admin_inline_js() {
885 if ( ! current_user_can( 'install_plugins' ) )
886 return;
887 ?>
888 <script type="text/javascript">
889 ( function( $ ) {
890 // ready event
891 $( function() {
892 // save dismiss state
893 $( '.rl-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .rl-dismissible-notice', function( e ) {
894 if ( $(this).attr( 'target' ) !== '_blank' )
895 e.preventDefault();
896
897 var notice_action = 'hide';
898
899 if ( $( e.currentTarget ).hasClass( 'rl-delay-notice' ) )
900 notice_action = 'delay';
901
902 $.post( ajaxurl, {
903 action: 'rl_dismiss_notice',
904 notice_action: notice_action,
905 url: '<?php echo esc_url_raw( admin_url( 'admin-ajax.php' ) ); ?>',
906 nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>'
907 } );
908
909 $( e.delegateTarget ).slideUp( 'fast' );
910 } );
911 } );
912 } )( jQuery );
913 </script>
914 <?php
915 }
916
917 /**
918 * Add links to Support Forum.
919 *
920 * @param array $links
921 * @param string $file
922 * @return array
923 */
924 public function plugin_extend_links( $links, $file ) {
925 if ( ! current_user_can( 'install_plugins' ) )
926 return $links;
927
928 if ( $file === RESPONSIVE_LIGHTBOX_BASENAME )
929 return array_merge( $links, [ sprintf( '<a href="http://www.dfactory.co/support/forum/responsive-lightbox/" target="_blank">%s</a>', esc_html__( 'Support', 'responsive-lightbox' ) ) ] );
930
931 return $links;
932 }
933
934 /**
935 * Add links to Settings page.
936 *
937 * @param array $links
938 * @param string $file
939 * @return array
940 */
941 public function plugin_settings_link( $links, $file ) {
942 if ( ! is_admin() || ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) )
943 return $links;
944
945 if ( ! empty( $links['deactivate'] ) ) {
946 // link already contains class attribute?
947 if ( preg_match( '/<a.*?class=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 )
948 $links['deactivate'] = preg_replace( '/(<a.*?class=(?:\'|").*?)((?:\'|").*?>)/s', '$1 rl-deactivate-plugin-modal$2', $links['deactivate'] );
949 else
950 $links['deactivate'] = preg_replace( '/(<a.*?)>/s', '$1 class="rl-deactivate-plugin-modal">', $links['deactivate'] );
951
952 // link already contains href attribute?
953 if ( preg_match( '/<a.*?href=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 ) {
954 if ( ! empty( $result[2] ) )
955 $this->deactivaion_url = $result[2];
956 }
957 }
958
959 // put settings link at start
960 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' ) ) );
961
962 // add add-ons link
963 $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' ) );
964
965 return $links;
966 }
967
968 /**
969 * Deactivation modal HTML template.
970 *
971 * @return void
972 */
973 public function modal_deactivation_template() {
974 global $pagenow;
975
976 // display only for plugins page
977 if ( $pagenow !== 'plugins.php' )
978 return;
979
980 echo '
981 <div id="rl-deactivation-modal" style="display: none;">
982 <div id="rl-deactivation-container">
983 <div id="rl-deactivation-body">
984 <div class="rl-deactivation-options">
985 <p><em>' . esc_html__( "We're sorry to see you go. Could you please tell us what happened?", 'responsive-lightbox' ) . '</em></p>
986 <ul>';
987
988 foreach ( [
989 '1' => __( "I couldn't figure out how to make it work.", 'responsive-lightbox' ),
990 '2' => __( 'I found another plugin to use for the same task.', 'responsive-lightbox' ),
991 '3' => __( 'The User Interface is not clear to me.', 'responsive-lightbox' ),
992 '4' => __( 'The plugin is not what I was looking for.', 'responsive-lightbox' ),
993 '5' => __( "Support isn't timely.", 'responsive-lightbox' ),
994 '6' => __( 'Other', 'responsive-lightbox' )
995 ] as $option => $text ) {
996 echo '
997 <li><label><input type="radio" name="rl_deactivation_option" value="' . (int) $option . '" ' . checked( '6', $option, false ) . ' />' . esc_html( $text ) . '</label></li>';
998 }
999
1000 echo '
1001 </ul>
1002 </div>
1003 <div class="rl-deactivation-textarea">
1004 <textarea name="rl_deactivation_other"></textarea>
1005 </div>
1006 </div>
1007 <div id="rl-deactivation-footer">
1008 <a href="" class="button rl-deactivate-plugin-cancel">' . esc_html__( 'Cancel', 'responsive-lightbox' ) . '</a>
1009 <a href="' . esc_url( $this->deactivaion_url ) . '" class="button button-secondary rl-deactivate-plugin-simple">' . esc_html__( 'Deactivate', 'responsive-lightbox' ) . '</a>
1010 <a href="' . esc_url( $this->deactivaion_url ) . '" class="button button-primary right rl-deactivate-plugin-data">' . esc_html__( 'Deactivate & Submit', 'responsive-lightbox' ) . '</a>
1011 <span class="spinner"></span>
1012 </div>
1013 </div>
1014 </div>';
1015 }
1016
1017 /**
1018 * Send data about deactivation of the plugin.
1019 *
1020 * @return void
1021 */
1022 public function deactivate_plugin() {
1023 // no nonce?
1024 if ( ! isset( $_POST['nonce'] ) )
1025 return;
1026
1027 if ( ! ctype_alnum( $_POST['nonce'] ) )
1028 return;
1029
1030 // check permissions
1031 if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'rl-deactivate-plugin' ) === false )
1032 return;
1033
1034 if ( isset( $_POST['option_id'] ) ) {
1035 $option_id = (int) $_POST['option_id'];
1036 $other = sanitize_text_field( $_POST['other'] );
1037
1038 // avoid fake submissions
1039 if ( $option_id == 6 && $other == '' )
1040 wp_send_json_success();
1041
1042 wp_remote_post(
1043 'https://www.dfactory.co/wp-json/api/v1/forms/',
1044 [
1045 'timeout' => 5,
1046 'blocking' => true,
1047 'headers' => [],
1048 'body' => [
1049 'id' => 13,
1050 'option' => $option_id,
1051 'other' => $other
1052 ]
1053 ]
1054 );
1055
1056 wp_send_json_success();
1057 }
1058
1059 wp_send_json_error();
1060 }
1061
1062 /**
1063 * Set current lightbox script.
1064 *
1065 * @return bool
1066 */
1067 public function set_lightbox_script( $script ) {
1068 if ( array_key_exists( $script, $this->settings->settings['settings']['fields']['script']['options'] ) ) {
1069 // set new lightbox script
1070 $this->current_script = $script;
1071
1072 return true;
1073 }
1074
1075 return false;
1076 }
1077
1078 /**
1079 * Initialize remote libraries.
1080 *
1081 * @return void
1082 */
1083 public function init_remote_libraries() {
1084 // include classes
1085 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library.php' );
1086 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library-api.php' );
1087
1088 $this->remote_library = new Responsive_Lightbox_Remote_Library();
1089
1090 // include providers
1091 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' );
1092 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' );
1093 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-wikimedia.php' );
1094 }
1095
1096 /**
1097 * Initialize galleries.
1098 *
1099 * @return void
1100 */
1101 public function init_galleries() {
1102 // initialize gallery class
1103 new Responsive_Lightbox_Galleries( ! $this->options['builder']['gallery_builder'] );
1104
1105 // end if in read only mode
1106 if ( ! $this->options['builder']['gallery_builder'] )
1107 return;
1108
1109 $taxonomies = [];
1110
1111 if ( $this->options['builder']['categories'] ) {
1112 $taxonomies[] = 'rl_category';
1113
1114 $data = [
1115 'public' => true,
1116 'hierarchical' => true,
1117 'labels' => [
1118 'name' => _x( 'Gallery Categories', 'taxonomy general name', 'responsive-lightbox' ),
1119 'singular_name' => _x( 'Gallery Category', 'taxonomy singular name', 'responsive-lightbox' ),
1120 'search_items' => __( 'Search Gallery Categories', 'responsive-lightbox' ),
1121 'all_items' => __( 'All Gallery Categories', 'responsive-lightbox' ),
1122 'parent_item' => __( 'Parent Gallery Category', 'responsive-lightbox' ),
1123 'parent_item_colon' => __( 'Parent Gallery Category:', 'responsive-lightbox' ),
1124 'edit_item' => __( 'Edit Gallery Category', 'responsive-lightbox' ),
1125 'view_item' => __( 'View Gallery Category', 'responsive-lightbox' ),
1126 'update_item' => __( 'Update Gallery Category', 'responsive-lightbox' ),
1127 'add_new_item' => __( 'Add New Gallery Category', 'responsive-lightbox' ),
1128 'new_item_name' => __( 'New Gallery Category Name', 'responsive-lightbox' ),
1129 'menu_name' => __( 'Categories', 'responsive-lightbox' )
1130 ],
1131 'show_ui' => true,
1132 'show_admin_column' => true,
1133 'update_count_callback' => '_update_post_term_count',
1134 'query_var' => true,
1135 'rewrite' => [
1136 'slug' => $this->options['builder']['permalink_categories'],
1137 'with_front' => false,
1138 'hierarchical' => false
1139 ]
1140 ];
1141
1142 if ( $this->options['capabilities']['active'] ) {
1143 $data['capabilities'] = [
1144 'manage_terms' => 'manage_gallery_categories',
1145 'edit_terms' => 'manage_gallery_categories',
1146 'delete_terms' => 'manage_gallery_categories',
1147 'assign_terms' => 'edit_galleries'
1148 ];
1149 }
1150
1151 register_taxonomy( 'rl_category', 'rl_gallery', $data );
1152 }
1153
1154 if ( $this->options['builder']['tags'] ) {
1155 $taxonomies[] = 'rl_tag';
1156
1157 $data = [
1158 'public' => true,
1159 'hierarchical' => false,
1160 'labels' => [
1161 'name' => _x( 'Gallery Tags', 'taxonomy general name', 'responsive-lightbox' ),
1162 'singular_name' => _x( 'Gallery Tag', 'taxonomy singular name', 'responsive-lightbox' ),
1163 'search_items' => __( 'Search Gallery Tags', 'responsive-lightbox' ),
1164 'popular_items' => __( 'Popular Gallery Tags', 'responsive-lightbox' ),
1165 'all_items' => __( 'All Gallery Tags', 'responsive-lightbox' ),
1166 'parent_item' => null,
1167 'parent_item_colon' => null,
1168 'edit_item' => __( 'Edit Gallery Tag', 'responsive-lightbox' ),
1169 'update_item' => __( 'Update Gallery Tag', 'responsive-lightbox' ),
1170 'add_new_item' => __( 'Add New Gallery Tag', 'responsive-lightbox' ),
1171 'new_item_name' => __( 'New Gallery Tag Name', 'responsive-lightbox' ),
1172 'separate_items_with_commas' => __( 'Separate gallery tags with commas', 'responsive-lightbox' ),
1173 'add_or_remove_items' => __( 'Add or remove gallery tags', 'responsive-lightbox' ),
1174 'choose_from_most_used' => __( 'Choose from the most used gallery tags', 'responsive-lightbox' ),
1175 'menu_name' => __( 'Tags', 'responsive-lightbox' )
1176 ],
1177 'show_ui' => true,
1178 'show_admin_column' => true,
1179 'update_count_callback' => '_update_post_term_count',
1180 'query_var' => true,
1181 'rewrite' => [
1182 'slug' => $this->options['builder']['permalink_tags'],
1183 'with_front' => false,
1184 'hierarchical' => false
1185 ]
1186 ];
1187
1188 if ( $this->options['capabilities']['active'] ) {
1189 $data['capabilities'] = [
1190 'manage_terms' => 'manage_gallery_tags',
1191 'edit_terms' => 'manage_gallery_tags',
1192 'delete_terms' => 'manage_gallery_tags',
1193 'assign_terms' => 'edit_galleries'
1194 ];
1195 }
1196
1197 register_taxonomy( 'rl_tag', 'rl_gallery', $data );
1198 }
1199
1200 $data = [
1201 'labels' => [
1202 'name' => _x( 'Galleries', 'post type general name', 'responsive-lightbox' ),
1203 'singular_name' => _x( 'Gallery', 'post type singular name', 'responsive-lightbox' ),
1204 'add_new' => __( 'Add New', 'responsive-lightbox' ),
1205 'add_new_item' => __( 'Add New Gallery', 'responsive-lightbox' ),
1206 'edit_item' => __( 'Edit Gallery', 'responsive-lightbox' ),
1207 'new_item' => __( 'New Gallery', 'responsive-lightbox' ),
1208 'view_item' => __( 'View Gallery', 'responsive-lightbox' ),
1209 'view_items' => __( 'View Galleries', 'responsive-lightbox' ),
1210 'search_items' => __( 'Search Galleries', 'responsive-lightbox' ),
1211 'not_found' => __( 'No galleries found', 'responsive-lightbox' ),
1212 'not_found_in_trash' => __( 'No galleries found in trash', 'responsive-lightbox' ),
1213 'all_items' => __( 'All Galleries', 'responsive-lightbox' ),
1214 'menu_name' => __( 'Gallery', 'responsive-lightbox' )
1215 ],
1216 'description' => '',
1217 'public' => true,
1218 'exclude_from_search' => false,
1219 'publicly_queryable' => true,
1220 'show_ui' => true,
1221 'show_in_menu' => true,
1222 'show_in_admin_bar' => true,
1223 'show_in_nav_menus' => true,
1224 'menu_position' => 57,
1225 'menu_icon' => 'dashicons-format-gallery',
1226 'map_meta_cap' => true,
1227 'hierarchical' => false,
1228 'supports' => [ 'title', 'author', 'thumbnail' ],
1229 'has_archive' => $this->options['builder']['archives'],
1230 'query_var' => true,
1231 'can_export' => true,
1232 'taxonomies' => $taxonomies,
1233 'rewrite' => [
1234 'slug' => $this->options['builder']['permalink'],
1235 'with_front' => false,
1236 'feed' => true,
1237 'pages' => true
1238 ]
1239 ];
1240
1241 if ( $this->options['capabilities']['active'] ) {
1242 $data['capability_type'] = [ 'gallery', 'galleries' ];
1243 $data['capabilities'] = [
1244 'publish_posts' => 'publish_galleries',
1245 'edit_posts' => 'edit_galleries',
1246 'edit_published_posts' => 'edit_published_galleries',
1247 'edit_others_posts' => 'edit_others_galleries',
1248 'edit_private_posts' => 'edit_private_galleries',
1249 'delete_posts' => 'delete_galleries',
1250 'delete_published_posts' => 'delete_published_galleries',
1251 'delete_others_posts' => 'delete_others_galleries',
1252 'delete_private_posts' => 'delete_private_galleries',
1253 'read_private_posts' => 'read_private_galleries',
1254 'edit_post' => 'edit_gallery',
1255 'delete_post' => 'delete_gallery',
1256 'read_post' => 'read_gallery'
1257 ];
1258 }
1259
1260 // register rl_gallery
1261 register_post_type( 'rl_gallery', $data );
1262
1263 if ( $this->options['builder']['archives'] && $this->options['builder']['archives_category'] !== 'all' && ! is_admin() )
1264 add_action( 'pre_get_posts', [ $this, 'gallery_archives' ] );
1265
1266 add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ] );
1267 }
1268
1269 /**
1270 * Create breadcrumbs.
1271 *
1272 * @return void
1273 */
1274 public function display_breadcrumbs() {
1275 global $pagenow, $typenow;
1276
1277 $breadcrumbs = [];
1278
1279 // get page
1280 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
1281
1282 // get tabs
1283 $tabs = $this->settings->get_data( 'tabs' );
1284
1285 // settings?
1286 if ( $page && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $tabs ) ) . ')$/', $page, $found_tabs ) === 1 ) {
1287 $tab_key = isset( $found_tabs[1] ) ? $found_tabs[1] : 'settings';
1288 $section_key = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : ( ! empty( $tabs[$tab_key]['default_section'] ) ? $tabs[$tab_key]['default_section'] : '' );
1289
1290 $breadcrumbs[] = [
1291 'url' => admin_url( 'admin.php?page=responsive-lightbox-settings' ),
1292 'name' => __( 'Settings', 'responsive-lightbox' )
1293 ];
1294
1295 if ( $tab_key === 'configuration' ) {
1296 $breadcrumbs[] = [
1297 'url' => admin_url( 'admin.php?page=responsive-lightbox-configuration' ),
1298 'name' => $tabs[$tab_key]['name']
1299 ];
1300
1301 // get scripts
1302 $scripts = $this->settings->get_data( 'scripts' );
1303
1304 // valid lightbox script?
1305 if ( array_key_exists( $section_key, $scripts ) ) {
1306 $breadcrumbs[] = [
1307 'url' => '',
1308 'name' => $scripts[$section_key]['name']
1309 ];
1310 }
1311 } elseif ( $tab_key === 'gallery' ) {
1312 $breadcrumbs[] = [
1313 'url' => admin_url( 'admin.php?page=responsive-lightbox-gallery' ),
1314 'name' => $tabs[$tab_key]['name']
1315 ];
1316
1317 // valid gallery?
1318 if ( array_key_exists( $section_key, $tabs['gallery']['sections'] ) ) {
1319 $breadcrumbs[] = [
1320 'url' => '',
1321 'name' => $tabs['gallery']['sections'][$section_key]
1322 ];
1323 }
1324 } else {
1325 $breadcrumbs[] = [
1326 'url' => '',
1327 'name' => $tabs[$tab_key]['name']
1328 ];
1329 }
1330 // gallery listing
1331 } elseif ( $pagenow === 'edit.php' && $typenow === 'rl_gallery' ) {
1332 $breadcrumbs[] = [
1333 'url' => '',
1334 'name' => __( 'Galleries', 'responsive-lightbox' )
1335 ];
1336 // single gallery
1337 } elseif ( $pagenow === 'post.php' && get_post_type() === 'rl_gallery' ) {
1338 $breadcrumbs[] = [
1339 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1340 'name' => __( 'Galleries', 'responsive-lightbox' )
1341 ];
1342
1343 $breadcrumbs[] = [
1344 'url' => '',
1345 'name' => __( 'Edit gallery', 'responsive-lightbox' )
1346 ];
1347 // new gallery
1348 } elseif ( $pagenow === 'post-new.php' && get_post_type() === 'rl_gallery' ) {
1349 $breadcrumbs[] = [
1350 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1351 'name' => __( 'Galleries', 'responsive-lightbox' )
1352 ];
1353
1354 $breadcrumbs[] = [
1355 'url' => '',
1356 'name' => __( 'New gallery', 'responsive-lightbox' )
1357 ];
1358 // gallery taxonomies
1359 } elseif ( in_array( $pagenow, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) ) {
1360 $post_type = sanitize_key( $_GET['post_type'] );
1361 $taxonomy = sanitize_key( $_GET['taxonomy'] );
1362
1363 if ( $post_type === 'rl_gallery' ) {
1364 $breadcrumbs[] = [
1365 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1366 'name' => __( 'Galleries', 'responsive-lightbox' )
1367 ];
1368
1369 // categories
1370 if ( $taxonomy === 'rl_category' ) {
1371 // new category
1372 if ( $pagenow === 'term.php' ) {
1373 $breadcrumbs[] = [
1374 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1375 'name' => __( 'Categories', 'responsive-lightbox' )
1376 ];
1377
1378 $breadcrumbs[] = [
1379 'url' => '',
1380 'name' => __( 'Edit category', 'responsive-lightbox' )
1381 ];
1382 // categories listing
1383 } else {
1384 $breadcrumbs[] = [
1385 'url' => '',
1386 'name' => __( 'Categories', 'responsive-lightbox' )
1387 ];
1388 }
1389 // tags
1390 } elseif ( $taxonomy === 'rl_tag' ) {
1391 // new tag
1392 if ( $pagenow === 'term.php' ) {
1393 $breadcrumbs[] = [
1394 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1395 'name' => __( 'Tags', 'responsive-lightbox' )
1396 ];
1397
1398 $breadcrumbs[] = [
1399 'url' => '',
1400 'name' => __( 'Edit tag', 'responsive-lightbox' )
1401 ];
1402 // tags listing
1403 } else {
1404 $breadcrumbs[] = [
1405 'url' => '',
1406 'name' => __( 'Tags', 'responsive-lightbox' )
1407 ];
1408 }
1409 }
1410 }
1411 }
1412
1413 // any breadcrumbs?
1414 if ( ! empty( $breadcrumbs ) ) {
1415 array_unshift( $breadcrumbs,
1416 [
1417 'url' => '',
1418 'name' => __( 'Responsive Lightbox & Gallery', 'responsive-lightbox' )
1419 ]
1420 );
1421
1422 $html = [];
1423
1424 foreach ( $breadcrumbs as $breadcrumb ) {
1425 if ( ! empty( $breadcrumb['url'] ) )
1426 $html[] = '<a href="' . esc_url( $breadcrumb['url'] ) . '">' . esc_html( $breadcrumb['name'] ) . '</a>';
1427 else
1428 $html[] = '<span>' . esc_html( $breadcrumb['name'] ) . '</span>';
1429 }
1430
1431 echo '
1432 <div class="responsive-lightbox-breadcrumbs-container">
1433 <div class="responsive-lightbox-breadcrumbs">
1434 <p>' . implode( ' / ', $html ) . '</p>
1435 </div>
1436 </div>';
1437 }
1438 }
1439
1440 /**
1441 * Gallery update messages.
1442 *
1443 * @param array $messages
1444 * @return void
1445 */
1446 public function gallery_archives( $query ) {
1447 if ( is_post_type_archive( 'rl_gallery' ) ) {
1448 $query->set(
1449 'tax_query',
1450 [
1451 'relation' => 'OR',
1452 [
1453 'taxonomy' => 'rl_category',
1454 'field' => 'slug',
1455 'terms' => $this->options['builder']['archives_category']
1456 ]
1457 ]
1458 );
1459 }
1460 }
1461
1462 /**
1463 * Gallery update messages.
1464 *
1465 * @param array $messages
1466 * @return array
1467 */
1468 public function post_updated_messages( $messages ) {
1469 $post = get_post();
1470 $post_type = get_post_type( $post );
1471 $post_type_object = get_post_type_object( $post_type );
1472
1473 $messages['rl_gallery'] = [
1474 1 => __( 'Gallery updated.', 'responsive-lightbox' ),
1475 4 => __( 'Gallery updated.', 'responsive-lightbox' ),
1476 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Gallery restored to revision from %s', 'responsive-lightbox' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
1477 6 => __( 'Gallery published.', 'responsive-lightbox' ),
1478 7 => __( 'Gallery saved.', 'responsive-lightbox' ),
1479 8 => __( 'Gallery submitted.', 'responsive-lightbox' ),
1480 9 => sprintf( __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'responsive-lightbox' ), date_i18n( __( 'M j, Y @ G:i', 'responsive-lightbox' ), strtotime( $post->post_date ) ) ),
1481 10 => __( 'Gallery draft updated.', 'responsive-lightbox' )
1482 ];
1483
1484 if ( $post_type_object->publicly_queryable && 'rl_gallery' === $post_type ) {
1485 $permalink = get_permalink( $post->ID );
1486
1487 $view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View gallery', 'responsive-lightbox' ) );
1488 $messages[$post_type][1] .= $view_link;
1489 $messages[$post_type][6] .= $view_link;
1490 $messages[$post_type][9] .= $view_link;
1491
1492 $preview_permalink = add_query_arg( 'preview', 'true', $permalink );
1493 $preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview gallery', 'responsive-lightbox' ) );
1494 $messages[$post_type][8] .= $preview_link;
1495 $messages[$post_type][10] .= $preview_link;
1496 }
1497
1498 return $messages;
1499 }
1500
1501 /**
1502 * Initialize folders.
1503 *
1504 * @return void
1505 */
1506 public function init_folders() {
1507 // initialize folder class
1508 new Responsive_Lightbox_Folders( ! $this->options['folders']['active'] );
1509
1510 // end if in read only mode
1511 if ( ! $this->options['folders']['active'] )
1512 return;
1513
1514 // register media taxonomy
1515 $this->register_media_taxonomy( 'rl_media_folder' );
1516
1517 // register media tags
1518 if ( $this->options['folders']['media_tags'] ) {
1519 register_taxonomy(
1520 'rl_media_tag',
1521 'attachment',
1522 [
1523 'public' => true,
1524 'hierarchical' => false,
1525 'labels' => [
1526 'name' => _x( 'Media Tags', 'taxonomy general name', 'responsive-lightbox' ),
1527 'singular_name' => _x( 'Media Tag', 'taxonomy singular name', 'responsive-lightbox' ),
1528 'search_items' => __( 'Search Tags', 'responsive-lightbox' ),
1529 'all_items' => __( 'All Tags', 'responsive-lightbox' ),
1530 'edit_item' => __( 'Edit Tag', 'responsive-lightbox' ),
1531 'update_item' => __( 'Update Tag', 'responsive-lightbox' ),
1532 'add_new_item' => __( 'Add New Tag', 'responsive-lightbox' ),
1533 'new_item_name' => __( 'New Tag Name', 'responsive-lightbox' ),
1534 'not_found' => __( 'No tags found.', 'responsive-lightbox' ),
1535 'menu_name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ),
1536 ],
1537 'show_ui' => true,
1538 'show_in_menu' => $this->options['folders']['show_in_menu'],
1539 'show_in_nav_menus' => false,
1540 'show_in_quick_edit' => true,
1541 'show_tagcloud' => false,
1542 'show_admin_column' => $this->options['folders']['show_in_menu'],
1543 'update_count_callback' => '_update_generic_term_count',
1544 'query_var' => false,
1545 'rewrite' => false
1546 ]
1547 );
1548 }
1549
1550 // get non-builtin hierarchical taxonomies
1551 $taxonomies = get_taxonomies(
1552 [
1553 'object_type' => [ 'attachment' ],
1554 'hierarchical' => true,
1555 '_builtin' => false
1556 ],
1557 'objects',
1558 'and'
1559 );
1560
1561 $media_taxonomies = [];
1562
1563 foreach ( $taxonomies as $taxonomy => $object ) {
1564 $media_taxonomies[$taxonomy] = $taxonomy . ' (' . $object->labels->menu_name . ')';
1565 }
1566
1567 $tax = $this->options['folders']['media_taxonomy'];
1568
1569 // selected hierarchical taxonomy does not exists?
1570 if ( ! in_array( $tax, $media_taxonomies, true ) ) {
1571 // check taxonomy existence
1572 if ( ( $taxonomy = get_taxonomy( $tax ) ) !== false ) {
1573 // update
1574 $media_taxonomies[$tax] = $tax . ' (' . $taxonomy->labels->menu_name . ')';
1575 // is it really old taxonomy?
1576 } elseif ( in_array( $tax, $this->folders->get_taxonomies(), true ) ) {
1577 $this->register_media_taxonomy( $tax );
1578
1579 $media_taxonomies[$tax] = $tax;
1580 // use default taxonomy
1581 } else {
1582 $media_taxonomies[$tax] = $tax;
1583 $this->options['folders']['media_taxonomy'] = $this->defaults['folders']['media_taxonomy'];
1584
1585 update_option( 'responsive_lightbox_folders', $this->options['folders'] );
1586 }
1587 }
1588
1589 $this->settings->settings['folders']['fields']['media_taxonomy']['options'] = $media_taxonomies;
1590 }
1591
1592 /**
1593 * Register media taxonomy.
1594 *
1595 * @return void
1596 */
1597 public function register_media_taxonomy( $taxonomy ) {
1598 $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' ) ) );
1599
1600 register_taxonomy(
1601 $taxonomy,
1602 'attachment',
1603 [
1604 'public' => true,
1605 'hierarchical' => true,
1606 'labels' => [
1607 'name' => _x( 'Media Folders', 'taxonomy general name', 'responsive-lightbox' ),
1608 'singular_name' => _x( 'Media Folder', 'taxonomy singular name', 'responsive-lightbox' ),
1609 'search_items' => __( 'Search Folders', 'responsive-lightbox' ),
1610 'all_items' => __( 'All Files', 'responsive-lightbox' ),
1611 'parent_item' => __( 'Parent Folder', 'responsive-lightbox' ),
1612 'parent_item_colon' => __( 'Parent Folder:', 'responsive-lightbox' ),
1613 'edit_item' => __( 'Edit Folder', 'responsive-lightbox' ),
1614 'update_item' => __( 'Update Folder', 'responsive-lightbox' ),
1615 'add_new_item' => __( 'Add New Folder', 'responsive-lightbox' ),
1616 'new_item_name' => __( 'New Folder Name', 'responsive-lightbox' ),
1617 'not_found' => __( 'No folders found.', 'responsive-lightbox' ),
1618 'menu_name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ),
1619 ],
1620 'show_ui' => ! ( $taxonomy === 'rl_media_folder' && $this->options['folders']['media_taxonomy'] !== 'rl_media_folder' ),
1621 'show_in_menu' => $show_in_menu,
1622 'show_in_nav_menus' => false,
1623 'show_in_quick_edit' => true,
1624 'show_tagcloud' => false,
1625 'show_admin_column' => $show_in_menu,
1626 'update_count_callback' => '_update_generic_term_count',
1627 'query_var' => false,
1628 'rewrite' => false
1629 ]
1630 );
1631 }
1632
1633 /**
1634 * Enqueue admin scripts and styles.
1635 *
1636 * @param string $page
1637 * @return void
1638 */
1639 public function admin_scripts_styles( $page ) {
1640 global $typenow;
1641
1642 // settings?
1643 if ( preg_match( '/^(toplevel|lightbox)_page_responsive-lightbox-(' . implode( '|', array_keys( $this->settings->get_data( 'tabs' ) ) ) . ')$/', $page ) === 1 ) {
1644 wp_enqueue_script( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/js/admin.js', [ 'jquery', 'wp-color-picker' ], $this->defaults['version'] );
1645
1646 // prepare script data
1647 $script_data = [
1648 'resetSettingsToDefaults' => esc_html__( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ),
1649 'taxNonce' => wp_create_nonce( 'rl-folders-ajax-taxonomies-nonce' )
1650 ];
1651
1652 wp_add_inline_script( 'responsive-lightbox-admin', 'var rlArgsAdmin = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
1653
1654 wp_enqueue_style( 'wp-color-picker' );
1655
1656 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
1657 // galleries?
1658 } elseif ( in_array( $page, [ 'post.php', 'post-new.php' ], true ) && get_post_type() === 'rl_gallery' || ( $page === 'edit.php' && $typenow === 'rl_gallery' ) ) {
1659 wp_enqueue_media();
1660
1661 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'] );
1662
1663 wp_enqueue_script( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/js/admin-galleries.js', [ 'jquery', 'underscore', 'wp-color-picker', 'jquery-ui-sortable' ], $this->defaults['version'] );
1664
1665 // get fields
1666 $fields = $this->galleries->get_data( 'fields' );
1667
1668 // prepare script data
1669 $script_data = [
1670 'mediaItemTemplate' => $this->galleries->get_media_item_template( $fields['images']['media']['attachments']['preview'] ),
1671 'mediaEmbedTemplate' => $this->galleries->get_media_embed_template( true ),
1672 'mediaExcludeTemplate' => $this->galleries->get_media_exclude_input_template(),
1673 'textSelectImages' => esc_html__( 'Select gallery items', 'responsive-lightbox' ),
1674 'textUseImages' => esc_html__( 'Use these items', 'responsive-lightbox' ),
1675 'clearSelection' => esc_html__( 'Clear selected items', 'responsive-lightbox' ),
1676 'selectedImages' => esc_html__( 'Selected gallery items', 'responsive-lightbox' ),
1677 'editAttachment' => esc_html__( 'Edit attachment', 'responsive-lightbox' ),
1678 'editEmbed' => esc_html__( 'Edit embed video', 'responsive-lightbox' ),
1679 'videoDetails' => esc_html__( 'Video details', 'responsive-lightbox' ),
1680 'saveChanges' => esc_html__( 'Save changes', 'responsive-lightbox' ),
1681 'embedVideo' => esc_html__( 'Embed Video', 'responsive-lightbox' ),
1682 'onlyEmbedProviders' => esc_html__( 'Videos can be embedded only from the following providers: %s.', 'responsive-lightbox' ),
1683 'nonce' => wp_create_nonce( 'rl-gallery' ),
1684 'postId' => get_the_ID(),
1685 'thumbnail' => wp_get_attachment_image_src( $this->galleries->maybe_generate_thumbnail(), 'thumbnail', false ),
1686 'videoIcon' => RESPONSIVE_LIGHTBOX_URL . '/images/responsive-lightbox-video-thumbnail.png',
1687 'supports' => [
1688 'default' => rl_current_lightbox_supports( 'video' ) ? [ 'image', 'video' ] : 'image',
1689 'youtube' => rl_current_lightbox_supports( 'youtube' ),
1690 'vimeo' => rl_current_lightbox_supports( 'vimeo' )
1691 ]
1692 ];
1693
1694 wp_add_inline_script( 'responsive-lightbox-admin-galleries', 'var rlArgsGalleries = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
1695
1696 wp_enqueue_style( 'wp-color-picker' );
1697
1698 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
1699
1700 wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', [], $this->defaults['version'] );
1701
1702 wp_enqueue_style( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/css/admin-galleries.css', [], $this->defaults['version'] );
1703 // plugins?
1704 } elseif ( $page === 'plugins.php' ) {
1705 add_thickbox();
1706
1707 wp_enqueue_script( 'responsive-lightbox-admin-plugins', RESPONSIVE_LIGHTBOX_URL . '/js/admin-plugins.js', [ 'jquery' ], $this->defaults['version'] );
1708
1709 wp_enqueue_style( 'responsive-lightbox-admin-plugins', RESPONSIVE_LIGHTBOX_URL . '/css/admin-plugins.css', [], $this->defaults['version'] );
1710
1711 // prepare script data
1712 $script_data = [
1713 'deactivate' => esc_html__( 'Responsive Lightbox & Gallery - Deactivation survey', 'responsive-lightbox' ),
1714 'nonce' => wp_create_nonce( 'rl-deactivate-plugin' )
1715 ];
1716
1717 wp_add_inline_script( 'responsive-lightbox-admin-plugins', 'var rlArgsPlugins = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
1718 // taxonomies?
1719 } elseif ( in_array( $page, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) ) {
1720 $post_type = sanitize_key( $_GET['post_type'] );
1721
1722 if ( $post_type === 'rl_gallery' )
1723 wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
1724 }
1725 }
1726
1727 /**
1728 * Init Gutenberg.
1729 *
1730 * @return void
1731 */
1732 public function init_gutenberg() {
1733 global $wp_version;
1734
1735 // actions
1736 add_action( 'enqueue_block_editor_assets', [ $this, 'gutenberg_enqueue_scripts' ] );
1737
1738 // filters
1739 if ( version_compare( $wp_version, '5.8', '>=' ) )
1740 add_filter( 'block_categories_all', [ $this, 'block_category' ] );
1741 else
1742 add_filter( 'block_categories', [ $this, 'block_category' ] );
1743 }
1744
1745 /**
1746 * Create block category.
1747 *
1748 * @return array
1749 */
1750 function block_category( $categories ) {
1751 return array_merge(
1752 $categories,
1753 [
1754 [
1755 'slug' => 'responsive-lightbox',
1756 'title' => 'Responsive Lightbox'
1757 ]
1758 ]
1759 );
1760 }
1761
1762 /**
1763 * Extend Gutenberg.
1764 *
1765 * @return void
1766 */
1767 public function gutenberg_enqueue_scripts() {
1768 global $pagenow;
1769
1770 // block editor dependencies
1771 $dependencies = [ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components' ];
1772
1773 // widgets page?
1774 if ( $pagenow === 'widgets.php' )
1775 $dependencies[] = 'wp-edit-widgets';
1776 // customizer?
1777 elseif ( $pagenow === 'customize.php' )
1778 $dependencies[] = 'wp-customize-widgets';
1779 // post page?
1780 else
1781 $dependencies[] = 'wp-editor';
1782
1783 // enqueue script
1784 wp_enqueue_script( 'responsive-lightbox-block-editor-script', RESPONSIVE_LIGHTBOX_URL . '/js/gutenberg.min.js', $dependencies, $this->defaults['version'] );
1785
1786 // enqueue styles
1787 wp_enqueue_style( 'responsive-lightbox-block-editor-styles', RESPONSIVE_LIGHTBOX_URL . '/css/gutenberg.min.css', '', $this->defaults['version'] );
1788
1789 // prepare script data
1790 $script_data = [
1791 'active' => true
1792 ];
1793
1794 wp_add_inline_script( 'responsive-lightbox-block-editor-script', 'var rlBlockEditor = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
1795
1796 // enqueue gallery
1797 $this->galleries->enqueue_gallery_scripts_styles();
1798
1799 // register gallery block
1800 register_block_type(
1801 'responsive-lightbox/gallery',
1802 [
1803 'editor_script' => 'block-editor-script'
1804 ]
1805 );
1806
1807 // register remote library image block
1808 register_block_type(
1809 'responsive-lightbox/remote-library-image',
1810 [
1811 'editor_script' => 'block-editor-script'
1812 ]
1813 );
1814 }
1815
1816 /**
1817 * Enqueue admin widget scripts.
1818 *
1819 * @return void
1820 */
1821 public function sidebar_admin_setup() {
1822 wp_enqueue_media();
1823
1824 wp_enqueue_script( 'responsive-lightbox-admin-widgets', RESPONSIVE_LIGHTBOX_URL . '/js/admin-widgets.js', [ 'jquery', 'underscore' ], $this->defaults['version'] );
1825
1826 // prepare script data
1827 $script_data = [
1828 'textRemoveImage' => esc_html__( 'Remove image', 'responsive-lightbox' ),
1829 'textSelectImages' => esc_html__( 'Select images', 'responsive-lightbox' ),
1830 'textSelectImage' => esc_html__( 'Select image', 'responsive-lightbox' ),
1831 'textUseImages' => esc_html__( 'Use these images', 'responsive-lightbox' ),
1832 'textUseImage' => esc_html__( 'Use this image', 'responsive-lightbox' )
1833 ];
1834
1835 wp_add_inline_script( 'responsive-lightbox-admin-widgets', 'var rlArgsWidgets = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
1836
1837 wp_register_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
1838 wp_enqueue_style( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/css/admin-galleries.css', [], $this->defaults['version'] );
1839 wp_enqueue_style( 'responsive-lightbox-admin' );
1840 }
1841
1842 /**
1843 * Enqueue frontend scripts and styles.
1844 *
1845 * @return void
1846 */
1847 public function front_scripts_styles() {
1848 $args = apply_filters(
1849 'rl_lightbox_args',
1850 [
1851 'script' => $this->current_script,
1852 'selector' => $this->options['settings']['selector'],
1853 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? $this->options['settings']['custom_events'] : '' ),
1854 'activeGalleries' => $this->options['settings']['galleries']
1855 ]
1856 );
1857
1858 $scripts = [];
1859 $styles = [];
1860
1861 switch ( $args['script'] ) {
1862 case 'prettyphoto':
1863 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' );
1864
1865 wp_register_style(
1866 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
1867 );
1868
1869 $scripts[] = 'responsive-lightbox-prettyphoto';
1870 $styles[] = 'responsive-lightbox-prettyphoto';
1871
1872 $args = array_merge(
1873 $args,
1874 [
1875 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'],
1876 'slideshow' => $this->options['configuration']['prettyphoto']['slideshow'],
1877 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'],
1878 'slideshowAutoplay' => $this->options['configuration']['prettyphoto']['slideshow_autoplay'],
1879 'opacity' => sprintf( '%.2f', $this->options['configuration']['prettyphoto']['opacity'] / 100 ),
1880 'showTitle' => $this->options['configuration']['prettyphoto']['show_title'],
1881 'allowResize' => $this->options['configuration']['prettyphoto']['allow_resize'],
1882 'allowExpand' => $this->options['configuration']['prettyphoto']['allow_expand'],
1883 'width' => $this->options['configuration']['prettyphoto']['width'],
1884 'height' => $this->options['configuration']['prettyphoto']['height'],
1885 'separator' => $this->options['configuration']['prettyphoto']['separator'],
1886 'theme' => $this->options['configuration']['prettyphoto']['theme'],
1887 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'],
1888 'hideFlash' => $this->options['configuration']['prettyphoto']['hide_flash'],
1889 'wmode' => $this->options['configuration']['prettyphoto']['wmode'],
1890 'videoAutoplay' => $this->options['configuration']['prettyphoto']['video_autoplay'],
1891 'modal' => $this->options['configuration']['prettyphoto']['modal'],
1892 'deeplinking' => $this->options['configuration']['prettyphoto']['deeplinking'],
1893 'overlayGallery' => $this->options['configuration']['prettyphoto']['overlay_gallery'],
1894 'keyboardShortcuts' => $this->options['configuration']['prettyphoto']['keyboard_shortcuts'],
1895 'social' => $this->options['configuration']['prettyphoto']['social']
1896 ]
1897 );
1898 break;
1899
1900 case 'swipebox':
1901 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' );
1902
1903 wp_register_style(
1904 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
1905 );
1906
1907 $scripts[] = 'responsive-lightbox-swipebox';
1908 $styles[] = 'responsive-lightbox-swipebox';
1909
1910 $args = array_merge(
1911 $args,
1912 [
1913 'animation' => $this->options['configuration']['swipebox']['animation'] === 'css',
1914 'hideCloseButtonOnMobile' => $this->options['configuration']['swipebox']['hide_close_mobile'],
1915 'removeBarsOnMobile' => $this->options['configuration']['swipebox']['remove_bars_mobile'],
1916 'hideBars' => $this->options['configuration']['swipebox']['hide_bars'],
1917 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'],
1918 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'],
1919 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'],
1920 'loopAtEnd' => $this->options['configuration']['swipebox']['loop_at_end']
1921 ]
1922 );
1923 break;
1924
1925 case 'fancybox':
1926 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' );
1927
1928 wp_register_style(
1929 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
1930 );
1931
1932 $scripts[] = 'responsive-lightbox-fancybox';
1933 $styles[] = 'responsive-lightbox-fancybox';
1934
1935 $args = array_merge(
1936 $args,
1937 [
1938 'modal' => $this->options['configuration']['fancybox']['modal'],
1939 'showOverlay' => $this->options['configuration']['fancybox']['show_overlay'],
1940 'showCloseButton' => $this->options['configuration']['fancybox']['show_close_button'],
1941 'enableEscapeButton' => $this->options['configuration']['fancybox']['enable_escape_button'],
1942 'hideOnOverlayClick' => $this->options['configuration']['fancybox']['hide_on_overlay_click'],
1943 'hideOnContentClick' => $this->options['configuration']['fancybox']['hide_on_content_click'],
1944 'cyclic' => $this->options['configuration']['fancybox']['cyclic'],
1945 'showNavArrows' => $this->options['configuration']['fancybox']['show_nav_arrows'],
1946 'autoScale' => $this->options['configuration']['fancybox']['auto_scale'],
1947 'scrolling' => $this->options['configuration']['fancybox']['scrolling'],
1948 'centerOnScroll' => $this->options['configuration']['fancybox']['center_on_scroll'],
1949 'opacity' => $this->options['configuration']['fancybox']['opacity'],
1950 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'],
1951 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'],
1952 'titleShow' => $this->options['configuration']['fancybox']['title_show'],
1953 'titlePosition' => $this->options['configuration']['fancybox']['title_position'],
1954 'transitions' => $this->options['configuration']['fancybox']['transitions'],
1955 'easings' => $this->options['configuration']['fancybox']['easings'],
1956 'speeds' => $this->options['configuration']['fancybox']['speeds'],
1957 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'],
1958 'changeFade' => $this->options['configuration']['fancybox']['change_fade'],
1959 'padding' => $this->options['configuration']['fancybox']['padding'],
1960 'margin' => $this->options['configuration']['fancybox']['margin'],
1961 'videoWidth' => $this->options['configuration']['fancybox']['video_width'],
1962 'videoHeight' => $this->options['configuration']['fancybox']['video_height']
1963 ]
1964 );
1965 break;
1966
1967 case 'nivo':
1968 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'] );
1969
1970 wp_register_style(
1971 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
1972 );
1973
1974 wp_register_style(
1975 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ ), [], $this->defaults['version']
1976 );
1977
1978 $scripts[] = 'responsive-lightbox-nivo';
1979 $styles[] = 'responsive-lightbox-nivo';
1980 $styles[] = 'responsive-lightbox-nivo-default';
1981
1982 $args = array_merge(
1983 $args,
1984 [
1985 'effect' => $this->options['configuration']['nivo']['effect'],
1986 'clickOverlayToClose' => $this->options['configuration']['nivo']['click_overlay_to_close'],
1987 'keyboardNav' => $this->options['configuration']['nivo']['keyboard_nav'],
1988 'errorMessage' => esc_html( $this->options['configuration']['nivo']['error_message'] )
1989 ]
1990 );
1991 break;
1992
1993 case 'imagelightbox':
1994 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' );
1995
1996 wp_register_style(
1997 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
1998 );
1999
2000 $scripts[] = 'responsive-lightbox-imagelightbox';
2001 $styles[] = 'responsive-lightbox-imagelightbox';
2002
2003 $args = array_merge(
2004 $args,
2005 [
2006 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'],
2007 'preloadNext' => $this->options['configuration']['imagelightbox']['preload_next'],
2008 'enableKeyboard' => $this->options['configuration']['imagelightbox']['enable_keyboard'],
2009 'quitOnEnd' => $this->options['configuration']['imagelightbox']['quit_on_end'],
2010 'quitOnImageClick' => $this->options['configuration']['imagelightbox']['quit_on_image_click'],
2011 'quitOnDocumentClick' => $this->options['configuration']['imagelightbox']['quit_on_document_click'],
2012 ]
2013 );
2014 break;
2015
2016 case 'tosrus':
2017 // swipe support, enqueue Hammer.js on mobile devices only
2018 if ( wp_is_mobile() ) {
2019 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' );
2020 $scripts[] = 'responsive-lightbox-hammer-js';
2021 }
2022
2023 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' );
2024
2025 wp_register_style(
2026 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
2027 );
2028
2029 $scripts[] = 'responsive-lightbox-tosrus';
2030 $styles[] = 'responsive-lightbox-tosrus';
2031
2032 $args = array_merge(
2033 $args,
2034 [
2035 'effect' => $this->options['configuration']['tosrus']['effect'],
2036 'infinite' => $this->options['configuration']['tosrus']['infinite'],
2037 'keys' => $this->options['configuration']['tosrus']['keys'],
2038 'autoplay' => $this->options['configuration']['tosrus']['autoplay'],
2039 'pauseOnHover' => $this->options['configuration']['tosrus']['pause_on_hover'],
2040 'timeout' => $this->options['configuration']['tosrus']['timeout'],
2041 'pagination' => $this->options['configuration']['tosrus']['pagination'],
2042 'paginationType' => $this->options['configuration']['tosrus']['pagination_type'],
2043 'closeOnClick' => $this->options['configuration']['tosrus']['close_on_click']
2044 ]
2045 );
2046 break;
2047
2048 case 'featherlight':
2049 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' );
2050
2051 wp_register_style(
2052 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
2053 );
2054
2055 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' );
2056
2057 wp_register_style(
2058 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version']
2059 );
2060
2061 $scripts[] = 'responsive-lightbox-featherlight';
2062 $styles[] = 'responsive-lightbox-featherlight';
2063 $scripts[] = 'responsive-lightbox-featherlight-gallery';
2064 $styles[] = 'responsive-lightbox-featherlight-gallery';
2065
2066 $args = array_merge(
2067 $args,
2068 [
2069 'openSpeed' => $this->options['configuration']['featherlight']['open_speed'],
2070 'closeSpeed' => $this->options['configuration']['featherlight']['close_speed'],
2071 'closeOnClick' => $this->options['configuration']['featherlight']['close_on_click'],
2072 'closeOnEsc' => $this->options['configuration']['featherlight']['close_on_esc'],
2073 'galleryFadeIn' => $this->options['configuration']['featherlight']['gallery_fade_in'],
2074 'galleryFadeOut' => $this->options['configuration']['featherlight']['gallery_fade_out']
2075 ]
2076 );
2077 break;
2078
2079 case 'magnific':
2080 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' );
2081
2082 wp_register_style( 'responsive-lightbox-magnific', plugins_url( 'assets/magnific/magnific-popup' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), [], $this->defaults['version'] );
2083
2084 $scripts[] = 'responsive-lightbox-magnific';
2085 $styles[] = 'responsive-lightbox-magnific';
2086
2087 $args = array_merge(
2088 $args,
2089 [
2090 'disableOn' => $this->options['configuration']['magnific']['disable_on'],
2091 'midClick' => $this->options['configuration']['magnific']['mid_click'],
2092 'preloader' => $this->options['configuration']['magnific']['preloader'],
2093 'closeOnContentClick' => $this->options['configuration']['magnific']['close_on_content_click'],
2094 'closeOnBgClick' => $this->options['configuration']['magnific']['close_on_background_click'],
2095 'closeBtnInside' => $this->options['configuration']['magnific']['close_button_inside'],
2096 'showCloseBtn' => $this->options['configuration']['magnific']['show_close_button'],
2097 'enableEscapeKey' => $this->options['configuration']['magnific']['enable_escape_key'],
2098 'alignTop' => $this->options['configuration']['magnific']['align_top'],
2099 'fixedContentPos' => $this->options['configuration']['magnific']['fixed_content_position'],
2100 'fixedBgPos' => $this->options['configuration']['magnific']['fixed_background_position'],
2101 'autoFocusLast' => $this->options['configuration']['magnific']['auto_focus_last']
2102 ]
2103 );
2104 break;
2105
2106 default:
2107 do_action( 'rl_lightbox_enqueue_scripts' );
2108
2109 $scripts = apply_filters( 'rl_lightbox_scripts', $scripts );
2110 $styles = apply_filters( 'rl_lightbox_styles', $styles );
2111 }
2112
2113 // run scripts by default
2114 $contitional_scripts = true;
2115
2116 if ( $this->options['settings']['conditional_loading'] === true ) {
2117 global $post;
2118
2119 if ( is_object( $post ) ) {
2120 // is gallery present in content
2121 $has_gallery = has_shortcode( $post->post_content, 'gallery' ) || has_shortcode( $post->post_content, 'rl_gallery' );
2122
2123 // are images present in content
2124 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $post->post_content, $links );
2125
2126 $has_images = (bool) $links[0];
2127
2128 if ( $has_gallery === false && $has_images === false )
2129 $contitional_scripts = false;
2130 }
2131 }
2132
2133 if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) {
2134 wp_register_script( 'responsive-lightbox-infinite-scroll', RESPONSIVE_LIGHTBOX_URL . '/assets/infinitescroll/infinite-scroll.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', [ 'jquery' ] );
2135 wp_register_script( 'responsive-lightbox-images-loaded', RESPONSIVE_LIGHTBOX_URL . '/assets/imagesloaded/imagesloaded.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', [ 'jquery' ] );
2136 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' );
2137
2138 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' );
2139
2140 $args['woocommerce_gallery'] = false;
2141
2142 if ( class_exists( 'WooCommerce' ) ) {
2143 global $woocommerce;
2144
2145 if ( $this->options['settings']['woocommerce_gallery_lightbox'] === true ) {
2146 if ( version_compare( $woocommerce->version, '3.0', ">=" ) )
2147 $args['woocommerce_gallery'] = true;
2148 }
2149 }
2150
2151 $scripts[] = 'responsive-lightbox';
2152
2153 $args['ajaxurl'] = admin_url( 'admin-ajax.php' );
2154 $args['nonce'] = wp_create_nonce( 'rl_nonce' );
2155 $args['preview'] = isset( $_GET['rl_gallery_revision_id'], $_GET['preview'] ) && $_GET['preview'] === 'true';
2156 $args['postId'] = (int) get_the_ID();
2157 $args['scriptExtension'] = array_key_exists( $args['script'], apply_filters( 'rl_settings_licenses', [] ) );
2158
2159 // enqueue scripts
2160 if ( $scripts && is_array( $scripts ) ) {
2161 foreach ( $scripts as $script ) {
2162 wp_enqueue_script( $script );
2163 }
2164
2165 wp_add_inline_script( 'responsive-lightbox', 'var rlArgs = ' . wp_json_encode( $args ) . ";\n", 'before' );
2166 }
2167
2168 // enqueue styles
2169 if ( $styles && is_array( $styles ) ) {
2170 foreach ( $styles as $style ) {
2171 wp_enqueue_style( $style );
2172 }
2173 }
2174 }
2175
2176 // gallery style
2177 wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), [], $this->defaults['version'] );
2178 }
2179
2180 /**
2181 * Convert HEX to RGB color.
2182 *
2183 * @param string $color
2184 * @return bool|array
2185 */
2186 public function hex2rgb( $color ) {
2187 if ( ! is_string( $color ) )
2188 return false;
2189
2190 // with hash?
2191 if ( $color[0] === '#' )
2192 $color = substr( $color, 1 );
2193
2194 if ( sanitize_hex_color_no_hash( $color ) !== $color )
2195 return false;
2196
2197 // 6 hex digits?
2198 if ( strlen( $color ) === 6 )
2199 list( $r, $g, $b ) = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
2200 // 3 hex digits?
2201 elseif ( strlen( $color ) === 3 )
2202 list( $r, $g, $b ) = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
2203 else
2204 return false;
2205
2206 return [ 'r' => hexdec( $r ), 'g' => hexdec( $g ), 'b' => hexdec( $b ) ];
2207 }
2208 }
2209
2210 /**
2211 * Initialize Responsive Lightbox.
2212 */
2213 function Responsive_Lightbox() {
2214 static $instance;
2215
2216 // first call to instance() initializes the plugin
2217 if ( $instance === null || ! ( $instance instanceof Responsive_Lightbox ) )
2218 $instance = Responsive_Lightbox::instance();
2219
2220 return $instance;
2221 }
2222
2223 Responsive_Lightbox();