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