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