PluginProbe
Responsive Lightbox & Gallery / 1.6.11
Responsive Lightbox & Gallery v1.6.11
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 All 105 releases
responsive-lightbox / responsive-lightbox.php
responsive-lightbox.php
782 lines 30.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Responsive Lightbox
4 Description: Responsive Lightbox allows users to view larger versions of images and galleries in a lightbox (overlay) effect optimized for mobile devices.
5 Version: 1.6.11
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
15 Copyright (C) 2013-2017, 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__ ) ) . '/' );
31
32 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-frontend.php' );
33 include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/class-settings.php' );
34
35 /**
36 * Responsive Lightbox class.
37 *
38 * @class Responsive_Lightbox
39 * @version 1.6.11
40 */
41 class Responsive_Lightbox {
42
43 public $defaults = array(
44 'settings' => array(
45 'script' => 'swipebox',
46 'selector' => 'lightbox',
47 'galleries' => true,
48 'gallery_image_size' => 'full',
49 'gallery_image_title' => 'default',
50 'force_custom_gallery' => false,
51 'woocommerce_gallery_lightbox' => false,
52 'videos' => true,
53 'image_links' => true,
54 'image_title' => 'default',
55 'images_as_gallery' => false,
56 'deactivation_delete' => false,
57 'loading_place' => 'header',
58 'conditional_loading' => false,
59 'enable_custom_events' => false,
60 'custom_events' => 'ajaxComplete',
61 'update_version' => 0,
62 'update_notice' => true
63 ),
64 'configuration' => array(
65 'prettyphoto' => array(
66 'animation_speed' => 'normal',
67 'slideshow' => false,
68 'slideshow_delay' => 5000,
69 'slideshow_autoplay' => false,
70 'opacity' => 75,
71 'show_title' => true,
72 'allow_resize' => true,
73 'allow_expand' => true,
74 'width' => 1080,
75 'height' => 720,
76 'separator' => '/',
77 'theme' => 'pp_default',
78 'horizontal_padding' => 20,
79 'hide_flash' => false,
80 'wmode' => 'opaque',
81 'video_autoplay' => false,
82 'modal' => false,
83 'deeplinking' => false,
84 'overlay_gallery' => true,
85 'keyboard_shortcuts' => true,
86 'social' => false
87 ),
88 'swipebox' => array(
89 'animation' => 'css',
90 'force_png_icons' => false,
91 'hide_close_mobile' => false,
92 'remove_bars_mobile' => false,
93 'hide_bars' => true,
94 'hide_bars_delay' => 5000,
95 'video_max_width' => 1080,
96 'loop_at_end' => false
97 ),
98 'fancybox' => array(
99 'modal' => false,
100 'show_overlay' => true,
101 'show_close_button' => true,
102 'enable_escape_button' => true,
103 'hide_on_overlay_click' => true,
104 'hide_on_content_click' => false,
105 'cyclic' => false,
106 'show_nav_arrows' => true,
107 'auto_scale' => true,
108 'scrolling' => 'yes',
109 'center_on_scroll' => true,
110 'opacity' => true,
111 'overlay_opacity' => 70,
112 'overlay_color' => '#666',
113 'title_show' => true,
114 'title_position' => 'outside',
115 'transitions' => 'fade',
116 'easings' => 'swing',
117 'speeds' => 300,
118 'change_speed' => 300,
119 'change_fade' => 100,
120 'padding' => 5,
121 'margin' => 5,
122 'video_width' => 1080,
123 'video_height' => 720
124 ),
125 'nivo' => array(
126 'effect' => 'fade',
127 'click_overlay_to_close' => true,
128 'keyboard_nav' => true,
129 'error_message' => 'The requested content cannot be loaded. Please try again later.'
130 ),
131 'imagelightbox' => array(
132 'animation_speed' => 250,
133 'preload_next' => true,
134 'enable_keyboard' => true,
135 'quit_on_end' => false,
136 'quit_on_image_click' => false,
137 'quit_on_document_click' => true
138 ),
139 'tosrus' => array(
140 'effect' => 'slide',
141 'infinite' => true,
142 'keys' => false,
143 'autoplay' => true,
144 'pause_on_hover' => false,
145 'timeout' => 4000,
146 'pagination' => true,
147 'pagination_type' => 'thumbnails'
148 ),
149 'featherlight' => array(
150 'open_speed' => 250,
151 'close_speed' => 250,
152 'close_on_click' => 'background',
153 'close_on_esc' => true,
154 'gallery_fade_in' => 100,
155 'gallery_fade_out' => 300
156 )
157 ),
158 'version' => '1.6.11'
159 );
160 public $options = array();
161 private $notices = array();
162 private static $_instance;
163
164 private function __clone() {}
165 private function __wakeup() {}
166
167 /**
168 * Main Responsive Lightbox instance.
169 */
170 public static function instance() {
171 if ( self::$_instance === null ) {
172 self::$_instance = new self();
173 }
174 return self::$_instance;
175 }
176
177 public function __construct() {
178 register_activation_hook( __FILE__, array( $this, 'activate_multisite' ) );
179 register_deactivation_hook( __FILE__, array( $this, 'deactivate_multisite' ) );
180
181 // change from older versions
182 $db_version = get_option( 'responsive_lightbox_version' );
183
184 if ( version_compare( ( $db_version === false ? '1.0.0' : $db_version ), '1.0.5', '<' ) ) {
185 if ( ($array = get_option( 'rl_settings' )) !== false ) {
186 update_option( 'responsive_lightbox_settings', $array );
187 delete_option( 'rl_settings' );
188 }
189
190 if ( ($array = get_option( 'rl_configuration' )) !== false ) {
191 update_option( 'responsive_lightbox_configuration', $array );
192 delete_option( 'rl_configuration' );
193 }
194 }
195
196 // update plugin version
197 update_option( 'responsive_lightbox_version', $this->defaults['version'], false );
198
199 $this->options['settings'] = array_merge( $this->defaults['settings'], ( ($array = get_option( 'responsive_lightbox_settings' ) ) === false ? array() : $array ) );
200
201 // for multi arrays we have to merge them separately
202 $db_conf_opts = ( ( $base = get_option( 'responsive_lightbox_configuration' ) ) === false ? array() : $base );
203
204 foreach ( $this->defaults['configuration'] as $script => $settings ) {
205 $this->options['configuration'][$script] = array_merge( $settings, (isset( $db_conf_opts[$script] ) ? $db_conf_opts[$script] : array() ) );
206 }
207
208 // actions
209 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
210 add_action( 'wp_enqueue_scripts', array( $this, 'front_scripts_styles' ) );
211 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_styles' ) );
212 add_action( 'admin_init', array( $this, 'update_notices' ) );
213 add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ), 999 );
214
215 // filters
216 add_filter( 'plugin_action_links', array( $this, 'plugin_settings_link' ), 10, 2 );
217 }
218
219 /**
220 * Single site activation function
221 */
222 public function activate_single() {
223 add_option( 'responsive_lightbox_settings', $this->defaults['settings'], '', 'no' );
224 add_option( 'responsive_lightbox_configuration', $this->defaults['configuration'], '', 'no' );
225 add_option( 'responsive_lightbox_version', $this->defaults['version'], '', 'no' );
226 }
227
228 /**
229 * Single site deactivation function
230 */
231 public function deactivate_single( $multi = false ) {
232 if ( $multi === true ) {
233 $options = get_option( 'responsive_lightbox_settings' );
234 $check = $options['deactivation_delete'];
235 } else
236 $check = $this->options['settings']['deactivation_delete'];
237
238 if ( $check === true ) {
239 delete_option( 'responsive_lightbox_settings' );
240 delete_option( 'responsive_lightbox_configuration' );
241 delete_option( 'responsive_lightbox_version' );
242 }
243 }
244
245 /**
246 * Activation function
247 */
248 public function activate_multisite( $networkwide ) {
249 if ( is_multisite() && $networkwide ) {
250 global $wpdb;
251
252 $activated_blogs = array();
253 $current_blog_id = $wpdb->blogid;
254 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
255
256 foreach ( $blogs_ids as $blog_id ) {
257 switch_to_blog( $blog_id );
258 $this->activate_single();
259 $activated_blogs[] = (int) $blog_id;
260 }
261
262 switch_to_blog( $current_blog_id );
263 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs, array() );
264 } else
265 $this->activate_single();
266 }
267
268 /**
269 * Dectivation function
270 */
271 public function deactivate_multisite( $networkwide ) {
272 if ( is_multisite() && $networkwide ) {
273 global $wpdb;
274
275 $current_blog_id = $wpdb->blogid;
276 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
277
278 if ( ($activated_blogs = get_site_option( 'responsive_lightbox_activated_blogs', false, false )) === false )
279 $activated_blogs = array();
280
281 foreach ( $blogs_ids as $blog_id ) {
282 switch_to_blog( $blog_id );
283 $this->deactivate_single( true );
284
285 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
286 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
287 }
288
289 switch_to_blog( $current_blog_id );
290 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs );
291 } else
292 $this->deactivate_single();
293 }
294
295 /**
296 * Load textdomain
297 */
298 public function load_textdomain() {
299 load_plugin_textdomain( 'responsive-lightbox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
300 }
301
302 /**
303 * Update notices.
304 */
305 public function update_notices() {
306 if ( ! current_user_can( 'install_plugins' ) )
307 return;
308
309 $current_update = 1;
310
311 if ( $this->options['settings']['update_version'] < $current_update ) {
312 // check version, if update ver is lower than plugin ver, set update notice to true
313 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_version' => $current_update, 'update_notice' => true ) );
314 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
315 } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'rl-hide-notice' ) {
316 if ( wp_verify_nonce( $_REQUEST['rl_nonce'], 'rl_action' ) ) {
317 // hide notice, if query arg is set, before it gets displayed
318 $this->options['settings'] = array_merge( $this->options['settings'], array( 'update_notice' => false ) );
319 update_option( 'responsive_lightbox_settings', $this->options['settings'] );
320 } else {
321 print_r( $_REQUEST );
322 }
323 }
324
325 // display current version notice
326 if ( $this->options['settings']['update_notice'] === true ) {
327
328 $this->add_notice( sprintf(__( 'Thank you for installing Responsive Lightbox version %s. <a href="%s">Click here</a> to check out our latest extensions!', 'responsive-lightbox'), $this->defaults['version'], wp_nonce_url( add_query_arg( array( 'action' => 'rl-hide-notice' ), admin_url( 'options-general.php' ) . '?page=responsive-lightbox&tab=addons' ), 'rl_action', 'rl_nonce' ) ), 'updated notice is-dismissible rl-notice' );
329 }
330 }
331
332 /**
333 * Add admin notices.
334 */
335 public function add_notice( $html = '', $status = 'error', $paragraph = true, $network = false ) {
336 $this->notices[] = array(
337 'html' => $html,
338 'status' => $status,
339 'paragraph' => $paragraph
340 );
341
342 add_action( 'admin_notices', array( $this, 'display_notice') );
343
344 if( $network )
345 add_action( 'network_admin_notices', array( $this, 'display_notice') );
346 }
347
348 /**
349 * Print admin notices.
350 */
351 public function display_notice() {
352 foreach( $this->notices as $notice ) {
353 echo '
354 <div class="' . $notice['status'] . '">
355 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
356 ' . $notice['html'] . '
357 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
358 </div>';
359 }
360 }
361
362 /**
363 * Print admin scripts.
364 */
365 public function admin_inline_js() {
366 if ( ! current_user_can( 'install_plugins' ) )
367 return;
368 ?>
369 <script type="text/javascript">
370 ( function ( $ ) {
371 $( document ).ready( function () {
372 // save dismiss state
373 $( '.rl-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function ( e ) {
374 e.preventDefault();
375
376 $.post( ajaxurl, {
377 action: 'rl-hide-notice',
378 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
379 rl_nonce: '<?php echo wp_create_nonce( 'rl_action' ); ?>'
380 } );
381
382 } );
383 } );
384 } )( jQuery );
385 </script>
386 <?php
387 }
388
389 /**
390 * Add links to Support Forum
391 */
392 public function plugin_extend_links( $links, $file ) {
393 if ( ! current_user_can( 'install_plugins' ) )
394 return $links;
395
396 $plugin = plugin_basename( __FILE__ );
397
398 if ( $file == $plugin ) {
399 return array_merge(
400 $links, array( sprintf( '<a href="http://www.dfactory.eu/support/forum/responsive-lightbox/" target="_blank">%s</a>', __( 'Support', 'responsive-lightbox' ) ) )
401 );
402 }
403
404 return $links;
405 }
406
407 /**
408 * Add links to Settings page
409 */
410 public function plugin_settings_link( $links, $file ) {
411 if ( ! is_admin() || ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ) ) )
412 return $links;
413
414 static $plugin;
415
416 $plugin = plugin_basename( __FILE__ );
417
418 if ( $file == $plugin ) {
419 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=responsive-lightbox', __( 'Settings', 'responsive-lightbox' ) );
420 array_unshift( $links, $settings_link );
421 }
422
423 return $links;
424 }
425
426 /**
427 * Enqueue admin scripts and styles
428 */
429 public function admin_scripts_styles( $page ) {
430 if ( $page === 'settings_page_responsive-lightbox' ) {
431
432 wp_register_script(
433 'responsive-lightbox-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), $this->defaults['version']
434 );
435 wp_enqueue_script( 'responsive-lightbox-admin' );
436
437 wp_localize_script(
438 'responsive-lightbox-admin', 'rlArgs', array(
439 'resetSettingsToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ),
440 'resetScriptToDefaults' => __( 'Are you sure you want to reset this script settings to defaults?', 'responsive-lightbox' ),
441 )
442 );
443
444 wp_enqueue_style( 'wp-color-picker' );
445
446 wp_register_style(
447 'responsive-lightbox-admin', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->defaults['version']
448 );
449 wp_enqueue_style( 'responsive-lightbox-admin' );
450 }
451 }
452
453 /**
454 * Enqueue frontend scripts and styles
455 */
456 public function front_scripts_styles() {
457
458 $args = apply_filters( 'rl_lightbox_args', array(
459 'script' => $this->options['settings']['script'],
460 'selector' => $this->options['settings']['selector'],
461 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? ' ' . $this->options['settings']['custom_events'] : '' ),
462 'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )
463 ) );
464
465 $scripts = array();
466 $styles = array();
467
468 switch ( $args['script'] ) {
469
470 case 'prettyphoto' :
471
472 wp_register_script(
473 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/js/jquery.prettyPhoto.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
474 );
475 wp_register_style(
476 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/css/prettyPhoto.css', __FILE__ ), array(), $this->defaults['version']
477 );
478
479 $scripts[] = 'responsive-lightbox-prettyphoto';
480 $styles[] = 'responsive-lightbox-prettyphoto';
481
482 $args = array_merge(
483 $args, array(
484 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'],
485 'slideshow' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow'] ),
486 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'],
487 'slideshowAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow_autoplay'] ),
488 'opacity' => sprintf( '%.2f', ($this->options['configuration']['prettyphoto']['opacity'] / 100 ) ),
489 'showTitle' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['show_title'] ),
490 'allowResize' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_resize'] ),
491 'allowExpand' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_expand'] ),
492 'width' => $this->options['configuration']['prettyphoto']['width'],
493 'height' => $this->options['configuration']['prettyphoto']['height'],
494 'separator' => $this->options['configuration']['prettyphoto']['separator'],
495 'theme' => $this->options['configuration']['prettyphoto']['theme'],
496 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'],
497 'hideFlash' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['hide_flash'] ),
498 'wmode' => $this->options['configuration']['prettyphoto']['wmode'],
499 'videoAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['video_autoplay'] ),
500 'modal' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['modal'] ),
501 'deeplinking' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['deeplinking'] ),
502 'overlayGallery' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['overlay_gallery'] ),
503 'keyboardShortcuts' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['keyboard_shortcuts'] ),
504 'social' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['social'] )
505 )
506 );
507
508 break;
509
510 case 'swipebox' :
511
512 wp_register_script(
513 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/js/jquery.swipebox.min.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
514 );
515 wp_register_style(
516 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/css/swipebox.min.css', __FILE__ ), array(), $this->defaults['version']
517 );
518
519 $scripts[] = 'responsive-lightbox-swipebox';
520 $styles[] = 'responsive-lightbox-swipebox';
521
522 $args = array_merge(
523 $args, array(
524 'animation' => $this->get_boolean_value( ($this->options['configuration']['swipebox']['animation'] === 'css' ? true : false ) ),
525 'hideCloseButtonOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_close_mobile'] ),
526 'removeBarsOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['remove_bars_mobile'] ),
527 'hideBars' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_bars'] ),
528 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'],
529 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'],
530 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'],
531 'loopAtEnd' => $this->get_boolean_value( $this->options['configuration']['swipebox']['loop_at_end'] )
532 )
533 );
534
535 break;
536
537 case 'fancybox' :
538
539 wp_register_script(
540 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox-1.3.4.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
541 );
542 wp_register_style(
543 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox-1.3.4.css', __FILE__ ), array(), $this->defaults['version']
544 );
545
546 $scripts[] = 'responsive-lightbox-fancybox';
547 $styles[] = 'responsive-lightbox-fancybox';
548
549 $args = array_merge(
550 $args, array(
551 'modal' => $this->get_boolean_value( $this->options['configuration']['fancybox']['modal'] ),
552 'showOverlay' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_overlay'] ),
553 'showCloseButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_close_button'] ),
554 'enableEscapeButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['enable_escape_button'] ),
555 'hideOnOverlayClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_overlay_click'] ),
556 'hideOnContentClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_content_click'] ),
557 'cyclic' => $this->get_boolean_value( $this->options['configuration']['fancybox']['cyclic'] ),
558 'showNavArrows' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_nav_arrows'] ),
559 'autoScale' => $this->get_boolean_value( $this->options['configuration']['fancybox']['auto_scale'] ),
560 'scrolling' => $this->options['configuration']['fancybox']['scrolling'],
561 'centerOnScroll' => $this->get_boolean_value( $this->options['configuration']['fancybox']['center_on_scroll'] ),
562 'opacity' => $this->get_boolean_value( $this->options['configuration']['fancybox']['opacity'] ),
563 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'],
564 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'],
565 'titleShow' => $this->get_boolean_value( $this->options['configuration']['fancybox']['title_show'] ),
566 'titlePosition' => $this->options['configuration']['fancybox']['title_position'],
567 'transitions' => $this->options['configuration']['fancybox']['transitions'],
568 'easings' => $this->options['configuration']['fancybox']['easings'],
569 'speeds' => $this->options['configuration']['fancybox']['speeds'],
570 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'],
571 'changeFade' => $this->options['configuration']['fancybox']['change_fade'],
572 'padding' => $this->options['configuration']['fancybox']['padding'],
573 'margin' => $this->options['configuration']['fancybox']['margin'],
574 'videoWidth' => $this->options['configuration']['fancybox']['video_width'],
575 'videoHeight' => $this->options['configuration']['fancybox']['video_height']
576 )
577 );
578
579 break;
580
581 case 'nivo' :
582
583 wp_register_script(
584 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox.min.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true ), $this->defaults['version']
585 );
586 wp_register_style(
587 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox.min.css', __FILE__ ), array(), $this->defaults['version']
588 );
589 wp_register_style(
590 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ ), array(), $this->defaults['version']
591 );
592
593 $scripts[] = 'responsive-lightbox-nivo';
594 $styles[] = 'responsive-lightbox-nivo';
595 $styles[] = 'responsive-lightbox-nivo-default';
596
597 $args = array_merge(
598 $args, array(
599 'effect' => $this->options['configuration']['nivo']['effect'],
600 'clickOverlayToClose' => $this->get_boolean_value( $this->options['configuration']['nivo']['click_overlay_to_close'] ),
601 'keyboardNav' => $this->get_boolean_value( $this->options['configuration']['nivo']['keyboard_nav'] ),
602 'errorMessage' => esc_attr( $this->options['configuration']['nivo']['error_message'] )
603 )
604 );
605
606 break;
607
608 case 'imagelightbox' :
609
610 wp_register_script(
611 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/js/imagelightbox.min.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
612 );
613 wp_register_style(
614 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/css/imagelightbox.css', __FILE__ ), array(), $this->defaults['version']
615 );
616
617 $scripts[] = 'responsive-lightbox-imagelightbox';
618 $styles[] = 'responsive-lightbox-imagelightbox';
619
620 $args = array_merge(
621 $args, array(
622 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'],
623 'preloadNext' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['preload_next'] ),
624 'enableKeyboard' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['enable_keyboard'] ),
625 'quitOnEnd' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_end'] ),
626 'quitOnImageClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_image_click'] ),
627 'quitOnDocumentClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_document_click'] ),
628 )
629 );
630
631 break;
632
633 case 'tosrus' :
634
635 // swipe support, enqueue Hammer.js on mobile devices only
636 if ( wp_is_mobile() ) {
637 wp_register_script(
638 'responsive-lightbox-hammer-js', plugins_url( 'assets/tosrus/js/hammer.min.js', __FILE__ ), array(), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
639 );
640 $scripts[] = 'responsive-lightbox-hammer-js';
641 }
642
643 wp_register_script(
644 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/js/jquery.tosrus.min.all.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
645 );
646 wp_register_style(
647 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/css/jquery.tosrus.all.css', __FILE__ ), array(), $this->defaults['version']
648 );
649
650 $scripts[] = 'responsive-lightbox-tosrus';
651 $styles[] = 'responsive-lightbox-tosrus';
652
653 $args = array_merge( $args, array(
654 'effect' => $this->options['configuration']['tosrus']['effect'],
655 'infinite' => $this->get_boolean_value( $this->options['configuration']['tosrus']['infinite'] ),
656 'keys' => $this->get_boolean_value( $this->options['configuration']['tosrus']['keys'] ),
657 'autoplay' => $this->get_boolean_value( $this->options['configuration']['tosrus']['autoplay'] ),
658 'pauseOnHover' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pause_on_hover'] ),
659 'timeout' => $this->options['configuration']['tosrus']['timeout'],
660 'pagination' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pagination'] ),
661 'paginationType' => $this->options['configuration']['tosrus']['pagination_type']
662 )
663 );
664
665 break;
666
667 case 'featherlight' :
668
669 wp_register_script(
670 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight.min.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
671 );
672 wp_register_style(
673 'responsive-lightbox-featherlight', plugins_url( 'assets/featherlight/featherlight.min.css', __FILE__ ), array(), $this->defaults['version']
674 );
675 wp_register_script(
676 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery.min.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ($this->options['settings']['loading_place'] === 'header' ? false : true )
677 );
678 wp_register_style(
679 'responsive-lightbox-featherlight-gallery', plugins_url( 'assets/featherlight/featherlight.gallery.min.css', __FILE__ ), array(), $this->defaults['version']
680 );
681
682 $scripts[] = 'responsive-lightbox-featherlight';
683 $styles[] = 'responsive-lightbox-featherlight';
684 $scripts[] = 'responsive-lightbox-featherlight-gallery';
685 $styles[] = 'responsive-lightbox-featherlight-gallery';
686
687 $args = array_merge(
688 $args, array(
689 'openSpeed' => $this->options['configuration']['featherlight']['open_speed'],
690 'closeSpeed' => $this->options['configuration']['featherlight']['close_speed'],
691 'closeOnClick' => $this->options['configuration']['featherlight']['close_on_click'],
692 'closeOnEsc' => $this->get_boolean_value( $this->options['configuration']['featherlight']['close_on_esc'] ),
693 'galleryFadeIn' => $this->options['configuration']['featherlight']['gallery_fade_in'],
694 'galleryFadeOut' => $this->options['configuration']['featherlight']['gallery_fade_out']
695 )
696 );
697
698 break;
699
700 default :
701
702 do_action( 'rl_lightbox_enqueue_scripts' );
703
704 $scripts = apply_filters( 'rl_lightbox_scripts', $scripts );
705 $styles = apply_filters( 'rl_lightbox_styles', $styles );
706
707 break;
708 }
709
710 // run scripts by default
711 $contitional_scripts = true;
712
713 if ( $this->options['settings']['conditional_loading'] === true ) {
714
715 global $post;
716
717 if ( is_object( $post ) ) {
718
719 // is gallery present in content
720 $has_gallery = has_shortcode( $post->post_content, 'gallery' );
721
722 // are images present in content
723 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png)(?:\'|")(.*?)>/i', $post->post_content, $links );
724
725 $has_images = (bool) $links[0];
726
727 if ( $has_gallery === false && $has_images === false ) {
728 $contitional_scripts = false;
729 }
730
731 }
732
733 }
734
735 if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) {
736
737 wp_register_script( 'responsive-lightbox', plugins_url( 'js/front.js', __FILE__ ), array( 'jquery' ), $this->defaults['version'], ( $this->options['settings']['loading_place'] === 'header' ? false : true ) );
738
739 $scripts[] = 'responsive-lightbox';
740
741 // enqueue scripts
742 if ( $scripts && is_array( $scripts ) ) {
743 foreach ( $scripts as $script ) {
744 wp_enqueue_script( $script );
745 }
746
747 wp_localize_script( 'responsive-lightbox', 'rlArgs', $args );
748 }
749
750 // enqueue styles
751 if ( $styles && is_array( $styles ) ) {
752 foreach ( $styles as $style ) {
753 wp_enqueue_style( $style );
754 }
755 }
756 }
757 }
758
759 /**
760 * Helper: convert value to boolean
761 */
762 private function get_boolean_value( $option ) {
763 return ( $option == true ? 1 : 0 );
764 }
765
766 }
767
768 /**
769 * Initialise Responsive Lightbox.
770 */
771 function Responsive_Lightbox() {
772 static $instance;
773
774 // first call to instance() initializes the plugin
775 if ( $instance === null || ! ($instance instanceof Responsive_Lightbox) ) {
776 $instance = Responsive_Lightbox::instance();
777 }
778
779 return $instance;
780 }
781
782 $responsive_lightbox = Responsive_Lightbox();