PluginProbe
Responsive Lightbox & Gallery / 2.5.0
Responsive Lightbox & Gallery v2.5.0
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 All 105 releases
responsive-lightbox / responsive-lightbox.php

responsive-lightbox.php in Responsive Lightbox & Gallery 2.5.0, at responsive-lightbox.php

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