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