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