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