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