PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 1.5.6
Responsive Lightbox & Gallery v1.5.6
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 13 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
630 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.6
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.6
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.6'
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 public function activate_single() {
205 add_option( 'responsive_lightbox_settings', $this->defaults['settings'], '', 'no' );
206 add_option( 'responsive_lightbox_configuration', $this->defaults['configuration'], '', 'no' );
207 add_option( 'responsive_lightbox_version', $this->defaults['version'], '', 'no' );
208 }
209
210 public function deactivate_single( $multi = false ) {
211 if ( $multi === true ) {
212 $options = get_option( 'responsive_lightbox_settings' );
213 $check = $options['deactivation_delete'];
214 } else
215 $check = $this->options['settings']['deactivation_delete'];
216
217 if ( $check === true ) {
218 delete_option( 'responsive_lightbox_settings' );
219 delete_option( 'responsive_lightbox_configuration' );
220 delete_option( 'responsive_lightbox_version' );
221 }
222 }
223
224 public function activate_multisite( $networkwide ) {
225 if ( is_multisite() && $networkwide ) {
226 global $wpdb;
227
228 $activated_blogs = array();
229 $current_blog_id = $wpdb->blogid;
230 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
231
232 foreach ( $blogs_ids as $blog_id ) {
233 switch_to_blog( $blog_id );
234 $this->activate_single();
235 $activated_blogs[] = (int) $blog_id;
236 }
237
238 switch_to_blog( $current_blog_id );
239 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs, array() );
240 } else
241 $this->activate_single();
242 }
243
244 public function deactivate_multisite( $networkwide ) {
245 if ( is_multisite() && $networkwide ) {
246 global $wpdb;
247
248 $current_blog_id = $wpdb->blogid;
249 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
250
251 if ( ($activated_blogs = get_site_option( 'responsive_lightbox_activated_blogs', false, false )) === false )
252 $activated_blogs = array();
253
254 foreach ( $blogs_ids as $blog_id ) {
255 switch_to_blog( $blog_id );
256 $this->deactivate_single( true );
257
258 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
259 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
260 }
261
262 switch_to_blog( $current_blog_id );
263 update_site_option( 'responsive_lightbox_activated_blogs', $activated_blogs );
264 } else
265 $this->deactivate_single();
266 }
267
268 /**
269 * Load textdomain
270 */
271 public function load_textdomain() {
272 load_plugin_textdomain( 'responsive-lightbox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
273 }
274
275 /**
276 * Add links to Support Forum
277 */
278 public function plugin_extend_links( $links, $file ) {
279 if ( ! current_user_can( 'install_plugins' ) )
280 return $links;
281
282 $plugin = plugin_basename( __FILE__ );
283
284 if ( $file == $plugin ) {
285 return array_merge(
286 $links, array( sprintf( '<a href="http://www.dfactory.eu/support/forum/responsive-lightbox/" target="_blank">%s</a>', __( 'Support', 'responsive-lightbox' ) ) )
287 );
288 }
289
290 return $links;
291 }
292
293 /**
294 * Add links to Settings page
295 */
296 public function plugin_settings_link( $links, $file ) {
297 if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
298 return $links;
299
300 static $plugin;
301
302 $plugin = plugin_basename( __FILE__ );
303
304 if ( $file == $plugin ) {
305 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=responsive-lightbox', __( 'Settings', 'responsive-lightbox' ) );
306 array_unshift( $links, $settings_link );
307 }
308
309 return $links;
310 }
311
312 /**
313 * Enqueue admin scripts and styles
314 */
315 public function admin_scripts_styles( $page ) {
316 if ( $page === 'settings_page_responsive-lightbox' ) {
317
318 wp_register_script(
319 'responsive-lightbox-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' )
320 );
321 wp_enqueue_script( 'responsive-lightbox-admin' );
322
323 wp_localize_script(
324 'responsive-lightbox-admin', 'rlArgs', array(
325 'resetSettingsToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'responsive-lightbox' ),
326 'resetScriptToDefaults' => __( 'Are you sure you want to reset this script settings to defaults?', 'responsive-lightbox' ),
327 )
328 );
329
330 wp_enqueue_style( 'wp-color-picker' );
331
332 wp_register_style(
333 'responsive-lightbox-admin', plugins_url( 'css/admin.css', __FILE__ )
334 );
335 wp_enqueue_style( 'responsive-lightbox-admin' );
336 }
337 }
338
339 /**
340 * Enqueue frontend scripts and styles
341 */
342 public function front_scripts_styles() {
343
344 $args = apply_filters( 'rl_lightbox_args', array(
345 'script' => $this->options['settings']['script'],
346 'selector' => $this->options['settings']['selector'],
347 'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? ' ' . $this->options['settings']['custom_events'] : '' ),
348 'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )
349 ) );
350
351 $scripts = array();
352 $styles = array();
353
354 switch ( $args['script'] ) {
355
356 case 'prettyphoto' :
357
358 wp_register_script(
359 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/js/jquery.prettyPhoto.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
360 );
361 wp_register_style(
362 'responsive-lightbox-prettyphoto', plugins_url( 'assets/prettyphoto/css/prettyPhoto.css', __FILE__ )
363 );
364
365 $scripts[] = 'responsive-lightbox-prettyphoto';
366 $styles[] = 'responsive-lightbox-prettyphoto';
367
368 $args = array_merge(
369 $args, array(
370 'animationSpeed' => $this->options['configuration']['prettyphoto']['animation_speed'],
371 'slideshow' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow'] ),
372 'slideshowDelay' => $this->options['configuration']['prettyphoto']['slideshow_delay'],
373 'slideshowAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['slideshow_autoplay'] ),
374 'opacity' => sprintf( '%.2f', ($this->options['configuration']['prettyphoto']['opacity'] / 100 ) ),
375 'showTitle' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['show_title'] ),
376 'allowResize' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_resize'] ),
377 'allowExpand' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['allow_expand'] ),
378 'width' => $this->options['configuration']['prettyphoto']['width'],
379 'height' => $this->options['configuration']['prettyphoto']['height'],
380 'separator' => $this->options['configuration']['prettyphoto']['separator'],
381 'theme' => $this->options['configuration']['prettyphoto']['theme'],
382 'horizontalPadding' => $this->options['configuration']['prettyphoto']['horizontal_padding'],
383 'hideFlash' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['hide_flash'] ),
384 'wmode' => $this->options['configuration']['prettyphoto']['wmode'],
385 'videoAutoplay' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['video_autoplay'] ),
386 'modal' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['modal'] ),
387 'deeplinking' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['deeplinking'] ),
388 'overlayGallery' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['overlay_gallery'] ),
389 'keyboardShortcuts' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['keyboard_shortcuts'] ),
390 'social' => $this->get_boolean_value( $this->options['configuration']['prettyphoto']['social'] )
391 )
392 );
393
394 break;
395
396 case 'swipebox' :
397
398 wp_register_script(
399 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/js/jquery.swipebox.min.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
400 );
401 wp_register_style(
402 'responsive-lightbox-swipebox', plugins_url( 'assets/swipebox/css/swipebox.min.css', __FILE__ )
403 );
404
405 $scripts[] = 'responsive-lightbox-swipebox';
406 $styles[] = 'responsive-lightbox-swipebox';
407
408 $args = array_merge(
409 $args, array(
410 'animation' => $this->get_boolean_value( ($this->options['configuration']['swipebox']['animation'] === 'css' ? true : false ) ),
411 'hideCloseButtonOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_close_mobile'] ),
412 'removeBarsOnMobile' => $this->get_boolean_value( $this->options['configuration']['swipebox']['remove_bars_mobile'] ),
413 'hideBars' => $this->get_boolean_value( $this->options['configuration']['swipebox']['hide_bars'] ),
414 'hideBarsDelay' => $this->options['configuration']['swipebox']['hide_bars_delay'],
415 'videoMaxWidth' => $this->options['configuration']['swipebox']['video_max_width'],
416 'useSVG' => ! $this->options['configuration']['swipebox']['force_png_icons'],
417 'loopAtEnd' => $this->get_boolean_value( $this->options['configuration']['swipebox']['loop_at_end'] )
418 )
419 );
420
421 break;
422
423 case 'fancybox' :
424
425 wp_register_script(
426 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox-1.3.4.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
427 );
428 wp_register_style(
429 'responsive-lightbox-fancybox', plugins_url( 'assets/fancybox/jquery.fancybox-1.3.4.css', __FILE__ )
430 );
431
432 $scripts[] = 'responsive-lightbox-fancybox';
433 $styles[] = 'responsive-lightbox-fancybox';
434
435 $args = array_merge(
436 $args, array(
437 'modal' => $this->get_boolean_value( $this->options['configuration']['fancybox']['modal'] ),
438 'showOverlay' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_overlay'] ),
439 'showCloseButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_close_button'] ),
440 'enableEscapeButton' => $this->get_boolean_value( $this->options['configuration']['fancybox']['enable_escape_button'] ),
441 'hideOnOverlayClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_overlay_click'] ),
442 'hideOnContentClick' => $this->get_boolean_value( $this->options['configuration']['fancybox']['hide_on_content_click'] ),
443 'cyclic' => $this->get_boolean_value( $this->options['configuration']['fancybox']['cyclic'] ),
444 'showNavArrows' => $this->get_boolean_value( $this->options['configuration']['fancybox']['show_nav_arrows'] ),
445 'autoScale' => $this->get_boolean_value( $this->options['configuration']['fancybox']['auto_scale'] ),
446 'scrolling' => $this->options['configuration']['fancybox']['scrolling'],
447 'centerOnScroll' => $this->get_boolean_value( $this->options['configuration']['fancybox']['center_on_scroll'] ),
448 'opacity' => $this->get_boolean_value( $this->options['configuration']['fancybox']['opacity'] ),
449 'overlayOpacity' => $this->options['configuration']['fancybox']['overlay_opacity'],
450 'overlayColor' => $this->options['configuration']['fancybox']['overlay_color'],
451 'titleShow' => $this->get_boolean_value( $this->options['configuration']['fancybox']['title_show'] ),
452 'titlePosition' => $this->options['configuration']['fancybox']['title_position'],
453 'transitions' => $this->options['configuration']['fancybox']['transitions'],
454 'easings' => $this->options['configuration']['fancybox']['easings'],
455 'speeds' => $this->options['configuration']['fancybox']['speeds'],
456 'changeSpeed' => $this->options['configuration']['fancybox']['change_speed'],
457 'changeFade' => $this->options['configuration']['fancybox']['change_fade'],
458 'padding' => $this->options['configuration']['fancybox']['padding'],
459 'margin' => $this->options['configuration']['fancybox']['margin'],
460 'videoWidth' => $this->options['configuration']['fancybox']['video_width'],
461 'videoHeight' => $this->options['configuration']['fancybox']['video_height']
462 )
463 );
464
465 break;
466
467 case 'nivo' :
468
469 wp_register_script(
470 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox.min.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
471 );
472 wp_register_style(
473 'responsive-lightbox-nivo', plugins_url( 'assets/nivo/nivo-lightbox.css', __FILE__ )
474 );
475 wp_register_style(
476 'responsive-lightbox-nivo-default', plugins_url( 'assets/nivo/themes/default/default.css', __FILE__ )
477 );
478
479 $scripts[] = 'responsive-lightbox-nivo';
480 $styles[] = 'responsive-lightbox-nivo';
481 $styles[] = 'responsive-lightbox-nivo-default';
482
483 $args = array_merge(
484 $args, array(
485 'effect' => $this->options['configuration']['nivo']['effect'],
486 'clickOverlayToClose' => $this->get_boolean_value( $this->options['configuration']['nivo']['click_overlay_to_close'] ),
487 'keyboardNav' => $this->get_boolean_value( $this->options['configuration']['nivo']['keyboard_nav'] ),
488 'errorMessage' => esc_attr( $this->options['configuration']['nivo']['error_message'] )
489 )
490 );
491
492 break;
493
494 case 'imagelightbox' :
495
496 wp_register_script(
497 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/js/imagelightbox.min.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
498 );
499 wp_register_style(
500 'responsive-lightbox-imagelightbox', plugins_url( 'assets/imagelightbox/css/imagelightbox.css', __FILE__ )
501 );
502
503 $scripts[] = 'responsive-lightbox-imagelightbox';
504 $styles[] = 'responsive-lightbox-imagelightbox';
505
506 $args = array_merge(
507 $args, array(
508 'animationSpeed' => $this->options['configuration']['imagelightbox']['animation_speed'],
509 'preloadNext' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['preload_next'] ),
510 'enableKeyboard' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['enable_keyboard'] ),
511 'quitOnEnd' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_end'] ),
512 'quitOnImageClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_image_click'] ),
513 'quitOnDocumentClick' => $this->get_boolean_value( $this->options['configuration']['imagelightbox']['quit_on_document_click'] ),
514 )
515 );
516
517 break;
518
519 case 'tosrus' :
520
521 // swipe support, enqueue Hammer.js on mobile devices only
522 if ( wp_is_mobile() ) {
523 wp_register_script(
524 'responsive-lightbox-hammer-js', plugins_url( 'assets/tosrus/js/hammer.min.js', __FILE__ ), array(), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
525 );
526 $scripts[] = 'responsive-lightbox-hammer-js';
527 }
528
529 wp_register_script(
530 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/js/jquery.tosrus.min.all.js', __FILE__ ), array( 'jquery' ), '', ($this->options['settings']['loading_place'] === 'header' ? false : true )
531 );
532 wp_register_style(
533 'responsive-lightbox-tosrus', plugins_url( 'assets/tosrus/css/jquery.tosrus.all.min.css', __FILE__ )
534 );
535
536 $scripts[] = 'responsive-lightbox-tosrus';
537 $styles[] = 'responsive-lightbox-tosrus';
538
539 $args = array_merge( $args, array(
540 'effect' => $this->options['configuration']['tosrus']['effect'],
541 'infinite' => $this->get_boolean_value( $this->options['configuration']['tosrus']['infinite'] ),
542 'keys' => $this->get_boolean_value( $this->options['configuration']['tosrus']['keys'] ),
543 'autoplay' => $this->get_boolean_value( $this->options['configuration']['tosrus']['autoplay'] ),
544 'pauseOnHover' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pause_on_hover'] ),
545 'timeout' => $this->options['configuration']['tosrus']['timeout'],
546 'pagination' => $this->get_boolean_value( $this->options['configuration']['tosrus']['pagination'] ),
547 'paginationType' => $this->options['configuration']['tosrus']['pagination_type']
548 )
549 );
550
551 break;
552
553 default :
554
555 break;
556 }
557
558 // run scripts by default
559 $contitional_scripts = true;
560
561 if ( $this->options['settings']['conditional_loading'] === true ) {
562
563 global $post;
564
565 if ( is_object( $post ) ) {
566
567 // is gallery present in content
568 $has_gallery = has_shortcode( $post->post_content, 'gallery' );
569
570 // are images present in content
571 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?).(bmp|gif|jpeg|jpg|png)(?:\'|")(.*?)>/i', $post->post_content, $links );
572
573 $has_images = (bool) $links[0];
574
575 if ( $has_gallery === false && $has_images === false ) {
576 $contitional_scripts = false;
577 }
578
579 }
580
581 }
582
583 if ( ! empty( $args['script'] ) && ! empty( $args['selector'] ) && apply_filters( 'rl_lightbox_conditional_loading', $contitional_scripts ) != false ) {
584
585 wp_register_script( 'responsive-lightbox', plugins_url( 'js/front.js', __FILE__ ), array( 'jquery' ), '', ( $this->options['settings']['loading_place'] === 'header' ? false : true ) );
586
587 $scripts[] = 'responsive-lightbox';
588
589 // enqueue scripts
590 if ( $scripts && is_array( $scripts ) ) {
591 foreach ( $scripts as $script ) {
592 wp_enqueue_script( $script );
593 }
594
595 wp_localize_script( 'responsive-lightbox', 'rlArgs', $args );
596 }
597
598 // enqueue styles
599 if ( $styles && is_array( $styles ) ) {
600 foreach ( $styles as $style ) {
601 wp_enqueue_style( $style );
602 }
603 }
604 }
605 }
606
607 /**
608 * Helper: convert value to boolean
609 */
610 private function get_boolean_value( $option ) {
611 return ( $option == true ? 1 : 0 );
612 }
613
614 }
615
616 /**
617 * Initialise Responsive Lightbox.
618 */
619 function Responsive_Lightbox() {
620 static $instance;
621
622 // first call to instance() initializes the plugin
623 if ( $instance === null || ! ($instance instanceof Responsive_Lightbox) ) {
624 $instance = Responsive_Lightbox::instance();
625 }
626
627 return $instance;
628 }
629
630 $responsive_lightbox = Responsive_Lightbox();