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