PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.2.2
Responsive Lightbox & Gallery v2.2.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 / includes / class-frontend.php
responsive-lightbox / includes Last commit date
providers 6 years ago class-fast-image.php 8 years ago class-folders-walker.php 7 years ago class-folders.php 6 years ago class-frontend.php 6 years ago class-galleries.php 6 years ago class-remote-library-api.php 6 years ago class-remote-library.php 6 years ago class-settings.php 6 years ago class-tour.php 6 years ago class-welcome.php 6 years ago class-widgets.php 6 years ago functions.php 6 years ago
class-frontend.php
2092 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 new Responsive_Lightbox_Frontend();
7
8 /**
9 * Responsive Lightbox frontend class.
10 *
11 * @class Responsive_Lightbox_Frontend
12 */
13 class Responsive_Lightbox_Frontend {
14
15 public $gallery_no = 0;
16
17 public function __construct() {
18 // set instance
19 Responsive_Lightbox()->frontend = $this;
20
21 // actions
22 add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 100 );
23 add_action( 'rl_before_gallery', array( $this, 'before_gallery' ), 10, 2 );
24 add_action( 'rl_after_gallery', array( $this, 'after_gallery' ), 10, 2 );
25 add_action( 'after_setup_theme', array( $this, 'woocommerce_gallery_init' ), 1000 );
26
27 // filters
28 add_filter( 'rl_gallery_container_class', array( $this, 'gallery_container_class' ), 10, 3 );
29 add_filter( 'the_content', array( $this, 'gallery_preview' ) );
30 add_filter( 'the_content', array( $this, 'add_lightbox' ) );
31 add_filter( 'wp_get_attachment_link', array( $this, 'wp_get_attachment_link' ), 1000, 6 );
32 add_filter( 'get_comment_text', array( $this, 'get_comment_text' ) );
33 add_filter( 'dynamic_sidebar_params', array( $this, 'dynamic_sidebar_params' ) );
34 add_filter( 'rl_widget_output', array( $this, 'widget_output' ), 10, 3 );
35 add_filter( 'post_gallery', array( $this, 'gallery_attributes' ), 1000, 2 );
36 add_filter( 'post_gallery', array( $this, 'basic_grid_gallery_shortcode' ), 1001, 2 );
37 add_filter( 'post_gallery', array( $this, 'basic_slider_gallery_shortcode' ), 1001, 2 );
38 add_filter( 'post_gallery', array( $this, 'basic_masonry_gallery_shortcode' ), 1001, 2 );
39 add_filter( 'post_gallery', array( $this, 'force_custom_gallery_lightbox' ), 2000 );
40
41 // visual composer
42 add_filter( 'vc_shortcode_content_filter_after', array( $this, 'vc_shortcode_content_filter_after' ), 10, 2 );
43
44 // woocommerce
45 add_filter( 'woocommerce_single_product_image_html', array( $this, 'woocommerce_single_product_image_html' ), 100 );
46 add_filter( 'woocommerce_single_product_image_thumbnail_html', array( $this, 'woocommerce_single_product_image_thumbnail_html' ), 100 );
47 }
48
49 /**
50 * Add lightbox to images, galleries and videos.
51 *
52 * @param string $content HTML content
53 * @return string Changed HTML content
54 */
55 public function add_lightbox( $content ) {
56 // get current script
57 $script = Responsive_Lightbox()->options['settings']['script'];
58
59 // prepare arguments
60 $args = array(
61 'selector' => Responsive_Lightbox()->options['settings']['selector'],
62 'script' => $script,
63 'settings' => array(
64 'script' => Responsive_Lightbox()->options['configuration'][$script],
65 'plugin' => Responsive_Lightbox()->options['settings']
66 ),
67 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports']
68 );
69
70 // workaround for builder galleries to bypass images_as_gallery option, applied only to rl_gallery posts
71 if ( is_singular( 'rl_gallery' ) )
72 $args['settings']['plugin']['images_as_gallery'] = true;
73
74 // search for links containing data-rl_content attribute
75 preg_match_all( '/<a.*?data-rl_content=(?:\'|")(.*?)(?:\'|").*?>/i', $content, $links );
76
77 // found any links?
78 if ( ! empty ( $links[0] ) ) {
79 foreach ( $links[0] as $link_number => $link ) {
80 // set content type
81 $args['content'] = $links[1][$link_number];
82
83 // set link number
84 $args['link_number'] = $link_number;
85
86 // update link
87 $content = str_replace( $link, $this->lightbox_content_link( $link, $args ), $content );
88 }
89 }
90
91 // images
92 if ( $args['settings']['plugin']['image_links'] || $args['settings']['plugin']['images_as_gallery'] || $args['settings']['plugin']['force_custom_gallery'] ) {
93 // search for image links
94 preg_match_all( '/<a([^<]*?)href=(?:\'|")([^<]*?)\.(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/is', $content, $links );
95
96 // found any links?
97 if ( ! empty ( $links[0] ) ) {
98 // generate hash for single images gallery
99 if ( $args['settings']['plugin']['images_as_gallery'] )
100 $args['rel_hash'] = '-gallery-' . $this->generate_hash();
101 else
102 $args['rel_hash'] = '';
103
104 foreach ( $links[0] as $link_number => $link ) {
105 // get attachment id
106 $args['image_id'] = $this->get_attachment_id_by_url( $links[2][$link_number] . '.' . $links[3][$link_number] );
107
108 // set link number
109 $args['link_number'] = $link_number;
110
111 // link parts
112 $args['link_parts'] = array( $links[1][$link_number], $links[2][$link_number], $links[3][$link_number], $links[4][$link_number] );
113
114 // get title type
115 $title_arg = $args['settings']['plugin']['force_custom_gallery'] ? $args['settings']['plugin']['gallery_image_title'] : $args['settings']['plugin']['image_title'];
116
117 // update title if needed
118 if ( $title_arg !== 'default' && $args['image_id'] )
119 $args['title'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $args['image_id'], $links[2][$link_number] . '.' . $links[3][$link_number] ) );
120 else
121 $args['title'] = '';
122
123 // get caption type
124 $caption_arg = $args['settings']['plugin']['force_custom_gallery'] ? $args['settings']['plugin']['gallery_image_caption'] : $args['settings']['plugin']['image_caption'];
125
126 // update caption if needed
127 if ( $caption_arg !== 'default' && $args['image_id'] )
128 $args['caption'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $args['image_id'], $links[2][$link_number] . '.' . $links[3][$link_number] ) );
129 else
130 $args['caption'] = '';
131
132 // update link
133 $content = str_replace( $link, $this->lightbox_image_link( $link, $args ), $content );
134 }
135 }
136 }
137
138 // videos
139 if ( $args['settings']['plugin']['videos'] ) {
140 // search for video links
141 preg_match_all('/<a(.*?)href=(?:\'|")((http|https)(?::\/\/|)(?:(?:(?:youtu\.be\/|(?:www\.)?youtube\.com\/)(?:embed\/|v\/|watch\?v=)?([\w-]{11})(?:\?)?([a-z0-9;:@#&%=+\/\$_.-]*))|(?:(?:www\.)?vimeo\.com\/([0-9]+)(?:\?)?([a-z0-9;:@#&%=+\/\$_.-]*))))(?:\'|")(.*?)>/i', $content, $links );
142
143 // set empty video arguments
144 $args['video_id'] = $args['video_type'] = $args['video_query'] = $args['video_protocol'] = '';
145
146 // found any links?
147 if ( ! empty ( $links[0] ) ) {
148 foreach ( $links[0] as $link_number => $link ) {
149 // youtube?
150 if ( $links[4][$link_number] !== '' ) {
151 $args['video_id'] = $links[4][$link_number];
152 $args['video_type'] = 'youtube';
153 $args['video_query'] = $links[5][$link_number];
154 // vimeo?
155 } elseif ( $links[6][$link_number] !== '' ) {
156 $args['video_id'] = $links[6][$link_number];
157 $args['video_type'] = 'vimeo';
158 $args['video_query'] = $links[7][$link_number];
159 }
160
161 // set video protocol
162 $args['video_protocol'] = $links[3][$link_number];
163
164 // set link number
165 $args['link_number'] = $link_number;
166
167 // link parts
168 $args['link_parts'] = array( $links[1][$link_number], $links[2][$link_number], $links[8][$link_number] );
169
170 // update link
171 $content = str_replace( $link, $this->lightbox_video_link( $link, $args ), $content );
172 }
173 }
174 }
175
176 return $content;
177 }
178
179 /**
180 * Add lightbox to video links.
181 *
182 * @param string $link Video link
183 * @param array $args Link arguments
184 * @return string Updated video link
185 */
186 public function lightbox_video_link( $link, $args ) {
187 // link already contains data-rel attribute?
188 if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 ) {
189 // allow to modify link?
190 if ( $result[1] !== 'norl' ) {
191 // swipebox video fix
192 if ( $args['script'] === 'swipebox' && $args['video_type'] === 'vimeo' )
193 $link = str_replace( $args['link_parts'][1], add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] ), $link );
194
195 // replace data-rel
196 $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/', 'data-rel="' . $args['selector'] . '-video-' . $args['link_number'] . '"', $link );
197
198 if ( $args['script'] === 'magnific' )
199 $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
200 }
201 } else {
202 // swipebox video fix
203 if ( $args['script'] === 'swipebox' && $args['video_type'] === 'vimeo' )
204 $args['link_parts'][1] = add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] );
205
206 // add data-rel
207 $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '" data-rel="' . $args['selector'] . '-video-' . $args['link_number'] . '"' . $args['link_parts'][2] . '>';
208
209 if ( $args['script'] === 'magnific' )
210 $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
211 }
212
213 return apply_filters( 'rl_lightbox_video_link', $link, $args );
214 }
215
216 /**
217 * Add lightbox to image links.
218 *
219 * @param string $link Image link
220 * @param array $args Link arguments
221 * @return string Updated image link
222 */
223 public function lightbox_image_link( $link, $args ) {
224 if ( rl_current_lightbox_supports( 'html_caption' ) ) {
225 $title = esc_attr( trim ( nl2br( $args['title'] ) ) );
226 $caption = esc_attr( trim( nl2br( $args['caption'] ) ) );
227 } else {
228 $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $args['title'] ) ), true ) );
229 $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $args['caption'] ) ), true ) );
230 }
231
232 if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
233 $this->gallery_no = (int) $_GET['rl_gallery_no'];
234
235 // link already contains data-rel attribute?
236 if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 ) {
237 // allow to modify link?
238 if ( $result[1] !== 'norl' ) {
239 // gallery?
240 if ( $args['settings']['plugin']['images_as_gallery'] || $args['settings']['plugin']['force_custom_gallery'] )
241 $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ), $link );
242 // single image
243 else
244 $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-image-' . base64_encode( $result[1] ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"', $link );
245 }
246 // link without data-rel
247 } else {
248 // force images?
249 if ( $args['settings']['plugin']['force_custom_gallery'] ) {
250 // link already contains rel attribute?
251 if ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 ) {
252 // allow to modify link?
253 if ( $result[1] !== 'norl' )
254 $link = preg_replace( '/rel=(\'|")(.*?)(\'|")/', 'data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ), $link );
255 } else
256 $link = '<a' . $args['link_parts'][0] . ' href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '" data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . $args['link_parts'][3] . '>';
257 } else
258 $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '"' . $args['link_parts'][3] . ' data-rel="' . $args['selector'] . ( $args['settings']['plugin']['images_as_gallery'] ? $args['rel_hash'] : '-image-' . $args['link_number'] ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__">';
259 }
260
261 // use safe replacement
262 $link = str_replace( '__RL_IMAGE_TITLE__', $title, str_replace( '__RL_IMAGE_CAPTION__', $caption, $link ) );
263
264 // title exists?
265 if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 ) {
266 $link = preg_replace( '/(<a.*? title=(?:\'|")).*?((?:\'|").*?>)/s', '${1}__RL_IMAGE_TITLE__$2', $link );
267 } else
268 $link = preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__">', $link );
269
270 // last safe replacement
271 $link = str_replace( '__RL_IMAGE_TITLE__', $title, $link );
272
273 return apply_filters( 'rl_lightbox_image_link', $link, $args );
274 }
275
276 /**
277 * Add lightbox to gallery image links.
278 *
279 * @param string $link
280 * @param int $id
281 * @param string $size
282 * @param bool $permalink
283 * @param mixed $icon
284 * @param mixed $text
285 */
286 public function wp_get_attachment_link( $link, $id, $size, $permalink, $icon, $text ) {
287 if ( Responsive_Lightbox()->options['settings']['galleries'] && wp_attachment_is_image( $id ) ) {
288 // deprecated filter
289 $link = apply_filters( 'rl_lightbox_attachment_link', $link, $id, $size, $permalink, $icon, $text, array() );
290
291 // get current script
292 $script = Responsive_Lightbox()->options['settings']['script'];
293
294 // prepare arguments
295 $args = array(
296 'selector' => Responsive_Lightbox()->options['settings']['selector'],
297 'script' => $script,
298 'settings' => array(
299 'script' => Responsive_Lightbox()->options['configuration'][$script],
300 'plugin' => Responsive_Lightbox()->options['settings']
301 ),
302 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports'],
303 'image_id' => $id,
304 'title' => '',
305 'caption' => '',
306 'src' => array()
307 );
308
309 $link = $this->lightbox_gallery_link( $link, $args );
310 }
311
312 return $link;
313 }
314
315 /**
316 * Add lightbox to gallery image links.
317 *
318 * @param string $link Gallery image link
319 * @param array $args Gallery link arguments
320 * @return string Updated gallery image link
321 */
322 public function lightbox_gallery_link( $link, $args ) {
323 // gallery image title
324 $title = ! empty( $args['title'] ) ? $args['title'] : '';
325
326 // get title type
327 $title_arg = $args['settings']['plugin']['gallery_image_title'];
328
329 // update title if needed
330 if ( ! empty( $args['image_id'] ) && $title_arg !== 'default' ) {
331 // original title
332 $args['title'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $args['image_id'], $link ) );
333 }
334
335 // sanitize title
336 if ( $html_caption = rl_current_lightbox_supports( 'html_caption' ) )
337 $title = esc_attr( trim( nl2br( $args['title'] ) ) );
338 else
339 $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $args['title'] ) ), true ) );
340
341 // add title and rl_title if needed
342 if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
343 $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a.*? title=(?:\'|")).*?((?:\'|").*?>)/s', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
344 else
345 $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
346
347 // add class if needed
348 if ( preg_match( '/<a[^>]*? class=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
349 $link = preg_replace( '/(<a.*?) class=(?:\'|")(.*?)(?:\'|")(.*?>)/s', '$1 class="$2 rl-gallery-link" $3', $link );
350 else
351 $link = preg_replace( '/(<a.*?)>/s', '$1 class="rl-gallery-link">', $link );
352
353 // gallery image caption
354 $caption = ! empty( $args['caption'] ) ? $args['caption'] : '';
355
356 // get caption type
357 $caption_arg = $args['settings']['plugin']['gallery_image_caption'];
358
359 // update caption if needed
360 if ( ! empty( $args['image_id'] ) && $caption_arg !== 'default' ) {
361 // original caption
362 $args['caption'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $args['image_id'], $link ) );
363 }
364
365 // sanitize caption
366 if ( $html_caption )
367 $caption = esc_attr( trim( nl2br( $args['caption'] ) ) );
368 else
369 $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $args['caption'] ) ), true ) );
370
371 // add rl_caption
372 $link = str_replace( '__RL_IMAGE_CAPTION__', $caption, preg_replace( '/(<a.*?)>/s', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
373
374 if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
375 $this->gallery_no = (int) $_GET['rl_gallery_no'];
376
377 // link already contains data-rel attribute?
378 if ( preg_match( '/<a.*?data-rel=(\'|")(.*?)(\'|").*?>/is', $link, $result ) === 1 ) {
379 if ( $result[2] !== 'norl' )
380 $link = preg_replace( '/(<a.*?data-rel=(?:\'|").*?)((?:\'|").*?>)/s', '${1}' . $args['selector'] . '-gallery-' . $this->gallery_no . '$2', $link );
381 } else
382 $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '">', $link );
383
384 if ( ! ( isset( $args['link'] ) && $args['link'] != 'file' ) ) {
385 // gallery image size
386 if ( ! empty( $args['image_id'] ) ) {
387 if ( $args['settings']['plugin']['gallery_image_size'] !== 'full' ) {
388 $args['src'] = wp_get_attachment_image_src( $args['image_id'], $args['settings']['plugin']['gallery_image_size'] );
389
390 if ( preg_match( '/<a.*? href=("|\').*?("|\').*?>/is', $link ) === 1 )
391 $link = preg_replace( '/(<a.*? href=(?:"|\')).*?((?:"|\').*?>)/', '$1' . $args['src'][0] . '$2', $link );
392 else
393 $link = preg_replace( '/(<a.*?)>/', '$1 href="' . $args['src'][0] . '">', $link );
394 } else {
395 $args['src'] = wp_get_attachment_image_src( $args['image_id'], 'full' );
396
397 if ( preg_match( '/<a.*? href=("|\').*?("|\').*?>/is', $link ) === 1 )
398 $link = preg_replace( '/(<a.*? href=(?:"|\')).*?((?:"|\').*?>)/', '$1' . $args['src'][0] . '$2', $link );
399 else
400 $link = preg_replace( '/(<a.*?)>/', '$1 href="' . $args['src'][0] . '">', $link );
401 }
402 }
403
404 if ( $args['script'] === 'magnific' )
405 $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="gallery">', $link );
406 }
407
408 return apply_filters( 'rl_lightbox_gallery_link', $link, $args );
409 }
410
411 /**
412 * Add lightbox to content links.
413 *
414 * @param string $link Content link
415 * @param array $args Content arguments
416 * @return string Updated content link
417 */
418 public function lightbox_content_link( $link, $args ) {
419 if ( in_array( $args['content'], $args['supports'], true ) ) {
420 // link already contains data-rel attribute?
421 if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 )
422 $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-content-' . base64_encode( $result[1] ) . '"', $link );
423 else
424 $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . $args['selector'] . '-content-' . $args['link_number'] . '">', $link );
425
426 switch ( $args['script'] ) {
427 case 'nivo':
428 $link = preg_replace( '/(<a.*?)>/s', '$1 data-lightbox-type="' . $args['content'] . '">', $link );
429 break;
430
431 case 'featherlight':
432 $link = preg_replace( '/(<a.*?)>/s', '$1 data-featherlight="' . $args['content'] . '">', $link );
433 break;
434
435 case 'fancybox':
436 if ( $args['content'] === 'iframe' )
437 $link = preg_replace( '/(<a.*?href=(?:\'|"))(.*?)((?:\'|").*?>)/is', '$1' . add_query_arg( 'iframe', '', '$2' ) . '$3', $link );
438 break;
439
440 case 'prettyphoto':
441 if ( $args['content'] === 'iframe' )
442 $link = preg_replace( '/(<a.*?href=(?:\'|"))(.*?)((?:\'|").*?>)/is', '$1' . add_query_arg( array( 'iframe' => 'true', 'width' => $args['settings']['width'], 'height' => $args['settings']['height'] ), '$2' ) . '$3', $link );
443 }
444 }
445
446 return apply_filters( 'rl_lightbox_content_link', $link, $args );
447 }
448
449 /**
450 * Get gallery fields.
451 *
452 * @param string $type Gallery type
453 * @return array Gallery fields
454 */
455 public function get_gallery_fields( $type ) {
456 $rl = Responsive_Lightbox();
457
458 // get gallery fields
459 $gallery_fields = $rl->settings->settings[$type . '_gallery']['fields'];
460
461 // assign settings and defaults
462 $gallery_defaults = $rl->defaults[$type . '_gallery'];
463 $gallery_values = $rl->options[$type . '_gallery'];
464
465 // make a copy
466 $fields_copy = $gallery_fields;
467
468 foreach ( $fields_copy as $field_key => $field ) {
469 if ( $field['type'] === 'multiple' ) {
470 foreach ( $field['fields'] as $subfield_key => $subfield ) {
471 $gallery_fields[$field_key]['fields'][$subfield_key]['default'] = $gallery_defaults[$subfield_key];
472 $gallery_fields[$field_key]['fields'][$subfield_key]['value'] = array_key_exists( $subfield_key, $gallery_values ) ? $gallery_values[$subfield_key] : $gallery_defaults[$subfield_key];
473 }
474 } else {
475 $gallery_fields[$field_key]['default'] = $gallery_defaults[$field_key];
476 $gallery_fields[$field_key]['value'] = array_key_exists( $field_key, $gallery_values ) ? $gallery_values[$field_key] : $gallery_defaults[$field_key];
477 }
478 }
479
480 // get shortcode gallery fields combined with defaults
481 return apply_filters( 'rl_get_gallery_fields', $this->get_unique_fields( $this->get_default_gallery_fields(), $gallery_fields ) );
482 }
483
484 /**
485 * Get unique gallery fields.
486 *
487 * @param array $defaults Default gallery fields
488 * @param array $fields Custom gallery fields
489 * @return array Unique fields
490 */
491 public function get_unique_fields( $defaults, $fields ) {
492 // check duplicated fields
493 $duplicates = array_intersect_key( $defaults, $fields );
494
495 // any duplicated fields?
496 if ( ! empty( $duplicates ) ) {
497 foreach ( $duplicates as $field_id => $field ) {
498 unset( $defaults[$field_id] );
499 }
500 }
501
502 // get default and custom fields all together
503 return $defaults + $fields;
504 }
505
506 /**
507 * Get gallery fields combined with shortcode attributes.
508 *
509 * @param array $fields Gallery fields
510 * @param array $shortcode_atts Gallery shortcode attributes
511 * @param bool $gallery Whether is it rl_gallery shortcode
512 * @return array All combined field attributes
513 */
514 public function get_gallery_fields_atts( $fields, $shortcode_atts, $gallery = true ) {
515 // prepare default values
516 $field_atts = array();
517
518 // get all default field values
519 foreach ( $fields as $field_key => $field ) {
520 if ( $field['type'] === 'multiple' ) {
521 foreach ( $field['fields'] as $subfield_key => $subfield ) {
522 $field_atts[$subfield_key] = array_key_exists( 'value', $subfield ) ? $subfield['value'] : $subfield['default'];
523 }
524 } else
525 $field_atts[$field_key] = array_key_exists( 'value', $field ) ? $field['value'] : $field['default'];
526 }
527
528 // is it rl gallery?
529 if ( $gallery ) {
530 $tabs = Responsive_Lightbox()->galleries->tabs;
531
532 if ( ! empty( $tabs ) ) {
533 foreach ( $tabs as $key => $args ) {
534 if ( in_array( $key, array( 'images', 'config' ) ) )
535 continue;
536
537 // get additional fields
538 $data = get_post_meta( $shortcode_atts['rl_gallery_id'], '_rl_' . $key, true );
539
540 // add those fields
541 if ( ! empty( $data['menu_item'] ) && is_array( $data[$data['menu_item']] ) )
542 $field_atts += $data[$data['menu_item']];
543 }
544 }
545
546 if ( $field_atts['hover_effect'] !== '0' )
547 $field_atts['gallery_custom_class'] .= ' rl-hover-effect-' . $field_atts['hover_effect'];
548
549 if ( $field_atts['show_icon'] !== '0' )
550 $field_atts['gallery_custom_class'] .= ' rl-hover-icon-' . $field_atts['show_icon'];
551 }
552
553 return apply_filters( 'rl_get_gallery_fields_atts', $field_atts );
554 }
555
556 /**
557 * Get default gallery fields.
558 *
559 * @return array Default gallery
560 */
561 public function get_default_gallery_fields() {
562 $sizes = get_intermediate_image_sizes();
563 $sizes['full'] = 'full';
564
565 return array(
566 'size' => array(
567 'title' => __( 'Size', 'responsive-lightbox' ),
568 'type' => 'select',
569 'description' => __( 'Specify the image size to use for the thumbnail display.', 'responsive-lightbox' ),
570 'default' => 'medium',
571 'options' => array_combine( $sizes, $sizes )
572 ),
573 'link' => array(
574 'title' => __( 'Link To', 'responsive-lightbox' ),
575 'type' => 'select',
576 'description' => __( 'Specify where you want the image to link.', 'responsive-lightbox' ),
577 'default' => 'file',
578 'options' => array(
579 'post' => __( 'Attachment Page', 'responsive-lightbox' ),
580 'file' => __( 'Media File', 'responsive-lightbox' ),
581 'none' => __( 'None', 'responsive-lightbox' ),
582 )
583 ),
584 'orderby' => array(
585 'title' => __( 'Orderby', 'responsive-lightbox' ),
586 'type' => 'select',
587 'description' => __( 'Specify how to sort the display thumbnails.', 'responsive-lightbox' ),
588 'default' => 'menu_order',
589 'options' => array(
590 'id' => __( 'ID', 'responsive-lightbox' ),
591 'title' => __( 'Title', 'responsive-lightbox' ),
592 'post_date' => __( 'Date', 'responsive-lightbox' ),
593 'menu_order' => __( 'Menu Order', 'responsive-lightbox' ),
594 'rand' => __( 'Random', 'responsive-lightbox' )
595 )
596 ),
597 'order' => array(
598 'title' => __( 'Order', 'responsive-lightbox' ),
599 'type' => 'radio',
600 'description' => __( 'Specify the sort order.', 'responsive-lightbox' ),
601 'default' => 'asc',
602 'options' => array(
603 'asc' => __( 'Ascending', 'responsive-lightbox' ),
604 'desc' => __( 'Descending', 'responsive-lightbox' )
605 )
606 ),
607 'columns' => array(
608 'title' => __( 'Columns', 'responsive-lightbox' ),
609 'type' => 'number',
610 'description' => __( 'Specify the number of columns.', 'responsive-lightbox' ),
611 'default' => 3,
612 'min' => 1,
613 'max' => 12
614 )
615 );
616 }
617
618 /**
619 * Sanitize shortcode gallery arguments.
620 *
621 * @param array $atts Shortcode arguments
622 * @param array $fields Gallery fields
623 * @return array Sanitized shortcode arguments
624 */
625 public function sanitize_shortcode_args( $atts, $fields ) {
626 $rl = Responsive_Lightbox();
627
628 // validate gallery fields
629 foreach ( $fields as $field_key => $field ) {
630 // checkbox field?
631 if ( $field['type'] === 'checkbox' ) {
632 // valid argument?
633 if ( array_key_exists( $field_key, $atts ) )
634 $atts[$field_key] = $rl->galleries->sanitize_field( $field_key, array_flip( explode( ',', $atts[$field_key] ) ), $field );
635 // boolean field?
636 } elseif ( $field['type'] === 'boolean' ) {
637 // multiple field?
638 if ( $field['type'] === 'multiple' ) {
639 foreach ( $field['fields'] as $subfield_key => $subfield ) {
640 // valid argument?
641 if ( array_key_exists( $subfield_key, $atts ) ) {
642 // true value?
643 if ( $atts[$subfield_key] === true || $atts[$subfield_key] === 'true' || $atts[$subfield_key] === '1' )
644 $atts[$subfield_key] = 1;
645 // false value?
646 elseif ( $atts[$subfield_key] === false || $atts[$subfield_key] === 'false' || $atts[$subfield_key] === '0' || $atts[$subfield_key] === '' )
647 $atts[$subfield_key] = 0;
648 // default value
649 else
650 $atts[$subfield_key] = (int) $field['default'];
651 }
652 }
653 } else {
654 // valid argument?
655 if ( array_key_exists( $field_key, $atts ) ) {
656 // true value?
657 if ( $atts[$field_key] === true || $atts[$field_key] === 'true' || $atts[$field_key] === '1' )
658 $atts[$field_key] = 1;
659 // false value?
660 elseif ( $atts[$field_key] === false || $atts[$field_key] === 'false' || $atts[$field_key] === '0' || $atts[$field_key] === '' )
661 $atts[$field_key] = 0;
662 // default value
663 else
664 $atts[$field_key] = (int) $field['default'];
665 }
666 }
667 // multiple field?
668 } elseif ( $field['type'] === 'multiple' ) {
669 foreach ( $field['fields'] as $subfield_key => $subfield ) {
670 // valid argument?
671 if ( array_key_exists( $subfield_key, $atts ) )
672 $atts[$subfield_key] = $rl->galleries->sanitize_field( $subfield_key, $atts[$subfield_key], $subfield );
673 }
674 // other field?
675 } else {
676 // valid argument?
677 if ( array_key_exists( $field_key, $atts ) )
678 $atts[$field_key] = $rl->galleries->sanitize_field( $field_key, $atts[$field_key], $field );
679 }
680 }
681
682 return apply_filters( 'rl_sanitize_shortcode_args', $atts );
683 }
684
685 /**
686 * Get gallery images.
687 *
688 * @param array $args Gallery arguments
689 * @return array Gallery images
690 */
691 public function get_gallery_shortcode_images( $shortcode_atts ) {
692 if ( ! isset( $shortcode_atts['show_title'] ) || $shortcode_atts['show_title'] === 'global' )
693 $shortcode_atts['show_title'] = Responsive_Lightbox()->options['settings']['gallery_image_title'];
694
695 if ( ! isset( $shortcode_atts['show_caption'] ) || $shortcode_atts['show_caption'] === 'global' )
696 $shortcode_atts['show_caption'] = Responsive_Lightbox()->options['settings']['gallery_image_caption'];
697
698 $images = array();
699
700 // get gallery id
701 $gallery_id = ! empty( $shortcode_atts['rl_gallery_id'] ) ? absint( $shortcode_atts['rl_gallery_id'] ) : 0;
702
703 // get images from gallery
704 if ( $gallery_id ) {
705 $images = Responsive_Lightbox()->galleries->get_gallery_images(
706 $gallery_id,
707 array(
708 'exclude' => true,
709 'image_size' => $shortcode_atts['src_size'],
710 'thumbnail_size' => $shortcode_atts['size']
711 )
712 );
713 // get images from shortcode atts
714 } else {
715 $ids = array();
716
717 if ( ! empty( $shortcode_atts['include'] ) ) {
718 // filter attachment IDs
719 $include = array_unique( array_filter( array_map( 'intval', explode( ',', $shortcode_atts['include'] ) ) ) );
720
721 // any attachments?
722 if ( ! empty( $include ) ) {
723 // get attachments
724 $ids = get_posts(
725 array(
726 'include' => implode( ',', $include ),
727 'post_status' => 'inherit',
728 'post_type' => 'attachment',
729 'post_mime_type' => 'image',
730 'order' => $shortcode_atts['order'],
731 'orderby' => ( $shortcode_atts['orderby'] === 'menu_order' || $shortcode_atts['orderby'] === '' ? 'post__in' : $shortcode_atts['orderby'] ),
732 'fields' => 'ids'
733 )
734 );
735 }
736 } elseif ( ! empty( $exclude ) ) {
737 // filter attachment IDs
738 $exclude = array_unique( array_filter( array_map( 'intval', explode( ',', $shortcode_atts['exclude'] ) ) ) );
739
740 // any attachments?
741 if ( ! empty( $exclude ) ) {
742 // get attachments
743 $ids = get_children(
744 array(
745 'post_parent' => $shortcode_atts['id'],
746 'exclude' => $exclude,
747 'post_status' => 'inherit',
748 'post_type' => 'attachment',
749 'post_mime_type' => 'image',
750 'order' => $shortcode_atts['order'],
751 'orderby' => $shortcode_atts['orderby'],
752 'fields' => 'ids'
753 )
754 );
755 }
756 } else {
757 // get attachments
758 $ids = get_children(
759 array(
760 'post_parent' => $shortcode_atts['id'],
761 'post_status' => 'inherit',
762 'post_type' => 'attachment',
763 'post_mime_type' => 'image',
764 'order' => $shortcode_atts['order'],
765 'orderby' => $shortcode_atts['orderby'],
766 'fields' => 'ids'
767 )
768 );
769 }
770
771 // any attachments?
772 if ( ! empty( $ids ) ) {
773 foreach ( $ids as $attachment_id ) {
774 // get thumbnail image data
775 $images[] = Responsive_Lightbox()->galleries->get_gallery_image_src( $attachment_id, $shortcode_atts['src_size'], $shortcode_atts['size'] );
776 }
777 }
778 }
779
780 // apply adjustments, as per settings
781 if ( $images ) {
782 // get current script
783 $script = Responsive_Lightbox()->options['settings']['script'];
784
785 // prepare arguments
786 $args = array(
787 'selector' => Responsive_Lightbox()->options['settings']['selector'],
788 'script' => $script,
789 'settings' => array(
790 'script' => Responsive_Lightbox()->options['configuration'][$script],
791 'plugin' => Responsive_Lightbox()->options['settings']
792 ),
793 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports'],
794 'image_id' => 0,
795 'caption' => '',
796 'title' => '',
797 'src' => array()
798 );
799
800 // lightbox image title
801 $args['settings']['plugin']['gallery_image_title'] = ! empty( $shortcode_atts['lightbox_image_title'] ) ? ( $shortcode_atts['lightbox_image_title'] === 'global' ? Responsive_Lightbox()->options['settings']['gallery_image_title'] : $shortcode_atts['lightbox_image_title'] ) : Responsive_Lightbox()->options['settings']['gallery_image_title'];
802
803 // lightbox image caption
804 $args['settings']['plugin']['gallery_image_caption'] = ! empty( $shortcode_atts['lightbox_image_caption'] ) ? ( $shortcode_atts['lightbox_image_caption'] === 'global' ? Responsive_Lightbox()->options['settings']['gallery_image_caption'] : $shortcode_atts['lightbox_image_caption'] ) : Responsive_Lightbox()->options['settings']['gallery_image_caption'];
805
806 // get gallery image link
807 $args['link'] = isset( $shortcode_atts['link'] ) ? $shortcode_atts['link'] : '';
808
809 // copy images
810 $images_tmp = $images;
811
812 // apply adjustments, according to gallery settings
813 foreach ( $images_tmp as $index => $image ) {
814 // assign image
815 $new_image = $images[$index] = array_merge( $image, Responsive_Lightbox()->galleries->get_gallery_image_src( $image, $shortcode_atts['src_size'], $shortcode_atts['size'] ) );
816
817 // create image source data
818 $args['src'] = array( $new_image['url'], $new_image['width'], $new_image['height'] );
819
820 // set alt text
821 $images[$index]['alt'] = ! empty( $new_image['alt'] ) ? esc_attr( $new_image['alt'] ) : ( ! empty( $new_image['id'] ) ? get_post_meta( $new_image['id'], '_wp_attachment_image_alt', true ) : '' );
822
823 // set lightbox image title
824 if ( $args['settings']['plugin']['gallery_image_title'] === 'default' )
825 $images[$index]['title'] = $args['title'] = '';
826 else
827 $images[$index]['title'] = $args['title'] = ! empty( $new_image['id'] ) ? $this->get_attachment_title( $new_image['id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $args['settings']['plugin']['gallery_image_title'], $new_image['id'], $images[$index]['link'] ) ) : $new_image['title'];
828
829 // set lightbox image caption
830 if ( $args['settings']['plugin']['gallery_image_caption'] === 'default' )
831 $images[$index]['caption'] = $args['caption'] = '';
832 else
833 $images[$index]['caption'] = $args['caption'] = ! empty( $new_image['id'] ) ? $this->get_attachment_title( $new_image['id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $args['settings']['plugin']['gallery_image_caption'], $images[$index]['link'] ) ) : $new_image['caption'];
834
835 // set image gallery link
836 $images[$index]['link'] = $this->lightbox_gallery_link( $this->get_gallery_image_link( $new_image['id'], $args['src'], array( $new_image['thumbnail_url'], $new_image['thumbnail_width'], $new_image['thumbnail_height'] ), $shortcode_atts ), $args );
837
838 // is lightbox active?
839 if ( isset( $shortcode_atts['lightbox_enable'] ) && $shortcode_atts['lightbox_enable'] === 0 )
840 $images[$index]['link'] = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/', 'data-rel="norl"', $images[$index]['link'] );
841 }
842 }
843
844 return apply_filters( 'rl_get_gallery_shortcode_images', $images, $gallery_id, $shortcode_atts );
845 }
846
847 /**
848 * Get gallery image link.
849 *
850 * @param int $attachment_id Attachment ID
851 * @param array $image Source image data
852 * @param array $thumbnail Thumbnail image data
853 * @param array $args Arguments
854 * @return string Generated gallery image link
855 */
856 function get_gallery_image_link( $attachment_id, $image, $thumbnail, $args ) {
857 switch ( $args['link'] ) {
858 case 'post':
859 $link = '<a href="' . get_permalink( $attachment_id ) . '"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
860 break;
861
862 case 'none':
863 $link = '<a href="javascript:void(0)" style="cursor: default;"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
864 break;
865
866 default:
867 case 'file':
868 $link = '<a href="' . $image[0] . '"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
869 }
870
871 $title = ! empty( $args['show_title'] ) ? trim( $this->get_attachment_title( $attachment_id, $args['show_title'] ) ) : '';
872 $caption = ! empty( $args['show_caption'] ) ? trim( $this->get_attachment_title( $attachment_id, $args['show_caption'] ) ) : '';
873
874 if ( $title || $caption ) {
875 $link .= '<span class="rl-gallery-caption">';
876
877 if ( $title )
878 $link .= '<span class="rl-gallery-item-title">' . esc_html( $title ) . '</span>';
879
880 if ( $caption )
881 $link .= '<span class="rl-gallery-item-caption">' . esc_html( $caption ) . '</span>';
882
883 $link .= '</span>';
884 }
885
886 $link .= '</a>';
887
888 return apply_filters( 'rl_gallery_image_link', $link, $attachment_id, $image, $thumbnail, $args );
889 }
890
891 /**
892 * Add lightbox to Jetpack tiled gallery.
893 *
894 * @param string $content
895 * @return string
896 */
897 public function force_custom_gallery_lightbox( $content ) {
898 if ( Responsive_Lightbox()->options['settings']['force_custom_gallery'] ) {
899 // search for image links
900 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?)\.(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $content, $links );
901
902 // found any links?
903 if ( ! empty ( $links[0] ) ) {
904 foreach ( $links[0] as $link_number => $link ) {
905 // get attachment id
906 $image_id = $this->get_attachment_id_by_url( $links[2][$link_number] . '.' . $links[3][$link_number] );
907
908 // get title type
909 $title_arg = Responsive_Lightbox()->options['settings']['gallery_image_title'];
910
911 // update title if needed
912 if ( $title_arg !== 'default' && $image_id )
913 $title = esc_attr( wp_strip_all_tags( trim ( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ) ), true ) );
914 else
915 $title = '';
916
917 // get caption type
918 $caption_arg = Responsive_Lightbox()->options['settings']['gallery_image_caption'];
919
920 // update caption if needed
921 if ( $caption_arg !== 'default' )
922 $caption = esc_attr( wp_strip_all_tags( trim ( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ) ), true ) );
923 else
924 $caption = '';
925
926 // link already contains data-rel attribute?
927 if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
928 // do not modify this link
929 if ( $result[1] === 'norl' )
930 continue;
931
932 $content = str_replace( $link, preg_replace( '/data-rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
933 } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
934 // do not modify this link
935 if ( $result[1] === 'norl' )
936 continue;
937
938 $content = str_replace( $link, preg_replace( '/rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
939 } else
940 $content = str_replace( $link, '<a' . $links[1][$link_number] . ' href="' . $links[2][$link_number] . '.' . $links[3][$link_number] . '" data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $this->gallery_no ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ) . $links[4][$link_number] . '>', $content );
941 }
942 }
943 }
944
945 return $content;
946 }
947
948 /**
949 * Remove WooCommerce prettyPhoto lightbox styles and scripts.
950 */
951 public function wp_enqueue_scripts() {
952 if ( class_exists( 'WooCommerce' ) ) {
953 global $woocommerce;
954
955 // specific WooCommerce gallery?
956 if ( ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
957 // replace default WooCommerce lightbox?
958 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
959 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
960 // dequeue scripts
961 wp_dequeue_script( 'flexslider' );
962 wp_dequeue_script( 'photoswipe' );
963 wp_dequeue_script( 'photoswipe-ui-default' );
964
965 // dequeue styles
966 wp_dequeue_style( 'photoswipe' );
967 wp_dequeue_style( 'photoswipe-default-skin' );
968
969 // remove theme supports
970 remove_theme_support( 'wc-product-gallery-lightbox' );
971 // remove_theme_support( 'wc-product-gallery-zoom' );
972 remove_theme_support( 'wc-product-gallery-slider' );
973 } else {
974 // remove styles
975 wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
976
977 // remove scripts
978 wp_dequeue_script( 'prettyPhoto' );
979 wp_dequeue_script( 'prettyPhoto-init' );
980 wp_dequeue_script( 'fancybox' );
981 wp_dequeue_script( 'enable-lightbox' );
982 }
983 } else {
984 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
985 // dequeue scripts
986 wp_dequeue_script( 'flexslider' );
987 }
988 }
989 // default gallery?
990 } else {
991 // replace default WooCommerce lightbox?
992 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
993 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
994 // dequeue scripts
995 wp_dequeue_script( 'photoswipe' );
996 wp_dequeue_script( 'photoswipe-ui-default' );
997
998 // dequeue styles
999 wp_dequeue_style( 'photoswipe' );
1000 wp_dequeue_style( 'photoswipe-default-skin' );
1001
1002 // remove theme supports
1003 remove_theme_support( 'wc-product-gallery-lightbox' );
1004 } else {
1005 // remove styles
1006 wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
1007
1008 // remove scripts
1009 wp_dequeue_script( 'prettyPhoto' );
1010 wp_dequeue_script( 'prettyPhoto-init' );
1011 wp_dequeue_script( 'fancybox' );
1012 wp_dequeue_script( 'enable-lightbox' );
1013 }
1014 }
1015 }
1016 }
1017
1018 // Visual Composer lightbox
1019 if ( class_exists( 'Vc_Manager' ) ) {
1020 wp_dequeue_script( 'prettyphoto' );
1021 wp_deregister_script( 'prettyphoto' );
1022 wp_dequeue_style( 'prettyphoto' );
1023 wp_deregister_style( 'prettyphoto' );
1024 }
1025 }
1026
1027 /**
1028 * Apply lightbox to WooCommerce product image.
1029 *
1030 * @param mixed $html
1031 * @return mixed
1032 */
1033 public function woocommerce_single_product_image_html( $html ) {
1034 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] )
1035 $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '"', $html );
1036
1037 return $html;
1038 }
1039
1040 /**
1041 * Apply lightbox to WooCommerce product gallery.
1042 *
1043 * @param mixed $html
1044 * @return mixed
1045 */
1046 public function woocommerce_single_product_image_thumbnail_html( $html ) {
1047 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] ) {
1048 // make sure main product image has same gallery number
1049 $gallery_no = $this->gallery_no + 1;
1050
1051 $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '"', $html );
1052
1053 preg_match( '/<a(.*?)((?:data-rel)=(?:\'|").*?(?:\'|"))(.*?)>/i', $html, $result );
1054
1055 // no data-rel?
1056 if ( empty( $result ) ) {
1057 preg_match( '/^(.*?)<a(.*?)((?:href)=(?:\'|").*?(?:\'|"))(.*?)>(.*?)$/i', $html, $result );
1058
1059 // found valid link?
1060 if ( ! empty( $result ) )
1061 $html = $result[1] . '<a' . $result[2] . ' data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1062 }
1063 }
1064
1065 return $html;
1066 }
1067
1068 /**
1069 * WooCommerce gallery init.
1070 */
1071 public function woocommerce_gallery_init() {
1072 if ( ( $priority = has_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails' ) ) != false && ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1073 // remove default gallery
1074 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', $priority );
1075
1076 // handle product gallery
1077 add_action( 'woocommerce_product_thumbnails', array( $this, 'woocommerce_gallery' ), $priority );
1078 }
1079 }
1080
1081 /**
1082 * WooCommerce gallery support.
1083 *
1084 * @global object $product
1085 * @return mixed
1086 */
1087 public function woocommerce_gallery() {
1088 global $product;
1089
1090 $attachment_ids = array();
1091
1092 // WooCommerce 3.x
1093 if ( method_exists( $product, 'get_gallery_image_ids' ) )
1094 $attachment_ids = $product->get_gallery_image_ids();
1095 // WooCommerce 2.x
1096 elseif ( method_exists( $product, 'get_gallery_attachment_ids' ) )
1097 $attachment_ids = $product->get_gallery_attachment_ids();
1098
1099 if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) )
1100 echo do_shortcode( '[gallery type="' . Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] . '" size="' . apply_filters( 'single_product_small_thumbnail_size', 'medium' ) . '" ids="' . implode( ',', $attachment_ids ) . '"]' );
1101 }
1102
1103 /**
1104 * Get attachment title function
1105 *
1106 * @param int $id
1107 * @param string $title_arg
1108 * @return string
1109 */
1110 public function get_attachment_title( $id, $title_arg ) {
1111 if ( empty( $title_arg ) || empty( $id ) )
1112 return false;
1113
1114 switch( $title_arg ) {
1115 case 'title':
1116 $title = get_the_title( $id );
1117 break;
1118
1119 case 'caption':
1120 $title = get_post_field( 'post_excerpt', $id ) ;
1121 break;
1122
1123 case 'alt':
1124 $title = get_post_meta( $id, '_wp_attachment_image_alt', true );
1125 break;
1126
1127 case 'description':
1128 $title = get_post_field( 'post_content', $id ) ;
1129 break;
1130
1131 default:
1132 $title = '';
1133 }
1134
1135 return apply_filters( 'rl_get_attachment_title', $title, $id, $title_arg );
1136 }
1137
1138 /**
1139 * Get attachment id by url function, adjusted to work for cropped images
1140 *
1141 * @param string $url
1142 * @return int
1143 */
1144 public function get_attachment_id_by_url( $url ) {
1145 $url = ! empty( $url ) ? esc_url( $url ) : '';
1146
1147 // get cached data
1148 // $post_id = wp_cache_get( md5( $url ), 'rl-attachment_id_by_url' );
1149 $post_ids = get_transient( 'rl-attachment_ids_by_url' );
1150 $post_id = 0;
1151
1152 // cached url not found?
1153 if ( $post_ids === false || ! in_array( $url, array_keys( $post_ids ) ) ) {
1154 $post_id = attachment_url_to_postid( $url );
1155
1156 if ( ! $post_id ) {
1157 $dir = wp_upload_dir();
1158 $path = $url;
1159
1160 if ( strpos( $path, $dir['baseurl'] . '/' ) === 0 )
1161 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
1162
1163 if ( preg_match( '/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches ) )
1164 $post_id = attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . $matches[3] );
1165 }
1166
1167 // set the cache expiration, 24 hours by default
1168 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1169
1170 // wp_cache_add( md5( $url ), $post_id, 'rl-attachment_id_by_url', $expire );
1171
1172 $post_ids[$url] = $post_id;
1173
1174 set_transient( 'rl-attachment_ids_by_url', $post_ids, $expire );
1175 // cached url found
1176 } elseif ( ! empty( $post_ids[$url] ) )
1177 $post_id = absint( $post_ids[$url] );
1178
1179 return (int) apply_filters( 'rl_get_attachment_id_by_url', $post_id, $url );
1180 }
1181
1182 /**
1183 * Get image size by URL.
1184 *
1185 * @param string $url Image URL
1186 * @return array
1187 */
1188 public function get_image_size_by_url( $url ) {
1189 $url = ! empty( $url ) ? esc_url( $url ) : '';
1190 $size = array( 0, 0 );
1191
1192 if ( ! empty( $url ) ) {
1193 // get cached data
1194 $image_sizes = get_transient( 'rl-image_sizes_by_url' );
1195
1196 // cached url not found?
1197 if ( $image_sizes === false || ! in_array( $url, array_keys( $image_sizes ) ) || empty( $image_sizes[$url] ) ) {
1198 if ( class_exists( 'Responsive_Lightbox_Fast_Image' ) ) {
1199 // loading image
1200 $image = new Responsive_Lightbox_Fast_Image( $url );
1201
1202 // get size
1203 $size = $image->get_size();
1204 } else {
1205 // get size using php
1206 $size = getimagesize( $url );
1207 }
1208
1209 // set the cache expiration, 24 hours by default
1210 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1211
1212 $image_sizes[$url] = $size;
1213
1214 set_transient( 'rl-image_sizes_by_url', $image_sizes, $expire );
1215 // cached url found
1216 } elseif ( ! empty( $image_sizes[$url] ) )
1217 $size = array_map( 'absint', $image_sizes[$url] );
1218 }
1219
1220 return apply_filters( 'rl_get_image_size_by_url', $size, $url );
1221 }
1222
1223 /**
1224 * Add gallery shortcode to gallery post content.
1225 *
1226 * @param string $content
1227 * @return string Updated content
1228 */
1229 public function gallery_preview( $content ) {
1230 if ( get_post_type() === 'rl_gallery' && ! ( is_archive() && is_main_query() ) )
1231 $content .= do_shortcode( '[rl_gallery id="' . get_the_ID() . '"]' );
1232
1233 return $content;
1234 }
1235
1236 /**
1237 * Helper: gallery number function
1238 *
1239 * @param mixed $content
1240 * @return mixed
1241 */
1242 public function gallery_attributes( $content, $shortcode_atts ) {
1243 ++$this->gallery_no;
1244
1245 // add inline style, to our galleries only
1246 if ( isset( $shortcode_atts['type'] ) ) {
1247 // gallery style
1248 wp_enqueue_style( 'responsive-lightbox-gallery' );
1249
1250 // is there rl_gallery ID?
1251 $rl_gallery_id = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1252
1253 // is it rl gallery?
1254 $rl_gallery = Responsive_Lightbox()->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1255
1256 // is it rl gallery? add design options
1257 if ( $rl_gallery ) {
1258 $fields = Responsive_Lightbox()->galleries->fields['design']['options'];
1259
1260 // get gallery fields attributes
1261 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1262
1263 // get only valid arguments
1264 $atts = shortcode_atts( $field_atts, array_merge( $field_atts, $shortcode_atts ), 'gallery' );
1265
1266 // sanitize gallery fields
1267 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1268
1269 // add inline style
1270 $inline_css = '
1271 .rl-gallery .rl-gallery-link {
1272 border: ' . $atts['border_width'] . 'px solid ' . $atts['border_color'] . ';
1273 }
1274 .rl-gallery .rl-gallery-link .rl-gallery-item-title {
1275 color: ' . $atts['title_color'] . ';
1276 }
1277 .rl-gallery .rl-gallery-link .rl-gallery-item-caption {
1278 color: ' . $atts['caption_color'] . ';
1279 }
1280 .rl-gallery .rl-gallery-link .rl-gallery-caption,
1281 .rl-gallery .rl-gallery-link:after {
1282 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1283 }
1284 [class^="rl-hover-icon-"] .rl-gallery-link:before,
1285 [class*=" rl-hover-icon-"] .rl-gallery-link:before {
1286 color: ' . $atts['title_color'] . ';
1287 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1288 }
1289 ';
1290
1291 wp_add_inline_style( 'responsive-lightbox-gallery', $inline_css );
1292 }
1293 }
1294
1295 return $content;
1296 }
1297
1298 /**
1299 * Generate unique hash.
1300 *
1301 * @param int $length
1302 * @return string
1303 */
1304 private function generate_hash( $length = 8 ) {
1305 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
1306 $hash = '';
1307
1308 for( $i = 0; $i < $length; $i++ ) {
1309 $hash .= substr( $chars, mt_rand( 0, strlen( $chars ) - 1 ), 1 );
1310 }
1311
1312 return $hash;
1313 }
1314
1315 /**
1316 * Replace widget callback function.
1317 *
1318 * @global array $wp_registered_widgets
1319 * @param array $sidebar_params
1320 * @return type
1321 */
1322 public function dynamic_sidebar_params( $sidebar_params ) {
1323 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['widgets'] != true )
1324 return $sidebar_params;
1325
1326 global $wp_registered_widgets;
1327
1328 $widget_id = $sidebar_params[0]['widget_id'];
1329 $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
1330 $wp_registered_widgets[ $widget_id ]['callback'] = array( $this, 'widget_callback_function' );
1331
1332 return $sidebar_params;
1333 }
1334
1335 /**
1336 * Widget callback function.
1337 *
1338 * @global array $wp_registered_widgets
1339 */
1340 public function widget_callback_function() {
1341 global $wp_registered_widgets;
1342
1343 $original_callback_params = func_get_args();
1344 $widget_id = $original_callback_params[0]['widget_id'];
1345 $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
1346 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
1347 $widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
1348
1349 if ( is_callable( $original_callback ) ) {
1350 ob_start();
1351
1352 call_user_func_array( $original_callback, $original_callback_params );
1353
1354 $widget_output = ob_get_clean();
1355
1356 echo apply_filters( 'rl_widget_output', $widget_output, $widget_id_base, $widget_id );
1357 }
1358 }
1359
1360 /**
1361 * Filter widget output.
1362 *
1363 * @param mixed $widget_output
1364 * @param string $widget_id_base
1365 * @param id $widget_id
1366 * @return mixed
1367 */
1368 public function widget_output( $content, $widget_id_base, $widget_id ) {
1369 return $this->add_lightbox( $content );
1370 }
1371
1372 /**
1373 * Filter comment content.
1374 *
1375 * @param mixed $comment_content
1376 * @return mixed
1377 */
1378 public function get_comment_text( $content ) {
1379 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['comments'] != true )
1380 return $content;
1381
1382 return $this->add_lightbox( $content );
1383 }
1384
1385 /**
1386 * Modify gallery container class.
1387 *
1388 * @param string $class
1389 * @param array $args
1390 * @param int $gallery_id
1391 * @return void
1392 */
1393 public function gallery_container_class( $class, $args, $gallery_id ) {
1394 if ( $gallery_id ) {
1395 $class .= ' rl-loading';
1396
1397 if ( $args['pagination'] )
1398 $class .= ' rl-pagination-' . $args['pagination_type'];
1399 }
1400
1401 return $class;
1402 }
1403
1404 /**
1405 * Display content before the gallery.
1406 *
1407 * @param array $args
1408 * @param int $gallery_id
1409 * @return void
1410 */
1411 public function before_gallery( $args, $gallery_id ) {
1412 // if ( $gallery_id && ! ( isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-gallery-page-content' ) ) {
1413 if ( $gallery_id ) {
1414 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'top' && get_post_type() !== 'rl_gallery' )
1415 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1416
1417 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'top' )
1418 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1419 }
1420 }
1421
1422 /**
1423 * Display content after the gallery.
1424 *
1425 * @param array $args
1426 * @param int $gallery_id
1427 * @return void
1428 */
1429 public function after_gallery( $args, $gallery_id ) {
1430 if ( $gallery_id ) {
1431 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'bottom' && get_post_type() !== 'rl_gallery' )
1432 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1433
1434 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'bottom' )
1435 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1436 }
1437 }
1438
1439 /**
1440 * Add lightbox to Visual Composer shortcodes.
1441 *
1442 * @param string $content HTML content
1443 * @param string $shortcode Shortcode type
1444 * @return string Changed HTML content
1445 */
1446 public function vc_shortcode_content_filter_after( $content, $shortcode ) {
1447 if ( in_array( $shortcode, apply_filters( 'rl_lightbox_vc_allowed_shortcode', array( 'vc_gallery', 'vc_single_image', 'vc_images_carousel' ) ), true ) )
1448 $content = $this->add_lightbox( $content );
1449
1450 return $content;
1451 }
1452
1453 /**
1454 * Render Basic Grid gallery shortcode.
1455 *
1456 * @global object $post Post object
1457 * @param mixed $output HTML output
1458 * @param array $shortcode_atts Shortcode attributes
1459 * @return string HTML output
1460 */
1461 public function basic_grid_gallery_shortcode( $output, $shortcode_atts ) {
1462 if ( ! empty( $output ) )
1463 return $output;
1464
1465 global $post;
1466
1467 $defaults = array(
1468 'rl_gallery_id' => 0,
1469 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1470 'class' => '',
1471 'include' => '',
1472 'exclude' => '',
1473 'urls' => '',
1474 'type' => '',
1475 'order' => 'asc',
1476 'orderby' => 'menu_order',
1477 'size' => 'medium',
1478 'link' => 'file',
1479 'columns' => 3
1480 );
1481
1482 // get main instance
1483 $rl = Responsive_Lightbox();
1484
1485 // is there rl_gallery ID?
1486 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1487
1488 // is it rl gallery?
1489 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1490
1491 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1492 $shortcode_atts['type'] = '';
1493
1494 // break if it is not basic grid gallery - first check
1495 if ( ! ( $shortcode_atts['type'] === 'basicgrid' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1496 return $output;
1497
1498 // get shortcode gallery fields combined with defaults
1499 $fields = rl_get_gallery_fields( 'basicgrid' );
1500
1501 // get gallery fields attributes
1502 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1503
1504 // is it rl gallery? add misc and lightbox fields
1505 if ( $rl_gallery )
1506 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1507
1508 // get only valid arguments
1509 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1510
1511 // sanitize gallery fields
1512 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1513
1514 // break if it is not basic grid gallery
1515 if ( ! ( $atts['type'] === 'basicgrid' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1516 return $output;
1517
1518 // ID
1519 $atts['id'] = (int) $atts['id'];
1520
1521 // add custom classes if needed
1522 if ( $rl_gallery )
1523 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1524
1525 // any classes?
1526 if ( $atts['class'] !== '' ) {
1527 $atts['class'] = trim( $atts['class'] );
1528
1529 // more than 1 class?
1530 if ( strpos( $atts['class'], ' ' ) !== false ) {
1531 // get unique valid HTML classes
1532 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1533
1534 if ( ! empty( $atts['class'] ) )
1535 $atts['class'] = implode( ' ', $atts['class'] );
1536 else
1537 $atts['class'] = '';
1538 // single class
1539 } else
1540 $atts['class'] = sanitize_html_class( $atts['class'] );
1541 }
1542
1543 // orderby
1544 if ( empty( $atts['orderby'] ) ) {
1545 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1546
1547 if ( empty( $atts['orderby'] ) )
1548 $atts['orderby'] = $defaults['orderby'];
1549 }
1550
1551 // order
1552 if ( strtolower( $atts['order'] ) === 'rand' )
1553 $atts['orderby'] = 'rand';
1554
1555 // check columns
1556 if ( $atts['columns_lg'] === 0 )
1557 $atts['columns_lg'] = $atts['columns'];
1558
1559 if ( $atts['columns_md'] === 0 )
1560 $atts['columns_md'] = $atts['columns'];
1561
1562 if ( $atts['columns_sm'] === 0 )
1563 $atts['columns_sm'] = $atts['columns'];
1564
1565 if ( $atts['columns_xs'] === 0 )
1566 $atts['columns_xs'] = $atts['columns'];
1567
1568 // gallery lightbox source size
1569 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1570 if ( $atts['lightbox_image_size'] === 'global' )
1571 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1572 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1573 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1574 else
1575 $atts['src_size'] = $atts['lightbox_image_size'];
1576 } else
1577 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1578
1579 // filter all shortcode arguments
1580 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1581
1582 // get gallery images
1583 $images = rl_get_gallery_shortcode_images( $atts );
1584
1585 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1586 return $output;
1587
1588 $gallery_no = $this->gallery_no;
1589
1590 ob_start(); ?>
1591
1592 <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
1593
1594 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1595
1596 <div class="rl-gallery rl-basicgrid-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
1597
1598 <?php foreach ( $images as $image ) {
1599 echo '<div class="rl-gallery-item">' . $image['link'] . '</div>';
1600 } ?>
1601
1602 </div>
1603
1604 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1605
1606 </div>
1607
1608 <?php $gallery_html = ob_get_contents();
1609
1610 ob_end_clean();
1611
1612 // styles
1613 wp_enqueue_style( 'responsive-lightbox-basicgrid-gallery', plugins_url( 'css/gallery-basicgrid.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
1614
1615 // add inline style
1616 $inline_css = '
1617 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery {
1618 padding: ' . ( -$atts['gutter'] ) . 'px;
1619 }
1620 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1621 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
1622 margin: ' . ( $atts['gutter'] / 2 ) . 'px;
1623 }
1624 @media all and (min-width: 1200px) {
1625 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1626 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
1627 }
1628 }
1629 @media all and (min-width: 992px) and (max-width: 1200px) {
1630 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1631 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
1632 }
1633 }
1634 @media all and (min-width: 768px) and (max-width: 992px) {
1635 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1636 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
1637 }
1638 }
1639 @media all and (max-width: 768px) {
1640 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1641 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
1642 }
1643 }
1644 ';
1645
1646 if ( $atts['force_height'] ) {
1647 $inline_css .= '
1648 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1649 height: ' . ( $atts['row_height'] ) . 'px;
1650 }
1651 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item img {
1652 height: ' . ( $atts['row_height'] ) . 'px;
1653 object-fit: cover;
1654 max-width: 100%;
1655 min-width: 100%;
1656 }';
1657 }
1658
1659 wp_add_inline_style( 'responsive-lightbox-basicgrid-gallery', $inline_css );
1660
1661 // remove any new lines from the output so that the reader parses it better
1662 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1663 }
1664
1665 /**
1666 * Render Basic Slider gallery shortcode.
1667 *
1668 * @global object $post Post object
1669 * @param mixed $output HTML output
1670 * @param array $shortcode_atts Shortcode attributes
1671 * @return string HTML output
1672 */
1673 public function basic_slider_gallery_shortcode( $output, $shortcode_atts ) {
1674 if ( ! empty( $output ) )
1675 return $output;
1676
1677 global $post;
1678
1679 $defaults = array(
1680 'rl_gallery_id' => 0,
1681 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1682 'class' => '',
1683 'include' => '',
1684 'exclude' => '',
1685 'urls' => '',
1686 'type' => '',
1687 'order' => 'asc',
1688 'orderby' => 'menu_order',
1689 'size' => 'medium',
1690 'link' => 'file',
1691 'columns' => 3
1692 );
1693
1694 // get main instance
1695 $rl = Responsive_Lightbox();
1696
1697 // is there rl_gallery ID?
1698 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1699
1700 // is it rl gallery?
1701 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1702
1703 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1704 $shortcode_atts['type'] = '';
1705
1706 // break if it is not basic slider gallery - first check
1707 if ( ! ( $shortcode_atts['type'] === 'basicslider' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1708 return $output;
1709
1710 // get shortcode gallery fields combined with defaults
1711 $fields = rl_get_gallery_fields( 'basicslider' );
1712
1713 // get gallery fields attributes
1714 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1715
1716 // is it rl gallery? add misc and lightbox fields
1717 if ( $rl_gallery )
1718 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1719
1720 // get only valid arguments
1721 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1722
1723 // sanitize gallery fields
1724 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1725
1726 // break if it is not basic slider gallery
1727 if ( ! ( $atts['type'] === 'basicslider' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1728 return $output;
1729
1730 // ID
1731 $atts['id'] = (int) $atts['id'];
1732
1733 // add custom classes if needed
1734 if ( $rl_gallery )
1735 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1736
1737 // any classes?
1738 if ( $atts['class'] !== '' ) {
1739 $atts['class'] = trim( $atts['class'] );
1740
1741 // more than 1 class?
1742 if ( strpos( $atts['class'], ' ' ) !== false ) {
1743 // get unique valid HTML classes
1744 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1745
1746 if ( ! empty( $atts['class'] ) )
1747 $atts['class'] = implode( ' ', $atts['class'] );
1748 else
1749 $atts['class'] = '';
1750 // single class
1751 } else
1752 $atts['class'] = sanitize_html_class( $atts['class'] );
1753 }
1754
1755 // orderby
1756 if ( empty( $atts['orderby'] ) ) {
1757 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1758
1759 if ( empty( $atts['orderby'] ) )
1760 $atts['orderby'] = $defaults['orderby'];
1761 }
1762
1763 // order
1764 if ( strtolower( $atts['order'] ) === 'rand' )
1765 $atts['orderby'] = 'rand';
1766
1767 // gallery lightbox source size
1768 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1769 if ( $atts['lightbox_image_size'] === 'global' )
1770 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1771 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1772 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1773 else
1774 $atts['src_size'] = $atts['lightbox_image_size'];
1775 } else
1776 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1777
1778 // filter all shortcode arguments
1779 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1780
1781 // get gallery images
1782 $images = rl_get_gallery_shortcode_images( $atts );
1783
1784 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1785 return $output;
1786
1787 $gallery_no = $this->gallery_no;
1788
1789 ob_start(); ?>
1790
1791 <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
1792
1793 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1794
1795 <ul class="rl-gallery rl-basicslider-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
1796
1797 <?php foreach ( $images as $image ) {
1798 echo '<li class="rl-gallery-item">' . $image['link'] . '</li>';
1799 } ?>
1800
1801 </ul>
1802
1803 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1804
1805 </div>
1806
1807 <?php $gallery_html = ob_get_contents();
1808
1809 ob_end_clean();
1810
1811 // scripts
1812 wp_register_script( 'responsive-lightbox-basicslider-gallery-js', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', dirname( __FILE__ ) ), array( 'jquery' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
1813 wp_enqueue_script( 'responsive-lightbox-basicslider-gallery', plugins_url( 'js/front-basicslider.js', dirname( __FILE__ ) ), array( 'jquery', 'responsive-lightbox-basicslider-gallery-js' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
1814
1815 // styles
1816 wp_enqueue_style( 'responsive-lightbox-basicslider-gallery', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
1817
1818 wp_localize_script(
1819 'responsive-lightbox-basicslider-gallery',
1820 'rlArgsBasicSliderGallery' . ( $gallery_no + 1 ),
1821 json_encode(
1822 array(
1823 'adaptive_height' => $atts['adaptive_height'],
1824 'loop' => $atts['loop'],
1825 'captions' => $atts['captions'],
1826 'init_single' => $atts['init_single'],
1827 'responsive' => $atts['responsive'],
1828 'preload' => $atts['preload'],
1829 'pager' => $atts['pager'],
1830 'controls' => $atts['controls'],
1831 'hide_on_end' => $atts['hide_on_end'],
1832 'slide_margin' => $atts['slide_margin'],
1833 'transition' => $atts['transition'],
1834 'kenburns_zoom' => $atts['kenburns_zoom'],
1835 'speed' => $atts['speed'],
1836 'easing' => $atts['easing'],
1837 'continuous' => $atts['continuous'],
1838 'use_css' => $atts['use_css'],
1839 'slideshow' => $atts['slideshow'],
1840 'slideshow_direction' => $atts['slideshow_direction'],
1841 'slideshow_hover' => $atts['slideshow_hover'],
1842 'slideshow_hover_delay' => $atts['slideshow_hover_delay'],
1843 'slideshow_delay' => $atts['slideshow_delay'],
1844 'slideshow_pause' => $atts['slideshow_pause']
1845 )
1846 )
1847 );
1848
1849 // remove any new lines from the output so that the reader parses it better
1850 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1851 }
1852
1853 /**
1854 * Render Basic Masonry gallery shortcode.
1855 *
1856 * @global object $post Post object
1857 * @param mixed $output HTML output
1858 * @param array $shortcode_atts Shortcode attributes
1859 * @return string HTML output
1860 */
1861 public function basic_masonry_gallery_shortcode( $output, $shortcode_atts ) {
1862 if ( ! empty( $output ) )
1863 return $output;
1864
1865 global $post;
1866
1867 $defaults = array(
1868 'rl_gallery_id' => 0,
1869 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1870 'class' => '',
1871 'include' => '',
1872 'exclude' => '',
1873 'urls' => '',
1874 'type' => '',
1875 'order' => 'asc',
1876 'orderby' => 'menu_order',
1877 'size' => 'medium',
1878 'link' => 'file',
1879 'columns' => 3
1880 );
1881
1882 // get main instance
1883 $rl = Responsive_Lightbox();
1884
1885 // is there rl_gallery ID?
1886 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1887
1888 // is it rl gallery?
1889 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1890
1891 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1892 $shortcode_atts['type'] = '';
1893
1894 // break if it is not basic masonry gallery - first check
1895 if ( ! ( $shortcode_atts['type'] === 'basicmasonry' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1896 return $output;
1897
1898 // get shortcode gallery fields combined with defaults
1899 $fields = rl_get_gallery_fields( 'basicmasonry' );
1900
1901 // get gallery fields attributes
1902 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1903
1904 // is it rl gallery? add misc and lightbox fields
1905 if ( $rl_gallery )
1906 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1907
1908 // get only valid arguments
1909 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1910
1911 // sanitize gallery fields
1912 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1913
1914 // break if it is not basic masonry gallery
1915 if ( ! ( $atts['type'] === 'basicmasonry' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1916 return $output;
1917
1918 // ID
1919 $atts['id'] = (int) $atts['id'];
1920
1921 // add custom classes if needed
1922 if ( $rl_gallery )
1923 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1924
1925 // any classes?
1926 if ( $atts['class'] !== '' ) {
1927 $atts['class'] = trim( $atts['class'] );
1928
1929 // more than 1 class?
1930 if ( strpos( $atts['class'], ' ' ) !== false ) {
1931 // get unique valid HTML classes
1932 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1933
1934 if ( ! empty( $atts['class'] ) )
1935 $atts['class'] = implode( ' ', $atts['class'] );
1936 else
1937 $atts['class'] = '';
1938 // single class
1939 } else
1940 $atts['class'] = sanitize_html_class( $atts['class'] );
1941 }
1942
1943 // orderby
1944 if ( empty( $atts['orderby'] ) ) {
1945 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1946
1947 if ( empty( $atts['orderby'] ) )
1948 $atts['orderby'] = $defaults['orderby'];
1949 }
1950
1951 // order
1952 if ( strtolower( $atts['order'] ) === 'rand' )
1953 $atts['orderby'] = 'rand';
1954
1955 // check columns
1956 if ( $atts['columns_lg'] === 0 )
1957 $atts['columns_lg'] = $atts['columns'];
1958
1959 if ( $atts['columns_md'] === 0 )
1960 $atts['columns_md'] = $atts['columns'];
1961
1962 if ( $atts['columns_sm'] === 0 )
1963 $atts['columns_sm'] = $atts['columns'];
1964
1965 if ( $atts['columns_xs'] === 0 )
1966 $atts['columns_xs'] = $atts['columns'];
1967
1968 // gallery lightbox source size
1969 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1970 if ( $atts['lightbox_image_size'] === 'global' )
1971 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1972 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1973 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1974 else
1975 $atts['src_size'] = $atts['lightbox_image_size'];
1976 } else
1977 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1978
1979 // filter all shortcode arguments
1980 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1981
1982 // get gallery images
1983 $images = rl_get_gallery_shortcode_images( $atts );
1984
1985 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1986 return $output;
1987
1988 $gallery_no = $this->gallery_no;
1989
1990 ob_start(); ?>
1991
1992 <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
1993
1994 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1995
1996 <div class="rl-gallery rl-basicmasonry-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
1997
1998 <?php
1999 $count = 0;
2000
2001 if ( $count === 0 )
2002 echo '<div class="rl-gutter-sizer"></div><div class="rl-grid-sizer"></div>';
2003
2004 foreach ( $images as $image ) {
2005 echo '
2006 <div class="rl-gallery-item' . ( $count === 0 ? ' rl-gallery-item-width-4' : '' ) . '" ' . implode( ' ', apply_filters( 'rl_gallery_item_extra_args', array(), $atts, $image ) ) . '>
2007 <div class="rl-gallery-item-content">
2008 ' . $image['link'] . '
2009 </div>
2010 </div>';
2011
2012 $count++;
2013 } ?>
2014
2015 </div>
2016
2017 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
2018
2019 </div>
2020
2021 <?php $gallery_html = ob_get_contents();
2022
2023 ob_clean();
2024
2025 // scripts
2026 wp_enqueue_script( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'js/front-basicmasonry.js', dirname( __FILE__ ) ), array( 'jquery', 'responsive-lightbox-masonry', 'responsive-lightbox-images-loaded' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2027
2028 // styles
2029 wp_enqueue_style( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'css/gallery-basicmasonry.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
2030
2031 // add inline style
2032 wp_add_inline_style( 'responsive-lightbox-basicmasonry-gallery', '
2033 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery {
2034 margin: ' . -( $atts['margin'] / 2 ) . 'px ' . -( $atts['gutter'] / 2 ) . 'px;
2035 padding: ' . $atts['margin'] . 'px 0;
2036 }
2037 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-bottom {
2038 margin-top: ' . ( $atts['margin'] / 2 ) . 'px
2039 }
2040 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-top {
2041 margin-bottom: ' . ( $atts['margin'] / 2 ) . 'px
2042 }
2043 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2044 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2045 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
2046 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2047 }
2048 @media all and (min-width: 1200px) {
2049 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2050 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2051 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
2052 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2053 }
2054 }
2055 @media all and (min-width: 992px) and (max-width: 1200px) {
2056 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2057 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2058 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
2059 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2060 }
2061 }
2062 @media all and (min-width: 768px) and (max-width: 992px) {
2063 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2064 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2065 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
2066 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2067 }
2068 }
2069 @media all and (max-width: 768px) {
2070 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2071 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2072 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
2073 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2074 }
2075 }'
2076 );
2077
2078 wp_localize_script(
2079 'responsive-lightbox-basicmasonry-gallery',
2080 'rlArgsBasicMasonryGallery' . ( $gallery_no + 1 ),
2081 json_encode(
2082 array(
2083 'originLeft' => $atts['origin_left'],
2084 'originTop' => $atts['origin_top']
2085 )
2086 )
2087 );
2088
2089 // remove any new lines from the output so that the reader parses it better
2090 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
2091 }
2092 }