PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.1
Responsive Lightbox & Gallery v2.1
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
class-fast-image.php 7 years ago class-folders-walker.php 7 years ago class-folders.php 7 years ago class-frontend.php 7 years ago class-galleries.php 7 years ago class-settings.php 7 years ago class-tour.php 7 years ago class-welcome.php 7 years ago class-widgets.php 7 years ago functions.php 7 years ago
class-frontend.php
2090 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 $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '"', $html );
1049
1050 preg_match( '/<a(.*?)((?:data-rel)=(?:\'|").*?(?:\'|"))(.*?)>/i', $html, $result );
1051
1052 // no data-rel?
1053 if ( empty( $result ) ) {
1054 preg_match( '/^(.*?)<a(.*?)((?:href)=(?:\'|").*?(?:\'|"))(.*?)>(.*?)$/i', $html, $result );
1055
1056 // found valid link?
1057 if ( ! empty( $result ) )
1058 $html = $result[1] . '<a' . $result[2] . ' data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1059 }
1060 }
1061
1062 return $html;
1063 }
1064
1065 /**
1066 * WooCommerce gallery init.
1067 */
1068 public function woocommerce_gallery_init() {
1069 if ( ( $priority = has_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails' ) ) != false && ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) ) {
1070 // remove default gallery
1071 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', $priority );
1072
1073 // handle product gallery
1074 add_action( 'woocommerce_product_thumbnails', array( $this, 'woocommerce_gallery' ), $priority );
1075 }
1076 }
1077
1078 /**
1079 * WooCommerce gallery support.
1080 *
1081 * @global object $product
1082 * @return mixed
1083 */
1084 public function woocommerce_gallery() {
1085 global $product;
1086
1087 $attachment_ids = array();
1088
1089 // WooCommerce 3.x
1090 if ( method_exists( $product, 'get_gallery_image_ids' ) ) {
1091 $attachment_ids = $product->get_gallery_image_ids();
1092 // WooCommerce 2.x
1093 } elseif ( method_exists( $product, 'get_gallery_attachment_ids' ) ) {
1094 $attachment_ids = $product->get_gallery_attachment_ids();
1095 }
1096
1097 if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) )
1098 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 ) . '"]' );
1099 }
1100
1101 /**
1102 * Get attachment title function
1103 *
1104 * @param int $id
1105 * @param string $title_arg
1106 * @return string
1107 */
1108 public function get_attachment_title( $id, $title_arg ) {
1109 if ( empty( $title_arg ) || empty( $id ) )
1110 return false;
1111
1112 switch( $title_arg ) {
1113 case 'title':
1114 $title = get_the_title( $id );
1115 break;
1116
1117 case 'caption':
1118 $title = get_post_field( 'post_excerpt', $id ) ;
1119 break;
1120
1121 case 'alt':
1122 $title = get_post_meta( $id, '_wp_attachment_image_alt', true );
1123 break;
1124
1125 case 'description':
1126 $title = get_post_field( 'post_content', $id ) ;
1127 break;
1128
1129 default:
1130 $title = '';
1131 }
1132
1133 return apply_filters( 'rl_get_attachment_title', $title, $id, $title_arg );
1134 }
1135
1136 /**
1137 * Get attachment id by url function, adjusted to work for cropped images
1138 *
1139 * @param string $url
1140 * @return int
1141 */
1142 public function get_attachment_id_by_url( $url ) {
1143 $url = ! empty( $url ) ? esc_url( $url ) : '';
1144
1145 // get cached data
1146 // $post_id = wp_cache_get( md5( $url ), 'rl-attachment_id_by_url' );
1147 $post_ids = get_transient( 'rl-attachment_ids_by_url' );
1148 $post_id = 0;
1149
1150 // cached url not found?
1151 if ( $post_ids === false || ! in_array( $url, array_keys( $post_ids ) ) ) {
1152 $post_id = attachment_url_to_postid( $url );
1153
1154 if ( ! $post_id ) {
1155 $dir = wp_upload_dir();
1156 $path = $url;
1157
1158 if ( strpos( $path, $dir['baseurl'] . '/' ) === 0 )
1159 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
1160
1161 if ( preg_match( '/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches ) )
1162 $post_id = attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . $matches[3] );
1163 }
1164
1165 // set the cache expiration, 24 hours by default
1166 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1167
1168 // wp_cache_add( md5( $url ), $post_id, 'rl-attachment_id_by_url', $expire );
1169
1170 $post_ids[$url] = $post_id;
1171
1172 set_transient( 'rl-attachment_ids_by_url', $post_ids, $expire );
1173 // cached url found
1174 } elseif ( ! empty( $post_ids[$url] ) )
1175 $post_id = absint( $post_ids[$url] );
1176
1177 return (int) apply_filters( 'rl_get_attachment_id_by_url', $post_id, $url );
1178 }
1179
1180 /**
1181 * Get image size by URL.
1182 *
1183 * @param string $url Image URL
1184 * @return array
1185 */
1186 public function get_image_size_by_url( $url ) {
1187 $url = ! empty( $url ) ? esc_url( $url ) : '';
1188 $size = array( 0, 0 );
1189
1190 if ( ! empty( $url ) ) {
1191 // get cached data
1192 $image_sizes = get_transient( 'rl-image_sizes_by_url' );
1193
1194 // cached url not found?
1195 if ( $image_sizes === false || ! in_array( $url, array_keys( $image_sizes ) ) || empty( $image_sizes[$url] ) ) {
1196 if ( class_exists( 'Responsive_Lightbox_Fast_Image' ) ) {
1197 // loading image
1198 $image = new Responsive_Lightbox_Fast_Image( $url );
1199
1200 // get size
1201 $size = $image->get_size();
1202 } else {
1203 // get size using php
1204 $size = getimagesize( $url );
1205 }
1206
1207 // set the cache expiration, 24 hours by default
1208 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1209
1210 $image_sizes[$url] = $size;
1211
1212 set_transient( 'rl-image_sizes_by_url', $image_sizes, $expire );
1213 // cached url found
1214 } elseif ( ! empty( $image_sizes[$url] ) )
1215 $size = array_map( 'absint', $image_sizes[$url] );
1216 }
1217
1218 return apply_filters( 'rl_get_image_size_by_url', $size, $url );
1219 }
1220
1221 /**
1222 * Add gallery shortcode to gallery post content.
1223 *
1224 * @param string $content
1225 * @return string Updated content
1226 */
1227 public function gallery_preview( $content ) {
1228 if ( get_post_type() === 'rl_gallery' && ! ( is_archive() && is_main_query() ) )
1229 $content .= do_shortcode( '[rl_gallery id="' . get_the_ID() . '"]' );
1230
1231 return $content;
1232 }
1233
1234 /**
1235 * Helper: gallery number function
1236 *
1237 * @param mixed $content
1238 * @return mixed
1239 */
1240 public function gallery_attributes( $content, $shortcode_atts ) {
1241 ++$this->gallery_no;
1242
1243 // add inline style, to our galleries only
1244 if ( isset( $shortcode_atts['type'] ) ) {
1245 // gallery style
1246 wp_enqueue_style( 'responsive-lightbox-gallery' );
1247
1248 // is there rl_gallery ID?
1249 $rl_gallery_id = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1250
1251 // is it rl gallery?
1252 $rl_gallery = Responsive_Lightbox()->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1253
1254 // is it rl gallery? add design options
1255 if ( $rl_gallery ) {
1256 $fields = Responsive_Lightbox()->galleries->fields['design']['options'];
1257
1258 // get gallery fields attributes
1259 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1260
1261 // get only valid arguments
1262 $atts = shortcode_atts( $field_atts, array_merge( $field_atts, $shortcode_atts ), 'gallery' );
1263
1264 // sanitize gallery fields
1265 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1266
1267 // add inline style
1268 $inline_css = '
1269 .rl-gallery .rl-gallery-link {
1270 border: ' . $atts['border_width'] . 'px solid ' . $atts['border_color'] . ';
1271 }
1272 .rl-gallery .rl-gallery-link .rl-gallery-item-title {
1273 color: ' . $atts['title_color'] . ';
1274 }
1275 .rl-gallery .rl-gallery-link .rl-gallery-item-caption {
1276 color: ' . $atts['caption_color'] . ';
1277 }
1278 .rl-gallery .rl-gallery-link .rl-gallery-caption,
1279 .rl-gallery .rl-gallery-link:after {
1280 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1281 }
1282 [class^="rl-hover-icon-"] .rl-gallery-link:before,
1283 [class*=" rl-hover-icon-"] .rl-gallery-link:before {
1284 color: ' . $atts['title_color'] . ';
1285 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1286 }
1287 ';
1288
1289 wp_add_inline_style( 'responsive-lightbox-gallery', $inline_css );
1290 }
1291 }
1292
1293 return $content;
1294 }
1295
1296 /**
1297 * Generate unique hash.
1298 *
1299 * @param int $length
1300 * @return string
1301 */
1302 private function generate_hash( $length = 8 ) {
1303 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
1304 $hash = '';
1305
1306 for( $i = 0; $i < $length; $i++ ) {
1307 $hash .= substr( $chars, mt_rand( 0, strlen( $chars ) - 1 ), 1 );
1308 }
1309
1310 return $hash;
1311 }
1312
1313 /**
1314 * Replace widget callback function.
1315 *
1316 * @global array $wp_registered_widgets
1317 * @param array $sidebar_params
1318 * @return type
1319 */
1320 public function dynamic_sidebar_params( $sidebar_params ) {
1321 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['widgets'] != true )
1322 return $sidebar_params;
1323
1324 global $wp_registered_widgets;
1325
1326 $widget_id = $sidebar_params[0]['widget_id'];
1327 $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
1328 $wp_registered_widgets[ $widget_id ]['callback'] = array( $this, 'widget_callback_function' );
1329
1330 return $sidebar_params;
1331 }
1332
1333 /**
1334 * Widget callback function.
1335 *
1336 * @global array $wp_registered_widgets
1337 */
1338 public function widget_callback_function() {
1339 global $wp_registered_widgets;
1340
1341 $original_callback_params = func_get_args();
1342 $widget_id = $original_callback_params[0]['widget_id'];
1343 $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
1344 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
1345 $widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
1346
1347 if ( is_callable( $original_callback ) ) {
1348 ob_start();
1349
1350 call_user_func_array( $original_callback, $original_callback_params );
1351
1352 $widget_output = ob_get_clean();
1353
1354 echo apply_filters( 'rl_widget_output', $widget_output, $widget_id_base, $widget_id );
1355 }
1356 }
1357
1358 /**
1359 * Filter widget output.
1360 *
1361 * @param mixed $widget_output
1362 * @param string $widget_id_base
1363 * @param id $widget_id
1364 * @return mixed
1365 */
1366 public function widget_output( $content, $widget_id_base, $widget_id ) {
1367 return $this->add_lightbox( $content );
1368 }
1369
1370 /**
1371 * Filter comment content.
1372 *
1373 * @param mixed $comment_content
1374 * @return mixed
1375 */
1376 public function get_comment_text( $content ) {
1377 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['comments'] != true )
1378 return $content;
1379
1380 return $this->add_lightbox( $content );
1381 }
1382
1383 /**
1384 * Modify gallery container class.
1385 *
1386 * @param string $class
1387 * @param array $args
1388 * @param int $gallery_id
1389 * @return void
1390 */
1391 public function gallery_container_class( $class, $args, $gallery_id ) {
1392 if ( $gallery_id ) {
1393 $class .= ' rl-loading';
1394
1395 if ( $args['pagination'] )
1396 $class .= ' rl-pagination-' . $args['pagination_type'];
1397 }
1398
1399 return $class;
1400 }
1401
1402 /**
1403 * Display content before the gallery.
1404 *
1405 * @param array $args
1406 * @param int $gallery_id
1407 * @return void
1408 */
1409 public function before_gallery( $args, $gallery_id ) {
1410 // if ( $gallery_id && ! ( isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-gallery-page-content' ) ) {
1411 if ( $gallery_id ) {
1412 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'top' && get_post_type() !== 'rl_gallery' )
1413 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1414
1415 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'top' )
1416 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1417 }
1418 }
1419
1420 /**
1421 * Display content after the gallery.
1422 *
1423 * @param array $args
1424 * @param int $gallery_id
1425 * @return void
1426 */
1427 public function after_gallery( $args, $gallery_id ) {
1428 if ( $gallery_id ) {
1429 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'bottom' && get_post_type() !== 'rl_gallery' )
1430 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1431
1432 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'bottom' )
1433 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1434 }
1435 }
1436
1437 /**
1438 * Add lightbox to Visual Composer shortcodes.
1439 *
1440 * @param string $content HTML content
1441 * @param string $shortcode Shortcode type
1442 * @return string Changed HTML content
1443 */
1444 public function vc_shortcode_content_filter_after( $content, $shortcode ) {
1445 if ( in_array( $shortcode, apply_filters( 'rl_lightbox_vc_allowed_shortcode', array( 'vc_gallery', 'vc_single_image', 'vc_images_carousel' ) ), true ) )
1446 $content = $this->add_lightbox( $content );
1447
1448 return $content;
1449 }
1450
1451 /**
1452 * Render Basic Grid gallery shortcode.
1453 *
1454 * @global object $post Post object
1455 * @param mixed $output HTML output
1456 * @param array $shortcode_atts Shortcode attributes
1457 * @return string HTML output
1458 */
1459 public function basic_grid_gallery_shortcode( $output, $shortcode_atts ) {
1460 if ( ! empty( $output ) )
1461 return $output;
1462
1463 global $post;
1464
1465 $defaults = array(
1466 'rl_gallery_id' => 0,
1467 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1468 'class' => '',
1469 'include' => '',
1470 'exclude' => '',
1471 'urls' => '',
1472 'type' => '',
1473 'order' => 'asc',
1474 'orderby' => 'menu_order',
1475 'size' => 'medium',
1476 'link' => 'file',
1477 'columns' => 3
1478 );
1479
1480 // get main instance
1481 $rl = Responsive_Lightbox();
1482
1483 // is there rl_gallery ID?
1484 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1485
1486 // is it rl gallery?
1487 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1488
1489 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1490 $shortcode_atts['type'] = '';
1491
1492 // break if it is not basic grid gallery - first check
1493 if ( ! ( $shortcode_atts['type'] === 'basicgrid' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1494 return $output;
1495
1496 // get shortcode gallery fields combined with defaults
1497 $fields = rl_get_gallery_fields( 'basicgrid' );
1498
1499 // get gallery fields attributes
1500 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1501
1502 // is it rl gallery? add misc and lightbox fields
1503 if ( $rl_gallery )
1504 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1505
1506 // get only valid arguments
1507 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1508
1509 // sanitize gallery fields
1510 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1511
1512 // break if it is not basic grid gallery
1513 if ( ! ( $atts['type'] === 'basicgrid' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1514 return $output;
1515
1516 // ID
1517 $atts['id'] = (int) $atts['id'];
1518
1519 // add custom classes if needed
1520 if ( $rl_gallery )
1521 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1522
1523 // any classes?
1524 if ( $atts['class'] !== '' ) {
1525 $atts['class'] = trim( $atts['class'] );
1526
1527 // more than 1 class?
1528 if ( strpos( $atts['class'], ' ' ) !== false ) {
1529 // get unique valid HTML classes
1530 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1531
1532 if ( ! empty( $atts['class'] ) )
1533 $atts['class'] = implode( ' ', $atts['class'] );
1534 else
1535 $atts['class'] = '';
1536 // single class
1537 } else
1538 $atts['class'] = sanitize_html_class( $atts['class'] );
1539 }
1540
1541 // orderby
1542 if ( empty( $atts['orderby'] ) ) {
1543 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1544
1545 if ( empty( $atts['orderby'] ) )
1546 $atts['orderby'] = $defaults['orderby'];
1547 }
1548
1549 // order
1550 if ( strtolower( $atts['order'] ) === 'rand' )
1551 $atts['orderby'] = 'rand';
1552
1553 // check columns
1554 if ( $atts['columns_lg'] === 0 )
1555 $atts['columns_lg'] = $atts['columns'];
1556
1557 if ( $atts['columns_md'] === 0 )
1558 $atts['columns_md'] = $atts['columns'];
1559
1560 if ( $atts['columns_sm'] === 0 )
1561 $atts['columns_sm'] = $atts['columns'];
1562
1563 if ( $atts['columns_xs'] === 0 )
1564 $atts['columns_xs'] = $atts['columns'];
1565
1566 // gallery lightbox source size
1567 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1568 if ( $atts['lightbox_image_size'] === 'global' )
1569 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1570 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1571 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1572 else
1573 $atts['src_size'] = $atts['lightbox_image_size'];
1574 } else
1575 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1576
1577 // filter all shortcode arguments
1578 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1579
1580 // get gallery images
1581 $images = rl_get_gallery_shortcode_images( $atts );
1582
1583 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1584 return $output;
1585
1586 $gallery_no = $this->gallery_no;
1587
1588 ob_start(); ?>
1589
1590 <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; ?>">
1591
1592 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1593
1594 <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; ?>">
1595
1596 <?php foreach ( $images as $image ) {
1597 echo '<div class="rl-gallery-item">' . $image['link'] . '</div>';
1598 } ?>
1599
1600 </div>
1601
1602 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1603
1604 </div>
1605
1606 <?php $gallery_html = ob_get_contents();
1607
1608 ob_end_clean();
1609
1610 // styles
1611 wp_enqueue_style( 'responsive-lightbox-basicgrid-gallery', plugins_url( 'css/gallery-basicgrid.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
1612
1613 // add inline style
1614 $inline_css = '
1615 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery {
1616 padding: ' . ( -$atts['gutter'] ) . 'px;
1617 }
1618 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1619 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
1620 margin: ' . ( $atts['gutter'] / 2 ) . 'px;
1621 }
1622 @media all and (min-width: 1200px) {
1623 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1624 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
1625 }
1626 }
1627 @media all and (min-width: 992px) and (max-width: 1200px) {
1628 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1629 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
1630 }
1631 }
1632 @media all and (min-width: 768px) and (max-width: 992px) {
1633 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1634 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
1635 }
1636 }
1637 @media all and (max-width: 768px) {
1638 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1639 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
1640 }
1641 }
1642 ';
1643
1644 if ( $atts['force_height'] ) {
1645 $inline_css .= '
1646 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1647 height: ' . ( $atts['row_height'] ) . 'px;
1648 }
1649 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item img {
1650 height: ' . ( $atts['row_height'] ) . 'px;
1651 object-fit: cover;
1652 max-width: 100%;
1653 min-width: 100%;
1654 }';
1655 }
1656
1657 wp_add_inline_style( 'responsive-lightbox-basicgrid-gallery', $inline_css );
1658
1659 // remove any new lines from the output so that the reader parses it better
1660 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1661 }
1662
1663 /**
1664 * Render Basic Slider gallery shortcode.
1665 *
1666 * @global object $post Post object
1667 * @param mixed $output HTML output
1668 * @param array $shortcode_atts Shortcode attributes
1669 * @return string HTML output
1670 */
1671 public function basic_slider_gallery_shortcode( $output, $shortcode_atts ) {
1672 if ( ! empty( $output ) )
1673 return $output;
1674
1675 global $post;
1676
1677 $defaults = array(
1678 'rl_gallery_id' => 0,
1679 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1680 'class' => '',
1681 'include' => '',
1682 'exclude' => '',
1683 'urls' => '',
1684 'type' => '',
1685 'order' => 'asc',
1686 'orderby' => 'menu_order',
1687 'size' => 'medium',
1688 'link' => 'file',
1689 'columns' => 3
1690 );
1691
1692 // get main instance
1693 $rl = Responsive_Lightbox();
1694
1695 // is there rl_gallery ID?
1696 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1697
1698 // is it rl gallery?
1699 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1700
1701 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1702 $shortcode_atts['type'] = '';
1703
1704 // break if it is not basic slider gallery - first check
1705 if ( ! ( $shortcode_atts['type'] === 'basicslider' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1706 return $output;
1707
1708 // get shortcode gallery fields combined with defaults
1709 $fields = rl_get_gallery_fields( 'basicslider' );
1710
1711 // get gallery fields attributes
1712 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1713
1714 // is it rl gallery? add misc and lightbox fields
1715 if ( $rl_gallery )
1716 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1717
1718 // get only valid arguments
1719 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1720
1721 // sanitize gallery fields
1722 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1723
1724 // break if it is not basic slider gallery
1725 if ( ! ( $atts['type'] === 'basicslider' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1726 return $output;
1727
1728 // ID
1729 $atts['id'] = (int) $atts['id'];
1730
1731 // add custom classes if needed
1732 if ( $rl_gallery )
1733 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1734
1735 // any classes?
1736 if ( $atts['class'] !== '' ) {
1737 $atts['class'] = trim( $atts['class'] );
1738
1739 // more than 1 class?
1740 if ( strpos( $atts['class'], ' ' ) !== false ) {
1741 // get unique valid HTML classes
1742 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1743
1744 if ( ! empty( $atts['class'] ) )
1745 $atts['class'] = implode( ' ', $atts['class'] );
1746 else
1747 $atts['class'] = '';
1748 // single class
1749 } else
1750 $atts['class'] = sanitize_html_class( $atts['class'] );
1751 }
1752
1753 // orderby
1754 if ( empty( $atts['orderby'] ) ) {
1755 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1756
1757 if ( empty( $atts['orderby'] ) )
1758 $atts['orderby'] = $defaults['orderby'];
1759 }
1760
1761 // order
1762 if ( strtolower( $atts['order'] ) === 'rand' )
1763 $atts['orderby'] = 'rand';
1764
1765 // gallery lightbox source size
1766 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1767 if ( $atts['lightbox_image_size'] === 'global' )
1768 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1769 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1770 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1771 else
1772 $atts['src_size'] = $atts['lightbox_image_size'];
1773 } else
1774 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1775
1776 // filter all shortcode arguments
1777 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1778
1779 // get gallery images
1780 $images = rl_get_gallery_shortcode_images( $atts );
1781
1782 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1783 return $output;
1784
1785 $gallery_no = $this->gallery_no;
1786
1787 ob_start(); ?>
1788
1789 <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; ?>">
1790
1791 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1792
1793 <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; ?>">
1794
1795 <?php foreach ( $images as $image ) {
1796 echo '<li class="rl-gallery-item">' . $image['link'] . '</li>';
1797 } ?>
1798
1799 </ul>
1800
1801 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1802
1803 </div>
1804
1805 <?php $gallery_html = ob_get_contents();
1806
1807 ob_end_clean();
1808
1809 // scripts
1810 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' ) );
1811 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' ) );
1812
1813 // styles
1814 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'] );
1815
1816 wp_localize_script(
1817 'responsive-lightbox-basicslider-gallery',
1818 'rlArgsBasicSliderGallery' . ( $gallery_no + 1 ),
1819 json_encode(
1820 array(
1821 'adaptive_height' => $atts['adaptive_height'],
1822 'loop' => $atts['loop'],
1823 'captions' => $atts['captions'],
1824 'init_single' => $atts['init_single'],
1825 'responsive' => $atts['responsive'],
1826 'preload' => $atts['preload'],
1827 'pager' => $atts['pager'],
1828 'controls' => $atts['controls'],
1829 'hide_on_end' => $atts['hide_on_end'],
1830 'slide_margin' => $atts['slide_margin'],
1831 'transition' => $atts['transition'],
1832 'kenburns_zoom' => $atts['kenburns_zoom'],
1833 'speed' => $atts['speed'],
1834 'easing' => $atts['easing'],
1835 'continuous' => $atts['continuous'],
1836 'use_css' => $atts['use_css'],
1837 'slideshow' => $atts['slideshow'],
1838 'slideshow_direction' => $atts['slideshow_direction'],
1839 'slideshow_hover' => $atts['slideshow_hover'],
1840 'slideshow_hover_delay' => $atts['slideshow_hover_delay'],
1841 'slideshow_delay' => $atts['slideshow_delay'],
1842 'slideshow_pause' => $atts['slideshow_pause']
1843 )
1844 )
1845 );
1846
1847 // remove any new lines from the output so that the reader parses it better
1848 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1849 }
1850
1851 /**
1852 * Render Basic Masonry gallery shortcode.
1853 *
1854 * @global object $post Post object
1855 * @param mixed $output HTML output
1856 * @param array $shortcode_atts Shortcode attributes
1857 * @return string HTML output
1858 */
1859 public function basic_masonry_gallery_shortcode( $output, $shortcode_atts ) {
1860 if ( ! empty( $output ) )
1861 return $output;
1862
1863 global $post;
1864
1865 $defaults = array(
1866 'rl_gallery_id' => 0,
1867 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1868 'class' => '',
1869 'include' => '',
1870 'exclude' => '',
1871 'urls' => '',
1872 'type' => '',
1873 'order' => 'asc',
1874 'orderby' => 'menu_order',
1875 'size' => 'medium',
1876 'link' => 'file',
1877 'columns' => 3
1878 );
1879
1880 // get main instance
1881 $rl = Responsive_Lightbox();
1882
1883 // is there rl_gallery ID?
1884 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1885
1886 // is it rl gallery?
1887 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1888
1889 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1890 $shortcode_atts['type'] = '';
1891
1892 // break if it is not basic masonry gallery - first check
1893 if ( ! ( $shortcode_atts['type'] === 'basicmasonry' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1894 return $output;
1895
1896 // get shortcode gallery fields combined with defaults
1897 $fields = rl_get_gallery_fields( 'basicmasonry' );
1898
1899 // get gallery fields attributes
1900 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1901
1902 // is it rl gallery? add misc and lightbox fields
1903 if ( $rl_gallery )
1904 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1905
1906 // get only valid arguments
1907 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1908
1909 // sanitize gallery fields
1910 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1911
1912 // break if it is not basic masonry gallery
1913 if ( ! ( $atts['type'] === 'basicmasonry' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1914 return $output;
1915
1916 // ID
1917 $atts['id'] = (int) $atts['id'];
1918
1919 // add custom classes if needed
1920 if ( $rl_gallery )
1921 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1922
1923 // any classes?
1924 if ( $atts['class'] !== '' ) {
1925 $atts['class'] = trim( $atts['class'] );
1926
1927 // more than 1 class?
1928 if ( strpos( $atts['class'], ' ' ) !== false ) {
1929 // get unique valid HTML classes
1930 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1931
1932 if ( ! empty( $atts['class'] ) )
1933 $atts['class'] = implode( ' ', $atts['class'] );
1934 else
1935 $atts['class'] = '';
1936 // single class
1937 } else
1938 $atts['class'] = sanitize_html_class( $atts['class'] );
1939 }
1940
1941 // orderby
1942 if ( empty( $atts['orderby'] ) ) {
1943 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1944
1945 if ( empty( $atts['orderby'] ) )
1946 $atts['orderby'] = $defaults['orderby'];
1947 }
1948
1949 // order
1950 if ( strtolower( $atts['order'] ) === 'rand' )
1951 $atts['orderby'] = 'rand';
1952
1953 // check columns
1954 if ( $atts['columns_lg'] === 0 )
1955 $atts['columns_lg'] = $atts['columns'];
1956
1957 if ( $atts['columns_md'] === 0 )
1958 $atts['columns_md'] = $atts['columns'];
1959
1960 if ( $atts['columns_sm'] === 0 )
1961 $atts['columns_sm'] = $atts['columns'];
1962
1963 if ( $atts['columns_xs'] === 0 )
1964 $atts['columns_xs'] = $atts['columns'];
1965
1966 // gallery lightbox source size
1967 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1968 if ( $atts['lightbox_image_size'] === 'global' )
1969 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1970 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1971 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1972 else
1973 $atts['src_size'] = $atts['lightbox_image_size'];
1974 } else
1975 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1976
1977 // filter all shortcode arguments
1978 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1979
1980 // get gallery images
1981 $images = rl_get_gallery_shortcode_images( $atts );
1982
1983 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1984 return $output;
1985
1986 $gallery_no = $this->gallery_no;
1987
1988 ob_start(); ?>
1989
1990 <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; ?>">
1991
1992 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1993
1994 <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; ?>">
1995
1996 <?php
1997 $count = 0;
1998
1999 if ( $count === 0 )
2000 echo '<div class="rl-gutter-sizer"></div><div class="rl-grid-sizer"></div>';
2001
2002 foreach ( $images as $image ) {
2003 echo '
2004 <div class="rl-gallery-item' . ( $count === 0 ? ' rl-gallery-item-width-4' : '' ) . '" ' . implode( ' ', apply_filters( 'rl_gallery_item_extra_args', array(), $atts, $image ) ) . '>
2005 <div class="rl-gallery-item-content">
2006 ' . $image['link'] . '
2007 </div>
2008 </div>';
2009
2010 $count++;
2011 } ?>
2012
2013 </div>
2014
2015 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
2016
2017 </div>
2018
2019 <?php $gallery_html = ob_get_contents();
2020
2021 ob_clean();
2022
2023 // scripts
2024 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' ) );
2025
2026 // styles
2027 wp_enqueue_style( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'css/gallery-basicmasonry.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
2028
2029 // add inline style
2030 wp_add_inline_style( 'responsive-lightbox-basicmasonry-gallery', '
2031 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery {
2032 margin: ' . -( $atts['margin'] / 2 ) . 'px ' . -( $atts['gutter'] / 2 ) . 'px;
2033 padding: ' . $atts['margin'] . 'px 0;
2034 }
2035 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-bottom {
2036 margin-top: ' . ( $atts['margin'] / 2 ) . 'px
2037 }
2038 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-top {
2039 margin-bottom: ' . ( $atts['margin'] / 2 ) . 'px
2040 }
2041 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2042 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2043 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
2044 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2045 }
2046 @media all and (min-width: 1200px) {
2047 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2048 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2049 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
2050 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2051 }
2052 }
2053 @media all and (min-width: 992px) and (max-width: 1200px) {
2054 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2055 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2056 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
2057 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2058 }
2059 }
2060 @media all and (min-width: 768px) and (max-width: 992px) {
2061 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2062 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2063 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
2064 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2065 }
2066 }
2067 @media all and (max-width: 768px) {
2068 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2069 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2070 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
2071 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2072 }
2073 }'
2074 );
2075
2076 wp_localize_script(
2077 'responsive-lightbox-basicmasonry-gallery',
2078 'rlArgsBasicMasonryGallery' . ( $gallery_no + 1 ),
2079 json_encode(
2080 array(
2081 'originLeft' => $atts['origin_left'],
2082 'originTop' => $atts['origin_top']
2083 )
2084 )
2085 );
2086
2087 // remove any new lines from the output so that the reader parses it better
2088 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
2089 }
2090 }