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