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