PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.2.3.1
Responsive Lightbox & Gallery v2.2.3.1
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / responsive-lightbox.php
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
1581 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.3.1
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-2020, 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.3
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' => false,
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.3',
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, 'plugins_loaded_init' ) );
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 * Early initialization.
465 *
466 * @return void
467 */
468 public function plugins_loaded_init() {
469 // load textdomain
470 load_plugin_textdomain( 'responsive-lightbox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
471
472 // set gallery types
473 $this->gallery_types = array(
474 'default' => __( 'Default', 'responsive-lightbox' ),
475 'basicgrid' => __( 'Basic Grid', 'responsive-lightbox' ),
476 'basicslider' => __( 'Basic Slider', 'responsive-lightbox' ),
477 'basicmasonry' => __( 'Basic Masonry', 'responsive-lightbox' )
478 );
479
480 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'class-multilang.php' );
481 }
482
483 /**
484 * Update notice.
485 *
486 * @return void
487 */
488 public function update_notice() {
489 if ( ! current_user_can( 'install_plugins' ) )
490 return;
491
492 $current_update = 2;
493
494 // get current time
495 $current_time = time();
496
497 if ( $this->options['settings']['update_version'] < $current_update ) {
498 // check version, if update ver is lower than plugin ver, set update notice to true
499 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_version' => $current_update, 'update_notice' => true ) );
500
501 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
502
503 // set activation date
504 $activation_date = get_option( 'responsive_lightbox_activation_date' );
505
506 if ( $activation_date === false )
507 update_option( 'responsive_lightbox_activation_date', $current_time );
508 }
509
510 // display current version notice
511 if ( $this->options['settings']['update_notice'] === true ) {
512 // include notice js, only if needed
513 add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ), 999 );
514
515 // get activation date
516 $activation_date = get_option( 'responsive_lightbox_activation_date' );
517
518 if ( (int) $this->options['settings']['update_delay_date'] === 0 ) {
519 if ( $activation_date + 1209600 > $current_time )
520 $this->options['settings']['update_delay_date'] = $activation_date + 1209600;
521 else
522 $this->options['settings']['update_delay_date'] = $current_time;
523
524 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
525 }
526
527 if ( ( ! empty( $this->options['settings']['update_delay_date'] ) ? (int) $this->options['settings']['update_delay_date'] : $current_time ) <= $current_time )
528 $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' );
529 }
530 }
531
532 /**
533 * Dismiss notice.
534 *
535 * @return void
536 */
537 public function dismiss_notice() {
538 if ( ! current_user_can( 'install_plugins' ) )
539 return;
540
541 if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'rl_dismiss_notice' ) ) {
542 $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] );
543
544 switch ( $notice_action ) {
545 // delay notice
546 case 'delay':
547 // set delay period to 1 week from now
548 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => time() + 1209600 ) );
549 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
550 break;
551
552 // hide notice
553 default:
554 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_notice' => false ) );
555 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_delay_date' => 0 ) );
556
557 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
558 }
559 }
560
561 exit;
562 }
563
564 /**
565 * Add admin notices.
566 *
567 * @param string $html Notice HTML
568 * @param string $status Notice status
569 * @param bool $paragraph Whether to use paragraph
570 * @param bool $network
571 * @return void
572 */
573 public function add_notice( $html = '', $status = 'error', $paragraph = true, $network = false ) {
574 $this->notices[] = array(
575 'html' => $html,
576 'status' => $status,
577 'paragraph' => $paragraph
578 );
579
580 add_action( 'admin_notices', array( $this, 'display_notice') );
581
582 if ( $network )
583 add_action( 'network_admin_notices', array( $this, 'display_notice') );
584 }
585
586 /**
587 * Print admin notices.
588 *
589 * @return void
590 */
591 public function display_notice() {
592 foreach( $this->notices as $notice ) {
593 echo '
594 <div class="' . $notice['status'] . '">
595 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
596 ' . $notice['html'] . '
597 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
598 </div>';
599 }
600 }
601
602 /**
603 * Print admin scripts.
604 *
605 * @return void
606 */
607 public function admin_inline_js() {
608 if ( ! current_user_can( 'install_plugins' ) )
609 return;
610 ?>
611 <script type="text/javascript">
612 ( function ( $ ) {
613 $( document ).ready( function () {
614 // save dismiss state
615 $( '.rl-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .rl-dismissible-notice', function ( e ) {
616 var notice_action = 'hide';
617
618 if ( $( e.currentTarget ).hasClass( 'rl-delay-notice' ) ) {
619 notice_action = 'delay'
620 }
621
622 $.post( ajaxurl, {
623 action: 'rl_dismiss_notice',
624 notice_action: notice_action,
625 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
626 nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>'
627 } );
628
629 $( e.delegateTarget ).slideUp( 'fast' );
630 } );
631 } );
632 } )( jQuery );
633 </script>
634 <?php
635 }
636
637 /**
638 * Add links to Support Forum.
639 *
640 * @param array $links
641 * @param string $file
642 * @return array
643 */
644 public function plugin_extend_links( $links, $file ) {
645 if ( ! current_user_can( 'install_plugins' ) )
646 return $links;
647
648 $plugin = plugin_basename( __FILE__ );
649
650 if ( $file == $plugin ) {
651 return array_merge(
652 $links, array( sprintf( '<a href="https://dfactory.eu/support/forum/responsive-lightbox/" target="_blank">%s</a>', __( 'Support', 'responsive-lightbox' ) ) )
653 );
654 }
655
656 return $links;
657 }
658
659 /**
660 * Add links to Settings page.
661 *
662 * @param array $links
663 * @param string $file
664 * @return array
665 */
666 public function plugin_settings_link( $links, $file ) {
667 if ( ! is_admin() || ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) )
668 return $links;
669
670 static $plugin;
671
672 $plugin = plugin_basename( __FILE__ );
673
674 if ( $file == $plugin ) {
675 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-settings', __( 'Settings', 'responsive-lightbox' ) );
676 array_unshift( $links, $settings_link );
677
678 $links[] = sprintf( '<a href="%s" style="color: green;">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-addons', __( 'Add-ons', 'responsive-lightbox' ) );
679 }
680
681 return $links;
682 }
683
684 /**
685 * Initialize remote libraries.
686 *
687 * @return void
688 */
689 public function init_remote_libraries() {
690 // include classes
691 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library.php' );
692 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-remote-library-api.php' );
693
694 $this->remote_library = new Responsive_Lightbox_Remote_Library();
695
696 // simple html dom
697 if ( ! function_exists( 'file_get_html' ) )
698 include_once( RESPONSIVE_LIGHTBOX_PATH . 'library/simplehtmldom/simple_html_dom.php' );
699
700 // include providers
701 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' );
702 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' );
703 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-wikimedia.php' );
704 }
705
706 /**
707 * Initialize galleries.
708 *
709 * @return void
710 */
711 public function init_galleries() {
712 // initialize gallery class
713 new Responsive_Lightbox_Galleries( ! $this->options['builder']['gallery_builder'] );
714
715 // end if in read only mode
716 if ( ! $this->options['builder']['gallery_builder'] )
717 return;
718
719 $taxonomies = array();
720
721 if ( $this->options['builder']['categories'] ) {
722 $taxonomies[] = 'rl_category';
723
724 register_taxonomy( 'rl_category', 'rl_gallery', array(
725 'public' => true,
726 'hierarchical' => true,
727 'labels' => array(
728 'name' => _x( 'Gallery Categories', 'taxonomy general name', 'responsive-lightbox' ),
729 'singular_name' => _x( 'Gallery Category', 'taxonomy singular name', 'responsive-lightbox' ),
730 'search_items' => __( 'Search Gallery Categories', 'responsive-lightbox' ),
731 'all_items' => __( 'All Gallery Categories', 'responsive-lightbox' ),
732 'parent_item' => __( 'Parent Gallery Category', 'responsive-lightbox' ),
733 'parent_item_colon' => __( 'Parent Gallery Category:', 'responsive-lightbox' ),
734 'edit_item' => __( 'Edit Gallery Category', 'responsive-lightbox' ),
735 'view_item' => __( 'View Gallery Category', 'responsive-lightbox' ),
736 'update_item' => __( 'Update Gallery Category', 'responsive-lightbox' ),
737 'add_new_item' => __( 'Add New Gallery Category', 'responsive-lightbox' ),
738 'new_item_name' => __( 'New Gallery Category Name', 'responsive-lightbox' ),
739 'menu_name' => __( 'Categories', 'responsive-lightbox' )
740 ),
741 'show_ui' => true,
742 'show_admin_column' => true,
743 'update_count_callback' => '_update_post_term_count',
744 'query_var' => true,
745 'rewrite' => array(
746 'slug' => $this->options['builder']['permalink_categories'],
747 'with_front' => false,
748 'hierarchical' => false
749 )
750 ) );
751 }
752
753 if ( $this->options['builder']['tags'] ) {
754 $taxonomies[] = 'rl_tag';
755
756 register_taxonomy( 'rl_tag', 'rl_gallery', array(
757 'public' => true,
758 'hierarchical' => false,
759 'labels' => array(
760 'name' => _x( 'Gallery Tags', 'taxonomy general name', 'responsive-lightbox' ),
761 'singular_name' => _x( 'Gallery Tag', 'taxonomy singular name', 'responsive-lightbox' ),
762 'search_items' => __( 'Search Gallery Tags', 'responsive-lightbox' ),
763 'popular_items' => __( 'Popular Gallery Tags', 'responsive-lightbox' ),
764 'all_items' => __( 'All Gallery Tags', 'responsive-lightbox' ),
765 'parent_item' => null,
766 'parent_item_colon' => null,
767 'edit_item' => __( 'Edit Gallery Tag', 'responsive-lightbox' ),
768 'update_item' => __( 'Update Gallery Tag', 'responsive-lightbox' ),
769 'add_new_item' => __( 'Add New Gallery Tag', 'responsive-lightbox' ),
770 'new_item_name' => __( 'New Gallery Tag Name', 'responsive-lightbox' ),
771 'separate_items_with_commas' => __( 'Separate gallery tags with commas', 'responsive-lightbox' ),
772 'add_or_remove_items' => __( 'Add or remove gallery tags', 'responsive-lightbox' ),
773 'choose_from_most_used' => __( 'Choose from the most used gallery tags', 'responsive-lightbox' ),
774 'menu_name' => __( 'Tags', 'responsive-lightbox' )
775 ),
776 'show_ui' => true,
777 'show_admin_column' => true,
778 'update_count_callback' => '_update_post_term_count',
779 'query_var' => true,
780 'rewrite' => array(
781 'slug' => $this->options['builder']['permalink_tags'],
782 'with_front' => false,
783 'hierarchical' => false
784 )
785 ) );
786 }
787
788 // register rl_gallery
789 register_post_type(
790 'rl_gallery',
791 array(
792 'labels' => array(
793 'name' => _x( 'Galleries', 'post type general name', 'responsive-lightbox' ),
794 'singular_name' => _x( 'Gallery', 'post type singular name', 'responsive-lightbox' ),
795 'add_new' => __( 'Add New', 'responsive-lightbox' ),
796 'add_new_item' => __( 'Add New Gallery', 'responsive-lightbox' ),
797 'edit_item' => __( 'Edit Gallery', 'responsive-lightbox' ),
798 'new_item' => __( 'New Gallery', 'responsive-lightbox' ),
799 'view_item' => __( 'View Gallery', 'responsive-lightbox' ),
800 'view_items' => __( 'View Galleries', 'responsive-lightbox' ),
801 'search_items' => __( 'Search Galleries', 'responsive-lightbox' ),
802 'not_found' => __( 'No galleries found', 'responsive-lightbox' ),
803 'not_found_in_trash' => __( 'No galleries found in trash', 'responsive-lightbox' ),
804 'all_items' => __( 'All Galleries', 'responsive-lightbox' ),
805 'menu_name' => __( 'Gallery', 'responsive-lightbox' )
806 ),
807 'description' => '',
808 'public' => true,
809 'exclude_from_search' => false,
810 'publicly_queryable' => true,
811 'show_ui' => true,
812 'show_in_menu' => true,
813 'show_in_admin_bar' => true,
814 'show_in_nav_menus' => true,
815 'menu_position' => 57,
816 'menu_icon' => 'dashicons-format-gallery',
817 'map_meta_cap' => true,
818 'hierarchical' => false,
819 'supports' => array( 'title', 'author', 'thumbnail' ),
820 'has_archive' => $this->options['builder']['archives'],
821 'query_var' => true,
822 'can_export' => true,
823 'rewrite' => array(
824 'slug' => $this->options['builder']['permalink'],
825 'with_front' => false,
826 'feed' => true,
827 'pages' => true
828 ),
829 'taxonomies' => $taxonomies
830 )
831 );
832
833 if ( $this->options['builder']['archives'] && $this->options['builder']['archives_category'] !== 'all' && ! is_admin() )
834 add_action( 'pre_get_posts', array( $this, 'gallery_archives' ) );
835
836 add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
837 }
838
839 /**
840 * Gallery update messages.
841 *
842 * @param array $messages
843 * @return array
844 */
845 public function gallery_archives( $query ) {
846 if ( is_post_type_archive( 'rl_gallery' ) ) {
847 $query->set(
848 'tax_query',
849 array(
850 'relation' => 'OR',
851 array(
852 'taxonomy' => 'rl_category',
853 'field' => 'slug',
854 'terms' => $this->options['builder']['archives_category']
855 )
856 )
857 );
858 }
859 }
860
861 /**
862 * Gallery update messages.
863 *
864 * @param array $messages
865 * @return array
866 */
867 public function post_updated_messages( $messages ) {
868 $post = get_post();
869 $post_type = get_post_type( $post );
870 $post_type_object = get_post_type_object( $post_type );
871
872 $messages['rl_gallery'] = array(
873 1 => __( 'Gallery updated.', 'responsive-lightbox' ),
874 4 => __( 'Gallery updated.', 'responsive-lightbox' ),
875 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Gallery restored to revision from %s', 'responsive-lightbox' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
876 6 => __( 'Gallery published.', 'responsive-lightbox' ),
877 7 => __( 'Gallery saved.', 'responsive-lightbox' ),
878 8 => __( 'Gallery submitted.', 'responsive-lightbox' ),
879 9 => sprintf(
880 __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'responsive-lightbox' ),
881 date_i18n( __( 'M j, Y @ G:i', 'responsive-lightbox' ), strtotime( $post->post_date ) )
882 ),
883 10 => __( 'Gallery draft updated.', 'responsive-lightbox' )
884 );
885
886 if ( $post_type_object->publicly_queryable && 'rl_gallery' === $post_type ) {
887 $permalink = get_permalink( $post->ID );
888
889 $view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View gallery', 'responsive-lightbox' ) );
890 $messages[$post_type][1] .= $view_link;
891 $messages[$post_type][6] .= $view_link;
892 $messages[$post_type][9] .= $view_link;
893
894 $preview_permalink = add_query_arg( 'preview', 'true', $permalink );
895 $preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview gallery', 'responsive-lightbox' ) );
896 $messages[$post_type][8] .= $preview_link;
897 $messages[$post_type][10] .= $preview_link;
898 }
899
900 return $messages;
901 }
902
903 /**
904 * Initialize folders.
905 *
906 * @return void
907 */
908 public function init_folders() {
909 // initialize folder class
910 new Responsive_Lightbox_Folders( ! $this->options['folders']['active'] );
911
912 // end if in read only mode
913 if ( ! $this->options['folders']['active'] )
914 return;
915
916 // register media taxonomy
917 $this->register_media_taxonomy( 'rl_media_folder' );
918
919 // register media tags
920 if ( $this->options['folders']['media_tags'] ) {
921 register_taxonomy(
922 'rl_media_tag',
923 'attachment',
924 array(
925 'public' => true,
926 'hierarchical' => false,
927 'labels' => array(
928 'name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ),
929 'singular_name' => _x( 'Tag', 'taxonomy singular name', 'responsive-lightbox' ),
930 'search_items' => __( 'Search Tags', 'responsive-lightbox' ),
931 'all_items' => __( 'All Tags', 'responsive-lightbox' ),
932 'edit_item' => __( 'Edit Tag', 'responsive-lightbox' ),
933 'update_item' => __( 'Update Tag', 'responsive-lightbox' ),
934 'add_new_item' => __( 'Add New Tag', 'responsive-lightbox' ),
935 'new_item_name' => __( 'New Tag Name', 'responsive-lightbox' ),
936 'not_found' => __( 'No tags found.', 'responsive-lightbox' ),
937 'menu_name' => _x( 'Tags', 'taxonomy general name', 'responsive-lightbox' ),
938 ),
939 'show_ui' => true,
940 'show_in_menu' => $this->options['folders']['show_in_menu'],
941 'show_in_nav_menus' => false,
942 'show_in_quick_edit' => true,
943 'show_tagcloud' => false,
944 'show_admin_column' => $this->options['folders']['show_in_menu'],
945 'update_count_callback' => '_update_generic_term_count',
946 'query_var' => false,
947 'rewrite' => false
948 )
949 );
950 }
951
952 // get non-builtin hierarchical taxonomies
953 $taxonomies = get_taxonomies(
954 array(
955 'object_type' => array( 'attachment' ),
956 'hierarchical' => true,
957 '_builtin' => false
958 ),
959 'objects',
960 'and'
961 );
962
963 $media_taxonomies = array();
964
965 foreach ( $taxonomies as $taxonomy => $object ) {
966 $media_taxonomies[$taxonomy] = $taxonomy . ' (' . $object->labels->menu_name . ')';
967 }
968
969 $tax = $this->options['folders']['media_taxonomy'];
970
971 // selected hierarchical taxonomy does not exists?
972 if ( ! in_array( $tax, $media_taxonomies, true ) ) {
973 // check taxonomy existence
974 if ( ( $taxonomy = get_taxonomy( $tax ) ) !== false ) {
975 // update
976 $media_taxonomies[$tax] = $tax . ' (' . $taxonomy->labels->menu_name . ')';
977 // is it really old taxonomy?
978 } elseif ( in_array( $tax, Responsive_Lightbox()->folders->get_taxonomies(), true ) ) {
979 $this->register_media_taxonomy( $tax );
980
981 $media_taxonomies[$tax] = $tax;
982 // use default taxonomy
983 } else {
984 $media_taxonomies[$tax] = $tax;
985 $this->options['folders']['media_taxonomy'] = $this->defaults['folders']['media_taxonomy'];
986
987 update_option( 'responsive_lightbox_folders', $this->options['folders'] );
988 }
989 }
990
991 $this->settings->settings['folders']['fields']['media_taxonomy']['options'] = $media_taxonomies;
992 }
993
994 /**
995 * Register media taxonomy.
996 *
997 * @return void
998 */
999 public function register_media_taxonomy( $taxonomy ) {
1000 $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' ) ) );
1001
1002 register_taxonomy(
1003 $taxonomy,
1004 'attachment',
1005 array(
1006 'public' => true,
1007 'hierarchical' => true,
1008 'labels' => array(
1009 'name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ),
1010 'singular_name' => _x( 'Folder', 'taxonomy singular name', 'responsive-lightbox' ),
1011 'search_items' => __( 'Search Folders', 'responsive-lightbox' ),
1012 'all_items' => __( 'All Files', 'responsive-lightbox' ),
1013 'parent_item' => __( 'Parent Folder', 'responsive-lightbox' ),
1014 'parent_item_colon' => __( 'Parent Folder:', 'responsive-lightbox' ),
1015 'edit_item' => __( 'Edit Folder', 'responsive-lightbox' ),
1016 'update_item' => __( 'Update Folder', 'responsive-lightbox' ),
1017 'add_new_item' => __( 'Add New Folder', 'responsive-lightbox' ),
1018 'new_item_name' => __( 'New Folder Name', 'responsive-lightbox' ),
1019 'not_found' => __( 'No folders found.', 'responsive-lightbox' ),
1020 'menu_name' => _x( 'Folders', 'taxonomy general name', 'responsive-lightbox' ),
1021 ),
1022 'show_ui' => ! ( $taxonomy === 'rl_media_folder' && $this->options['folders']['media_taxonomy'] !== 'rl_media_folder' ),
1023 'show_in_menu' => $show_in_menu,
1024 'show_in_nav_menus' => false,
1025 'show_in_quick_edit' => true,
1026 'show_tagcloud' => false,
1027 'show_admin_column' => $show_in_menu,
1028 'update_count_callback' => '_update_generic_term_count',
1029 'query_var' => false,
1030 'rewrite' => false
1031 )
1032 );
1033 }
1034
1035 /**
1036 * Enqueue admin scripts and styles.
1037 *
1038 * @param string $page
1039 * @return void
1040 */
1041 public function admin_scripts_styles( $page ) {
1042 wp_register_script( 'rl-knockout', RESPONSIVE_LIGHTBOX_URL . '/assets/knockout/knockout' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', null, $this->defaults['version'] );
1043
1044 if ( preg_match( '/^(toplevel|lightbox)_page_responsive-lightbox-(' . implode( '|', array_keys( Responsive_Lightbox()->settings->tabs ) ) . ')$/', $page ) === 1 ) {
1045 wp_enqueue_script( 'responsive-lightbox-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), $this->defaults['version'] );
1046
1047 wp_localize_script(
1048 'responsive-lightbox-admin',
1049 'rlArgsAdmin',
1050 array(
1051 'resetSettingsToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ),
1052 'resetScriptToDefaults' => __( 'Are you sure you want to reset this script settings to defaults?', 'responsive-lightbox' ),
1053 'resetGalleryToDefaults' => __( 'Are you sure you want to reset this gallery settings to defaults?', 'responsive-lightbox' ),
1054 'tax_nonce' => wp_create_nonce( 'rl-folders-ajax-taxonomies-nonce' ),
1055 )
1056 );
1057
1058 wp_enqueue_style( 'wp-color-picker' );
1059
1060 wp_enqueue_style( 'responsive-lightbox-admin', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->defaults['version'] );
1061 } elseif ( in_array( $page, array( 'post.php', 'edit.php', 'post-new.php' ), true ) && get_post_type() === 'rl_gallery' ) {
1062 wp_enqueue_media();
1063
1064 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'] );
1065
1066 wp_enqueue_script( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/js/admin-galleries.js', array( 'jquery', 'underscore', 'wp-color-picker' ), $this->defaults['version'] );
1067
1068 wp_localize_script(
1069 'responsive-lightbox-admin-galleries',
1070 'rlArgsGalleries',
1071 array(
1072 'mediaItemTemplate' => $this->galleries->get_media_item_template( $this->galleries->fields['images']['media']['attachments']['preview'] ),
1073 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ),
1074 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ),
1075 'editTitle' => __( 'Edit attachment', 'responsive-lightbox' ),
1076 'buttonEditFile' => __( 'Save attachment', 'responsive-lightbox' ),
1077 'nonce' => wp_create_nonce( 'rl-gallery' ),
1078 'post_id' => get_the_ID()
1079 )
1080 );
1081
1082 wp_enqueue_style( 'wp-color-picker' );
1083
1084 wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', array(), $this->defaults['version'] );
1085
1086 wp_enqueue_style( 'responsive-lightbox-admin-galleries', RESPONSIVE_LIGHTBOX_URL . '/css/admin-galleries.css', array(), $this->defaults['version'] );
1087 }
1088 }
1089
1090 /**
1091 * Init Gutenberg.
1092 *
1093 * @return void
1094 */
1095 public function init_gutenberg() {
1096 // actions
1097 add_action( 'enqueue_block_editor_assets', array( $this, 'gutenberg_enqueue_scripts' ) );
1098
1099 // filters
1100 add_filter( 'block_categories', array( $this, 'block_category' ) );
1101 }
1102
1103 /**
1104 * Create block category.
1105 *
1106 * @return array
1107 */
1108 function block_category( $categories ) {
1109 return array_merge(
1110 $categories,
1111 array(
1112 array(
1113 'slug' => 'responsive-lightbox',
1114 'title' => 'Responsive Lightbox'
1115 )
1116 )
1117 );
1118 }
1119
1120 /**
1121 * Extend Gutenberg.
1122 *
1123 * @return void
1124 */
1125 public function gutenberg_enqueue_scripts() {
1126 $rl = Responsive_Lightbox();
1127
1128 // enqueue gallery
1129 $rl->galleries->enqueue_gallery_scripts_styles();
1130
1131 // enqueue script
1132 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'] );
1133
1134 // enqueue styles
1135 wp_enqueue_style( 'responsive-lightbox-block-editor-styles', RESPONSIVE_LIGHTBOX_URL . '/css/gutenberg.min.css', '', $rl->defaults['version'] );
1136
1137 wp_localize_script(
1138 'responsive-lightbox-block-editor-script',
1139 'rlBlockEditor',
1140 array(
1141 'active' => true
1142 )
1143 );
1144
1145 // register gallery block
1146 register_block_type(
1147 'responsive-lightbox/gallery',
1148 array(
1149 'editor_script' => 'block-editor-script'
1150 )
1151 );
1152
1153 // register remote library image block
1154 register_block_type(
1155 'responsive-lightbox/remote-library-image',
1156 array(
1157 'editor_script' => 'block-editor-script'
1158 )
1159 );
1160 }
1161
1162 /**
1163 * Enqueue admin widget scripts.
1164 *
1165 * @return void
1166 */
1167 public function sidebar_admin_setup() {
1168 wp_enqueue_media();
1169
1170 wp_enqueue_script( 'responsive-lightbox-admin-widgets', RESPONSIVE_LIGHTBOX_URL . '/js/admin-widgets.js', array( 'jquery', 'underscore' ), $this->defaults['version'] );
1171
1172 wp_localize_script(
1173 'responsive-lightbox-admin-widgets',
1174 'rlArgsWidgets',
1175 array(
1176 'textRemoveImage' => __( 'Remove image', 'responsive-lightbox' ),
1177 'textSelectImages' => __( 'Select images', 'responsive-lightbox' ),
1178 'textSelectImage' => __( 'Select image', 'responsive-lightbox' ),
1179 'textUseImages' => __( 'Use these images', 'responsive-lightbox' ),
1180 'textUseImage' => __( 'Use this image', 'responsive-lightbox' )
1181 )
1182 );
1183
1184 wp_register_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', array(), $this->defaults['version'] );
1185 wp_enqueue_style( 'responsive-lightbox-admin' );
1186 }
1187
1188 /**
1189 * Enqueue frontend scripts and styles.
1190 *
1191 * @return void
1192 */
1193 public function front_scripts_styles() {
1194 $args = apply_filters( 'rl_lightbox_args', array(
1195 'script' => $this->options['settings']['script'],
1196 'selector' => $this->options['settings']['selector'],
1197 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? ' ' . $this->options['settings']['custom_events'] : '' ),
1198 'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )
1199 ) );
1200
1201 $scripts = array();
1202 $styles = array();
1203
1204 switch ( $args['script'] ) {
1205 case 'prettyphoto':
1206 wp_register_script(
1207 '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 )
1208 );
1209
1210 wp_register_style(
1211 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/prettyPhoto' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1212 );
1213
1214 $scripts[] = 'responsive-lightbox-prettyphoto';
1215 $styles[] = 'responsive-lightbox-prettyphoto';
1216
1217 $args = array_merge(
1218 $args,
1219 array(
1220 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'],
1221 'slideshow' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow'] ),
1222 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'],
1223 'slideshowAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow_autoplay'] ),
1224 'opacity' => sprintf( '%.2f', ($this->options['configuration']['prettyphoto']['opacity'] / 100 ) ),
1225 'showTitle' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['show_title'] ),
1226 'allowResize' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_resize'] ),
1227 'allowExpand' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_expand'] ),
1228 'width' => $this->options['configuration']['prettyphoto']['width'],
1229 'height' => $this->options['configuration']['prettyphoto']['height'],
1230 'separator' => $this->options['configuration']['prettyphoto']['separator'],
1231 'theme' => $this->options['configuration']['prettyphoto']['theme'],
1232 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'],
1233 'hideFlash' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['hide_flash'] ),
1234 'wmode' => $this->options['configuration']['prettyphoto']['wmode'],
1235 'videoAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['video_autoplay'] ),
1236 'modal' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['modal'] ),
1237 'deeplinking' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['deeplinking'] ),
1238 'overlayGallery' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['overlay_gallery'] ),
1239 'keyboardShortcuts' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['keyboard_shortcuts'] ),
1240 'social' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['social'] )
1241 )
1242 );
1243 break;
1244
1245 case 'swipebox':
1246 wp_register_script(
1247 '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 )
1248 );
1249
1250 wp_register_style(
1251 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/swipebox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1252 );
1253
1254 $scripts[] = 'responsive-lightbox-swipebox';
1255 $styles[] = 'responsive-lightbox-swipebox';
1256
1257 $args = array_merge(
1258 $args, array(
1259 'animation' => $this->get_boolean_value( ($this->options['configuration']['swipebox']['animation'] === 'css' ? true : false ) ),
1260 'hideCloseButtonOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_close_mobile'] ),
1261 'removeBarsOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['remove_bars_mobile'] ),
1262 'hideBars' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_bars'] ),
1263 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'],
1264 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'],
1265 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'],
1266 'loopAtEnd' => $this->get_boolean_value( $this->options['configuration']['swipebox']['loop_at_end'] )
1267 )
1268 );
1269 break;
1270
1271 case 'fancybox':
1272 wp_register_script(
1273 '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 )
1274 );
1275
1276 wp_register_style(
1277 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1278 );
1279
1280 $scripts[] = 'responsive-lightbox-fancybox';
1281 $styles[] = 'responsive-lightbox-fancybox';
1282
1283 $args = array_merge(
1284 $args, array(
1285 'modal' => $this->get_boolean_value( $this->options['configuration']['fancybox']['modal'] ),
1286 'showOverlay' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_overlay'] ),
1287 'showCloseButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_close_button'] ),
1288 'enableEscapeButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['enable_escape_button'] ),
1289 'hideOnOverlayClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_overlay_click'] ),
1290 'hideOnContentClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_content_click'] ),
1291 'cyclic' => $this->get_boolean_value( $this->options['configuration']['fancybox']['cyclic'] ),
1292 'showNavArrows' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_nav_arrows'] ),
1293 'autoScale' => $this->get_boolean_value( $this->options['configuration']['fancybox']['auto_scale'] ),
1294 'scrolling' => $this->options['configuration']['fancybox']['scrolling'],
1295 'centerOnScroll' => $this->get_boolean_value( $this->options['configuration']['fancybox']['center_on_scroll'] ),
1296 'opacity' => $this->get_boolean_value( $this->options['configuration']['fancybox']['opacity'] ),
1297 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'],
1298 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'],
1299 'titleShow' => $this->get_boolean_value( $this->options['configuration']['fancybox']['title_show'] ),
1300 'titlePosition' => $this->options['configuration']['fancybox']['title_position'],
1301 'transitions' => $this->options['configuration']['fancybox']['transitions'],
1302 'easings' => $this->options['configuration']['fancybox']['easings'],
1303 'speeds' => $this->options['configuration']['fancybox']['speeds'],
1304 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'],
1305 'changeFade' => $this->options['configuration']['fancybox']['change_fade'],
1306 'padding' => $this->options['configuration']['fancybox']['padding'],
1307 'margin' => $this->options['configuration']['fancybox']['margin'],
1308 'videoWidth' => $this->options['configuration']['fancybox']['video_width'],
1309 'videoHeight' => $this->options['configuration']['fancybox']['video_height']
1310 )
1311 );
1312 break;
1313
1314 case 'nivo':
1315 wp_register_script(
1316 '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']
1317 );
1318
1319 wp_register_style(
1320 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1321 );
1322
1323 wp_register_style(
1324 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ ), array(), $this->defaults['version']
1325 );
1326
1327 $scripts[] = 'responsive-lightbox-nivo';
1328 $styles[] = 'responsive-lightbox-nivo';
1329 $styles[] = 'responsive-lightbox-nivo-default';
1330
1331 $args = array_merge(
1332 $args, array(
1333 'effect' => $this->options['configuration']['nivo']['effect'],
1334 'clickOverlayToClose' => $this->get_boolean_value( $this->options['configuration']['nivo']['click_overlay_to_close'] ),
1335 'keyboardNav' => $this->get_boolean_value( $this->options['configuration']['nivo']['keyboard_nav'] ),
1336 'errorMessage' => esc_attr( $this->options['configuration']['nivo']['error_message'] )
1337 )
1338 );
1339 break;
1340
1341 case 'imagelightbox':
1342 wp_register_script(
1343 '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 )
1344 );
1345
1346 wp_register_style(
1347 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/imagelightbox' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1348 );
1349
1350 $scripts[] = 'responsive-lightbox-imagelightbox';
1351 $styles[] = 'responsive-lightbox-imagelightbox';
1352
1353 $args = array_merge(
1354 $args, array(
1355 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'],
1356 'preloadNext' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['preload_next'] ),
1357 'enableKeyboard' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['enable_keyboard'] ),
1358 'quitOnEnd' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_end'] ),
1359 'quitOnImageClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_image_click'] ),
1360 'quitOnDocumentClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_document_click'] ),
1361 )
1362 );
1363 break;
1364
1365 case 'tosrus':
1366 // swipe support, enqueue Hammer.js on mobile devices only
1367 if ( wp_is_mobile() ) {
1368 wp_register_script(
1369 '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 )
1370 );
1371 $scripts[] = 'responsive-lightbox-hammer-js';
1372 }
1373
1374 wp_register_script(
1375 '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 )
1376 );
1377
1378 wp_register_style(
1379 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/jquery.tosrus' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1380 );
1381
1382 $scripts[] = 'responsive-lightbox-tosrus';
1383 $styles[] = 'responsive-lightbox-tosrus';
1384
1385 $args = array_merge( $args, array(
1386 'effect' => $this->options['configuration']['tosrus']['effect'],
1387 'infinite' => $this->get_boolean_value( $this->options['configuration']['tosrus']['infinite'] ),
1388 'keys' => $this->get_boolean_value( $this->options['configuration']['tosrus']['keys'] ),
1389 'autoplay' => $this->get_boolean_value( $this->options['configuration']['tosrus']['autoplay'] ),
1390 'pauseOnHover' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pause_on_hover'] ),
1391 'timeout' => $this->options['configuration']['tosrus']['timeout'],
1392 'pagination' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pagination'] ),
1393 'paginationType' => $this->options['configuration']['tosrus']['pagination_type'],
1394 'closeOnClick' => $this->get_boolean_value( $this->options['configuration']['tosrus']['close_on_click'] )
1395 )
1396 );
1397 break;
1398
1399 case 'featherlight':
1400 wp_register_script(
1401 '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 )
1402 );
1403
1404 wp_register_style(
1405 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1406 );
1407
1408 wp_register_script(
1409 '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 )
1410 );
1411
1412 wp_register_style(
1413 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version']
1414 );
1415
1416 $scripts[] = 'responsive-lightbox-featherlight';
1417 $styles[] = 'responsive-lightbox-featherlight';
1418 $scripts[] = 'responsive-lightbox-featherlight-gallery';
1419 $styles[] = 'responsive-lightbox-featherlight-gallery';
1420
1421 $args = array_merge(
1422 $args,
1423 array(
1424 'openSpeed' => $this->options['configuration']['featherlight']['open_speed'],
1425 'closeSpeed' => $this->options['configuration']['featherlight']['close_speed'],
1426 'closeOnClick' => $this->options['configuration']['featherlight']['close_on_click'],
1427 'closeOnEsc' => $this->get_boolean_value( $this->options['configuration']['featherlight']['close_on_esc'] ),
1428 'galleryFadeIn' => $this->options['configuration']['featherlight']['gallery_fade_in'],
1429 'galleryFadeOut' => $this->options['configuration']['featherlight']['gallery_fade_out']
1430 )
1431 );
1432 break;
1433
1434 case 'magnific':
1435 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 ) );
1436
1437 wp_register_style( 'responsive-lightbox-magnific', plugins_url( 'assets/magnific/magnific-popup' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', __FILE__ ), array(), $this->defaults['version'] );
1438
1439 $scripts[] = 'responsive-lightbox-magnific';
1440 $styles[] = 'responsive-lightbox-magnific';
1441
1442 $args = array_merge(
1443 $args,
1444 array(
1445 'disableOn' => $this->options['configuration']['magnific']['disable_on'],
1446 'midClick' => $this->options['configuration']['magnific']['mid_click'],
1447 'preloader' => $this->options['configuration']['magnific']['preloader'],
1448 'closeOnContentClick' => $this->options['configuration']['magnific']['close_on_content_click'],
1449 'closeOnBgClick' => $this->options['configuration']['magnific']['close_on_background_click'],
1450 'closeBtnInside' => $this->options['configuration']['magnific']['close_button_inside'],
1451 'showCloseBtn' => $this->options['configuration']['magnific']['show_close_button'],
1452 'enableEscapeKey' => $this->options['configuration']['magnific']['enable_escape_key'],
1453 'alignTop' => $this->options['configuration']['magnific']['align_top'],
1454 'fixedContentPos' => $this->options['configuration']['magnific']['fixed_content_position'],
1455 'fixedBgPos' => $this->options['configuration']['magnific']['fixed_background_position'],
1456 'autoFocusLast' => $this->options['configuration']['magnific']['auto_focus_last']
1457 )
1458 );
1459 break;
1460
1461 default:
1462 do_action( 'rl_lightbox_enqueue_scripts' );
1463
1464 $scripts = apply_filters( 'rl_lightbox_scripts', $scripts );
1465 $styles = apply_filters( 'rl_lightbox_styles', $styles );
1466 }
1467
1468 // run scripts by default
1469 $contitional_scripts = true;
1470
1471 if ( $this->options['settings']['conditional_loading'] === true ) {
1472 global $post;
1473
1474 if ( is_object( $post ) ) {
1475 // is gallery present in content
1476 $has_gallery = has_shortcode( $post->post_content, 'gallery' ) || has_shortcode( $post->post_content, 'rl_gallery' );
1477
1478 // are images present in content
1479 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $post->post_content, $links );
1480
1481 $has_images = (bool) $links[0];
1482
1483 if ( $has_gallery === false && $has_images === false )
1484 $contitional_scripts = false;
1485 }
1486 }
1487
1488 if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) {
1489 wp_register_script( 'responsive-lightbox-infinite-scroll', RESPONSIVE_LIGHTBOX_URL . '/assets/infinitescroll/infinite-scroll.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) );
1490 wp_register_script( 'responsive-lightbox-images-loaded', RESPONSIVE_LIGHTBOX_URL . '/assets/imagesloaded/imagesloaded.pkgd' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ) );
1491 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' ) );
1492
1493 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 ) );
1494
1495 $args['woocommerce_gallery'] = 0;
1496
1497 if ( class_exists( 'WooCommerce' ) ) {
1498 global $woocommerce;
1499
1500 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1501 if ( version_compare( $woocommerce->version, '3.0', ">=" ) )
1502 $args['woocommerce_gallery'] = 1;
1503 }
1504 }
1505
1506 $scripts[] = 'responsive-lightbox';
1507
1508 $args['ajaxurl'] = admin_url( 'admin-ajax.php' );
1509 $args['nonce'] = wp_create_nonce( 'rl_nonce' );
1510
1511 // enqueue scripts
1512 if ( $scripts && is_array( $scripts ) ) {
1513 foreach ( $scripts as $script ) {
1514 wp_enqueue_script( $script );
1515 }
1516
1517 wp_localize_script( 'responsive-lightbox', 'rlArgs', $args );
1518 }
1519
1520 // enqueue styles
1521 if ( $styles && is_array( $styles ) ) {
1522 foreach ( $styles as $style ) {
1523 wp_enqueue_style( $style );
1524 }
1525 }
1526 }
1527
1528 // gallery style
1529 wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), array(), Responsive_Lightbox()->defaults['version'] );
1530 }
1531
1532 /**
1533 * Helper: convert value to boolean
1534 *
1535 * @param int $option
1536 * @return bool
1537 */
1538 private function get_boolean_value( $option ) {
1539 return ( $option == true ? 1 : 0 );
1540 }
1541
1542 /**
1543 * Helper: convert hex color to rgb color.
1544 *
1545 * @param type $color
1546 * @return array
1547 */
1548 public function hex2rgb( $color ) {
1549 if ( $color[0] == '#' )
1550 $color = substr( $color, 1 );
1551
1552 if ( strlen( $color ) == 6 )
1553 list( $r, $g, $b ) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
1554 elseif ( strlen( $color ) == 3 )
1555 list( $r, $g, $b ) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
1556 else
1557 return false;
1558
1559 $r = hexdec( $r );
1560 $g = hexdec( $g );
1561 $b = hexdec( $b );
1562
1563 return array( $r, $g, $b );
1564 }
1565 }
1566
1567 /**
1568 * Initialize Responsive Lightbox.
1569 */
1570 function Responsive_Lightbox() {
1571 static $instance;
1572
1573 // first call to instance() initializes the plugin
1574 if ( $instance === null || ! ($instance instanceof Responsive_Lightbox) ) {
1575 $instance = Responsive_Lightbox::instance();
1576 }
1577
1578 return $instance;
1579 }
1580
1581 $responsive_lightbox = Responsive_Lightbox();