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