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