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