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