responsive-lightbox
Last commit date
assets
6 years ago
css
6 years ago
font
8 years ago
images
8 years ago
includes
6 years ago
js
6 years ago
languages
6 years ago
library
6 years ago
index.php
12 years ago
readme.txt
6 years ago
responsive-lightbox.php
6 years ago
wpml-config.xml
8 years ago
responsive-lightbox.php
1571 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Responsive Lightbox & Gallery |
| 4 | Description: Responsive Lightbox & Gallery allows users to create galleries and view larger versions of images, galleries and videos in a lightbox (overlay) effect optimized for mobile devices. |
| 5 | Version: 2.2.2 |
| 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 | // exit if accessed directly |
| 25 | if ( ! defined( 'ABSPATH' ) ) |
| 26 | exit; |
| 27 | |
| 28 | define( 'RESPONSIVE_LIGHTBOX_URL', plugins_url( '', __FILE__ ) ); |
| 29 | define( 'RESPONSIVE_LIGHTBOX_PATH', plugin_dir_path( __FILE__ ) ); |
| 30 | define( 'RESPONSIVE_LIGHTBOX_REL_PATH', dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR ); |
| 31 | |
| 32 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-fast-image.php' ); |
| 33 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-galleries.php' ); |
| 34 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-folders.php' ); |
| 35 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-frontend.php' ); |
| 36 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-settings.php' ); |
| 37 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-tour.php' ); |
| 38 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-welcome.php' ); |
| 39 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-widgets.php' ); |
| 40 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'functions.php' ); |
| 41 | |
| 42 | /** |
| 43 | * Responsive Lightbox class. |
| 44 | * |
| 45 | * @class Responsive_Lightbox |
| 46 | * @version 2.2.2 |
| 47 | */ |
| 48 | class Responsive_Lightbox { |
| 49 | |
| 50 | public $defaults = array( |
| 51 | 'settings' => array( |
| 52 | 'tour' => true, |
| 53 | 'script' => 'swipebox', |
| 54 | 'selector' => 'lightbox', |
| 55 | 'default_gallery' => 'default', |
| 56 | 'builder_gallery' => 'basicgrid', |
| 57 | 'default_woocommerce_gallery' => 'default', |
| 58 | 'galleries' => true, |
| 59 | 'gallery_image_size' => 'full', |
| 60 | 'gallery_image_title' => 'default', |
| 61 | 'gallery_image_caption' => 'default', |
| 62 | 'force_custom_gallery' => false, |
| 63 | 'woocommerce_gallery_lightbox' => false, |
| 64 | 'videos' => true, |
| 65 | 'widgets' => false, |
| 66 | 'comments' => false, |
| 67 | 'image_links' => true, |
| 68 | 'image_title' => 'default', |
| 69 | 'image_caption' => 'default', |
| 70 | 'images_as_gallery' => false, |
| 71 | 'deactivation_delete' => false, |
| 72 | 'loading_place' => 'header', |
| 73 | 'conditional_loading' => false, |
| 74 | 'enable_custom_events' => false, |
| 75 | 'custom_events' => 'ajaxComplete', |
| 76 | 'update_version' => 1, |
| 77 | 'update_notice' => true, |
| 78 | 'update_delay_date' => 0 |
| 79 | ), |
| 80 | 'builder' => array( |
| 81 | 'gallery_builder' => true, |
| 82 | 'categories' => true, |
| 83 | 'tags' => true, |
| 84 | 'permalink' => 'rl_gallery', |
| 85 | 'permalink_categories' => 'rl_category', |
| 86 | 'permalink_tags' => 'rl_tag', |
| 87 | 'archives' => true, |
| 88 | 'archives_category' => 'all' |
| 89 | ), |
| 90 | 'configuration' => array( |
| 91 | 'swipebox' => array( |
| 92 | 'animation' => 'css', |
| 93 | 'force_png_icons' => false, |
| 94 | 'hide_close_mobile' => false, |
| 95 | 'remove_bars_mobile' => false, |
| 96 | 'hide_bars' => true, |
| 97 | 'hide_bars_delay' => 5000, |
| 98 | 'video_max_width' => 1080, |
| 99 | 'loop_at_end' => false |
| 100 | ), |
| 101 | 'prettyphoto' => array( |
| 102 | 'animation_speed' => 'normal', |
| 103 | 'slideshow' => false, |
| 104 | 'slideshow_delay' => 5000, |
| 105 | 'slideshow_autoplay' => false, |
| 106 | 'opacity' => 75, |
| 107 | 'show_title' => true, |
| 108 | 'allow_resize' => true, |
| 109 | 'allow_expand' => true, |
| 110 | 'width' => 1080, |
| 111 | 'height' => 720, |
| 112 | 'separator' => '/', |
| 113 | 'theme' => 'pp_default', |
| 114 | 'horizontal_padding' => 20, |
| 115 | 'hide_flash' => false, |
| 116 | 'wmode' => 'opaque', |
| 117 | 'video_autoplay' => false, |
| 118 | 'modal' => false, |
| 119 | 'deeplinking' => false, |
| 120 | 'overlay_gallery' => true, |
| 121 | 'keyboard_shortcuts' => true, |
| 122 | 'social' => false |
| 123 | ), |
| 124 | 'fancybox' => array( |
| 125 | 'modal' => false, |
| 126 | 'show_overlay' => true, |
| 127 | 'show_close_button' => true, |
| 128 | 'enable_escape_button' => true, |
| 129 | 'hide_on_overlay_click' => true, |
| 130 | 'hide_on_content_click' => false, |
| 131 | 'cyclic' => false, |
| 132 | 'show_nav_arrows' => true, |
| 133 | 'auto_scale' => true, |
| 134 | 'scrolling' => 'yes', |
| 135 | 'center_on_scroll' => true, |
| 136 | 'opacity' => true, |
| 137 | 'overlay_opacity' => 70, |
| 138 | 'overlay_color' => '#666', |
| 139 | 'title_show' => true, |
| 140 | 'title_position' => 'outside', |
| 141 | 'transitions' => 'fade', |
| 142 | 'easings' => 'swing', |
| 143 | 'speeds' => 300, |
| 144 | 'change_speed' => 300, |
| 145 | 'change_fade' => 100, |
| 146 | 'padding' => 5, |
| 147 | 'margin' => 5, |
| 148 | 'video_width' => 1080, |
| 149 | 'video_height' => 720 |
| 150 | ), |
| 151 | 'nivo' => array( |
| 152 | 'effect' => 'fade', |
| 153 | 'click_overlay_to_close' => true, |
| 154 | 'keyboard_nav' => true, |
| 155 | 'error_message' => 'The requested content cannot be loaded. Please try again later.' |
| 156 | ), |
| 157 | 'imagelightbox' => array( |
| 158 | 'animation_speed' => 250, |
| 159 | 'preload_next' => true, |
| 160 | 'enable_keyboard' => true, |
| 161 | 'quit_on_end' => false, |
| 162 | 'quit_on_image_click' => false, |
| 163 | 'quit_on_document_click' => true |
| 164 | ), |
| 165 | 'tosrus' => array( |
| 166 | 'effect' => 'slide', |
| 167 | 'infinite' => true, |
| 168 | 'keys' => false, |
| 169 | 'autoplay' => true, |
| 170 | 'pause_on_hover' => false, |
| 171 | 'timeout' => 4000, |
| 172 | 'pagination' => true, |
| 173 | 'pagination_type' => 'thumbnails', |
| 174 | 'close_on_click' => false |
| 175 | ), |
| 176 | 'featherlight' => array( |
| 177 | 'open_speed' => 250, |
| 178 | 'close_speed' => 250, |
| 179 | 'close_on_click' => 'background', |
| 180 | 'close_on_esc' => true, |
| 181 | 'gallery_fade_in' => 100, |
| 182 | 'gallery_fade_out' => 300 |
| 183 | ), |
| 184 | 'magnific' => array( |
| 185 | 'disable_on' => 0, |
| 186 | 'mid_click' => true, |
| 187 | 'preloader' => true, |
| 188 | 'close_on_content_click' => true, |
| 189 | 'close_on_background_click' => true, |
| 190 | 'close_button_inside' => true, |
| 191 | 'show_close_button' => true, |
| 192 | 'enable_escape_key' => true, |
| 193 | 'align_top' => false, |
| 194 | 'fixed_content_position' => 'auto', |
| 195 | 'fixed_background_position' => 'auto', |
| 196 | 'auto_focus_last' => true |
| 197 | ) |
| 198 | ), |
| 199 | 'folders' => array( |
| 200 | 'active' => true, |
| 201 | 'media_taxonomy' => 'rl_media_folder', |
| 202 | 'media_tags' => 'rl_media_tag', |
| 203 | // 'jstree_style' => 'default', |
| 204 | 'jstree_wholerow' => true, |
| 205 | 'show_in_menu' => false, |
| 206 | 'folders_removal' => true |
| 207 | ), |
| 208 | 'remote_library' => array( |
| 209 | 'active' => true, |
| 210 | 'caching' => false, |
| 211 | 'cache_expiry' => 1, |
| 212 | 'flickr' => array( |
| 213 | 'active' => false, |
| 214 | 'api_key' => '' |
| 215 | ), |
| 216 | 'unsplash' => array( |
| 217 | 'active' => false, |
| 218 | 'api_key' => '' |
| 219 | ), |
| 220 | 'wikimedia' => array( |
| 221 | 'active' => true |
| 222 | ) |
| 223 | ), |
| 224 | 'basicgrid_gallery' => array( |
| 225 | 'columns_lg' => 4, |
| 226 | 'columns_md' => 3, |
| 227 | 'columns_sm' => 2, |
| 228 | 'columns_xs' => 1, |
| 229 | 'gutter' => 2, |
| 230 | 'force_height' => false, |
| 231 | 'row_height' => 150 |
| 232 | ), |
| 233 | 'basicslider_gallery' => array( |
| 234 | 'adaptive_height' => true, |
| 235 | 'loop' => false, |
| 236 | 'captions' => 'overlay', |
| 237 | 'init_single' => true, |
| 238 | 'responsive' => true, |
| 239 | 'preload' => 'visible', |
| 240 | 'pager' => true, |
| 241 | 'controls' => true, |
| 242 | 'hide_on_end' => true, |
| 243 | 'slide_margin' => 0, |
| 244 | 'transition' => 'fade', |
| 245 | 'kenburns_zoom' => 120, |
| 246 | 'speed' => 800, |
| 247 | 'easing' => 'swing', |
| 248 | 'continuous' => true, |
| 249 | 'use_css' => true, |
| 250 | 'slideshow' => true, |
| 251 | 'slideshow_direction' => 'next', |
| 252 | 'slideshow_hover' => true, |
| 253 | 'slideshow_hover_delay' => 100, |
| 254 | 'slideshow_delay' => 500, |
| 255 | 'slideshow_pause' => 3000 |
| 256 | ), |
| 257 | 'basicmasonry_gallery' => array( |
| 258 | 'columns_lg' => 4, |
| 259 | 'columns_md' => 3, |
| 260 | 'columns_sm' => 2, |
| 261 | 'columns_xs' => 2, |
| 262 | 'gutter' => 20, |
| 263 | 'margin' => 20, |
| 264 | 'origin_left' => true, |
| 265 | 'origin_top' => true |
| 266 | ), |
| 267 | 'version' => '2.2.2', |
| 268 | 'activation_date' => '' |
| 269 | ); |
| 270 | public $options = array(); |
| 271 | public $providers = array(); |
| 272 | public $gallery_types = array(); |
| 273 | private $version = false; |
| 274 | private $notices = array(); |
| 275 | private static $_instance; |
| 276 | |
| 277 | private function __clone() {} |
| 278 | private function __wakeup() {} |
| 279 | |
| 280 | /** |
| 281 | * Main Responsive Lightbox instance. |
| 282 | * |
| 283 | * @return object |
| 284 | */ |
| 285 | public static function instance() { |
| 286 | if ( self::$_instance === null ) |
| 287 | self::$_instance = new self(); |
| 288 | |
| 289 | return self::$_instance; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Constructor. |
| 294 | * |
| 295 | * @return void |
| 296 | */ |
| 297 | public function __construct() { |
| 298 | register_activation_hook( __FILE__, array( $this, 'activate_multisite' ) ); |
| 299 | register_deactivation_hook( __FILE__, array( $this, 'deactivate_multisite' ) ); |
| 300 | |
| 301 | // change from older versions |
| 302 | $this->version = $db_version = get_option( 'responsive_lightbox_version' ); |
| 303 | |
| 304 | // legacy version update |
| 305 | if ( version_compare( ( $db_version === false ? '1.0.0' : $db_version ), '1.0.5', '<' ) ) { |
| 306 | if ( ( $array = get_option( 'rl_settings' ) ) !== false ) { |
| 307 | update_option( 'responsive_lightbox_settings', $array ); |
| 308 | delete_option( 'rl_settings' ); |
| 309 | } |
| 310 | |
| 311 | if ( ( $array = get_option( 'rl_configuration' ) ) !== false ) { |
| 312 | update_option( 'responsive_lightbox_configuration', $array ); |
| 313 | delete_option( 'rl_configuration' ); |
| 314 | } |
| 315 | // plugin version update |
| 316 | } elseif ( version_compare( ( $db_version === false ? '1.0.0' : $db_version ), $this->defaults['version'], '<' ) ) |
| 317 | update_option( 'responsive_lightbox_version', $this->defaults['version'], false ); |
| 318 | |
| 319 | $this->options['settings'] = array_merge( $this->defaults['settings'], ( ( $array = get_option( 'responsive_lightbox_settings' ) ) === false ? array() : $array ) ); |
| 320 | $this->options['folders'] = array_merge( $this->defaults['folders'], ( ( $array = get_option( 'responsive_lightbox_folders' ) ) === false ? array() : $array ) ); |
| 321 | $this->options['builder'] = array_merge( $this->defaults['builder'], ( ( $array = get_option( 'responsive_lightbox_builder' ) ) === false ? array() : $array ) ); |
| 322 | $this->options['remote_library'] = array_merge( $this->defaults['remote_library'], ( ( $array = get_option( 'responsive_lightbox_remote_library' ) ) === false ? array() : $array ) ); |
| 323 | |
| 324 | // for multi arrays we have to merge them separately |
| 325 | $db_conf_opts = ( ( $base = get_option( 'responsive_lightbox_configuration' ) ) === false ? array() : $base ); |
| 326 | |
| 327 | foreach ( $this->defaults['configuration'] as $script => $settings ) { |
| 328 | $this->options['configuration'][$script] = array_merge( $settings, ( isset( $db_conf_opts[$script] ) ? $db_conf_opts[$script] : array() ) ); |
| 329 | } |
| 330 | |
| 331 | // add default galleries options |
| 332 | $this->options['basicgrid_gallery'] = array_merge( $this->defaults['basicgrid_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicgrid_gallery', $this->defaults['basicgrid_gallery'] ) ) == false ? array() : $array ) ); |
| 333 | $this->options['basicslider_gallery'] = array_merge( $this->defaults['basicslider_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicslider_gallery', $this->defaults['basicslider_gallery'] ) ) == false ? array() : $array ) ); |
| 334 | $this->options['basicmasonry_gallery'] = array_merge( $this->defaults['basicmasonry_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicmasonry_gallery', $this->defaults['basicmasonry_gallery'] ) ) == false ? array() : $array ) ); |
| 335 | |
| 336 | // actions |
| 337 | add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
| 338 | add_action( 'after_setup_theme', array( $this, 'init_remote_libraries' ), 11 ); |
| 339 | add_action( 'init', array( $this, 'init_galleries' ) ); |
| 340 | add_action( 'init', array( $this, 'init_folders' ) ); |
| 341 | add_action( 'init', array( $this, 'init_gutenberg' ) ); |
| 342 | add_action( 'wp_enqueue_scripts', array( $this, 'front_scripts_styles' ) ); |
| 343 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_styles' ) ); |
| 344 | add_action( 'sidebar_admin_setup', array( $this, 'sidebar_admin_setup' ) ); |
| 345 | add_action( 'admin_init', array( $this, 'update_notice' ) ); |
| 346 | add_action( 'wp_ajax_rl_dismiss_notice', array( $this, 'dismiss_notice' ) ); |
| 347 | |
| 348 | // filters |
| 349 | add_filter( 'plugin_action_links', array( $this, 'plugin_settings_link' ), 10, 2 ); |
| 350 | add_filter( 'plugin_row_meta', array( $this, 'plugin_extend_links' ), 10, 2 ); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Single site activation function. |
| 355 | * |
| 356 | * @return void |
| 357 | */ |
| 358 | public function activate_single() { |
| 359 | // transient for welcome screen |
| 360 | if ( get_option( 'responsive_lightbox_activation_date', false ) === false ) |
| 361 | set_transient( 'rl_activation_redirect', 1, 3600 ); |
| 362 | elseif ( $this->version !== false ) { |
| 363 | // activated from old version |
| 364 | if ( version_compare( $this->version, '2.0.0', '<' ) ) { |
| 365 | set_transient( 'rl_activation_redirect', 1, 3600 ); |
| 366 | } |
| 367 | } else |
| 368 | set_transient( 'rl_activation_redirect', 1, 3600 ); |
| 369 | |
| 370 | add_option( 'responsive_lightbox_settings', $this->defaults['settings'], '', 'no' ); |
| 371 | add_option( 'responsive_lightbox_configuration', $this->defaults['configuration'], '', 'no' ); |
| 372 | add_option( 'responsive_lightbox_folders', $this->defaults['folders'], '', 'no' ); |
| 373 | add_option( 'responsive_lightbox_builder', $this->defaults['builder'], '', 'no' ); |
| 374 | add_option( 'responsive_lightbox_remote_library', $this->defaults['remote_library'], '', 'no' ); |
| 375 | add_option( 'responsive_lightbox_version', $this->defaults['version'], '', 'no' ); |
| 376 | |
| 377 | // permalinks |
| 378 | flush_rewrite_rules(); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Single site deactivation function. |
| 383 | * |
| 384 | * @param bool $multi Multisite? |
| 385 | * @return void |
| 386 | */ |
| 387 | public function deactivate_single( $multi = false ) { |
| 388 | if ( $multi === true ) { |
| 389 | $options = get_option( 'responsive_lightbox_settings' ); |
| 390 | $check = $options['deactivation_delete']; |
| 391 | } else |
| 392 | $check = $this->options['settings']['deactivation_delete']; |
| 393 | |
| 394 | if ( $check ) { |
| 395 | delete_option( 'responsive_lightbox_settings' ); |
| 396 | delete_option( 'responsive_lightbox_configuration' ); |
| 397 | delete_option( 'responsive_lightbox_folders' ); |
| 398 | delete_option( 'responsive_lightbox_builder' ); |
| 399 | delete_option( 'responsive_lightbox_remote_library' ); |
| 400 | delete_option( 'responsive_lightbox_version' ); |
| 401 | } |
| 402 | |
| 403 | // permalinks |
| 404 | flush_rewrite_rules(); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Activation function. |
| 409 | * |
| 410 | * @param bool $networkwide Multisite? |
| 411 | * @return void |
| 412 | */ |
| 413 | public function activate_multisite( $networkwide ) { |
| 414 | if ( is_multisite() && $networkwide ) { |
| 415 | global $wpdb; |
| 416 | |
| 417 | $activated_blogs = array(); |
| 418 | $current_blog_id = $wpdb->blogid; |
| 419 | $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) ); |
| 420 | |
| 421 | foreach ( $blogs_ids as $blog_id ) { |
| 422 | switch_to_blog( $blog_id ); |
| 423 | $this->activate_single(); |
| 424 | $activated_blogs[] = (int) $blog_id; |
| 425 | } |
| 426 | |
| 427 | switch_to_blog( $current_blog_id ); |
| 428 | update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs, array() ); |
| 429 | } else |
| 430 | $this->activate_single(); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Dectivation function. |
| 435 | * |
| 436 | * @param bool $networkwide Multisite? |
| 437 | * @return void |
| 438 | */ |
| 439 | public function deactivate_multisite( $networkwide ) { |
| 440 | if ( is_multisite() && $networkwide ) { |
| 441 | global $wpdb; |
| 442 | |
| 443 | $current_blog_id = $wpdb->blogid; |
| 444 | $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) ); |
| 445 | |
| 446 | if ( ($activated_blogs = get_site_option( 'responsive_lightbox_activated_blogs', false, false )) === false ) |
| 447 | $activated_blogs = array(); |
| 448 | |
| 449 | foreach ( $blogs_ids as $blog_id ) { |
| 450 | switch_to_blog( $blog_id ); |
| 451 | $this->deactivate_single( true ); |
| 452 | |
| 453 | if ( in_array( (int) $blog_id, $activated_blogs, true ) ) |
| 454 | unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] ); |
| 455 | } |
| 456 | |
| 457 | switch_to_blog( $current_blog_id ); |
| 458 | update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs ); |
| 459 | } else |
| 460 | $this->deactivate_single(); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Load textdomain |
| 465 | * |
| 466 | * @return void |
| 467 | */ |
| 468 | public function load_textdomain() { |
| 469 | load_plugin_textdomain( 'responsive-lightbox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 470 | |
| 471 | // gallery types |
| 472 | $this->gallery_types = array( |
| 473 | 'default' => __( 'Default', 'responsive-lightbox' ), |
| 474 | 'basicgrid' => __( 'Basic Grid', 'responsive-lightbox' ), |
| 475 | 'basicslider' => __( 'Basic Slider', 'responsive-lightbox' ), |
| 476 | 'basicmasonry' => __( 'Basic Masonry', 'responsive-lightbox' ) |
| 477 | ); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Update notice. |
| 482 | * |
| 483 | * @return void |
| 484 | */ |
| 485 | public function update_notice() { |
| 486 | if ( ! current_user_can( 'install_plugins' ) ) |
| 487 | return; |
| 488 | |
| 489 | $current_update = 2; |
| 490 | |
| 491 | // get current time |
| 492 | $current_time = time(); |
| 493 | |
| 494 | if ( $this->options['settings']['update_version'] < $current_update ) { |
| 495 | // check version, if update ver is lower than plugin ver, set update notice to true |
| 496 | $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_version' => $current_update, 'update_notice' => true ) ); |
| 497 | |
| 498 | update_option( 'responsive_lightbox_settings', $this->options['settings'] ); |
| 499 | |
| 500 | // set activation date |
| 501 | $activation_date = get_option( 'responsive_lightbox_activation_date' ); |
| 502 | |
| 503 | if ( $activation_date === false ) |
| 504 | update_option( 'responsive_lightbox_activation_date', $current_time ); |
| 505 | } |
| 506 | |
| 507 | // display current version notice |
| 508 | if ( $this->options['settings']['update_notice'] === true ) { |
| 509 | // include notice js, only if needed |
| 510 | add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ), 999 ); |
| 511 | |
| 512 | // get activation date |
| 513 | $activation_date = get_option( 'responsive_lightbox_activation_date' ); |
| 514 | |
| 515 | if ( (int) $this->options['settings']['update_delay_date'] === 0 ) { |
| 516 | if ( $activation_date + 1209600 > $current_time ) |
| 517 | $this->options['settings']['update_delay_date'] = $activation_date + 1209600; |
| 518 | else |
| 519 | $this->options['settings']['update_delay_date'] = $current_time; |
| 520 | |
| 521 | update_option( 'responsive_lightbox_settings', $this->options['settings'] ); |
| 522 | } |
| 523 | |
| 524 | if ( ( ! empty( $this->options['settings']['update_delay_date'] ) ? (int) $this->options['settings']['update_delay_date'] : $current_time ) <= $current_time ) |
| 525 | $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' ); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Dismiss notice. |
| 531 | * |
| 532 | * @return void |
| 533 | */ |
| 534 | public function dismiss_notice() { |
| 535 | if ( ! current_user_can( 'install_plugins' ) ) |
| 536 | return; |
| 537 | |
| 538 | if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'rl_dismiss_notice' ) ) { |
| 539 | $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] ); |
| 540 | |
| 541 | switch ( $notice_action ) { |
| 542 | // delay notice |
| 543 | case 'delay': |
| 544 | // set delay period to 1 week from now |
| 545 | $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => time() + 1209600 ) ); |
| 546 | update_option( 'responsive_lightbox_settings', $this->options['settings'] ); |
| 547 | break; |
| 548 | |
| 549 | // hide notice |
| 550 | default: |
| 551 | $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_notice' => false ) ); |
| 552 | $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => 0 ) ); |
| 553 | |
| 554 | update_option( 'responsive_lightbox_settings', $this->options['settings'] ); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | exit; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Add admin notices. |
| 563 | * |
| 564 | * @param string $html Notice HTML |
| 565 | * @param string $status Notice status |
| 566 | * @param bool $paragraph Whether to use paragraph |
| 567 | * @param bool $network |
| 568 | * @return void |
| 569 | */ |
| 570 | public function add_notice( $html = '', $status = 'error', $paragraph = true, $network = false ) { |
| 571 | $this->notices[] = array( |
| 572 | 'html' => $html, |
| 573 | 'status' => $status, |
| 574 | 'paragraph' => $paragraph |
| 575 | ); |
| 576 | |
| 577 | add_action( 'admin_notices', array( $this, 'display_notice') ); |
| 578 | |
| 579 | if ( $network ) |
| 580 | add_action( 'network_admin_notices', array( $this, 'display_notice') ); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Print admin notices. |
| 585 | * |
| 586 | * @return void |
| 587 | */ |
| 588 | public function display_notice() { |
| 589 | foreach( $this->notices as $notice ) { |
| 590 | echo ' |
| 591 | <div class="' . $notice['status'] . '"> |
| 592 | ' . ( $notice['paragraph'] ? '<p>' : '' ) . ' |
| 593 | ' . $notice['html'] . ' |
| 594 | ' . ( $notice['paragraph'] ? '</p>' : '' ) . ' |
| 595 | </div>'; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Print admin scripts. |
| 601 | * |
| 602 | * @return void |
| 603 | */ |
| 604 | public function admin_inline_js() { |
| 605 | if ( ! current_user_can( 'install_plugins' ) ) |
| 606 | return; |
| 607 | ?> |
| 608 | <script type="text/javascript"> |
| 609 | ( function ( $ ) { |
| 610 | $( document ).ready( function () { |
| 611 | // save dismiss state |
| 612 | $( '.rl-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .rl-dismissible-notice', function ( e ) { |
| 613 | var notice_action = 'hide'; |
| 614 | |
| 615 | if ( $( e.currentTarget ).hasClass( 'rl-delay-notice' ) ) { |
| 616 | notice_action = 'delay' |
| 617 | } |
| 618 | |
| 619 | $.post( ajaxurl, { |
| 620 | action: 'rl_dismiss_notice', |
| 621 | notice_action: notice_action, |
| 622 | url: '<?php echo admin_url( 'admin-ajax.php' ); ?>', |
| 623 | nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>' |
| 624 | } ); |
| 625 | |
| 626 | $( e.delegateTarget ).slideUp( 'fast' ); |
| 627 | } ); |
| 628 | } ); |
| 629 | } )( jQuery ); |
| 630 | </script> |
| 631 | <?php |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Add links to Support Forum. |
| 636 | * |
| 637 | * @param array $links |
| 638 | * @param string $file |
| 639 | * @return array |
| 640 | */ |
| 641 | public function plugin_extend_links( $links, $file ) { |
| 642 | if ( ! current_user_can( 'install_plugins' ) ) |
| 643 | return $links; |
| 644 | |
| 645 | $plugin = plugin_basename( __FILE__ ); |
| 646 | |
| 647 | if ( $file == $plugin ) { |
| 648 | return array_merge( |
| 649 | $links, array( sprintf( '<a href="https://dfactory.eu/support/forum/responsive-lightbox/" target="_blank">%s</a>', __( 'Support', 'responsive-lightbox' ) ) ) |
| 650 | ); |
| 651 | } |
| 652 | |
| 653 | return $links; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Add links to Settings page. |
| 658 | * |
| 659 | * @param array $links |
| 660 | * @param string $file |
| 661 | * @return array |
| 662 | */ |
| 663 | public function plugin_settings_link( $links, $file ) { |
| 664 | if ( ! is_admin() || ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) ) |
| 665 | return $links; |
| 666 | |
| 667 | static $plugin; |
| 668 | |
| 669 | $plugin = plugin_basename( __FILE__ ); |
| 670 | |
| 671 | if ( $file == $plugin ) { |
| 672 | $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-settings', __( 'Settings', 'responsive-lightbox' ) ); |
| 673 | array_unshift( $links, $settings_link ); |
| 674 | |
| 675 | $links[] = sprintf( '<a href="%s" style="color: green;">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-addons', __( 'Add-ons', 'responsive-lightbox' ) ); |
| 676 | } |
| 677 | |
| 678 | return $links; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Initialize remote libraries. |
| 683 | * |
| 684 | * @return void |
| 685 | */ |
| 686 | public function init_remote_libraries() { |
| 687 | // include classes |
| 688 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library.php' ); |
| 689 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library-api.php' ); |
| 690 | |
| 691 | $this->remote_library = new Responsive_Lightbox_Remote_Library(); |
| 692 | |
| 693 | // simple html dom |
| 694 | if ( ! function_exists( 'file_get_html' ) ) |
| 695 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'library/simplehtmldom/simple_html_dom.php' ); |
| 696 | |
| 697 | // include providers |
| 698 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' ); |
| 699 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' ); |
| 700 | include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-wikimedia.php' ); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Initialize galleries. |
| 705 | * |
| 706 | * @return void |
| 707 | */ |
| 708 | public function init_galleries() { |
| 709 | // initialize gallery class |
| 710 | new Responsive_Lightbox_Galleries( ! $this->options['builder']['gallery_builder'] ); |
| 711 | |
| 712 | // end if in read only mode |
| 713 | if ( ! $this->options['builder']['gallery_builder'] ) |
| 714 | return; |
| 715 | |
| 716 | $taxonomies = array(); |
| 717 | |
| 718 | if ( $this->options['builder']['categories'] ) { |
| 719 | $taxonomies[] = 'rl_category'; |
| 720 | |
| 721 | register_taxonomy( 'rl_category', 'rl_gallery', array( |
| 722 | 'public' => true, |
| 723 | 'hierarchical' => true, |
| 724 | 'labels' => array( |
| 725 | 'name' => _x( 'Gallery Categories', 'taxonomy general name', 'responsive-lightbox' ), |
| 726 | 'singular_name' => _x( 'Gallery Category', 'taxonomy singular name', 'responsive-lightbox' ), |
| 727 | 'search_items' => __( 'Search Gallery Categories', 'responsive-lightbox' ), |
| 728 | 'all_items' => __( 'All Gallery Categories', 'responsive-lightbox' ), |
| 729 | 'parent_item' => __( 'Parent Gallery Category', 'responsive-lightbox' ), |
| 730 | 'parent_item_colon' => __( 'Parent Gallery Category:', 'responsive-lightbox' ), |
| 731 | 'edit_item' => __( 'Edit Gallery Category', 'responsive-lightbox' ), |
| 732 | 'view_item' => __( 'View Gallery Category', 'responsive-lightbox' ), |
| 733 | 'update_item' => __( 'Update Gallery Category', 'responsive-lightbox' ), |
| 734 | 'add_new_item' => __( 'Add New Gallery Category', 'responsive-lightbox' ), |
| 735 | 'new_item_name' => __( 'New Gallery Category Name', 'responsive-lightbox' ), |
| 736 | 'menu_name' => __( 'Categories', 'responsive-lightbox' ) |
| 737 | ), |
| 738 | 'show_ui' => true, |
| 739 | 'show_admin_column' => true, |
| 740 | 'update_count_callback' => '_update_post_term_count', |
| 741 | 'query_var' => true, |
| 742 | 'rewrite' => array( |
| 743 | 'slug' => $this->options['builder']['permalink_categories'], |
| 744 | 'with_front' => false, |
| 745 | 'hierarchical' => false |
| 746 | ) |
| 747 | ) ); |
| 748 | } |
| 749 | |
| 750 | if ( $this->options['builder']['tags'] ) { |
| 751 | $taxonomies[] = 'rl_tag'; |
| 752 | |
| 753 | register_taxonomy( 'rl_tag', 'rl_gallery', array( |
| 754 | 'public' => true, |
| 755 | 'hierarchical' => false, |
| 756 | 'labels' => array( |
| 757 | 'name' => _x( 'Gallery Tags', 'taxonomy general name', 'responsive-lightbox' ), |
| 758 | 'singular_name' => _x( 'Gallery Tag', 'taxonomy singular name', 'responsive-lightbox' ), |
| 759 | 'search_items' => __( 'Search Gallery Tags', 'responsive-lightbox' ), |
| 760 | 'popular_items' => __( 'Popular Gallery Tags', 'responsive-lightbox' ), |
| 761 | 'all_items' => __( 'All Gallery Tags', 'responsive-lightbox' ), |
| 762 | 'parent_item' => null, |
| 763 | 'parent_item_colon' => null, |
| 764 | 'edit_item' => __( 'Edit Gallery Tag', 'responsive-lightbox' ), |
| 765 | 'update_item' => __( 'Update Gallery Tag', 'responsive-lightbox' ), |
| 766 | 'add_new_item' => __( 'Add New Gallery Tag', 'responsive-lightbox' ), |
| 767 | 'new_item_name' => __( 'New Gallery Tag Name', 'responsive-lightbox' ), |
| 768 | 'separate_items_with_commas' => __( 'Separate gallery tags with commas', 'responsive-lightbox' ), |
| 769 | 'add_or_remove_items' => __( 'Add or remove gallery tags', 'responsive-lightbox' ), |
| 770 | 'choose_from_most_used' => __( 'Choose from the most used gallery tags', 'responsive-lightbox' ), |
| 771 | 'menu_name' => __( 'Tags', 'responsive-lightbox' ) |
| 772 | ), |
| 773 | 'show_ui' => true, |
| 774 | 'show_admin_column' => true, |
| 775 | 'update_count_callback' => '_update_post_term_count', |
| 776 | 'query_var' => true, |
| 777 | 'rewrite' => array( |
| 778 | 'slug' => $this->options['builder']['permalink_tags'], |
| 779 | 'with_front' => false, |
| 780 | 'hierarchical' => false |
| 781 | ) |
| 782 | ) ); |
| 783 | } |
| 784 | |
| 785 | // register rl_gallery |
| 786 | register_post_type( |
| 787 | 'rl_gallery', |
| 788 | array( |
| 789 | 'labels' => array( |
| 790 | 'name' => _x( 'Galleries', 'post type general name', 'responsive-lightbox' ), |
| 791 | 'singular_name' => _x( 'Gallery', 'post type singular name', 'responsive-lightbox' ), |
| 792 | 'add_new' => __( 'Add New', 'responsive-lightbox' ), |
| 793 | 'add_new_item' => __( 'Add New Gallery', 'responsive-lightbox' ), |
| 794 | 'edit_item' => __( 'Edit Gallery', 'responsive-lightbox' ), |
| 795 | 'new_item' => __( 'New Gallery', 'responsive-lightbox' ), |
| 796 | 'view_item' => __( 'View Gallery', 'responsive-lightbox' ), |
| 797 | 'view_items' => __( 'View Galleries', 'responsive-lightbox' ), |
| 798 | 'search_items' => __( 'Search Galleries', 'responsive-lightbox' ), |
| 799 | 'not_found' => __( 'No galleries found', 'responsive-lightbox' ), |
| 800 | 'not_found_in_trash' => __( 'No galleries found in trash', 'responsive-lightbox' ), |
| 801 | 'all_items' => __( 'All Galleries', 'responsive-lightbox' ), |
| 802 | 'menu_name' => __( 'Gallery', 'responsive-lightbox' ) |
| 803 | ), |
| 804 | 'description' => '', |
| 805 | 'public' => true, |
| 806 | 'exclude_from_search' => false, |
| 807 | 'publicly_queryable' => true, |
| 808 | 'show_ui' => true, |
| 809 | 'show_in_menu' => true, |
| 810 | 'show_in_admin_bar' => true, |
| 811 | 'show_in_nav_menus' => true, |
| 812 | 'menu_position' => 57, |
| 813 | 'menu_icon' => 'dashicons-format-gallery', |
| 814 | 'map_meta_cap' => true, |
| 815 | 'hierarchical' => false, |
| 816 | 'supports' => array( 'title', 'author', 'thumbnail' ), |
| 817 | 'has_archive' => $this->options['builder']['archives'], |
| 818 | 'query_var' => true, |
| 819 | 'can_export' => true, |
| 820 | 'rewrite' => array( |
| 821 | 'slug' => $this->options['builder']['permalink'], |
| 822 | 'with_front' => false, |
| 823 | 'feed' => true, |
| 824 | 'pages' => true |
| 825 | ), |
| 826 | 'taxonomies' => $taxonomies |
| 827 | ) |
| 828 | ); |
| 829 | |
| 830 | if ( $this->options['builder']['archives'] && $this->options['builder']['archives_category'] !== 'all' && ! is_admin() ) |
| 831 | add_action( 'pre_get_posts', array( $this, 'gallery_archives' ) ); |
| 832 | |
| 833 | add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Gallery update messages. |
| 838 | * |
| 839 | * @param array $messages |
| 840 | * @return array |
| 841 | */ |
| 842 | public function gallery_archives( $query ) { |
| 843 | if ( is_post_type_archive( 'rl_gallery' ) ) { |
| 844 | $query->set( |
| 845 | 'tax_query', |
| 846 | array( |
| 847 | 'relation' => 'OR', |
| 848 | array( |
| 849 | 'taxonomy' => 'rl_category', |
| 850 | 'field' => 'slug', |
| 851 | 'terms' => $this->options['builder']['archives_category'] |
| 852 | ) |
| 853 | ) |
| 854 | ); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Gallery update messages. |
| 860 | * |
| 861 | * @param array $messages |
| 862 | * @return array |
| 863 | */ |
| 864 | public function post_updated_messages( $messages ) { |
| 865 | $post = get_post(); |
| 866 | $post_type = get_post_type( $post ); |
| 867 | $post_type_object = get_post_type_object( $post_type ); |
| 868 | |
| 869 | $messages['rl_gallery'] = array( |
| 870 | 1 => __( 'Gallery updated.', 'responsive-lightbox' ), |
| 871 | 4 => __( 'Gallery updated.', 'responsive-lightbox' ), |
| 872 | 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Gallery restored to revision from %s', 'responsive-lightbox' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 873 | 6 => __( 'Gallery published.', 'responsive-lightbox' ), |
| 874 | 7 => __( 'Gallery saved.', 'responsive-lightbox' ), |
| 875 | 8 => __( 'Gallery submitted.', 'responsive-lightbox' ), |
| 876 | 9 => sprintf( |
| 877 | __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'responsive-lightbox' ), |
| 878 | date_i18n( __( 'M j, Y @ G:i', 'responsive-lightbox' ), strtotime( $post->post_date ) ) |
| 879 | ), |
| 880 | 10 => __( 'Gallery draft updated.', 'responsive-lightbox' ) |
| 881 | ); |
| 882 | |
| 883 | if ( $post_type_object->publicly_queryable && 'rl_gallery' === $post_type ) { |
| 884 | $permalink = get_permalink( $post->ID ); |
| 885 | |
| 886 | $view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View gallery', 'responsive-lightbox' ) ); |
| 887 | $messages[$post_type][1] .= $view_link; |
| 888 | $messages[$post_type][6] .= $view_link; |
| 889 | $messages[$post_type][9] .= $view_link; |
| 890 | |
| 891 | $preview_permalink = add_query_arg( 'preview', 'true', $permalink ); |
| 892 | $preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview gallery', 'responsive-lightbox' ) ); |
| 893 | $messages[$post_type][8] .= $preview_link; |
| 894 | $messages[$post_type][10] .= $preview_link; |
| 895 | } |
| 896 | |
| 897 | return $messages; |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Initialize folders. |
| 902 | * |
| 903 | * @return void |
| 904 | */ |
| 905 | public function init_folders() { |
| 906 | // initialize folder class |
| 907 | new Responsive_Lightbox_Folders( ! $this->options['folders']['active'] ); |
| 908 | |
| 909 | // end if in read only mode |
| 910 | if ( ! $this->options['folders']['active'] ) |
| 911 | return; |
| 912 | |
| 913 | // register media taxonomy |
| 914 | $this->register_media_taxonomy( 'rl_media_folder' ); |
| 915 | |
| 916 | // register media tags |
| 917 | if ( $this->options['folders']['media_tags'] ) { |
| 918 | register_taxonomy( |
| 919 | 'rl_media_tag', |
| 920 | 'attachment', |
| 921 | array( |
| 922 | 'public' => true, |
| 923 | 'hierarchical' => false, |
| 924 | 'labels' => array( |
| 925 | 'name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ), |
| 926 | 'singular_name' => _x( 'Tag', 'taxonomy singular name', 'responsive-lightbox' ), |
| 927 | 'search_items' => __( 'Search Tags', 'responsive-lightbox' ), |
| 928 | 'all_items' => __( 'All Tags', 'responsive-lightbox' ), |
| 929 | 'edit_item' => __( 'Edit Tag', 'responsive-lightbox' ), |
| 930 | 'update_item' => __( 'Update Tag', 'responsive-lightbox' ), |
| 931 | 'add_new_item' => __( 'Add New Tag', 'responsive-lightbox' ), |
| 932 | 'new_item_name' => __( 'New Tag Name', 'responsive-lightbox' ), |
| 933 | 'not_found' => __( 'No tags found.', 'responsive-lightbox' ), |
| 934 | 'menu_name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ), |
| 935 | ), |
| 936 | 'show_ui' => true, |
| 937 | 'show_in_menu' => $this->options['folders']['show_in_menu'], |
| 938 | 'show_in_nav_menus' => false, |
| 939 | 'show_in_quick_edit' => true, |
| 940 | 'show_tagcloud' => false, |
| 941 | 'show_admin_column' => true, |
| 942 | 'update_count_callback' => '_update_generic_term_count', |
| 943 | 'query_var' => false, |
| 944 | 'rewrite' => false |
| 945 | ) |
| 946 | ); |
| 947 | } |
| 948 | |
| 949 | // get non-builtin hierarchical taxonomies |
| 950 | $taxonomies = get_taxonomies( |
| 951 | array( |
| 952 | 'object_type' => array( 'attachment' ), |
| 953 | 'hierarchical' => true, |
| 954 | '_builtin' => false |
| 955 | ), |
| 956 | 'objects', |
| 957 | 'and' |
| 958 | ); |
| 959 | |
| 960 | $media_taxonomies = array(); |
| 961 | |
| 962 | foreach ( $taxonomies as $taxonomy => $object ) { |
| 963 | $media_taxonomies[$taxonomy] = $taxonomy . ' (' . $object->labels->menu_name . ')'; |
| 964 | } |
| 965 | |
| 966 | $tax = $this->options['folders']['media_taxonomy']; |
| 967 | |
| 968 | // selected hierarchical taxonomy does not exists? |
| 969 | if ( ! in_array( $tax, $media_taxonomies, true ) ) { |
| 970 | // check taxonomy existence |
| 971 | if ( ( $taxonomy = get_taxonomy( $tax ) ) !== false ) { |
| 972 | // update |
| 973 | $media_taxonomies[$tax] = $tax . ' (' . $taxonomy->labels->menu_name . ')'; |
| 974 | // is it really old taxonomy? |
| 975 | } elseif ( in_array( $tax, Responsive_Lightbox()->folders->get_taxonomies(), true ) ) { |
| 976 | $this->register_media_taxonomy( $tax ); |
| 977 | |
| 978 | $media_taxonomies[$tax] = $tax; |
| 979 | // use default taxonomy |
| 980 | } else { |
| 981 | $media_taxonomies[$tax] = $tax; |
| 982 | $this->options['folders']['media_taxonomy'] = $this->defaults['folders']['media_taxonomy']; |
| 983 | |
| 984 | update_option( 'responsive_lightbox_folders', $this->options['folders'] ); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | $this->settings->settings['folders']['fields']['media_taxonomy']['options'] = $media_taxonomies; |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Register media taxonomy. |
| 993 | * |
| 994 | * @return void |
| 995 | */ |
| 996 | public function register_media_taxonomy( $taxonomy ) { |
| 997 | register_taxonomy( |
| 998 | $taxonomy, |
| 999 | 'attachment', |
| 1000 | array( |
| 1001 | 'public' => true, |
| 1002 | 'hierarchical' => true, |
| 1003 | 'labels' => array( |
| 1004 | 'name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ), |
| 1005 | 'singular_name' => _x( 'Folder', 'taxonomy singular name', 'responsive-lightbox' ), |
| 1006 | 'search_items' => __( 'Search Folders', 'responsive-lightbox' ), |
| 1007 | 'all_items' => __( 'All Files', 'responsive-lightbox' ), |
| 1008 | 'parent_item' => __( 'Parent Folder', 'responsive-lightbox' ), |
| 1009 | 'parent_item_colon' => __( 'Parent Folder:', 'responsive-lightbox' ), |
| 1010 | 'edit_item' => __( 'Edit Folder', 'responsive-lightbox' ), |
| 1011 | 'update_item' => __( 'Update Folder', 'responsive-lightbox' ), |
| 1012 | 'add_new_item' => __( 'Add New Folder', 'responsive-lightbox' ), |
| 1013 | 'new_item_name' => __( 'New Folder Name', 'responsive-lightbox' ), |
| 1014 | 'not_found' => __( 'No folders found.', 'responsive-lightbox' ), |
| 1015 | 'menu_name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ), |
| 1016 | ), |
| 1017 | 'show_ui' => ! ( $taxonomy === 'rl_media_folder' && $this->options['folders']['media_taxonomy'] !== 'rl_media_folder' ), |
| 1018 | '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' ) ) ), |
| 1019 | 'show_in_nav_menus' => false, |
| 1020 | 'show_in_quick_edit' => true, |
| 1021 | 'show_tagcloud' => false, |
| 1022 | 'show_admin_column' => true, |
| 1023 | 'update_count_callback' => '_update_generic_term_count', |
| 1024 | 'query_var' => false, |
| 1025 | 'rewrite' => false |
| 1026 | ) |
| 1027 | ); |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Enqueue admin scripts and styles. |
| 1032 | * |
| 1033 | * @param string $page |
| 1034 | * @return void |
| 1035 | */ |
| 1036 | public function admin_scripts_styles( $page ) { |
| 1037 | wp_register_script( 'rl-knockout', RESPONSIVE_LIGHTBOX_URL . '/assets/knockout/knockout' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', null, $this->defaults['version'] ); |
| 1038 | |
| 1039 | if ( preg_match( '/^(toplevel|lightbox)_page_responsive-lightbox-(' . implode( '|', array_keys( Responsive_Lightbox()->settings->tabs ) ) . ')$/', $page ) === 1 ) { |
| 1040 | wp_enqueue_script( 'responsive-lightbox-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), $this->defaults['version'] ); |
| 1041 | |
| 1042 | wp_localize_script( |
| 1043 | 'responsive-lightbox-admin', |
| 1044 | 'rlArgsAdmin', |
| 1045 | array( |
| 1046 | 'resetSettingsToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ), |
| 1047 | 'resetScriptToDefaults' => __( 'Are you sure you want to reset this script settings to defaults?', 'responsive-lightbox' ), |
| 1048 | 'resetGalleryToDefaults' => __( 'Are you sure you want to reset this gallery settings to defaults?', 'responsive-lightbox' ), |
| 1049 | 'tax_nonce' => wp_create_nonce( 'rl-folders-ajax-taxonomies-nonce' ), |
| 1050 | ) |
| 1051 | ); |
| 1052 | |
| 1053 | wp_enqueue_style( 'wp-color-picker' ); |
| 1054 | |
| 1055 | wp_enqueue_style( 'responsive-lightbox-admin', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->defaults['version'] ); |
| 1056 | } elseif ( in_array( $page, array( 'post.php', 'edit.php', 'post-new.php' ), true ) && get_post_type() === 'rl_gallery' ) { |
| 1057 | wp_enqueue_media(); |
| 1058 | |
| 1059 | wp_enqueue_script( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2.full' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ), $this->defaults['version'] ); |
| 1060 | |
| 1061 | wp_enqueue_script( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/js/admin-galleries.js', array( 'jquery', 'underscore', 'wp-color-picker' ), $this->defaults['version'] ); |
| 1062 | |
| 1063 | wp_localize_script( |
| 1064 | 'responsive-lightbox-admin-galleries', |
| 1065 | 'rlArgsGalleries', |
| 1066 | array( |
| 1067 | 'mediaItemTemplate' => $this->galleries->get_media_item_template( $this->galleries->fields['images']['media']['attachments']['preview'] ), |
| 1068 | 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ), |
| 1069 | 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ), |
| 1070 | 'editTitle' => __( 'Edit attachment', 'responsive-lightbox' ), |
| 1071 | 'buttonEditFile' => __( 'Save attachment', 'responsive-lightbox' ), |
| 1072 | 'nonce' => wp_create_nonce( 'rl-gallery' ), |
| 1073 | 'post_id' => get_the_ID() |
| 1074 | ) |
| 1075 | ); |
| 1076 | |
| 1077 | wp_enqueue_style( 'wp-color-picker' ); |
| 1078 | |
| 1079 | wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', array(), $this->defaults['version'] ); |
| 1080 | |
| 1081 | wp_enqueue_style( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/css/admin-galleries.css', array(), $this->defaults['version'] ); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Init Gutenberg. |
| 1087 | * |
| 1088 | * @return void |
| 1089 | */ |
| 1090 | public function init_gutenberg() { |
| 1091 | add_action( 'enqueue_block_editor_assets', array( $this, 'gutenberg_enqueue_scripts' ) ); |
| 1092 | |
| 1093 | add_filter( 'block_categories', array( $this, 'block_category' ) ); |
| 1094 | } |
| 1095 | |
| 1096 | /** |
| 1097 | * Create block category. |
| 1098 | * |
| 1099 | * @return array |
| 1100 | */ |
| 1101 | function block_category( $categories ) { |
| 1102 | return array_merge( |
| 1103 | $categories, |
| 1104 | array( |
| 1105 | array( |
| 1106 | 'slug' => 'responsive-lightbox', |
| 1107 | 'title' => 'Responsive Lightbox' |
| 1108 | ) |
| 1109 | ) |
| 1110 | ); |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * Extend Gutenberg. |
| 1115 | * |
| 1116 | * @return void |
| 1117 | */ |
| 1118 | public function gutenberg_enqueue_scripts() { |
| 1119 | $rl = Responsive_Lightbox(); |
| 1120 | |
| 1121 | // enqueue script |
| 1122 | wp_enqueue_script( 'responsive-lightbox-block-editor-script', RESPONSIVE_LIGHTBOX_URL . '/js/gutenberg.min.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-components' ), $rl->defaults['version'] ); |
| 1123 | |
| 1124 | // enqueue styles |
| 1125 | wp_enqueue_style( 'responsive-lightbox-block-editor-styles', RESPONSIVE_LIGHTBOX_URL . '/css/gutenberg.min.css', '', $rl->defaults['version'] ); |
| 1126 | |
| 1127 | wp_localize_script( |
| 1128 | 'responsive-lightbox-block-editor-script', |
| 1129 | 'rlBlockEditor', |
| 1130 | array( |
| 1131 | 'active' => true |
| 1132 | ) |
| 1133 | ); |
| 1134 | |
| 1135 | // register gallery block |
| 1136 | register_block_type( |
| 1137 | 'responsive-lightbox/gallery', |
| 1138 | array( |
| 1139 | 'editor_script' => 'block-editor-script' |
| 1140 | ) |
| 1141 | ); |
| 1142 | |
| 1143 | // register remote library image block |
| 1144 | register_block_type( |
| 1145 | 'responsive-lightbox/remote-library-image', |
| 1146 | array( |
| 1147 | 'editor_script' => 'block-editor-script' |
| 1148 | ) |
| 1149 | ); |
| 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * Enqueue admin widget scripts. |
| 1154 | * |
| 1155 | * @return void |
| 1156 | */ |
| 1157 | public function sidebar_admin_setup() { |
| 1158 | wp_enqueue_media(); |
| 1159 | |
| 1160 | wp_enqueue_script( 'responsive-lightbox-admin-widgets', RESPONSIVE_LIGHTBOX_URL . '/js/admin-widgets.js', array( 'jquery', 'underscore' ), $this->defaults['version'] ); |
| 1161 | |
| 1162 | wp_localize_script( |
| 1163 | 'responsive-lightbox-admin-widgets', |
| 1164 | 'rlArgsWidgets', |
| 1165 | array( |
| 1166 | 'textRemoveImage' => __( 'Remove image', 'responsive-lightbox' ), |
| 1167 | 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ), |
| 1168 | 'textSelectImage' => __( 'Select image', 'responsive-lightbox' ), |
| 1169 | 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ), |
| 1170 | 'textUseImage' => __( 'Use this image', 'responsive-lightbox' ) |
| 1171 | ) |
| 1172 | ); |
| 1173 | |
| 1174 | wp_register_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] ); |
| 1175 | wp_enqueue_style( 'responsive-lightbox-admin' ); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Enqueue frontend scripts and styles. |
| 1180 | * |
| 1181 | * @return void |
| 1182 | */ |
| 1183 | public function front_scripts_styles() { |
| 1184 | $args = apply_filters( 'rl_lightbox_args', array( |
| 1185 | 'script' => $this->options['settings']['script'], |
| 1186 | 'selector' => $this->options['settings']['selector'], |
| 1187 | 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? ' ' . $this->options['settings']['custom_events'] : '' ), |
| 1188 | 'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] ) |
| 1189 | ) ); |
| 1190 | |
| 1191 | $scripts = array(); |
| 1192 | $styles = array(); |
| 1193 | |
| 1194 | switch ( $args['script'] ) { |
| 1195 | case 'prettyphoto': |
| 1196 | wp_register_script( |
| 1197 | 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/jquery.prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ) |
| 1198 | ); |
| 1199 | |
| 1200 | wp_register_style( |
| 1201 | 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1202 | ); |
| 1203 | |
| 1204 | $scripts[] = 'responsive-lightbox-prettyphoto'; |
| 1205 | $styles[] = 'responsive-lightbox-prettyphoto'; |
| 1206 | |
| 1207 | $args = array_merge( |
| 1208 | $args, |
| 1209 | array( |
| 1210 | 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'], |
| 1211 | 'slideshow' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow'] ), |
| 1212 | 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'], |
| 1213 | 'slideshowAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow_autoplay'] ), |
| 1214 | 'opacity' => sprintf( '%.2f', ($this->options['configuration']['prettyphoto']['opacity'] / 100 ) ), |
| 1215 | 'showTitle' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['show_title'] ), |
| 1216 | 'allowResize' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_resize'] ), |
| 1217 | 'allowExpand' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_expand'] ), |
| 1218 | 'width' => $this->options['configuration']['prettyphoto']['width'], |
| 1219 | 'height' => $this->options['configuration']['prettyphoto']['height'], |
| 1220 | 'separator' => $this->options['configuration']['prettyphoto']['separator'], |
| 1221 | 'theme' => $this->options['configuration']['prettyphoto']['theme'], |
| 1222 | 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'], |
| 1223 | 'hideFlash' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['hide_flash'] ), |
| 1224 | 'wmode' => $this->options['configuration']['prettyphoto']['wmode'], |
| 1225 | 'videoAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['video_autoplay'] ), |
| 1226 | 'modal' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['modal'] ), |
| 1227 | 'deeplinking' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['deeplinking'] ), |
| 1228 | 'overlayGallery' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['overlay_gallery'] ), |
| 1229 | 'keyboardShortcuts' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['keyboard_shortcuts'] ), |
| 1230 | 'social' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['social'] ) |
| 1231 | ) |
| 1232 | ); |
| 1233 | break; |
| 1234 | |
| 1235 | case 'swipebox': |
| 1236 | wp_register_script( |
| 1237 | 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/jquery.swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ) |
| 1238 | ); |
| 1239 | |
| 1240 | wp_register_style( |
| 1241 | 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1242 | ); |
| 1243 | |
| 1244 | $scripts[] = 'responsive-lightbox-swipebox'; |
| 1245 | $styles[] = 'responsive-lightbox-swipebox'; |
| 1246 | |
| 1247 | $args = array_merge( |
| 1248 | $args, array( |
| 1249 | 'animation' => $this->get_boolean_value( ($this->options['configuration']['swipebox']['animation'] === 'css' ? true : false ) ), |
| 1250 | 'hideCloseButtonOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_close_mobile'] ), |
| 1251 | 'removeBarsOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['remove_bars_mobile'] ), |
| 1252 | 'hideBars' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_bars'] ), |
| 1253 | 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'], |
| 1254 | 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'], |
| 1255 | 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'], |
| 1256 | 'loopAtEnd' => $this->get_boolean_value( $this->options['configuration']['swipebox']['loop_at_end'] ) |
| 1257 | ) |
| 1258 | ); |
| 1259 | break; |
| 1260 | |
| 1261 | case 'fancybox': |
| 1262 | wp_register_script( |
| 1263 | '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 ) |
| 1264 | ); |
| 1265 | |
| 1266 | wp_register_style( |
| 1267 | 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1268 | ); |
| 1269 | |
| 1270 | $scripts[] = 'responsive-lightbox-fancybox'; |
| 1271 | $styles[] = 'responsive-lightbox-fancybox'; |
| 1272 | |
| 1273 | $args = array_merge( |
| 1274 | $args, array( |
| 1275 | 'modal' => $this->get_boolean_value( $this->options['configuration']['fancybox']['modal'] ), |
| 1276 | 'showOverlay' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_overlay'] ), |
| 1277 | 'showCloseButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_close_button'] ), |
| 1278 | 'enableEscapeButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['enable_escape_button'] ), |
| 1279 | 'hideOnOverlayClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_overlay_click'] ), |
| 1280 | 'hideOnContentClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_content_click'] ), |
| 1281 | 'cyclic' => $this->get_boolean_value( $this->options['configuration']['fancybox']['cyclic'] ), |
| 1282 | 'showNavArrows' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_nav_arrows'] ), |
| 1283 | 'autoScale' => $this->get_boolean_value( $this->options['configuration']['fancybox']['auto_scale'] ), |
| 1284 | 'scrolling' => $this->options['configuration']['fancybox']['scrolling'], |
| 1285 | 'centerOnScroll' => $this->get_boolean_value( $this->options['configuration']['fancybox']['center_on_scroll'] ), |
| 1286 | 'opacity' => $this->get_boolean_value( $this->options['configuration']['fancybox']['opacity'] ), |
| 1287 | 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'], |
| 1288 | 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'], |
| 1289 | 'titleShow' => $this->get_boolean_value( $this->options['configuration']['fancybox']['title_show'] ), |
| 1290 | 'titlePosition' => $this->options['configuration']['fancybox']['title_position'], |
| 1291 | 'transitions' => $this->options['configuration']['fancybox']['transitions'], |
| 1292 | 'easings' => $this->options['configuration']['fancybox']['easings'], |
| 1293 | 'speeds' => $this->options['configuration']['fancybox']['speeds'], |
| 1294 | 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'], |
| 1295 | 'changeFade' => $this->options['configuration']['fancybox']['change_fade'], |
| 1296 | 'padding' => $this->options['configuration']['fancybox']['padding'], |
| 1297 | 'margin' => $this->options['configuration']['fancybox']['margin'], |
| 1298 | 'videoWidth' => $this->options['configuration']['fancybox']['video_width'], |
| 1299 | 'videoHeight' => $this->options['configuration']['fancybox']['video_height'] |
| 1300 | ) |
| 1301 | ); |
| 1302 | break; |
| 1303 | |
| 1304 | case 'nivo': |
| 1305 | wp_register_script( |
| 1306 | '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'] |
| 1307 | ); |
| 1308 | |
| 1309 | wp_register_style( |
| 1310 | 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1311 | ); |
| 1312 | |
| 1313 | wp_register_style( |
| 1314 | 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ ), array(), $this->defaults['version'] |
| 1315 | ); |
| 1316 | |
| 1317 | $scripts[] = 'responsive-lightbox-nivo'; |
| 1318 | $styles[] = 'responsive-lightbox-nivo'; |
| 1319 | $styles[] = 'responsive-lightbox-nivo-default'; |
| 1320 | |
| 1321 | $args = array_merge( |
| 1322 | $args, array( |
| 1323 | 'effect' => $this->options['configuration']['nivo']['effect'], |
| 1324 | 'clickOverlayToClose' => $this->get_boolean_value( $this->options['configuration']['nivo']['click_overlay_to_close'] ), |
| 1325 | 'keyboardNav' => $this->get_boolean_value( $this->options['configuration']['nivo']['keyboard_nav'] ), |
| 1326 | 'errorMessage' => esc_attr( $this->options['configuration']['nivo']['error_message'] ) |
| 1327 | ) |
| 1328 | ); |
| 1329 | break; |
| 1330 | |
| 1331 | case 'imagelightbox': |
| 1332 | wp_register_script( |
| 1333 | 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ) |
| 1334 | ); |
| 1335 | |
| 1336 | wp_register_style( |
| 1337 | 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1338 | ); |
| 1339 | |
| 1340 | $scripts[] = 'responsive-lightbox-imagelightbox'; |
| 1341 | $styles[] = 'responsive-lightbox-imagelightbox'; |
| 1342 | |
| 1343 | $args = array_merge( |
| 1344 | $args, array( |
| 1345 | 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'], |
| 1346 | 'preloadNext' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['preload_next'] ), |
| 1347 | 'enableKeyboard' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['enable_keyboard'] ), |
| 1348 | 'quitOnEnd' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_end'] ), |
| 1349 | 'quitOnImageClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_image_click'] ), |
| 1350 | 'quitOnDocumentClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_document_click'] ), |
| 1351 | ) |
| 1352 | ); |
| 1353 | break; |
| 1354 | |
| 1355 | case 'tosrus': |
| 1356 | // swipe support, enqueue Hammer.js on mobile devices only |
| 1357 | if ( wp_is_mobile() ) { |
| 1358 | wp_register_script( |
| 1359 | 'responsive-lightbox-hammer-js', plugins_url( 'assets/tosrus/hammer' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array(), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ) |
| 1360 | ); |
| 1361 | $scripts[] = 'responsive-lightbox-hammer-js'; |
| 1362 | } |
| 1363 | |
| 1364 | wp_register_script( |
| 1365 | 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ) |
| 1366 | ); |
| 1367 | |
| 1368 | wp_register_style( |
| 1369 | 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1370 | ); |
| 1371 | |
| 1372 | $scripts[] = 'responsive-lightbox-tosrus'; |
| 1373 | $styles[] = 'responsive-lightbox-tosrus'; |
| 1374 | |
| 1375 | $args = array_merge( $args, array( |
| 1376 | 'effect' => $this->options['configuration']['tosrus']['effect'], |
| 1377 | 'infinite' => $this->get_boolean_value( $this->options['configuration']['tosrus']['infinite'] ), |
| 1378 | 'keys' => $this->get_boolean_value( $this->options['configuration']['tosrus']['keys'] ), |
| 1379 | 'autoplay' => $this->get_boolean_value( $this->options['configuration']['tosrus']['autoplay'] ), |
| 1380 | 'pauseOnHover' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pause_on_hover'] ), |
| 1381 | 'timeout' => $this->options['configuration']['tosrus']['timeout'], |
| 1382 | 'pagination' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pagination'] ), |
| 1383 | 'paginationType' => $this->options['configuration']['tosrus']['pagination_type'], |
| 1384 | 'closeOnClick' => $this->get_boolean_value( $this->options['configuration']['tosrus']['close_on_click'] ) |
| 1385 | ) |
| 1386 | ); |
| 1387 | break; |
| 1388 | |
| 1389 | case 'featherlight': |
| 1390 | wp_register_script( |
| 1391 | '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 ) |
| 1392 | ); |
| 1393 | |
| 1394 | wp_register_style( |
| 1395 | 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1396 | ); |
| 1397 | |
| 1398 | wp_register_script( |
| 1399 | '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 ) |
| 1400 | ); |
| 1401 | |
| 1402 | wp_register_style( |
| 1403 | 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] |
| 1404 | ); |
| 1405 | |
| 1406 | $scripts[] = 'responsive-lightbox-featherlight'; |
| 1407 | $styles[] = 'responsive-lightbox-featherlight'; |
| 1408 | $scripts[] = 'responsive-lightbox-featherlight-gallery'; |
| 1409 | $styles[] = 'responsive-lightbox-featherlight-gallery'; |
| 1410 | |
| 1411 | $args = array_merge( |
| 1412 | $args, |
| 1413 | array( |
| 1414 | 'openSpeed' => $this->options['configuration']['featherlight']['open_speed'], |
| 1415 | 'closeSpeed' => $this->options['configuration']['featherlight']['close_speed'], |
| 1416 | 'closeOnClick' => $this->options['configuration']['featherlight']['close_on_click'], |
| 1417 | 'closeOnEsc' => $this->get_boolean_value( $this->options['configuration']['featherlight']['close_on_esc'] ), |
| 1418 | 'galleryFadeIn' => $this->options['configuration']['featherlight']['gallery_fade_in'], |
| 1419 | 'galleryFadeOut' => $this->options['configuration']['featherlight']['gallery_fade_out'] |
| 1420 | ) |
| 1421 | ); |
| 1422 | break; |
| 1423 | |
| 1424 | case 'magnific': |
| 1425 | 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 ) ); |
| 1426 | |
| 1427 | wp_register_style( 'responsive-lightbox-magnific', plugins_url( 'assets/magnific/magnific-popup' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] ); |
| 1428 | |
| 1429 | $scripts[] = 'responsive-lightbox-magnific'; |
| 1430 | $styles[] = 'responsive-lightbox-magnific'; |
| 1431 | |
| 1432 | $args = array_merge( |
| 1433 | $args, |
| 1434 | array( |
| 1435 | 'disableOn' => $this->options['configuration']['magnific']['disable_on'], |
| 1436 | 'midClick' => $this->options['configuration']['magnific']['mid_click'], |
| 1437 | 'preloader' => $this->options['configuration']['magnific']['preloader'], |
| 1438 | 'closeOnContentClick' => $this->options['configuration']['magnific']['close_on_content_click'], |
| 1439 | 'closeOnBgClick' => $this->options['configuration']['magnific']['close_on_background_click'], |
| 1440 | 'closeBtnInside' => $this->options['configuration']['magnific']['close_button_inside'], |
| 1441 | 'showCloseBtn' => $this->options['configuration']['magnific']['show_close_button'], |
| 1442 | 'enableEscapeKey' => $this->options['configuration']['magnific']['enable_escape_key'], |
| 1443 | 'alignTop' => $this->options['configuration']['magnific']['align_top'], |
| 1444 | 'fixedContentPos' => $this->options['configuration']['magnific']['fixed_content_position'], |
| 1445 | 'fixedBgPos' => $this->options['configuration']['magnific']['fixed_background_position'], |
| 1446 | 'autoFocusLast' => $this->options['configuration']['magnific']['auto_focus_last'] |
| 1447 | ) |
| 1448 | ); |
| 1449 | break; |
| 1450 | |
| 1451 | default: |
| 1452 | do_action( 'rl_lightbox_enqueue_scripts' ); |
| 1453 | |
| 1454 | $scripts = apply_filters( 'rl_lightbox_scripts', $scripts ); |
| 1455 | $styles = apply_filters( 'rl_lightbox_styles', $styles ); |
| 1456 | } |
| 1457 | |
| 1458 | // run scripts by default |
| 1459 | $contitional_scripts = true; |
| 1460 | |
| 1461 | if ( $this->options['settings']['conditional_loading'] === true ) { |
| 1462 | global $post; |
| 1463 | |
| 1464 | if ( is_object( $post ) ) { |
| 1465 | // is gallery present in content |
| 1466 | $has_gallery = has_shortcode( $post->post_content, 'gallery' ) || has_shortcode( $post->post_content, 'rl_gallery' ); |
| 1467 | |
| 1468 | // are images present in content |
| 1469 | preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $post->post_content, $links ); |
| 1470 | |
| 1471 | $has_images = (bool) $links[0]; |
| 1472 | |
| 1473 | if ( $has_gallery === false && $has_images === false ) |
| 1474 | $contitional_scripts = false; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) { |
| 1479 | wp_register_script( 'responsive-lightbox-infinite-scroll', RESPONSIVE_LIGHTBOX_URL . '/assets/infinitescroll/infinite-scroll.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) ); |
| 1480 | wp_register_script( 'responsive-lightbox-images-loaded', RESPONSIVE_LIGHTBOX_URL . '/assets/imagesloaded/imagesloaded.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) ); |
| 1481 | 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' ) ); |
| 1482 | |
| 1483 | 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 ) ); |
| 1484 | |
| 1485 | $args['woocommerce_gallery'] = 0; |
| 1486 | |
| 1487 | if ( class_exists( 'WooCommerce' ) ) { |
| 1488 | global $woocommerce; |
| 1489 | |
| 1490 | if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) { |
| 1491 | if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) |
| 1492 | $args['woocommerce_gallery'] = 1; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | $scripts[] = 'responsive-lightbox'; |
| 1497 | |
| 1498 | $args['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
| 1499 | $args['nonce'] = wp_create_nonce( 'rl_nonce' ); |
| 1500 | |
| 1501 | // enqueue scripts |
| 1502 | if ( $scripts && is_array( $scripts ) ) { |
| 1503 | foreach ( $scripts as $script ) { |
| 1504 | wp_enqueue_script( $script ); |
| 1505 | } |
| 1506 | |
| 1507 | wp_localize_script( 'responsive-lightbox', 'rlArgs', $args ); |
| 1508 | } |
| 1509 | |
| 1510 | // enqueue styles |
| 1511 | if ( $styles && is_array( $styles ) ) { |
| 1512 | foreach ( $styles as $style ) { |
| 1513 | wp_enqueue_style( $style ); |
| 1514 | } |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | // gallery style |
| 1519 | wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), array(), Responsive_Lightbox()->defaults['version'] ); |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * Helper: convert value to boolean |
| 1524 | * |
| 1525 | * @param int $option |
| 1526 | * @return bool |
| 1527 | */ |
| 1528 | private function get_boolean_value( $option ) { |
| 1529 | return ( $option == true ? 1 : 0 ); |
| 1530 | } |
| 1531 | |
| 1532 | /** |
| 1533 | * Helper: convert hex color to rgb color. |
| 1534 | * |
| 1535 | * @param type $color |
| 1536 | * @return array |
| 1537 | */ |
| 1538 | public function hex2rgb( $color ) { |
| 1539 | if ( $color[0] == '#' ) |
| 1540 | $color = substr( $color, 1 ); |
| 1541 | |
| 1542 | if ( strlen( $color ) == 6 ) |
| 1543 | list( $r, $g, $b ) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); |
| 1544 | elseif ( strlen( $color ) == 3 ) |
| 1545 | list( $r, $g, $b ) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); |
| 1546 | else |
| 1547 | return false; |
| 1548 | |
| 1549 | $r = hexdec( $r ); |
| 1550 | $g = hexdec( $g ); |
| 1551 | $b = hexdec( $b ); |
| 1552 | |
| 1553 | return array( $r, $g, $b ); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * Initialize Responsive Lightbox. |
| 1559 | */ |
| 1560 | function Responsive_Lightbox() { |
| 1561 | static $instance; |
| 1562 | |
| 1563 | // first call to instance() initializes the plugin |
| 1564 | if ( $instance === null || ! ($instance instanceof Responsive_Lightbox) ) { |
| 1565 | $instance = Responsive_Lightbox::instance(); |
| 1566 | } |
| 1567 | |
| 1568 | return $instance; |
| 1569 | } |
| 1570 | |
| 1571 | $responsive_lightbox = Responsive_Lightbox(); |