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