Responsive Lightbox & Gallery - Version 2.4.1

Version Description

  • Fix: WooCommerce product gallery
  • Fix: WooCommerce gallery lightbox
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Responsive Lightbox & Gallery
Version 2.4.1
Comparing to
See all releases

Code changes from version 2.4.0 to 2.4.1

images/df-black-sm.png DELETED
Binary file
images/logo-dfactory.png DELETED
Binary file
includes/class-frontend.php CHANGED
@@ -48,7 +48,7 @@ class Responsive_Lightbox_Frontend {
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 );
52
  }
53
 
54
  /**
@@ -58,18 +58,21 @@ class Responsive_Lightbox_Frontend {
58
  * @return string
59
  */
60
  public function add_lightbox( $content ) {
 
 
 
61
  // get current script
62
- $script = Responsive_Lightbox()->options['settings']['script'];
63
 
64
  // prepare arguments
65
  $args = array(
66
- 'selector' => Responsive_Lightbox()->options['settings']['selector'],
67
  'script' => $script,
68
  'settings' => array(
69
- 'script' => Responsive_Lightbox()->options['configuration'][$script],
70
- 'plugin' => Responsive_Lightbox()->options['settings']
71
  ),
72
- 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports']
73
  );
74
 
75
  // workaround for builder galleries to bypass images_as_gallery option, applied only to rl_gallery posts
@@ -308,22 +311,25 @@ class Responsive_Lightbox_Frontend {
308
  * @return string
309
  */
310
  public function wp_get_attachment_link( $link, $id, $size, $permalink, $icon, $text ) {
311
- if ( Responsive_Lightbox()->options['settings']['galleries'] && wp_attachment_is_image( $id ) ) {
 
 
 
312
  // deprecated filter
313
  $link = apply_filters( 'rl_lightbox_attachment_link', $link, $id, $size, $permalink, $icon, $text, [] );
314
 
315
  // get current script
316
- $script = Responsive_Lightbox()->options['settings']['script'];
317
 
318
  // prepare arguments
319
  $args = array(
320
- 'selector' => Responsive_Lightbox()->options['settings']['selector'],
321
  'script' => $script,
322
  'settings' => array(
323
- 'script' => Responsive_Lightbox()->options['configuration'][$script],
324
- 'plugin' => Responsive_Lightbox()->options['settings']
325
  ),
326
- 'supports' => Responsive_Lightbox()->settings->scripts[$script]['supports'],
327
  'image_id' => $id,
328
  'title' => '',
329
  'caption' => '',
@@ -821,7 +827,7 @@ class Responsive_Lightbox_Frontend {
821
  // apply adjustments, as per settings
822
  if ( $images ) {
823
  // get current script
824
- $script = $rl->options['settings']['script'];
825
 
826
  // prepare arguments
827
  $args = array(
@@ -971,18 +977,24 @@ class Responsive_Lightbox_Frontend {
971
  * @return string
972
  */
973
  public function force_custom_gallery_lightbox( $content ) {
974
- if ( Responsive_Lightbox()->options['settings']['force_custom_gallery'] ) {
 
 
 
975
  // search for image links
976
  preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?)\.(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $content, $links );
977
 
978
  // found any links?
979
  if ( ! empty ( $links[0] ) ) {
 
 
 
980
  foreach ( $links[0] as $link_number => $link ) {
981
  // get attachment id
982
  $image_id = $this->get_attachment_id_by_url( $links[2][$link_number] . '.' . $links[3][$link_number] );
983
 
984
  // get title type
985
- $title_arg = Responsive_Lightbox()->options['settings']['gallery_image_title'];
986
 
987
  // update title if needed
988
  if ( $title_arg !== 'default' && $image_id )
@@ -991,7 +1003,7 @@ class Responsive_Lightbox_Frontend {
991
  $title = '';
992
 
993
  // get caption type
994
- $caption_arg = Responsive_Lightbox()->options['settings']['gallery_image_caption'];
995
 
996
  // update caption if needed
997
  if ( $caption_arg !== 'default' )
@@ -1005,15 +1017,15 @@ class Responsive_Lightbox_Frontend {
1005
  if ( $result[1] === 'norl' )
1006
  continue;
1007
 
1008
- $content = str_replace( $link, preg_replace( '/data-rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
1009
  } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
1010
  // do not modify this link
1011
  if ( $result[1] === 'norl' )
1012
  continue;
1013
 
1014
- $content = str_replace( $link, preg_replace( '/rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
1015
  } else
1016
- $content = str_replace( $link, '<a' . $links[1][$link_number] . ' href="' . $links[2][$link_number] . '.' . $links[3][$link_number] . '" data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . base64_encode( $this->gallery_no ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( Responsive_Lightbox()->options['settings']['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ) . $links[4][$link_number] . '>', $content );
1017
  }
1018
  }
1019
  }
@@ -1032,10 +1044,13 @@ class Responsive_Lightbox_Frontend {
1032
  if ( class_exists( 'WooCommerce' ) ) {
1033
  global $woocommerce;
1034
 
 
 
 
1035
  // specific WooCommerce gallery?
1036
- if ( ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1037
  // replace default WooCommerce lightbox?
1038
- if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1039
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1040
  // dequeue scripts
1041
  wp_dequeue_script( 'flexslider' );
@@ -1069,7 +1084,7 @@ class Responsive_Lightbox_Frontend {
1069
  // default gallery?
1070
  } else {
1071
  // replace default WooCommerce lightbox?
1072
- if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1073
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1074
  // dequeue scripts
1075
  wp_dequeue_script( 'photoswipe' );
@@ -1121,9 +1136,10 @@ class Responsive_Lightbox_Frontend {
1121
  * Apply lightbox to WooCommerce product gallery.
1122
  *
1123
  * @param string $html
 
1124
  * @return string
1125
  */
1126
- public function woocommerce_single_product_image_thumbnail_html( $html ) {
1127
  if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] ) {
1128
  // make sure main product image has same gallery number
1129
  $gallery_no = $this->gallery_no + 1;
@@ -1138,13 +1154,81 @@ class Responsive_Lightbox_Frontend {
1138
 
1139
  // found valid link?
1140
  if ( ! empty( $result ) )
1141
- $html = $result[1] . '<a' . $result[2] . ' data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1142
  }
 
 
1143
  }
1144
 
1145
  return $html;
1146
  }
1147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1148
  /**
1149
  * WooCommerce gallery init.
1150
  *
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
  /**
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
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' => '',
827
  // apply adjustments, as per settings
828
  if ( $images ) {
829
  // get current script
830
+ $script = $rl->get_lightbox_script();
831
 
832
  // prepare arguments
833
  $args = array(
977
  * @return string
978
  */
979
  public function force_custom_gallery_lightbox( $content ) {
980
+ // get main instance
981
+ $rl = Responsive_Lightbox();
982
+
983
+ if ( $rl->options['settings']['force_custom_gallery'] ) {
984
  // search for image links
985
  preg_match_all( '/<a(.*?)href=(?:\'|")([^<]*?)\.(bmp|gif|jpeg|jpg|png|webp)(?:\'|")(.*?)>/i', $content, $links );
986
 
987
  // found any links?
988
  if ( ! empty ( $links[0] ) ) {
989
+ // get current script
990
+ $script = $rl->get_lightbox_script();
991
+
992
  foreach ( $links[0] as $link_number => $link ) {
993
  // get attachment id
994
  $image_id = $this->get_attachment_id_by_url( $links[2][$link_number] . '.' . $links[3][$link_number] );
995
 
996
  // get title type
997
+ $title_arg = $rl->options['settings']['gallery_image_title'];
998
 
999
  // update title if needed
1000
  if ( $title_arg !== 'default' && $image_id )
1003
  $title = '';
1004
 
1005
  // get caption type
1006
+ $caption_arg = $rl->options['settings']['gallery_image_caption'];
1007
 
1008
  // update caption if needed
1009
  if ( $caption_arg !== 'default' )
1017
  if ( $result[1] === 'norl' )
1018
  continue;
1019
 
1020
+ $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 );
1021
  } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
1022
  // do not modify this link
1023
  if ( $result[1] === 'norl' )
1024
  continue;
1025
 
1026
+ $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 );
1027
  } else
1028
+ $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 );
1029
  }
1030
  }
1031
  }
1044
  if ( class_exists( 'WooCommerce' ) ) {
1045
  global $woocommerce;
1046
 
1047
+ // get main instance
1048
+ $rl = Responsive_Lightbox();
1049
+
1050
  // specific WooCommerce gallery?
1051
+ if ( ! empty( $rl->options['settings']['default_woocommerce_gallery'] ) && $rl->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1052
  // replace default WooCommerce lightbox?
1053
+ if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1054
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1055
  // dequeue scripts
1056
  wp_dequeue_script( 'flexslider' );
1084
  // default gallery?
1085
  } else {
1086
  // replace default WooCommerce lightbox?
1087
+ if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1088
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1089
  // dequeue scripts
1090
  wp_dequeue_script( 'photoswipe' );
1136
  * Apply lightbox to WooCommerce product gallery.
1137
  *
1138
  * @param string $html
1139
+ * @param int $attachment_id
1140
  * @return string
1141
  */
1142
+ public function woocommerce_single_product_image_thumbnail_html( $html, $attachment_id ) {
1143
  if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] ) {
1144
  // make sure main product image has same gallery number
1145
  $gallery_no = $this->gallery_no + 1;
1154
 
1155
  // found valid link?
1156
  if ( ! empty( $result ) )
1157
+ $html = $result[1] . '<a' . $result[2] . 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1158
  }
1159
+
1160
+ $html = $this->woocommerce_gallery_link( $html, $attachment_id );
1161
  }
1162
 
1163
  return $html;
1164
  }
1165
 
1166
+ /**
1167
+ * Add title and caption to WooCommerce gallery image links.
1168
+ *
1169
+ * @param string $link
1170
+ * @param int $attachment_id
1171
+ * @return string
1172
+ */
1173
+ public function woocommerce_gallery_link( $link, $attachment_id ) {
1174
+ // get main instance
1175
+ $rl = Responsive_Lightbox();
1176
+
1177
+ // gallery image title
1178
+ $title = '';
1179
+
1180
+ // get title type
1181
+ $title_arg = $rl->options['settings']['gallery_image_title'];
1182
+
1183
+ // update title if needed
1184
+ if ( $title_arg !== 'default' ) {
1185
+ // original title
1186
+ $title = $this->get_attachment_title( $attachment_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $attachment_id, $link ) );
1187
+ }
1188
+
1189
+ if ( $title !== '' ) {
1190
+ // sanitize title
1191
+ if ( $html_caption = rl_current_lightbox_supports( 'html_caption' ) )
1192
+ $title = esc_attr( trim( nl2br( $title ) ) );
1193
+ else
1194
+ $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $title ) ), true ) );
1195
+
1196
+ // add title and rl_title if needed
1197
+ if ( preg_match( '/<a[^>]*?title=(?:\'|")[^>]*?(?:\'|").*?>/is', $link ) === 1 )
1198
+ $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a[^>]*?title=(?:\'|"))[^>]*?((?:\'|").*?>)/is', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
1199
+ else
1200
+ $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a[^>]*?)>/is', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
1201
+ }
1202
+
1203
+ // gallery image caption
1204
+ $caption = '';
1205
+
1206
+ // get caption type
1207
+ $caption_arg = $rl->options['settings']['gallery_image_caption'];
1208
+
1209
+ // update caption if needed
1210
+ if ( $caption_arg !== 'default' ) {
1211
+ // original caption
1212
+ $caption = $this->get_attachment_title( $attachment_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $attachment_id, $link ) );
1213
+ }
1214
+
1215
+ if ( $caption !== '' ) {
1216
+ // sanitize caption
1217
+ if ( $html_caption )
1218
+ $caption = esc_attr( trim( nl2br( $caption ) ) );
1219
+ else
1220
+ $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $caption ) ), true ) );
1221
+
1222
+ // add rl_caption
1223
+ $link = str_replace( '__RL_IMAGE_CAPTION__', $caption, preg_replace( '/(<a[^>]*?)>/is', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
1224
+ }
1225
+
1226
+ if ( $rl->get_lightbox_script() === 'magnific' )
1227
+ $link = preg_replace( '/(<a[^>]*?)>/is', '$1 data-magnific_type="gallery">', $link );
1228
+
1229
+ return $link;
1230
+ }
1231
+
1232
  /**
1233
  * WooCommerce gallery init.
1234
  *
includes/class-galleries.php CHANGED
@@ -50,6 +50,7 @@ class Responsive_Lightbox_Galleries {
50
  add_action( '_wp_put_post_revision', array( $this, 'save_revision' ) );
51
  add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
52
  add_action( 'shutdown', array( $this, 'shutdown_preview' ) );
 
53
 
54
  // filters
55
  add_filter( 'manage_rl_gallery_posts_columns', array( $this, 'gallery_columns' ) );
@@ -167,6 +168,10 @@ class Responsive_Lightbox_Galleries {
167
  // get main instance
168
  $rl = Responsive_Lightbox();
169
 
 
 
 
 
170
  $config_menu_items = apply_filters( 'rl_gallery_types', $rl->gallery_types );
171
  $config_menu_items['default'] = __( 'Global', 'responsive-lightbox' );
172
 
@@ -2785,17 +2790,17 @@ class Responsive_Lightbox_Galleries {
2785
  $this->gallery_args['total'] = (int) ceil( $images_count / $args['images_per_page'] );
2786
 
2787
  // remove actions to avoid issues with multiple galleries on single page
2788
- remove_action( 'rl_before_gallery', array( $this, 'do_pagination' ), 10 );
2789
- remove_action( 'rl_after_gallery', array( $this, 'do_pagination' ), 10 );
2790
 
2791
  // pagination position
2792
  if ( $args['pagination_position'] === 'top' )
2793
- add_action( 'rl_before_gallery', array( $this, 'do_pagination' ), 10, 2 );
2794
  elseif ( $args['pagination_position'] === 'bottom' )
2795
- add_action( 'rl_after_gallery', array( $this, 'do_pagination' ), 10, 2 );
2796
  else {
2797
- add_action( 'rl_before_gallery', array( $this, 'do_pagination' ), 10, 2 );
2798
- add_action( 'rl_after_gallery', array( $this, 'do_pagination' ), 10, 2 );
2799
  }
2800
  }
2801
 
@@ -2814,6 +2819,9 @@ class Responsive_Lightbox_Galleries {
2814
  public function do_pagination( $args, $gallery_id ) {
2815
  global $wp;
2816
 
 
 
 
2817
  // get current action
2818
  $current_action = current_action();
2819
 
@@ -2824,15 +2832,22 @@ class Responsive_Lightbox_Galleries {
2824
  else
2825
  $class = '';
2826
 
 
 
 
2827
  if ( empty( $args['pagination_type'] ) )
2828
  $args['pagination_type'] = 'paged';
2829
 
 
 
 
 
2830
  echo
2831
  '<div class="rl-pagination' . $class . '"' . ( $args['pagination_type'] === 'infinite' ? ' data-button="' . $args['load_more'] . '"' : '' ) .'>' .
2832
  paginate_links(
2833
- array(
2834
  'format' => '?rl_page=%#%',
2835
- 'base' => add_query_arg( array( 'rl_gallery_no' => Responsive_Lightbox()->frontend->gallery_no, 'rl_page' => '%#%' ), $args['pagination_type'] !== 'paged' ? get_permalink( $gallery_id ) : home_url( $wp->request ) ),
2836
  'total' => $this->gallery_args['total'],
2837
  'current' => $this->gallery_args['page'],
2838
  'show_all' => false,
@@ -2846,11 +2861,33 @@ class Responsive_Lightbox_Galleries {
2846
  'add_fragment' => '',
2847
  'before_page_number' => '',
2848
  'after_page_number' => ''
2849
- )
2850
  ) .
2851
  '</div>' . ( $args['pagination_type'] === 'infinite' && $args['load_more'] === 'manually' ? '<div class="rl-gallery-button"><button class="rl-button rl-load-more">' . esc_html__( 'Load more', 'responsive-lightbox' ) . '</button></div>' : '' );
2852
  }
2853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2854
  /**
2855
  * Get gallery page.
2856
  *
@@ -2858,7 +2895,7 @@ class Responsive_Lightbox_Galleries {
2858
  * @return void
2859
  */
2860
  public function get_gallery_page( $args ) {
2861
- if ( isset( $_POST['gallery_id'], $_POST['gallery_no'], $_POST['page'], $_POST['nonce'], $_POST['preview'], $_POST['post_id'] ) && wp_verify_nonce( $_POST['nonce'], 'rl_nonce' ) ) {
2862
  // cast page number
2863
  $_GET['rl_page'] = (int) $_POST['page'];
2864
 
50
  add_action( '_wp_put_post_revision', array( $this, 'save_revision' ) );
51
  add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
52
  add_action( 'shutdown', array( $this, 'shutdown_preview' ) );
53
+ add_action( 'wp_loaded', array( $this, 'maybe_change_lightbox' ), 1 );
54
 
55
  // filters
56
  add_filter( 'manage_rl_gallery_posts_columns', array( $this, 'gallery_columns' ) );
168
  // get main instance
169
  $rl = Responsive_Lightbox();
170
 
171
+ // set lightbox script for infinite scroll pages
172
+ if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'], $_GET['rl_lightbox_script'] ) )
173
+ $rl->set_lightbox_script( $_GET['rl_lightbox_script'] );
174
+
175
  $config_menu_items = apply_filters( 'rl_gallery_types', $rl->gallery_types );
176
  $config_menu_items['default'] = __( 'Global', 'responsive-lightbox' );
177
 
2790
  $this->gallery_args['total'] = (int) ceil( $images_count / $args['images_per_page'] );
2791
 
2792
  // remove actions to avoid issues with multiple galleries on single page
2793
+ remove_action( 'rl_before_gallery', [ $this, 'do_pagination' ], 10 );
2794
+ remove_action( 'rl_after_gallery', [ $this, 'do_pagination' ], 10 );
2795
 
2796
  // pagination position
2797
  if ( $args['pagination_position'] === 'top' )
2798
+ add_action( 'rl_before_gallery', [ $this, 'do_pagination' ], 10, 2 );
2799
  elseif ( $args['pagination_position'] === 'bottom' )
2800
+ add_action( 'rl_after_gallery', [ $this, 'do_pagination' ], 10, 2 );
2801
  else {
2802
+ add_action( 'rl_before_gallery', [ $this, 'do_pagination' ], 10, 2 );
2803
+ add_action( 'rl_after_gallery', [ $this, 'do_pagination' ], 10, 2 );
2804
  }
2805
  }
2806
 
2819
  public function do_pagination( $args, $gallery_id ) {
2820
  global $wp;
2821
 
2822
+ // get main instance
2823
+ $rl = Responsive_Lightbox();
2824
+
2825
  // get current action
2826
  $current_action = current_action();
2827
 
2832
  else
2833
  $class = '';
2834
 
2835
+ // set base arguments
2836
+ $base_args = [ 'rl_gallery_no' => $rl->frontend->gallery_no, 'rl_page' => '%#%' ];
2837
+
2838
  if ( empty( $args['pagination_type'] ) )
2839
  $args['pagination_type'] = 'paged';
2840
 
2841
+ // infinite scroll?
2842
+ if ( $args['pagination_type'] === 'infinite' )
2843
+ $base_args['rl_lightbox_script'] = $rl->get_lightbox_script();
2844
+
2845
  echo
2846
  '<div class="rl-pagination' . $class . '"' . ( $args['pagination_type'] === 'infinite' ? ' data-button="' . $args['load_more'] . '"' : '' ) .'>' .
2847
  paginate_links(
2848
+ [
2849
  'format' => '?rl_page=%#%',
2850
+ 'base' => add_query_arg( $base_args, $args['pagination_type'] !== 'paged' ? get_permalink( $gallery_id ) : home_url( $wp->request ) ),
2851
  'total' => $this->gallery_args['total'],
2852
  'current' => $this->gallery_args['page'],
2853
  'show_all' => false,
2861
  'add_fragment' => '',
2862
  'before_page_number' => '',
2863
  'after_page_number' => ''
2864
+ ]
2865
  ) .
2866
  '</div>' . ( $args['pagination_type'] === 'infinite' && $args['load_more'] === 'manually' ? '<div class="rl-gallery-button"><button class="rl-button rl-load-more">' . esc_html__( 'Load more', 'responsive-lightbox' ) . '</button></div>' : '' );
2867
  }
2868
 
2869
+ /**
2870
+ * Check whether is it valid gallery AJAX request (rl-get-gallery-page-content action).
2871
+ *
2872
+ * @return bool
2873
+ */
2874
+ public function gallery_ajax_verified() {
2875
+ return ( wp_doing_ajax() && isset( $_POST['action'], $_POST['gallery_id'], $_POST['gallery_no'], $_POST['page'], $_POST['nonce'], $_POST['preview'], $_POST['post_id'], $_POST['lightbox'] ) && $_POST['action'] === 'rl-get-gallery-page-content' && wp_verify_nonce( $_POST['nonce'], 'rl_nonce' ) );
2876
+ }
2877
+
2878
+ /**
2879
+ * Try to change lightbox in valid gallery AJAX request (rl-get-gallery-page-content action).
2880
+ *
2881
+ * @return void
2882
+ */
2883
+ public function maybe_change_lightbox() {
2884
+ // early ajax check
2885
+ if ( $this->gallery_ajax_verified() ) {
2886
+ // set new lightbox script
2887
+ Responsive_Lightbox()->set_lightbox_script( $_POST['lightbox'] );
2888
+ }
2889
+ }
2890
+
2891
  /**
2892
  * Get gallery page.
2893
  *
2895
  * @return void
2896
  */
2897
  public function get_gallery_page( $args ) {
2898
+ if ( $this->gallery_ajax_verified() ) {
2899
  // cast page number
2900
  $_GET['rl_page'] = (int) $_POST['page'];
2901
 
includes/functions.php CHANGED
@@ -109,6 +109,24 @@ function rl_get_image_size_by_url( $url ) {
109
  return Responsive_Lightbox()->frontend->get_image_size_by_url( $url );
110
  }
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  /**
113
  * Check whether lightbox supports specified type.
114
  *
@@ -121,7 +139,7 @@ function rl_current_lightbox_supports( $type = '', $compare_mode = 'AND' ) {
121
  $rl = Responsive_Lightbox();
122
 
123
  // get current script
124
- $script = $rl->options['settings']['script'];
125
 
126
  // get scripts
127
  $scripts = $rl->settings->scripts;
109
  return Responsive_Lightbox()->frontend->get_image_size_by_url( $url );
110
  }
111
 
112
+ /**
113
+ * Get current lightbox script.
114
+ *
115
+ * @return string
116
+ */
117
+ function rl_get_lightbox_script() {
118
+ return Responsive_Lightbox()->get_lightbox_script();
119
+ }
120
+
121
+ /**
122
+ * Set current lightbox script.
123
+ *
124
+ * @return bool
125
+ */
126
+ function rl_set_lightbox_script( $script ) {
127
+ return Responsive_Lightbox()->set_lightbox_script( $script );
128
+ }
129
+
130
  /**
131
  * Check whether lightbox supports specified type.
132
  *
139
  $rl = Responsive_Lightbox();
140
 
141
  // get current script
142
+ $script = $rl->get_lightbox_script();
143
 
144
  // get scripts
145
  $scripts = $rl->settings->scripts;
js/admin-galleries.js CHANGED
@@ -900,7 +900,6 @@
900
  } ).get(),
901
  nonce: rlArgsGalleries.nonce
902
  } ).done( function( response ) {
903
- // try {
904
  if ( response.success ) {
905
  container.find( 'tr[data-field_type]' ).each( function() {
906
  var el = $( this );
@@ -933,9 +932,6 @@
933
  } else {
934
  // @todo
935
  }
936
- // } catch ( e ) {
937
- // console.log( 'err' );
938
- // }
939
  } ).always( function() {
940
  // hide spinner
941
  spinner.fadeOut( 'fast' );
900
  } ).get(),
901
  nonce: rlArgsGalleries.nonce
902
  } ).done( function( response ) {
 
903
  if ( response.success ) {
904
  container.find( 'tr[data-field_type]' ).each( function() {
905
  var el = $( this );
932
  } else {
933
  // @todo
934
  }
 
 
 
935
  } ).always( function() {
936
  // hide spinner
937
  spinner.fadeOut( 'fast' );
js/front.js CHANGED
@@ -148,7 +148,8 @@
148
  post_id: rlArgs.postId,
149
  page: parseQueryString( 'rl_page', link.prop( 'href' ) ),
150
  nonce: rlArgs.nonce,
151
- preview: rlArgs.preview
 
152
  } ).done( function( response ) {
153
  // replace container with new content
154
  container.replaceWith( $( response ).removeClass( 'rl-loading' ) );
@@ -213,10 +214,39 @@
213
  e.preventDefault();
214
  e.stopPropagation();
215
 
216
- if ( flex.length )
217
- flex.find( '.flex-active-slide a[data-rel]' ).trigger( 'click' );
218
- else
219
- gallery.find( 'a[data-rel]' ).first().trigger( 'click' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  } );
221
  }
222
  }
@@ -333,12 +363,20 @@
333
 
334
  $( 'a[rel*="' + selector + '"], a[data-rel*="' + selector + '"]' ).each( function() {
335
  var el = $( this );
 
 
 
 
 
 
 
 
336
 
337
  // set description
338
- el.attr( 'title', el.data( 'rl_caption' ) );
339
 
340
  // set title
341
- el.find( 'img' ).attr( 'alt', el.data( 'rl_title' ) );
342
  } );
343
 
344
  $( 'a[rel*="' + selector + '"], a[data-rel*="' + selector + '"]' ).prettyPhoto( {
@@ -765,7 +803,16 @@
765
  fixedBgPos: args.fixedBgPos === 'auto' ? 'auto' : ( args.fixedBgPos === '1' ),
766
  image: {
767
  titleSrc: function( item ) {
768
- return item.el.attr( 'data-rl_title' ) + '<small>' + item.el.attr( 'data-rl_caption' ) + '</small>';
 
 
 
 
 
 
 
 
 
769
  }
770
  },
771
  gallery: {
148
  post_id: rlArgs.postId,
149
  page: parseQueryString( 'rl_page', link.prop( 'href' ) ),
150
  nonce: rlArgs.nonce,
151
+ preview: rlArgs.preview,
152
+ lightbox: rlArgs.script
153
  } ).done( function( response ) {
154
  // replace container with new content
155
  container.replaceWith( $( response ).removeClass( 'rl-loading' ) );
214
  e.preventDefault();
215
  e.stopPropagation();
216
 
217
+ if ( script === 'lightgallery' ) {
218
+ if ( flex.length ) {
219
+ var image = flex.find( '.flex-active-slide a[data-rel] img' );
220
+ var linkId = flex.find( '.flex-active-slide a[data-rel]' ).data( 'lg-id' );
221
+
222
+ image.trigger( 'click.lgcustom-item-' + linkId );
223
+ } else {
224
+ var link = gallery.find( 'a[data-rel]' ).first();
225
+ var image = link.find( 'img' );
226
+
227
+ image.trigger( 'click.lgcustom-item-' + link.data( 'lg-id' ) );
228
+ }
229
+ } else if ( script === 'fancybox_pro' ) {
230
+ if ( flex.length ) {
231
+ var index = flex.find( '.flex-active-slide' ).index();
232
+ var imageId = flex.find( '.flex-active-slide a[data-rel]' ).data( 'fancybox' );
233
+
234
+ Fancybox.fromOpener( '[data-fancybox="' + imageId + '"]', {
235
+ startIndex: index
236
+ } );
237
+ } else {
238
+ var link = gallery.find( 'a[data-rel]' ).first();
239
+
240
+ Fancybox.fromOpener( '[data-fancybox="' + link.data( 'fancybox' ) + '"]', {
241
+ startIndex: 0
242
+ } );
243
+ }
244
+ } else {
245
+ if ( flex.length )
246
+ flex.find( '.flex-active-slide a[data-rel]' ).trigger( 'click' );
247
+ else
248
+ gallery.find( 'a[data-rel]' ).first().trigger( 'click' );
249
+ }
250
  } );
251
  }
252
  }
363
 
364
  $( 'a[rel*="' + selector + '"], a[data-rel*="' + selector + '"]' ).each( function() {
365
  var el = $( this );
366
+ var title = el.data( 'rl_title' );
367
+ var caption = el.data( 'rl_caption' );
368
+
369
+ if ( ! title )
370
+ title = '';
371
+
372
+ if ( ! caption )
373
+ caption = '';
374
 
375
  // set description
376
+ el.attr( 'title', caption );
377
 
378
  // set title
379
+ el.find( 'img' ).attr( 'alt', title );
380
  } );
381
 
382
  $( 'a[rel*="' + selector + '"], a[data-rel*="' + selector + '"]' ).prettyPhoto( {
803
  fixedBgPos: args.fixedBgPos === 'auto' ? 'auto' : ( args.fixedBgPos === '1' ),
804
  image: {
805
  titleSrc: function( item ) {
806
+ var title = item.el.data( 'rl_title' );
807
+ var caption = item.el.data( 'rl_caption' );
808
+
809
+ if ( ! title )
810
+ title = '';
811
+
812
+ if ( ! caption )
813
+ caption = '';
814
+
815
+ return title + '<small>' + caption + '</small>';
816
  }
817
  },
818
  gallery: {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.dfactory.eu/
4
  Tags: gallery, galleries, image, images, responsive, lightbox, photo, photography, masonry, video, builder
5
  Requires at least: 5.0
6
  Tested up to: 6.0
7
- Stable tag: 2.4.0
8
  Requires PHP: 5.4
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
@@ -67,6 +67,7 @@ Responsive Lightbox and Gallery plugin can be extended with our <a href="?utm_so
67
  > [Lightgallery Lightbox](https://www.dfactory.eu/products/lightgallery-lightbox/)
68
  > [Strip Lightbox](https://www.dfactory.eu/products/strip-lightbox/)
69
  > [Fancybox Pro](https://www.dfactory.eu/products/fancybox-pro/)
 
70
 
71
  = Full Feature List =
72
 
@@ -139,6 +140,10 @@ Responsive Lightbox and Gallery plugin comes with many styles and effects alread
139
 
140
  == Changelog ==
141
 
 
 
 
 
142
  = 2.4.0 =
143
  * New: WordPress 6.0 compatibility
144
  * New: HTML5 Media Library videos support (with Lightgallery, Fancybox Pro and Lightcase lightboxes)
@@ -491,5 +496,6 @@ Initial release
491
 
492
  == Upgrade Notice ==
493
 
494
- = 2.4.0 =
495
- WordPress 6.0 compatibility, HTML5 Media Library videos support & emmbed Youtube & Vimeo videos support (with Lightgallery, Fancybox Pro and Lightcase lightboxes)
 
4
  Tags: gallery, galleries, image, images, responsive, lightbox, photo, photography, masonry, video, builder
5
  Requires at least: 5.0
6
  Tested up to: 6.0
7
+ Stable tag: 2.4.1
8
  Requires PHP: 5.4
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
67
  > [Lightgallery Lightbox](https://www.dfactory.eu/products/lightgallery-lightbox/)
68
  > [Strip Lightbox](https://www.dfactory.eu/products/strip-lightbox/)
69
  > [Fancybox Pro](https://www.dfactory.eu/products/fancybox-pro/)
70
+ > [Lightbox Comments](https://dfactory.co/products/lightbox-comments/)
71
 
72
  = Full Feature List =
73
 
140
 
141
  == Changelog ==
142
 
143
+ = 2.4.1 =
144
+ * Fix: WooCommerce product gallery
145
+ * Fix: WooCommerce gallery lightbox
146
+
147
  = 2.4.0 =
148
  * New: WordPress 6.0 compatibility
149
  * New: HTML5 Media Library videos support (with Lightgallery, Fancybox Pro and Lightcase lightboxes)
496
 
497
  == Upgrade Notice ==
498
 
499
+ = 2.4.1 =
500
+ * Fix: WooCommerce product gallery
501
+ * Fix: WooCommerce gallery lightbox
responsive-lightbox.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Responsive Lightbox & Gallery
4
  Description: Responsive Lightbox & Gallery allows users to create galleries and view larger versions of images, galleries and videos in a lightbox (overlay) effect optimized for mobile devices.
5
- Version: 2.4.0
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/responsive-lightbox/
@@ -43,7 +43,7 @@ include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes' . DIRECTORY_SEPARATOR . 'fun
43
  * Responsive Lightbox class.
44
  *
45
  * @class Responsive_Lightbox
46
- * @version 2.4.0
47
  */
48
  class Responsive_Lightbox {
49
 
@@ -304,7 +304,7 @@ class Responsive_Lightbox {
304
  'origin_left' => true,
305
  'origin_top' => true
306
  ],
307
- 'version' => '2.4.0',
308
  'activation_date' => ''
309
  ];
310
  public $options = [];
@@ -328,6 +328,7 @@ class Responsive_Lightbox {
328
  private $deactivaion_url = '';
329
  private $version = false;
330
  private $notices = [];
 
331
  private static $_instance;
332
 
333
  /**
@@ -382,6 +383,9 @@ class Responsive_Lightbox {
382
  $this->options['basicslider_gallery'] = array_merge( $this->defaults['basicslider_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicslider_gallery', $this->defaults['basicslider_gallery'] ) ) == false ? [] : $array ) );
383
  $this->options['basicmasonry_gallery'] = array_merge( $this->defaults['basicmasonry_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicmasonry_gallery', $this->defaults['basicmasonry_gallery'] ) ) == false ? [] : $array ) );
384
 
 
 
 
385
  // actions
386
  add_action( 'upgrader_process_complete', [ $this, 'update_plugin' ], 10, 2 );
387
  add_action( 'plugins_loaded', [ $this, 'plugins_loaded_init' ] );
@@ -1019,6 +1023,32 @@ class Responsive_Lightbox {
1019
  wp_send_json_error();
1020
  }
1021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  /**
1023
  * Initialize remote libraries.
1024
  *
@@ -1054,9 +1084,6 @@ class Responsive_Lightbox {
1054
  if ( ! $this->options['builder']['gallery_builder'] )
1055
  return;
1056
 
1057
- // get current script
1058
- $script = $this->options['settings']['script'];
1059
-
1060
  $taxonomies = [];
1061
 
1062
  if ( $this->options['builder']['categories'] ) {
@@ -1788,7 +1815,7 @@ class Responsive_Lightbox {
1788
  $args = apply_filters(
1789
  'rl_lightbox_args',
1790
  [
1791
- 'script' => $this->options['settings']['script'],
1792
  'selector' => $this->options['settings']['selector'],
1793
  'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? $this->options['settings']['custom_events'] : '' ),
1794
  'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )
2
  /*
3
  Plugin Name: Responsive Lightbox & Gallery
4
  Description: Responsive Lightbox & Gallery allows users to create galleries and view larger versions of images, galleries and videos in a lightbox (overlay) effect optimized for mobile devices.
5
+ Version: 2.4.1
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/responsive-lightbox/
43
  * Responsive Lightbox class.
44
  *
45
  * @class Responsive_Lightbox
46
+ * @version 2.4.1
47
  */
48
  class Responsive_Lightbox {
49
 
304
  'origin_left' => true,
305
  'origin_top' => true
306
  ],
307
+ 'version' => '2.4.1',
308
  'activation_date' => ''
309
  ];
310
  public $options = [];
328
  private $deactivaion_url = '';
329
  private $version = false;
330
  private $notices = [];
331
+ private $current_script = '';
332
  private static $_instance;
333
 
334
  /**
383
  $this->options['basicslider_gallery'] = array_merge( $this->defaults['basicslider_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicslider_gallery', $this->defaults['basicslider_gallery'] ) ) == false ? [] : $array ) );
384
  $this->options['basicmasonry_gallery'] = array_merge( $this->defaults['basicmasonry_gallery'], ( ( $array = get_option( 'responsive_lightbox_basicmasonry_gallery', $this->defaults['basicmasonry_gallery'] ) ) == false ? [] : $array ) );
385
 
386
+ // set current lightbox script
387
+ $this->current_script = $this->options['settings']['script'];
388
+
389
  // actions
390
  add_action( 'upgrader_process_complete', [ $this, 'update_plugin' ], 10, 2 );
391
  add_action( 'plugins_loaded', [ $this, 'plugins_loaded_init' ] );
1023
  wp_send_json_error();
1024
  }
1025
 
1026
+ /**
1027
+ * Get current lightbox script.
1028
+ *
1029
+ * @return string
1030
+ */
1031
+ public function get_lightbox_script() {
1032
+ // get current script
1033
+ return $this->current_script;
1034
+ }
1035
+
1036
+ /**
1037
+ * Set current lightbox script.
1038
+ *
1039
+ * @return bool
1040
+ */
1041
+ public function set_lightbox_script( $script ) {
1042
+ if ( array_key_exists( $script, $this->settings->settings['settings']['fields']['script']['options'] ) ) {
1043
+ // set new lightbox script
1044
+ $this->current_script = $script;
1045
+
1046
+ return true;
1047
+ }
1048
+
1049
+ return false;
1050
+ }
1051
+
1052
  /**
1053
  * Initialize remote libraries.
1054
  *
1084
  if ( ! $this->options['builder']['gallery_builder'] )
1085
  return;
1086
 
 
 
 
1087
  $taxonomies = [];
1088
 
1089
  if ( $this->options['builder']['categories'] ) {
1815
  $args = apply_filters(
1816
  'rl_lightbox_args',
1817
  [
1818
+ 'script' => $this->get_lightbox_script(),
1819
  'selector' => $this->options['settings']['selector'],
1820
  'customEvents' => ( $this->options['settings']['enable_custom_events'] === true ? $this->options['settings']['custom_events'] : '' ),
1821
  'activeGalleries' => $this->get_boolean_value( $this->options['settings']['galleries'] )