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