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