PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.3.2
Responsive Lightbox & Gallery v2.3.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 5 years ago class-fast-image.php 8 years ago class-folders-walker.php 7 years ago class-folders.php 5 years ago class-frontend.php 5 years ago class-galleries.php 5 years ago class-multilang.php 5 years ago class-remote-library-api.php 5 years ago class-remote-library.php 5 years ago class-settings.php 5 years ago class-tour.php 5 years ago class-welcome.php 5 years ago class-widgets.php 5 years ago functions.php 5 years ago
class-frontend.php
2102 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( $atts[$field_key] ), $field );
635 }
636 // boolean field?
637 } elseif ( $field['type'] === 'boolean' ) {
638 // multiple field?
639 if ( $field['type'] === 'multiple' ) {
640 foreach ( $field['fields'] as $subfield_key => $subfield ) {
641 // valid argument?
642 if ( array_key_exists( $subfield_key, $atts ) ) {
643 // true value?
644 if ( $atts[$subfield_key] === true || $atts[$subfield_key] === 'true' || $atts[$subfield_key] === '1' )
645 $atts[$subfield_key] = 1;
646 // false value?
647 elseif ( $atts[$subfield_key] === false || $atts[$subfield_key] === 'false' || $atts[$subfield_key] === '0' || $atts[$subfield_key] === '' )
648 $atts[$subfield_key] = 0;
649 // default value
650 else
651 $atts[$subfield_key] = (int) $field['default'];
652 }
653 }
654 } else {
655 // valid argument?
656 if ( array_key_exists( $field_key, $atts ) ) {
657 // true value?
658 if ( $atts[$field_key] === true || $atts[$field_key] === 'true' || $atts[$field_key] === '1' )
659 $atts[$field_key] = 1;
660 // false value?
661 elseif ( $atts[$field_key] === false || $atts[$field_key] === 'false' || $atts[$field_key] === '0' || $atts[$field_key] === '' )
662 $atts[$field_key] = 0;
663 // default value
664 else
665 $atts[$field_key] = (int) $field['default'];
666 }
667 }
668 // multiple field?
669 } elseif ( $field['type'] === 'multiple' ) {
670 foreach ( $field['fields'] as $subfield_key => $subfield ) {
671 // valid argument?
672 if ( array_key_exists( $subfield_key, $atts ) )
673 $atts[$subfield_key] = $rl->galleries->sanitize_field( $subfield_key, $atts[$subfield_key], $subfield );
674 }
675 // other field?
676 } else {
677 // valid argument?
678 if ( array_key_exists( $field_key, $atts ) )
679 $atts[$field_key] = $rl->galleries->sanitize_field( $field_key, $atts[$field_key], $field );
680 }
681 }
682
683 return apply_filters( 'rl_sanitize_shortcode_args', $atts );
684 }
685
686 /**
687 * Get gallery images.
688 *
689 * @param array $args Gallery arguments
690 * @return array Gallery images
691 */
692 public function get_gallery_shortcode_images( $shortcode_atts ) {
693 if ( ! isset( $shortcode_atts['show_title'] ) || $shortcode_atts['show_title'] === 'global' )
694 $shortcode_atts['show_title'] = Responsive_Lightbox()->options['settings']['gallery_image_title'];
695
696 if ( ! isset( $shortcode_atts['show_caption'] ) || $shortcode_atts['show_caption'] === 'global' )
697 $shortcode_atts['show_caption'] = Responsive_Lightbox()->options['settings']['gallery_image_caption'];
698
699 $images = array();
700
701 // get gallery id
702 $gallery_id = ! empty( $shortcode_atts['rl_gallery_id'] ) ? absint( $shortcode_atts['rl_gallery_id'] ) : 0;
703
704 // get images from gallery
705 if ( $gallery_id ) {
706 $images = Responsive_Lightbox()->galleries->get_gallery_images(
707 $gallery_id,
708 array(
709 'exclude' => true,
710 'image_size' => $shortcode_atts['src_size'],
711 'thumbnail_size' => $shortcode_atts['size']
712 )
713 );
714 // get images from shortcode atts
715 } else {
716 $ids = array();
717
718 if ( ! empty( $shortcode_atts['include'] ) ) {
719 // filter attachment IDs
720 $include = array_unique( array_filter( array_map( 'intval', explode( ',', $shortcode_atts['include'] ) ) ) );
721
722 // any attachments?
723 if ( ! empty( $include ) ) {
724 // get attachments
725 $ids = get_posts(
726 array(
727 'include' => implode( ',', $include ),
728 'post_status' => 'inherit',
729 'post_type' => 'attachment',
730 'post_mime_type' => 'image',
731 'order' => $shortcode_atts['order'],
732 'orderby' => ( $shortcode_atts['orderby'] === 'menu_order' || $shortcode_atts['orderby'] === '' ? 'post__in' : $shortcode_atts['orderby'] ),
733 'fields' => 'ids'
734 )
735 );
736 }
737 } elseif ( ! empty( $exclude ) ) {
738 // filter attachment IDs
739 $exclude = array_unique( array_filter( array_map( 'intval', explode( ',', $shortcode_atts['exclude'] ) ) ) );
740
741 // any attachments?
742 if ( ! empty( $exclude ) ) {
743 // get attachments
744 $ids = get_children(
745 array(
746 'post_parent' => $shortcode_atts['id'],
747 'exclude' => $exclude,
748 'post_status' => 'inherit',
749 'post_type' => 'attachment',
750 'post_mime_type' => 'image',
751 'order' => $shortcode_atts['order'],
752 'orderby' => $shortcode_atts['orderby'],
753 'fields' => 'ids'
754 )
755 );
756 }
757 } else {
758 // get attachments
759 $ids = get_children(
760 array(
761 'post_parent' => $shortcode_atts['id'],
762 'post_status' => 'inherit',
763 'post_type' => 'attachment',
764 'post_mime_type' => 'image',
765 'order' => $shortcode_atts['order'],
766 'orderby' => $shortcode_atts['orderby'],
767 'fields' => 'ids'
768 )
769 );
770 }
771
772 // any attachments?
773 if ( ! empty( $ids ) ) {
774 foreach ( $ids as $attachment_id ) {
775 // get thumbnail image data
776 $images[] = Responsive_Lightbox()->galleries->get_gallery_image_src( $attachment_id, $shortcode_atts['src_size'], $shortcode_atts['size'] );
777 }
778 }
779 }
780
781 // apply adjustments, as per settings
782 if ( $images ) {
783 // get current script
784 $script = Responsive_Lightbox()->options['settings']['script'];
785
786 // prepare arguments
787 $args = array(
788 'selector' => Responsive_Lightbox()->options['settings']['selector'],
789 'script' => $script,
790 'settings' => array(
791 'script' => Responsive_Lightbox()->options['configuration'][$script],
792 'plugin' => Responsive_Lightbox()->options['settings']
793 ),
794 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports'],
795 'image_id' => 0,
796 'caption' => '',
797 'title' => '',
798 'src' => array()
799 );
800
801 // lightbox image title
802 $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'];
803
804 // lightbox image caption
805 $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'];
806
807 // get gallery image link
808 $args['link'] = isset( $shortcode_atts['link'] ) ? $shortcode_atts['link'] : '';
809
810 // copy images
811 $images_tmp = $images;
812
813 // apply adjustments, according to gallery settings
814 foreach ( $images_tmp as $index => $image ) {
815 // assign image
816 $new_image = $images[$index] = array_merge( $image, Responsive_Lightbox()->galleries->get_gallery_image_src( $image, $shortcode_atts['src_size'], $shortcode_atts['size'] ) );
817
818 // create image source data
819 $args['src'] = array( $new_image['url'], $new_image['width'], $new_image['height'] );
820
821 // set alt text
822 $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 ) : '' );
823
824 // set lightbox image title
825 if ( $args['settings']['plugin']['gallery_image_title'] === 'default' )
826 $images[$index]['title'] = $args['title'] = '';
827 else
828 $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'];
829
830 // set lightbox image caption
831 if ( $args['settings']['plugin']['gallery_image_caption'] === 'default' )
832 $images[$index]['caption'] = $args['caption'] = '';
833 else
834 $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'];
835
836 // set image gallery link
837 $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 );
838
839 // is lightbox active?
840 if ( isset( $shortcode_atts['lightbox_enable'] ) && $shortcode_atts['lightbox_enable'] === 0 )
841 $images[$index]['link'] = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/', 'data-rel="norl"', $images[$index]['link'] );
842 }
843 }
844
845 return apply_filters( 'rl_get_gallery_shortcode_images', $images, $gallery_id, $shortcode_atts );
846 }
847
848 /**
849 * Get gallery image link.
850 *
851 * @param int $attachment_id Attachment ID
852 * @param array $image Source image data
853 * @param array $thumbnail Thumbnail image data
854 * @param array $args Arguments
855 * @return string Generated gallery image link
856 */
857 function get_gallery_image_link( $attachment_id, $image, $thumbnail, $args ) {
858 switch ( $args['link'] ) {
859 case 'post':
860 $link = '<a href="' . get_permalink( $attachment_id ) . '"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
861 break;
862
863 case 'none':
864 $link = '<a href="javascript:void(0)" style="cursor: default;"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
865 break;
866
867 default:
868 case 'file':
869 $link = '<a href="' . $image[0] . '"><img src="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />';
870 }
871
872 $title = ! empty( $args['show_title'] ) ? trim( $this->get_attachment_title( $attachment_id, $args['show_title'] ) ) : '';
873 $caption = ! empty( $args['show_caption'] ) ? trim( $this->get_attachment_title( $attachment_id, $args['show_caption'] ) ) : '';
874
875 if ( $title || $caption ) {
876 $link .= '<span class="rl-gallery-caption">';
877
878 if ( $title )
879 $link .= '<span class="rl-gallery-item-title">' . esc_html( $title ) . '</span>';
880
881 if ( $caption )
882 $link .= '<span class="rl-gallery-item-caption">' . esc_html( $caption ) . '</span>';
883
884 $link .= '</span>';
885 }
886
887 $link .= '</a>';
888
889 return apply_filters( 'rl_gallery_image_link', $link, $attachment_id, $image, $thumbnail, $args );
890 }
891
892 /**
893 * Add lightbox to Jetpack tiled gallery.
894 *
895 * @param string $content
896 * @return string
897 */
898 public function force_custom_gallery_lightbox( $content ) {
899 if ( Responsive_Lightbox()->options['settings']['force_custom_gallery'] ) {
900 // search for image links
901 preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?)\.(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $content, $links );
902
903 // found any links?
904 if ( ! empty ( $links[0] ) ) {
905 foreach ( $links[0] as $link_number => $link ) {
906 // get attachment id
907 $image_id = $this->get_attachment_id_by_url( $links[2][$link_number] . '.' . $links[3][$link_number] );
908
909 // get title type
910 $title_arg = Responsive_Lightbox()->options['settings']['gallery_image_title'];
911
912 // update title if needed
913 if ( $title_arg !== 'default' && $image_id )
914 $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 ) );
915 else
916 $title = '';
917
918 // get caption type
919 $caption_arg = Responsive_Lightbox()->options['settings']['gallery_image_caption'];
920
921 // update caption if needed
922 if ( $caption_arg !== 'default' )
923 $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 ) );
924 else
925 $caption = '';
926
927 // link already contains data-rel attribute?
928 if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
929 // do not modify this link
930 if ( $result[1] === 'norl' )
931 continue;
932
933 $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 );
934 } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
935 // do not modify this link
936 if ( $result[1] === 'norl' )
937 continue;
938
939 $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 );
940 } else
941 $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 );
942 }
943 }
944 }
945
946 return $content;
947 }
948
949 /**
950 * Remove WooCommerce prettyPhoto lightbox styles and scripts.
951 */
952 public function wp_enqueue_scripts() {
953 if ( class_exists( 'WooCommerce' ) ) {
954 global $woocommerce;
955
956 // specific WooCommerce gallery?
957 if ( ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
958 // replace default WooCommerce lightbox?
959 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
960 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
961 // dequeue scripts
962 wp_dequeue_script( 'flexslider' );
963 wp_dequeue_script( 'photoswipe' );
964 wp_dequeue_script( 'photoswipe-ui-default' );
965
966 // dequeue styles
967 wp_dequeue_style( 'photoswipe' );
968 wp_dequeue_style( 'photoswipe-default-skin' );
969
970 // remove theme supports
971 remove_theme_support( 'wc-product-gallery-lightbox' );
972 // remove_theme_support( 'wc-product-gallery-zoom' );
973 remove_theme_support( 'wc-product-gallery-slider' );
974 } else {
975 // remove styles
976 wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
977
978 // remove scripts
979 wp_dequeue_script( 'prettyPhoto' );
980 wp_dequeue_script( 'prettyPhoto-init' );
981 wp_dequeue_script( 'fancybox' );
982 wp_dequeue_script( 'enable-lightbox' );
983 }
984 } else {
985 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
986 // dequeue scripts
987 wp_dequeue_script( 'flexslider' );
988 }
989 }
990 // default gallery?
991 } else {
992 // replace default WooCommerce lightbox?
993 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
994 if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
995 // dequeue scripts
996 wp_dequeue_script( 'photoswipe' );
997 wp_dequeue_script( 'photoswipe-ui-default' );
998
999 // dequeue styles
1000 wp_dequeue_style( 'photoswipe' );
1001 wp_dequeue_style( 'photoswipe-default-skin' );
1002
1003 // remove theme supports
1004 remove_theme_support( 'wc-product-gallery-lightbox' );
1005 } else {
1006 // remove styles
1007 wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
1008
1009 // remove scripts
1010 wp_dequeue_script( 'prettyPhoto' );
1011 wp_dequeue_script( 'prettyPhoto-init' );
1012 wp_dequeue_script( 'fancybox' );
1013 wp_dequeue_script( 'enable-lightbox' );
1014 }
1015 }
1016 }
1017 }
1018
1019 // Visual Composer lightbox
1020 if ( class_exists( 'Vc_Manager' ) ) {
1021 wp_dequeue_script( 'prettyphoto' );
1022 wp_deregister_script( 'prettyphoto' );
1023 wp_dequeue_style( 'prettyphoto' );
1024 wp_deregister_style( 'prettyphoto' );
1025 }
1026 }
1027
1028 /**
1029 * Apply lightbox to WooCommerce product image.
1030 *
1031 * @param mixed $html
1032 * @return mixed
1033 */
1034 public function woocommerce_single_product_image_html( $html ) {
1035 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] )
1036 $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '"', $html );
1037
1038 return $html;
1039 }
1040
1041 /**
1042 * Apply lightbox to WooCommerce product gallery.
1043 *
1044 * @param mixed $html
1045 * @return mixed
1046 */
1047 public function woocommerce_single_product_image_thumbnail_html( $html ) {
1048 if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] ) {
1049 // make sure main product image has same gallery number
1050 $gallery_no = $this->gallery_no + 1;
1051
1052 $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '"', $html );
1053
1054 preg_match( '/<a(.*?)((?:data-rel)=(?:\'|").*?(?:\'|"))(.*?)>/i', $html, $result );
1055
1056 // no data-rel?
1057 if ( empty( $result ) ) {
1058 preg_match( '/^(.*?)<a(.*?)((?:href)=(?:\'|").*?(?:\'|"))(.*?)>(.*?)$/i', $html, $result );
1059
1060 // found valid link?
1061 if ( ! empty( $result ) )
1062 $html = $result[1] . '<a' . $result[2] . ' data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1063 }
1064 }
1065
1066 return $html;
1067 }
1068
1069 /**
1070 * WooCommerce gallery init.
1071 */
1072 public function woocommerce_gallery_init() {
1073 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' ) {
1074 // remove default gallery
1075 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', $priority );
1076
1077 // handle product gallery
1078 add_action( 'woocommerce_product_thumbnails', array( $this, 'woocommerce_gallery' ), $priority );
1079 }
1080 }
1081
1082 /**
1083 * WooCommerce gallery support.
1084 *
1085 * @global object $product
1086 * @return mixed
1087 */
1088 public function woocommerce_gallery() {
1089 global $product;
1090
1091 $attachment_ids = array();
1092
1093 // WooCommerce 3.x
1094 if ( method_exists( $product, 'get_gallery_image_ids' ) )
1095 $attachment_ids = $product->get_gallery_image_ids();
1096 // WooCommerce 2.x
1097 elseif ( method_exists( $product, 'get_gallery_attachment_ids' ) )
1098 $attachment_ids = $product->get_gallery_attachment_ids();
1099
1100 if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) )
1101 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 ) . '"]' );
1102 }
1103
1104 /**
1105 * Get attachment title function
1106 *
1107 * @param int $id
1108 * @param string $title_arg
1109 * @return string
1110 */
1111 public function get_attachment_title( $id, $title_arg ) {
1112 if ( empty( $title_arg ) || empty( $id ) )
1113 return false;
1114
1115 switch( $title_arg ) {
1116 case 'title':
1117 $title = get_the_title( $id );
1118 break;
1119
1120 case 'caption':
1121 $title = get_post_field( 'post_excerpt', $id ) ;
1122 break;
1123
1124 case 'alt':
1125 $title = get_post_meta( $id, '_wp_attachment_image_alt', true );
1126 break;
1127
1128 case 'description':
1129 $title = get_post_field( 'post_content', $id ) ;
1130 break;
1131
1132 default:
1133 $title = '';
1134 }
1135
1136 return apply_filters( 'rl_get_attachment_title', $title, $id, $title_arg );
1137 }
1138
1139 /**
1140 * Get attachment id by url function, adjusted to work for cropped images
1141 *
1142 * @param string $url
1143 * @return int
1144 */
1145 public function get_attachment_id_by_url( $url ) {
1146 $url = ! empty( $url ) ? esc_url( $url ) : '';
1147
1148 // get cached data
1149 // $post_id = wp_cache_get( md5( $url ), 'rl-attachment_id_by_url' );
1150 $post_ids = get_transient( 'rl-attachment_ids_by_url' );
1151 $post_id = 0;
1152
1153 // cached url not found?
1154 if ( $post_ids === false || ! in_array( $url, array_keys( $post_ids ) ) ) {
1155 $post_id = attachment_url_to_postid( $url );
1156
1157 if ( ! $post_id ) {
1158 $dir = wp_upload_dir();
1159 $path = $url;
1160
1161 if ( strpos( $path, $dir['baseurl'] . '/' ) === 0 )
1162 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
1163
1164 if ( preg_match( '/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches ) )
1165 $post_id = attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . $matches[3] );
1166 }
1167
1168 // set the cache expiration, 24 hours by default
1169 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1170
1171 // wp_cache_add( md5( $url ), $post_id, 'rl-attachment_id_by_url', $expire );
1172
1173 $post_ids[$url] = $post_id;
1174
1175 set_transient( 'rl-attachment_ids_by_url', $post_ids, $expire );
1176 // cached url found
1177 } elseif ( ! empty( $post_ids[$url] ) )
1178 $post_id = absint( $post_ids[$url] );
1179
1180 return (int) apply_filters( 'rl_get_attachment_id_by_url', $post_id, $url );
1181 }
1182
1183 /**
1184 * Get image size by URL.
1185 *
1186 * @param string $url Image URL
1187 * @return array
1188 */
1189 public function get_image_size_by_url( $url ) {
1190 $url = ! empty( $url ) ? esc_url( $url ) : '';
1191 $size = array( 0, 0 );
1192
1193 if ( ! empty( $url ) ) {
1194 // get cached data
1195 $image_sizes = get_transient( 'rl-image_sizes_by_url' );
1196
1197 // cached url not found?
1198 if ( $image_sizes === false || ! in_array( $url, array_keys( $image_sizes ) ) || empty( $image_sizes[$url] ) ) {
1199 if ( class_exists( 'Responsive_Lightbox_Fast_Image' ) ) {
1200 // loading image
1201 $image = new Responsive_Lightbox_Fast_Image( $url );
1202
1203 // get size
1204 $size = $image->get_size();
1205 } else {
1206 // get size using php
1207 $size = getimagesize( $url );
1208 }
1209
1210 // set the cache expiration, 24 hours by default
1211 $expire = absint( apply_filters( 'rl_object_cache_expire', DAY_IN_SECONDS ) );
1212
1213 $image_sizes[$url] = $size;
1214
1215 set_transient( 'rl-image_sizes_by_url', $image_sizes, $expire );
1216 // cached url found
1217 } elseif ( ! empty( $image_sizes[$url] ) )
1218 $size = array_map( 'absint', $image_sizes[$url] );
1219 }
1220
1221 return apply_filters( 'rl_get_image_size_by_url', $size, $url );
1222 }
1223
1224 /**
1225 * Add gallery shortcode to gallery post content.
1226 *
1227 * @param string $content
1228 * @return string Updated content
1229 */
1230 public function gallery_preview( $content ) {
1231 if ( get_post_type() === 'rl_gallery' && ! ( is_archive() && is_main_query() ) )
1232 $content .= do_shortcode( '[rl_gallery id="' . get_the_ID() . '"]' );
1233
1234 return $content;
1235 }
1236
1237 /**
1238 * Helper: gallery number function
1239 *
1240 * @param mixed $content
1241 * @return mixed
1242 */
1243 public function gallery_attributes( $content, $shortcode_atts ) {
1244 ++$this->gallery_no;
1245
1246 // add inline style, to our galleries only
1247 if ( isset( $shortcode_atts['type'] ) ) {
1248 // gallery style
1249 wp_enqueue_style( 'responsive-lightbox-gallery' );
1250
1251 // is there rl_gallery ID?
1252 $rl_gallery_id = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1253
1254 // is it rl gallery?
1255 $rl_gallery = Responsive_Lightbox()->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1256
1257 // is it rl gallery? add design options
1258 if ( $rl_gallery ) {
1259 $fields = Responsive_Lightbox()->galleries->fields['design']['options'];
1260
1261 // get gallery fields attributes
1262 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1263
1264 // get only valid arguments
1265 $atts = shortcode_atts( $field_atts, array_merge( $field_atts, $shortcode_atts ), 'gallery' );
1266
1267 // sanitize gallery fields
1268 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1269
1270 // add inline style
1271 $inline_css = '
1272 .rl-gallery .rl-gallery-link {
1273 border: ' . $atts['border_width'] . 'px solid ' . $atts['border_color'] . ';
1274 }
1275 .rl-gallery .rl-gallery-link .rl-gallery-item-title {
1276 color: ' . $atts['title_color'] . ';
1277 }
1278 .rl-gallery .rl-gallery-link .rl-gallery-item-caption {
1279 color: ' . $atts['caption_color'] . ';
1280 }
1281 .rl-gallery .rl-gallery-link .rl-gallery-caption,
1282 .rl-gallery .rl-gallery-link:after {
1283 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1284 }
1285 [class^="rl-hover-icon-"] .rl-gallery-link:before,
1286 [class*=" rl-hover-icon-"] .rl-gallery-link:before {
1287 color: ' . $atts['title_color'] . ';
1288 background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1289 }
1290 ';
1291
1292 wp_add_inline_style( 'responsive-lightbox-gallery', $inline_css );
1293 }
1294 }
1295
1296 return $content;
1297 }
1298
1299 /**
1300 * Generate unique hash.
1301 *
1302 * @param int $length
1303 * @return string
1304 */
1305 private function generate_hash( $length = 8 ) {
1306 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
1307 $hash = '';
1308
1309 for( $i = 0; $i < $length; $i++ ) {
1310 $hash .= substr( $chars, mt_rand( 0, strlen( $chars ) - 1 ), 1 );
1311 }
1312
1313 return $hash;
1314 }
1315
1316 /**
1317 * Replace widget callback function.
1318 *
1319 * @global array $wp_registered_widgets
1320 * @param array $sidebar_params
1321 * @return type
1322 */
1323 public function dynamic_sidebar_params( $sidebar_params ) {
1324 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['widgets'] != true )
1325 return $sidebar_params;
1326
1327 global $wp_registered_widgets;
1328
1329 $widget_id = $sidebar_params[0]['widget_id'];
1330 $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
1331 $wp_registered_widgets[ $widget_id ]['callback'] = array( $this, 'widget_callback_function' );
1332
1333 return $sidebar_params;
1334 }
1335
1336 /**
1337 * Widget callback function.
1338 *
1339 * @global array $wp_registered_widgets
1340 */
1341 public function widget_callback_function() {
1342 global $wp_registered_widgets;
1343
1344 $original_callback_params = func_get_args();
1345 $widget_id = $original_callback_params[0]['widget_id'];
1346 $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
1347 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
1348 $widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
1349
1350 if ( is_callable( $original_callback ) ) {
1351 ob_start();
1352
1353 call_user_func_array( $original_callback, $original_callback_params );
1354
1355 $widget_output = ob_get_clean();
1356
1357 echo apply_filters( 'rl_widget_output', $widget_output, $widget_id_base, $widget_id );
1358 }
1359 }
1360
1361 /**
1362 * Filter widget output.
1363 *
1364 * @param mixed $widget_output
1365 * @param string $widget_id_base
1366 * @param id $widget_id
1367 * @return mixed
1368 */
1369 public function widget_output( $content, $widget_id_base, $widget_id ) {
1370 return $this->add_lightbox( $content );
1371 }
1372
1373 /**
1374 * Filter comment content.
1375 *
1376 * @param mixed $comment_content
1377 * @return mixed
1378 */
1379 public function get_comment_text( $content ) {
1380 if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['comments'] != true )
1381 return $content;
1382
1383 return $this->add_lightbox( $content );
1384 }
1385
1386 /**
1387 * Modify gallery container class.
1388 *
1389 * @param string $class
1390 * @param array $args
1391 * @param int $gallery_id
1392 * @return void
1393 */
1394 public function gallery_container_class( $class, $args, $gallery_id ) {
1395 if ( $gallery_id ) {
1396 $class .= ' rl-loading';
1397
1398 if ( $args['pagination'] )
1399 $class .= ' rl-pagination-' . $args['pagination_type'];
1400 }
1401
1402 return $class;
1403 }
1404
1405 /**
1406 * Display content before the gallery.
1407 *
1408 * @param array $args
1409 * @param int $gallery_id
1410 * @return void
1411 */
1412 public function before_gallery( $args, $gallery_id ) {
1413 // if ( $gallery_id && ! ( isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-gallery-page-content' ) ) {
1414 if ( $gallery_id ) {
1415 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'top' && get_post_type() !== 'rl_gallery' )
1416 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1417
1418 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'top' )
1419 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1420 }
1421 }
1422
1423 /**
1424 * Display content after the gallery.
1425 *
1426 * @param array $args
1427 * @param int $gallery_id
1428 * @return void
1429 */
1430 public function after_gallery( $args, $gallery_id ) {
1431 if ( $gallery_id ) {
1432 if ( isset( $args['gallery_title_position'] ) && $args['gallery_title_position'] === 'bottom' && get_post_type() !== 'rl_gallery' )
1433 echo '<div class="rl-gallery-title">' . esc_html( get_the_title( $gallery_id ) ) . '</div>';
1434
1435 if ( isset( $args['gallery_description_position'] ) && $args['gallery_description_position'] === 'bottom' )
1436 echo '<div class="rl-gallery-description">' . nl2br( esc_html( $args['gallery_description'] ) ) . '</div>';
1437 }
1438 }
1439
1440 /**
1441 * Add lightbox to Visual Composer shortcodes.
1442 *
1443 * @param string $content HTML content
1444 * @param string $shortcode Shortcode type
1445 * @return string Changed HTML content
1446 */
1447 public function vc_shortcode_content_filter_after( $content, $shortcode ) {
1448 if ( in_array( $shortcode, apply_filters( 'rl_lightbox_vc_allowed_shortcode', array( 'vc_gallery', 'vc_single_image', 'vc_images_carousel' ) ), true ) )
1449 $content = $this->add_lightbox( $content );
1450
1451 return $content;
1452 }
1453
1454 /**
1455 * Render Basic Grid gallery shortcode.
1456 *
1457 * @global object $post Post object
1458 * @param mixed $output HTML output
1459 * @param array $shortcode_atts Shortcode attributes
1460 * @return string HTML output
1461 */
1462 public function basic_grid_gallery_shortcode( $output, $shortcode_atts ) {
1463 if ( ! empty( $output ) )
1464 return $output;
1465
1466 global $post;
1467
1468 $defaults = array(
1469 'rl_gallery_id' => 0,
1470 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1471 'class' => '',
1472 'include' => '',
1473 'exclude' => '',
1474 'urls' => '',
1475 'type' => '',
1476 'order' => 'asc',
1477 'orderby' => 'menu_order',
1478 'size' => 'medium',
1479 'link' => 'file',
1480 'columns' => 3
1481 );
1482
1483 // get main instance
1484 $rl = Responsive_Lightbox();
1485
1486 if ( ! is_array( $shortcode_atts ) )
1487 $shortcode_atts = wp_parse_args( $shortcode_atts, $defaults );
1488
1489 // is there rl_gallery ID?
1490 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1491
1492 // is it rl gallery?
1493 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1494
1495 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1496 $shortcode_atts['type'] = '';
1497
1498 // break if it is not basic grid gallery - first check
1499 if ( ! ( $shortcode_atts['type'] === 'basicgrid' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1500 return $output;
1501
1502 // get shortcode gallery fields combined with defaults
1503 $fields = rl_get_gallery_fields( 'basicgrid' );
1504
1505 // get gallery fields attributes
1506 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1507
1508 // is it rl gallery? add misc and lightbox fields
1509 if ( $rl_gallery )
1510 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1511
1512 // get only valid arguments
1513 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1514
1515 // sanitize gallery fields
1516 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1517
1518 // break if it is not basic grid gallery
1519 if ( ! ( $atts['type'] === 'basicgrid' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicgrid' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicgrid' ) ) ) ) )
1520 return $output;
1521
1522 // ID
1523 $atts['id'] = (int) $atts['id'];
1524
1525 // add custom classes if needed
1526 if ( $rl_gallery )
1527 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1528
1529 // any classes?
1530 if ( $atts['class'] !== '' ) {
1531 $atts['class'] = trim( $atts['class'] );
1532
1533 // more than 1 class?
1534 if ( strpos( $atts['class'], ' ' ) !== false ) {
1535 // get unique valid HTML classes
1536 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1537
1538 if ( ! empty( $atts['class'] ) )
1539 $atts['class'] = implode( ' ', $atts['class'] );
1540 else
1541 $atts['class'] = '';
1542 // single class
1543 } else
1544 $atts['class'] = sanitize_html_class( $atts['class'] );
1545 }
1546
1547 // orderby
1548 if ( empty( $atts['orderby'] ) ) {
1549 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1550
1551 if ( empty( $atts['orderby'] ) )
1552 $atts['orderby'] = $defaults['orderby'];
1553 }
1554
1555 // order
1556 if ( strtolower( $atts['order'] ) === 'rand' )
1557 $atts['orderby'] = 'rand';
1558
1559 // check columns
1560 if ( $atts['columns_lg'] === 0 )
1561 $atts['columns_lg'] = $atts['columns'];
1562
1563 if ( $atts['columns_md'] === 0 )
1564 $atts['columns_md'] = $atts['columns'];
1565
1566 if ( $atts['columns_sm'] === 0 )
1567 $atts['columns_sm'] = $atts['columns'];
1568
1569 if ( $atts['columns_xs'] === 0 )
1570 $atts['columns_xs'] = $atts['columns'];
1571
1572 // gallery lightbox source size
1573 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1574 if ( $atts['lightbox_image_size'] === 'global' )
1575 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1576 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1577 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1578 else
1579 $atts['src_size'] = $atts['lightbox_image_size'];
1580 } else
1581 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1582
1583 // filter all shortcode arguments
1584 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1585
1586 // get gallery images
1587 $images = rl_get_gallery_shortcode_images( $atts );
1588
1589 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1590 return $output;
1591
1592 $gallery_no = $this->gallery_no;
1593
1594 ob_start(); ?>
1595
1596 <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; ?>">
1597
1598 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1599
1600 <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; ?>">
1601
1602 <?php foreach ( $images as $image ) {
1603 echo '<div class="rl-gallery-item">' . $image['link'] . '</div>';
1604 } ?>
1605
1606 </div>
1607
1608 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1609
1610 </div>
1611
1612 <?php $gallery_html = ob_get_contents();
1613
1614 ob_end_clean();
1615
1616 // styles
1617 wp_enqueue_style( 'responsive-lightbox-basicgrid-gallery', plugins_url( 'css/gallery-basicgrid.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
1618
1619 // add inline style
1620 $inline_css = '
1621 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery {
1622 padding: ' . ( -$atts['gutter'] ) . 'px;
1623 }
1624 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1625 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
1626 margin: ' . ( $atts['gutter'] / 2 ) . 'px;
1627 }
1628 @media all and (min-width: 1200px) {
1629 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1630 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
1631 }
1632 }
1633 @media all and (min-width: 992px) and (max-width: 1200px) {
1634 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1635 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
1636 }
1637 }
1638 @media all and (min-width: 768px) and (max-width: 992px) {
1639 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1640 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
1641 }
1642 }
1643 @media all and (max-width: 768px) {
1644 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1645 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
1646 }
1647 }
1648 ';
1649
1650 if ( $atts['force_height'] ) {
1651 $inline_css .= '
1652 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1653 height: ' . ( $atts['row_height'] ) . 'px;
1654 }
1655 #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item img {
1656 height: ' . ( $atts['row_height'] ) . 'px;
1657 object-fit: cover;
1658 max-width: 100%;
1659 min-width: 100%;
1660 }';
1661 }
1662
1663 wp_add_inline_style( 'responsive-lightbox-basicgrid-gallery', $inline_css );
1664
1665 // remove any new lines from the output so that the reader parses it better
1666 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1667 }
1668
1669 /**
1670 * Render Basic Slider gallery shortcode.
1671 *
1672 * @global object $post Post object
1673 * @param mixed $output HTML output
1674 * @param array $shortcode_atts Shortcode attributes
1675 * @return string HTML output
1676 */
1677 public function basic_slider_gallery_shortcode( $output, $shortcode_atts ) {
1678 if ( ! empty( $output ) )
1679 return $output;
1680
1681 global $post;
1682
1683 $defaults = array(
1684 'rl_gallery_id' => 0,
1685 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1686 'class' => '',
1687 'include' => '',
1688 'exclude' => '',
1689 'urls' => '',
1690 'type' => '',
1691 'order' => 'asc',
1692 'orderby' => 'menu_order',
1693 'size' => 'medium',
1694 'link' => 'file',
1695 'columns' => 3
1696 );
1697
1698 // get main instance
1699 $rl = Responsive_Lightbox();
1700
1701 if ( ! is_array( $shortcode_atts ) )
1702 $shortcode_atts = wp_parse_args( $shortcode_atts, $defaults );
1703
1704 // is there rl_gallery ID?
1705 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1706
1707 // is it rl gallery?
1708 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1709
1710 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1711 $shortcode_atts['type'] = '';
1712
1713 // break if it is not basic slider gallery - first check
1714 if ( ! ( $shortcode_atts['type'] === 'basicslider' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1715 return $output;
1716
1717 // get shortcode gallery fields combined with defaults
1718 $fields = rl_get_gallery_fields( 'basicslider' );
1719
1720 // get gallery fields attributes
1721 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1722
1723 // is it rl gallery? add misc and lightbox fields
1724 if ( $rl_gallery )
1725 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1726
1727 // get only valid arguments
1728 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1729
1730 // sanitize gallery fields
1731 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1732
1733 // break if it is not basic slider gallery
1734 if ( ! ( $atts['type'] === 'basicslider' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicslider' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicslider' ) ) ) ) )
1735 return $output;
1736
1737 // ID
1738 $atts['id'] = (int) $atts['id'];
1739
1740 // add custom classes if needed
1741 if ( $rl_gallery )
1742 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1743
1744 // any classes?
1745 if ( $atts['class'] !== '' ) {
1746 $atts['class'] = trim( $atts['class'] );
1747
1748 // more than 1 class?
1749 if ( strpos( $atts['class'], ' ' ) !== false ) {
1750 // get unique valid HTML classes
1751 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1752
1753 if ( ! empty( $atts['class'] ) )
1754 $atts['class'] = implode( ' ', $atts['class'] );
1755 else
1756 $atts['class'] = '';
1757 // single class
1758 } else
1759 $atts['class'] = sanitize_html_class( $atts['class'] );
1760 }
1761
1762 // orderby
1763 if ( empty( $atts['orderby'] ) ) {
1764 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1765
1766 if ( empty( $atts['orderby'] ) )
1767 $atts['orderby'] = $defaults['orderby'];
1768 }
1769
1770 // order
1771 if ( strtolower( $atts['order'] ) === 'rand' )
1772 $atts['orderby'] = 'rand';
1773
1774 // gallery lightbox source size
1775 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1776 if ( $atts['lightbox_image_size'] === 'global' )
1777 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1778 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1779 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1780 else
1781 $atts['src_size'] = $atts['lightbox_image_size'];
1782 } else
1783 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1784
1785 // filter all shortcode arguments
1786 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1787
1788 // get gallery images
1789 $images = rl_get_gallery_shortcode_images( $atts );
1790
1791 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1792 return $output;
1793
1794 $gallery_no = $this->gallery_no;
1795
1796 ob_start(); ?>
1797
1798 <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; ?>">
1799
1800 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1801
1802 <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; ?>">
1803
1804 <?php foreach ( $images as $image ) {
1805 echo '<li class="rl-gallery-item">' . $image['link'] . '</li>';
1806 } ?>
1807
1808 </ul>
1809
1810 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
1811
1812 </div>
1813
1814 <?php $gallery_html = ob_get_contents();
1815
1816 ob_end_clean();
1817
1818 // scripts
1819 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' ) );
1820 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' ) );
1821
1822 // styles
1823 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'] );
1824
1825 wp_localize_script(
1826 'responsive-lightbox-basicslider-gallery',
1827 'rlArgsBasicSliderGallery' . ( $gallery_no + 1 ),
1828 json_encode(
1829 array(
1830 'adaptive_height' => $atts['adaptive_height'],
1831 'loop' => $atts['loop'],
1832 'captions' => $atts['captions'],
1833 'init_single' => $atts['init_single'],
1834 'responsive' => $atts['responsive'],
1835 'preload' => $atts['preload'],
1836 'pager' => $atts['pager'],
1837 'controls' => $atts['controls'],
1838 'hide_on_end' => $atts['hide_on_end'],
1839 'slide_margin' => $atts['slide_margin'],
1840 'transition' => $atts['transition'],
1841 'kenburns_zoom' => $atts['kenburns_zoom'],
1842 'speed' => $atts['speed'],
1843 'easing' => $atts['easing'],
1844 'continuous' => $atts['continuous'],
1845 'use_css' => $atts['use_css'],
1846 'slideshow' => $atts['slideshow'],
1847 'slideshow_direction' => $atts['slideshow_direction'],
1848 'slideshow_hover' => $atts['slideshow_hover'],
1849 'slideshow_hover_delay' => $atts['slideshow_hover_delay'],
1850 'slideshow_delay' => $atts['slideshow_delay'],
1851 'slideshow_pause' => $atts['slideshow_pause']
1852 )
1853 )
1854 );
1855
1856 // remove any new lines from the output so that the reader parses it better
1857 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1858 }
1859
1860 /**
1861 * Render Basic Masonry gallery shortcode.
1862 *
1863 * @global object $post Post object
1864 * @param mixed $output HTML output
1865 * @param array $shortcode_atts Shortcode attributes
1866 * @return string HTML output
1867 */
1868 public function basic_masonry_gallery_shortcode( $output, $shortcode_atts ) {
1869 if ( ! empty( $output ) )
1870 return $output;
1871
1872 global $post;
1873
1874 $defaults = array(
1875 'rl_gallery_id' => 0,
1876 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1877 'class' => '',
1878 'include' => '',
1879 'exclude' => '',
1880 'urls' => '',
1881 'type' => '',
1882 'order' => 'asc',
1883 'orderby' => 'menu_order',
1884 'size' => 'medium',
1885 'link' => 'file',
1886 'columns' => 3
1887 );
1888
1889 // get main instance
1890 $rl = Responsive_Lightbox();
1891
1892 if ( ! is_array( $shortcode_atts ) )
1893 $shortcode_atts = wp_parse_args( $shortcode_atts, $defaults );
1894
1895 // is there rl_gallery ID?
1896 $rl_gallery_id = $defaults['rl_gallery_id'] = ! empty( $shortcode_atts['rl_gallery_id'] ) ? (int) $shortcode_atts['rl_gallery_id'] : 0;
1897
1898 // is it rl gallery?
1899 $rl_gallery = $rl->options['builder']['gallery_builder'] && $rl_gallery_id && get_post_type( $rl_gallery_id ) === 'rl_gallery';
1900
1901 if ( ! array_key_exists( 'type', $shortcode_atts ) )
1902 $shortcode_atts['type'] = '';
1903
1904 // break if it is not basic masonry gallery - first check
1905 if ( ! ( $shortcode_atts['type'] === 'basicmasonry' || ( $shortcode_atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1906 return $output;
1907
1908 // get shortcode gallery fields combined with defaults
1909 $fields = rl_get_gallery_fields( 'basicmasonry' );
1910
1911 // get gallery fields attributes
1912 $field_atts = rl_get_gallery_fields_atts( $fields, $shortcode_atts, $rl_gallery );
1913
1914 // is it rl gallery? add misc and lightbox fields
1915 if ( $rl_gallery )
1916 $fields += $rl->galleries->fields['lightbox']['options'] + $rl->galleries->fields['misc']['options'];
1917
1918 // get only valid arguments
1919 $atts = shortcode_atts( array_merge( $defaults, $field_atts ), $shortcode_atts, 'gallery' );
1920
1921 // sanitize gallery fields
1922 $atts = $this->sanitize_shortcode_args( $atts, $fields );
1923
1924 // break if it is not basic masonry gallery
1925 if ( ! ( $atts['type'] === 'basicmasonry' || ( $atts['type'] === '' && ( ( $rl_gallery && $rl->options['settings']['builder_gallery'] === 'basicmasonry' ) || ( ! $rl_gallery && $rl->options['settings']['default_gallery'] === 'basicmasonry' ) ) ) ) )
1926 return $output;
1927
1928 // ID
1929 $atts['id'] = (int) $atts['id'];
1930
1931 // add custom classes if needed
1932 if ( $rl_gallery )
1933 $atts['class'] .= ' ' . $atts['gallery_custom_class'];
1934
1935 // any classes?
1936 if ( $atts['class'] !== '' ) {
1937 $atts['class'] = trim( $atts['class'] );
1938
1939 // more than 1 class?
1940 if ( strpos( $atts['class'], ' ' ) !== false ) {
1941 // get unique valid HTML classes
1942 $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1943
1944 if ( ! empty( $atts['class'] ) )
1945 $atts['class'] = implode( ' ', $atts['class'] );
1946 else
1947 $atts['class'] = '';
1948 // single class
1949 } else
1950 $atts['class'] = sanitize_html_class( $atts['class'] );
1951 }
1952
1953 // orderby
1954 if ( empty( $atts['orderby'] ) ) {
1955 $atts['orderby'] = sanitize_sql_orderby( $atts['orderby'] );
1956
1957 if ( empty( $atts['orderby'] ) )
1958 $atts['orderby'] = $defaults['orderby'];
1959 }
1960
1961 // order
1962 if ( strtolower( $atts['order'] ) === 'rand' )
1963 $atts['orderby'] = 'rand';
1964
1965 // check columns
1966 if ( $atts['columns_lg'] === 0 )
1967 $atts['columns_lg'] = $atts['columns'];
1968
1969 if ( $atts['columns_md'] === 0 )
1970 $atts['columns_md'] = $atts['columns'];
1971
1972 if ( $atts['columns_sm'] === 0 )
1973 $atts['columns_sm'] = $atts['columns'];
1974
1975 if ( $atts['columns_xs'] === 0 )
1976 $atts['columns_xs'] = $atts['columns'];
1977
1978 // gallery lightbox source size
1979 if ( ! empty( $atts['lightbox_image_size'] ) ) {
1980 if ( $atts['lightbox_image_size'] === 'global' )
1981 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1982 elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1983 $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1984 else
1985 $atts['src_size'] = $atts['lightbox_image_size'];
1986 } else
1987 $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1988
1989 // filter all shortcode arguments
1990 $atts = apply_filters( 'rl_gallery_shortcode_atts', $atts, $rl_gallery_id );
1991
1992 // get gallery images
1993 $images = rl_get_gallery_shortcode_images( $atts );
1994
1995 if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1996 return $output;
1997
1998 $gallery_no = $this->gallery_no;
1999
2000 ob_start(); ?>
2001
2002 <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; ?>">
2003
2004 <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
2005
2006 <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; ?>">
2007
2008 <?php
2009 $count = 0;
2010
2011 if ( $count === 0 )
2012 echo '<div class="rl-gutter-sizer"></div><div class="rl-grid-sizer"></div>';
2013
2014 foreach ( $images as $image ) {
2015 echo '
2016 <div class="rl-gallery-item' . ( $count === 0 ? ' rl-gallery-item-width-4' : '' ) . '" ' . implode( ' ', apply_filters( 'rl_gallery_item_extra_args', array(), $atts, $image ) ) . '>
2017 <div class="rl-gallery-item-content">
2018 ' . $image['link'] . '
2019 </div>
2020 </div>';
2021
2022 $count++;
2023 } ?>
2024
2025 </div>
2026
2027 <?php do_action( 'rl_after_gallery', $atts, $rl_gallery_id ); ?>
2028
2029 </div>
2030
2031 <?php $gallery_html = ob_get_contents();
2032
2033 ob_clean();
2034
2035 // scripts
2036 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' ) );
2037
2038 // styles
2039 wp_enqueue_style( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'css/gallery-basicmasonry.css', dirname( __FILE__ ) ), array(), $rl->defaults['version'] );
2040
2041 // add inline style
2042 wp_add_inline_style( 'responsive-lightbox-basicmasonry-gallery', '
2043 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery {
2044 margin: ' . -( $atts['margin'] / 2 ) . 'px ' . -( $atts['gutter'] / 2 ) . 'px;
2045 padding: ' . $atts['margin'] . 'px 0;
2046 }
2047 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-bottom {
2048 margin-top: ' . ( $atts['margin'] / 2 ) . 'px
2049 }
2050 #rl-gallery-container-' . $gallery_no . ' .rl-pagination-top {
2051 margin-bottom: ' . ( $atts['margin'] / 2 ) . 'px
2052 }
2053 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2054 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2055 width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
2056 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2057 }
2058 @media all and (min-width: 1200px) {
2059 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2060 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2061 width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
2062 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2063 }
2064 }
2065 @media all and (min-width: 992px) and (max-width: 1200px) {
2066 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2067 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2068 width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
2069 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2070 }
2071 }
2072 @media all and (min-width: 768px) and (max-width: 992px) {
2073 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2074 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2075 width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
2076 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2077 }
2078 }
2079 @media all and (max-width: 768px) {
2080 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2081 #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2082 width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
2083 margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2084 }
2085 }'
2086 );
2087
2088 wp_localize_script(
2089 'responsive-lightbox-basicmasonry-gallery',
2090 'rlArgsBasicMasonryGallery' . ( $gallery_no + 1 ),
2091 json_encode(
2092 array(
2093 'originLeft' => $atts['origin_left'],
2094 'originTop' => $atts['origin_top']
2095 )
2096 )
2097 );
2098
2099 // remove any new lines from the output so that the reader parses it better
2100 return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
2101 }
2102 }