Responsive Lightbox & Gallery - Version 2.4.3

Version Description

  • Fix: General sanitization and validation overhaul
  • Fix: Displaying legacy gallery and image widgets
  • Fix: Getting colors for media folders
  • Fix: Assigning terms to media folders
Download this release

Release Info

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

Code changes from version 2.4.2 to 2.4.3

includes/class-fast-image.php CHANGED
@@ -1,201 +1,201 @@
1
- <?php
2
- /**
3
- * Finds the dimensions or filetype of an image given its uri by fetching as little as needed
4
- *
5
- * Based on the FastImage class (https://github.com/tommoor/fastimage)
6
- *
7
- * @version 0.1
8
- */
9
- class Responsive_Lightbox_Fast_Image {
10
-
11
- private $strpos = 0;
12
- private $str;
13
- private $type;
14
- private $handle;
15
-
16
- public function __construct( $uri = null ) {
17
- if ( $uri )
18
- $this->load( $uri );
19
- }
20
-
21
- public function load( $uri ) {
22
- if ( $this->handle )
23
- $this->close();
24
-
25
- $this->handle = fopen( $uri, 'r' );
26
- }
27
-
28
- public function close() {
29
- if ( $this->handle ) {
30
- fclose( $this->handle );
31
-
32
- $this->handle = null;
33
- $this->type = null;
34
- $this->str = null;
35
- }
36
- }
37
-
38
- public function get_size() {
39
- $this->strpos = 0;
40
-
41
- if ( $this->get_type() )
42
- return array_values( $this->parse_size() );
43
-
44
- return false;
45
- }
46
-
47
- public function get_type() {
48
- $this->strpos = 0;
49
-
50
- if ( ! $this->type ) {
51
- switch ( $this->get_chars( 2 ) ) {
52
- case "BM":
53
- return $this->type = 'bmp';
54
-
55
- case "GI":
56
- return $this->type = 'gif';
57
-
58
- case chr( 0xFF ) . chr( 0xd8 ):
59
- return $this->type = 'jpeg';
60
-
61
- case chr( 0x89 ) . 'P':
62
- return $this->type = 'png';
63
-
64
- default:
65
- return false;
66
- }
67
- }
68
-
69
- return $this->type;
70
- }
71
-
72
- private function parse_size() {
73
- $this->strpos = 0;
74
-
75
- switch ( $this->type ) {
76
- case 'png':
77
- return $this->parse_size_png();
78
-
79
- case 'gif':
80
- return $this->parse_size_gif();
81
-
82
- case 'bmp':
83
- return $this->parse_size_bmp();
84
-
85
- case 'jpeg':
86
- return $this->parse_size_jpeg();
87
- }
88
-
89
- return null;
90
- }
91
-
92
- private function parse_size_png() {
93
- $chars = $this->get_chars( 25 );
94
-
95
- return unpack( "N*", substr( $chars, 16, 8 ) );
96
- }
97
-
98
- private function parse_size_gif() {
99
- $chars = $this->get_chars( 11 );
100
-
101
- return unpack( "S*", substr( $chars, 6, 4 ) );
102
- }
103
-
104
- private function parse_size_bmp() {
105
- $chars = $this->get_chars( 29 );
106
- $chars = substr( $chars, 14, 14 );
107
- $type = unpack( 'C', $chars );
108
-
109
- return ( reset( $type ) == 40 ) ? unpack( 'L*', substr( $chars, 4 ) ) : unpack( 'L*', substr( $chars, 4, 8 ) );
110
- }
111
-
112
- private function parse_size_jpeg() {
113
- $state = null;
114
- $i = 0;
115
-
116
- while ( true ) {
117
- switch ( $state ) {
118
- default:
119
- $this->get_chars( 2 );
120
- $state = 'started';
121
- break;
122
-
123
- case 'started':
124
- $b = $this->get_byte();
125
- if ( $b === false )
126
- return false;
127
-
128
- $state = $b == 0xFF ? 'sof' : 'started';
129
- break;
130
-
131
- case 'sof':
132
- $b = $this->get_byte();
133
- if ( in_array( $b, range( 0xe0, 0xef ) ) )
134
- $state = 'skipframe';
135
- elseif ( in_array( $b, array_merge( range( 0xC0, 0xC3 ), range( 0xC5, 0xC7 ), range( 0xC9, 0xCB ), range( 0xCD, 0xCF ) ) ) )
136
- $state = 'readsize';
137
- elseif ( $b == 0xFF )
138
- $state = 'sof';
139
- else
140
- $state = 'skipframe';
141
- break;
142
-
143
- case 'skipframe':
144
- $skip = $this->read_int( $this->get_chars( 2 ) ) - 2;
145
- $state = 'doskip';
146
- break;
147
-
148
- case 'doskip':
149
- $this->get_chars( $skip );
150
- $state = 'started';
151
- break;
152
-
153
- case 'readsize':
154
- $c = $this->get_chars( 7 );
155
-
156
- return array( $this->read_int( substr( $c, 5, 2 ) ), $this->read_int( substr( $c, 3, 2 ) ) );
157
- }
158
- }
159
- }
160
-
161
- private function get_chars( $n ) {
162
- $response = null;
163
-
164
- // do we need more data?
165
- if ( $this->strpos + $n - 1 >= strlen( $this->str ) ) {
166
- $end = ( $this->strpos + $n );
167
-
168
- while ( strlen( $this->str ) < $end && $response !== false ) {
169
- // read more from the file handle
170
- $need = $end - ftell( $this->handle );
171
-
172
- if ( $response = fread( $this->handle, $need ) )
173
- $this->str .= $response;
174
- else
175
- return false;
176
- }
177
- }
178
-
179
- $result = substr( $this->str, $this->strpos, $n );
180
- $this->strpos += $n;
181
-
182
- return $result;
183
- }
184
-
185
- private function get_byte() {
186
- $c = $this->get_chars( 1 );
187
- $b = unpack( "C", $c );
188
-
189
- return reset( $b );
190
- }
191
-
192
- private function read_int( $str ) {
193
- $size = unpack( "C*", $str );
194
-
195
- return ( $size[1] << 8 ) + $size[2];
196
- }
197
-
198
- public function __destruct() {
199
- $this->close();
200
- }
201
  }
1
+ <?php
2
+ /**
3
+ * Finds the dimensions or filetype of an image given its uri by fetching as little as needed
4
+ *
5
+ * Based on the FastImage class (https://github.com/tommoor/fastimage)
6
+ *
7
+ * @version 0.1
8
+ */
9
+ class Responsive_Lightbox_Fast_Image {
10
+
11
+ private $strpos = 0;
12
+ private $str;
13
+ private $type;
14
+ private $handle;
15
+
16
+ public function __construct( $uri = null ) {
17
+ if ( $uri )
18
+ $this->load( $uri );
19
+ }
20
+
21
+ public function load( $uri ) {
22
+ if ( $this->handle )
23
+ $this->close();
24
+
25
+ $this->handle = fopen( $uri, 'r' );
26
+ }
27
+
28
+ public function close() {
29
+ if ( $this->handle ) {
30
+ fclose( $this->handle );
31
+
32
+ $this->handle = null;
33
+ $this->type = null;
34
+ $this->str = null;
35
+ }
36
+ }
37
+
38
+ public function get_size() {
39
+ $this->strpos = 0;
40
+
41
+ if ( $this->get_type() )
42
+ return array_values( $this->parse_size() );
43
+
44
+ return false;
45
+ }
46
+
47
+ public function get_type() {
48
+ $this->strpos = 0;
49
+
50
+ if ( ! $this->type ) {
51
+ switch ( $this->get_chars( 2 ) ) {
52
+ case "BM":
53
+ return $this->type = 'bmp';
54
+
55
+ case "GI":
56
+ return $this->type = 'gif';
57
+
58
+ case chr( 0xFF ) . chr( 0xd8 ):
59
+ return $this->type = 'jpeg';
60
+
61
+ case chr( 0x89 ) . 'P':
62
+ return $this->type = 'png';
63
+
64
+ default:
65
+ return false;
66
+ }
67
+ }
68
+
69
+ return $this->type;
70
+ }
71
+
72
+ private function parse_size() {
73
+ $this->strpos = 0;
74
+
75
+ switch ( $this->type ) {
76
+ case 'png':
77
+ return $this->parse_size_png();
78
+
79
+ case 'gif':
80
+ return $this->parse_size_gif();
81
+
82
+ case 'bmp':
83
+ return $this->parse_size_bmp();
84
+
85
+ case 'jpeg':
86
+ return $this->parse_size_jpeg();
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+ private function parse_size_png() {
93
+ $chars = $this->get_chars( 25 );
94
+
95
+ return unpack( "N*", substr( $chars, 16, 8 ) );
96
+ }
97
+
98
+ private function parse_size_gif() {
99
+ $chars = $this->get_chars( 11 );
100
+
101
+ return unpack( "S*", substr( $chars, 6, 4 ) );
102
+ }
103
+
104
+ private function parse_size_bmp() {
105
+ $chars = $this->get_chars( 29 );
106
+ $chars = substr( $chars, 14, 14 );
107
+ $type = unpack( 'C', $chars );
108
+
109
+ return ( reset( $type ) == 40 ) ? unpack( 'L*', substr( $chars, 4 ) ) : unpack( 'L*', substr( $chars, 4, 8 ) );
110
+ }
111
+
112
+ private function parse_size_jpeg() {
113
+ $state = null;
114
+ $i = 0;
115
+
116
+ while ( true ) {
117
+ switch ( $state ) {
118
+ default:
119
+ $this->get_chars( 2 );
120
+ $state = 'started';
121
+ break;
122
+
123
+ case 'started':
124
+ $b = $this->get_byte();
125
+ if ( $b === false )
126
+ return false;
127
+
128
+ $state = $b == 0xFF ? 'sof' : 'started';
129
+ break;
130
+
131
+ case 'sof':
132
+ $b = $this->get_byte();
133
+ if ( in_array( $b, range( 0xe0, 0xef ) ) )
134
+ $state = 'skipframe';
135
+ elseif ( in_array( $b, array_merge( range( 0xC0, 0xC3 ), range( 0xC5, 0xC7 ), range( 0xC9, 0xCB ), range( 0xCD, 0xCF ) ) ) )
136
+ $state = 'readsize';
137
+ elseif ( $b == 0xFF )
138
+ $state = 'sof';
139
+ else
140
+ $state = 'skipframe';
141
+ break;
142
+
143
+ case 'skipframe':
144
+ $skip = $this->read_int( $this->get_chars( 2 ) ) - 2;
145
+ $state = 'doskip';
146
+ break;
147
+
148
+ case 'doskip':
149
+ $this->get_chars( $skip );
150
+ $state = 'started';
151
+ break;
152
+
153
+ case 'readsize':
154
+ $c = $this->get_chars( 7 );
155
+
156
+ return [ $this->read_int( substr( $c, 5, 2 ) ), $this->read_int( substr( $c, 3, 2 ) ) ];
157
+ }
158
+ }
159
+ }
160
+
161
+ private function get_chars( $n ) {
162
+ $response = null;
163
+
164
+ // do we need more data?
165
+ if ( $this->strpos + $n - 1 >= strlen( $this->str ) ) {
166
+ $end = ( $this->strpos + $n );
167
+
168
+ while ( strlen( $this->str ) < $end && $response !== false ) {
169
+ // read more from the file handle
170
+ $need = $end - ftell( $this->handle );
171
+
172
+ if ( $response = fread( $this->handle, $need ) )
173
+ $this->str .= $response;
174
+ else
175
+ return false;
176
+ }
177
+ }
178
+
179
+ $result = substr( $this->str, $this->strpos, $n );
180
+ $this->strpos += $n;
181
+
182
+ return $result;
183
+ }
184
+
185
+ private function get_byte() {
186
+ $c = $this->get_chars( 1 );
187
+ $b = unpack( "C", $c );
188
+
189
+ return reset( $b );
190
+ }
191
+
192
+ private function read_int( $str ) {
193
+ $size = unpack( "C*", $str );
194
+
195
+ return ( $size[1] << 8 ) + $size[2];
196
+ }
197
+
198
+ public function __destruct() {
199
+ $this->close();
200
+ }
201
  }
includes/class-folders.php CHANGED
@@ -11,15 +11,15 @@ if ( ! defined( 'ABSPATH' ) )
11
  class Responsive_Lightbox_Folders {
12
 
13
  private $mode = '';
14
- private $term_counters = array(
15
- 'keys' => array(),
16
- 'values' => array()
17
- );
18
 
19
  /**
20
  * Class constructor.
21
  *
22
- * @param bool $read_only Whether run this in read only mode
23
  * @return void
24
  */
25
  public function __construct( $read_only = false ) {
@@ -27,33 +27,32 @@ class Responsive_Lightbox_Folders {
27
  Responsive_Lightbox()->folders = $this;
28
 
29
  // allow to load old taxonomies even in read only mode
30
- add_action( 'wp_ajax_rl-folders-load-old-taxonomies', array( $this, 'load_old_taxonomies' ) );
31
 
32
  if ( $read_only )
33
  return;
34
 
35
  // actions
36
- add_action( 'init', array( $this, 'detect_library_mode' ), 11 );
37
- add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
38
- add_action( 'wp_enqueue_media', array( $this, 'add_library_scripts' ) );
39
- add_action( 'admin_enqueue_scripts', array( $this, 'add_library_scripts' ) );
40
- add_action( 'pre-upload-ui', array( $this, 'pre_upload_ui' ) );
41
- add_action( 'post-upload-ui', array( $this, 'post_upload_ui' ) );
42
- add_action( 'add_attachment', array( $this, 'add_attachment' ) );
43
- add_action( 'wp_ajax_save-attachment-compat', array( $this, 'ajax_save_attachment_compat' ), 0 );
44
- add_action( 'wp_ajax_rl-folders-delete-term', array( $this, 'delete_term' ) );
45
- add_action( 'wp_ajax_rl-folders-rename-term', array( $this, 'rename_term' ) );
46
- add_action( 'wp_ajax_rl-folders-add-term', array( $this, 'add_term' ) );
47
- add_action( 'wp_ajax_rl-folders-move-term', array( $this, 'move_term' ) );
48
- add_action( 'wp_ajax_rl-folders-get-terms', array( $this, 'get_terms' ) );
49
- add_action( 'wp_ajax_rl-folders-move-attachments', array( $this, 'move_attachments' ) );
50
 
51
  // filters
52
- add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
53
- add_filter( 'parse_query', array( $this, 'parse_query' ) );
54
- add_filter( 'ajax_query_attachments_args', array( $this, 'ajax_query_attachments_args' ) );
55
- add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
56
- add_filter( 'rl_count_attachments', array( $this, 'count_attachments' ), 10 );
57
  }
58
 
59
  /**
@@ -62,32 +61,44 @@ class Responsive_Lightbox_Folders {
62
  * @return void
63
  */
64
  public function load_old_taxonomies() {
65
- if ( isset( $_POST['taxonomies'], $_POST['nonce'] ) && is_array( $_POST['taxonomies'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-taxonomies-nonce' ) ) {
66
- $fields = $this->get_taxonomies();
 
67
 
68
- // any results?
69
- if ( ! empty( $fields ) ) {
70
- // remove main taxonomy
71
- if ( ( $key = array_search( 'rl_media_folder', $fields, true ) ) !== false )
72
- unset( $fields[$key] );
73
 
74
- // remove media tags
75
- if ( ( $key = array_search( 'rl_media_tag', $fields, true ) ) !== false )
76
- unset( $fields[$key] );
77
 
78
- foreach ( $_POST['taxonomies'] as $taxonomy ) {
79
- // remove available taxonomy
80
- if ( ( $key = array_search( $taxonomy, $fields, true ) ) !== false )
81
- unset( $fields[$key] );
82
- }
83
- }
 
 
84
 
85
- // send taxonomies, reindex them to avoid casting to an object in js
86
- wp_send_json_success( array( 'taxonomies' => array_values( $fields ) ) );
 
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
- // send JSON error
90
- wp_send_json_error();
 
91
  }
92
 
93
  /**
@@ -102,14 +113,18 @@ class Responsive_Lightbox_Folders {
102
 
103
  if ( $pagenow === 'upload.php' ) {
104
  // available modes
105
- $modes = array( 'grid', 'list' );
 
 
 
 
 
 
106
 
107
- // check $_GET mode
108
- if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes, true ) ) {
109
- $mode = $_GET['mode'];
110
- } else {
111
  // get user mode
112
- $user_mode = get_user_option( 'media_library_mode' );
113
 
114
  // valid user mode?
115
  if ( in_array( $user_mode, $modes, true ) )
@@ -123,9 +138,9 @@ class Responsive_Lightbox_Folders {
123
  $this->mode = $mode;
124
  }
125
 
126
- if ( $pagenow === 'upload.php' || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
127
  $this->rl_media_tag_terms = get_terms(
128
- array(
129
  'taxonomy' => 'rl_media_tag',
130
  'hide_empty' => false,
131
  'orderby' => 'name',
@@ -133,7 +148,7 @@ class Responsive_Lightbox_Folders {
133
  'number' => 0,
134
  'fields' => 'id=>name',
135
  'hierarchical' => false
136
- )
137
  );
138
  }
139
  }
@@ -167,17 +182,17 @@ class Responsive_Lightbox_Folders {
167
  private function get_folders( $taxonomy, $selected = 0 ) {
168
  // get only 1 term to check if taxonomy is empty
169
  $any_terms = get_terms(
170
- array(
171
  'taxonomy' => $taxonomy,
172
  'hide_empty' => false,
173
  'fields' => 'ids',
174
  'hierarchical' => false,
175
  'number' => 1
176
- )
177
  );
178
 
179
  // prepare dropdown categories parameters
180
- $args = array(
181
  'orderby' => 'name',
182
  'order' => 'asc',
183
  'show_option_all' => __( 'Root Folder', 'responsive-lightbox' ),
@@ -190,7 +205,7 @@ class Responsive_Lightbox_Folders {
190
  'id' => 'rl_folders_upload_files',
191
  'name' => 'rl_folders_upload_files_term_id',
192
  'taxonomy' => $taxonomy
193
- );
194
 
195
  // no terms?
196
  if ( ! is_wp_error( $any_terms ) && empty( $any_terms ) ) {
@@ -207,7 +222,7 @@ class Responsive_Lightbox_Folders {
207
  * @return void
208
  */
209
  public function pre_upload_ui() {
210
- add_filter( 'upload_post_params', array( $this, 'upload_post_params' ) );
211
  }
212
 
213
  /**
@@ -233,17 +248,17 @@ class Responsive_Lightbox_Folders {
233
 
234
  // get only 1 term to check if taxonomy is empty
235
  $any_terms = get_terms(
236
- array(
237
  'taxonomy' => $taxonomy,
238
  'hide_empty' => false,
239
  'fields' => 'ids',
240
  'hierarchical' => false,
241
  'number' => 1
242
- )
243
  );
244
 
245
  // prepare dropdown categories parameters
246
- $args = array(
247
  'orderby' => 'name',
248
  'order' => 'asc',
249
  'show_option_all' => __( 'Root Folder', 'responsive-lightbox' ),
@@ -256,7 +271,7 @@ class Responsive_Lightbox_Folders {
256
  'id' => 'rl_folders_upload_files',
257
  'name' => 'rl_folders_upload_files_term_id',
258
  'taxonomy' => $taxonomy
259
- );
260
 
261
  // no terms?
262
  if ( ! is_wp_error( $any_terms ) && empty( $any_terms ) ) {
@@ -265,7 +280,7 @@ class Responsive_Lightbox_Folders {
265
  }
266
 
267
  // display select
268
- echo '<p><label>' . __( 'Upload files to', 'responsive-lightbox' ) . ': ' . wp_dropdown_categories( $args ) . '</label></p>';
269
  }
270
 
271
  /**
@@ -303,7 +318,7 @@ class Responsive_Lightbox_Folders {
303
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
304
 
305
  $html = wp_dropdown_categories(
306
- array(
307
  'orderby' => 'name',
308
  'order' => 'asc',
309
  'id' => 'media-attachment-rl-folders-filters',
@@ -316,10 +331,13 @@ class Responsive_Lightbox_Folders {
316
  'taxonomy' => $taxonomy,
317
  'hide_if_empty' => true,
318
  'echo' => false
319
- )
320
  );
321
 
322
- echo ( $html === '' ? '<select name="' . $taxonomy . '" id="media-attachment-rl-folders-filters" class="postform"><option>' . __( 'All Files', 'responsive-lightbox' ) . '</option></select> ' : $html );
 
 
 
323
  }
324
  }
325
 
@@ -342,30 +360,30 @@ class Responsive_Lightbox_Folders {
342
  $tax_query = $query->get( 'tax_query' );
343
 
344
  if ( empty( $tax_query ) || ! is_array( $tax_query ) )
345
- $tax_query = array();
346
 
347
  // -1 === root, 0 === all files, >0 === term_id
348
  $term_id = (int) $_GET[$taxonomy];
349
 
350
  if ( $term_id !== 0 && ( $query->is_main_query() || empty( $query->query['rl_folders_root'] ) ) ) {
351
- $tax = array(
352
- 'taxonomy' => $taxonomy,
353
- 'field' => 'id'
354
- );
355
 
356
  // root folder?
357
  if ( $term_id === -1 ) {
358
  $tax['terms'] = 0;
359
  $tax['operator'] = 'NOT EXISTS';
360
  $tax['include_children'] = false;
361
- // specified term id
362
  } else {
363
  $tax['terms'] = $term_id;
364
  $tax['include_children'] = false;
365
  }
366
 
367
  // add new tax query
368
- $tax_query[] = array( 'relation' => 'AND', $tax );
369
 
370
  // set new tax query
371
  $query->set( 'tax_query', $tax_query );
@@ -386,27 +404,29 @@ class Responsive_Lightbox_Folders {
386
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
387
 
388
  if ( isset( $_POST['query'][$taxonomy] ) ) {
389
- if ( $_POST['query'][$taxonomy] === 'all' )
 
 
390
  return $query;
391
 
392
- $term_id = (int) $_POST['query'][$taxonomy];
393
 
394
  if ( $term_id < 0 )
395
  return $query;
396
 
397
  if ( empty( $query['tax_query'] ) || ! is_array( $query['tax_query'] ) )
398
- $query['tax_query'] = array();
399
 
400
- $query['tax_query'][] = array(
401
  'relation' => 'AND',
402
- array(
403
  'taxonomy' => $taxonomy,
404
  'field' => 'id',
405
  'terms' => $term_id,
406
  'include_children' => ( ! ( isset( $_POST['query']['include_children'] ) && $_POST['query']['include_children'] === 'false' ) ),
407
  'operator' => ( $term_id === 0 ? 'NOT EXISTS' : 'IN' )
408
- )
409
- );
410
  }
411
 
412
  return $query;
@@ -420,7 +440,7 @@ class Responsive_Lightbox_Folders {
420
  * @return array
421
  */
422
  public function attachment_fields_to_edit( $fields, $post ) {
423
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
424
  // get taxonomy option
425
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
426
 
@@ -432,13 +452,13 @@ class Responsive_Lightbox_Folders {
432
  return $fields;
433
 
434
  if ( empty( $tax['args'] ) )
435
- $tax['args'] = array();
436
 
437
- $ids = wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
438
 
439
  // get select HTML
440
  $dropdown = wp_dropdown_categories(
441
- array(
442
  'orderby' => 'name',
443
  'order' => 'asc',
444
  'show_option_none' => __( 'Root Folder', 'responsive-lightbox' ),
@@ -451,7 +471,7 @@ class Responsive_Lightbox_Folders {
451
  'taxonomy' => $taxonomy,
452
  'hide_if_empty' => false,
453
  'echo' => false
454
- )
455
  );
456
 
457
  $tax['input'] = 'html';
@@ -469,25 +489,27 @@ class Responsive_Lightbox_Folders {
469
  return $fields;
470
 
471
  if ( empty( $tax['args'] ) )
472
- $tax['args'] = array();
473
 
474
  $tags_html = '';
475
 
476
  // get terms
477
- $tags = wp_get_post_terms( $post->ID, 'rl_media_tag', array( 'fields' => 'id=>name' ) );
478
 
479
  // valid terms?
480
  if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
481
  foreach ( $tags as $tag_name ) {
482
- $tags_html .= '<option value="' . $tag_name . '" selected="selected">' . esc_html( $tag_name ) . '</li>';
483
  }
484
  } else
485
- $tags = array();
486
 
487
  // update input
488
  $tax['input'] = 'html';
 
 
489
  $tax['html'] = '
490
- <select class="rl-media-tag-select2" multiple="multiple" name="attachments[' . $post->ID . '][rl_media_tag]">
491
  ' . $tags_html . '
492
  </select>';
493
 
@@ -506,21 +528,37 @@ class Responsive_Lightbox_Folders {
506
  * @return void
507
  */
508
  function ajax_save_attachment_compat() {
509
- if ( ! isset( $_REQUEST['id'] ) || ( $id = (int) $_REQUEST['id'] ) <= 0 || empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][$id] ) )
 
510
  wp_send_json_error();
511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  check_ajax_referer( 'update-post_' . $id, 'nonce' );
513
 
514
  if ( ! current_user_can( 'edit_post', $id ) )
515
  wp_send_json_error();
516
 
 
517
  $post = get_post( $id, ARRAY_A );
518
 
519
- if ( $post['post_type'] !== 'attachment' )
520
  wp_send_json_error();
521
 
522
  // update attachment data if needed
523
- $post = apply_filters( 'attachment_fields_to_save', $post, $_REQUEST['attachments'][$id] );
524
 
525
  if ( isset( $post['errors'] ) )
526
  wp_send_json_error();
@@ -532,92 +570,83 @@ class Responsive_Lightbox_Folders {
532
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
533
 
534
  // first if needed?
535
- if ( isset( $_REQUEST['attachments'][$id][$taxonomy] ) )
536
- wp_set_object_terms( $id, (int) reset( array_map( 'trim', $_REQUEST['attachments'][$id][$taxonomy] ) ), $taxonomy, false );
537
  elseif ( isset( $_REQUEST[$taxonomy . '_term'] ) )
538
  wp_set_object_terms( $id, (int) $_REQUEST[$taxonomy . '_term'], $taxonomy, false );
539
  else
540
  wp_set_object_terms( $id, '', $taxonomy, false );
541
 
542
  // check media tags
543
- if ( isset( $_REQUEST['attachments'][$id]['rl_media_tag'] ) ) {
544
- $media_tags = explode( ',', $_REQUEST['attachments'][$id]['rl_media_tag'] );
545
 
546
- if ( is_array( $media_tags ) )
547
- $media_tags = array_filter( array_map( 'trim', $media_tags ) );
548
 
549
  // any media tags?
550
- if ( ! empty( $media_tags ) ) {
551
  wp_set_object_terms( $id, $media_tags, 'rl_media_tag', false );
552
- } else {
553
  wp_set_object_terms( $id, '', 'rl_media_tag', false );
554
- }
555
  }
556
 
557
- if ( ! ( $attachment = wp_prepare_attachment_for_js( $id ) ) )
 
 
 
 
558
  wp_send_json_error();
559
 
560
- // send JSON success
561
  wp_send_json_success( $attachment );
562
  }
563
 
564
  /**
565
- * Assign new term IDs to given attachment ID via AJAX in modal attachment edit screen.
566
  *
567
  * @return void
568
  */
569
- function get_terms() {
570
- $tags_html = '';
 
 
571
 
572
- $tags = wp_get_post_terms( $post->ID, 'rl_media_tag', array( 'fields' => 'id=>name' ) );
 
 
573
 
574
- if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
575
- foreach ( $tags as $tag_id => $tag_name ) {
576
- $tags_html .= '<option value="' . $tag_id . '" selected="selected">' . esc_html( $tag_name ) . '</li>';
577
- }
578
- } else
579
- $tags = array();
580
 
581
- if ( ! empty( $this->rl_media_tag_terms ) ) {
582
- foreach ( $this->rl_media_tag_terms as $tag_id => $tag_name ) {
583
- if ( ! array_key_exists( $tag_id, $tags ) )
584
- $tags_html .= '<option value="' . $tag_id . '">' . esc_html( $tag_name ) . '</li>';
585
- }
586
- }
587
- }
588
 
589
- /**
590
- * AJAX action to delete term.
591
- *
592
- * @return void
593
- */
594
- public function delete_term() {
595
- if ( isset( $_POST['term_id'], $_POST['nonce'], $_POST['children'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) && ( $term_id = (int) $_POST['term_id'] ) > 0 ) {
596
- // get taxonomy
597
- $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
598
 
599
- // delete children?
600
- if ( $_POST['children'] === '1' ) {
601
- // get term children
602
- $children = get_term_children( $term_id, $taxonomy );
603
-
604
- // found any children?
605
- if ( ! empty( $children ) && ! is_wp_error( $children ) ) {
606
- // reverse array to delete terms with no children first
607
- foreach ( array_reverse( $children ) as $child_id ) {
608
- // delete child
609
- wp_delete_term( $child_id, $taxonomy );
610
- }
 
611
  }
612
  }
613
-
614
- // delete parent
615
- if ( ! is_wp_error( wp_delete_term( $term_id, $taxonomy ) ) )
616
- wp_send_json_success( $this->get_folders( $taxonomy ) );
617
  }
618
 
619
- // send JSON error
620
- wp_send_json_error();
 
 
 
621
  }
622
 
623
  /**
@@ -626,14 +655,25 @@ class Responsive_Lightbox_Folders {
626
  * @return void
627
  */
628
  public function move_term() {
 
 
 
 
 
 
 
 
629
  // get taxonomy
630
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
631
 
632
- if ( isset( $_POST['parent_id'], $_POST['term_id'], $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) && ! is_wp_error( wp_update_term( (int) $_POST['term_id'], $taxonomy, array( 'parent' => (int) $_POST['parent_id'] ) ) ) )
633
- wp_send_json_success( $this->get_folders( $taxonomy ) );
634
 
635
- // send JSON error
636
- wp_send_json_error();
 
 
 
637
  }
638
 
639
  /**
@@ -642,57 +682,71 @@ class Responsive_Lightbox_Folders {
642
  * @return void
643
  */
644
  public function add_term() {
645
- if ( isset( $_POST['parent_id'], $_POST['name'], $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) ) {
646
- // get taxonomy
647
- $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
648
 
649
- // prepare data
650
- $original_slug = $slug = sanitize_title( $_POST['name'] );
651
- $parent_id = (int) $_POST['parent_id'];
652
-
653
- // get all term slugs
654
- $terms = get_terms(
655
- array(
656
- 'taxonomy' => $taxonomy,
657
- 'hide_empty' => false,
658
- 'number' => 0,
659
- 'fields' => 'id=>slug',
660
- 'hierarchical' => true
661
- )
662
- );
663
 
664
- // any terms?
665
- if ( ! is_wp_error( $terms ) && is_array( $terms ) && ! empty( $terms ) ) {
666
- $i = 2;
667
 
668
- // slug already exists? create unique one
669
- while ( in_array( $slug, $terms, true ) ) {
670
- $slug = $original_slug . '-' . $i ++;
671
- }
672
- }
673
 
674
- // add new term
675
- $term = wp_insert_term(
676
- $_POST['name'],
677
- $taxonomy,
678
- array(
679
- 'parent' => $parent_id,
680
- 'slug' => $slug
681
- )
682
- );
 
683
 
684
- // no errors?
685
- if ( ! is_wp_error( $term ) ) {
686
- $term = get_term( $term['term_id'], $taxonomy );
687
 
688
- // no errors?
689
- if ( ! is_wp_error( $term ) )
690
- wp_send_json_success( array( 'name' => $term->name, 'term_id' => $term->term_id, 'url' => admin_url( 'upload.php?mode=' . $this->mode . '&' . $taxonomy . '=' . $term->term_id ), 'select' => $this->get_folders( $taxonomy, $term->term_id ) ) );
691
  }
692
  }
693
 
694
- // send JSON error
695
- wp_send_json_error();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
696
  }
697
 
698
  /**
@@ -701,97 +755,127 @@ class Responsive_Lightbox_Folders {
701
  * @return void
702
  */
703
  public function rename_term() {
704
- if ( isset( $_POST['term_id'], $_POST['name'], $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) && ( $term_id = (int) $_POST['term_id'] ) > 0 ) {
705
- // get taxonomy
706
- $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
707
 
708
- // update term
709
- if ( ! is_wp_error( wp_update_term( $term_id, $taxonomy, array( 'name' => $_POST['name'] ) ) ) ) {
710
- $term = get_term( $term_id, $taxonomy );
711
 
712
- // no errors?
713
- if ( ! is_wp_error( $term ) )
714
- wp_send_json_success( array( 'name' => $term->name, 'select' => $this->get_folders( $taxonomy, $term_id ) ) );
715
- }
716
- }
 
 
 
 
 
 
 
 
 
 
 
 
717
 
718
- // send JSON error
719
- wp_send_json_error();
 
 
 
 
 
 
 
 
 
720
  }
721
 
722
  /**
723
- * AJAX action to assign new term to an attachment(s).
724
  *
725
  * @return void
726
  */
727
  public function move_attachments() {
728
- if ( isset( $_POST['attachment_ids'], $_POST['old_term_id'], $_POST['new_term_id'], $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) && is_array( $_POST['attachment_ids'] ) && ! empty( $_POST['attachment_ids'] ) ) {
729
- // get taxonomy
730
- $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
731
 
732
- // prepare data
733
- $ids = $all_terms = array();
734
- $attachments = array(
735
- 'success' => array(),
736
- 'failure' => array(),
737
- 'duplicated' => array()
738
- );
739
 
740
- // get only numeric values first
741
- foreach ( $_POST['attachment_ids'] as $id ) {
742
- if ( is_numeric( $id ) )
743
- $ids[] = (int) $id;
744
- }
 
 
 
 
 
 
745
 
746
- // filter unwanted data
747
- $ids = array_unique( array_filter( $ids ) );
748
 
749
- // no ids?
750
- if ( empty( $ids ) )
751
- wp_send_json_error();
752
 
753
- // prepare term ids
754
- $old_term_id = (int) $_POST['old_term_id'];
755
- $new_term_id = (int) $_POST['new_term_id'];
756
 
757
- // moving to root folder?
758
- if ( $new_term_id === 0 ) {
759
- foreach ( $ids as $id ) {
760
- // get attachment's term ids
761
- $all_terms[$id] = wp_get_object_terms( $id, $taxonomy, array( 'fields' => 'ids' ) );
762
 
763
- // remove all terms assigned to attachment
764
- if ( ! is_wp_error( wp_set_object_terms( $id, null, $taxonomy, false ) ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
  $attachments['success'][] = $id;
766
  else
767
  $attachments['failure'][] = $id;
768
  }
769
- } else {
770
- foreach ( $ids as $id ) {
771
- // get attachment's term ids
772
- $terms = wp_get_object_terms( $id, $taxonomy, array( 'fields' => 'ids' ) );
773
-
774
- // got terms?
775
- if ( ! is_wp_error( $terms ) ) {
776
- // save existing term (attachment already assigned to this term)
777
- if ( in_array( $new_term_id, $terms, true ) )
778
- $attachments['duplicated'][] = $id;
779
-
780
- // update attachment's term
781
- if ( ! is_wp_error( wp_set_object_terms( $id, $new_term_id, $taxonomy, false ) ) )
782
- $attachments['success'][] = $id;
783
- else
784
- $attachments['failure'][] = $id;
785
- }
786
- }
787
  }
788
-
789
- if ( ! empty( $attachments['success'] ) )
790
- wp_send_json_success( array( 'attachments' => $attachments, 'terms' => $all_terms ) );
791
  }
792
 
793
- // send JSON error
794
- wp_send_json_error();
 
 
 
 
 
 
 
 
795
  }
796
 
797
  /**
@@ -824,14 +908,15 @@ class Responsive_Lightbox_Folders {
824
  if ( $term !== false ) {
825
  $this->term_counters['keys'][] = $term->term_id;
826
 
827
- // set term ID
828
  $url_term_id = $term_id = $term->term_id;
829
  }
830
  }
831
  }
832
  }
833
 
834
- return 'href="' . esc_url( apply_filters( 'rl_folders_media_folder_url', add_query_arg( array( 'mode' => $this->mode, $taxonomy => $url_term_id ) ), $matches, $this->mode, $url_term_id ) ) . '" data-term_id="' . $term_id . '"';
 
835
  }
836
 
837
  /**
@@ -842,7 +927,7 @@ class Responsive_Lightbox_Folders {
842
  */
843
  public function replace_folders_count( $matches ) {
844
  if ( isset( $matches[1] ) ) {
845
- $count = (int) str_replace( array( ' ', '&nbsp;' ), '', $matches[1] );
846
  $this->term_counters['values'][] = $count;
847
 
848
  return ' (' . $count . ')</a>';
@@ -903,16 +988,20 @@ class Responsive_Lightbox_Folders {
903
  $rl = Responsive_Lightbox();
904
 
905
  // include select2 styles
906
- wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', array(), $rl->defaults['version'] );
907
 
908
  // filterable media folders taxonomy
909
  $taxonomy = get_taxonomy( $rl->options['folders']['media_taxonomy'] );
910
 
 
 
 
 
911
  // main script dependencies
912
- $dependencies = array( 'jquery', 'underscore', 'jquery-ui-draggable', 'jquery-ui-droppable', 'media-models', 'tags-suggest' );
913
 
914
  // create folder counters
915
- $counters = array();
916
 
917
  if ( $page !== 'media' ) {
918
  // prepare variables
@@ -937,10 +1026,18 @@ class Responsive_Lightbox_Folders {
937
  if ( empty( $current_color_scheme ) )
938
  $current_color_scheme = 'fresh';
939
 
940
- if ( isset( $_wp_admin_css_colors[$current_color_scheme] ) )
941
- $color = implode( ',', $rl->hex2rgb( $_wp_admin_css_colors[$current_color_scheme]->colors[3] ) );
 
 
 
 
 
 
 
942
  }
943
 
 
944
  wp_add_inline_style(
945
  'responsive-lightbox-folders-jstree',
946
  '#rl-folders-tree-container .jstree .rl-folders-state-active.rl-folders-state-hover {
@@ -956,8 +1053,8 @@ class Responsive_Lightbox_Folders {
956
  }'
957
  );
958
 
959
- // list categories parameters
960
- $categories = array(
961
  'orderby' => 'name',
962
  'order' => 'asc',
963
  'show_count' => true,
@@ -970,7 +1067,7 @@ class Responsive_Lightbox_Folders {
970
  'taxonomy' => $taxonomy->name,
971
  'hide_title_if_empty' => true,
972
  'echo' => false
973
- );
974
 
975
  // get current term id
976
  $term_id = isset( $_GET[$taxonomy->name] ) ? (int) $_GET[$taxonomy->name] : 0;
@@ -988,7 +1085,7 @@ class Responsive_Lightbox_Folders {
988
  ob_start();
989
 
990
  // display "no media" table row
991
- echo '<tr class="no-items"><td class="colspanchange" colspan="' . $wp_list_table->get_column_count() . '">';
992
 
993
  $wp_list_table->no_items();
994
 
@@ -1030,14 +1127,14 @@ class Responsive_Lightbox_Folders {
1030
 
1031
  if ( $html !== '' ) {
1032
  // fix for urls
1033
- $html = preg_replace_callback( '/href=(?:\'|")(.*?)(?:\'|")/', array( $this, 'replace_folders_href' ), $html );
1034
 
1035
  // fix for counters
1036
- $html = preg_replace_callback( '/<\/a> \(((?:\d+|&nbsp;)+)\)/', array( $this, 'replace_folders_count' ), $html );
1037
 
1038
  // open all needed folders at start
1039
  if ( $term_id > 0 )
1040
- $html = preg_replace_callback( '/class="cat-item cat-item-(\d+)(?:[a-z\s0-9-]+)?"/', array( $this, 'open_folders' ), $html );
1041
 
1042
  // check whether counters are valid
1043
  if ( ! ( empty( $this->term_counters['keys'] ) || empty( $this->term_counters['values'] ) || count( $this->term_counters['keys'] ) !== count( $this->term_counters['values'] ) ) ) {
@@ -1051,26 +1148,26 @@ class Responsive_Lightbox_Folders {
1051
  $root_query = new WP_Query(
1052
  apply_filters(
1053
  'rl_root_folder_query_args',
1054
- array(
1055
  'rl_folders_root' => true,
1056
  'posts_per_page' => -1,
1057
  'post_type' => 'attachment',
1058
  'post_status' => 'inherit,private',
1059
  'fields' => 'ids',
1060
  'no_found_rows' => false,
1061
- 'tax_query' => array(
1062
- array(
1063
  'relation' => 'AND',
1064
- array(
1065
  'taxonomy' => $taxonomy->name,
1066
  'field' => 'id',
1067
  'terms' => 0,
1068
  'include_children' => false,
1069
  'operator' => 'NOT EXISTS'
1070
- )
1071
- )
1072
- )
1073
- )
1074
  )
1075
  );
1076
 
@@ -1080,27 +1177,27 @@ class Responsive_Lightbox_Folders {
1080
  // set number of root attachments (not categorized)
1081
  $counters[0] = (int) $root_query->post_count;
1082
 
1083
-
1084
  $html = '
1085
  <ul>
1086
  <li class="cat-item cat-item-all"' . ( $term_id === 0 ? ' data-jstree=\'{ "selected": true }\'' : '' ) . '>
1087
- <a href="' . apply_filters( 'rl_folders_media_folder_url', add_query_arg( array( 'mode' => $this->mode, $taxonomy->name => 0 ) ), null, $this->mode, 0 ) . '" data-term_id="all">' . __( 'All Files', 'responsive-lightbox' ) . ' (' . $counters[-1] . ')</a>
1088
  </li>
1089
  <li class="cat-item cat-item-0" data-jstree=\'{ "opened": true' . ( $term_id === -1 ? ', "selected": true ' : '' ) . ' }\'>
1090
- <a href="' . apply_filters( 'rl_folders_media_folder_url', add_query_arg( array( 'mode' => $this->mode, $taxonomy->name => -1 ) ), null, $this->mode, -1 ) . '" data-term_id="0">' . __( 'Root Folder', 'responsive-lightbox' ) . ' (' . $counters[0] . ')</a>
1091
  <ul>' . $html . '</ul>
1092
  </li>
1093
  </ul>';
1094
 
1095
  // register scripts
1096
- wp_register_script( 'responsive-lightbox-folders-jstree', RESPONSIVE_LIGHTBOX_URL . '/assets/jstree/jstree' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array(), $rl->defaults['version'], false );
1097
- wp_register_script( 'responsive-lightbox-folders-perfect-scrollbar', RESPONSIVE_LIGHTBOX_URL . '/assets/perfect-scrollbar/perfect-scrollbar' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array(), $rl->defaults['version'], false );
1098
 
1099
  $dependencies[] = 'responsive-lightbox-folders-jstree';
1100
  $dependencies[] = 'responsive-lightbox-folders-perfect-scrollbar';
1101
  }
1102
 
1103
- wp_enqueue_script( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2.full' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', array( 'jquery' ), $rl->defaults['version'], false );
1104
 
1105
  wp_enqueue_script( 'responsive-lightbox-folders-admin', RESPONSIVE_LIGHTBOX_URL . '/js/admin-folders.js', $dependencies, $rl->defaults['version'], false );
1106
 
@@ -1108,15 +1205,15 @@ class Responsive_Lightbox_Folders {
1108
  wp_localize_script(
1109
  'responsive-lightbox-folders-admin',
1110
  'rlFoldersArgs',
1111
- array(
1112
- 'taxonomy' => $taxonomy->name,
1113
- 'page' => $page,
1114
- 'root' => __( 'Root Folder', 'responsive-lightbox' ),
1115
- 'terms' => wp_dropdown_categories(
1116
- array(
1117
  'orderby' => 'name',
1118
  'order' => 'asc',
1119
- 'show_option_all' => __( 'All Files', 'responsive-lightbox' ),
1120
  'show_count' => false,
1121
  'hide_empty' => false,
1122
  'hierarchical' => true,
@@ -1125,15 +1222,15 @@ class Responsive_Lightbox_Folders {
1125
  'taxonomy' => $taxonomy->name,
1126
  'hide_if_empty' => true,
1127
  'echo' => false
1128
- )
1129
  )
1130
- )
1131
  );
1132
  } else {
1133
  wp_localize_script(
1134
  'responsive-lightbox-folders-admin',
1135
  'rlFoldersArgs',
1136
- array(
1137
  'remove_children' => (int) $rl->options['folders']['folders_removal'],
1138
  'wholerow' => (int) $rl->options['folders']['jstree_wholerow'],
1139
  'theme' => 'default',
@@ -1141,17 +1238,17 @@ class Responsive_Lightbox_Folders {
1141
  'no_media_items' => $no_items,
1142
  'taxonomy' => $taxonomy->name,
1143
  'page' => $page,
1144
- 'root' => __( 'Root Folder', 'responsive-lightbox' ),
1145
- 'all_terms' => __( 'All Files', 'responsive-lightbox' ),
1146
- 'new_folder' => __( 'New Folder', 'responsive-lightbox' ),
1147
- 'delete_term' => __( 'Are you sure you want to delete this folder?', 'responsive-lightbox' ),
1148
- 'delete_terms' => __( 'Are you sure you want to delete this folder with all subfolders?', 'responsive-lightbox' ),
1149
  'nonce' => wp_create_nonce( 'rl-folders-ajax-library-nonce' ),
1150
  'terms' => wp_dropdown_categories(
1151
- array(
1152
  'orderby' => 'name',
1153
  'order' => 'asc',
1154
- 'show_option_all' => __( 'All Files', 'responsive-lightbox' ),
1155
  'show_count' => false,
1156
  'hide_empty' => false,
1157
  'hierarchical' => true,
@@ -1160,30 +1257,30 @@ class Responsive_Lightbox_Folders {
1160
  'taxonomy' => $taxonomy->name,
1161
  'hide_if_empty' => true,
1162
  'echo' => false
1163
- )
1164
  ),
1165
  'template' => '
1166
  <div id="rl-folders-tree-container">
1167
  <div class="media-toolbar wp-filter">
1168
  <div class="view-switch rl-folders-action-links">
1169
- <a href="#" title="' . $taxonomy->labels->add_new_item . '" class="dashicons dashicons-plus rl-folders-add-new-folder' . ( $this->mode === 'list' && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1170
- <a href="#" title="' . sprintf( __( 'Save new %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-yes rl-folders-save-new-folder" style="display: none;"></a>
1171
- <a href="#" title="' . sprintf( __( 'Cancel adding new %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-no rl-folders-cancel-new-folder" style="display: none;"></a>
1172
- <a href="#" title="' . $taxonomy->labels->edit_item . '" class="dashicons dashicons-edit rl-folders-rename-folder' . ( $this->mode === 'list' && $term_id > 0 ? '' : ' disabled-link' ) . '"></a>
1173
- <a href="#" title="' . sprintf( __( 'Save %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-yes rl-folders-save-folder" style="display: none;"></a>
1174
- <a href="#" title="' . sprintf( __( 'Cancel renaming %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-no rl-folders-cancel-folder" style="display: none;"></a>
1175
- <a href="#" title="' . sprintf( __( 'Delete %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-trash rl-folders-delete-folder' . ( $this->mode === 'list' && $term_id > 0 ? '' : ' disabled-link' ) . '"></a>
1176
- <a href="#" title="' . sprintf( __( 'Expand %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-arrow-down-alt2 rl-folders-expand-folder' . ( $this->mode === 'list' && ! $childless && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1177
- <a href="#" title="' . sprintf( __( 'Collapse %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) . '" class="dashicons dashicons-arrow-up-alt2 rl-folders-collapse-folder' . ( $this->mode === 'list' && ! $childless && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1178
  </div>
1179
  </div>
1180
  <div id="rl-folders-tree">' . esc_html( $html ) . '</div>
1181
  </div>'
1182
- )
1183
  );
1184
  }
1185
 
1186
- add_action( 'admin_print_styles', array( $this, 'admin_print_media_styles' ) );
1187
  }
1188
 
1189
  /**
@@ -1217,13 +1314,13 @@ class Responsive_Lightbox_Folders {
1217
  global $wpdb;
1218
 
1219
  // query
1220
- $fields = $wpdb->get_col( '
1221
  SELECT DISTINCT tt.taxonomy
1222
- FROM ' . $wpdb->prefix . 'term_taxonomy tt
1223
- LEFT JOIN ' . $wpdb->prefix . 'term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
1224
- LEFT JOIN ' . $wpdb->prefix . 'posts p ON p.ID = tr.object_id
1225
- WHERE p.post_type = \'attachment\'
1226
- ORDER BY tt.taxonomy ASC'
1227
  );
1228
 
1229
  if ( ! empty( $fields ) ) {
11
  class Responsive_Lightbox_Folders {
12
 
13
  private $mode = '';
14
+ private $term_counters = [
15
+ 'keys' => [],
16
+ 'values' => []
17
+ ];
18
 
19
  /**
20
  * Class constructor.
21
  *
22
+ * @param bool $read_only Whether plugin is in read only mode
23
  * @return void
24
  */
25
  public function __construct( $read_only = false ) {
27
  Responsive_Lightbox()->folders = $this;
28
 
29
  // allow to load old taxonomies even in read only mode
30
+ add_action( 'wp_ajax_rl-folders-load-old-taxonomies', [ $this, 'load_old_taxonomies' ] );
31
 
32
  if ( $read_only )
33
  return;
34
 
35
  // actions
36
+ add_action( 'init', [ $this, 'detect_library_mode' ], 11 );
37
+ add_action( 'restrict_manage_posts', [ $this, 'restrict_manage_posts' ] );
38
+ add_action( 'wp_enqueue_media', [ $this, 'add_library_scripts' ] );
39
+ add_action( 'admin_enqueue_scripts', [ $this, 'add_library_scripts' ] );
40
+ add_action( 'pre-upload-ui', [ $this, 'pre_upload_ui' ] );
41
+ add_action( 'post-upload-ui', [ $this, 'post_upload_ui' ] );
42
+ add_action( 'add_attachment', [ $this, 'add_attachment' ] );
43
+ add_action( 'wp_ajax_save-attachment-compat', [ $this, 'ajax_save_attachment_compat' ], 0 );
44
+ add_action( 'wp_ajax_rl-folders-delete-term', [ $this, 'delete_term' ] );
45
+ add_action( 'wp_ajax_rl-folders-rename-term', [ $this, 'rename_term' ] );
46
+ add_action( 'wp_ajax_rl-folders-add-term', [ $this, 'add_term' ] );
47
+ add_action( 'wp_ajax_rl-folders-move-term', [ $this, 'move_term' ] );
48
+ add_action( 'wp_ajax_rl-folders-move-attachments', [ $this, 'move_attachments' ] );
 
49
 
50
  // filters
51
+ add_filter( 'admin_body_class', [ $this, 'admin_body_class' ] );
52
+ add_filter( 'parse_query', [ $this, 'parse_query' ] );
53
+ add_filter( 'ajax_query_attachments_args', [ $this, 'ajax_query_attachments_args' ] );
54
+ add_filter( 'attachment_fields_to_edit', [ $this, 'attachment_fields_to_edit' ], 10, 2 );
55
+ add_filter( 'rl_count_attachments', [ $this, 'count_attachments' ], 10 );
56
  }
57
 
58
  /**
61
  * @return void
62
  */
63
  public function load_old_taxonomies() {
64
+ // no data?
65
+ if ( ! isset( $_POST['taxonomies'], $_POST['nonce'] ) )
66
+ wp_send_json_error();
67
 
68
+ // invalid taxonomies format?
69
+ if ( ! is_array( $_POST['taxonomies'] ) )
70
+ wp_send_json_error();
 
 
71
 
72
+ // invalid nonce?
73
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-taxonomies-nonce' ) )
74
+ wp_send_json_error();
75
 
76
+ // get all possible (current and previous) taxonomies
77
+ $fields = $this->get_taxonomies();
78
+
79
+ // any results?
80
+ if ( ! empty( $fields ) ) {
81
+ // remove main taxonomy
82
+ if ( ( $key = array_search( 'rl_media_folder', $fields, true ) ) !== false )
83
+ unset( $fields[$key] );
84
 
85
+ // remove media tags
86
+ if ( ( $key = array_search( 'rl_media_tag', $fields, true ) ) !== false )
87
+ unset( $fields[$key] );
88
+
89
+ // sanitize taxonomies
90
+ $taxonomies = array_map( 'santize_key', $_POST['taxonomies'] );
91
+
92
+ foreach ( $taxonomies as $taxonomy ) {
93
+ // remove available taxonomy
94
+ if ( ( $key = array_search( $taxonomy, $fields, true ) ) !== false )
95
+ unset( $fields[$key] );
96
+ }
97
  }
98
 
99
+ // send taxonomies, reindex them to avoid casting to an object in js
100
+ wp_send_json_success( [ 'taxonomies' => array_values( $fields ) ] );
101
+
102
  }
103
 
104
  /**
113
 
114
  if ( $pagenow === 'upload.php' ) {
115
  // available modes
116
+ $modes = [ 'grid', 'list' ];
117
+
118
+ // sanitize mode
119
+ if ( isset( $_GET['mode'] ) )
120
+ $mode = sanitize_key( $_GET['mode'] );
121
+ else
122
+ $mode = '';
123
 
124
+ // check mode
125
+ if ( ! ( $mode && ctype_lower( $mode ) && in_array( $mode, $modes, true ) ) ) {
 
 
126
  // get user mode
127
+ $user_mode = (string) get_user_option( 'media_library_mode' );
128
 
129
  // valid user mode?
130
  if ( in_array( $user_mode, $modes, true ) )
138
  $this->mode = $mode;
139
  }
140
 
141
+ if ( $pagenow === 'upload.php' || wp_doing_ajax() ) {
142
  $this->rl_media_tag_terms = get_terms(
143
+ [
144
  'taxonomy' => 'rl_media_tag',
145
  'hide_empty' => false,
146
  'orderby' => 'name',
148
  'number' => 0,
149
  'fields' => 'id=>name',
150
  'hierarchical' => false
151
+ ]
152
  );
153
  }
154
  }
182
  private function get_folders( $taxonomy, $selected = 0 ) {
183
  // get only 1 term to check if taxonomy is empty
184
  $any_terms = get_terms(
185
+ [
186
  'taxonomy' => $taxonomy,
187
  'hide_empty' => false,
188
  'fields' => 'ids',
189
  'hierarchical' => false,
190
  'number' => 1
191
+ ]
192
  );
193
 
194
  // prepare dropdown categories parameters
195
+ $args = [
196
  'orderby' => 'name',
197
  'order' => 'asc',
198
  'show_option_all' => __( 'Root Folder', 'responsive-lightbox' ),
205
  'id' => 'rl_folders_upload_files',
206
  'name' => 'rl_folders_upload_files_term_id',
207
  'taxonomy' => $taxonomy
208
+ ];
209
 
210
  // no terms?
211
  if ( ! is_wp_error( $any_terms ) && empty( $any_terms ) ) {
222
  * @return void
223
  */
224
  public function pre_upload_ui() {
225
+ add_filter( 'upload_post_params', [ $this, 'upload_post_params' ] );
226
  }
227
 
228
  /**
248
 
249
  // get only 1 term to check if taxonomy is empty
250
  $any_terms = get_terms(
251
+ [
252
  'taxonomy' => $taxonomy,
253
  'hide_empty' => false,
254
  'fields' => 'ids',
255
  'hierarchical' => false,
256
  'number' => 1
257
+ ]
258
  );
259
 
260
  // prepare dropdown categories parameters
261
+ $args = [
262
  'orderby' => 'name',
263
  'order' => 'asc',
264
  'show_option_all' => __( 'Root Folder', 'responsive-lightbox' ),
271
  'id' => 'rl_folders_upload_files',
272
  'name' => 'rl_folders_upload_files_term_id',
273
  'taxonomy' => $taxonomy
274
+ ];
275
 
276
  // no terms?
277
  if ( ! is_wp_error( $any_terms ) && empty( $any_terms ) ) {
280
  }
281
 
282
  // display select
283
+ echo '<p><label>' . esc_html__( 'Upload files to', 'responsive-lightbox' ) . ': ' . wp_dropdown_categories( $args ) . '</label></p>';
284
  }
285
 
286
  /**
318
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
319
 
320
  $html = wp_dropdown_categories(
321
+ [
322
  'orderby' => 'name',
323
  'order' => 'asc',
324
  'id' => 'media-attachment-rl-folders-filters',
331
  'taxonomy' => $taxonomy,
332
  'hide_if_empty' => true,
333
  'echo' => false
334
+ ]
335
  );
336
 
337
+ if ( $html === '' )
338
+ echo '<select name="' . esc_attr( $taxonomy ) . '" id="media-attachment-rl-folders-filters" class="postform"><option>' . esc_html__( 'All Files', 'responsive-lightbox' ) . '</option></select> ';
339
+ else
340
+ echo $html;
341
  }
342
  }
343
 
360
  $tax_query = $query->get( 'tax_query' );
361
 
362
  if ( empty( $tax_query ) || ! is_array( $tax_query ) )
363
+ $tax_query = [];
364
 
365
  // -1 === root, 0 === all files, >0 === term_id
366
  $term_id = (int) $_GET[$taxonomy];
367
 
368
  if ( $term_id !== 0 && ( $query->is_main_query() || empty( $query->query['rl_folders_root'] ) ) ) {
369
+ $tax = [
370
+ 'taxonomy' => $taxonomy,
371
+ 'field' => 'id'
372
+ ];
373
 
374
  // root folder?
375
  if ( $term_id === -1 ) {
376
  $tax['terms'] = 0;
377
  $tax['operator'] = 'NOT EXISTS';
378
  $tax['include_children'] = false;
379
+ // specified term id
380
  } else {
381
  $tax['terms'] = $term_id;
382
  $tax['include_children'] = false;
383
  }
384
 
385
  // add new tax query
386
+ $tax_query[] = [ 'relation' => 'AND', $tax ];
387
 
388
  // set new tax query
389
  $query->set( 'tax_query', $tax_query );
404
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
405
 
406
  if ( isset( $_POST['query'][$taxonomy] ) ) {
407
+ $term_id = sanitize_key( $_POST['query'][$taxonomy] );
408
+
409
+ if ( $term_id === 'all' )
410
  return $query;
411
 
412
+ $term_id = (int) $term_id;
413
 
414
  if ( $term_id < 0 )
415
  return $query;
416
 
417
  if ( empty( $query['tax_query'] ) || ! is_array( $query['tax_query'] ) )
418
+ $query['tax_query'] = [];
419
 
420
+ $query['tax_query'][] = [
421
  'relation' => 'AND',
422
+ [
423
  'taxonomy' => $taxonomy,
424
  'field' => 'id',
425
  'terms' => $term_id,
426
  'include_children' => ( ! ( isset( $_POST['query']['include_children'] ) && $_POST['query']['include_children'] === 'false' ) ),
427
  'operator' => ( $term_id === 0 ? 'NOT EXISTS' : 'IN' )
428
+ ]
429
+ ];
430
  }
431
 
432
  return $query;
440
  * @return array
441
  */
442
  public function attachment_fields_to_edit( $fields, $post ) {
443
+ if ( wp_doing_ajax() ) {
444
  // get taxonomy option
445
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
446
 
452
  return $fields;
453
 
454
  if ( empty( $tax['args'] ) )
455
+ $tax['args'] = [];
456
 
457
+ $ids = wp_get_post_terms( $post->ID, $taxonomy, [ 'fields' => 'ids' ] );
458
 
459
  // get select HTML
460
  $dropdown = wp_dropdown_categories(
461
+ [
462
  'orderby' => 'name',
463
  'order' => 'asc',
464
  'show_option_none' => __( 'Root Folder', 'responsive-lightbox' ),
471
  'taxonomy' => $taxonomy,
472
  'hide_if_empty' => false,
473
  'echo' => false
474
+ ]
475
  );
476
 
477
  $tax['input'] = 'html';
489
  return $fields;
490
 
491
  if ( empty( $tax['args'] ) )
492
+ $tax['args'] = [];
493
 
494
  $tags_html = '';
495
 
496
  // get terms
497
+ $tags = wp_get_post_terms( $post->ID, 'rl_media_tag', [ 'fields' => 'id=>name' ] );
498
 
499
  // valid terms?
500
  if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
501
  foreach ( $tags as $tag_name ) {
502
+ $tags_html .= '<option value="' . esc_attr( $tag_name ) . '" selected="selected">' . esc_html( $tag_name ) . '</li>';
503
  }
504
  } else
505
+ $tags = [];
506
 
507
  // update input
508
  $tax['input'] = 'html';
509
+
510
+ // $tags_html is already escaped here
511
  $tax['html'] = '
512
+ <select class="rl-media-tag-select2" multiple="multiple" name="attachments[' . (int) $post->ID . '][rl_media_tag]">
513
  ' . $tags_html . '
514
  </select>';
515
 
528
  * @return void
529
  */
530
  function ajax_save_attachment_compat() {
531
+ // no attachment id?
532
+ if ( ! isset( $_REQUEST['id'] ) )
533
  wp_send_json_error();
534
 
535
+ $id = (int) $_REQUEST['id'];
536
+
537
+ // invalid id?
538
+ if ( $id <= 0 )
539
+ wp_send_json_error();
540
+
541
+ // no valid data?
542
+ if ( empty( $_REQUEST['attachments'][$id] ) || ! is_array( $_REQUEST['attachments'][$id] ) )
543
+ wp_send_json_error();
544
+
545
+ // no sanitization like in wordpress core: wp_ajax_save_attachment_compat() function
546
+ $attachment_data = $_REQUEST['attachments'][$id];
547
+
548
+ // check nonce
549
  check_ajax_referer( 'update-post_' . $id, 'nonce' );
550
 
551
  if ( ! current_user_can( 'edit_post', $id ) )
552
  wp_send_json_error();
553
 
554
+ // get post
555
  $post = get_post( $id, ARRAY_A );
556
 
557
+ if ( empty( $post ) || $post['post_type'] !== 'attachment' )
558
  wp_send_json_error();
559
 
560
  // update attachment data if needed
561
+ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
562
 
563
  if ( isset( $post['errors'] ) )
564
  wp_send_json_error();
570
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
571
 
572
  // first if needed?
573
+ if ( isset( $attachment_data[$taxonomy] ) )
574
+ wp_set_object_terms( $id, (int) reset( array_map( 'trim', $attachment_data[$taxonomy] ) ), $taxonomy, false );
575
  elseif ( isset( $_REQUEST[$taxonomy . '_term'] ) )
576
  wp_set_object_terms( $id, (int) $_REQUEST[$taxonomy . '_term'], $taxonomy, false );
577
  else
578
  wp_set_object_terms( $id, '', $taxonomy, false );
579
 
580
  // check media tags
581
+ if ( isset( $attachment_data['rl_media_tag'] ) && is_string( $attachment_data['rl_media_tag'] ) ) {
582
+ $media_tags = explode( ',', $attachment_data['rl_media_tag'] );
583
 
584
+ if ( ! empty( $media_tags ) && is_array( $media_tags ) )
585
+ $media_tags = array_filter( array_map( 'sanitize_title', $media_tags ) );
586
 
587
  // any media tags?
588
+ if ( ! empty( $media_tags ) )
589
  wp_set_object_terms( $id, $media_tags, 'rl_media_tag', false );
590
+ else
591
  wp_set_object_terms( $id, '', 'rl_media_tag', false );
 
592
  }
593
 
594
+ // get attachment data
595
+ $attachment = wp_prepare_attachment_for_js( $id );
596
+
597
+ // invalid attachment?
598
+ if ( ! $attachment )
599
  wp_send_json_error();
600
 
601
+ // finally send success
602
  wp_send_json_success( $attachment );
603
  }
604
 
605
  /**
606
+ * AJAX action to delete term.
607
  *
608
  * @return void
609
  */
610
+ public function delete_term() {
611
+ // no data?
612
+ if ( ! isset( $_POST['term_id'], $_POST['nonce'], $_POST['children'] ) )
613
+ wp_send_json_error();
614
 
615
+ // invalid nonce?
616
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) )
617
+ wp_send_json_error();
618
 
619
+ // sanitize term id
620
+ $term_id = (int) $_POST['term_id'];
 
 
 
 
621
 
622
+ if ( $term_id <= 0 )
623
+ wp_send_json_error();
 
 
 
 
 
624
 
625
+ // get taxonomy
626
+ $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
 
 
 
 
 
 
 
627
 
628
+ $remove_children = (int) $_POST['children'];
629
+
630
+ // delete children?
631
+ if ( $remove_children === 1 ) {
632
+ // get term children
633
+ $children = get_term_children( $term_id, $taxonomy );
634
+
635
+ // found any children?
636
+ if ( ! empty( $children ) && ! is_wp_error( $children ) ) {
637
+ // reverse array to delete terms with no children first
638
+ foreach ( array_reverse( $children ) as $child_id ) {
639
+ // delete child
640
+ wp_delete_term( $child_id, $taxonomy );
641
  }
642
  }
 
 
 
 
643
  }
644
 
645
+ // delete parent
646
+ if ( is_wp_error( wp_delete_term( $term_id, $taxonomy ) ) )
647
+ wp_send_json_error();
648
+ else
649
+ wp_send_json_success( $this->get_folders( $taxonomy ) );
650
  }
651
 
652
  /**
655
  * @return void
656
  */
657
  public function move_term() {
658
+ // no data?
659
+ if ( ! isset( $_POST['parent_id'], $_POST['term_id'], $_POST['nonce'] ) )
660
+ wp_send_json_error();
661
+
662
+ // invalid nonce?
663
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) )
664
+ wp_send_json_error();
665
+
666
  // get taxonomy
667
  $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
668
 
669
+ // update term
670
+ $update = wp_update_term( (int) $_POST['term_id'], $taxonomy, [ 'parent' => (int) $_POST['parent_id'] ] );
671
 
672
+ // error?
673
+ if ( is_wp_error( $update ) )
674
+ wp_send_json_error();
675
+ else
676
+ wp_send_json_success( $this->get_folders( $taxonomy ) );
677
  }
678
 
679
  /**
682
  * @return void
683
  */
684
  public function add_term() {
685
+ // no data?
686
+ if ( ! isset( $_POST['parent_id'], $_POST['name'], $_POST['nonce'] ) )
687
+ wp_send_json_error();
688
 
689
+ // invalid nonce?
690
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) )
691
+ wp_send_json_error();
 
 
 
 
 
 
 
 
 
 
 
692
 
693
+ // get taxonomy
694
+ $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
 
695
 
696
+ // prepare data
697
+ $original_slug = $slug = sanitize_title( $_POST['name'] );
698
+ $parent_id = (int) $_POST['parent_id'];
 
 
699
 
700
+ // get all term slugs
701
+ $terms = get_terms(
702
+ [
703
+ 'taxonomy' => $taxonomy,
704
+ 'hide_empty' => false,
705
+ 'number' => 0,
706
+ 'fields' => 'id=>slug',
707
+ 'hierarchical' => true
708
+ ]
709
+ );
710
 
711
+ // any terms?
712
+ if ( ! is_wp_error( $terms ) && is_array( $terms ) && ! empty( $terms ) ) {
713
+ $i = 2;
714
 
715
+ // slug already exists? create unique one
716
+ while ( in_array( $slug, $terms, true ) ) {
717
+ $slug = $original_slug . '-' . $i ++;
718
  }
719
  }
720
 
721
+ // add new term, name is sanitized inside wp_insert_term with sanitize_term function
722
+ $term = wp_insert_term(
723
+ $_POST['name'],
724
+ $taxonomy,
725
+ [
726
+ 'parent' => $parent_id,
727
+ 'slug' => $slug
728
+ ]
729
+ );
730
+
731
+ // error?
732
+ if ( is_wp_error( $term ) )
733
+ wp_send_json_error();
734
+
735
+ $term = get_term( $term['term_id'], $taxonomy );
736
+
737
+ // error?
738
+ if ( is_wp_error( $term ) )
739
+ wp_send_json_error();
740
+ else {
741
+ wp_send_json_success(
742
+ [
743
+ 'name' => $term->name,
744
+ 'term_id' => $term->term_id,
745
+ 'url' => admin_url( 'upload.php?mode=' . $this->mode . '&' . $taxonomy . '=' . $term->term_id ),
746
+ 'select' => $this->get_folders( $taxonomy, $term->term_id )
747
+ ]
748
+ );
749
+ }
750
  }
751
 
752
  /**
755
  * @return void
756
  */
757
  public function rename_term() {
758
+ // no data?
759
+ if ( ! isset( $_POST['term_id'], $_POST['name'], $_POST['nonce'] ) )
760
+ wp_send_json_error();
761
 
762
+ // invalid nonce?
763
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) )
764
+ wp_send_json_error();
765
 
766
+ // sanitize term id
767
+ $term_id = (int) $_POST['term_id'];
768
+
769
+ if ( $term_id <= 0 )
770
+ wp_send_json_error();
771
+
772
+ // get taxonomy
773
+ $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
774
+
775
+ // update term, name is sanitized inside wp_update_term with sanitize_term function
776
+ $update = wp_update_term( $term_id, $taxonomy, [ 'name' => $_POST['name'] ] );
777
+
778
+ // error?
779
+ if ( is_wp_error( $update ) )
780
+ wp_send_json_error();
781
+
782
+ $term = get_term( $term_id, $taxonomy );
783
 
784
+ // error?
785
+ if ( is_wp_error( $term ) )
786
+ wp_send_json_error();
787
+ else {
788
+ wp_send_json_success(
789
+ [
790
+ 'name' => $term->name,
791
+ 'select' => $this->get_folders( $taxonomy, $term_id )
792
+ ]
793
+ );
794
+ }
795
  }
796
 
797
  /**
798
+ * AJAX action to assign new term to attachments.
799
  *
800
  * @return void
801
  */
802
  public function move_attachments() {
803
+ // no data?
804
+ if ( ! isset( $_POST['attachment_ids'], $_POST['old_term_id'], $_POST['new_term_id'], $_POST['nonce'] ) )
805
+ wp_send_json_error();
806
 
807
+ // invalid nonce?
808
+ if ( ! ctype_alnum( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rl-folders-ajax-library-nonce' ) )
809
+ wp_send_json_error();
 
 
 
 
810
 
811
+ // not empty attachment ids array?
812
+ if ( empty( $_POST['attachment_ids'] ) || ! is_array( $_POST['attachment_ids'] ) )
813
+ wp_send_json_error();
814
+
815
+ // prepare data
816
+ $ids = $all_terms = [];
817
+ $attachments = [
818
+ 'success' => [],
819
+ 'failure' => [],
820
+ 'duplicated' => []
821
+ ];
822
 
823
+ // filter unwanted data
824
+ $ids = array_unique( array_filter( array_map( 'intval', $_POST['attachment_ids'] ) ) );
825
 
826
+ // no ids?
827
+ if ( empty( $ids ) )
828
+ wp_send_json_error();
829
 
830
+ // prepare term ids
831
+ $old_term_id = (int) $_POST['old_term_id'];
832
+ $new_term_id = (int) $_POST['new_term_id'];
833
 
834
+ // get taxonomy
835
+ $taxonomy = Responsive_Lightbox()->options['folders']['media_taxonomy'];
 
 
 
836
 
837
+ // moving to root folder?
838
+ if ( $new_term_id === 0 ) {
839
+ foreach ( $ids as $id ) {
840
+ // get attachment term ids
841
+ $all_terms[$id] = wp_get_object_terms( $id, $taxonomy, [ 'fields' => 'ids' ] );
842
+
843
+ // remove all terms assigned to attachment
844
+ if ( ! is_wp_error( wp_set_object_terms( $id, null, $taxonomy, false ) ) )
845
+ $attachments['success'][] = $id;
846
+ else
847
+ $attachments['failure'][] = $id;
848
+ }
849
+ } else {
850
+ foreach ( $ids as $id ) {
851
+ // get attachment term ids
852
+ $terms = wp_get_object_terms( $id, $taxonomy, [ 'fields' => 'ids' ] );
853
+
854
+ // got terms?
855
+ if ( ! is_wp_error( $terms ) ) {
856
+ // save existing term (attachment already assigned to this term)
857
+ if ( in_array( $new_term_id, $terms, true ) )
858
+ $attachments['duplicated'][] = $id;
859
+
860
+ // update attachment's term
861
+ if ( ! is_wp_error( wp_set_object_terms( $id, $new_term_id, $taxonomy, false ) ) )
862
  $attachments['success'][] = $id;
863
  else
864
  $attachments['failure'][] = $id;
865
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
  }
 
 
 
867
  }
868
 
869
+ if ( empty( $attachments['success'] ) )
870
+ wp_send_json_error();
871
+ else {
872
+ wp_send_json_success(
873
+ [
874
+ 'attachments' => $attachments,
875
+ 'terms' => $all_terms
876
+ ]
877
+ );
878
+ }
879
  }
880
 
881
  /**
908
  if ( $term !== false ) {
909
  $this->term_counters['keys'][] = $term->term_id;
910
 
911
+ // set term id
912
  $url_term_id = $term_id = $term->term_id;
913
  }
914
  }
915
  }
916
  }
917
 
918
+ // escape url early
919
+ return 'href="' . esc_url( apply_filters( 'rl_folders_media_folder_url', add_query_arg( [ 'mode' => $this->mode, $taxonomy => $url_term_id ] ), $matches, $this->mode, $url_term_id ) ) . '" data-term_id="' . $term_id . '"';
920
  }
921
 
922
  /**
927
  */
928
  public function replace_folders_count( $matches ) {
929
  if ( isset( $matches[1] ) ) {
930
+ $count = (int) str_replace( [ ' ', '&nbsp;' ], '', $matches[1] );
931
  $this->term_counters['values'][] = $count;
932
 
933
  return ' (' . $count . ')</a>';
988
  $rl = Responsive_Lightbox();
989
 
990
  // include select2 styles
991
+ wp_enqueue_style( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', [], $rl->defaults['version'] );
992
 
993
  // filterable media folders taxonomy
994
  $taxonomy = get_taxonomy( $rl->options['folders']['media_taxonomy'] );
995
 
996
+ // no taxonomy? it should be available here, updated in init_folders method
997
+ if ( $taxonomy === false )
998
+ return;
999
+
1000
  // main script dependencies
1001
+ $dependencies = [ 'jquery', 'underscore', 'jquery-ui-draggable', 'jquery-ui-droppable', 'media-models', 'tags-suggest' ];
1002
 
1003
  // create folder counters
1004
+ $counters = [];
1005
 
1006
  if ( $page !== 'media' ) {
1007
  // prepare variables
1026
  if ( empty( $current_color_scheme ) )
1027
  $current_color_scheme = 'fresh';
1028
 
1029
+ // color exists? some schemes don't have 4 colors
1030
+ if ( isset( $_wp_admin_css_colors[$current_color_scheme] ) && property_exists( $_wp_admin_css_colors[$current_color_scheme], 'colors' ) && isset( $_wp_admin_css_colors[$current_color_scheme]->colors[3] ) ) {
1031
+ // convert color
1032
+ $rgb = $rl->hex2rgb( $_wp_admin_css_colors[$current_color_scheme]->colors[3] );
1033
+
1034
+ // valid color?
1035
+ if ( $rgb !== false )
1036
+ $color = implode( ',', $rgb );
1037
+ }
1038
  }
1039
 
1040
+ // $color is already validated, no escaping
1041
  wp_add_inline_style(
1042
  'responsive-lightbox-folders-jstree',
1043
  '#rl-folders-tree-container .jstree .rl-folders-state-active.rl-folders-state-hover {
1053
  }'
1054
  );
1055
 
1056
+ // list categories parameters
1057
+ $categories = [
1058
  'orderby' => 'name',
1059
  'order' => 'asc',
1060
  'show_count' => true,
1067
  'taxonomy' => $taxonomy->name,
1068
  'hide_title_if_empty' => true,
1069
  'echo' => false
1070
+ ];
1071
 
1072
  // get current term id
1073
  $term_id = isset( $_GET[$taxonomy->name] ) ? (int) $_GET[$taxonomy->name] : 0;
1085
  ob_start();
1086
 
1087
  // display "no media" table row
1088
+ echo '<tr class="no-items"><td class="colspanchange" colspan="' . (int) $wp_list_table->get_column_count() . '">';
1089
 
1090
  $wp_list_table->no_items();
1091
 
1127
 
1128
  if ( $html !== '' ) {
1129
  // fix for urls
1130
+ $html = preg_replace_callback( '/href=(?:\'|")(.*?)(?:\'|")/', [ $this, 'replace_folders_href' ], $html );
1131
 
1132
  // fix for counters
1133
+ $html = preg_replace_callback( '/<\/a> \(((?:\d+|&nbsp;)+)\)/', [ $this, 'replace_folders_count' ], $html );
1134
 
1135
  // open all needed folders at start
1136
  if ( $term_id > 0 )
1137
+ $html = preg_replace_callback( '/class="cat-item cat-item-(\d+)(?:[a-z\s0-9-]+)?"/', [ $this, 'open_folders' ], $html );
1138
 
1139
  // check whether counters are valid
1140
  if ( ! ( empty( $this->term_counters['keys'] ) || empty( $this->term_counters['values'] ) || count( $this->term_counters['keys'] ) !== count( $this->term_counters['values'] ) ) ) {
1148
  $root_query = new WP_Query(
1149
  apply_filters(
1150
  'rl_root_folder_query_args',
1151
+ [
1152
  'rl_folders_root' => true,
1153
  'posts_per_page' => -1,
1154
  'post_type' => 'attachment',
1155
  'post_status' => 'inherit,private',
1156
  'fields' => 'ids',
1157
  'no_found_rows' => false,
1158
+ 'tax_query' => [
1159
+ [
1160
  'relation' => 'AND',
1161
+ [
1162
  'taxonomy' => $taxonomy->name,
1163
  'field' => 'id',
1164
  'terms' => 0,
1165
  'include_children' => false,
1166
  'operator' => 'NOT EXISTS'
1167
+ ]
1168
+ ]
1169
+ ]
1170
+ ]
1171
  )
1172
  );
1173
 
1177
  // set number of root attachments (not categorized)
1178
  $counters[0] = (int) $root_query->post_count;
1179
 
1180
+ // $html is escaped at the end
1181
  $html = '
1182
  <ul>
1183
  <li class="cat-item cat-item-all"' . ( $term_id === 0 ? ' data-jstree=\'{ "selected": true }\'' : '' ) . '>
1184
+ <a href="' . esc_url( apply_filters( 'rl_folders_media_folder_url', add_query_arg( [ 'mode' => $this->mode, $taxonomy->name => 0 ] ), null, $this->mode, 0 ) ) . '" data-term_id="all">' . esc_html__( 'All Files', 'responsive-lightbox' ) . ' (' . (int) $counters[-1] . ')</a>
1185
  </li>
1186
  <li class="cat-item cat-item-0" data-jstree=\'{ "opened": true' . ( $term_id === -1 ? ', "selected": true ' : '' ) . ' }\'>
1187
+ <a href="' . esc_url( apply_filters( 'rl_folders_media_folder_url', add_query_arg( [ 'mode' => $this->mode, $taxonomy->name => -1 ] ), null, $this->mode, -1 ) ) . '" data-term_id="0">' . esc_html__( 'Root Folder', 'responsive-lightbox' ) . ' (' . (int) $counters[0] . ')</a>
1188
  <ul>' . $html . '</ul>
1189
  </li>
1190
  </ul>';
1191
 
1192
  // register scripts
1193
+ wp_register_script( 'responsive-lightbox-folders-jstree', RESPONSIVE_LIGHTBOX_URL . '/assets/jstree/jstree' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', [], $rl->defaults['version'], false );
1194
+ wp_register_script( 'responsive-lightbox-folders-perfect-scrollbar', RESPONSIVE_LIGHTBOX_URL . '/assets/perfect-scrollbar/perfect-scrollbar' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', [], $rl->defaults['version'], false );
1195
 
1196
  $dependencies[] = 'responsive-lightbox-folders-jstree';
1197
  $dependencies[] = 'responsive-lightbox-folders-perfect-scrollbar';
1198
  }
1199
 
1200
+ wp_enqueue_script( 'responsive-lightbox-admin-select2', RESPONSIVE_LIGHTBOX_URL . '/assets/select2/select2.full' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', [ 'jquery' ], $rl->defaults['version'], false );
1201
 
1202
  wp_enqueue_script( 'responsive-lightbox-folders-admin', RESPONSIVE_LIGHTBOX_URL . '/js/admin-folders.js', $dependencies, $rl->defaults['version'], false );
1203
 
1205
  wp_localize_script(
1206
  'responsive-lightbox-folders-admin',
1207
  'rlFoldersArgs',
1208
+ [
1209
+ 'taxonomy' => $taxonomy->name,
1210
+ 'page' => $page,
1211
+ 'root' => esc_html__( 'Root Folder', 'responsive-lightbox' ),
1212
+ 'terms' => wp_dropdown_categories(
1213
+ [
1214
  'orderby' => 'name',
1215
  'order' => 'asc',
1216
+ 'show_option_all' => esc_html__( 'All Files', 'responsive-lightbox' ),
1217
  'show_count' => false,
1218
  'hide_empty' => false,
1219
  'hierarchical' => true,
1222
  'taxonomy' => $taxonomy->name,
1223
  'hide_if_empty' => true,
1224
  'echo' => false
1225
+ ]
1226
  )
1227
+ ]
1228
  );
1229
  } else {
1230
  wp_localize_script(
1231
  'responsive-lightbox-folders-admin',
1232
  'rlFoldersArgs',
1233
+ [
1234
  'remove_children' => (int) $rl->options['folders']['folders_removal'],
1235
  'wholerow' => (int) $rl->options['folders']['jstree_wholerow'],
1236
  'theme' => 'default',
1238
  'no_media_items' => $no_items,
1239
  'taxonomy' => $taxonomy->name,
1240
  'page' => $page,
1241
+ 'root' => esc_html__( 'Root Folder', 'responsive-lightbox' ),
1242
+ 'all_terms' => esc_html__( 'All Files', 'responsive-lightbox' ),
1243
+ 'new_folder' => esc_html__( 'New Folder', 'responsive-lightbox' ),
1244
+ 'delete_term' => esc_html__( 'Are you sure you want to delete this folder?', 'responsive-lightbox' ),
1245
+ 'delete_terms' => esc_html__( 'Are you sure you want to delete this folder with all subfolders?', 'responsive-lightbox' ),
1246
  'nonce' => wp_create_nonce( 'rl-folders-ajax-library-nonce' ),
1247
  'terms' => wp_dropdown_categories(
1248
+ [
1249
  'orderby' => 'name',
1250
  'order' => 'asc',
1251
+ 'show_option_all' => esc_html__( 'All Files', 'responsive-lightbox' ),
1252
  'show_count' => false,
1253
  'hide_empty' => false,
1254
  'hierarchical' => true,
1257
  'taxonomy' => $taxonomy->name,
1258
  'hide_if_empty' => true,
1259
  'echo' => false
1260
+ ]
1261
  ),
1262
  'template' => '
1263
  <div id="rl-folders-tree-container">
1264
  <div class="media-toolbar wp-filter">
1265
  <div class="view-switch rl-folders-action-links">
1266
+ <a href="#" title="' . esc_attr( $taxonomy->labels->add_new_item ) . '" class="dashicons dashicons-plus rl-folders-add-new-folder' . ( $this->mode === 'list' && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1267
+ <a href="#" title="' . esc_attr( sprintf( __( 'Save new %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-yes rl-folders-save-new-folder" style="display: none;"></a>
1268
+ <a href="#" title="' . esc_attr( sprintf( __( 'Cancel adding new %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-no rl-folders-cancel-new-folder" style="display: none;"></a>
1269
+ <a href="#" title="' . esc_attr( $taxonomy->labels->edit_item ) . '" class="dashicons dashicons-edit rl-folders-rename-folder' . ( $this->mode === 'list' && $term_id > 0 ? '' : ' disabled-link' ) . '"></a>
1270
+ <a href="#" title="' . esc_attr( sprintf( __( 'Save %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-yes rl-folders-save-folder" style="display: none;"></a>
1271
+ <a href="#" title="' . esc_attr( sprintf( __( 'Cancel renaming %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-no rl-folders-cancel-folder" style="display: none;"></a>
1272
+ <a href="#" title="' . esc_attr( sprintf( __( 'Delete %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-trash rl-folders-delete-folder' . ( $this->mode === 'list' && $term_id > 0 ? '' : ' disabled-link' ) . '"></a>
1273
+ <a href="#" title="' . esc_attr( sprintf( __( 'Expand %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-arrow-down-alt2 rl-folders-expand-folder' . ( $this->mode === 'list' && ! $childless && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1274
+ <a href="#" title="' . esc_attr( sprintf( __( 'Collapse %s', 'responsive-lightbox' ), $taxonomy->labels->singular_name ) ) . '" class="dashicons dashicons-arrow-up-alt2 rl-folders-collapse-folder' . ( $this->mode === 'list' && ! $childless && ( $term_id === -1 || $term_id > 0 ) ? '' : ' disabled-link' ) . '"></a>
1275
  </div>
1276
  </div>
1277
  <div id="rl-folders-tree">' . esc_html( $html ) . '</div>
1278
  </div>'
1279
+ ]
1280
  );
1281
  }
1282
 
1283
+ add_action( 'admin_print_styles', [ $this, 'admin_print_media_styles' ] );
1284
  }
1285
 
1286
  /**
1314
  global $wpdb;
1315
 
1316
  // query
1317
+ $fields = $wpdb->get_col( "
1318
  SELECT DISTINCT tt.taxonomy
1319
+ FROM " . $wpdb->prefix . "term_taxonomy tt
1320
+ LEFT JOIN " . $wpdb->prefix . "term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
1321
+ LEFT JOIN " . $wpdb->prefix . "posts p ON p.ID = tr.object_id
1322
+ WHERE p.post_type = 'attachment'
1323
+ ORDER BY tt.taxonomy ASC"
1324
  );
1325
 
1326
  if ( ! empty( $fields ) ) {
includes/class-frontend.php CHANGED
@@ -24,31 +24,31 @@ class Responsive_Lightbox_Frontend {
24
  Responsive_Lightbox()->frontend = $this;
25
 
26
  // actions
27
- add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 100 );
28
- add_action( 'rl_before_gallery', array( $this, 'before_gallery' ), 10, 2 );
29
- add_action( 'rl_after_gallery', array( $this, 'after_gallery' ), 10, 2 );
30
- add_action( 'after_setup_theme', array( $this, 'woocommerce_gallery_init' ), 1000 );
31
 
32
  // filters
33
- add_filter( 'rl_gallery_container_class', array( $this, 'gallery_container_class' ), 10, 3 );
34
- add_filter( 'the_content', array( $this, 'gallery_preview' ) );
35
- add_filter( 'the_content', array( $this, 'add_lightbox' ), 11 );
36
- add_filter( 'wp_get_attachment_link', array( $this, 'wp_get_attachment_link' ), 1000, 6 );
37
- add_filter( 'get_comment_text', array( $this, 'get_comment_text' ) );
38
- add_filter( 'dynamic_sidebar_params', array( $this, 'dynamic_sidebar_params' ) );
39
- add_filter( 'rl_widget_output', array( $this, 'widget_output' ), 10, 3 );
40
- add_filter( 'post_gallery', array( $this, 'gallery_attributes' ), 1000, 2 );
41
- add_filter( 'post_gallery', array( $this, 'basic_grid_gallery_shortcode' ), 1001, 2 );
42
- add_filter( 'post_gallery', array( $this, 'basic_slider_gallery_shortcode' ), 1001, 2 );
43
- add_filter( 'post_gallery', array( $this, 'basic_masonry_gallery_shortcode' ), 1001, 2 );
44
- add_filter( 'post_gallery', array( $this, 'force_custom_gallery_lightbox' ), 2000 );
45
 
46
  // visual composer
47
- add_filter( 'vc_shortcode_content_filter_after', array( $this, 'vc_shortcode_content_filter_after' ), 10, 2 );
48
 
49
  // woocommerce
50
- add_filter( 'woocommerce_single_product_image_html', array( $this, 'woocommerce_single_product_image_html' ), 100 );
51
- add_filter( 'woocommerce_single_product_image_thumbnail_html', array( $this, 'woocommerce_single_product_image_thumbnail_html' ), 100, 2 );
52
  }
53
 
54
  /**
@@ -65,15 +65,15 @@ class Responsive_Lightbox_Frontend {
65
  $script = $rl->get_lightbox_script();
66
 
67
  // prepare arguments
68
- $args = array(
69
  'selector' => $rl->options['settings']['selector'],
70
  'script' => $script,
71
- 'settings' => array(
72
  'script' => $rl->options['configuration'][$script],
73
  'plugin' => $rl->options['settings']
74
- ),
75
  'supports' => $rl->settings->scripts[$script]['supports']
76
- );
77
 
78
  // workaround for builder galleries to bypass images_as_gallery option, applied only to rl_gallery posts
79
  if ( is_singular( 'rl_gallery' ) )
@@ -117,7 +117,7 @@ class Responsive_Lightbox_Frontend {
117
  $args['link_number'] = $link_number;
118
 
119
  // link parts
120
- $args['link_parts'] = array( $links[1][$link_number], $links[2][$link_number], $links[3][$link_number], $links[4][$link_number], $links[5][$link_number] );
121
 
122
  // get title type
123
  $title_arg = $args['settings']['plugin']['force_custom_gallery'] ? $args['settings']['plugin']['gallery_image_title'] : $args['settings']['plugin']['image_title'];
@@ -179,7 +179,7 @@ class Responsive_Lightbox_Frontend {
179
  $args['link_number'] = $link_number;
180
 
181
  // link parts
182
- $args['link_parts'] = array( $links[1][$link_number], $links[2][$link_number], $links[8][$link_number], $links[9][$link_number] );
183
 
184
  // rl gallery link?
185
  if ( preg_match( '/class="(?:.*?)rl-gallery-link[^"]*?"/i', $links[1][$link_number] ) === 1 || preg_match( '/class="(?:.*?)rl-gallery-link[^"]*?"/i', $links[8][$link_number] ) === 1 ) {
@@ -215,7 +215,7 @@ class Responsive_Lightbox_Frontend {
215
  $link = str_replace( $args['link_parts'][1], add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] ), $link );
216
 
217
  // replace data-rel
218
- $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/', 'data-rel="' . $args['selector'] . '-video-' . $args['link_number'] . '"', $link );
219
 
220
  if ( $args['script'] === 'magnific' )
221
  $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
@@ -226,7 +226,7 @@ class Responsive_Lightbox_Frontend {
226
  $args['link_parts'][1] = add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] );
227
 
228
  // add data-rel
229
- $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '" data-rel="' . $args['selector'] . '-video-' . $args['link_number'] . '"' . $args['link_parts'][2] . '>' . $args['link_parts'][3] . '</a>';
230
 
231
  if ( $args['script'] === 'magnific' )
232
  $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
@@ -246,14 +246,6 @@ class Responsive_Lightbox_Frontend {
246
  */
247
  public function lightbox_image_link( $link, $args, $only_filter = false ) {
248
  if ( ! $only_filter ) {
249
- if ( rl_current_lightbox_supports( 'html_caption' ) ) {
250
- $title = esc_attr( trim ( nl2br( $args['title'] ) ) );
251
- $caption = esc_attr( trim( nl2br( $args['caption'] ) ) );
252
- } else {
253
- $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $args['title'] ) ), true ) );
254
- $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $args['caption'] ) ), true ) );
255
- }
256
-
257
  if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
258
  $this->gallery_no = (int) $_GET['rl_gallery_no'];
259
 
@@ -263,10 +255,10 @@ class Responsive_Lightbox_Frontend {
263
  if ( $result[1] !== 'norl' ) {
264
  // gallery?
265
  if ( $args['settings']['plugin']['images_as_gallery'] || $args['settings']['plugin']['force_custom_gallery'] )
266
- $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ), $link );
267
  // single image
268
  else
269
- $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-image-' . base64_encode( $result[1] ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"', $link );
270
  }
271
  // link without data-rel
272
  } else {
@@ -276,15 +268,24 @@ class Responsive_Lightbox_Frontend {
276
  if ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 ) {
277
  // allow to modify link?
278
  if ( $result[1] !== 'norl' )
279
- $link = preg_replace( '/rel=(\'|")(.*?)(\'|")/', 'data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ), $link );
280
  } else
281
- $link = '<a' . $args['link_parts'][0] . ' href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '" data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . $args['link_parts'][3] . '>' . $args['link_parts'][4] . '</a>';
282
  } else
283
- $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '"' . $args['link_parts'][3] . ' data-rel="' . $args['selector'] . ( $args['settings']['plugin']['images_as_gallery'] ? $args['rel_hash'] : '-image-' . $args['link_number'] ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__">' . $args['link_parts'][4] . '</a>';
 
 
 
 
 
 
 
 
 
284
  }
285
 
286
- // use safe replacement
287
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, str_replace( '__RL_IMAGE_CAPTION__', $caption, $link ) );
288
 
289
  // title exists?
290
  if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 ) {
@@ -292,8 +293,8 @@ class Responsive_Lightbox_Frontend {
292
  } else
293
  $link = preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__">', $link );
294
 
295
- // last safe replacement
296
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, $link );
297
  }
298
 
299
  return apply_filters( 'rl_lightbox_image_link', $link, $args );
@@ -303,38 +304,31 @@ class Responsive_Lightbox_Frontend {
303
  * Add lightbox to gallery image links.
304
  *
305
  * @param string $link
306
- * @param int $id
307
- * @param string $size
308
- * @param bool $permalink
309
- * @param mixed $icon
310
- * @param mixed $text
311
  * @return string
312
  */
313
- public function wp_get_attachment_link( $link, $id, $size, $permalink, $icon, $text ) {
314
  // get main instance
315
  $rl = Responsive_Lightbox();
316
 
317
  if ( $rl->options['settings']['galleries'] && wp_attachment_is_image( $id ) ) {
318
- // deprecated filter
319
- $link = apply_filters( 'rl_lightbox_attachment_link', $link, $id, $size, $permalink, $icon, $text, [] );
320
-
321
  // get current script
322
  $script = $rl->get_lightbox_script();
323
 
324
  // prepare arguments
325
- $args = array(
326
  'selector' => $rl->options['settings']['selector'],
327
  'script' => $script,
328
- 'settings' => array(
329
  'script' => $rl->options['configuration'][$script],
330
  'plugin' => $rl->options['settings']
331
- ),
332
  'supports' => $rl->settings->scripts[$script]['supports'],
333
  'image_id' => $id,
334
  'title' => '',
335
  'caption' => '',
336
  'src' => []
337
- );
338
 
339
  $link = $this->lightbox_gallery_link( $link, $args );
340
  }
@@ -362,17 +356,17 @@ class Responsive_Lightbox_Frontend {
362
  $args['title'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $args['image_id'], $link ) );
363
  }
364
 
365
- // sanitize title
366
- if ( $html_caption = rl_current_lightbox_supports( 'html_caption' ) )
367
- $title = esc_attr( trim( nl2br( $args['title'] ) ) );
368
- else
369
- $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $args['title'] ) ), true ) );
370
 
371
- // add title and rl_title if needed
372
  if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
373
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a.*? title=(?:\'|")).*?((?:\'|").*?>)/s', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
374
  else
375
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
376
 
377
  // add class if needed
378
  if ( preg_match( '/<a[^>]*? class=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
@@ -392,14 +386,14 @@ class Responsive_Lightbox_Frontend {
392
  $args['caption'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $args['image_id'], $link ) );
393
  }
394
 
395
- // sanitize caption
396
- if ( $html_caption )
397
- $caption = esc_attr( trim( nl2br( $args['caption'] ) ) );
398
- else
399
- $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $args['caption'] ) ), true ) );
400
 
401
- // add rl_caption
402
- $link = str_replace( '__RL_IMAGE_CAPTION__', $caption, preg_replace( '/(<a.*?)>/s', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
 
 
 
403
 
404
  if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
405
  $this->gallery_no = (int) $_GET['rl_gallery_no'];
@@ -407,20 +401,23 @@ class Responsive_Lightbox_Frontend {
407
  // link already contains data-rel attribute?
408
  if ( preg_match( '/<a.*?data-rel=(\'|")(.*?)(\'|").*?>/is', $link, $result ) === 1 ) {
409
  if ( $result[2] !== 'norl' )
410
- $link = preg_replace( '/(<a.*?data-rel=(?:\'|").*?)((?:\'|").*?>)/s', '${1}' . $args['selector'] . '-gallery-' . $this->gallery_no . '$2', $link );
411
  } else
412
- $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . $args['selector'] . '-gallery-' . $this->gallery_no . '">', $link );
413
 
414
- if ( ! ( isset( $args['link'] ) && $args['link'] != 'file' ) ) {
415
  // gallery image size
416
  if ( ! empty( $args['image_id'] ) ) {
417
  if ( empty( $args['src'] ) )
418
  $args['src'] = wp_get_attachment_image_src( $args['image_id'], $args['settings']['plugin']['gallery_image_size'] );
419
 
420
- if ( preg_match( '/<a.*? href=("|\').*?("|\').*?>/is', $link ) === 1 )
421
- $link = preg_replace( '/(<a.*? href=(?:"|\')).*?((?:"|\').*?>)/', '$1' . $args['src'][0] . '$2', $link );
422
- else
423
- $link = preg_replace( '/(<a.*?)>/', '$1 href="' . $args['src'][0] . '">', $link );
 
 
 
424
  }
425
 
426
  if ( $args['script'] === 'magnific' )
@@ -441,17 +438,17 @@ class Responsive_Lightbox_Frontend {
441
  if ( in_array( $args['content'], $args['supports'], true ) ) {
442
  // link already contains data-rel attribute?
443
  if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 )
444
- $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . $args['selector'] . '-content-' . base64_encode( $result[1] ) . '"', $link );
445
  else
446
- $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . $args['selector'] . '-content-' . $args['link_number'] . '">', $link );
447
 
448
  switch ( $args['script'] ) {
449
  case 'nivo':
450
- $link = preg_replace( '/(<a.*?)>/s', '$1 data-lightbox-type="' . $args['content'] . '">', $link );
451
  break;
452
 
453
  case 'featherlight':
454
- $link = preg_replace( '/(<a.*?)>/s', '$1 data-featherlight="' . $args['content'] . '">', $link );
455
  break;
456
 
457
  case 'fancybox':
@@ -461,7 +458,7 @@ class Responsive_Lightbox_Frontend {
461
 
462
  case 'prettyphoto':
463
  if ( $args['content'] === 'iframe' )
464
- $link = preg_replace( '/(<a.*?href=(?:\'|"))(.*?)((?:\'|").*?>)/is', '$1' . add_query_arg( array( 'iframe' => 'true', 'width' => $args['settings']['width'], 'height' => $args['settings']['height'] ), '$2' ) . '$3', $link );
465
  }
466
  }
467
 
@@ -505,12 +502,12 @@ class Responsive_Lightbox_Frontend {
505
  }
506
 
507
  /**
508
- * Get unique gallery fields.
509
- *
510
  * @param array $defaults Default gallery fields
511
  * @param array $fields Custom gallery fields
512
- * @return array
513
- */
514
  public function get_unique_fields( $defaults, $fields ) {
515
  // check duplicated fields
516
  $duplicates = array_intersect_key( $defaults, $fields );
@@ -554,7 +551,7 @@ class Responsive_Lightbox_Frontend {
554
 
555
  if ( ! empty( $tabs ) ) {
556
  foreach ( $tabs as $key => $args ) {
557
- if ( in_array( $key, array( 'images', 'config' ) ) )
558
  continue;
559
 
560
  // get additional fields
@@ -577,65 +574,65 @@ class Responsive_Lightbox_Frontend {
577
  }
578
 
579
  /**
580
- * Get default gallery fields.
581
- *
582
- * @return array
583
- */
584
  public function get_default_gallery_fields() {
585
  $sizes = get_intermediate_image_sizes();
586
  $sizes['full'] = 'full';
587
 
588
- return array(
589
- 'size' => array(
590
- 'title' => __( 'Size', 'responsive-lightbox' ),
591
- 'type' => 'select',
592
- 'description' => __( 'Specify the image size to use for the thumbnail display.', 'responsive-lightbox' ),
593
- 'default' => 'medium',
594
- 'options' => array_combine( $sizes, $sizes )
595
- ),
596
- 'link' => array(
597
- 'title' => __( 'Link To', 'responsive-lightbox' ),
598
- 'type' => 'select',
599
- 'description' => __( 'Specify where you want the image to link.', 'responsive-lightbox' ),
600
- 'default' => 'file',
601
- 'options' => array(
602
  'post' => __( 'Attachment Page', 'responsive-lightbox' ),
603
  'file' => __( 'Media File', 'responsive-lightbox' ),
604
- 'none' => __( 'None', 'responsive-lightbox' ),
605
- )
606
- ),
607
- 'orderby' => array(
608
- 'title' => __( 'Orderby', 'responsive-lightbox' ),
609
- 'type' => 'select',
610
- 'description' => __( 'Specify how to sort the display thumbnails.', 'responsive-lightbox' ),
611
- 'default' => 'menu_order',
612
- 'options' => array(
613
  'id' => __( 'ID', 'responsive-lightbox' ),
614
  'title' => __( 'Title', 'responsive-lightbox' ),
615
  'post_date' => __( 'Date', 'responsive-lightbox' ),
616
  'menu_order' => __( 'Menu Order', 'responsive-lightbox' ),
617
  'rand' => __( 'Random', 'responsive-lightbox' )
618
- )
619
- ),
620
- 'order' => array(
621
- 'title' => __( 'Order', 'responsive-lightbox' ),
622
- 'type' => 'radio',
623
- 'description' => __( 'Specify the sort order.', 'responsive-lightbox' ),
624
- 'default' => 'asc',
625
- 'options' => array(
626
  'asc' => __( 'Ascending', 'responsive-lightbox' ),
627
  'desc' => __( 'Descending', 'responsive-lightbox' )
628
- )
629
- ),
630
- 'columns' => array(
631
- 'title' => __( 'Columns', 'responsive-lightbox' ),
632
- 'type' => 'number',
633
- 'description' => __( 'Specify the number of columns.', 'responsive-lightbox' ),
634
- 'default' => 3,
635
- 'min' => 1,
636
- 'max' => 12
637
- )
638
- );
639
  }
640
 
641
  /**
@@ -761,7 +758,7 @@ class Responsive_Lightbox_Frontend {
761
  if ( ! empty( $include ) ) {
762
  // get attachments
763
  $ids = get_posts(
764
- array(
765
  'include' => implode( ',', $include ),
766
  'post_status' => 'inherit',
767
  'post_type' => 'attachment',
@@ -769,7 +766,7 @@ class Responsive_Lightbox_Frontend {
769
  'order' => $shortcode_atts['order'],
770
  'orderby' => ( $shortcode_atts['orderby'] === 'menu_order' || $shortcode_atts['orderby'] === '' ? 'post__in' : $shortcode_atts['orderby'] ),
771
  'fields' => 'ids'
772
- )
773
  );
774
  }
775
  } elseif ( ! empty( $exclude ) ) {
@@ -780,7 +777,7 @@ class Responsive_Lightbox_Frontend {
780
  if ( ! empty( $exclude ) ) {
781
  // get attachments
782
  $ids = get_children(
783
- array(
784
  'post_parent' => $shortcode_atts['id'],
785
  'exclude' => $exclude,
786
  'post_status' => 'inherit',
@@ -789,13 +786,13 @@ class Responsive_Lightbox_Frontend {
789
  'order' => $shortcode_atts['order'],
790
  'orderby' => $shortcode_atts['orderby'],
791
  'fields' => 'ids'
792
- )
793
  );
794
  }
795
  } else {
796
  // get attachments
797
  $ids = get_children(
798
- array(
799
  'post_parent' => $shortcode_atts['id'],
800
  'post_status' => 'inherit',
801
  'post_type' => 'attachment',
@@ -803,7 +800,7 @@ class Responsive_Lightbox_Frontend {
803
  'order' => $shortcode_atts['order'],
804
  'orderby' => $shortcode_atts['orderby'],
805
  'fields' => 'ids'
806
- )
807
  );
808
  }
809
 
@@ -822,19 +819,19 @@ class Responsive_Lightbox_Frontend {
822
  $script = $rl->get_lightbox_script();
823
 
824
  // prepare arguments
825
- $args = array(
826
  'selector' => $rl->options['settings']['selector'],
827
  'script' => $script,
828
- 'settings' => array(
829
  'script' => $rl->options['configuration'][$script],
830
  'plugin' => $rl->options['settings']
831
- ),
832
  'supports' => $rl->settings->scripts[$script]['supports'],
833
  'image_id' => 0,
834
  'caption' => '',
835
  'title' => '',
836
  'src' => []
837
- );
838
 
839
  // lightbox image title
840
  $args['settings']['plugin']['gallery_image_title'] = ! empty( $shortcode_atts['lightbox_image_title'] ) ? ( $shortcode_atts['lightbox_image_title'] === 'global' ? $rl->options['settings']['gallery_image_title'] : $shortcode_atts['lightbox_image_title'] ) : $rl->options['settings']['gallery_image_title'];
@@ -854,7 +851,7 @@ class Responsive_Lightbox_Frontend {
854
  $new_image = $images[$index] = array_merge( $image, $rl->galleries->get_gallery_image_src( $image, $shortcode_atts['src_size'], $shortcode_atts['size'] ) );
855
 
856
  // create image source data
857
- $args['src'] = array( $new_image['url'], $new_image['width'], $new_image['height'], $new_image );
858
 
859
  // update image id
860
  if ( ! empty( $new_image['id'] ) )
@@ -886,7 +883,7 @@ class Responsive_Lightbox_Frontend {
886
  }
887
 
888
  // set image gallery link
889
- $images[$index]['link'] = $this->lightbox_gallery_link( $this->get_gallery_image_link( $new_image['id'], $args['src'], array( $new_image['thumbnail_url'], $new_image['thumbnail_width'], $new_image['thumbnail_height'] ), $shortcode_atts ), $args );
890
 
891
  // is lightbox active?
892
  if ( isset( $shortcode_atts['lightbox_enable'] ) && $shortcode_atts['lightbox_enable'] === 0 )
@@ -907,33 +904,34 @@ class Responsive_Lightbox_Frontend {
907
  * @return string
908
  */
909
  function get_gallery_image_link( $attachment_id, $image, $thumbnail, $args ) {
 
910
  switch ( $args['link'] ) {
911
  case 'post':
912
  // embed element?
913
  if ( preg_match( '/^e\d+$/', $attachment_id ) === 1 )
914
- $attr = array( 'href' => $image[0] );
915
  else
916
- $attr = array( 'href' => get_permalink( $attachment_id ) );
917
  break;
918
 
919
  case 'none':
920
- $attr = array( 'href' => 'javascript:void(0)', 'style' => 'cursor: default;' );
921
  break;
922
 
923
  default:
924
  case 'file':
925
- $attr = array( 'href' => $image[0] );
926
  }
927
 
 
928
  $attr = apply_filters( 'rl_gallery_image_link_attributes', $attr, $attachment_id, $image, $args );
929
 
930
- // escape attributes
931
- $attr = array_map( 'esc_attr', $attr );
932
-
933
  $link = '<a';
934
 
 
935
  foreach ( $attr as $name => $value ) {
936
- $link .= " $name=" . '"' . $value . '"';
937
  }
938
 
939
  $link .= '>';
@@ -995,7 +993,7 @@ class Responsive_Lightbox_Frontend {
995
 
996
  // update title if needed
997
  if ( $title_arg !== 'default' && $image_id )
998
- $title = esc_attr( wp_strip_all_tags( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ), true ) );
999
  else
1000
  $title = '';
1001
 
@@ -1004,7 +1002,7 @@ class Responsive_Lightbox_Frontend {
1004
 
1005
  // update caption if needed
1006
  if ( $caption_arg !== 'default' )
1007
- $caption = esc_attr( wp_strip_all_tags( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ), true ) );
1008
  else
1009
  $caption = '';
1010
 
@@ -1014,15 +1012,15 @@ class Responsive_Lightbox_Frontend {
1014
  if ( $result[1] === 'norl' )
1015
  continue;
1016
 
1017
- $content = str_replace( $link, preg_replace( '/data-rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . $rl->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
1018
  } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
1019
  // do not modify this link
1020
  if ( $result[1] === 'norl' )
1021
  continue;
1022
 
1023
- $content = str_replace( $link, preg_replace( '/rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . $rl->options['settings']['selector'] . '-gallery-' . base64_encode( $result[1] ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ), $link ), $content );
1024
  } else
1025
- $content = str_replace( $link, '<a' . $links[1][$link_number] . ' href="' . $links[2][$link_number] . '.' . $links[3][$link_number] . '" data-rel="' . $rl->options['settings']['selector'] . '-gallery-' . base64_encode( $this->gallery_no ) . '" data-rl_title="' . $title . '" data-rl_caption="' . $caption . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . $link_number . '"' : '' ) . $links[4][$link_number] . '>', $content );
1026
  }
1027
  }
1028
  }
@@ -1031,22 +1029,23 @@ class Responsive_Lightbox_Frontend {
1031
  }
1032
 
1033
  /**
1034
- * Remove WooCommerce prettyPhoto lightbox styles and scripts.
1035
  *
1036
  * @global object $woocommerce
1037
  *
1038
  * @return void
1039
  */
1040
- public function wp_enqueue_scripts() {
 
1041
  if ( class_exists( 'WooCommerce' ) ) {
1042
  global $woocommerce;
1043
 
1044
  // get main instance
1045
  $rl = Responsive_Lightbox();
1046
 
1047
- // specific WooCommerce gallery?
1048
  if ( ! empty( $rl->options['settings']['default_woocommerce_gallery'] ) && $rl->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1049
- // replace default WooCommerce lightbox?
1050
  if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1051
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1052
  // dequeue scripts
@@ -1060,7 +1059,6 @@ class Responsive_Lightbox_Frontend {
1060
 
1061
  // remove theme supports
1062
  remove_theme_support( 'wc-product-gallery-lightbox' );
1063
- // remove_theme_support( 'wc-product-gallery-zoom' );
1064
  remove_theme_support( 'wc-product-gallery-slider' );
1065
  } else {
1066
  // remove styles
@@ -1080,7 +1078,7 @@ class Responsive_Lightbox_Frontend {
1080
  }
1081
  // default gallery?
1082
  } else {
1083
- // replace default WooCommerce lightbox?
1084
  if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1085
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1086
  // dequeue scripts
@@ -1107,7 +1105,7 @@ class Responsive_Lightbox_Frontend {
1107
  }
1108
  }
1109
 
1110
- // Visual Composer lightbox
1111
  if ( class_exists( 'Vc_Manager' ) ) {
1112
  wp_dequeue_script( 'prettyphoto' );
1113
  wp_deregister_script( 'prettyphoto' );
@@ -1124,7 +1122,7 @@ class Responsive_Lightbox_Frontend {
1124
  */
1125
  public function woocommerce_single_product_image_html( $html ) {
1126
  if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] )
1127
- $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '"', $html );
1128
 
1129
  return $html;
1130
  }
@@ -1141,7 +1139,7 @@ class Responsive_Lightbox_Frontend {
1141
  // make sure main product image has same gallery number
1142
  $gallery_no = $this->gallery_no + 1;
1143
 
1144
- $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '"', $html );
1145
 
1146
  preg_match( '/<a(.*?)((?:data-rel)=(?:\'|").*?(?:\'|"))(.*?)>/i', $html, $result );
1147
 
@@ -1151,7 +1149,7 @@ class Responsive_Lightbox_Frontend {
1151
 
1152
  // found valid link?
1153
  if ( ! empty( $result ) )
1154
- $html = $result[1] . '<a' . $result[2] . 'data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1155
  }
1156
 
1157
  $html = $this->woocommerce_gallery_link( $html, $attachment_id );
@@ -1184,17 +1182,17 @@ class Responsive_Lightbox_Frontend {
1184
  }
1185
 
1186
  if ( $title !== '' ) {
1187
- // sanitize title
1188
- if ( $html_caption = rl_current_lightbox_supports( 'html_caption' ) )
1189
- $title = esc_attr( trim( nl2br( $title ) ) );
1190
- else
1191
- $title = esc_attr( wp_strip_all_tags( trim ( nl2br( $title ) ), true ) );
1192
 
1193
  // add title and rl_title if needed
1194
  if ( preg_match( '/<a[^>]*?title=(?:\'|")[^>]*?(?:\'|").*?>/is', $link ) === 1 )
1195
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a[^>]*?title=(?:\'|"))[^>]*?((?:\'|").*?>)/is', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
1196
  else
1197
- $link = str_replace( '__RL_IMAGE_TITLE__', $title, preg_replace( '/(<a[^>]*?)>/is', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
1198
  }
1199
 
1200
  // gallery image caption
@@ -1210,14 +1208,14 @@ class Responsive_Lightbox_Frontend {
1210
  }
1211
 
1212
  if ( $caption !== '' ) {
1213
- // sanitize caption
1214
- if ( $html_caption )
1215
- $caption = esc_attr( trim( nl2br( $caption ) ) );
1216
- else
1217
- $caption = esc_attr( wp_strip_all_tags( trim( nl2br( $caption ) ), true ) );
1218
 
1219
  // add rl_caption
1220
- $link = str_replace( '__RL_IMAGE_CAPTION__', $caption, preg_replace( '/(<a[^>]*?)>/is', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
1221
  }
1222
 
1223
  if ( $rl->get_lightbox_script() === 'magnific' )
@@ -1232,12 +1230,12 @@ class Responsive_Lightbox_Frontend {
1232
  * @return void
1233
  */
1234
  public function woocommerce_gallery_init() {
1235
- if ( ( $priority = has_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails' ) ) != false && ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1236
  // remove default gallery
1237
  remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', $priority );
1238
 
1239
  // handle product gallery
1240
- add_action( 'woocommerce_product_thumbnails', array( $this, 'woocommerce_gallery' ), $priority );
1241
  }
1242
  }
1243
 
@@ -1253,15 +1251,15 @@ class Responsive_Lightbox_Frontend {
1253
 
1254
  $attachment_ids = [];
1255
 
1256
- // WooCommerce 3.x
1257
  if ( method_exists( $product, 'get_gallery_image_ids' ) )
1258
  $attachment_ids = $product->get_gallery_image_ids();
1259
- // WooCommerce 2.x
1260
  elseif ( method_exists( $product, 'get_gallery_attachment_ids' ) )
1261
  $attachment_ids = $product->get_gallery_attachment_ids();
1262
 
1263
  if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) )
1264
- echo do_shortcode( '[gallery type="' . Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] . '" size="' . apply_filters( 'single_product_small_thumbnail_size', 'medium' ) . '" ids="' . implode( ',', $attachment_ids ) . '"]' );
1265
  }
1266
 
1267
  /**
@@ -1338,7 +1336,7 @@ class Responsive_Lightbox_Frontend {
1338
  */
1339
  public function get_attachment_id_by_url( $url ) {
1340
  // parse url
1341
- $url = ! empty( $url ) ? esc_url( $url ) : '';
1342
 
1343
  // set post id
1344
  $post_id = 0;
@@ -1349,7 +1347,7 @@ class Responsive_Lightbox_Frontend {
1349
  // cached url not found?
1350
  if ( $post_ids === false || ! in_array( $url, array_keys( $post_ids ) ) ) {
1351
  // try to get post id
1352
- $post_id = attachment_url_to_postid( $url );
1353
 
1354
  // no post id?
1355
  if ( ! $post_id ) {
@@ -1361,11 +1359,11 @@ class Responsive_Lightbox_Frontend {
1361
 
1362
  // try to check full size image
1363
  if ( preg_match( '/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches ) )
1364
- $post_id = attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . $matches[3] );
1365
 
1366
  // try to check scaled size image
1367
  if ( ! $post_id && ! empty( $matches[1] ) && ! empty( $matches[3] ) )
1368
- $post_id = attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . '-scaled' . $matches[3] );
1369
  }
1370
 
1371
  // set the cache expiration, 24 hours by default
@@ -1378,9 +1376,9 @@ class Responsive_Lightbox_Frontend {
1378
  set_transient( 'rl-attachment_ids_by_url', $post_ids, $expire );
1379
  // cached url found
1380
  } elseif ( ! empty( $post_ids[$url] ) )
1381
- $post_id = $post_ids[$url];
1382
 
1383
- return (int) apply_filters( 'rl_get_attachment_id_by_url', $post_id, $url );
1384
  }
1385
 
1386
  /**
@@ -1390,8 +1388,9 @@ class Responsive_Lightbox_Frontend {
1390
  * @return array
1391
  */
1392
  public function get_image_size_by_url( $url ) {
1393
- $url = ! empty( $url ) ? esc_url( $url ) : '';
1394
- $size = array( 0, 0 );
 
1395
 
1396
  if ( ! empty( $url ) ) {
1397
  // get cached data
@@ -1421,7 +1420,7 @@ class Responsive_Lightbox_Frontend {
1421
  $size = array_map( 'absint', $image_sizes[$url] );
1422
  }
1423
 
1424
- return apply_filters( 'rl_get_image_size_by_url', $size, $url );
1425
  }
1426
 
1427
  /**
@@ -1432,13 +1431,13 @@ class Responsive_Lightbox_Frontend {
1432
  */
1433
  public function gallery_preview( $content ) {
1434
  if ( get_post_type() === 'rl_gallery' && ! ( is_archive() && is_main_query() ) )
1435
- $content .= do_shortcode( '[rl_gallery id="' . get_the_ID() . '"]' );
1436
 
1437
  return $content;
1438
  }
1439
 
1440
  /**
1441
- * Helper: gallery number function
1442
  *
1443
  * @param string $content
1444
  * @return string
@@ -1477,29 +1476,40 @@ class Responsive_Lightbox_Frontend {
1477
  // sanitize gallery fields
1478
  $atts = $this->sanitize_shortcode_args( $atts, $fields );
1479
 
 
 
 
 
 
 
 
 
 
 
 
 
1480
  // add inline style
1481
- $inline_css = '
1482
- .rl-gallery .rl-gallery-link {
1483
- border: ' . $atts['border_width'] . 'px solid ' . $atts['border_color'] . ';
 
1484
  }
1485
  .rl-gallery .rl-gallery-link .rl-gallery-item-title {
1486
- color: ' . $atts['title_color'] . ';
1487
  }
1488
  .rl-gallery .rl-gallery-link .rl-gallery-item-caption {
1489
- color: ' . $atts['caption_color'] . ';
1490
  }
1491
  .rl-gallery .rl-gallery-link .rl-gallery-caption,
1492
  .rl-gallery .rl-gallery-link:after {
1493
- background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1494
  }
1495
  [class^="rl-hover-icon-"] .rl-gallery-link:before,
1496
  [class*=" rl-hover-icon-"] .rl-gallery-link:before {
1497
- color: ' . $atts['title_color'] . ';
1498
- background-color: rgba( ' . implode( ', ', Responsive_Lightbox()->hex2rgb( $atts['background_color'] ) ) . ', ' . round( $atts['background_opacity'] / 100, 2 ) . ' );
1499
- }
1500
- ';
1501
-
1502
- wp_add_inline_style( 'responsive-lightbox-gallery', $inline_css );
1503
  }
1504
  }
1505
 
@@ -1532,14 +1542,14 @@ class Responsive_Lightbox_Frontend {
1532
  * @return array
1533
  */
1534
  public function dynamic_sidebar_params( $sidebar_params ) {
1535
- if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['widgets'] != true )
1536
  return $sidebar_params;
1537
 
1538
  global $wp_registered_widgets;
1539
 
1540
  $widget_id = $sidebar_params[0]['widget_id'];
1541
  $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
1542
- $wp_registered_widgets[ $widget_id ]['callback'] = array( $this, 'widget_callback_function' );
1543
 
1544
  return $sidebar_params;
1545
  }
@@ -1590,7 +1600,7 @@ class Responsive_Lightbox_Frontend {
1590
  * @return string
1591
  */
1592
  public function get_comment_text( $content ) {
1593
- if ( ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) || Responsive_Lightbox()->options['settings']['comments'] != true )
1594
  return $content;
1595
 
1596
  return $this->add_lightbox( $content );
@@ -1669,7 +1679,7 @@ class Responsive_Lightbox_Frontend {
1669
  * @return string
1670
  */
1671
  public function vc_shortcode_content_filter_after( $content, $shortcode ) {
1672
- if ( in_array( $shortcode, apply_filters( 'rl_lightbox_vc_allowed_shortcode', array( 'vc_gallery', 'vc_single_image', 'vc_images_carousel' ) ), true ) )
1673
  $content = $this->add_lightbox( $content );
1674
 
1675
  return $content;
@@ -1690,20 +1700,20 @@ class Responsive_Lightbox_Frontend {
1690
 
1691
  global $post;
1692
 
1693
- $defaults = array(
1694
- 'rl_gallery_id' => 0,
1695
- 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1696
- 'class' => '',
1697
- 'include' => '',
1698
- 'exclude' => '',
1699
- 'urls' => '',
1700
- 'type' => '',
1701
- 'order' => 'asc',
1702
- 'orderby' => 'menu_order',
1703
- 'size' => 'medium',
1704
- 'link' => 'file',
1705
- 'columns' => 3
1706
- );
1707
 
1708
  // get main instance
1709
  $rl = Responsive_Lightbox();
@@ -1756,7 +1766,7 @@ class Responsive_Lightbox_Frontend {
1756
  $atts['class'] = trim( $atts['class'] );
1757
 
1758
  // more than 1 class?
1759
- if ( strpos( $atts['class'], ' ' ) !== false ) {
1760
  // get unique valid HTML classes
1761
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1762
 
@@ -1799,7 +1809,7 @@ class Responsive_Lightbox_Frontend {
1799
  if ( $atts['lightbox_image_size'] === 'global' )
1800
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1801
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1802
- $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
1803
  else
1804
  $atts['src_size'] = $atts['lightbox_image_size'];
1805
  } else
@@ -1814,17 +1824,20 @@ class Responsive_Lightbox_Frontend {
1814
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1815
  return $output;
1816
 
1817
- $gallery_no = $this->gallery_no;
 
1818
 
1819
- ob_start(); ?>
1820
 
1821
- <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
 
1822
 
1823
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1824
 
1825
- <div class="rl-gallery rl-basicgrid-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
1826
 
1827
  <?php foreach ( $images as $image ) {
 
1828
  echo '<div class="rl-gallery-item">' . $image['link'] . '</div>';
1829
  } ?>
1830
 
@@ -1843,31 +1856,28 @@ class Responsive_Lightbox_Frontend {
1843
 
1844
  // add inline style
1845
  $inline_css = '
1846
- #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery {
1847
- padding: ' . ( -$atts['gutter'] ) . 'px;
1848
- }
1849
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1850
- width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
1851
- margin: ' . ( $atts['gutter'] / 2 ) . 'px;
1852
  }
1853
  @media all and (min-width: 1200px) {
1854
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1855
- width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
1856
  }
1857
  }
1858
  @media all and (min-width: 992px) and (max-width: 1200px) {
1859
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1860
- width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
1861
  }
1862
  }
1863
  @media all and (min-width: 768px) and (max-width: 992px) {
1864
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1865
- width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
1866
  }
1867
  }
1868
  @media all and (max-width: 768px) {
1869
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1870
- width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
1871
  }
1872
  }
1873
  ';
@@ -1875,17 +1885,17 @@ class Responsive_Lightbox_Frontend {
1875
  if ( $atts['force_height'] ) {
1876
  $inline_css .= '
1877
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1878
- height: ' . ( $atts['row_height'] ) . 'px;
1879
  }
1880
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item img {
1881
- height: ' . ( $atts['row_height'] ) . 'px;
1882
  object-fit: cover;
1883
  max-width: 100%;
1884
  min-width: 100%;
1885
  }';
1886
  }
1887
 
1888
- wp_add_inline_style( 'responsive-lightbox-basicgrid-gallery', $inline_css );
1889
 
1890
  // remove any new lines from the output so that the reader parses it better
1891
  return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
@@ -1906,20 +1916,20 @@ class Responsive_Lightbox_Frontend {
1906
 
1907
  global $post;
1908
 
1909
- $defaults = array(
1910
- 'rl_gallery_id' => 0,
1911
- 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1912
- 'class' => '',
1913
- 'include' => '',
1914
- 'exclude' => '',
1915
- 'urls' => '',
1916
- 'type' => '',
1917
- 'order' => 'asc',
1918
- 'orderby' => 'menu_order',
1919
- 'size' => 'medium',
1920
- 'link' => 'file',
1921
- 'columns' => 3
1922
- );
1923
 
1924
  // get main instance
1925
  $rl = Responsive_Lightbox();
@@ -1972,7 +1982,7 @@ class Responsive_Lightbox_Frontend {
1972
  $atts['class'] = trim( $atts['class'] );
1973
 
1974
  // more than 1 class?
1975
- if ( strpos( $atts['class'], ' ' ) !== false ) {
1976
  // get unique valid HTML classes
1977
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1978
 
@@ -2002,7 +2012,7 @@ class Responsive_Lightbox_Frontend {
2002
  if ( $atts['lightbox_image_size'] === 'global' )
2003
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
2004
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
2005
- $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
2006
  else
2007
  $atts['src_size'] = $atts['lightbox_image_size'];
2008
  } else
@@ -2017,17 +2027,20 @@ class Responsive_Lightbox_Frontend {
2017
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
2018
  return $output;
2019
 
2020
- $gallery_no = $this->gallery_no;
 
2021
 
2022
- ob_start(); ?>
2023
 
2024
- <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
 
2025
 
2026
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
2027
 
2028
- <ul class="rl-gallery rl-basicslider-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
2029
 
2030
  <?php foreach ( $images as $image ) {
 
2031
  echo '<li class="rl-gallery-item">' . $image['link'] . '</li>';
2032
  } ?>
2033
 
@@ -2042,8 +2055,8 @@ class Responsive_Lightbox_Frontend {
2042
  ob_end_clean();
2043
 
2044
  // scripts
2045
- wp_register_script( 'responsive-lightbox-basicslider-gallery-js', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', dirname( __FILE__ ) ), array( 'jquery' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2046
- wp_enqueue_script( 'responsive-lightbox-basicslider-gallery', plugins_url( 'js/front-basicslider.js', dirname( __FILE__ ) ), array( 'jquery', 'responsive-lightbox-basicslider-gallery-js' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2047
 
2048
  // styles
2049
  wp_enqueue_style( 'responsive-lightbox-basicslider-gallery', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', dirname( __FILE__ ) ), [], $rl->defaults['version'] );
@@ -2051,8 +2064,8 @@ class Responsive_Lightbox_Frontend {
2051
  wp_localize_script(
2052
  'responsive-lightbox-basicslider-gallery',
2053
  'rlArgsBasicSliderGallery' . ( $gallery_no + 1 ),
2054
- array(
2055
- 'data' => array(
2056
  'adaptive_height' => $atts['adaptive_height'],
2057
  'loop' => $atts['loop'],
2058
  'captions' => $atts['captions'],
@@ -2075,8 +2088,8 @@ class Responsive_Lightbox_Frontend {
2075
  'slideshow_hover_delay' => $atts['slideshow_hover_delay'],
2076
  'slideshow_delay' => $atts['slideshow_delay'],
2077
  'slideshow_pause' => $atts['slideshow_pause']
2078
- )
2079
- )
2080
  );
2081
 
2082
  // remove any new lines from the output so that the reader parses it better
@@ -2098,20 +2111,20 @@ class Responsive_Lightbox_Frontend {
2098
 
2099
  global $post;
2100
 
2101
- $defaults = array(
2102
- 'rl_gallery_id' => 0,
2103
- 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
2104
- 'class' => '',
2105
- 'include' => '',
2106
- 'exclude' => '',
2107
- 'urls' => '',
2108
- 'type' => '',
2109
- 'order' => 'asc',
2110
- 'orderby' => 'menu_order',
2111
- 'size' => 'medium',
2112
- 'link' => 'file',
2113
- 'columns' => 3
2114
- );
2115
 
2116
  // get main instance
2117
  $rl = Responsive_Lightbox();
@@ -2164,7 +2177,7 @@ class Responsive_Lightbox_Frontend {
2164
  $atts['class'] = trim( $atts['class'] );
2165
 
2166
  // more than 1 class?
2167
- if ( strpos( $atts['class'], ' ' ) !== false ) {
2168
  // get unique valid HTML classes
2169
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
2170
 
@@ -2207,7 +2220,7 @@ class Responsive_Lightbox_Frontend {
2207
  if ( $atts['lightbox_image_size'] === 'global' )
2208
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
2209
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
2210
- $atts['src_size'] = array( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] );
2211
  else
2212
  $atts['src_size'] = $atts['lightbox_image_size'];
2213
  } else
@@ -2222,15 +2235,17 @@ class Responsive_Lightbox_Frontend {
2222
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
2223
  return $output;
2224
 
2225
- $gallery_no = $this->gallery_no;
 
2226
 
2227
- ob_start(); ?>
2228
 
2229
- <div class="rl-gallery-container<?php echo apply_filters( 'rl_gallery_container_class', '', $atts, $rl_gallery_id ); ?>" id="rl-gallery-container-<?php echo $gallery_no; ?>" data-gallery_id="<?php echo $rl_gallery_id; ?>">
 
2230
 
2231
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
2232
 
2233
- <div class="rl-gallery rl-basicmasonry-gallery <?php echo $atts['class']; ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
2234
 
2235
  <?php
2236
  $count = 0;
@@ -2239,6 +2254,7 @@ class Responsive_Lightbox_Frontend {
2239
  echo '<div class="rl-gutter-sizer"></div><div class="rl-grid-sizer"></div>';
2240
 
2241
  foreach ( $images as $image ) {
 
2242
  echo '
2243
  <div class="rl-gallery-item' . ( $count === 0 ? ' rl-gallery-item-width-4' : '' ) . '" ' . implode( ' ', apply_filters( 'rl_gallery_item_extra_args', [], $atts, $image ) ) . '>
2244
  <div class="rl-gallery-item-content">
@@ -2260,54 +2276,54 @@ class Responsive_Lightbox_Frontend {
2260
  ob_clean();
2261
 
2262
  // scripts
2263
- wp_enqueue_script( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'js/front-basicmasonry.js', dirname( __FILE__ ) ), array( 'jquery', 'responsive-lightbox-masonry', 'responsive-lightbox-images-loaded' ), $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2264
 
2265
  // styles
2266
  wp_enqueue_style( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'css/gallery-basicmasonry.css', dirname( __FILE__ ) ), [], $rl->defaults['version'] );
2267
 
2268
  // add inline style
2269
- wp_add_inline_style( 'responsive-lightbox-basicmasonry-gallery', '
2270
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery {
2271
- margin: ' . -( $atts['margin'] / 2 ) . 'px ' . -( $atts['gutter'] / 2 ) . 'px;
2272
- padding: ' . $atts['margin'] . 'px 0;
2273
  }
2274
  #rl-gallery-container-' . $gallery_no . ' .rl-pagination-bottom {
2275
- margin-top: ' . ( $atts['margin'] / 2 ) . 'px
2276
  }
2277
  #rl-gallery-container-' . $gallery_no . ' .rl-pagination-top {
2278
- margin-bottom: ' . ( $atts['margin'] / 2 ) . 'px
2279
  }
2280
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2281
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2282
- width: calc(' . ( 100 / $atts['columns'] ) . '% - ' . $atts['gutter'] . 'px);
2283
- margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2284
  }
2285
  @media all and (min-width: 1200px) {
2286
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2287
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2288
- width: calc(' . ( 100 / $atts['columns_lg'] ) . '% - ' . $atts['gutter'] . 'px);
2289
- margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2290
  }
2291
  }
2292
  @media all and (min-width: 992px) and (max-width: 1200px) {
2293
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2294
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2295
- width: calc(' . ( 100 / $atts['columns_md'] ) . '% - ' . $atts['gutter'] . 'px);
2296
- margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2297
  }
2298
  }
2299
  @media all and (min-width: 768px) and (max-width: 992px) {
2300
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2301
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2302
- width: calc(' . ( 100 / $atts['columns_sm'] ) . '% - ' . $atts['gutter'] . 'px);
2303
- margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2304
  }
2305
  }
2306
  @media all and (max-width: 768px) {
2307
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2308
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2309
- width: calc(' . ( 100 / $atts['columns_xs'] ) . '% - ' . $atts['gutter'] . 'px);
2310
- margin: ' . ( $atts['margin'] / 2 ) . 'px ' . ( $atts['gutter'] / 2 ) . 'px;
2311
  }
2312
  }'
2313
  );
@@ -2315,12 +2331,12 @@ class Responsive_Lightbox_Frontend {
2315
  wp_localize_script(
2316
  'responsive-lightbox-basicmasonry-gallery',
2317
  'rlArgsBasicMasonryGallery' . ( $gallery_no + 1 ),
2318
- array(
2319
- 'data' => array(
2320
  'originLeft' => $atts['origin_left'],
2321
  'originTop' => $atts['origin_top']
2322
- )
2323
- )
2324
  );
2325
 
2326
  // remove any new lines from the output so that the reader parses it better
24
  Responsive_Lightbox()->frontend = $this;
25
 
26
  // actions
27
+ add_action( 'wp_enqueue_scripts', [ $this, 'wp_dequeue_scripts' ], 100 );
28
+ add_action( 'rl_before_gallery', [ $this, 'before_gallery' ], 10, 2 );
29
+ add_action( 'rl_after_gallery', [ $this, 'after_gallery' ], 10, 2 );
30
+ add_action( 'after_setup_theme', [ $this, 'woocommerce_gallery_init' ], 1000 );
31
 
32
  // filters
33
+ add_filter( 'rl_gallery_container_class', [ $this, 'gallery_container_class' ], 10, 3 );
34
+ add_filter( 'the_content', [ $this, 'gallery_preview' ] );
35
+ add_filter( 'the_content', [ $this, 'add_lightbox' ], 11 );
36
+ add_filter( 'wp_get_attachment_link', [ $this, 'wp_get_attachment_link' ], 1000, 2 );
37
+ add_filter( 'get_comment_text', [ $this, 'get_comment_text' ] );
38
+ add_filter( 'dynamic_sidebar_params', [ $this, 'dynamic_sidebar_params' ] );
39
+ add_filter( 'rl_widget_output', [ $this, 'widget_output' ], 10, 3 );
40
+ add_filter( 'post_gallery', [ $this, 'gallery_attributes' ], 1000, 2 );
41
+ add_filter( 'post_gallery', [ $this, 'basic_grid_gallery_shortcode' ], 1001, 2 );
42
+ add_filter( 'post_gallery', [ $this, 'basic_slider_gallery_shortcode' ], 1001, 2 );
43
+ add_filter( 'post_gallery', [ $this, 'basic_masonry_gallery_shortcode' ], 1001, 2 );
44
+ add_filter( 'post_gallery', [ $this, 'force_custom_gallery_lightbox' ], 2000 );
45
 
46
  // visual composer
47
+ add_filter( 'vc_shortcode_content_filter_after', [ $this, 'vc_shortcode_content_filter_after' ], 10, 2 );
48
 
49
  // woocommerce
50
+ add_filter( 'woocommerce_single_product_image_html', [ $this, 'woocommerce_single_product_image_html' ], 100 );
51
+ add_filter( 'woocommerce_single_product_image_thumbnail_html', [ $this, 'woocommerce_single_product_image_thumbnail_html' ], 100, 2 );
52
  }
53
 
54
  /**
65
  $script = $rl->get_lightbox_script();
66
 
67
  // prepare arguments
68
+ $args = [
69
  'selector' => $rl->options['settings']['selector'],
70
  'script' => $script,
71
+ 'settings' => [
72
  'script' => $rl->options['configuration'][$script],
73
  'plugin' => $rl->options['settings']
74
+ ],
75
  'supports' => $rl->settings->scripts[$script]['supports']
76
+ ];
77
 
78
  // workaround for builder galleries to bypass images_as_gallery option, applied only to rl_gallery posts
79
  if ( is_singular( 'rl_gallery' ) )
117
  $args['link_number'] = $link_number;
118
 
119
  // link parts
120
+ $args['link_parts'] = [ $links[1][$link_number], $links[2][$link_number], $links[3][$link_number], $links[4][$link_number], $links[5][$link_number] ];
121
 
122
  // get title type
123
  $title_arg = $args['settings']['plugin']['force_custom_gallery'] ? $args['settings']['plugin']['gallery_image_title'] : $args['settings']['plugin']['image_title'];
179
  $args['link_number'] = $link_number;
180
 
181
  // link parts
182
+ $args['link_parts'] = [ $links[1][$link_number], $links[2][$link_number], $links[8][$link_number], $links[9][$link_number] ];
183
 
184
  // rl gallery link?
185
  if ( preg_match( '/class="(?:.*?)rl-gallery-link[^"]*?"/i', $links[1][$link_number] ) === 1 || preg_match( '/class="(?:.*?)rl-gallery-link[^"]*?"/i', $links[8][$link_number] ) === 1 ) {
215
  $link = str_replace( $args['link_parts'][1], add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] ), $link );
216
 
217
  // replace data-rel
218
+ $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/', 'data-rel="' . esc_attr( $args['selector'] ) . '-video-' . (int) $args['link_number'] . '"', $link );
219
 
220
  if ( $args['script'] === 'magnific' )
221
  $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
226
  $args['link_parts'][1] = add_query_arg( 'width', $args['settings']['script']['video_max_width'], $args['link_parts'][1] );
227
 
228
  // add data-rel
229
+ $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '" data-rel="' . esc_attr( $args['selector'] ) . '-video-' . (int) $args['link_number'] . '"' . $args['link_parts'][2] . '>' . $args['link_parts'][3] . '</a>';
230
 
231
  if ( $args['script'] === 'magnific' )
232
  $link = preg_replace( '/(<a.*?)>/is', '$1 data-magnific_type="video">', $link );
246
  */
247
  public function lightbox_image_link( $link, $args, $only_filter = false ) {
248
  if ( ! $only_filter ) {
 
 
 
 
 
 
 
 
249
  if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
250
  $this->gallery_no = (int) $_GET['rl_gallery_no'];
251
 
255
  if ( $result[1] !== 'norl' ) {
256
  // gallery?
257
  if ( $args['settings']['plugin']['images_as_gallery'] || $args['settings']['plugin']['force_custom_gallery'] )
258
+ $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . esc_attr( $args['selector'] ) . '-gallery-' . esc_attr( base64_encode( $result[1] ) ) . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . (int) $args['link_number'] . '"' : '' ), $link );
259
  // single image
260
  else
261
+ $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . esc_attr( $args['selector'] ) . '-image-' . esc_attr( base64_encode( $result[1] ) ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . (int) $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"', $link );
262
  }
263
  // link without data-rel
264
  } else {
268
  if ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 ) {
269
  // allow to modify link?
270
  if ( $result[1] !== 'norl' )
271
+ $link = preg_replace( '/rel=(\'|")(.*?)(\'|")/', 'data-rel="' . esc_attr( $args['selector'] ) . '-gallery-' . (int) $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . (int) $args['link_number'] . '"' : '' ), $link );
272
  } else
273
+ $link = '<a' . $args['link_parts'][0] . ' href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '" data-rel="' . esc_attr( $args['selector'] ) . '-gallery-' . (int) $this->gallery_no . '" data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="gallery"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . (int) $args['link_number'] . '"' : '' ) . $args['link_parts'][3] . '>' . $args['link_parts'][4] . '</a>';
274
  } else
275
+ $link = '<a' . $args['link_parts'][0] . 'href="' . $args['link_parts'][1] . '.' . $args['link_parts'][2] . '"' . $args['link_parts'][3] . ' data-rel="' . esc_attr( $args['selector'] ) . ( $args['settings']['plugin']['images_as_gallery'] ? esc_attr( $args['rel_hash'] ) : '-image-' . (int) $args['link_number'] ) . '"' . ( $args['script'] === 'magnific' ? ' data-magnific_type="image"' : '' ) . ( $args['script'] === 'imagelightbox' ? ' data-imagelightbox="' . (int) $args['link_number'] . '"' : '' ) . ' data-rl_title="__RL_IMAGE_TITLE__" data-rl_caption="__RL_IMAGE_CAPTION__">' . $args['link_parts'][4] . '</a>';
276
+ }
277
+
278
+ // prepare title and caption
279
+ $title = trim ( nl2br( $args['title'] ) );
280
+ $caption = trim( nl2br( $args['caption'] ) );
281
+
282
+ if ( ! rl_current_lightbox_supports( 'html_caption' ) ) {
283
+ $title = wp_strip_all_tags( $title, true );
284
+ $caption = wp_strip_all_tags( $caption, true );
285
  }
286
 
287
+ // use safe replacement for data-rl_title and data-rl_caption
288
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), str_replace( '__RL_IMAGE_CAPTION__', esc_attr( $caption ), $link ) );
289
 
290
  // title exists?
291
  if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 ) {
293
  } else
294
  $link = preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__">', $link );
295
 
296
+ // last safe replacement for title
297
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), $link );
298
  }
299
 
300
  return apply_filters( 'rl_lightbox_image_link', $link, $args );
304
  * Add lightbox to gallery image links.
305
  *
306
  * @param string $link
307
+ * @param int|object $id
 
 
 
 
308
  * @return string
309
  */
310
+ public function wp_get_attachment_link( $link, $id ) {
311
  // get main instance
312
  $rl = Responsive_Lightbox();
313
 
314
  if ( $rl->options['settings']['galleries'] && wp_attachment_is_image( $id ) ) {
 
 
 
315
  // get current script
316
  $script = $rl->get_lightbox_script();
317
 
318
  // prepare arguments
319
+ $args = [
320
  'selector' => $rl->options['settings']['selector'],
321
  'script' => $script,
322
+ 'settings' => [
323
  'script' => $rl->options['configuration'][$script],
324
  'plugin' => $rl->options['settings']
325
+ ],
326
  'supports' => $rl->settings->scripts[$script]['supports'],
327
  'image_id' => $id,
328
  'title' => '',
329
  'caption' => '',
330
  'src' => []
331
+ ];
332
 
333
  $link = $this->lightbox_gallery_link( $link, $args );
334
  }
356
  $args['title'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $args['image_id'], $link ) );
357
  }
358
 
359
+ // prepare title
360
+ $title = trim ( nl2br( $args['title'] ) );
361
+
362
+ if ( ! rl_current_lightbox_supports( 'html_caption' ) )
363
+ $title = wp_strip_all_tags( $title, true );
364
 
365
+ // use safe replacement for title and data-rl_title
366
  if ( preg_match( '/<a.*? title=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
367
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), preg_replace( '/(<a.*? title=(?:\'|")).*?((?:\'|").*?>)/s', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
368
  else
369
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), preg_replace( '/(<a.*?)>/s', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
370
 
371
  // add class if needed
372
  if ( preg_match( '/<a[^>]*? class=(?:\'|").*?(?:\'|").*?>/is', $link ) === 1 )
386
  $args['caption'] = $this->get_attachment_title( $args['image_id'], apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $args['image_id'], $link ) );
387
  }
388
 
389
+ // prepare caption
390
+ $caption = trim( nl2br( $args['caption'] ) );
 
 
 
391
 
392
+ if ( ! rl_current_lightbox_supports( 'html_caption' ) )
393
+ $caption = wp_strip_all_tags( $caption, true );
394
+
395
+ // use safe replacement for data-rl_caption
396
+ $link = str_replace( '__RL_IMAGE_CAPTION__', esc_attr( $caption ), preg_replace( '/(<a.*?)>/s', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
397
 
398
  if ( isset( $_GET['rl_gallery_no'], $_GET['rl_page'] ) )
399
  $this->gallery_no = (int) $_GET['rl_gallery_no'];
401
  // link already contains data-rel attribute?
402
  if ( preg_match( '/<a.*?data-rel=(\'|")(.*?)(\'|").*?>/is', $link, $result ) === 1 ) {
403
  if ( $result[2] !== 'norl' )
404
+ $link = preg_replace( '/(<a.*?data-rel=(?:\'|").*?)((?:\'|").*?>)/s', '${1}' . esc_attr( $args['selector'] ) . '-gallery-' . (int) $this->gallery_no . '$2', $link );
405
  } else
406
+ $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . esc_attr( $args['selector'] ) . '-gallery-' . (int) $this->gallery_no . '">', $link );
407
 
408
+ if ( ! ( isset( $args['link'] ) && $args['link'] !== 'file' ) ) {
409
  // gallery image size
410
  if ( ! empty( $args['image_id'] ) ) {
411
  if ( empty( $args['src'] ) )
412
  $args['src'] = wp_get_attachment_image_src( $args['image_id'], $args['settings']['plugin']['gallery_image_size'] );
413
 
414
+ // valid source?
415
+ if ( ! empty( $args['src'][0] ) ) {
416
+ if ( preg_match( '/<a.*? href=("|\').*?("|\').*?>/is', $link ) === 1 )
417
+ $link = preg_replace( '/(<a.*? href=(?:"|\')).*?((?:"|\').*?>)/', '$1' . $args['src'][0] . '$2', $link );
418
+ else
419
+ $link = preg_replace( '/(<a.*?)>/', '$1 href="' . $args['src'][0] . '">', $link );
420
+ }
421
  }
422
 
423
  if ( $args['script'] === 'magnific' )
438
  if ( in_array( $args['content'], $args['supports'], true ) ) {
439
  // link already contains data-rel attribute?
440
  if ( preg_match( '/<a.*?(?:data-rel)=(?:\'|")(.*?)(?:\'|").*?>/is', $link, $result ) === 1 )
441
+ $link = preg_replace( '/data-rel=(\'|")(.*?)(\'|")/s', 'data-rel="' . esc_attr( $args['selector'] ) . '-content-' . esc_attr( base64_encode( $result[1] ) ) . '"', $link );
442
  else
443
+ $link = preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . esc_attr( $args['selector'] ) . '-content-' . (int) $args['link_number'] . '">', $link );
444
 
445
  switch ( $args['script'] ) {
446
  case 'nivo':
447
+ $link = preg_replace( '/(<a.*?)>/s', '$1 data-lightbox-type="' . esc_attr( $args['content'] ) . '">', $link );
448
  break;
449
 
450
  case 'featherlight':
451
+ $link = preg_replace( '/(<a.*?)>/s', '$1 data-featherlight="' . esc_attr( $args['content'] ) . '">', $link );
452
  break;
453
 
454
  case 'fancybox':
458
 
459
  case 'prettyphoto':
460
  if ( $args['content'] === 'iframe' )
461
+ $link = preg_replace( '/(<a.*?href=(?:\'|"))(.*?)((?:\'|").*?>)/is', '$1' . add_query_arg( [ 'iframe' => 'true', 'width' => (int) $args['settings']['width'], 'height' => (int) $args['settings']['height'] ], '$2' ) . '$3', $link );
462
  }
463
  }
464
 
502
  }
503
 
504
  /**
505
+ * Get unique gallery fields.
506
+ *
507
  * @param array $defaults Default gallery fields
508
  * @param array $fields Custom gallery fields
509
+ * @return array
510
+ */
511
  public function get_unique_fields( $defaults, $fields ) {
512
  // check duplicated fields
513
  $duplicates = array_intersect_key( $defaults, $fields );
551
 
552
  if ( ! empty( $tabs ) ) {
553
  foreach ( $tabs as $key => $args ) {
554
+ if ( in_array( $key, [ 'images', 'config' ] ) )
555
  continue;
556
 
557
  // get additional fields
574
  }
575
 
576
  /**
577
+ * Get default gallery fields.
578
+ *
579
+ * @return array
580
+ */
581
  public function get_default_gallery_fields() {
582
  $sizes = get_intermediate_image_sizes();
583
  $sizes['full'] = 'full';
584
 
585
+ return [
586
+ 'size' => [
587
+ 'title' => __( 'Size', 'responsive-lightbox' ),
588
+ 'type' => 'select',
589
+ 'description' => __( 'Specify the image size to use for the thumbnail display.', 'responsive-lightbox' ),
590
+ 'default' => 'medium',
591
+ 'options' => array_combine( $sizes, $sizes )
592
+ ],
593
+ 'link' => [
594
+ 'title' => __( 'Link To', 'responsive-lightbox' ),
595
+ 'type' => 'select',
596
+ 'description' => __( 'Specify where you want the image to link.', 'responsive-lightbox' ),
597
+ 'default' => 'file',
598
+ 'options' => [
599
  'post' => __( 'Attachment Page', 'responsive-lightbox' ),
600
  'file' => __( 'Media File', 'responsive-lightbox' ),
601
+ 'none' => __( 'None', 'responsive-lightbox' )
602
+ ]
603
+ ],
604
+ 'orderby' => [
605
+ 'title' => __( 'Orderby', 'responsive-lightbox' ),
606
+ 'type' => 'select',
607
+ 'description' => __( 'Specify how to sort the display thumbnails.', 'responsive-lightbox' ),
608
+ 'default' => 'menu_order',
609
+ 'options' => [
610
  'id' => __( 'ID', 'responsive-lightbox' ),
611
  'title' => __( 'Title', 'responsive-lightbox' ),
612
  'post_date' => __( 'Date', 'responsive-lightbox' ),
613
  'menu_order' => __( 'Menu Order', 'responsive-lightbox' ),
614
  'rand' => __( 'Random', 'responsive-lightbox' )
615
+ ]
616
+ ],
617
+ 'order' => [
618
+ 'title' => __( 'Order', 'responsive-lightbox' ),
619
+ 'type' => 'radio',
620
+ 'description' => __( 'Specify the sort order.', 'responsive-lightbox' ),
621
+ 'default' => 'asc',
622
+ 'options' => [
623
  'asc' => __( 'Ascending', 'responsive-lightbox' ),
624
  'desc' => __( 'Descending', 'responsive-lightbox' )
625
+ ]
626
+ ],
627
+ 'columns' => [
628
+ 'title' => __( 'Columns', 'responsive-lightbox' ),
629
+ 'type' => 'number',
630
+ 'description' => __( 'Specify the number of columns.', 'responsive-lightbox' ),
631
+ 'default' => 3,
632
+ 'min' => 1,
633
+ 'max' => 12
634
+ ]
635
+ ];
636
  }
637
 
638
  /**
758
  if ( ! empty( $include ) ) {
759
  // get attachments
760
  $ids = get_posts(
761
+ [
762
  'include' => implode( ',', $include ),
763
  'post_status' => 'inherit',
764
  'post_type' => 'attachment',
766
  'order' => $shortcode_atts['order'],
767
  'orderby' => ( $shortcode_atts['orderby'] === 'menu_order' || $shortcode_atts['orderby'] === '' ? 'post__in' : $shortcode_atts['orderby'] ),
768
  'fields' => 'ids'
769
+ ]
770
  );
771
  }
772
  } elseif ( ! empty( $exclude ) ) {
777
  if ( ! empty( $exclude ) ) {
778
  // get attachments
779
  $ids = get_children(
780
+ [
781
  'post_parent' => $shortcode_atts['id'],
782
  'exclude' => $exclude,
783
  'post_status' => 'inherit',
786
  'order' => $shortcode_atts['order'],
787
  'orderby' => $shortcode_atts['orderby'],
788
  'fields' => 'ids'
789
+ ]
790
  );
791
  }
792
  } else {
793
  // get attachments
794
  $ids = get_children(
795
+ [
796
  'post_parent' => $shortcode_atts['id'],
797
  'post_status' => 'inherit',
798
  'post_type' => 'attachment',
800
  'order' => $shortcode_atts['order'],
801
  'orderby' => $shortcode_atts['orderby'],
802
  'fields' => 'ids'
803
+ ]
804
  );
805
  }
806
 
819
  $script = $rl->get_lightbox_script();
820
 
821
  // prepare arguments
822
+ $args = [
823
  'selector' => $rl->options['settings']['selector'],
824
  'script' => $script,
825
+ 'settings' => [
826
  'script' => $rl->options['configuration'][$script],
827
  'plugin' => $rl->options['settings']
828
+ ],
829
  'supports' => $rl->settings->scripts[$script]['supports'],
830
  'image_id' => 0,
831
  'caption' => '',
832
  'title' => '',
833
  'src' => []
834
+ ];
835
 
836
  // lightbox image title
837
  $args['settings']['plugin']['gallery_image_title'] = ! empty( $shortcode_atts['lightbox_image_title'] ) ? ( $shortcode_atts['lightbox_image_title'] === 'global' ? $rl->options['settings']['gallery_image_title'] : $shortcode_atts['lightbox_image_title'] ) : $rl->options['settings']['gallery_image_title'];
851
  $new_image = $images[$index] = array_merge( $image, $rl->galleries->get_gallery_image_src( $image, $shortcode_atts['src_size'], $shortcode_atts['size'] ) );
852
 
853
  // create image source data
854
+ $args['src'] = [ $new_image['url'], $new_image['width'], $new_image['height'], $new_image ];
855
 
856
  // update image id
857
  if ( ! empty( $new_image['id'] ) )
883
  }
884
 
885
  // set image gallery link
886
+ $images[$index]['link'] = $this->lightbox_gallery_link( $this->get_gallery_image_link( $new_image['id'], $args['src'], [ $new_image['thumbnail_url'], $new_image['thumbnail_width'], $new_image['thumbnail_height'] ], $shortcode_atts ), $args );
887
 
888
  // is lightbox active?
889
  if ( isset( $shortcode_atts['lightbox_enable'] ) && $shortcode_atts['lightbox_enable'] === 0 )
904
  * @return string
905
  */
906
  function get_gallery_image_link( $attachment_id, $image, $thumbnail, $args ) {
907
+ // link type
908
  switch ( $args['link'] ) {
909
  case 'post':
910
  // embed element?
911
  if ( preg_match( '/^e\d+$/', $attachment_id ) === 1 )
912
+ $attr = [ 'href' => $image[0] ];
913
  else
914
+ $attr = [ 'href' => get_permalink( $attachment_id ) ];
915
  break;
916
 
917
  case 'none':
918
+ $attr = [ 'href' => 'javascript:void(0);', 'style' => 'cursor: default;' ];
919
  break;
920
 
921
  default:
922
  case 'file':
923
+ $attr = [ 'href' => $image[0] ];
924
  }
925
 
926
+ // filter attributes
927
  $attr = apply_filters( 'rl_gallery_image_link_attributes', $attr, $attachment_id, $image, $args );
928
 
929
+ // start link
 
 
930
  $link = '<a';
931
 
932
+ // escape attributes
933
  foreach ( $attr as $name => $value ) {
934
+ $link .= ' ' . esc_attr( $name ) . '="' . ( $name === 'href' ? esc_url( $value ) : esc_attr( $value ) ) . '"';
935
  }
936
 
937
  $link .= '>';
993
 
994
  // update title if needed
995
  if ( $title_arg !== 'default' && $image_id )
996
+ $title = wp_strip_all_tags( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $title_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ), true );
997
  else
998
  $title = '';
999
 
1002
 
1003
  // update caption if needed
1004
  if ( $caption_arg !== 'default' )
1005
+ $caption = wp_strip_all_tags( $this->get_attachment_title( $image_id, apply_filters( 'rl_lightbox_attachment_image_title_arg', $caption_arg, $image_id, $links[2][$link_number] . '.' . $links[3][$link_number] ) ), true );
1006
  else
1007
  $caption = '';
1008
 
1012
  if ( $result[1] === 'norl' )
1013
  continue;
1014
 
1015
+ $content = str_replace( $link, preg_replace( '/data-rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . esc_attr( $rl->options['settings']['selector'] ) . '-gallery-' . esc_attr( base64_encode( $result[1] ) ) . '" data-rl_title="' . esc_attr( $title ) . '" data-rl_caption="' . esc_attr( $caption ) . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . (int) $link_number . '"' : '' ), $link ), $content );
1016
  } elseif ( preg_match( '/<a.*?(?:rel)=(?:\'|")(.*?)(?:\'|").*?>/', $link, $result ) === 1 ) {
1017
  // do not modify this link
1018
  if ( $result[1] === 'norl' )
1019
  continue;
1020
 
1021
+ $content = str_replace( $link, preg_replace( '/rel=(?:\'|")(.*?)(?:\'|")/', 'data-rel="' . esc_attr( $rl->options['settings']['selector'] ) . '-gallery-' . esc_attr( base64_encode( $result[1] ) ) . '" data-rl_title="' . esc_attr( $title ) . '" data-rl_caption="' . esc_attr( $caption ) . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . (int) $link_number . '"' : '' ), $link ), $content );
1022
  } else
1023
+ $content = str_replace( $link, '<a' . $links[1][$link_number] . ' href="' . $links[2][$link_number] . '.' . $links[3][$link_number] . '" data-rel="' . esc_attr( $rl->options['settings']['selector'] ) . '-gallery-' . esc_attr( base64_encode( $this->gallery_no ) ) . '" data-rl_title="' . esc_attr( $title ) . '" data-rl_caption="' . esc_attr( $caption ) . '"' . ( $script === 'imagelightbox' ? ' data-imagelightbox="' . (int) $link_number . '"' : '' ) . $links[4][$link_number] . '>', $content );
1024
  }
1025
  }
1026
  }
1029
  }
1030
 
1031
  /**
1032
+ * Remove specific styles and scripts.
1033
  *
1034
  * @global object $woocommerce
1035
  *
1036
  * @return void
1037
  */
1038
+ public function wp_dequeue_scripts() {
1039
+ // woocommerce
1040
  if ( class_exists( 'WooCommerce' ) ) {
1041
  global $woocommerce;
1042
 
1043
  // get main instance
1044
  $rl = Responsive_Lightbox();
1045
 
1046
+ // specific woocommerce gallery?
1047
  if ( ! empty( $rl->options['settings']['default_woocommerce_gallery'] ) && $rl->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1048
+ // replace default woocommerce lightbox?
1049
  if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1050
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1051
  // dequeue scripts
1059
 
1060
  // remove theme supports
1061
  remove_theme_support( 'wc-product-gallery-lightbox' );
 
1062
  remove_theme_support( 'wc-product-gallery-slider' );
1063
  } else {
1064
  // remove styles
1078
  }
1079
  // default gallery?
1080
  } else {
1081
+ // replace default woocommerce lightbox?
1082
  if ( $rl->options['settings']['woocommerce_gallery_lightbox'] === true ) {
1083
  if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
1084
  // dequeue scripts
1105
  }
1106
  }
1107
 
1108
+ // visual composer
1109
  if ( class_exists( 'Vc_Manager' ) ) {
1110
  wp_dequeue_script( 'prettyphoto' );
1111
  wp_deregister_script( 'prettyphoto' );
1122
  */
1123
  public function woocommerce_single_product_image_html( $html ) {
1124
  if ( Responsive_Lightbox()->options['settings']['woocommerce_gallery_lightbox'] )
1125
+ $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . esc_attr( Responsive_Lightbox()->options['settings']['selector'] ) . '-gallery-' . (int) $this->gallery_no . '"', $html );
1126
 
1127
  return $html;
1128
  }
1139
  // make sure main product image has same gallery number
1140
  $gallery_no = $this->gallery_no + 1;
1141
 
1142
+ $html = preg_replace( '/data-rel=\"(.*?)\"/', 'data-rel="' . esc_attr( Responsive_Lightbox()->options['settings']['selector'] ) . '-gallery-' . (int) $gallery_no . '"', $html );
1143
 
1144
  preg_match( '/<a(.*?)((?:data-rel)=(?:\'|").*?(?:\'|"))(.*?)>/i', $html, $result );
1145
 
1149
 
1150
  // found valid link?
1151
  if ( ! empty( $result ) )
1152
+ $html = $result[1] . '<a' . $result[2] . 'data-rel="' . esc_attr( Responsive_Lightbox()->options['settings']['selector'] ) . '-gallery-' . (int) $gallery_no . '" ' . $result[3] . $result[4] . '>' . $result[5];
1153
  }
1154
 
1155
  $html = $this->woocommerce_gallery_link( $html, $attachment_id );
1182
  }
1183
 
1184
  if ( $title !== '' ) {
1185
+ // title
1186
+ $title = trim( nl2br( $title ) );
1187
+
1188
+ if ( ! rl_current_lightbox_supports( 'html_caption' ) )
1189
+ $title = wp_strip_all_tags( $title, true );
1190
 
1191
  // add title and rl_title if needed
1192
  if ( preg_match( '/<a[^>]*?title=(?:\'|")[^>]*?(?:\'|").*?>/is', $link ) === 1 )
1193
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), preg_replace( '/(<a[^>]*?title=(?:\'|"))[^>]*?((?:\'|").*?>)/is', '$1__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__$2', $link ) );
1194
  else
1195
+ $link = str_replace( '__RL_IMAGE_TITLE__', esc_attr( $title ), preg_replace( '/(<a[^>]*?)>/is', '$1 title="__RL_IMAGE_TITLE__" data-rl_title="__RL_IMAGE_TITLE__">', $link ) );
1196
  }
1197
 
1198
  // gallery image caption
1208
  }
1209
 
1210
  if ( $caption !== '' ) {
1211
+ // caption
1212
+ $caption = trim( nl2br( $caption ) );
1213
+
1214
+ if ( ! rl_current_lightbox_supports( 'html_caption' ) )
1215
+ $caption = wp_strip_all_tags( $caption, true );
1216
 
1217
  // add rl_caption
1218
+ $link = str_replace( '__RL_IMAGE_CAPTION__', esc_attr( $caption ), preg_replace( '/(<a[^>]*?)>/is', '$1 data-rl_caption="__RL_IMAGE_CAPTION__">', $link ) );
1219
  }
1220
 
1221
  if ( $rl->get_lightbox_script() === 'magnific' )
1230
  * @return void
1231
  */
1232
  public function woocommerce_gallery_init() {
1233
+ if ( ( $priority = has_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails' ) ) !== false && ! empty( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) && Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default' ) {
1234
  // remove default gallery
1235
  remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', $priority );
1236
 
1237
  // handle product gallery
1238
+ add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_gallery' ], $priority );
1239
  }
1240
  }
1241
 
1251
 
1252
  $attachment_ids = [];
1253
 
1254
+ // woocommerce 3.x
1255
  if ( method_exists( $product, 'get_gallery_image_ids' ) )
1256
  $attachment_ids = $product->get_gallery_image_ids();
1257
+ // woocommerce 2.x
1258
  elseif ( method_exists( $product, 'get_gallery_attachment_ids' ) )
1259
  $attachment_ids = $product->get_gallery_attachment_ids();
1260
 
1261
  if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) )
1262
+ echo do_shortcode( '[gallery type="' . esc_attr( Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] ) . '" size="medium" ids="' . esc_attr( implode( ',', $attachment_ids ) ) . '"]' );
1263
  }
1264
 
1265
  /**
1336
  */
1337
  public function get_attachment_id_by_url( $url ) {
1338
  // parse url
1339
+ $url = ! empty( $url ) ? esc_url_raw( $url ) : '';
1340
 
1341
  // set post id
1342
  $post_id = 0;
1347
  // cached url not found?
1348
  if ( $post_ids === false || ! in_array( $url, array_keys( $post_ids ) ) ) {
1349
  // try to get post id
1350
+ $post_id = (int) attachment_url_to_postid( $url );
1351
 
1352
  // no post id?
1353
  if ( ! $post_id ) {
1359
 
1360
  // try to check full size image
1361
  if ( preg_match( '/^(.*)(\-\d*x\d*)(\.\w{1,})/i', $path, $matches ) )
1362
+ $post_id = (int) attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . $matches[3] );
1363
 
1364
  // try to check scaled size image
1365
  if ( ! $post_id && ! empty( $matches[1] ) && ! empty( $matches[3] ) )
1366
+ $post_id = (int) attachment_url_to_postid( $dir['baseurl'] . '/' . $matches[1] . '-scaled' . $matches[3] );
1367
  }
1368
 
1369
  // set the cache expiration, 24 hours by default
1376
  set_transient( 'rl-attachment_ids_by_url', $post_ids, $expire );
1377
  // cached url found
1378
  } elseif ( ! empty( $post_ids[$url] ) )
1379
+ $post_id = (int) $post_ids[$url];
1380
 
1381
+ return (int) apply_filters( 'rl_get_attachment_id_by_url', $post_id, $url );
1382
  }
1383
 
1384
  /**
1388
  * @return array
1389
  */
1390
  public function get_image_size_by_url( $url ) {
1391
+ // parse url
1392
+ $url = ! empty( $url ) ? esc_url_raw( $url ) : '';
1393
+ $size = [ 0, 0 ];
1394
 
1395
  if ( ! empty( $url ) ) {
1396
  // get cached data
1420
  $size = array_map( 'absint', $image_sizes[$url] );
1421
  }
1422
 
1423
+ return (array) apply_filters( 'rl_get_image_size_by_url', $size, $url );
1424
  }
1425
 
1426
  /**
1431
  */
1432
  public function gallery_preview( $content ) {
1433
  if ( get_post_type() === 'rl_gallery' && ! ( is_archive() && is_main_query() ) )
1434
+ $content .= do_shortcode( '[rl_gallery id="' . (int) get_the_ID() . '"]' );
1435
 
1436
  return $content;
1437
  }
1438
 
1439
  /**
1440
+ * Helper: gallery number function.
1441
  *
1442
  * @param string $content
1443
  * @return string
1476
  // sanitize gallery fields
1477
  $atts = $this->sanitize_shortcode_args( $atts, $fields );
1478
 
1479
+ // convert color
1480
+ $background_color = Responsive_Lightbox()->hex2rgb( $atts['background_color'] );
1481
+
1482
+ // invalid color?
1483
+ if ( ! $background_color )
1484
+ $background_color = '0,0,0';
1485
+ else
1486
+ $background_color = implode( ',', $background_color );
1487
+
1488
+ // get opacity
1489
+ $opacity = (string) round( $atts['background_opacity'] / 100, 2 );
1490
+
1491
  // add inline style
1492
+ wp_add_inline_style(
1493
+ 'responsive-lightbox-gallery',
1494
+ '.rl-gallery .rl-gallery-link {
1495
+ border: ' . (int) $atts['border_width'] . 'px solid ' . esc_attr( $atts['border_color'] ) . ';
1496
  }
1497
  .rl-gallery .rl-gallery-link .rl-gallery-item-title {
1498
+ color: ' . esc_attr( $atts['title_color'] ) . ';
1499
  }
1500
  .rl-gallery .rl-gallery-link .rl-gallery-item-caption {
1501
+ color: ' . esc_attr( $atts['caption_color'] ) . ';
1502
  }
1503
  .rl-gallery .rl-gallery-link .rl-gallery-caption,
1504
  .rl-gallery .rl-gallery-link:after {
1505
+ background-color: rgba( ' . esc_attr( $background_color ) . ', ' . esc_attr( $opacity ) . ' );
1506
  }
1507
  [class^="rl-hover-icon-"] .rl-gallery-link:before,
1508
  [class*=" rl-hover-icon-"] .rl-gallery-link:before {
1509
+ color: ' . esc_attr( $atts['title_color'] ) . ';
1510
+ background-color: rgba( ' . esc_attr( $background_color ) . ', ' . esc_attr( $opacity ) . ' );
1511
+ }'
1512
+ );
 
 
1513
  }
1514
  }
1515
 
1542
  * @return array
1543
  */
1544
  public function dynamic_sidebar_params( $sidebar_params ) {
1545
+ if ( ( is_admin() && ! wp_doing_ajax() ) || Responsive_Lightbox()->options['settings']['widgets'] !== true )
1546
  return $sidebar_params;
1547
 
1548
  global $wp_registered_widgets;
1549
 
1550
  $widget_id = $sidebar_params[0]['widget_id'];
1551
  $wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
1552
+ $wp_registered_widgets[ $widget_id ]['callback'] = [ $this, 'widget_callback_function' ];
1553
 
1554
  return $sidebar_params;
1555
  }
1600
  * @return string
1601
  */
1602
  public function get_comment_text( $content ) {
1603
+ if ( ( is_admin() && ! wp_doing_ajax() ) || Responsive_Lightbox()->options['settings']['comments'] !== true )
1604
  return $content;
1605
 
1606
  return $this->add_lightbox( $content );
1679
  * @return string
1680
  */
1681
  public function vc_shortcode_content_filter_after( $content, $shortcode ) {
1682
+ if ( in_array( $shortcode, apply_filters( 'rl_lightbox_vc_allowed_shortcode', [ 'vc_gallery', 'vc_single_image', 'vc_images_carousel' ] ), true ) )
1683
  $content = $this->add_lightbox( $content );
1684
 
1685
  return $content;
1700
 
1701
  global $post;
1702
 
1703
+ $defaults = [
1704
+ 'rl_gallery_id' => 0,
1705
+ 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1706
+ 'class' => '',
1707
+ 'include' => '',
1708
+ 'exclude' => '',
1709
+ 'urls' => '',
1710
+ 'type' => '',
1711
+ 'order' => 'asc',
1712
+ 'orderby' => 'menu_order',
1713
+ 'size' => 'medium',
1714
+ 'link' => 'file',
1715
+ 'columns' => 3
1716
+ ];
1717
 
1718
  // get main instance
1719
  $rl = Responsive_Lightbox();
1766
  $atts['class'] = trim( $atts['class'] );
1767
 
1768
  // more than 1 class?
1769
+ if ( strpos( $atts['class'], ' ' ) !== false ) {
1770
  // get unique valid HTML classes
1771
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1772
 
1809
  if ( $atts['lightbox_image_size'] === 'global' )
1810
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
1811
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
1812
+ $atts['src_size'] = [ $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ];
1813
  else
1814
  $atts['src_size'] = $atts['lightbox_image_size'];
1815
  } else
1824
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
1825
  return $output;
1826
 
1827
+ // make sure it is integer
1828
+ $gallery_no = (int) $this->gallery_no;
1829
 
1830
+ ob_start();
1831
 
1832
+ // $gallery_no and $rl_gallery_id are both integers ?>
1833
+ <div class="rl-gallery-container<?php echo esc_attr( 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; ?>">
1834
 
1835
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
1836
 
1837
+ <div class="rl-gallery rl-basicgrid-gallery <?php echo esc_attr( $atts['class'] ); ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
1838
 
1839
  <?php foreach ( $images as $image ) {
1840
+ // $image['link'] is already escaped
1841
  echo '<div class="rl-gallery-item">' . $image['link'] . '</div>';
1842
  } ?>
1843
 
1856
 
1857
  // add inline style
1858
  $inline_css = '
 
 
 
1859
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1860
+ width: calc(' . (string) round( 100 / (int) $atts['columns'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
1861
+ margin: ' . (string) round( (int) $atts['gutter'] / 2, 2 ) . 'px;
1862
  }
1863
  @media all and (min-width: 1200px) {
1864
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1865
+ width: calc(' . (string) round( 100 / (int) $atts['columns_lg'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
1866
  }
1867
  }
1868
  @media all and (min-width: 992px) and (max-width: 1200px) {
1869
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1870
+ width: calc(' . (string) round( 100 / (int) $atts['columns_md'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
1871
  }
1872
  }
1873
  @media all and (min-width: 768px) and (max-width: 992px) {
1874
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1875
+ width: calc(' . (string) round( 100 / (int) $atts['columns_sm'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
1876
  }
1877
  }
1878
  @media all and (max-width: 768px) {
1879
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1880
+ width: calc(' . (string) round( 100 / (int) $atts['columns_xs'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
1881
  }
1882
  }
1883
  ';
1885
  if ( $atts['force_height'] ) {
1886
  $inline_css .= '
1887
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item {
1888
+ height: ' . (int) $atts['row_height'] . 'px;
1889
  }
1890
  #rl-gallery-container-' . $gallery_no . ' .rl-basicgrid-gallery .rl-gallery-item img {
1891
+ height: ' . (int) $atts['row_height'] . 'px;
1892
  object-fit: cover;
1893
  max-width: 100%;
1894
  min-width: 100%;
1895
  }';
1896
  }
1897
 
1898
+ wp_add_inline_style( 'responsive-lightbox-basicgrid-gallery', $inline_css );
1899
 
1900
  // remove any new lines from the output so that the reader parses it better
1901
  return apply_filters( 'rl_gallery_shortcode_html', trim( preg_replace( '/\s+/', ' ', $gallery_html ) ), $atts, $rl_gallery_id );
1916
 
1917
  global $post;
1918
 
1919
+ $defaults = [
1920
+ 'rl_gallery_id' => 0,
1921
+ 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
1922
+ 'class' => '',
1923
+ 'include' => '',
1924
+ 'exclude' => '',
1925
+ 'urls' => '',
1926
+ 'type' => '',
1927
+ 'order' => 'asc',
1928
+ 'orderby' => 'menu_order',
1929
+ 'size' => 'medium',
1930
+ 'link' => 'file',
1931
+ 'columns' => 3
1932
+ ];
1933
 
1934
  // get main instance
1935
  $rl = Responsive_Lightbox();
1982
  $atts['class'] = trim( $atts['class'] );
1983
 
1984
  // more than 1 class?
1985
+ if ( strpos( $atts['class'], ' ' ) !== false ) {
1986
  // get unique valid HTML classes
1987
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
1988
 
2012
  if ( $atts['lightbox_image_size'] === 'global' )
2013
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
2014
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
2015
+ $atts['src_size'] = [ $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ];
2016
  else
2017
  $atts['src_size'] = $atts['lightbox_image_size'];
2018
  } else
2027
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
2028
  return $output;
2029
 
2030
+ // make sure it is integer
2031
+ $gallery_no = (int) $this->gallery_no;
2032
 
2033
+ ob_start();
2034
 
2035
+ // $gallery_no and $rl_gallery_id are both integers ?>
2036
+ <div class="rl-gallery-container<?php echo esc_attr( 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; ?>">
2037
 
2038
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
2039
 
2040
+ <ul class="rl-gallery rl-basicslider-gallery <?php echo esc_attr( $atts['class'] ); ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
2041
 
2042
  <?php foreach ( $images as $image ) {
2043
+ // $image['link'] is already escaped
2044
  echo '<li class="rl-gallery-item">' . $image['link'] . '</li>';
2045
  } ?>
2046
 
2055
  ob_end_clean();
2056
 
2057
  // scripts
2058
+ wp_register_script( 'responsive-lightbox-basicslider-gallery-js', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.js', dirname( __FILE__ ) ), [ 'jquery' ], $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2059
+ wp_enqueue_script( 'responsive-lightbox-basicslider-gallery', plugins_url( 'js/front-basicslider.js', dirname( __FILE__ ) ), [ 'jquery', 'responsive-lightbox-basicslider-gallery-js' ], $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2060
 
2061
  // styles
2062
  wp_enqueue_style( 'responsive-lightbox-basicslider-gallery', plugins_url( 'assets/slippry/slippry' . ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '' ) . '.css', dirname( __FILE__ ) ), [], $rl->defaults['version'] );
2064
  wp_localize_script(
2065
  'responsive-lightbox-basicslider-gallery',
2066
  'rlArgsBasicSliderGallery' . ( $gallery_no + 1 ),
2067
+ [
2068
+ 'data' => [
2069
  'adaptive_height' => $atts['adaptive_height'],
2070
  'loop' => $atts['loop'],
2071
  'captions' => $atts['captions'],
2088
  'slideshow_hover_delay' => $atts['slideshow_hover_delay'],
2089
  'slideshow_delay' => $atts['slideshow_delay'],
2090
  'slideshow_pause' => $atts['slideshow_pause']
2091
+ ]
2092
+ ]
2093
  );
2094
 
2095
  // remove any new lines from the output so that the reader parses it better
2111
 
2112
  global $post;
2113
 
2114
+ $defaults = [
2115
+ 'rl_gallery_id' => 0,
2116
+ 'id' => isset( $post->ID ) ? (int) $post->ID : 0,
2117
+ 'class' => '',
2118
+ 'include' => '',
2119
+ 'exclude' => '',
2120
+ 'urls' => '',
2121
+ 'type' => '',
2122
+ 'order' => 'asc',
2123
+ 'orderby' => 'menu_order',
2124
+ 'size' => 'medium',
2125
+ 'link' => 'file',
2126
+ 'columns' => 3
2127
+ ];
2128
 
2129
  // get main instance
2130
  $rl = Responsive_Lightbox();
2177
  $atts['class'] = trim( $atts['class'] );
2178
 
2179
  // more than 1 class?
2180
+ if ( strpos( $atts['class'], ' ' ) !== false ) {
2181
  // get unique valid HTML classes
2182
  $atts['class'] = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $atts['class'] ) ) ) );
2183
 
2220
  if ( $atts['lightbox_image_size'] === 'global' )
2221
  $atts['src_size'] = $rl->options['settings']['gallery_image_size'];
2222
  elseif ( $atts['lightbox_image_size'] === 'lightbox_custom_size' && isset( $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ) )
2223
+ $atts['src_size'] = [ $atts['lightbox_custom_size_width'], $atts['lightbox_custom_size_height'] ];
2224
  else
2225
  $atts['src_size'] = $atts['lightbox_image_size'];
2226
  } else
2235
  if ( empty( $images ) || is_feed() || defined( 'IS_HTML_EMAIL' ) )
2236
  return $output;
2237
 
2238
+ // make sure it is integer
2239
+ $gallery_no = (int) $this->gallery_no;
2240
 
2241
+ ob_start();
2242
 
2243
+ // $gallery_no and $rl_gallery_id are both integers ?>
2244
+ <div class="rl-gallery-container<?php echo esc_attr( 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; ?>">
2245
 
2246
  <?php do_action( 'rl_before_gallery', $atts, $rl_gallery_id ); ?>
2247
 
2248
+ <div class="rl-gallery rl-basicmasonry-gallery <?php echo esc_attr( $atts['class'] ); ?>" id="rl-gallery-<?php echo $gallery_no; ?>" data-gallery_no="<?php echo $gallery_no; ?>">
2249
 
2250
  <?php
2251
  $count = 0;
2254
  echo '<div class="rl-gutter-sizer"></div><div class="rl-grid-sizer"></div>';
2255
 
2256
  foreach ( $images as $image ) {
2257
+ // $image['link'] is already escaped
2258
  echo '
2259
  <div class="rl-gallery-item' . ( $count === 0 ? ' rl-gallery-item-width-4' : '' ) . '" ' . implode( ' ', apply_filters( 'rl_gallery_item_extra_args', [], $atts, $image ) ) . '>
2260
  <div class="rl-gallery-item-content">
2276
  ob_clean();
2277
 
2278
  // scripts
2279
+ wp_enqueue_script( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'js/front-basicmasonry.js', dirname( __FILE__ ) ), [ 'jquery', 'responsive-lightbox-masonry', 'responsive-lightbox-images-loaded' ], $rl->defaults['version'], ( $rl->options['settings']['loading_place'] === 'footer' ) );
2280
 
2281
  // styles
2282
  wp_enqueue_style( 'responsive-lightbox-basicmasonry-gallery', plugins_url( 'css/gallery-basicmasonry.css', dirname( __FILE__ ) ), [], $rl->defaults['version'] );
2283
 
2284
  // add inline style
2285
+ wp_add_inline_style( 'responsive-lightbox-basicmasonry-gallery', '
2286
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery {
2287
+ margin: ' . -(string) round( (int) $atts['margin'] / 2, 1 ) . 'px ' . -(string) round( (int) $atts['gutter'] / 2, 1 ) . 'px;
2288
+ padding: ' . (int) $atts['margin'] . 'px 0;
2289
  }
2290
  #rl-gallery-container-' . $gallery_no . ' .rl-pagination-bottom {
2291
+ margin-top: ' . ( (int) $atts['margin'] / 2 ) . 'px
2292
  }
2293
  #rl-gallery-container-' . $gallery_no . ' .rl-pagination-top {
2294
+ margin-bottom: ' . ( (int) $atts['margin'] / 2 ) . 'px
2295
  }
2296
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2297
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2298
+ width: calc(' . (string) round( 100 / (int) $atts['columns'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
2299
+ margin: ' . ( (int) $atts['margin'] / 2 ) . 'px ' . ( (int) $atts['gutter'] / 2 ) . 'px;
2300
  }
2301
  @media all and (min-width: 1200px) {
2302
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2303
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2304
+ width: calc(' . (string) round( 100 / (int) $atts['columns_lg'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
2305
+ margin: ' . ( (int) $atts['margin'] / 2 ) . 'px ' . ( (int) $atts['gutter'] / 2 ) . 'px;
2306
  }
2307
  }
2308
  @media all and (min-width: 992px) and (max-width: 1200px) {
2309
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2310
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2311
+ width: calc(' . (string) round( 100 / (int) $atts['columns_md'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
2312
+ margin: ' . ( (int) $atts['margin'] / 2 ) . 'px ' . ( (int) $atts['gutter'] / 2 ) . 'px;
2313
  }
2314
  }
2315
  @media all and (min-width: 768px) and (max-width: 992px) {
2316
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2317
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2318
+ width: calc(' . (string) round( 100 / (int) $atts['columns_sm'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
2319
+ margin: ' . ( (int) $atts['margin'] / 2 ) . 'px ' . ( (int) $atts['gutter'] / 2 ) . 'px;
2320
  }
2321
  }
2322
  @media all and (max-width: 768px) {
2323
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-gallery-item,
2324
  #rl-gallery-container-' . $gallery_no . ' .rl-basicmasonry-gallery .rl-grid-sizer {
2325
+ width: calc(' . (string) round( 100 / (int) $atts['columns_xs'], 2 ) . '% - ' . (int) $atts['gutter'] . 'px);
2326
+ margin: ' . ( (int) $atts['margin'] / 2 ) . 'px ' . ( (int) $atts['gutter'] / 2 ) . 'px;
2327
  }
2328
  }'
2329
  );
2331
  wp_localize_script(
2332
  'responsive-lightbox-basicmasonry-gallery',
2333
  'rlArgsBasicMasonryGallery' . ( $gallery_no + 1 ),
2334
+ [
2335
+ 'data' => [
2336
  'originLeft' => $atts['origin_left'],
2337
  'originTop' => $atts['origin_top']
2338
+ ]
2339
+ ]
2340
  );
2341
 
2342
  // remove any new lines from the output so that the reader parses it better
includes/class-galleries.php CHANGED
@@ -88,9 +88,9 @@ class Responsive_Lightbox_Galleries {
88
  </div>
89
  </div>
90
  <div class="rl-gallery-actions">' .
91
- ( $args['changeable'] ? '<a href="#" class="rl-gallery-image-status dashicons dashicons-marker" title="' . __( 'Status', 'responsive-lightbox' ) . '"></a>' : '' ) .
92
- ( $args['editable'] ? '<a href="#" class="rl-gallery-image-edit dashicons dashicons-edit" title="' . __( 'Edit image', 'responsive-lightbox' ) . '"></a>' : '' ) .
93
- ( $args['removable'] ? '<a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' . __( 'Remove image', 'responsive-lightbox' ) . '"></a>' : '' ) . '
94
  </div>
95
  </li>';
96
  }
@@ -147,9 +147,9 @@ class Responsive_Lightbox_Galleries {
147
  '__MEDIA_FIELD_VALUE__'
148
  ],
149
  [
150
- $tab_id,
151
- $menu_item,
152
- $field_name,
153
  empty( $excluded_value ) ? '' : esc_attr( $excluded_value )
154
  ],
155
  $template
@@ -170,7 +170,7 @@ class Responsive_Lightbox_Galleries {
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' );
@@ -693,29 +693,29 @@ class Responsive_Lightbox_Galleries {
693
  * @return void
694
  */
695
  public function duplicate_gallery() {
696
- if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) ) || ! isset( $_REQUEST['action'] ) || ! isset( $_REQUEST['rl_gallery_nonce'] ) || ( isset( $_REQUEST['rl_gallery_nonce'] ) && ! wp_verify_nonce( esc_attr( $_REQUEST['rl_gallery_nonce'] ), 'responsive-lightbox-duplicate-gallery' ) ) )
697
- wp_die( __( 'No gallery to duplicate has been supplied!', 'responsive-lightbox' ) );
698
 
699
  // get the original post
700
- $post_id = ( isset( $_GET['post'] ) ? (int) $_GET['post'] : (int) $_POST['post'] );
701
 
702
  if ( empty( $post_id ) )
703
- wp_die( __( 'No gallery to duplicate has been supplied!', 'responsive-lightbox' ) );
704
 
705
  if ( ! current_user_can( 'edit_post', $post_id ) )
706
- wp_die( __( 'You do not have permission to copy this gallery.', 'responsive-lightbox' ) );
707
 
708
  $post = get_post( $post_id );
709
 
710
  // copy the post and insert it
711
- if ( isset( $post ) && $post != null ) {
712
- $new_id = $this->create_gallery_duplicate( $post );
713
 
714
  // redirect to the post list screen
715
  wp_redirect( admin_url( 'edit.php?post_type=' . $post->post_type ) );
716
  exit;
717
  } else
718
- wp_die( esc_attr( __( 'Copy creation failed, could not find original gallery:', 'responsive-lightbox' ) ) . ' ' . htmlspecialchars( $post_id ) );
719
  }
720
 
721
  /**
@@ -737,7 +737,7 @@ class Responsive_Lightbox_Galleries {
737
  return $actions;
738
 
739
  // duplicate link
740
- $actions['duplicate_gallery'] = '<a class="duplicate-gallery" title="' . esc_attr__( 'Duplicate this item', 'responsive-lightbox' ) . '" href="' . wp_nonce_url( admin_url( $pagenow . '?post=' . $post->ID . '&action=duplicate_gallery' ), 'responsive-lightbox-duplicate-gallery', 'rl_gallery_nonce' ) . '">' . __( 'Duplicate', 'responsive-lightbox' ) . '</a>';
741
 
742
  return $actions;
743
  }
@@ -750,12 +750,12 @@ class Responsive_Lightbox_Galleries {
750
  */
751
  public function create_gallery_duplicate( $post ) {
752
  // skip revisions
753
- if ( $post->post_type == 'revision' )
754
  return;
755
 
756
  $new_post = apply_filters(
757
  'rl_duplicate_gallery_args',
758
- array(
759
  'menu_order' => $post->menu_order,
760
  'comment_status' => $post->comment_status,
761
  'ping_status' => $post->ping_status,
@@ -770,14 +770,14 @@ class Responsive_Lightbox_Galleries {
770
  'post_type' => $post->post_type,
771
  'post_date' => current_time( 'mysql' ),
772
  'post_date_gmt' => get_gmt_from_date( current_time( 'mysql' ) )
773
- ),
774
  $post
775
  );
776
 
777
  $new_post_id = wp_insert_post( $new_post );
778
 
779
  // if the copy is published or scheduled, we have to set a proper slug
780
- if ( $new_post['post_status'] == 'publish' || $new_post['post_status'] == 'future' ) {
781
  $post_name = wp_unique_post_slug( $post->post_name, $new_post_id, $new_post['post_status'], $post->post_type, $new_post['post_parent'] );
782
 
783
  $new_post = [];
@@ -989,9 +989,9 @@ class Responsive_Lightbox_Galleries {
989
 
990
  foreach ( $fields as $arg => $value ) {
991
  if ( is_array( $value ) )
992
- $shortcode .= ' ' . $arg . '="' . (string) implode( ',', $value ) . '"';
993
  else
994
- $shortcode .= ' ' . $arg . '="' . (string) $value . '"';
995
  }
996
 
997
  // get design data
@@ -999,7 +999,7 @@ class Responsive_Lightbox_Galleries {
999
 
1000
  if ( ! empty( $design['menu_item'] ) ) {
1001
  foreach ( $design[$design['menu_item']] as $arg => $value ) {
1002
- $shortcode .= ' ' . $arg . '="' . (string) $value . '"';
1003
  }
1004
  }
1005
 
@@ -1008,7 +1008,7 @@ class Responsive_Lightbox_Galleries {
1008
 
1009
  if ( ! empty( $lightbox['menu_item'] ) ) {
1010
  foreach ( $lightbox[$lightbox['menu_item']] as $arg => $value ) {
1011
- $shortcode .= ' ' . $arg . '="' . (string) $value . '"';
1012
  }
1013
  }
1014
 
@@ -1023,7 +1023,7 @@ class Responsive_Lightbox_Galleries {
1023
  }
1024
 
1025
  // get content
1026
- $content = do_shortcode( '[gallery rl_gallery_id="' . $args['id'] .'"' . $forced_gallery_no . ' include="' . ( empty( $attachments ) ? '' : implode( ',', $attachments ) ) . '"' . $shortcode . ']' );
1027
 
1028
  // make sure every filter is available in frontend ajax
1029
  if ( wp_doing_ajax() )
@@ -1044,7 +1044,7 @@ class Responsive_Lightbox_Galleries {
1044
 
1045
  $this->enqueue_gallery_scripts_styles();
1046
 
1047
- echo '<button type="button" id="rl-insert-modal-gallery-button" class="button" data-editor="' . $editor_id . '"><span class="wp-media-buttons-icon dashicons dashicons-format-gallery"></span> ' . __( 'Add Gallery', 'responsive-lightbox' ) . '</button>';
1048
  }
1049
 
1050
  /**
@@ -1103,6 +1103,8 @@ class Responsive_Lightbox_Galleries {
1103
  // get main instance
1104
  $rl = Responsive_Lightbox();
1105
 
 
 
1106
  // builder categories?
1107
  if ( $rl->options['builder']['categories'] ) {
1108
  $terms = get_terms(
@@ -1140,34 +1142,34 @@ class Responsive_Lightbox_Galleries {
1140
  echo '
1141
  <div id="rl-modal-gallery" style="display: none;">
1142
  <div class="media-modal wp-core-ui">
1143
- <button type="button" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text">' . __( 'Close', 'responsive-lightbox' ) . '</span></span></button>
1144
  <div class="media-modal-content">
1145
  <div class="media-frame mode-select wp-core-ui hide-menu hide-router">
1146
  <div class="media-frame-title">
1147
- <h1 class="wrap">' . __( 'Insert Gallery', 'responsive-lightbox' ) . ' <a class="rl-reload-galleries page-title-action" href="#">' . __( 'Reload', 'responsive-lightbox' ). '</a><span class="rl-gallery-reload-spinner spinner"></span></h1>
1148
  </div>
1149
  <div class="media-frame-content" data-columns="0">
1150
  <div class="attachments-browser">
1151
  <div class="uploader-inline rl-no-galleries" style="display: none;">
1152
  <div class="uploader-inline-content has-upload-message">
1153
- <h2 class="upload-message">' . esc_html( 'No items found.', 'responsive-lightbox' ) . '</h2>
1154
  <div class="upload-ui">
1155
- <h2 class="upload-instructions">' . esc_html( 'No galleries? Create them first or try another search phrase.', 'responsive-lightbox' ) . '</h2>
1156
  </div>
1157
  </div>
1158
  </div>
1159
  <div class="media-toolbar">' . ( $rl->options['builder']['categories'] ? '
1160
  <div class="media-toolbar-secondary"><label for="rl-media-attachment-categories" class="screen-reader-text">' . esc_html__( 'Filter by category', 'responsive-lightbox' ) . '</label>' . $categories . '</div>' : '' ) . '
1161
  <div class="media-toolbar-primary search-form">
1162
- <label for="rl-media-search-input" class="screen-reader-text">' . __( 'Search galleries', 'responsive-lightbox' ) . '</label><input type="search" placeholder="' . esc_attr__( 'Search galleries', 'responsive-lightbox' ) . '" id="rl-media-search-input" class="search">
1163
  </div>
1164
  </div>
1165
  <ul class="attachments rl-galleries-list ui-sortable ui-sortable-disabled">
1166
  </ul>
1167
  <div class="media-sidebar visible">
1168
- <h2>' . __( 'Select A Gallery', 'responsive-lightbox' ) . '</h2>
1169
- <p>' . __( 'To select a gallery simply click on one of the boxes to the left.', 'responsive-lightbox' ) . '</p>
1170
- <p>' . __( 'To insert your gallery into the editor, click on the "Insert Gallery" button below.', 'responsive-lightbox' ) . '</p>
1171
  </div>
1172
  </div>
1173
  </div>
@@ -1176,8 +1178,8 @@ class Responsive_Lightbox_Galleries {
1176
  <div class="media-toolbar-secondary">
1177
  <div class="media-selection empty">
1178
  <div class="selection-info">
1179
- <span class="rl-gallery-count count">' . sprintf( _n( '%s image', '%s images', 0, 'responsive-lightbox' ), 0 ) . '</span>
1180
- <a href="" class="button-link rl-edit-gallery-link">' . __( 'Edit gallery', 'responsive-lightbox' ) . '</a>
1181
  </div>
1182
  <div class="selection-view">
1183
  <span class="rl-gallery-images-spinner spinner" style="display: none;"></span>
@@ -1187,9 +1189,9 @@ class Responsive_Lightbox_Galleries {
1187
  </div>
1188
  </div>
1189
  <div class="media-toolbar-primary search-form">
1190
- <button style="display: none;" type="button" class="button media-button button-primary button-large rl-media-button-insert-gallery" disabled="disabled">' . __( 'Insert gallery into post', 'responsive-lightbox') . '</button>
1191
- <button style="display: none;" type="button" class="button media-button button-primary button-large rl-media-button-select-gallery" disabled="disabled">' . __( 'Select gallery', 'responsive-lightbox') . '</button>
1192
- <button type="button" class="button media-button button-secondary button-large rl-media-button-cancel-gallery">' . __( 'Cancel', 'responsive-lightbox') . '</button>
1193
  </div>
1194
  </div>
1195
  </div>
@@ -1217,8 +1219,8 @@ class Responsive_Lightbox_Galleries {
1217
  $html = '';
1218
  $subhtml = '';
1219
  } else {
1220
- $template = $args['type'] === 'section' ? '<th colspan="2"><h3>%s</h3></th>' : '<th><label for="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '">%s</label></th><td>%s</td>';
1221
- $html = '<tr class="rl-gallery-field-' . $tab_id . '-' . $menu_item . '-' . $field . ' rl-gallery-field-' . $args['type'] . '" data-field_type="' . $args['type'] . '" data-field_name="' . $field . '">';
1222
  $subhtml = '';
1223
  }
1224
 
@@ -1227,7 +1229,7 @@ class Responsive_Lightbox_Galleries {
1227
  $html .= sprintf(
1228
  $template,
1229
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1230
- '<input id="rl_' . $tab_id . '_' . $menu_item . '_' . $field . '" type="range" value="' . $args['value'] . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" min="' . ( ! empty( $args['min'] ) ? $args['min'] : 0 ) . '"' . ( ! empty( $args['max'] ) ? ' max="' . $args['max'] . '"' : '' ) . ' step="' . ( ! empty( $args['step'] ) ? $args['step'] : 1 ) . '" oninput="this.form.rl_' . $tab_id . '_' . $menu_item . '_' . $field . '_range.value=this.value" /><output class="rl-gallery-field-output" name="rl_' . $tab_id . '_' . $menu_item . '_' . $field . '_range">' . $args['value'] . '</output>' . ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1231
  );
1232
  break;
1233
 
@@ -1235,13 +1237,13 @@ class Responsive_Lightbox_Galleries {
1235
  $subhtml = '';
1236
 
1237
  foreach ( $args['options'] as $key => $label ) {
1238
- $subhtml .= '<label class="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" for="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-' . $key . '"><input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-' . $key . '" type="radio" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" value="' . $key . '" ' . checked( $key, $args['value'], false ) . ' />' . esc_html( $label ) . '</label> ';
1239
  }
1240
 
1241
  $html .= sprintf(
1242
  $template,
1243
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1244
- $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1245
  );
1246
  break;
1247
 
@@ -1249,7 +1251,7 @@ class Responsive_Lightbox_Galleries {
1249
  $html .= sprintf(
1250
  $template,
1251
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1252
- '<input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" class="small-text" type="number" value="' . $args['value'] . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" min="' . ( ! empty( $args['min'] ) ? $args['min'] : 0 ) . '"' . ( ! empty( $args['max'] ) ? ' max="' . $args['max'] . '"' : '' ) . ' step="' . ( ! empty( $args['step'] ) ? $args['step'] : 1 ) . '" />' . ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1253
  );
1254
  break;
1255
 
@@ -1257,7 +1259,7 @@ class Responsive_Lightbox_Galleries {
1257
  $html .= sprintf(
1258
  $template,
1259
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1260
- '<input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '"' . ( ! empty( $args['class'] ) ? ' class="' . $args['class'] . '"' : '' ) . ' type="text" value="' . esc_attr( $args['value'] ) . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" />' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1261
  );
1262
  break;
1263
 
@@ -1266,22 +1268,22 @@ class Responsive_Lightbox_Galleries {
1266
  $html .= sprintf(
1267
  $template,
1268
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1269
- '<textarea id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '"' . ( ! empty( $args['class'] ) ? ' class="' . $args['class'] . '"' : '' ) . ' name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']">' . esc_textarea( $args['value'] ) . '</textarea>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1270
  );
1271
  break;
1272
 
1273
  case 'select':
1274
- $subhtml = '<select id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']">';
1275
 
1276
  foreach ( $args['options'] as $key => $label ) {
1277
  $subhtml .= '
1278
- <option value="' . $key . '" ' . selected( $args['value'], $key, false ) . '>' . $label . '</option>';
1279
  }
1280
 
1281
  $html .= sprintf(
1282
  $template,
1283
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1284
- $subhtml . '</select>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1285
  );
1286
  break;
1287
 
@@ -1306,28 +1308,28 @@ class Responsive_Lightbox_Galleries {
1306
  )
1307
  );
1308
  } else
1309
- $subhtml = '<select id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . '][]" ><option value="0">' . esc_html__( 'Root Folder', 'responsive-lightbox' ) . '</option></select> ';
1310
 
1311
  if ( isset( $args['include_children'] ) && $args['include_children'] ) {
1312
- $subhtml .= '<label class="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-include-children" for="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-include-children"><input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-include-children" type="checkbox" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . '][children]" value="true" ' . checked( $args['value']['children'], true, false ) . ' />' . esc_html__( 'Include children.', 'responsive-lightbox' ) . '</label>';
1313
  }
1314
 
1315
  $html .= sprintf(
1316
  $template,
1317
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1318
- $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1319
  );
1320
  break;
1321
 
1322
  case 'multiselect':
1323
- $subhtml = '<select multiple="multiple" class="select2" id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" data-empty="' . ( (int) empty( $args['value'] ) ) . '" data-type="' . $field . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . '][]">';
1324
 
1325
  if ( $field === 'post_term' ) {
1326
  foreach ( $args['options'] as $taxanomy => $data ) {
1327
  $subhtml .= '<optgroup label="' . esc_attr( $data['label'] ) . '">';
1328
 
1329
  foreach ( $data['terms'] as $term_id => $name ) {
1330
- $subhtml .= '<option value="' . $term_id . '" ' . selected( in_array( $term_id, $args['value'], false ), true, false ) . '>' . esc_html( $name ) . '</option>';
1331
  }
1332
 
1333
  $subhtml .= '</optgroup>';
@@ -1335,14 +1337,14 @@ class Responsive_Lightbox_Galleries {
1335
  } else {
1336
  foreach ( $args['options'] as $key => $label ) {
1337
  $subhtml .= '
1338
- <option value="' . $key . '" ' . selected( in_array( $key, $args['value'], false ), true, false ) . '>' . $label . '</option>';
1339
  }
1340
  }
1341
 
1342
  $html .= sprintf(
1343
  $template,
1344
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1345
- $subhtml . '</select>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1346
  );
1347
  break;
1348
 
@@ -1350,7 +1352,7 @@ class Responsive_Lightbox_Galleries {
1350
  $html .= sprintf(
1351
  $template,
1352
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1353
- '<label class="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" for="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '"><input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" type="checkbox" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" value="true" ' . checked( $args['value'], true, false ) . ' />' . $args['label'] . '</label>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1354
  );
1355
  break;
1356
 
@@ -1358,13 +1360,13 @@ class Responsive_Lightbox_Galleries {
1358
  $subhtml = '';
1359
 
1360
  foreach ( $args['options'] as $key => $label ) {
1361
- $subhtml .= '<label class="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-' . $key . '" for="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-' . $key . '"><input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '-' . $key . '" type="checkbox" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . '][' . $key . ']" value="true" ' . checked( in_array( $key, $args['value'], true ), true, false ) . ' />' . $label . '</label><br />';
1362
  }
1363
 
1364
  $html .= sprintf(
1365
  $template,
1366
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1367
- $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1368
  );
1369
  break;
1370
 
@@ -1378,7 +1380,7 @@ class Responsive_Lightbox_Galleries {
1378
  $html .= sprintf(
1379
  $template,
1380
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1381
- $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1382
  );
1383
  break;
1384
 
@@ -1386,7 +1388,7 @@ class Responsive_Lightbox_Galleries {
1386
  $html .= sprintf(
1387
  $template,
1388
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1389
- '<input id="rl-' . $tab_id . '-' . $menu_item . '-' . $field . '" class="color-picker" type="text" value="' . $args['value'] . '" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . ']" data-default-color="' . $args['default'] . '" />' . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1390
  );
1391
  break;
1392
 
@@ -1400,7 +1402,7 @@ class Responsive_Lightbox_Galleries {
1400
  $button_label = __( 'Select images', 'responsive-lightbox' );
1401
 
1402
  // get images
1403
- if ( ( ! empty( $data['menu_item'] ) && $data['menu_item'] === 'media' ) || ! ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-menu-content' ) )
1404
  $images = $this->get_gallery_images( $gallery_id );
1405
  else
1406
  $images = [];
@@ -1409,15 +1411,15 @@ class Responsive_Lightbox_Galleries {
1409
  $media_item_template = $this->get_media_item_template( $args['preview'] );
1410
 
1411
  // media buttons
1412
- $buttons = [ '<a href="#" class="rl-gallery-select button button-secondary">' . $button_label . '</a>' ];
1413
 
1414
  $html .= '
1415
  <td colspan="2" class="rl-colspan">
1416
- <input type="hidden" class="rl-gallery-ids" name="rl_gallery[' . $tab_id . '][' . $menu_item . '][' . $field . '][ids]" value="' . ( ! empty( $args['value']['ids'] ) ? implode( ',', $args['value']['ids'] ) : '' ) . '">';
1417
 
1418
  // embed video support?
1419
  if ( rl_current_lightbox_supports( [ 'youtube', 'vimeo' ], 'OR' ) )
1420
- $buttons[] = '<a href="#" class="rl-gallery-select-videos button button-secondary" style="margin-left: 10px;">' . __( 'Embed videos', 'responsive-lightbox' ) . '</a>';
1421
 
1422
  // add buttons
1423
  $html .= implode( '', $buttons );
@@ -1456,11 +1458,11 @@ class Responsive_Lightbox_Galleries {
1456
  $html .= '
1457
  <td colspan="2" class="rl-colspan">
1458
  <div class="rl-gallery-preview-inside">
1459
- <a href="#" class="rl-gallery-update-preview button button-secondary">' . __( 'Update preview', 'responsive-lightbox' ) . '</a><span class="spinner" style="display: none;"></span>
1460
- <p class="description">' . __( 'Use this button after any change of the options below to see updated gallery preview.', 'responsive-lightbox' ) . '</p>
1461
  </div>
1462
  <div class="rl-gallery-content">
1463
- <ul class="rl-gallery-images rl-gallery-images-' . $menu_item . '">';
1464
 
1465
  if ( ! empty( $images ) ) {
1466
  foreach ( $images as $image ) {
@@ -1503,7 +1505,7 @@ class Responsive_Lightbox_Galleries {
1503
  $html .= sprintf(
1504
  $template,
1505
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1506
- apply_filters( 'rl_render_gallery_field_' . $args['type'], $subhtml, $field, $tab_id, $menu_item, $args, $subfield ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . $args['description'] . '</p>' : '' )
1507
  );
1508
  }
1509
 
@@ -1520,7 +1522,6 @@ class Responsive_Lightbox_Galleries {
1520
  * @return string
1521
  */
1522
  public function get_preview_pagination( $current_page = 1 ) {
1523
- $items = '';
1524
  $page_links = [];
1525
  $total_pages = $current_page + 1;
1526
  $current = $current_page;
@@ -1529,7 +1530,7 @@ class Responsive_Lightbox_Galleries {
1529
 
1530
  if ( $current == 1 ) {
1531
  $disable_first = true;
1532
- $disable_prev = true;
1533
  } elseif ( $current == 2 )
1534
  $disable_first = true;
1535
 
@@ -1547,7 +1548,7 @@ class Responsive_Lightbox_Galleries {
1547
  $page_links[] = sprintf(
1548
  '<a class="first-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1549
  $current_url,
1550
- __( 'First page', 'responsive-lightbox' ),
1551
  '&laquo;'
1552
  );
1553
  }
@@ -1558,14 +1559,14 @@ class Responsive_Lightbox_Galleries {
1558
  $page_links[] = sprintf(
1559
  '<a class="prev-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1560
  $current_url . '/' . max( 1, $current - 1 ),
1561
- __( 'Previous page', 'responsive-lightbox' ),
1562
  '&lsaquo;'
1563
  );
1564
  }
1565
 
1566
  $html_current_page = sprintf(
1567
  '%s<input disabled="disabled" class="current-page" id="current-page-selector" type="text" name="paged" value="%s" size="%d" aria-describedby="table-paging" /><span class="tablenav-paging-text">',
1568
- '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page', 'responsive-lightbox' ) . '</label>',
1569
  $current,
1570
  strlen( $total_pages )
1571
  );
@@ -1579,7 +1580,7 @@ class Responsive_Lightbox_Galleries {
1579
  $page_links[] = sprintf(
1580
  '<a class="next-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1581
  $current_url . '/' . min( $total_pages, $current + 1 ),
1582
- __( 'Next page', 'responsive-lightbox' ),
1583
  '&rsaquo;'
1584
  );
1585
  }
@@ -1590,17 +1591,17 @@ class Responsive_Lightbox_Galleries {
1590
  $page_links[] = sprintf(
1591
  '<a class="last-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1592
  $current_url . '/' . $total_pages,
1593
- __( 'Last page', 'responsive-lightbox' ),
1594
  '&raquo;'
1595
  );
1596
  }
1597
 
1598
  if ( $total_pages )
1599
- $page_class = $total_pages < 2 ? ' one-page' : '';
1600
  else
1601
- $page_class = ' no-pages';
1602
 
1603
- return '<div class="rl-gallery-preview-pagination tablenav"><div class="tablenav-pages' . $page_class . '">' . $items . '<span class="pagination-links">' . join( "\n", $page_links ) . '</span></div>';
1604
  }
1605
 
1606
  /**
@@ -1701,7 +1702,7 @@ class Responsive_Lightbox_Galleries {
1701
  $value = trim( $value );
1702
 
1703
  // more than 1 class?
1704
- if ( strpos( $value, ' ' ) !== false ) {
1705
  // get unique valid HTML classes
1706
  $value = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $value ) ) ) );
1707
 
@@ -1777,7 +1778,7 @@ class Responsive_Lightbox_Galleries {
1777
 
1778
  continue;
1779
  } else
1780
- $copy[$embed_id]['url'] = esc_url( $embed_data['url'] );
1781
 
1782
  // check width
1783
  if ( ! array_key_exists( 'width', $embed_data ) )
@@ -1795,7 +1796,7 @@ class Responsive_Lightbox_Galleries {
1795
  if ( empty( $embed_data['thumbnail_url'] ) )
1796
  $copy[$embed_id]['thumbnail_url'] = '';
1797
  else
1798
- $copy[$embed_id]['thumbnail_url'] = esc_url( $embed_data['thumbnail_url'] );
1799
 
1800
  // check thumbnail width
1801
  if ( ! array_key_exists( 'thumbnail_width', $embed_data ) )
@@ -1974,14 +1975,16 @@ class Responsive_Lightbox_Galleries {
1974
 
1975
  global $wp_meta_boxes;
1976
 
1977
- $active_tab = ! empty( $_GET['rl_active_tab'] ) && array_key_exists( $_GET['rl_active_tab'], $this->tabs ) ? $_GET['rl_active_tab'] : 'images';
 
 
1978
 
1979
  echo '
1980
  <h2 class="nav-tab-wrapper">';
1981
 
1982
  foreach ( $this->tabs as $key => $data ) {
1983
  echo '
1984
- <a id="rl-gallery-tab-' . $key . '" class="rl-gallery-tab nav-tab' . ( $key === $active_tab ? ' nav-tab-active' : '' ) . '" href="#' . $key . '">' . $data['label'] . '</a>';
1985
  }
1986
 
1987
  echo '
@@ -2025,7 +2028,10 @@ class Responsive_Lightbox_Galleries {
2025
  * @return string
2026
  */
2027
  function add_active_tab( $location ) {
2028
- return add_query_arg( 'rl_active_tab', ! empty( $_POST['rl_active_tab'] ) && array_key_exists( $_POST['rl_active_tab'], $this->tabs ) ? $_POST['rl_active_tab'] : 'images', $location );
 
 
 
2029
  }
2030
 
2031
  /**
@@ -2034,7 +2040,9 @@ class Responsive_Lightbox_Galleries {
2034
  * @return void
2035
  */
2036
  public function add_meta_boxes() {
2037
- $active_tab = ! empty( $_GET['rl_active_tab'] ) && array_key_exists( $_GET['rl_active_tab'], $this->tabs ) ? $_GET['rl_active_tab'] : 'images';
 
 
2038
 
2039
  // normal metaboxes
2040
  foreach ( $this->tabs as $key => $args ) {
@@ -2049,11 +2057,11 @@ class Responsive_Lightbox_Galleries {
2049
  else
2050
  add_filter( 'postbox_classes_rl_gallery_responsive-gallery-' . $key, array( $this, 'hide_metabox' ) );
2051
 
2052
- add_meta_box( 'responsive-gallery-' . $key, sprintf( __( 'Gallery %s', 'responsive-lightbox' ), $args['label'] ), array( $this, 'add_metabox' ), 'rl_gallery', 'responsive_lightbox_metaboxes', 'high', $new_args );
2053
  }
2054
 
2055
  // side metaboxes
2056
- add_meta_box( 'responsive-gallery-shortcode', __( 'Gallery Code', 'responsive-lightbox' ), array( $this, 'shortcode_metabox' ), 'rl_gallery', 'side', 'core' );
2057
  }
2058
 
2059
  /**
@@ -2087,16 +2095,16 @@ class Responsive_Lightbox_Galleries {
2087
  $menu_item = ! empty( $data['menu_item'] ) && in_array( $data['menu_item'], array_keys( $callback_args['args']['menu_items'] ) ) ? $data['menu_item'] : key( $callback_args['args']['menu_items'] );
2088
 
2089
  $html .= '
2090
- <div class="rl-gallery-tab-menu rl-gallery-tab-menu-' . $callback_args['args']['tab_id'] . '">';
2091
 
2092
  foreach ( $callback_args['args']['menu_items'] as $menu_key => $menu_label ) {
2093
  // disable select for remote library if needed
2094
  if ( $menu_key === 'remote_library' && ! $rl->options['remote_library']['active'] ) {
2095
- $title = ' title="' . __( 'Remote Library is disabled. Enable it in the settings.', 'responsive-lightbox' ) . '"';
2096
  $disabled = ' disabled="disabled"';
2097
  // disable select for media folders if needed
2098
  } elseif ( $menu_key === 'folders' && ! $rl->options['folders']['active'] ) {
2099
- $title = ' title="' . __( 'Media Folders are disabled. Enable it in the settings.', 'responsive-lightbox' ) . '"';
2100
  $disabled = ' disabled="disabled"';
2101
  // other menu items
2102
  } else {
@@ -2105,7 +2113,7 @@ class Responsive_Lightbox_Galleries {
2105
  }
2106
 
2107
  $html .= '
2108
- <label' . $title . '><input type="radio" class="rl-gallery-tab-menu-item" name="rl_gallery[' . $callback_args['args']['tab_id'] . '][menu_item]" value="' . $menu_key . '" ' . checked( $menu_item, $menu_key, false ) . $disabled . ' />' . esc_html( $menu_label ) . ( $callback_args['args']['tab_id'] === 'config' && $menu_key === 'default' ? ' (' . $this->tabs['config']['menu_items'][$rl->options['settings']['builder_gallery']] . ')' : '' ) . '</label>';
2109
  }
2110
 
2111
  $html .= '
@@ -2117,10 +2125,10 @@ class Responsive_Lightbox_Galleries {
2117
 
2118
  // disable gallery images content for remote library or media folders if needed
2119
  if ( $callback_args['args']['tab_id'] === 'images' && ( ( $menu_item === 'remote_library' && ! $rl->options['remote_library']['active'] ) || ( $menu_item === 'folders' && ! $rl->options['folders']['active'] ) ) )
2120
- $content = ' rl-loading-content';
2121
 
2122
  $html .= '
2123
- <div class="rl-gallery-tab-content rl-gallery-tab-content-' . $callback_args['args']['tab_id'] . $content . '">';
2124
 
2125
  $html .= ! empty( $callback_args['args']['callback'] ) && is_callable( $callback_args['args']['callback'] ) ? call_user_func( $callback_args['args']['callback'], $callback_args['args']['tab_id'], $data, $menu_item, $post->ID ) : $this->get_metabox_content( $callback_args['args']['tab_id'], $data, $menu_item, $post->ID );
2126
 
@@ -2141,7 +2149,7 @@ class Responsive_Lightbox_Galleries {
2141
  */
2142
  public function get_metabox_content( $tab_id, $data, $menu_item, $gallery_id = 0 ) {
2143
  $html = '
2144
- <div class="rl-gallery-tab-inside rl-gallery-tab-inside-' . $tab_id . '-' . $menu_item . '">
2145
  <table class="form-table">';
2146
 
2147
  switch ( $tab_id ) {
@@ -2198,7 +2206,7 @@ class Responsive_Lightbox_Galleries {
2198
  }
2199
  // just in case ajax would fail
2200
  } else
2201
- $html .= '<p>' . __( 'No data', 'responsive-lightbox' ) . '</p>';
2202
  break;
2203
 
2204
  default:
@@ -2332,7 +2340,7 @@ class Responsive_Lightbox_Galleries {
2332
  global $pagenow;
2333
 
2334
  // is it preview?
2335
- if ( ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) && $gallery_id ) || ( isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-preview-content' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && ( $_POST['action'] === 'rl-post-gallery-preview' || $_POST['action'] === 'rl-get-menu-content' ) ) )
2336
  $args['images_per_page'] = 0;
2337
 
2338
  if ( isset( $_GET['rl_page'] ) )
@@ -2827,9 +2835,9 @@ class Responsive_Lightbox_Galleries {
2827
  $current_action = current_action();
2828
 
2829
  if ( $current_action === 'rl_before_gallery' )
2830
- $class = ' rl-pagination-top';
2831
  elseif ( $current_action === 'rl_after_gallery' )
2832
- $class = ' rl-pagination-bottom';
2833
  else
2834
  $class = '';
2835
 
@@ -2844,7 +2852,7 @@ class Responsive_Lightbox_Galleries {
2844
  $base_args['rl_lightbox_script'] = $rl->get_lightbox_script();
2845
 
2846
  echo
2847
- '<div class="rl-pagination' . $class . '"' . ( $args['pagination_type'] === 'infinite' ? ' data-button="' . $args['load_more'] . '"' : '' ) .'>' .
2848
  paginate_links(
2849
  [
2850
  'format' => '?rl_page=%#%',
@@ -2855,8 +2863,8 @@ class Responsive_Lightbox_Galleries {
2855
  'end_size' => 1,
2856
  'mid_size' => 2,
2857
  'prev_next' => true,
2858
- 'prev_text' => __( '&laquo; Previous', 'responsive-lightbox' ),
2859
- 'next_text' => __( 'Next &raquo;', 'responsive-lightbox' ),
2860
  'type' => 'plain',
2861
  'add_args' => '',
2862
  'add_fragment' => '',
@@ -2882,10 +2890,10 @@ class Responsive_Lightbox_Galleries {
2882
  * @return void
2883
  */
2884
  public function maybe_change_lightbox() {
2885
- // early ajax check
2886
  if ( $this->gallery_ajax_verified() ) {
2887
  // set new lightbox script
2888
- Responsive_Lightbox()->set_lightbox_script( $_POST['lightbox'] );
2889
  }
2890
  }
2891
 
@@ -2896,6 +2904,7 @@ class Responsive_Lightbox_Galleries {
2896
  * @return void
2897
  */
2898
  public function get_gallery_page( $args ) {
 
2899
  if ( $this->gallery_ajax_verified() ) {
2900
  // cast page number
2901
  $_GET['rl_page'] = (int) $_POST['page'];
@@ -2926,15 +2935,18 @@ class Responsive_Lightbox_Galleries {
2926
  wp_send_json_error();
2927
 
2928
  // check page
2929
- if ( ! in_array( $_POST['page'], [ 'widgets.php', 'customize.php', 'post.php', 'post-new.php' ], true ) )
 
 
 
2930
  wp_send_json_error();
2931
 
2932
  // check edit_post capability
2933
- if ( ( $_POST['page'] === 'post.php' || $_POST['page'] === 'post-new.php' ) && ! current_user_can( 'edit_post', (int) $_POST['post_id'] ) )
2934
  wp_send_json_error();
2935
 
2936
  // check edit_theme_options capability
2937
- if ( ( $_POST['page'] === 'widgets.php' || $_POST['page'] === 'customize.php' ) && ! current_user_can( 'edit_theme_options' ) )
2938
  wp_send_json_error();
2939
 
2940
  // parse gallery id
@@ -2962,11 +2974,11 @@ class Responsive_Lightbox_Galleries {
2962
  if ( ! empty( $images ) ) {
2963
  foreach ( $images as $image ) {
2964
  $html .= '
2965
- <li tabindex="0" role="checkbox" aria-label="' . esc_attr( $image['title'] ) . '" aria-checked="true" data-id="' . $image['id'] . '" class="attachment selection selected rl-status-active">
2966
  <div class="attachment-preview js--select-attachment type-image ' . esc_attr( $image['thumbnail_orientation'] ). '">
2967
  <div class="thumbnail">
2968
  <div class="centered">
2969
- <img src="' . $image['thumbnail_url'] . '" draggable="false" alt="" />
2970
  </div>
2971
  </div>
2972
  </div>
@@ -2978,8 +2990,8 @@ class Responsive_Lightbox_Galleries {
2978
  wp_send_json_success(
2979
  array(
2980
  'attachments' => $html,
2981
- 'count' => sprintf( _n( '%s image', '%s images', $images_count, 'responsive-lightbox' ), $images_count ),
2982
- 'edit_url' => current_user_can( 'edit_post', $gallery_id ) ? admin_url( 'post.php?post=' . $gallery_id . '&action=edit' ): ''
2983
  )
2984
  );
2985
  }
@@ -2995,15 +3007,18 @@ class Responsive_Lightbox_Galleries {
2995
  wp_send_json_error();
2996
 
2997
  // check page
2998
- if ( ! in_array( $_POST['page'], [ 'widgets.php', 'customize.php', 'post.php', 'post-new.php' ], true ) )
 
 
 
2999
  wp_send_json_error();
3000
 
3001
  // check edit_post capability
3002
- if ( ( $_POST['page'] === 'post.php' || $_POST['page'] === 'post-new.php' ) && ! current_user_can( 'edit_post', (int) $_POST['post_id'] ) )
3003
  wp_send_json_error();
3004
 
3005
  // check edit_theme_options capability
3006
- if ( ( $_POST['page'] === 'widgets.php' || $_POST['page'] === 'customize.php' ) && ! current_user_can( 'edit_theme_options' ) )
3007
  wp_send_json_error();
3008
 
3009
  $args = array(
@@ -3018,15 +3033,18 @@ class Responsive_Lightbox_Galleries {
3018
  'cache_results' => false
3019
  );
3020
 
 
 
 
3021
  // specific category?
3022
- if ( ! empty( $_POST['category'] ) ) {
3023
  $args['tax_query'] = array(
3024
  array(
3025
  'taxonomy' => 'rl_category',
3026
  'field' => 'term_id',
3027
  'operator' => 'IN',
3028
  'include_children' => false,
3029
- 'terms' => (int) $_POST['category']
3030
  )
3031
  );
3032
  }
@@ -3046,7 +3064,7 @@ class Responsive_Lightbox_Galleries {
3046
  if ( ! empty( $query->posts ) ) {
3047
  foreach ( $query->posts as $gallery ) {
3048
  // save gallery id
3049
- $ids[] = $gallery->ID;
3050
 
3051
  // get featured image
3052
  $featured = $this->get_featured_image_src( $gallery->ID );
@@ -3057,13 +3075,13 @@ class Responsive_Lightbox_Galleries {
3057
  $featured_image = '';
3058
 
3059
  // get title
3060
- $title = $gallery->post_title !== '' ? $gallery->post_title : __( '(no title)', 'responsive-gallery' );
3061
 
3062
  $html .= '
3063
- <li tabindex="0" role="checkbox" aria-label="' . esc_attr( $title ) . '" aria-checked="true" data-id="' . $gallery->ID . '" class="attachment selection">
3064
  <div class="attachment-preview js--select-attachment type-image ' . ( ! empty( $featured['thumbnail_orientation'] ) ? esc_attr( $featured['thumbnail_orientation'] ) : 'landscape' ) . '">
3065
  <div class="thumbnail">
3066
- <div class="centered" data-full-src="' . $featured_image . '">
3067
  ' . $this->get_featured_image( $gallery->ID, 'thumbnail' ) . '
3068
  </div>
3069
  <div class="filename">
@@ -3071,7 +3089,7 @@ class Responsive_Lightbox_Galleries {
3071
  </div>
3072
  </div>
3073
  </div>
3074
- <button type="button" class="button-link check"><span class="media-modal-icon"></span><span class="screen-reader-text">' . __( 'Deselect', 'responsive-lightbox' ) . '</span></button>
3075
  </li>';
3076
  }
3077
  }
@@ -3091,14 +3109,29 @@ class Responsive_Lightbox_Galleries {
3091
  * @return void
3092
  */
3093
  public function get_menu_content() {
3094
- if ( ! isset( $_POST['post_id'], $_POST['tab'], $_POST['menu_item'], $_POST['nonce'] ) || ! check_ajax_referer( 'rl-gallery', 'nonce', false ) || ! current_user_can( 'edit_post', $post_id = (int) $_POST['post_id'] ) || ! array_key_exists( $_POST['tab'], $this->tabs ) )
 
 
 
 
 
 
3095
  wp_send_json_error();
3096
 
 
 
 
 
 
 
 
 
 
3097
  // get selected menu item
3098
- $menu_item = ! empty( $_POST['menu_item'] ) && in_array( $_POST['menu_item'], array_keys( $this->tabs[$_POST['tab']]['menu_items'] ) ) ? esc_attr( $_POST['menu_item'] ) : key( $this->tabs[$_POST['tab']]['menu_items'] );
3099
 
3100
  // get tab content
3101
- wp_send_json_success( $this->get_metabox_content( $_POST['tab'], get_post_meta( $post_id, '_rl_' . $_POST['tab'], true ), $menu_item, $post_id ) );
3102
  }
3103
 
3104
  /**
@@ -3136,13 +3169,16 @@ class Responsive_Lightbox_Galleries {
3136
  }
3137
 
3138
  // check preview type
3139
- if ( ! in_array( $_POST['preview_type'], [ 'page', 'update' ], true ) )
 
 
 
3140
  $args['preview_type'] = 'page';
3141
  else
3142
- $args['preview_type'] = $_POST['preview_type'];
3143
 
3144
- // check for POST menu item
3145
- $menu_item = ! empty( $_POST['menu_item'] ) && is_string( $_POST['menu_item'] ) ? esc_attr( $_POST['menu_item'] ) : '';
3146
 
3147
  // set images menu item
3148
  $menu_item = $this->menu_item = ! empty( $menu_item ) && array_key_exists( $menu_item, $this->tabs['images']['menu_items'] ) ? $menu_item : 'media';
@@ -3206,11 +3242,11 @@ class Responsive_Lightbox_Galleries {
3206
  }
3207
 
3208
  // parse excluded images
3209
- $excluded = ! empty( $_POST['excluded'] ) ? $_POST['excluded'] : [];
3210
 
3211
  // get excluded images
3212
- if ( $excluded )
3213
- $excluded = array_unique( array_filter( array_map( 'intval', $excluded ) ) );
3214
 
3215
  // get media item template
3216
  $media_item_template = $this->get_media_item_template( $this->fields['images'][$menu_item]['attachments']['preview'] );
@@ -3270,7 +3306,7 @@ class Responsive_Lightbox_Galleries {
3270
  '__EMBED_DATE__'
3271
  ],
3272
  [
3273
- $image['id'],
3274
  esc_url( $image['url'] ),
3275
  (int) $image['width'],
3276
  (int) $image['height'],
@@ -3279,7 +3315,7 @@ class Responsive_Lightbox_Galleries {
3279
  (int) $image['thumbnail_height'],
3280
  esc_attr( $image['title'] ),
3281
  esc_textarea( $image['caption'] ),
3282
- $image['date']
3283
  ],
3284
  $this->get_media_embed_template( false )
3285
  );
@@ -3296,9 +3332,9 @@ class Responsive_Lightbox_Galleries {
3296
  ],
3297
  [
3298
  $this->get_media_exclude_input_template( $tab_id, $menu_item, $field_name, $excluded_flag ? $excluded_item : '' ) . $media_html . $image['thumbnail_link'],
3299
- $image['id'],
3300
  $excluded_flag ? ' rl-status-inactive' : ' rl-status-active',
3301
- $image['type']
3302
  ],
3303
  $template
3304
  );
@@ -3344,15 +3380,12 @@ class Responsive_Lightbox_Galleries {
3344
  // apply filters if any
3345
  $attr = apply_filters( 'rl_get_gallery_image_attributes', $attr, $image, $size );
3346
 
3347
- // escape every attribute
3348
- $attr = array_map( 'esc_attr', $attr );
3349
-
3350
  // start link output
3351
  $link = rtrim( '<img ' . image_hwstring( $width, $height ) );
3352
 
3353
  // add attributes
3354
  foreach ( $attr as $name => $value ) {
3355
- $link .= ' ' . $name . '="' . $value . '"';
3356
  }
3357
 
3358
  // end link output
@@ -3497,19 +3530,19 @@ class Responsive_Lightbox_Galleries {
3497
 
3498
  $imagedata = array(
3499
  'id' => ! empty( $image['id'] ) ? ( preg_match( '/^e\d+$/', $image['id'] ) === 1 ? $image['id'] : (int) $image['id'] ) : 0,
3500
- 'title' => ! empty( $image['title'] ) ? esc_html( $image['title'] ) : '',
3501
- 'date' => ! empty( $image['date'] ) ? esc_html( $image['date'] ) : '',
3502
- 'caption' => ! empty( $image['caption'] ) ? esc_html( $image['caption'] ) : '',
3503
- 'alt' => ! empty( $image['alt'] ) ? esc_html( $image['alt'] ) : '',
3504
- 'url' => ! empty( $image['url'] ) ? esc_url( $image['url'] ) : '',
3505
  'width' => ! empty( $image['width'] ) ? (int) $image['width'] : 0,
3506
  'height' => ! empty( $image['height'] ) ? (int) $image['height'] : 0,
3507
- 'thumbnail_url' => ! empty( $image['thumbnail_url'] ) ? esc_url( $image['thumbnail_url'] ) : '',
3508
  'thumbnail_width' => ! empty( $image['thumbnail_width'] ) ? (int) $image['thumbnail_width'] : 0,
3509
  'thumbnail_height' => ! empty( $image['thumbnail_height'] ) ? (int) $image['thumbnail_height'] : 0,
3510
- 'link' => ! empty( $image['link'] ) ? esc_url( $image['link'] ) : '',
3511
- 'thumbnail_link' => ! empty( $image['thumbnail_link'] ) ? esc_url( $image['thumbnail_link'] ) : '',
3512
- 'type' => ! empty( $image['type'] ) ? esc_html( $image['type'] ) : 'image'
3513
  );
3514
 
3515
  $imagedata['orientation'] = $imagedata['height'] > $imagedata['width'] ? 'portrait' : 'landscape';
@@ -3916,12 +3949,18 @@ class Responsive_Lightbox_Galleries {
3916
  public function init_admin() {
3917
  global $pagenow;
3918
 
 
 
 
 
 
 
3919
  // prepare query arguments if needed
3920
- if ( ( $pagenow === 'post.php' && ( ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) === 'rl_gallery' ) || ( isset( $_POST['post_ID'] ) && get_post_type( $_POST['post_ID'] ) === 'rl_gallery' ) ) ) || ( in_array( $pagenow, array( 'edit.php', 'post-new.php'), true ) && isset( $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' ) || ( $pagenow === 'admin-ajax.php' && isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'rl-get-preview-content', 'rl-post-gallery-preview', 'rl-get-menu-content' ), true ) ) )
3921
  $this->fields['images']['featured'] = $this->prepare_featured_fields( $this->fields['images']['featured'] );
3922
 
3923
  // add default thumbnail image if needed
3924
- if ( Responsive_Lightbox()->options['builder']['gallery_builder'] && $pagenow === 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' )
3925
  $this->maybe_generate_thumbnail();
3926
  }
3927
 
@@ -4487,7 +4526,10 @@ class Responsive_Lightbox_Galleries {
4487
  * @return void
4488
  */
4489
  public function save_post( $post_id, $post, $update ) {
4490
- if ( wp_is_post_revision( $post_id ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! $update || in_array( $post->post_status, array( 'trash', 'auto-draft' ), true ) || ( isset( $_GET['action'] ) && $_GET['action'] === 'untrash' ) || empty( $_POST['rl_gallery'] ) )
 
 
 
4491
  return;
4492
 
4493
  // save gallery
@@ -4575,7 +4617,7 @@ class Responsive_Lightbox_Galleries {
4575
  // custom url
4576
  case 'url':
4577
  $thumbnail_id = $this->maybe_generate_thumbnail();
4578
- $featured_image = isset( $post_data['_rl_thumbnail_url'] ) ? esc_url( $post_data['_rl_thumbnail_url'] ) : '';
4579
  break;
4580
 
4581
  // first image
@@ -4611,7 +4653,7 @@ class Responsive_Lightbox_Galleries {
4611
 
4612
  $postdata = [
4613
  'ID' => $post_id,
4614
- 'post_excerpt' => wp_kses_post( $safedata['misc']['options']['gallery_description'] )
4615
  ];
4616
 
4617
  wp_update_post( $postdata );
@@ -4679,10 +4721,10 @@ class Responsive_Lightbox_Galleries {
4679
  */
4680
  public function shortcode_metabox( $post ) {
4681
  echo '
4682
- <p>' . __( 'You can place this gallery anywhere into your posts, pages, custom post types or widgets by using the shortcode below', 'responsive-lightbox' ) . ':</p>
4683
- <code class="rl-shortcode" data-number="0">[rl_gallery id=&quot;' . $post->ID . '&quot;]</code>
4684
- <p>' . __( 'You can also place this gallery into your template files by using the template tag below', 'responsive-lightbox' ) . ':</p>
4685
- <code class="rl-shortcode" data-number="1">if ( function_exists( \'rl_gallery\' ) ) { rl_gallery( \'' . $post->ID . '\' ); }</code>';
4686
  }
4687
 
4688
  /**
@@ -4699,7 +4741,7 @@ class Responsive_Lightbox_Galleries {
4699
  $columns = array_merge(
4700
  array_slice( $columns, 0, $offset ),
4701
  array(
4702
- 'image' => __( 'Gallery', 'responsive-lightbox' )
4703
  ),
4704
  array_slice( $columns, $offset )
4705
  );
@@ -4708,9 +4750,9 @@ class Responsive_Lightbox_Galleries {
4708
  $columns = array_merge(
4709
  array_slice( $columns, 0, $offset + 2 ),
4710
  array(
4711
- 'shortcode' => __( 'Shortcode', 'responsive-lightbox' ),
4712
- 'type' => __( 'Type', 'responsive-lightbox' ),
4713
- 'source' => __( 'Source', 'responsive-lightbox' )
4714
  ),
4715
  array_slice( $columns, $offset + 2 )
4716
  );
@@ -4739,23 +4781,23 @@ class Responsive_Lightbox_Galleries {
4739
 
4740
  // display count
4741
  if ( ! empty( $image ) )
4742
- echo '<span class="media-icon image-icon">' . $image . '</span><span>' . sprintf( _n( '%s element', '%s elements', $images_count, 'responsive-lightbox' ), $images_count ) . '</span>';
4743
  else
4744
  echo '<span class="media-icon image-icon">' . wp_get_attachment_image( 0, array( 60, 60 ), true, array( 'alt' => '' ) ) . '</span>';
4745
  break;
4746
 
4747
  case 'shortcode':
4748
- echo '<code>[rl_gallery id="' . $post_id . '"]</code>';
4749
  break;
4750
 
4751
  case 'type':
4752
  $config = get_post_meta( $post_id, '_rl_config', true );
4753
 
4754
  if ( ! empty( $config['menu_item'] ) && array_key_exists( $config['menu_item'], $this->tabs['config']['menu_items'] ) ) {
4755
- echo $this->tabs['config']['menu_items'][$config['menu_item']];
4756
 
4757
  if ( $config['menu_item'] === 'default' )
4758
- echo ' (' . $this->tabs['config']['menu_items'][Responsive_Lightbox()->options['settings']['builder_gallery']] . ')';
4759
  } else
4760
  echo '-';
4761
  break;
@@ -4764,7 +4806,7 @@ class Responsive_Lightbox_Galleries {
4764
  $images = get_post_meta( $post_id, '_rl_images', true );
4765
 
4766
  if ( ! empty( $images['menu_item'] ) && array_key_exists( $images['menu_item'], $this->tabs['images']['menu_items'] ) )
4767
- echo $this->tabs['images']['menu_items'][$images['menu_item']];
4768
  else
4769
  echo '-';
4770
  break;
@@ -4785,16 +4827,16 @@ class Responsive_Lightbox_Galleries {
4785
  $sizes = [];
4786
 
4787
  foreach ( get_intermediate_image_sizes() as $_size ) {
4788
- if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
4789
  $sizes[$_size]['width'] = get_option( "{$_size}_size_w" );
4790
  $sizes[$_size]['height'] = get_option( "{$_size}_size_h" );
4791
  $sizes[$_size]['crop'] = (bool) get_option( "{$_size}_crop" );
4792
  } elseif ( isset( $_wp_additional_image_sizes[$_size] ) ) {
4793
- $sizes[$_size] = array(
4794
  'width' => $_wp_additional_image_sizes[$_size]['width'],
4795
  'height' => $_wp_additional_image_sizes[$_size]['height'],
4796
  'crop' => $_wp_additional_image_sizes[$_size]['crop'],
4797
- );
4798
  }
4799
  }
4800
 
@@ -4829,7 +4871,7 @@ class Responsive_Lightbox_Galleries {
4829
  $type = ! empty( $type ) && in_array( $type, array( 'image', 'id', 'url' ) ) ? $type : 'image';
4830
 
4831
  // force media library image
4832
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
4833
  $type = 'id';
4834
  // post featured image is post thumbnail replacement?
4835
  elseif ( $this->maybe_generate_thumbnail() === (int) $thumbnail_id ) {
88
  </div>
89
  </div>
90
  <div class="rl-gallery-actions">' .
91
+ ( $args['changeable'] ? '<a href="#" class="rl-gallery-image-status dashicons dashicons-marker" title="' . esc_attr__( 'Status', 'responsive-lightbox' ) . '"></a>' : '' ) .
92
+ ( $args['editable'] ? '<a href="#" class="rl-gallery-image-edit dashicons dashicons-edit" title="' . esc_attr__( 'Edit image', 'responsive-lightbox' ) . '"></a>' : '' ) .
93
+ ( $args['removable'] ? '<a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' . esc_attr__( 'Remove image', 'responsive-lightbox' ) . '"></a>' : '' ) . '
94
  </div>
95
  </li>';
96
  }
147
  '__MEDIA_FIELD_VALUE__'
148
  ],
149
  [
150
+ esc_attr( $tab_id ),
151
+ esc_attr( $menu_item ),
152
+ esc_attr( $field_name ),
153
  empty( $excluded_value ) ? '' : esc_attr( $excluded_value )
154
  ],
155
  $template
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( sanitize_key( $_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' );
693
  * @return void
694
  */
695
  public function duplicate_gallery() {
696
+ if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) ) || ! isset( $_REQUEST['action'] ) || ! isset( $_REQUEST['rl_gallery_nonce'] ) || ( isset( $_REQUEST['rl_gallery_nonce'] ) && ! wp_verify_nonce( $_REQUEST['rl_gallery_nonce'], 'responsive-lightbox-duplicate-gallery' ) ) )
697
+ wp_die( esc_html__( 'No gallery to duplicate has been supplied!', 'responsive-lightbox' ) );
698
 
699
  // get the original post
700
+ $post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : ( isset( $_POST['post'] ) ? (int) $_POST['post'] : 0 );
701
 
702
  if ( empty( $post_id ) )
703
+ wp_die( esc_html__( 'No gallery to duplicate has been supplied!', 'responsive-lightbox' ) );
704
 
705
  if ( ! current_user_can( 'edit_post', $post_id ) )
706
+ wp_die( esc_html__( 'You do not have permission to copy this gallery.', 'responsive-lightbox' ) );
707
 
708
  $post = get_post( $post_id );
709
 
710
  // copy the post and insert it
711
+ if ( isset( $post ) && $post !== null ) {
712
+ $this->create_gallery_duplicate( $post );
713
 
714
  // redirect to the post list screen
715
  wp_redirect( admin_url( 'edit.php?post_type=' . $post->post_type ) );
716
  exit;
717
  } else
718
+ wp_die( esc_html__( 'Copy creation failed, could not find original gallery:', 'responsive-lightbox' ) . ' ' . (int) $post_id );
719
  }
720
 
721
  /**
737
  return $actions;
738
 
739
  // duplicate link
740
+ $actions['duplicate_gallery'] = '<a class="duplicate-gallery" title="' . esc_attr__( 'Duplicate this item', 'responsive-lightbox' ) . '" href="' . esc_url( wp_nonce_url( admin_url( $pagenow . '?post=' . $post->ID . '&action=duplicate_gallery' ), 'responsive-lightbox-duplicate-gallery', 'rl_gallery_nonce' ) ) . '">' . esc_html__( 'Duplicate', 'responsive-lightbox' ) . '</a>';
741
 
742
  return $actions;
743
  }
750
  */
751
  public function create_gallery_duplicate( $post ) {
752
  // skip revisions
753
+ if ( $post->post_type === 'revision' )
754
  return;
755
 
756
  $new_post = apply_filters(
757
  'rl_duplicate_gallery_args',
758
+ [
759
  'menu_order' => $post->menu_order,
760
  'comment_status' => $post->comment_status,
761
  'ping_status' => $post->ping_status,
770
  'post_type' => $post->post_type,
771
  'post_date' => current_time( 'mysql' ),
772
  'post_date_gmt' => get_gmt_from_date( current_time( 'mysql' ) )
773
+ ],
774
  $post
775
  );
776
 
777
  $new_post_id = wp_insert_post( $new_post );
778
 
779
  // if the copy is published or scheduled, we have to set a proper slug
780
+ if ( $new_post['post_status'] === 'publish' || $new_post['post_status'] === 'future' ) {
781
  $post_name = wp_unique_post_slug( $post->post_name, $new_post_id, $new_post['post_status'], $post->post_type, $new_post['post_parent'] );
782
 
783
  $new_post = [];
989
 
990
  foreach ( $fields as $arg => $value ) {
991
  if ( is_array( $value ) )
992
+ $shortcode .= ' ' . esc_attr( $arg ) . '="' . esc_attr( (string) implode( ',', $value ) ) . '"';
993
  else
994
+ $shortcode .= ' ' . esc_attr( $arg ) . '="' . esc_attr( (string) $value ) . '"';
995
  }
996
 
997
  // get design data
999
 
1000
  if ( ! empty( $design['menu_item'] ) ) {
1001
  foreach ( $design[$design['menu_item']] as $arg => $value ) {
1002
+ $shortcode .= ' ' . esc_attr( $arg ) . '="' . esc_attr( (string) $value ) . '"';
1003
  }
1004
  }
1005
 
1008
 
1009
  if ( ! empty( $lightbox['menu_item'] ) ) {
1010
  foreach ( $lightbox[$lightbox['menu_item']] as $arg => $value ) {
1011
+ $shortcode .= ' ' . esc_attr( $arg ) . '="' . esc_attr( (string) $value ) . '"';
1012
  }
1013
  }
1014
 
1023
  }
1024
 
1025
  // get content
1026
+ $content = do_shortcode( '[gallery rl_gallery_id="' . esc_attr( $args['id'] ) .'"' . $forced_gallery_no . ' include="' . ( empty( $attachments ) ? '' : esc_attr( implode( ',', $attachments ) ) ) . '"' . $shortcode . ']' );
1027
 
1028
  // make sure every filter is available in frontend ajax
1029
  if ( wp_doing_ajax() )
1044
 
1045
  $this->enqueue_gallery_scripts_styles();
1046
 
1047
+ echo '<button type="button" id="rl-insert-modal-gallery-button" class="button" data-editor="' . esc_attr( $editor_id ) . '"><span class="wp-media-buttons-icon dashicons dashicons-format-gallery"></span> ' . esc_html__( 'Add Gallery', 'responsive-lightbox' ) . '</button>';
1048
  }
1049
 
1050
  /**
1103
  // get main instance
1104
  $rl = Responsive_Lightbox();
1105
 
1106
+ $categories = '';
1107
+
1108
  // builder categories?
1109
  if ( $rl->options['builder']['categories'] ) {
1110
  $terms = get_terms(
1142
  echo '
1143
  <div id="rl-modal-gallery" style="display: none;">
1144
  <div class="media-modal wp-core-ui">
1145
+ <button type="button" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text">' . esc_html__( 'Close', 'responsive-lightbox' ) . '</span></span></button>
1146
  <div class="media-modal-content">
1147
  <div class="media-frame mode-select wp-core-ui hide-menu hide-router">
1148
  <div class="media-frame-title">
1149
+ <h1 class="wrap">' . esc_html__( 'Insert Gallery', 'responsive-lightbox' ) . ' <a class="rl-reload-galleries page-title-action" href="#">' . esc_html__( 'Reload', 'responsive-lightbox' ). '</a><span class="rl-gallery-reload-spinner spinner"></span></h1>
1150
  </div>
1151
  <div class="media-frame-content" data-columns="0">
1152
  <div class="attachments-browser">
1153
  <div class="uploader-inline rl-no-galleries" style="display: none;">
1154
  <div class="uploader-inline-content has-upload-message">
1155
+ <h2 class="upload-message">' . esc_html__( 'No items found.', 'responsive-lightbox' ) . '</h2>
1156
  <div class="upload-ui">
1157
+ <h2 class="upload-instructions">' . esc_html__( 'No galleries? Create them first or try another search phrase.', 'responsive-lightbox' ) . '</h2>
1158
  </div>
1159
  </div>
1160
  </div>
1161
  <div class="media-toolbar">' . ( $rl->options['builder']['categories'] ? '
1162
  <div class="media-toolbar-secondary"><label for="rl-media-attachment-categories" class="screen-reader-text">' . esc_html__( 'Filter by category', 'responsive-lightbox' ) . '</label>' . $categories . '</div>' : '' ) . '
1163
  <div class="media-toolbar-primary search-form">
1164
+ <label for="rl-media-search-input" class="screen-reader-text">' . esc_html__( 'Search galleries', 'responsive-lightbox' ) . '</label><input type="search" placeholder="' . esc_attr__( 'Search galleries', 'responsive-lightbox' ) . '" id="rl-media-search-input" class="search">
1165
  </div>
1166
  </div>
1167
  <ul class="attachments rl-galleries-list ui-sortable ui-sortable-disabled">
1168
  </ul>
1169
  <div class="media-sidebar visible">
1170
+ <h2>' . esc_html__( 'Select A Gallery', 'responsive-lightbox' ) . '</h2>
1171
+ <p>' . esc_html__( 'To select a gallery simply click on one of the boxes to the left.', 'responsive-lightbox' ) . '</p>
1172
+ <p>' . esc_html__( 'To insert your gallery into the editor, click on the "Insert Gallery" button below.', 'responsive-lightbox' ) . '</p>
1173
  </div>
1174
  </div>
1175
  </div>
1178
  <div class="media-toolbar-secondary">
1179
  <div class="media-selection empty">
1180
  <div class="selection-info">
1181
+ <span class="rl-gallery-count count">' . esc_html( sprintf( _n( '%s image', '%s images', 0, 'responsive-lightbox' ), 0 ) ) . '</span>
1182
+ <a href="" class="button-link rl-edit-gallery-link">' . esc_html__( 'Edit gallery', 'responsive-lightbox' ) . '</a>
1183
  </div>
1184
  <div class="selection-view">
1185
  <span class="rl-gallery-images-spinner spinner" style="display: none;"></span>
1189
  </div>
1190
  </div>
1191
  <div class="media-toolbar-primary search-form">
1192
+ <button style="display: none;" type="button" class="button media-button button-primary button-large rl-media-button-insert-gallery" disabled="disabled">' . esc_html__( 'Insert gallery into post', 'responsive-lightbox') . '</button>
1193
+ <button style="display: none;" type="button" class="button media-button button-primary button-large rl-media-button-select-gallery" disabled="disabled">' . esc_html__( 'Select gallery', 'responsive-lightbox') . '</button>
1194
+ <button type="button" class="button media-button button-secondary button-large rl-media-button-cancel-gallery">' . esc_html__( 'Cancel', 'responsive-lightbox') . '</button>
1195
  </div>
1196
  </div>
1197
  </div>
1219
  $html = '';
1220
  $subhtml = '';
1221
  } else {
1222
+ $template = $args['type'] === 'section' ? '<th colspan="2"><h3>%s</h3></th>' : '<th><label for="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '">%s</label></th><td>%s</td>';
1223
+ $html = '<tr class="rl-gallery-field-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . ' rl-gallery-field-' . esc_attr( $args['type'] ) . '" data-field_type="' . esc_attr( $args['type'] ) . '" data-field_name="' . esc_attr( $field ) . '">';
1224
  $subhtml = '';
1225
  }
1226
 
1229
  $html .= sprintf(
1230
  $template,
1231
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1232
+ '<input id="rl_' . esc_attr( $tab_id . '_' . $menu_item . '_' . $field ) . '" type="range" value="' . (int) $args['value'] . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" min="' . ( ! empty( $args['min'] ) ? (int) $args['min'] : 0 ) . '"' . ( ! empty( $args['max'] ) ? ' max="' . (int) $args['max'] . '"' : '' ) . ' step="' . ( ! empty( $args['step'] ) ? (int) $args['step'] : 1 ) . '" oninput="this.form.rl_' . esc_attr( $tab_id ) . '_' . esc_attr( $menu_item ) . '_' . esc_attr( $field ) . '_range.value=this.value" /><output class="rl-gallery-field-output" name="rl_' . esc_attr( $tab_id ) . '_' . esc_attr( $menu_item ) . '_' . esc_attr( $field ) . '_range">' . (int) $args['value'] . '</output>' . ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1233
  );
1234
  break;
1235
 
1237
  $subhtml = '';
1238
 
1239
  foreach ( $args['options'] as $key => $label ) {
1240
+ $subhtml .= '<label class="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" for="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field . '-' . $key ) . '"><input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field . '-' . $key ) . '" type="radio" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" value="' . esc_attr( $key ) . '" ' . checked( $key, $args['value'], false ) . ' />' . esc_html( $label ) . '</label> ';
1241
  }
1242
 
1243
  $html .= sprintf(
1244
  $template,
1245
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1246
+ $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1247
  );
1248
  break;
1249
 
1251
  $html .= sprintf(
1252
  $template,
1253
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1254
+ '<input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" class="small-text" type="number" value="' . esc_attr( $args['value'] ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" min="' . ( ! empty( $args['min'] ) ? (int) $args['min'] : 0 ) . '"' . ( ! empty( $args['max'] ) ? ' max="' . (int) $args['max'] . '"' : '' ) . ' step="' . ( ! empty( $args['step'] ) ? (int) $args['step'] : 1 ) . '" />' . ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1255
  );
1256
  break;
1257
 
1259
  $html .= sprintf(
1260
  $template,
1261
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1262
+ '<input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '"' . ( ! empty( $args['class'] ) ? ' class="' . esc_attr( $args['class'] ) . '"' : '' ) . ' type="text" value="' . esc_attr( $args['value'] ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" />' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1263
  );
1264
  break;
1265
 
1268
  $html .= sprintf(
1269
  $template,
1270
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1271
+ '<textarea id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '"' . ( ! empty( $args['class'] ) ? ' class="' . esc_attr( $args['class'] ) . '"' : '' ) . ' name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']">' . esc_textarea( $args['value'] ) . '</textarea>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1272
  );
1273
  break;
1274
 
1275
  case 'select':
1276
+ $subhtml = '<select id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']">';
1277
 
1278
  foreach ( $args['options'] as $key => $label ) {
1279
  $subhtml .= '
1280
+ <option value="' . esc_attr( $key ) . '" ' . selected( $args['value'], $key, false ) . '>' . esc_html( $label ) . '</option>';
1281
  }
1282
 
1283
  $html .= sprintf(
1284
  $template,
1285
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1286
+ $subhtml . '</select>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1287
  );
1288
  break;
1289
 
1308
  )
1309
  );
1310
  } else
1311
+ $subhtml = '<select id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . '][]" ><option value="0">' . esc_html__( 'Root Folder', 'responsive-lightbox' ) . '</option></select> ';
1312
 
1313
  if ( isset( $args['include_children'] ) && $args['include_children'] ) {
1314
+ $subhtml .= '<label class="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '-include-children" for="rl-' . esc_attr( $tab_id ) . '-' . esc_attr( $menu_item ) . '-' . esc_attr( $field ) . '-include-children"><input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '-include-children" type="checkbox" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . '][children]" value="true" ' . checked( $args['value']['children'], true, false ) . ' />' . esc_html__( 'Include children.', 'responsive-lightbox' ) . '</label>';
1315
  }
1316
 
1317
  $html .= sprintf(
1318
  $template,
1319
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1320
+ $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1321
  );
1322
  break;
1323
 
1324
  case 'multiselect':
1325
+ $subhtml = '<select multiple="multiple" class="select2" id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" data-empty="' . (int) empty( $args['value'] ) . '" data-type="' . esc_attr( $field ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . '][]">';
1326
 
1327
  if ( $field === 'post_term' ) {
1328
  foreach ( $args['options'] as $taxanomy => $data ) {
1329
  $subhtml .= '<optgroup label="' . esc_attr( $data['label'] ) . '">';
1330
 
1331
  foreach ( $data['terms'] as $term_id => $name ) {
1332
+ $subhtml .= '<option value="' . esc_attr( $term_id ) . '" ' . selected( in_array( $term_id, $args['value'], false ), true, false ) . '>' . esc_html( $name ) . '</option>';
1333
  }
1334
 
1335
  $subhtml .= '</optgroup>';
1337
  } else {
1338
  foreach ( $args['options'] as $key => $label ) {
1339
  $subhtml .= '
1340
+ <option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $args['value'], false ), true, false ) . '>' . esc_html( $label ) . '</option>';
1341
  }
1342
  }
1343
 
1344
  $html .= sprintf(
1345
  $template,
1346
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1347
+ $subhtml . '</select>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1348
  );
1349
  break;
1350
 
1352
  $html .= sprintf(
1353
  $template,
1354
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1355
+ '<label class="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" for="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '"><input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" type="checkbox" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" value="true" ' . checked( $args['value'], true, false ) . ' />' . esc_html( $args['label'] ) . '</label>' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1356
  );
1357
  break;
1358
 
1360
  $subhtml = '';
1361
 
1362
  foreach ( $args['options'] as $key => $label ) {
1363
+ $subhtml .= '<label class="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field . '-' . $key ) . '" for="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field . '-' . $key ) . '"><input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field . '-' . $key ) . '" type="checkbox" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . '][' . esc_attr( $key ) . ']" value="true" ' . checked( in_array( $key, $args['value'], true ), true, false ) . ' />' . esc_html( $label ) . '</label><br />';
1364
  }
1365
 
1366
  $html .= sprintf(
1367
  $template,
1368
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1369
+ $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1370
  );
1371
  break;
1372
 
1380
  $html .= sprintf(
1381
  $template,
1382
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1383
+ $subhtml . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1384
  );
1385
  break;
1386
 
1388
  $html .= sprintf(
1389
  $template,
1390
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1391
+ '<input id="rl-' . esc_attr( $tab_id . '-' . $menu_item . '-' . $field ) . '" class="color-picker" type="text" value="' . esc_attr( $args['value'] ) . '" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . ']" data-default-color="' . esc_attr( $args['default'] ) . '" />' . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1392
  );
1393
  break;
1394
 
1402
  $button_label = __( 'Select images', 'responsive-lightbox' );
1403
 
1404
  // get images
1405
+ if ( ( ! empty( $data['menu_item'] ) && $data['menu_item'] === 'media' ) || ! ( wp_doing_ajax() && isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-menu-content' ) )
1406
  $images = $this->get_gallery_images( $gallery_id );
1407
  else
1408
  $images = [];
1411
  $media_item_template = $this->get_media_item_template( $args['preview'] );
1412
 
1413
  // media buttons
1414
+ $buttons = [ '<a href="#" class="rl-gallery-select button button-secondary">' . esc_html( $button_label ) . '</a>' ];
1415
 
1416
  $html .= '
1417
  <td colspan="2" class="rl-colspan">
1418
+ <input type="hidden" class="rl-gallery-ids" name="rl_gallery[' . esc_attr( $tab_id ) . '][' . esc_attr( $menu_item ) . '][' . esc_attr( $field ) . '][ids]" value="' . esc_attr( ! empty( $args['value']['ids'] ) ? implode( ',', $args['value']['ids'] ) : '' ) . '">';
1419
 
1420
  // embed video support?
1421
  if ( rl_current_lightbox_supports( [ 'youtube', 'vimeo' ], 'OR' ) )
1422
+ $buttons[] = '<a href="#" class="rl-gallery-select-videos button button-secondary" style="margin-left: 10px;">' . esc_html__( 'Embed videos', 'responsive-lightbox' ) . '</a>';
1423
 
1424
  // add buttons
1425
  $html .= implode( '', $buttons );
1458
  $html .= '
1459
  <td colspan="2" class="rl-colspan">
1460
  <div class="rl-gallery-preview-inside">
1461
+ <a href="#" class="rl-gallery-update-preview button button-secondary">' . esc_html__( 'Update preview', 'responsive-lightbox' ) . '</a><span class="spinner" style="display: none;"></span>
1462
+ <p class="description">' . esc_html__( 'Use this button after any change of the options below to see updated gallery preview.', 'responsive-lightbox' ) . '</p>
1463
  </div>
1464
  <div class="rl-gallery-content">
1465
+ <ul class="rl-gallery-images rl-gallery-images-' . esc_attr( $menu_item ) . '">';
1466
 
1467
  if ( ! empty( $images ) ) {
1468
  foreach ( $images as $image ) {
1505
  $html .= sprintf(
1506
  $template,
1507
  ! empty( $args['title'] ) ? esc_html( $args['title'] ) : '',
1508
+ apply_filters( 'rl_render_gallery_field_' . $args['type'], $subhtml, $field, $tab_id, $menu_item, $args, $subfield ) . ( ! empty ( $args['description'] ) ? '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' : '' )
1509
  );
1510
  }
1511
 
1522
  * @return string
1523
  */
1524
  public function get_preview_pagination( $current_page = 1 ) {
 
1525
  $page_links = [];
1526
  $total_pages = $current_page + 1;
1527
  $current = $current_page;
1530
 
1531
  if ( $current == 1 ) {
1532
  $disable_first = true;
1533
+ $disable_prev = true;
1534
  } elseif ( $current == 2 )
1535
  $disable_first = true;
1536
 
1548
  $page_links[] = sprintf(
1549
  '<a class="first-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1550
  $current_url,
1551
+ esc_html__( 'First page', 'responsive-lightbox' ),
1552
  '&laquo;'
1553
  );
1554
  }
1559
  $page_links[] = sprintf(
1560
  '<a class="prev-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1561
  $current_url . '/' . max( 1, $current - 1 ),
1562
+ esc_html__( 'Previous page', 'responsive-lightbox' ),
1563
  '&lsaquo;'
1564
  );
1565
  }
1566
 
1567
  $html_current_page = sprintf(
1568
  '%s<input disabled="disabled" class="current-page" id="current-page-selector" type="text" name="paged" value="%s" size="%d" aria-describedby="table-paging" /><span class="tablenav-paging-text">',
1569
+ '<label for="current-page-selector" class="screen-reader-text">' . esc_html__( 'Current Page', 'responsive-lightbox' ) . '</label>',
1570
  $current,
1571
  strlen( $total_pages )
1572
  );
1580
  $page_links[] = sprintf(
1581
  '<a class="next-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1582
  $current_url . '/' . min( $total_pages, $current + 1 ),
1583
+ esc_html__( 'Next page', 'responsive-lightbox' ),
1584
  '&rsaquo;'
1585
  );
1586
  }
1591
  $page_links[] = sprintf(
1592
  '<a class="last-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
1593
  $current_url . '/' . $total_pages,
1594
+ esc_html__( 'Last page', 'responsive-lightbox' ),
1595
  '&raquo;'
1596
  );
1597
  }
1598
 
1599
  if ( $total_pages )
1600
+ $page_class = $total_pages < 2 ? 'one-page' : '';
1601
  else
1602
+ $page_class = 'no-pages';
1603
 
1604
+ return '<div class="rl-gallery-preview-pagination tablenav"><div class="tablenav-pages ' . esc_attr( $page_class ) . '"><span class="pagination-links">' . join( "\n", $page_links ) . '</span></div>';
1605
  }
1606
 
1607
  /**
1702
  $value = trim( $value );
1703
 
1704
  // more than 1 class?
1705
+ if ( strpos( $value, ' ' ) !== false ) {
1706
  // get unique valid HTML classes
1707
  $value = array_unique( array_filter( array_map( 'sanitize_html_class', explode( ' ', $value ) ) ) );
1708
 
1778
 
1779
  continue;
1780
  } else
1781
+ $copy[$embed_id]['url'] = esc_url_raw( $embed_data['url'] );
1782
 
1783
  // check width
1784
  if ( ! array_key_exists( 'width', $embed_data ) )
1796
  if ( empty( $embed_data['thumbnail_url'] ) )
1797
  $copy[$embed_id]['thumbnail_url'] = '';
1798
  else
1799
+ $copy[$embed_id]['thumbnail_url'] = esc_url_raw( $embed_data['thumbnail_url'] );
1800
 
1801
  // check thumbnail width
1802
  if ( ! array_key_exists( 'thumbnail_width', $embed_data ) )
1975
 
1976
  global $wp_meta_boxes;
1977
 
1978
+ // check active tab
1979
+ $active_tab = isset( $_GET['rl_active_tab'] ) ? sanitize_key( $_GET['rl_active_tab'] ) : '';
1980
+ $active_tab = ! empty( $active_tab ) && array_key_exists( $active_tab, $this->tabs ) ? $active_tab : 'images';
1981
 
1982
  echo '
1983
  <h2 class="nav-tab-wrapper">';
1984
 
1985
  foreach ( $this->tabs as $key => $data ) {
1986
  echo '
1987
+ <a id="rl-gallery-tab-' . esc_attr( $key ) . '" class="rl-gallery-tab nav-tab' . ( $key === $active_tab ? ' nav-tab-active' : '' ) . '" href="#' . esc_attr( $key ) . '">' . esc_html( $data['label'] ) . '</a>';
1988
  }
1989
 
1990
  echo '
2028
  * @return string
2029
  */
2030
  function add_active_tab( $location ) {
2031
+ // check active tab
2032
+ $active_tab = isset( $_POST['rl_active_tab'] ) ? sanitize_key( $_POST['rl_active_tab'] ) : '';
2033
+
2034
+ return add_query_arg( 'rl_active_tab', ! empty( $active_tab ) && array_key_exists( $active_tab, $this->tabs ) ? $active_tab : 'images', $location );
2035
  }
2036
 
2037
  /**
2040
  * @return void
2041
  */
2042
  public function add_meta_boxes() {
2043
+ // check active tab
2044
+ $active_tab = isset( $_GET['rl_active_tab'] ) ? sanitize_key( $_GET['rl_active_tab'] ) : '';
2045
+ $active_tab = ! empty( $active_tab ) && array_key_exists( $active_tab, $this->tabs ) ? $active_tab : 'images';
2046
 
2047
  // normal metaboxes
2048
  foreach ( $this->tabs as $key => $args ) {
2057
  else
2058
  add_filter( 'postbox_classes_rl_gallery_responsive-gallery-' . $key, array( $this, 'hide_metabox' ) );
2059
 
2060
+ add_meta_box( 'responsive-gallery-' . $key, sprintf( esc_html__( 'Gallery %s', 'responsive-lightbox' ), $args['label'] ), array( $this, 'add_metabox' ), 'rl_gallery', 'responsive_lightbox_metaboxes', 'high', $new_args );
2061
  }
2062
 
2063
  // side metaboxes
2064
+ add_meta_box( 'responsive-gallery-shortcode', esc_html__( 'Gallery Code', 'responsive-lightbox' ), array( $this, 'shortcode_metabox' ), 'rl_gallery', 'side', 'core' );
2065
  }
2066
 
2067
  /**
2095
  $menu_item = ! empty( $data['menu_item'] ) && in_array( $data['menu_item'], array_keys( $callback_args['args']['menu_items'] ) ) ? $data['menu_item'] : key( $callback_args['args']['menu_items'] );
2096
 
2097
  $html .= '
2098
+ <div class="rl-gallery-tab-menu rl-gallery-tab-menu-' . esc_attr( $callback_args['args']['tab_id'] ) . '">';
2099
 
2100
  foreach ( $callback_args['args']['menu_items'] as $menu_key => $menu_label ) {
2101
  // disable select for remote library if needed
2102
  if ( $menu_key === 'remote_library' && ! $rl->options['remote_library']['active'] ) {
2103
+ $title = ' title="' . esc_attr__( 'Remote Library is disabled. Enable it in the settings.', 'responsive-lightbox' ) . '"';
2104
  $disabled = ' disabled="disabled"';
2105
  // disable select for media folders if needed
2106
  } elseif ( $menu_key === 'folders' && ! $rl->options['folders']['active'] ) {
2107
+ $title = ' title="' . esc_attr__( 'Media Folders are disabled. Enable it in the settings.', 'responsive-lightbox' ) . '"';
2108
  $disabled = ' disabled="disabled"';
2109
  // other menu items
2110
  } else {
2113
  }
2114
 
2115
  $html .= '
2116
+ <label' . $title . '><input type="radio" class="rl-gallery-tab-menu-item" name="rl_gallery[' . esc_attr( $callback_args['args']['tab_id'] ) . '][menu_item]" value="' . esc_attr( $menu_key ) . '" ' . checked( $menu_item, $menu_key, false ) . $disabled . ' />' . esc_html( $menu_label ) . ( $callback_args['args']['tab_id'] === 'config' && $menu_key === 'default' ? ' (' . esc_html( $this->tabs['config']['menu_items'][$rl->options['settings']['builder_gallery']] ) . ')' : '' ) . '</label>';
2117
  }
2118
 
2119
  $html .= '
2125
 
2126
  // disable gallery images content for remote library or media folders if needed
2127
  if ( $callback_args['args']['tab_id'] === 'images' && ( ( $menu_item === 'remote_library' && ! $rl->options['remote_library']['active'] ) || ( $menu_item === 'folders' && ! $rl->options['folders']['active'] ) ) )
2128
+ $content = 'rl-loading-content';
2129
 
2130
  $html .= '
2131
+ <div class="rl-gallery-tab-content rl-gallery-tab-content-' . esc_attr( $callback_args['args']['tab_id'] ) . ' ' . esc_attr( $content ) . '">';
2132
 
2133
  $html .= ! empty( $callback_args['args']['callback'] ) && is_callable( $callback_args['args']['callback'] ) ? call_user_func( $callback_args['args']['callback'], $callback_args['args']['tab_id'], $data, $menu_item, $post->ID ) : $this->get_metabox_content( $callback_args['args']['tab_id'], $data, $menu_item, $post->ID );
2134
 
2149
  */
2150
  public function get_metabox_content( $tab_id, $data, $menu_item, $gallery_id = 0 ) {
2151
  $html = '
2152
+ <div class="rl-gallery-tab-inside rl-gallery-tab-inside-' . esc_attr( $tab_id ) . '-' . esc_attr( $menu_item ) . '">
2153
  <table class="form-table">';
2154
 
2155
  switch ( $tab_id ) {
2206
  }
2207
  // just in case ajax would fail
2208
  } else
2209
+ $html .= '<p>' . esc_html__( 'No data', 'responsive-lightbox' ) . '</p>';
2210
  break;
2211
 
2212
  default:
2340
  global $pagenow;
2341
 
2342
  // is it preview?
2343
+ if ( ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) && $gallery_id ) || ( isset( $_POST['action'] ) && $_POST['action'] === 'rl-get-preview-content' ) || ( wp_doing_ajax() && isset( $_POST['action'] ) && ( $_POST['action'] === 'rl-post-gallery-preview' || $_POST['action'] === 'rl-get-menu-content' ) ) )
2344
  $args['images_per_page'] = 0;
2345
 
2346
  if ( isset( $_GET['rl_page'] ) )
2835
  $current_action = current_action();
2836
 
2837
  if ( $current_action === 'rl_before_gallery' )
2838
+ $class = 'rl-pagination-top';
2839
  elseif ( $current_action === 'rl_after_gallery' )
2840
+ $class = 'rl-pagination-bottom';
2841
  else
2842
  $class = '';
2843
 
2852
  $base_args['rl_lightbox_script'] = $rl->get_lightbox_script();
2853
 
2854
  echo
2855
+ '<div class="rl-pagination ' . esc_attr( $class ) . '"' . ( $args['pagination_type'] === 'infinite' ? ' data-button="' . esc_attr( $args['load_more'] ) . '"' : '' ) .'>' .
2856
  paginate_links(
2857
  [
2858
  'format' => '?rl_page=%#%',
2863
  'end_size' => 1,
2864
  'mid_size' => 2,
2865
  'prev_next' => true,
2866
+ 'prev_text' => esc_html__( '&laquo; Previous', 'responsive-lightbox' ),
2867
+ 'next_text' => esc_html__( 'Next &raquo;', 'responsive-lightbox' ),
2868
  'type' => 'plain',
2869
  'add_args' => '',
2870
  'add_fragment' => '',
2890
  * @return void
2891
  */
2892
  public function maybe_change_lightbox() {
2893
+ // check whether is it valid gallery ajax request
2894
  if ( $this->gallery_ajax_verified() ) {
2895
  // set new lightbox script
2896
+ Responsive_Lightbox()->set_lightbox_script( sanitize_key( $_POST['lightbox'] ) );
2897
  }
2898
  }
2899
 
2904
  * @return void
2905
  */
2906
  public function get_gallery_page( $args ) {
2907
+ // check whether is it valid gallery ajax request
2908
  if ( $this->gallery_ajax_verified() ) {
2909
  // cast page number
2910
  $_GET['rl_page'] = (int) $_POST['page'];
2935
  wp_send_json_error();
2936
 
2937
  // check page
2938
+ $page = preg_replace( '/[^a-z.]/i', '', $_POST['page'] );
2939
+
2940
+ // check page
2941
+ if ( ! in_array( $page, [ 'widgets.php', 'customize.php', 'post.php', 'post-new.php' ], true ) )
2942
  wp_send_json_error();
2943
 
2944
  // check edit_post capability
2945
+ if ( ( $page === 'post.php' || $page === 'post-new.php' ) && ! current_user_can( 'edit_post', (int) $_POST['post_id'] ) )
2946
  wp_send_json_error();
2947
 
2948
  // check edit_theme_options capability
2949
+ if ( ( $page === 'widgets.php' || $page === 'customize.php' ) && ! current_user_can( 'edit_theme_options' ) )
2950
  wp_send_json_error();
2951
 
2952
  // parse gallery id
2974
  if ( ! empty( $images ) ) {
2975
  foreach ( $images as $image ) {
2976
  $html .= '
2977
+ <li tabindex="0" role="checkbox" aria-label="' . esc_attr( $image['title'] ) . '" aria-checked="true" data-id="' . esc_attr( $image['id'] ) . '" class="attachment selection selected rl-status-active">
2978
  <div class="attachment-preview js--select-attachment type-image ' . esc_attr( $image['thumbnail_orientation'] ). '">
2979
  <div class="thumbnail">
2980
  <div class="centered">
2981
+ <img src="' . esc_url( $image['thumbnail_url'] ) . '" draggable="false" alt="" />
2982
  </div>
2983
  </div>
2984
  </div>
2990
  wp_send_json_success(
2991
  array(
2992
  'attachments' => $html,
2993
+ 'count' => esc_html( sprintf( _n( '%s image', '%s images', $images_count, 'responsive-lightbox' ), $images_count ) ),
2994
+ 'edit_url' => current_user_can( 'edit_post', $gallery_id ) ? esc_url_raw( admin_url( 'post.php?post=' . $gallery_id . '&action=edit' ) ) : ''
2995
  )
2996
  );
2997
  }
3007
  wp_send_json_error();
3008
 
3009
  // check page
3010
+ $page = preg_replace( '/[^a-z.]/i', '', $_POST['page'] );
3011
+
3012
+ // check page
3013
+ if ( ! in_array( $page, [ 'widgets.php', 'customize.php', 'post.php', 'post-new.php' ], true ) )
3014
  wp_send_json_error();
3015
 
3016
  // check edit_post capability
3017
+ if ( ( $page === 'post.php' || $page === 'post-new.php' ) && ! current_user_can( 'edit_post', (int) $_POST['post_id'] ) )
3018
  wp_send_json_error();
3019
 
3020
  // check edit_theme_options capability
3021
+ if ( ( $page === 'widgets.php' || $page === 'customize.php' ) && ! current_user_can( 'edit_theme_options' ) )
3022
  wp_send_json_error();
3023
 
3024
  $args = array(
3033
  'cache_results' => false
3034
  );
3035
 
3036
+ // check category
3037
+ $category = isset( $_POST['category'] ) ? (int) $_POST['category'] : 0;
3038
+
3039
  // specific category?
3040
+ if ( ! empty( $category ) ) {
3041
  $args['tax_query'] = array(
3042
  array(
3043
  'taxonomy' => 'rl_category',
3044
  'field' => 'term_id',
3045
  'operator' => 'IN',
3046
  'include_children' => false,
3047
+ 'terms' => $category
3048
  )
3049
  );
3050
  }
3064
  if ( ! empty( $query->posts ) ) {
3065
  foreach ( $query->posts as $gallery ) {
3066
  // save gallery id
3067
+ $ids[] = (int) $gallery->ID;
3068
 
3069
  // get featured image
3070
  $featured = $this->get_featured_image_src( $gallery->ID );
3075
  $featured_image = '';
3076
 
3077
  // get title
3078
+ $title = $gallery->post_title !== '' ? $gallery->post_title : esc_html__( '(no title)', 'responsive-gallery' );
3079
 
3080
  $html .= '
3081
+ <li tabindex="0" role="checkbox" aria-label="' . esc_attr( $title ) . '" aria-checked="true" data-id="' . (int) $gallery->ID . '" class="attachment selection">
3082
  <div class="attachment-preview js--select-attachment type-image ' . ( ! empty( $featured['thumbnail_orientation'] ) ? esc_attr( $featured['thumbnail_orientation'] ) : 'landscape' ) . '">
3083
  <div class="thumbnail">
3084
+ <div class="centered" data-full-src="' . esc_url( $featured_image ) . '">
3085
  ' . $this->get_featured_image( $gallery->ID, 'thumbnail' ) . '
3086
  </div>
3087
  <div class="filename">
3089
  </div>
3090
  </div>
3091
  </div>
3092
+ <button type="button" class="button-link check"><span class="media-modal-icon"></span><span class="screen-reader-text">' . esc_html__( 'Deselect', 'responsive-lightbox' ) . '</span></button>
3093
  </li>';
3094
  }
3095
  }
3109
  * @return void
3110
  */
3111
  public function get_menu_content() {
3112
+ if ( ! isset( $_POST['post_id'], $_POST['tab'], $_POST['menu_item'], $_POST['nonce'] ) || ! check_ajax_referer( 'rl-gallery', 'nonce', false ) )
3113
+ wp_send_json_error();
3114
+
3115
+ // check tab
3116
+ $tab = isset( $_POST['tab'] ) ? sanitize_key( $_POST['tab'] ) : '';
3117
+
3118
+ if ( ! array_key_exists( $tab, $this->tabs ) )
3119
  wp_send_json_error();
3120
 
3121
+ // get post id
3122
+ $post_id = (int) $_POST['post_id'];
3123
+
3124
+ if ( ! current_user_can( 'edit_post', $post_id ) )
3125
+ wp_send_json_error();
3126
+
3127
+ // check menu item
3128
+ $menu_item = sanitize_key( $_POST['menu_item'] );
3129
+
3130
  // get selected menu item
3131
+ $menu_item = ! empty( $menu_item ) && in_array( $menu_item, array_keys( $this->tabs[$tab]['menu_items'] ) ) ? $menu_item : key( $this->tabs[$tab]['menu_items'] );
3132
 
3133
  // get tab content
3134
+ wp_send_json_success( $this->get_metabox_content( $tab, get_post_meta( $post_id, '_rl_' . $tab, true ), $menu_item, $post_id ) );
3135
  }
3136
 
3137
  /**
3169
  }
3170
 
3171
  // check preview type
3172
+ $preview_type = sanitize_key( $_POST['preview_type'] );
3173
+
3174
+ // check preview type
3175
+ if ( ! in_array( $preview_type, [ 'page', 'update' ], true ) )
3176
  $args['preview_type'] = 'page';
3177
  else
3178
+ $args['preview_type'] = $preview_type;
3179
 
3180
+ // check menu item
3181
+ $menu_item = sanitize_key( $_POST['menu_item'] );
3182
 
3183
  // set images menu item
3184
  $menu_item = $this->menu_item = ! empty( $menu_item ) && array_key_exists( $menu_item, $this->tabs['images']['menu_items'] ) ? $menu_item : 'media';
3242
  }
3243
 
3244
  // parse excluded images
3245
+ $excluded = ! empty( $_POST['excluded'] ) && is_array( $_POST['excluded'] ) ? array_map( 'intval', $_POST['excluded'] ) : [];
3246
 
3247
  // get excluded images
3248
+ if ( ! empty( $excluded ) )
3249
+ $excluded = array_unique( array_filter( $excluded ) );
3250
 
3251
  // get media item template
3252
  $media_item_template = $this->get_media_item_template( $this->fields['images'][$menu_item]['attachments']['preview'] );
3306
  '__EMBED_DATE__'
3307
  ],
3308
  [
3309
+ esc_attr( $image['id'] ),
3310
  esc_url( $image['url'] ),
3311
  (int) $image['width'],
3312
  (int) $image['height'],
3315
  (int) $image['thumbnail_height'],
3316
  esc_attr( $image['title'] ),
3317
  esc_textarea( $image['caption'] ),
3318
+ esc_attr( $image['date'] )
3319
  ],
3320
  $this->get_media_embed_template( false )
3321
  );
3332
  ],
3333
  [
3334
  $this->get_media_exclude_input_template( $tab_id, $menu_item, $field_name, $excluded_flag ? $excluded_item : '' ) . $media_html . $image['thumbnail_link'],
3335
+ esc_attr( $image['id'] ),
3336
  $excluded_flag ? ' rl-status-inactive' : ' rl-status-active',
3337
+ esc_attr( $image['type'] )
3338
  ],
3339
  $template
3340
  );
3380
  // apply filters if any
3381
  $attr = apply_filters( 'rl_get_gallery_image_attributes', $attr, $image, $size );
3382
 
 
 
 
3383
  // start link output
3384
  $link = rtrim( '<img ' . image_hwstring( $width, $height ) );
3385
 
3386
  // add attributes
3387
  foreach ( $attr as $name => $value ) {
3388
+ $link .= ' ' . esc_attr( $name ) . '="' . ( $name === 'src' ? esc_url( $value ) : esc_attr( $value ) ) . '"';
3389
  }
3390
 
3391
  // end link output
3530
 
3531
  $imagedata = array(
3532
  'id' => ! empty( $image['id'] ) ? ( preg_match( '/^e\d+$/', $image['id'] ) === 1 ? $image['id'] : (int) $image['id'] ) : 0,
3533
+ 'title' => ! empty( $image['title'] ) ? ( $image['title'] ) : '',
3534
+ 'date' => ! empty( $image['date'] ) ? ( $image['date'] ) : '',
3535
+ 'caption' => ! empty( $image['caption'] ) ? ( $image['caption'] ) : '',
3536
+ 'alt' => ! empty( $image['alt'] ) ? ( $image['alt'] ) : '',
3537
+ 'url' => ! empty( $image['url'] ) ? esc_url_raw( $image['url'] ) : '',
3538
  'width' => ! empty( $image['width'] ) ? (int) $image['width'] : 0,
3539
  'height' => ! empty( $image['height'] ) ? (int) $image['height'] : 0,
3540
+ 'thumbnail_url' => ! empty( $image['thumbnail_url'] ) ? esc_url_raw( $image['thumbnail_url'] ) : '',
3541
  'thumbnail_width' => ! empty( $image['thumbnail_width'] ) ? (int) $image['thumbnail_width'] : 0,
3542
  'thumbnail_height' => ! empty( $image['thumbnail_height'] ) ? (int) $image['thumbnail_height'] : 0,
3543
+ 'link' => ! empty( $image['link'] ) ? esc_url_raw( $image['link'] ) : '',
3544
+ 'thumbnail_link' => ! empty( $image['thumbnail_link'] ) ? esc_url_raw( $image['thumbnail_link'] ) : '',
3545
+ 'type' => ! empty( $image['type'] ) ? ( $image['type'] ) : 'image'
3546
  );
3547
 
3548
  $imagedata['orientation'] = $imagedata['height'] > $imagedata['width'] ? 'portrait' : 'landscape';
3949
  public function init_admin() {
3950
  global $pagenow;
3951
 
3952
+ // check values
3953
+ $post = isset( $_GET['post'] ) ? (int) $_GET['post'] : 0;
3954
+ $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
3955
+ $action = isset( $_POST['action'] ) ? sanitize_key( $_POST['action'] ) : '';
3956
+ $post_type = isset( $_POST['post_type'] ) ? sanitize_key( $_POST['post_type'] ) : '';
3957
+
3958
  // prepare query arguments if needed
3959
+ if ( ( $pagenow === 'post.php' && ( ( $post && get_post_type( $post ) === 'rl_gallery' ) || ( $post_id && get_post_type( $post_id ) === 'rl_gallery' ) ) ) || ( in_array( $pagenow, array( 'edit.php', 'post-new.php'), true ) && $post_type === 'rl_gallery' ) || ( $pagenow === 'admin-ajax.php' && $action && in_array( $action, array( 'rl-get-preview-content', 'rl-post-gallery-preview', 'rl-get-menu-content' ), true ) ) )
3960
  $this->fields['images']['featured'] = $this->prepare_featured_fields( $this->fields['images']['featured'] );
3961
 
3962
  // add default thumbnail image if needed
3963
+ if ( Responsive_Lightbox()->options['builder']['gallery_builder'] && $pagenow === 'edit.php' && $post_type && $post_type === 'rl_gallery' )
3964
  $this->maybe_generate_thumbnail();
3965
  }
3966
 
4526
  * @return void
4527
  */
4528
  public function save_post( $post_id, $post, $update ) {
4529
+ // check action
4530
+ $action = isset( $_GET['action'] ) ? sanitize_key( $_GET['action'] ) : '';
4531
+
4532
+ if ( wp_is_post_revision( $post_id ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! $update || in_array( $post->post_status, array( 'trash', 'auto-draft' ), true ) || ( $action === 'untrash' ) || empty( $_POST['rl_gallery'] ) )
4533
  return;
4534
 
4535
  // save gallery
4617
  // custom url
4618
  case 'url':
4619
  $thumbnail_id = $this->maybe_generate_thumbnail();
4620
+ $featured_image = isset( $post_data['_rl_thumbnail_url'] ) ? esc_url_raw( $post_data['_rl_thumbnail_url'] ) : '';
4621
  break;
4622
 
4623
  // first image
4653
 
4654
  $postdata = [
4655
  'ID' => $post_id,
4656
+ 'post_excerpt' => sanitize_textarea_field( $safedata['misc']['options']['gallery_description'] )
4657
  ];
4658
 
4659
  wp_update_post( $postdata );
4721
  */
4722
  public function shortcode_metabox( $post ) {
4723
  echo '
4724
+ <p>' . esc_html__( 'You can place this gallery anywhere into your posts, pages, custom post types or widgets by using the shortcode below', 'responsive-lightbox' ) . ':</p>
4725
+ <code class="rl-shortcode" data-number="0">[rl_gallery id=&quot;' . (int) $post->ID . '&quot;]</code>
4726
+ <p>' . esc_html__( 'You can also place this gallery into your template files by using the template tag below', 'responsive-lightbox' ) . ':</p>
4727
+ <code class="rl-shortcode" data-number="1">if ( function_exists( \'rl_gallery\' ) ) { rl_gallery( \'' . (int) $post->ID . '\' ); }</code>';
4728
  }
4729
 
4730
  /**
4741
  $columns = array_merge(
4742
  array_slice( $columns, 0, $offset ),
4743
  array(
4744
+ 'image' => esc_html__( 'Gallery', 'responsive-lightbox' )
4745
  ),
4746
  array_slice( $columns, $offset )
4747
  );
4750
  $columns = array_merge(
4751
  array_slice( $columns, 0, $offset + 2 ),
4752
  array(
4753
+ 'shortcode' => esc_html__( 'Shortcode', 'responsive-lightbox' ),
4754
+ 'type' => esc_html__( 'Type', 'responsive-lightbox' ),
4755
+ 'source' => esc_html__( 'Source', 'responsive-lightbox' )
4756
  ),
4757
  array_slice( $columns, $offset + 2 )
4758
  );
4781
 
4782
  // display count
4783
  if ( ! empty( $image ) )
4784
+ echo '<span class="media-icon image-icon">' . $image . '</span><span>' . esc_html( sprintf( _n( '%s element', '%s elements', $images_count, 'responsive-lightbox' ), $images_count ) ) . '</span>';
4785
  else
4786
  echo '<span class="media-icon image-icon">' . wp_get_attachment_image( 0, array( 60, 60 ), true, array( 'alt' => '' ) ) . '</span>';
4787
  break;
4788
 
4789
  case 'shortcode':
4790
+ echo '<code>[rl_gallery id="' . (int) $post_id . '"]</code>';
4791
  break;
4792
 
4793
  case 'type':
4794
  $config = get_post_meta( $post_id, '_rl_config', true );
4795
 
4796
  if ( ! empty( $config['menu_item'] ) && array_key_exists( $config['menu_item'], $this->tabs['config']['menu_items'] ) ) {
4797
+ echo esc_html( $this->tabs['config']['menu_items'][$config['menu_item']] );
4798
 
4799
  if ( $config['menu_item'] === 'default' )
4800
+ echo esc_html( ' (' . $this->tabs['config']['menu_items'][Responsive_Lightbox()->options['settings']['builder_gallery']] . ')' );
4801
  } else
4802
  echo '-';
4803
  break;
4806
  $images = get_post_meta( $post_id, '_rl_images', true );
4807
 
4808
  if ( ! empty( $images['menu_item'] ) && array_key_exists( $images['menu_item'], $this->tabs['images']['menu_items'] ) )
4809
+ echo esc_html( $this->tabs['images']['menu_items'][$images['menu_item']] );
4810
  else
4811
  echo '-';
4812
  break;
4827
  $sizes = [];
4828
 
4829
  foreach ( get_intermediate_image_sizes() as $_size ) {
4830
+ if ( in_array( $_size, [ 'thumbnail', 'medium', 'medium_large', 'large' ] ) ) {
4831
  $sizes[$_size]['width'] = get_option( "{$_size}_size_w" );
4832
  $sizes[$_size]['height'] = get_option( "{$_size}_size_h" );
4833
  $sizes[$_size]['crop'] = (bool) get_option( "{$_size}_crop" );
4834
  } elseif ( isset( $_wp_additional_image_sizes[$_size] ) ) {
4835
+ $sizes[$_size] = [
4836
  'width' => $_wp_additional_image_sizes[$_size]['width'],
4837
  'height' => $_wp_additional_image_sizes[$_size]['height'],
4838
  'crop' => $_wp_additional_image_sizes[$_size]['crop'],
4839
+ ];
4840
  }
4841
  }
4842
 
4871
  $type = ! empty( $type ) && in_array( $type, array( 'image', 'id', 'url' ) ) ? $type : 'image';
4872
 
4873
  // force media library image
4874
+ if ( wp_doing_ajax() )
4875
  $type = 'id';
4876
  // post featured image is post thumbnail replacement?
4877
  elseif ( $this->maybe_generate_thumbnail() === (int) $thumbnail_id ) {
includes/class-multilang.php CHANGED
@@ -10,8 +10,9 @@ new Responsive_Lightbox_Multilang();
10
  * @class Responsive_Lightbox_Multilang
11
  */
12
  class Responsive_Lightbox_Multilang {
 
13
  public $multilang = false;
14
- public $languages = array();
15
  public $default_lang = '';
16
  public $current_lang = '';
17
  public $active_plugin = '';
@@ -47,7 +48,7 @@ class Responsive_Lightbox_Multilang {
47
  $this->default_lang = pll_default_language();
48
 
49
  // filters
50
- add_filter( 'rl_count_attachments', array( $this, 'count_attachments' ), 9 );
51
  // WPML support
52
  } elseif ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'SitePress' ) ) {
53
  $this->multilang = true;
@@ -66,22 +67,23 @@ class Responsive_Lightbox_Multilang {
66
  // get default language
67
  $this->default_lang = $sitepress->get_default_language();
68
 
69
- // actions
70
- add_action( 'admin_init', array( $this, 'hide_thumbnail' ) );
 
71
  }
72
 
73
  // multilang?
74
  if ( $this->multilang ) {
75
  // ations
76
- add_action( 'admin_init', array( $this, 'media_url_redirect' ) );
77
 
78
  // filters
79
- add_filter( 'setup_theme', array( $this, 'get_current_admin_language' ), 11 );
80
- add_filter( 'rl_root_folder_query_args', array( $this, 'root_folder_query_args' ) );
81
- add_filter( 'rl_gallery_query_args', array( $this, 'gallery_featured_query_args' ) );
82
- add_filter( 'rl_folders_query_args', array( $this, 'gallery_folders_query_args' ) );
83
- add_filter( 'rl_get_gallery_images_attachments', array( $this, 'update_gallery_images_attachments' ) );
84
- add_filter( 'rl_folders_media_folder_url', array( $this, 'media_folder_url' ) );
85
  }
86
  }
87
 
@@ -116,7 +118,7 @@ class Responsive_Lightbox_Multilang {
116
  * @return array
117
  */
118
  public function update_gallery_images_attachments( $attachments ) {
119
- $new_attachments = array();
120
 
121
  foreach ( $attachments as $attachment_id ) {
122
  if ( $this->active_plugin === 'polylang' )
@@ -153,7 +155,7 @@ class Responsive_Lightbox_Multilang {
153
  // active language?
154
  if ( $this->current_lang !== '' ) {
155
  // remove internal WP counter to avoid unwanted query
156
- remove_filter( 'rl_count_attachments', array( Responsive_Lightbox()->folders, 'count_attachments' ), 10 );
157
  // if not let internal WP counter do the job
158
  } else
159
  return $number;
@@ -162,14 +164,14 @@ class Responsive_Lightbox_Multilang {
162
  $taxonomies = PLL()->model->get_filtered_taxonomies_query_vars();
163
 
164
  // prepare defaults
165
- $defaults = array(
166
  'author' => '',
167
  'author_name' => '',
168
  'monthnum' => '',
169
  'day' => '',
170
  'year' => '',
171
  'm' => ''
172
- );
173
 
174
  // add additional taxonomies
175
  foreach ( $taxonomies as $tax ) {
10
  * @class Responsive_Lightbox_Multilang
11
  */
12
  class Responsive_Lightbox_Multilang {
13
+
14
  public $multilang = false;
15
+ public $languages = [];
16
  public $default_lang = '';
17
  public $current_lang = '';
18
  public $active_plugin = '';
48
  $this->default_lang = pll_default_language();
49
 
50
  // filters
51
+ add_filter( 'rl_count_attachments', [ $this, 'count_attachments' ], 9 );
52
  // WPML support
53
  } elseif ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'SitePress' ) ) {
54
  $this->multilang = true;
67
  // get default language
68
  $this->default_lang = $sitepress->get_default_language();
69
 
70
+ // if galleries enabled
71
+ if ( Responsive_Lightbox()->options['builder']['gallery_builder'] )
72
+ add_action( 'admin_init', [ $this, 'hide_thumbnail' ] );
73
  }
74
 
75
  // multilang?
76
  if ( $this->multilang ) {
77
  // ations
78
+ add_action( 'admin_init', [ $this, 'media_url_redirect' ] );
79
 
80
  // filters
81
+ add_filter( 'setup_theme', [ $this, 'get_current_admin_language' ], 11 );
82
+ add_filter( 'rl_root_folder_query_args', [ $this, 'root_folder_query_args' ] );
83
+ add_filter( 'rl_gallery_query_args', [ $this, 'gallery_featured_query_args' ] );
84
+ add_filter( 'rl_folders_query_args', [ $this, 'gallery_folders_query_args' ] );
85
+ add_filter( 'rl_get_gallery_images_attachments', [ $this, 'update_gallery_images_attachments' ] );
86
+ add_filter( 'rl_folders_media_folder_url', [ $this, 'media_folder_url' ] );
87
  }
88
  }
89
 
118
  * @return array
119
  */
120
  public function update_gallery_images_attachments( $attachments ) {
121
+ $new_attachments = [];
122
 
123
  foreach ( $attachments as $attachment_id ) {
124
  if ( $this->active_plugin === 'polylang' )
155
  // active language?
156
  if ( $this->current_lang !== '' ) {
157
  // remove internal WP counter to avoid unwanted query
158
+ remove_filter( 'rl_count_attachments', [ Responsive_Lightbox()->folders, 'count_attachments' ], 10 );
159
  // if not let internal WP counter do the job
160
  } else
161
  return $number;
164
  $taxonomies = PLL()->model->get_filtered_taxonomies_query_vars();
165
 
166
  // prepare defaults
167
+ $defaults = [
168
  'author' => '',
169
  'author_name' => '',
170
  'monthnum' => '',
171
  'day' => '',
172
  'year' => '',
173
  'm' => ''
174
+ ];
175
 
176
  // add additional taxonomies
177
  foreach ( $taxonomies as $tax ) {
includes/class-remote-library-api.php CHANGED
@@ -43,14 +43,14 @@ abstract class Responsive_Lightbox_Remote_Library_API {
43
  $this->rl = Responsive_Lightbox();
44
 
45
  // add provider
46
- $this->rl->providers[$provider->slug] = array(
47
  'instance' => $provider,
48
  'slug' => ! empty( $provider->slug ) ? sanitize_title( $provider->slug ) : '',
49
  'name' => ! empty( $provider->name ) ? esc_html( $provider->name ) : '',
50
  'defaults' => ! empty( $provider->defaults ) && is_array( $provider->defaults ) ? $provider->defaults : [],
51
  'fields' => ! empty( $provider->fields ) && is_array( $provider->fields ) ? $provider->fields : [],
52
  'response_args' => ! empty( $provider->response_data_args ) && is_array( $provider->response_data_args ) ? $provider->response_data_args : []
53
- );
54
 
55
  // add provider default values
56
  $this->rl->defaults['remote_library'][$provider->slug] = $this->rl->providers[$provider->slug]['defaults'];
@@ -59,10 +59,10 @@ abstract class Responsive_Lightbox_Remote_Library_API {
59
  $this->rl->settings->settings['remote_library']['fields'][$provider->slug] = $this->rl->providers[$provider->slug]['fields'];
60
 
61
  // validate provider settings
62
- add_filter( 'rl_remote_library_settings', array( $this, 'validate_settings' ) );
63
 
64
  // provider query
65
- add_filter( 'rl_remote_library_query', array( $this, 'get_images' ), 10, 4 );
66
  }
67
 
68
  /**
@@ -170,7 +170,7 @@ abstract class Responsive_Lightbox_Remote_Library_API {
170
  * @return array
171
  */
172
  public function sanitize_results( $results ) {
173
- return is_array( $results ) ? array_filter( array_map( array( $this, 'sanitize_result' ), $results ) ) : [];
174
  }
175
 
176
  /**
43
  $this->rl = Responsive_Lightbox();
44
 
45
  // add provider
46
+ $this->rl->providers[$provider->slug] = [
47
  'instance' => $provider,
48
  'slug' => ! empty( $provider->slug ) ? sanitize_title( $provider->slug ) : '',
49
  'name' => ! empty( $provider->name ) ? esc_html( $provider->name ) : '',
50
  'defaults' => ! empty( $provider->defaults ) && is_array( $provider->defaults ) ? $provider->defaults : [],
51
  'fields' => ! empty( $provider->fields ) && is_array( $provider->fields ) ? $provider->fields : [],
52
  'response_args' => ! empty( $provider->response_data_args ) && is_array( $provider->response_data_args ) ? $provider->response_data_args : []
53
+ ];
54
 
55
  // add provider default values
56
  $this->rl->defaults['remote_library'][$provider->slug] = $this->rl->providers[$provider->slug]['defaults'];
59
  $this->rl->settings->settings['remote_library']['fields'][$provider->slug] = $this->rl->providers[$provider->slug]['fields'];
60
 
61
  // validate provider settings
62
+ add_filter( 'rl_remote_library_settings', [ $this, 'validate_settings' ] );
63
 
64
  // provider query
65
+ add_filter( 'rl_remote_library_query', [ $this, 'get_images' ], 10, 4 );
66
  }
67
 
68
  /**
170
  * @return array
171
  */
172
  public function sanitize_results( $results ) {
173
+ return is_array( $results ) ? array_filter( array_map( [ $this, 'sanitize_result' ], $results ) ) : [];
174
  }
175
 
176
  /**
includes/class-remote-library.php CHANGED
@@ -23,12 +23,12 @@ class Responsive_Lightbox_Remote_Library {
23
  return;
24
 
25
  // actions
26
- add_action( 'wp_ajax_rl_remote_library_query', array( $this, 'ajax_query_media' ) );
27
- add_action( 'wp_ajax_rl_upload_image', array( $this, 'ajax_upload_image' ) );
28
- add_action( 'admin_enqueue_scripts', array( $this, 'remote_library_scripts' ) );
29
 
30
  // add filter to send new data to editor
31
- add_filter( 'image_send_to_editor', array( $this, 'send_image_to_editor' ), 21, 8 );
32
  }
33
 
34
  /**
@@ -82,15 +82,15 @@ class Responsive_Lightbox_Remote_Library {
82
  * @return string
83
  */
84
  function send_image_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
85
- if ( $id === Responsive_Lightbox()->galleries->maybe_generate_thumbnail() && isset( $_POST['attachment'] ) ) {
86
  $attachment = wp_unslash( $_POST['attachment'] );
87
 
88
  if ( isset( $attachment['remote_library_image'], $attachment['width'], $attachment['height'] ) ) {
89
- $html = preg_replace( '/src=(\'|")(.*?)(\'|")/', 'src="' . ( ! empty( $attachment['rl_url'] ) ? $attachment['rl_url'] : $url ) . '"', $html );
90
- $html = preg_replace( '/width=(\'|")(.*?)(\'|")/', 'width="' . ( (int) $attachment['width'] ) . '"', $html );
91
- $html = preg_replace( '/height=(\'|")(.*?)(\'|")/', 'height="' . ( (int) $attachment['height'] ) . '"', $html );
92
- $html = preg_replace( '/(\s)?id="attachment_' . $id . '"/', '', $html );
93
- $html = preg_replace( '/(\s)?wp-image-' . $id . '/', '', $html );
94
  }
95
  }
96
 
@@ -155,12 +155,12 @@ class Responsive_Lightbox_Remote_Library {
155
  // get main instance
156
  $rl = Responsive_Lightbox();
157
 
158
- wp_enqueue_script( 'rl-remote-library-media', RESPONSIVE_LIGHTBOX_URL . '/js/admin-media.js', array( 'jquery', 'media-models', 'underscore' ), $rl->defaults['version'] );
159
 
160
  wp_localize_script(
161
  'rl-remote-library-media',
162
  'rlRemoteLibraryMedia',
163
- array(
164
  'thumbnailID' => $rl->galleries->maybe_generate_thumbnail(),
165
  'postID' => get_the_ID(),
166
  'providers' => $this->get_providers(),
@@ -170,7 +170,7 @@ class Responsive_Lightbox_Remote_Library {
170
  'uploadAndSelect' => __( 'Upload and Select', 'responsive-lightbox' ),
171
  'filterByremoteLibrary' => __( 'Filter by remote library', 'responsive-lightbox' ),
172
  'getUploadNonce' => wp_create_nonce( 'rl-remote-library-upload-image' )
173
- )
174
  );
175
 
176
  // enqueue gallery
@@ -184,69 +184,73 @@ class Responsive_Lightbox_Remote_Library {
184
  */
185
  public function ajax_query_media() {
186
  $data = stripslashes_deep( $_POST );
187
- $results = array(
188
  'last' => false,
189
  'images' => [],
190
  'data' => []
191
- );
192
 
193
- if ( isset( $data['media_provider'], $data['media_search'], $data['media_page'] ) && ( $data['media_provider'] === 'all' || $this->is_active_provider( $data['media_provider'] ) ) ) {
194
- $data['preview_page'] = (int) $data['media_page'];
195
- $data['preview_per_page'] = 20;
196
 
197
- // get images
198
- $results['images'] = $this->get_remote_library_images( $data );
 
199
 
200
- // get main instance
201
- $rl = Responsive_Lightbox();
202
 
203
- // single provider?
204
- if ( $data['media_provider'] !== 'all' ) {
205
- // get provider
206
- $provider = $rl->providers[$data['media_provider']];
207
-
208
- // add response data arguments if needed
209
- if ( ! empty( $provider['response_args'] ) ) {
210
- $response = $provider['instance']->get_response_data();
211
-
212
- foreach ( $provider['response_args'] as $arg ) {
213
- if ( array_key_exists( $arg, $response ) )
214
- $results['data'][$provider['slug']][$arg] = base64_encode( json_encode( $response[$arg] ) );
215
- }
216
- }
217
- } else {
218
- // get active providers
219
- $providers = $this->get_active_providers();
220
 
221
- if ( ! empty( $providers ) ) {
222
- foreach ( $providers as $provider ) {
223
- // get provider
224
- $provider = $rl->providers[$provider];
225
 
226
- // add response data arguments if needed
227
- if ( ! empty( $provider['response_args'] ) ) {
228
- $response = $provider['instance']->get_response_data();
229
 
230
- foreach ( $provider['response_args'] as $arg ) {
231
- if ( array_key_exists( $arg, $response ) )
232
- $results['data'][$provider['slug']][$arg] = base64_encode( json_encode( $response[$arg] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
  }
235
  }
236
  }
237
- }
238
 
239
- if ( ! empty( $results['images'] ) ) {
240
- // create WP compatible attachments
241
- $results['images'] = $this->create_wp_remote_attachments( $results['images'], $data );
242
 
243
- // handle last page if needed
244
- $results['last'] = apply_filters( 'rl_remote_library_query_last_page', false, $results, $data );
245
- } else
246
- $results['last'] = true;
 
247
  }
248
 
249
- // send JSON
250
  wp_send_json( $results );
251
  }
252
 
@@ -287,34 +291,35 @@ class Responsive_Lightbox_Remote_Library {
287
  $loaded = wp_upload_bits( $file_name, null, $bits, current_time( 'Y/m' ) );
288
 
289
  if ( isset( $loaded['error'] ) && $loaded['error'] ) {
290
- $results = array(
291
  'error' => true,
292
  'message' => $loaded['error']
293
- );
294
  } else {
295
  // simulate upload
296
- $_FILES['rl-remote-image'] = array(
297
  'error' => 0,
298
  'name' => $file_name,
299
  'tmp_name' => $loaded['file'],
300
  'size' => filesize( $loaded['file'] )
301
- );
302
 
303
  // get post ID
304
  $post_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
305
 
306
- // upload image
307
  $attachment_id = media_handle_upload(
308
  'rl-remote-image',
309
  $post_id,
310
- array(
311
  'post_title' => $data['image']['title'],
312
  'post_content' => $data['image']['description'],
313
  'post_excerpt' => $data['image']['caption']
314
- ), array(
 
315
  'action' => 'rl_remote_library_handle_upload',
316
  'test_form' => false
317
- )
318
  );
319
 
320
  // upload success?
@@ -329,7 +334,7 @@ class Responsive_Lightbox_Remote_Library {
329
  }
330
  }
331
 
332
- // send JSON
333
  wp_send_json( $new_data );
334
  }
335
 
@@ -341,12 +346,22 @@ class Responsive_Lightbox_Remote_Library {
341
  * @return array
342
  */
343
  public function create_wp_remote_attachments( $results, $args ) {
 
344
  $user = wp_get_current_user();
 
 
345
  $copy = $results;
 
 
346
  $time = current_time( 'timestamp' );
 
 
347
  $date_format = get_option( 'date_format' );
 
 
348
  $date = date_i18n( __( 'F j Y' ), $time );
349
 
 
350
  foreach ( $results as $no => $result ) {
351
  // make sure those attributes are strings
352
  $copy[$no]['caption'] = (string) $result['caption'];
@@ -358,11 +373,11 @@ class Responsive_Lightbox_Remote_Library {
358
  $copy[$no]['id'] = 'rl-attachment-' . ( ( $args['preview_page'] - 1 ) * $args['preview_per_page'] + $no ) . '-' . $args['media_provider'];
359
  $copy[$no]['remote_library_image'] = true;
360
  $copy[$no]['author'] = $user->ID;
361
- $copy[$no]['authorName'] = $user->user_login;
362
- $copy[$no]['can'] = array(
363
  'save' => true,
364
  'remove' => false
365
- );
366
  $copy[$no]['compat'] = '';
367
  $copy[$no]['date'] = $time;
368
  $copy[$no]['dateFormatted'] = $date;
@@ -392,31 +407,31 @@ class Responsive_Lightbox_Remote_Library {
392
  }
393
 
394
  $copy[$no]['modified'] = $time;
395
- $copy[$no]['nonces'] = array(
396
  'delete' => '',
397
- 'edit' => '',
398
  'update' => ''
399
- );
400
  $copy[$no]['orientation'] = $result['orientation'];
401
  $copy[$no]['status'] = 'inherit';
402
  $copy[$no]['type'] = 'image';
403
  $copy[$no]['uploadedTo'] = 0;
404
  $copy[$no]['uploadedToLink'] = '';
405
  $copy[$no]['uploadedToTitle'] = '';
406
- $copy[$no]['sizes'] = array(
407
- 'medium' => array(
408
  'height' => $result['thumbnail_height'],
409
  'width' => $result['thumbnail_width'],
410
  'orientation' => $result['thumbnail_orientation'],
411
  'url' => $result['thumbnail_url']
412
- ),
413
- 'full' => array(
414
  'height' => $result['height'],
415
  'width' => $result['width'],
416
  'orientation' => $result['orientation'],
417
  'url' => $result['url']
418
- )
419
- );
420
  }
421
 
422
  return apply_filters( 'rl_remote_library_wp_attachments', $copy, $args );
23
  return;
24
 
25
  // actions
26
+ add_action( 'wp_ajax_rl_remote_library_query', [ $this, 'ajax_query_media' ] );
27
+ add_action( 'wp_ajax_rl_upload_image', [ $this, 'ajax_upload_image' ] );
28
+ add_action( 'admin_enqueue_scripts', [ $this, 'remote_library_scripts' ] );
29
 
30
  // add filter to send new data to editor
31
+ add_filter( 'image_send_to_editor', [ $this, 'send_image_to_editor' ], 21, 8 );
32
  }
33
 
34
  /**
82
  * @return string
83
  */
84
  function send_image_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
85
+ if ( $id === Responsive_Lightbox()->galleries->maybe_generate_thumbnail() && isset( $_POST['attachment'] ) && is_array( $_POST['attachment'] ) ) {
86
  $attachment = wp_unslash( $_POST['attachment'] );
87
 
88
  if ( isset( $attachment['remote_library_image'], $attachment['width'], $attachment['height'] ) ) {
89
+ $html = preg_replace( '/src=(\'|")(.*?)(\'|")/', 'src="' . ( ! empty( $attachment['rl_url'] ) ? esc_url( $attachment['rl_url'] ) : $url ) . '"', $html );
90
+ $html = preg_replace( '/width=(\'|")(.*?)(\'|")/', 'width="' . (int) $attachment['width'] . '"', $html );
91
+ $html = preg_replace( '/height=(\'|")(.*?)(\'|")/', 'height="' . (int) $attachment['height'] . '"', $html );
92
+ $html = preg_replace( '/(\s)?id="attachment_' . (int) $id . '"/', '', $html );
93
+ $html = preg_replace( '/(\s)?wp-image-' . (int) $id . '/', '', $html );
94
  }
95
  }
96
 
155
  // get main instance
156
  $rl = Responsive_Lightbox();
157
 
158
+ wp_enqueue_script( 'rl-remote-library-media', RESPONSIVE_LIGHTBOX_URL . '/js/admin-media.js', [ 'jquery', 'media-models', 'underscore' ], $rl->defaults['version'] );
159
 
160
  wp_localize_script(
161
  'rl-remote-library-media',
162
  'rlRemoteLibraryMedia',
163
+ [
164
  'thumbnailID' => $rl->galleries->maybe_generate_thumbnail(),
165
  'postID' => get_the_ID(),
166
  'providers' => $this->get_providers(),
170
  'uploadAndSelect' => __( 'Upload and Select', 'responsive-lightbox' ),
171
  'filterByremoteLibrary' => __( 'Filter by remote library', 'responsive-lightbox' ),
172
  'getUploadNonce' => wp_create_nonce( 'rl-remote-library-upload-image' )
173
+ ]
174
  );
175
 
176
  // enqueue gallery
184
  */
185
  public function ajax_query_media() {
186
  $data = stripslashes_deep( $_POST );
187
+ $results = [
188
  'last' => false,
189
  'images' => [],
190
  'data' => []
191
+ ];
192
 
193
+ if ( isset( $data['media_provider'], $data['media_search'], $data['media_page'] ) ) {
194
+ $data['media_provider'] = sanitize_key( $data['media_provider'] );
 
195
 
196
+ if ( $data['media_provider'] === 'all' || $this->is_active_provider( $data['media_provider'] ) ) {
197
+ $data['preview_page'] = (int) $data['media_page'];
198
+ $data['preview_per_page'] = 20;
199
 
200
+ // get images
201
+ $results['images'] = $this->get_remote_library_images( $data );
202
 
203
+ // get main instance
204
+ $rl = Responsive_Lightbox();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
+ // single provider?
207
+ if ( $data['media_provider'] !== 'all' ) {
208
+ // get provider
209
+ $provider = $rl->providers[$data['media_provider']];
210
 
211
+ // add response data arguments if needed
212
+ if ( ! empty( $provider['response_args'] ) ) {
213
+ $response = $provider['instance']->get_response_data();
214
 
215
+ foreach ( $provider['response_args'] as $arg ) {
216
+ if ( array_key_exists( $arg, $response ) )
217
+ $results['data'][$provider['slug']][$arg] = base64_encode( json_encode( $response[$arg] ) );
218
+ }
219
+ }
220
+ } else {
221
+ // get active providers
222
+ $providers = $this->get_active_providers();
223
+
224
+ if ( ! empty( $providers ) ) {
225
+ foreach ( $providers as $provider ) {
226
+ // get provider
227
+ $provider = $rl->providers[$provider];
228
+
229
+ // add response data arguments if needed
230
+ if ( ! empty( $provider['response_args'] ) ) {
231
+ $response = $provider['instance']->get_response_data();
232
+
233
+ foreach ( $provider['response_args'] as $arg ) {
234
+ if ( array_key_exists( $arg, $response ) )
235
+ $results['data'][$provider['slug']][$arg] = base64_encode( json_encode( $response[$arg] ) );
236
+ }
237
  }
238
  }
239
  }
240
  }
 
241
 
242
+ if ( ! empty( $results['images'] ) ) {
243
+ // create WP compatible attachments
244
+ $results['images'] = $this->create_wp_remote_attachments( $results['images'], $data );
245
 
246
+ // handle last page if needed
247
+ $results['last'] = apply_filters( 'rl_remote_library_query_last_page', false, $results, $data );
248
+ } else
249
+ $results['last'] = true;
250
+ }
251
  }
252
 
253
+ // send data
254
  wp_send_json( $results );
255
  }
256
 
291
  $loaded = wp_upload_bits( $file_name, null, $bits, current_time( 'Y/m' ) );
292
 
293
  if ( isset( $loaded['error'] ) && $loaded['error'] ) {
294
+ $results = [
295
  'error' => true,
296
  'message' => $loaded['error']
297
+ ];
298
  } else {
299
  // simulate upload
300
+ $_FILES['rl-remote-image'] = [
301
  'error' => 0,
302
  'name' => $file_name,
303
  'tmp_name' => $loaded['file'],
304
  'size' => filesize( $loaded['file'] )
305
+ ];
306
 
307
  // get post ID
308
  $post_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
309
 
310
+ // upload image, wp handle sanitization and validation here
311
  $attachment_id = media_handle_upload(
312
  'rl-remote-image',
313
  $post_id,
314
+ [
315
  'post_title' => $data['image']['title'],
316
  'post_content' => $data['image']['description'],
317
  'post_excerpt' => $data['image']['caption']
318
+ ],
319
+ [
320
  'action' => 'rl_remote_library_handle_upload',
321
  'test_form' => false
322
+ ]
323
  );
324
 
325
  // upload success?
334
  }
335
  }
336
 
337
+ // send data
338
  wp_send_json( $new_data );
339
  }
340
 
346
  * @return array
347
  */
348
  public function create_wp_remote_attachments( $results, $args ) {
349
+ // get current user
350
  $user = wp_get_current_user();
351
+
352
+ // copy results
353
  $copy = $results;
354
+
355
+ // get current time
356
  $time = current_time( 'timestamp' );
357
+
358
+ // get date format
359
  $date_format = get_option( 'date_format' );
360
+
361
+ // format date
362
  $date = date_i18n( __( 'F j Y' ), $time );
363
 
364
+ // $result is already sanitized by specific provider sanitize_result function
365
  foreach ( $results as $no => $result ) {
366
  // make sure those attributes are strings
367
  $copy[$no]['caption'] = (string) $result['caption'];
373
  $copy[$no]['id'] = 'rl-attachment-' . ( ( $args['preview_page'] - 1 ) * $args['preview_per_page'] + $no ) . '-' . $args['media_provider'];
374
  $copy[$no]['remote_library_image'] = true;
375
  $copy[$no]['author'] = $user->ID;
376
+ $copy[$no]['authorName'] = esc_html( $user->user_login );
377
+ $copy[$no]['can'] = [
378
  'save' => true,
379
  'remove' => false
380
+ ];
381
  $copy[$no]['compat'] = '';
382
  $copy[$no]['date'] = $time;
383
  $copy[$no]['dateFormatted'] = $date;
407
  }
408
 
409
  $copy[$no]['modified'] = $time;
410
+ $copy[$no]['nonces'] = [
411
  'delete' => '',
412
+ 'edit' => '',
413
  'update' => ''
414
+ ];
415
  $copy[$no]['orientation'] = $result['orientation'];
416
  $copy[$no]['status'] = 'inherit';
417
  $copy[$no]['type'] = 'image';
418
  $copy[$no]['uploadedTo'] = 0;
419
  $copy[$no]['uploadedToLink'] = '';
420
  $copy[$no]['uploadedToTitle'] = '';
421
+ $copy[$no]['sizes'] = [
422
+ 'medium' => [
423
  'height' => $result['thumbnail_height'],
424
  'width' => $result['thumbnail_width'],
425
  'orientation' => $result['thumbnail_orientation'],
426
  'url' => $result['thumbnail_url']
427
+ ],
428
+ 'full' => [
429
  'height' => $result['height'],
430
  'width' => $result['width'],
431
  'orientation' => $result['orientation'],
432
  'url' => $result['url']
433
+ ]
434
+ ];
435
  }
436
 
437
  return apply_filters( 'rl_remote_library_wp_attachments', $copy, $args );
includes/class-settings.php CHANGED
@@ -12,9 +12,9 @@ new Responsive_Lightbox_Settings();
12
  */
13
  class Responsive_Lightbox_Settings {
14
 
15
- public $settings = array();
16
- public $tabs = array();
17
- public $scripts = array();
18
 
19
  /**
20
  * Class constructor.
@@ -26,10 +26,10 @@ class Responsive_Lightbox_Settings {
26
  Responsive_Lightbox()->settings = $this;
27
 
28
  // actions
29
- add_action( 'admin_init', array( $this, 'register_settings' ) );
30
- add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
31
- add_action( 'after_setup_theme', array( $this, 'load_defaults' ) );
32
- add_action( 'init', array( $this, 'init_builder' ) );
33
  }
34
 
35
  /**
@@ -40,7 +40,7 @@ class Responsive_Lightbox_Settings {
40
  public function init_builder() {
41
  // add categories
42
  if ( Responsive_Lightbox()->options['builder']['gallery_builder'] && Responsive_Lightbox()->options['builder']['categories'] && Responsive_Lightbox()->options['builder']['archives'] ) {
43
- $terms = get_terms( array( 'taxonomy' => 'rl_category', 'hide_empty' => false ) );
44
 
45
  if ( ! empty( $terms ) ) {
46
  foreach ( $terms as $term ) {
@@ -65,100 +65,103 @@ class Responsive_Lightbox_Settings {
65
  // assign main instance
66
  $rl = Responsive_Lightbox();
67
 
68
- $this->scripts = apply_filters( 'rl_settings_scripts', array(
69
- 'swipebox' => array(
70
- 'name' => __( 'SwipeBox', 'responsive-lightbox' ),
71
- 'animations' => array(
72
- 'css' => __( 'CSS', 'responsive-lightbox' ),
73
- 'jquery' => __( 'jQuery', 'responsive-lightbox' )
74
- ),
75
- 'supports' => array( 'title' )
76
- ),
77
- 'prettyphoto' => array(
78
- 'name' => __( 'prettyPhoto', 'responsive-lightbox' ),
79
- 'animation_speeds' => array(
80
- 'slow' => __( 'slow', 'responsive-lightbox' ),
81
- 'normal' => __( 'normal', 'responsive-lightbox' ),
82
- 'fast' => __( 'fast', 'responsive-lightbox' )
83
- ),
84
- 'themes' => array(
85
- 'pp_default' => __( 'default', 'responsive-lightbox' ),
86
- 'light_rounded' => __( 'light rounded', 'responsive-lightbox' ),
87
- 'dark_rounded' => __( 'dark rounded', 'responsive-lightbox' ),
88
- 'light_square' => __( 'light square', 'responsive-lightbox' ),
89
- 'dark_square' => __( 'dark square', 'responsive-lightbox' ),
90
- 'facebook' => __( 'facebook', 'responsive-lightbox' )
91
- ),
92
- 'wmodes' => array(
93
- 'window' => __( 'window', 'responsive-lightbox' ),
94
- 'transparent' => __( 'transparent', 'responsive-lightbox' ),
95
- 'opaque' => __( 'opaque', 'responsive-lightbox' ),
96
- 'direct' => __( 'direct', 'responsive-lightbox' ),
97
- 'gpu' => __( 'gpu', 'responsive-lightbox' )
98
- ),
99
- 'supports' => array( 'inline', 'iframe', 'ajax', 'title', 'caption' )
100
- ),
101
- 'fancybox' => array(
102
- 'name' => __( 'FancyBox', 'responsive-lightbox' ),
103
- 'transitions' => array(
104
- 'elastic' => __( 'elastic', 'responsive-lightbox' ),
105
- 'fade' => __( 'fade', 'responsive-lightbox' ),
106
- 'none' => __( 'none', 'responsive-lightbox' )
107
- ),
108
- 'scrollings' => array(
109
- 'auto' => __( 'auto', 'responsive-lightbox' ),
110
- 'yes' => __( 'yes', 'responsive-lightbox' ),
111
- 'no' => __( 'no', 'responsive-lightbox' )
112
- ),
113
- 'easings' => array(
114
- 'swing' => __( 'swing', 'responsive-lightbox' ),
115
- 'linear' => __( 'linear', 'responsive-lightbox' )
116
- ),
117
- 'positions' => array(
118
- 'outside' => __( 'outside', 'responsive-lightbox' ),
119
- 'inside' => __( 'inside', 'responsive-lightbox' ),
120
- 'over' => __( 'over', 'responsive-lightbox' )
121
- ),
122
- 'supports' => array( 'inline', 'iframe', 'ajax', 'title' )
123
- ),
124
- 'nivo' => array(
125
- 'name' => __( 'Nivo Lightbox', 'responsive-lightbox' ),
126
- 'effects' => array(
127
- 'fade' => __( 'fade', 'responsive-lightbox' ),
128
- 'fadeScale' => __( 'fade scale', 'responsive-lightbox' ),
129
- 'slideLeft' => __( 'slide left', 'responsive-lightbox' ),
130
- 'slideRight' => __( 'slide right', 'responsive-lightbox' ),
131
- 'slideUp' => __( 'slide up', 'responsive-lightbox' ),
132
- 'slideDown' => __( 'slide down', 'responsive-lightbox' ),
133
- 'fall' => __( 'fall', 'responsive-lightbox' )
134
- ),
135
- 'supports' => array( 'inline', 'iframe', 'ajax', 'title' )
136
- ),
137
- 'imagelightbox' => array(
138
- 'name' => __( 'Image Lightbox', 'responsive-lightbox' ),
139
- 'supports' => array()
140
- ),
141
- 'tosrus' => array(
142
- 'name' => __( 'TosRUs', 'responsive-lightbox' ),
143
- 'supports' => array( 'inline', 'title' )
144
- ),
145
- 'featherlight' => array(
146
- 'name' => __( 'Featherlight', 'responsive-lightbox' ),
147
- 'supports' => array( 'inline', 'iframe', 'ajax' )
148
- ),
149
- 'magnific' => array(
150
- 'name' => __( 'Magnific Popup', 'responsive-lightbox' ),
151
- 'supports' => array( 'inline', 'iframe', 'ajax', 'title', 'caption' )
152
- )
153
- ) );
154
-
155
- $this->image_titles = array(
 
 
 
156
  'default' => __( 'None', 'responsive-lightbox' ),
157
  'title' => __( 'Image Title', 'responsive-lightbox' ),
158
  'caption' => __( 'Image Caption', 'responsive-lightbox' ),
159
  'alt' => __( 'Image Alt Text', 'responsive-lightbox' ),
160
  'description' => __( 'Image Description', 'responsive-lightbox' )
161
- );
162
 
163
  // get scripts
164
  foreach ( $this->scripts as $key => $value ) {
@@ -166,568 +169,571 @@ class Responsive_Lightbox_Settings {
166
  }
167
 
168
  // get image sizes
169
- $sizes = apply_filters( 'image_size_names_choose', array(
170
- 'thumbnail' => __( 'Thumbnail', 'responsive-lightbox' ),
171
- 'medium' => __( 'Medium', 'responsive-lightbox' ),
172
- 'large' => __( 'Large', 'responsive-lightbox' ),
173
- 'full' => __( 'Full Size', 'responsive-lightbox' ),
174
- ) );
 
 
 
175
 
176
  // prepare galeries
177
- $galleries = $builder_galleries = wp_parse_args( apply_filters( 'rl_gallery_types', array() ), $rl->gallery_types );
178
 
179
  unset( $builder_galleries['default'] );
180
 
181
- $this->settings = array(
182
- 'settings' => array(
183
  'option_group' => 'responsive_lightbox_settings',
184
  'option_name' => 'responsive_lightbox_settings',
185
- 'sections' => array(
186
- 'responsive_lightbox_settings' => array(
187
  'title' => __( 'General Settings', 'responsive-lightbox' )
188
- )
189
- ),
190
  'prefix' => 'rl',
191
- 'fields' => array(
192
- 'tour' => array(
193
  'title' => __( 'Introduction Tour', 'responsive-lightbox' ),
194
  'section' => 'responsive_lightbox_settings',
195
  'type' => 'button',
196
  'label' => __( 'Start Tour', 'responsive-lightbox' ),
197
  'description' => __( 'Take this tour to quickly learn about the use of this plugin.', 'responsive-lightbox' ),
198
  'classname' => 'button-primary button-hero',
199
- ),
200
- 'script' => array(
201
  'title' => __( 'Default lightbox', 'responsive-lightbox' ),
202
  'section' => 'responsive_lightbox_settings',
203
  'type' => 'select',
204
  'label' => '',
205
- 'description' => sprintf(__( 'Select your preferred ligthbox effect script or get our <a href="%s">premium extensions</a>.', 'responsive-lightbox' ), wp_nonce_url( add_query_arg( array( 'action' => 'rl-hide-notice' ), admin_url( 'admin.php?page=responsive-lightbox-addons' ) ), 'rl_action', 'rl_nonce' ) ),
206
  'options' => $scripts
207
- ),
208
- 'selector' => array(
209
  'title' => __( 'Selector', 'responsive-lightbox' ),
210
  'section' => 'responsive_lightbox_settings',
211
  'type' => 'text',
212
  'description' => __( 'Enter the rel selector lightbox effect will be applied to.', 'responsive-lightbox' )
213
- ),
214
- 'image_links' => array(
215
  'title' => __( 'Images', 'responsive-lightbox' ),
216
  'section' => 'responsive_lightbox_settings',
217
  'type' => 'boolean',
218
  'label' => __( 'Enable lightbox for WordPress image links.', 'responsive-lightbox' )
219
- ),
220
- 'image_title' => array(
221
  'title' => __( 'Single image title', 'responsive-lightbox' ),
222
  'section' => 'responsive_lightbox_settings',
223
  'type' => 'select',
224
  'description' => __( 'Select title for single images.', 'responsive-lightbox' ),
225
  'options' => $this->image_titles
226
- ),
227
- 'image_caption' => array(
228
  'title' => __( 'Single image caption', 'responsive-lightbox' ),
229
  'section' => 'responsive_lightbox_settings',
230
  'type' => 'select',
231
  'description' => __( 'Select caption for single images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ),
232
  'options' => $this->image_titles
233
- ),
234
- 'images_as_gallery' => array(
235
  'title' => __( 'Single images as gallery', 'responsive-lightbox' ),
236
  'section' => 'responsive_lightbox_settings',
237
  'type' => 'boolean',
238
  'label' => __( 'Display single post images as a gallery.', 'responsive-lightbox' )
239
- ),
240
- 'galleries' => array(
241
  'title' => __( 'Galleries', 'responsive-lightbox' ),
242
  'section' => 'responsive_lightbox_settings',
243
  'type' => 'boolean',
244
  'label' => __( 'Enable lightbox for WordPress image galleries.', 'responsive-lightbox' )
245
- ),
246
- 'default_gallery' => array(
247
  'title' => __( 'WordPress gallery', 'responsive-lightbox' ),
248
  'section' => 'responsive_lightbox_settings',
249
  'type' => 'select',
250
  'description' => __( 'Select your preferred default WordPress gallery style.', 'responsive-lightbox' ),
251
  'options' => $galleries
252
- ),
253
- 'builder_gallery' => array(
254
  'title' => __( 'Builder gallery', 'responsive-lightbox' ),
255
  'section' => 'responsive_lightbox_settings',
256
  'type' => 'select',
257
  'description' => __( 'Select your preferred default builder gallery style.', 'responsive-lightbox' ),
258
  'options' => $builder_galleries
259
- ),
260
- 'default_woocommerce_gallery' => array(
261
  'title' => __( 'WooCommerce gallery', 'responsive-lightbox' ),
262
  'section' => 'responsive_lightbox_settings',
263
  'type' => 'select',
264
  'disabled' => ! class_exists( 'WooCommerce' ),
265
  'description' => __( 'Select your preferred gallery style for WooCommerce product gallery.', 'responsive-lightbox' ),
266
  'options' => $galleries
267
- ),
268
- 'gallery_image_size' => array(
269
  'title' => __( 'Gallery image size', 'responsive-lightbox' ),
270
  'section' => 'responsive_lightbox_settings',
271
  'type' => 'select',
272
  'description' => __( 'Select image size for gallery image links.', 'responsive-lightbox' ),
273
  'options' => $sizes
274
- ),
275
- 'gallery_image_title' => array(
276
  'title' => __( 'Gallery image title', 'responsive-lightbox' ),
277
  'section' => 'responsive_lightbox_settings',
278
  'type' => 'select',
279
  'description' => __( 'Select title for the gallery images.', 'responsive-lightbox' ),
280
  'options' => $this->image_titles
281
- ),
282
- 'gallery_image_caption' => array(
283
  'title' => __( 'Gallery image caption', 'responsive-lightbox' ),
284
  'section' => 'responsive_lightbox_settings',
285
  'type' => 'select',
286
  'description' => __( 'Select caption for the gallery images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ),
287
  'options' => $this->image_titles
288
- ),
289
- 'videos' => array(
290
  'title' => __( 'Videos', 'responsive-lightbox' ),
291
  'section' => 'responsive_lightbox_settings',
292
  'type' => 'boolean',
293
  'label' => __( 'Enable lightbox for YouTube and Vimeo video links.', 'responsive-lightbox' )
294
- ),
295
- 'widgets' => array(
296
  'title' => __( 'Widgets', 'responsive-lightbox' ),
297
  'section' => 'responsive_lightbox_settings',
298
  'type' => 'boolean',
299
  'label' => __( 'Enable lightbox for widgets content.', 'responsive-lightbox' )
300
- ),
301
- 'comments' => array(
302
  'title' => __( 'Comments', 'responsive-lightbox' ),
303
  'section' => 'responsive_lightbox_settings',
304
  'type' => 'boolean',
305
  'label' => __( 'Enable lightbox for comments content.', 'responsive-lightbox' )
306
- ),
307
- 'force_custom_gallery' => array(
308
  'title' => __( 'Force lightbox', 'responsive-lightbox' ),
309
  'section' => 'responsive_lightbox_settings',
310
  'type' => 'boolean',
311
  'label' => __( 'Try to force lightbox for custom WP gallery replacements, like Jetpack or Visual Composer galleries.', 'responsive-lightbox' )
312
- ),
313
- 'woocommerce_gallery_lightbox' => array(
314
  'title' => __( 'WooCommerce lightbox', 'responsive-lightbox' ),
315
  'section' => 'responsive_lightbox_settings',
316
  'type' => 'boolean',
317
  'label' => __( 'Replace WooCommerce product gallery lightbox.', 'responsive-lightbox' ),
318
  'disabled' => ! class_exists( 'WooCommerce' ) || Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default'
319
- ),
320
- 'enable_custom_events' => array(
321
  'title' => __( 'Custom events', 'responsive-lightbox' ),
322
  'section' => 'responsive_lightbox_settings',
323
  'type' => 'multiple',
324
- 'fields' => array(
325
- 'enable_custom_events' => array(
326
  'type' => 'boolean',
327
  'label' => __( 'Enable triggering lightbox on custom jQuery events.', 'responsive-lightbox' )
328
- ),
329
- 'custom_events' => array(
330
  'type' => 'text',
331
  'description' => __( 'Enter a space separated list of events.', 'responsive-lightbox' )
332
- )
333
- )
334
- ),
335
- 'loading_place' => array(
336
  'title' => __( 'Loading place', 'responsive-lightbox' ),
337
  'section' => 'responsive_lightbox_settings',
338
  'type' => 'radio',
339
  'description' => __( 'Select where all the lightbox scripts should be placed.', 'responsive-lightbox' ),
340
- 'options' => array(
341
  'header' => __( 'Header', 'responsive-lightbox' ),
342
  'footer' => __( 'Footer', 'responsive-lightbox' )
343
- )
344
- ),
345
- 'conditional_loading' => array(
346
  'title' => __( 'Conditional loading', 'responsive-lightbox' ),
347
  'section' => 'responsive_lightbox_settings',
348
  'type' => 'boolean',
349
  'label' => __( 'Enable to load scripts and styles only on pages that have images or galleries in post content.', 'responsive-lightbox' )
350
- ),
351
- 'deactivation_delete' => array(
352
  'title' => __( 'Delete data', 'responsive-lightbox' ),
353
  'section' => 'responsive_lightbox_settings',
354
  'type' => 'boolean',
355
  'label' => __( 'Delete all plugin settings on deactivation.', 'responsive-lightbox' ),
356
  'description' => __( 'Enable this to delete all plugin settings and also delete all plugin capabilities from all users on deactivation.', 'responsive-lightbox' )
357
- )
358
- )
359
- ),
360
- 'builder' => array(
361
  'option_group' => 'responsive_lightbox_builder',
362
  'option_name' => 'responsive_lightbox_builder',
363
- 'sections' => array(
364
- 'responsive_lightbox_builder' => array(
365
  'title' => __( 'Gallery Builder Settings', 'responsive-lightbox' )
366
- )
367
- ),
368
  'prefix' => 'rl',
369
- 'fields' => array(
370
- 'gallery_builder' => array(
371
  'title' => __( 'Gallery Builder', 'responsive-lightbox' ),
372
  'section' => 'responsive_lightbox_builder',
373
  'type' => 'boolean',
374
  'label' => __( 'Enable advanced gallery builder.', 'responsive-lightbox' )
375
- ),
376
- 'categories' => array(
377
  'title' => __( 'Categories', 'responsive-lightbox' ),
378
  'section' => 'responsive_lightbox_builder',
379
  'type' => 'boolean',
380
  'label' => __( 'Enable Gallery Categories.', 'responsive-lightbox' ),
381
  'description' => __( 'Enable if you want to use Gallery Categories.', 'responsive-lightbox' )
382
- ),
383
- 'tags' => array(
384
  'title' => __( 'Tags', 'responsive-lightbox' ),
385
  'section' => 'responsive_lightbox_builder',
386
  'type' => 'boolean',
387
  'label' => __( 'Enable Gallery Tags.', 'responsive-lightbox' ),
388
  'description' => __( 'Enable if you want to use Gallery Tags.', 'responsive-lightbox' )
389
- ),
390
- 'permalink' => array(
391
  'title' => __( 'Gallery Permalink', 'responsive-lightbox' ),
392
  'section' => 'responsive_lightbox_builder',
393
  'type' => 'text',
394
- 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink'] ) ) . '</strong>/</code><br />' . __( 'Enter gallery page slug.', 'responsive-lightbox' )
395
- ),
396
- 'permalink_categories' => array(
397
  'title' => __( 'Categories Permalink', 'responsive-lightbox' ),
398
  'section' => 'responsive_lightbox_builder',
399
  'type' => 'text',
400
- 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink_categories'] ) ) . '</strong>/</code><br />' . __( 'Enter gallery categories archive page slug.', 'responsive-lightbox' )
401
- ),
402
- 'permalink_tags' => array(
403
  'title' => __( 'Tags Permalink', 'responsive-lightbox' ),
404
  'section' => 'responsive_lightbox_builder',
405
  'type' => 'text',
406
- 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink_tags'] ) ) . '</strong>/</code><br />' . __( 'Enter gallery tags archive page slug.', 'responsive-lightbox' )
407
- ),
408
- 'archives' => array(
409
  'title' => __( 'Archives', 'responsive-lightbox' ),
410
  'section' => 'responsive_lightbox_builder',
411
  'type' => 'boolean',
412
  'label' => __( 'Enable gallery archives.', 'responsive-lightbox' )
413
- ),
414
- 'archives_category' => array(
415
  'title' => __( 'Archives category', 'responsive-lightbox' ),
416
  'section' => 'responsive_lightbox_builder',
417
  'type' => 'select',
418
  'description' => __( 'Select category for gallery archives.', 'responsive-lightbox' ),
419
- 'options' => array(
420
  'all' => __( 'All', 'responsive-lightbox' )
421
- )
422
- )
423
- )
424
- ),
425
- 'folders' => array(
426
  'option_group' => 'responsive_lightbox_folders',
427
  'option_name' => 'responsive_lightbox_folders',
428
- 'sections' => array(
429
- 'responsive_lightbox_folders' => array(
430
  'title' => __( 'Folders Settings', 'responsive-lightbox' )
431
- )
432
- ),
433
  'prefix' => 'rl',
434
- 'fields' => array(
435
- 'active' => array(
436
  'title' => __( 'Folders', 'responsive-lightbox' ),
437
  'section' => 'responsive_lightbox_folders',
438
  'type' => 'boolean',
439
  'label' => __( 'Enable media folders.', 'responsive-lightbox' )
440
- ),
441
- 'media_taxonomy' => array(
442
  'title' => __( 'Media taxonomy', 'responsive-lightbox' ),
443
  'section' => 'responsive_lightbox_folders',
444
  'type' => 'select',
445
  'description' => __( 'Select media taxonomy.', 'responsive-lightbox' ) . '<br />' . __( 'If you have ever used custom media taxonomies you may try to <a id="rl_folders_load_old_taxonomies" href="#">load and use them.</a>', 'responsive-lightbox' ),
446
  'after_field' => '<span class="spinner rl-spinner"></span>',
447
- 'options' => array( $rl->options['folders']['media_taxonomy'] => $rl->options['folders']['media_taxonomy'] . ' (' . __( 'Folders', 'responsive-lightbox' ) . ')' )
448
- ),
449
- 'media_tags' => array(
450
  'title' => __( 'Media tags', 'responsive-lightbox' ),
451
  'section' => 'responsive_lightbox_folders',
452
  'type' => 'boolean',
453
  'label' => __( 'Enable media tags.', 'responsive-lightbox' ),
454
  'description' => __( 'Enable if you want to use media tags.', 'responsive-lightbox' )
455
- ),
456
- 'show_in_menu' => array(
457
  'title' => __( 'Show in menu', 'responsive-lightbox' ),
458
  'section' => 'responsive_lightbox_folders',
459
  'type' => 'boolean',
460
  'label' => __( 'Enable to show the taxonomy in the admin menu.', 'responsive-lightbox' )
461
- ),
462
- 'folders_removal' => array(
463
  'title' => __( 'Subfolder removal', 'responsive-lightbox' ),
464
  'section' => 'responsive_lightbox_folders',
465
  'type' => 'boolean',
466
  'label' => __( 'Select to remove subfolders when parent folder is deleted.', 'responsive-lightbox' )
467
- ),
468
- 'jstree_wholerow' => array(
469
  'title' => __( 'Whole row', 'responsive-lightbox' ),
470
  'section' => 'responsive_lightbox_folders',
471
  'type' => 'boolean',
472
  'label' => __( 'Enable to highlight folder\'s row as a clickable area.', 'responsive-lightbox' )
473
- )
474
- )
475
- ),
476
- 'remote_library' => array(
477
  'option_group' => 'responsive_lightbox_remote_library',
478
  'option_name' => 'responsive_lightbox_remote_library',
479
- 'sections' => array(
480
- 'responsive_lightbox_remote_library' => array(
481
  'title' => __( 'Remote Library Settings', 'responsive-lightbox' )
482
- ),
483
- 'responsive_lightbox_remote_library_providers' => array(
484
  'title' => __( 'Media Providers', 'responsive-lightbox' ),
485
  'page' => 'responsive_lightbox_remote_library',
486
- 'callback' => array( $this, 'remote_library_providers_description' )
487
- )
488
- ),
489
  'prefix' => 'rl',
490
- 'fields' => array(
491
- 'active' => array(
492
  'title' => __( 'Remote Library', 'responsive-lightbox' ),
493
  'section' => 'responsive_lightbox_remote_library',
494
  'type' => 'boolean',
495
  'label' => __( 'Enable remote libraries.', 'responsive-lightbox' ),
496
  'description' => __( 'Check this to enable remote access to the following image libraries.', 'responsive-lightbox' )
497
- ),
498
- 'caching' => array(
499
  'title' => __( 'Caching', 'responsive-lightbox' ),
500
  'section' => 'responsive_lightbox_remote_library',
501
  'type' => 'boolean',
502
  'label' => __( 'Enable remote library requests caching.', 'responsive-lightbox' )
503
- ),
504
- 'cache_expiry' => array(
505
  'title' => __( 'Cache expiry', 'responsive-lightbox' ),
506
  'section' => 'responsive_lightbox_remote_library',
507
  'type' => 'number',
508
  'min' => 1,
509
  'description' => __( 'Enter the cache expiry time.', 'responsive-lightbox' ),
510
  'append' => __( 'hour(s)', 'responsive-lightbox' )
511
- )
512
- )
513
- ),
514
- 'configuration' => array(
515
  'option_group' => 'responsive_lightbox_configuration',
516
  'option_name' => 'responsive_lightbox_configuration',
517
- 'sections' => array(
518
- 'responsive_lightbox_configuration' => array(
519
  'title' => sprintf( __( '%s Settings', 'responsive-lightbox' ), ( isset( $this->scripts[$rl->options['settings']['script']]['name'] ) ? $this->scripts[$rl->options['settings']['script']]['name'] : $this->scripts[$rl->defaults['settings']['script']]['name'] ) )
520
- ),
521
- ),
522
  'prefix' => 'rl',
523
- 'fields' => array()
524
- ),
525
- 'capabilities' => array(
526
  'option_group' => 'responsive_lightbox_capabilities',
527
  'option_name' => 'responsive_lightbox_capabilities',
528
- 'callback' => array( $this, 'validate_capabilities' ),
529
- 'sections' => array(
530
- 'responsive_lightbox_capabilities_fields' => array(
531
  'title' => __( 'Capabilities Settings', 'responsive-lightbox' ),
532
  'page' => 'responsive_lightbox_capabilities'
533
- ),
534
- 'responsive_lightbox_capabilities' => array(
535
- 'callback' => array( $this, 'capabilities_table' )
536
- )
537
- ),
538
  'prefix' => 'rl',
539
- 'fields' => array(
540
- 'active' => array(
541
  'title' => __( 'Capabilities', 'responsive-lightbox' ),
542
  'section' => 'responsive_lightbox_capabilities_fields',
543
  'type' => 'boolean',
544
  'label' => __( 'Enable advanced capability management.', 'responsive-lightbox' ),
545
  'description' => __( 'Check this to enable access to plugin features for selected user roles.', 'responsive-lightbox' )
546
- )
547
- )
548
- ),
549
- 'basicgrid_gallery' => array(
550
  'option_group' => 'responsive_lightbox_basicgrid_gallery',
551
  'option_name' => 'responsive_lightbox_basicgrid_gallery',
552
- 'sections' => array(
553
- 'responsive_lightbox_basicgrid_gallery' => array(
554
  'title' => __( 'Basic Grid Gallery Settings', 'responsive-lightbox' )
555
- )
556
- ),
557
  'prefix' => 'rl',
558
- 'fields' => array(
559
- 'screen_size_columns' => array(
560
  'title' => __( 'Screen sizes', 'responsive-lightbox' ),
561
  'section' => 'responsive_lightbox_basicgrid_gallery',
562
  'type' => 'multiple',
563
  'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
564
- 'fields' => array(
565
- 'columns_lg' => array(
566
  'type' => 'number',
567
  'min' => 0,
568
  'max' => 6,
569
  'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
570
- ),
571
- 'columns_md' => array(
572
  'type' => 'number',
573
  'min' => 0,
574
  'max' => 6,
575
  'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
576
- ),
577
- 'columns_sm' => array(
578
  'type' => 'number',
579
  'min' => 0,
580
  'max' => 6,
581
  'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
582
- ),
583
- 'columns_xs' => array(
584
  'type' => 'number',
585
  'min' => 0,
586
  'max' => 6,
587
  'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
588
- )
589
- ),
590
- ),
591
- 'gutter' => array(
592
  'title' => __( 'Gutter', 'responsive-lightbox' ),
593
  'section' => 'responsive_lightbox_basicgrid_gallery',
594
  'type' => 'number',
595
  'min' => 0,
596
  'description' => __( 'Set the pixel width between the columns and rows.', 'responsive-lightbox' ),
597
  'append' => 'px'
598
- ),
599
- 'force_height' => array(
600
  'title' => __( 'Force height', 'responsive-lightbox' ),
601
  'section' => 'responsive_lightbox_basicgrid_gallery',
602
  'type' => 'boolean',
603
  'label' => __( 'Enable to force the thumbnail row height.', 'responsive-lightbox' )
604
- ),
605
- 'row_height' => array(
606
  'title' => __( 'Row height', 'responsive-lightbox' ),
607
  'section' => 'responsive_lightbox_basicgrid_gallery',
608
  'type' => 'number',
609
  'min' => 50,
610
  'description' => __( 'Enter the thumbnail row height in pixels (used if Force height is enabled). Defaults to 150px.', 'responsive-lightbox' ),
611
  'append' => 'px'
612
- )
613
- )
614
- ),
615
- 'basicslider_gallery' => array(
616
  'option_group' => 'responsive_lightbox_basicslider_gallery',
617
  'option_name' => 'responsive_lightbox_basicslider_gallery',
618
- 'sections' => array(
619
- 'responsive_lightbox_basicslider_gallery' => array(
620
  'title' => __( 'Basic Slider Gallery Settings', 'responsive-lightbox' )
621
- )
622
- ),
623
  'prefix' => 'rl',
624
- 'fields' => array(
625
- 'adaptive_height' => array(
626
  'title' => __( 'Adaptive Height', 'responsive-lightbox' ),
627
  'section' => 'responsive_lightbox_basicslider_gallery',
628
  'type' => 'boolean',
629
  'label' => __( 'The slider height should change on the fly according to the current slide.', 'responsive-lightbox' )
630
- ),
631
- 'loop' => array(
632
  'title' => __( 'Loop', 'responsive-lightbox' ),
633
  'section' => 'responsive_lightbox_basicslider_gallery',
634
  'type' => 'boolean',
635
  'label' => __( 'Whether the slider should loop (i.e. the first slide goes to the last, the last slide goes to the first).', 'responsive-lightbox' )
636
- ),
637
- 'captions' => array(
638
  'title' => __( 'Captions Position', 'responsive-lightbox' ),
639
  'section' => 'responsive_lightbox_basicslider_gallery',
640
  'type' => 'select',
641
  'description' => __( 'Specifies the position of captions or no captions at all.', 'responsive-lightbox' ),
642
- 'options' => array(
643
  'none' => __( 'None', 'responsive-lightbox' ),
644
  'overlay' => __( 'Overlay', 'responsive-lightbox' ),
645
  'below' => __( 'Below', 'responsive-lightbox' )
646
- )
647
- ),
648
- 'init_single' => array(
649
  'title' => __( 'Single Image Slider', 'responsive-lightbox' ),
650
  'section' => 'responsive_lightbox_basicslider_gallery',
651
  'type' => 'boolean',
652
  'label' => __( 'Whether the slider should initialize even if there is only one slide element.', 'responsive-lightbox' )
653
- ),
654
- 'responsive' => array(
655
  'title' => __( 'Responsive', 'responsive-lightbox' ),
656
  'section' => 'responsive_lightbox_basicslider_gallery',
657
  'type' => 'boolean',
658
  'label' => __( 'Whether the slider should be responsive.', 'responsive-lightbox' )
659
- ),
660
- 'preload' => array(
661
  'title' => __( 'Preload', 'responsive-lightbox' ),
662
  'section' => 'responsive_lightbox_basicslider_gallery',
663
  'type' => 'select',
664
  'description' => __( 'Elements that are preloaded before slider shows.', 'responsive-lightbox' ),
665
- 'options' => array(
666
  'all' => __( 'All', 'responsive-lightbox' ),
667
  'visible' => __( 'Only visible', 'responsive-lightbox' )
668
- )
669
- ),
670
- 'pager' => array(
671
  'title' => __( 'Pager', 'responsive-lightbox' ),
672
  'section' => 'responsive_lightbox_basicslider_gallery',
673
  'type' => 'boolean',
674
  'label' => __( 'Whether the slider should have a pager.', 'responsive-lightbox' )
675
- ),
676
- 'controls' => array(
677
  'title' => __( 'Controls', 'responsive-lightbox' ),
678
  'section' => 'responsive_lightbox_basicslider_gallery',
679
  'type' => 'boolean',
680
  'label' => __( 'Whether the slider should have controls (next, previous arrows).', 'responsive-lightbox' )
681
- ),
682
- 'hide_on_end' => array(
683
  'title' => __( 'Hide Controls on End', 'responsive-lightbox' ),
684
  'section' => 'responsive_lightbox_basicslider_gallery',
685
  'type' => 'boolean',
686
  'label' => __( 'Hide the previous or next control when it reaches the first or last slide respectively.', 'responsive-lightbox' )
687
- ),
688
- 'slide_margin' => array(
689
  'title' => __( 'Slide Margin', 'responsive-lightbox' ),
690
  'section' => 'responsive_lightbox_basicslider_gallery',
691
  'type' => 'number',
692
  'min' => 0,
693
  'description' => __( 'The spacing between slides.', 'responsive-lightbox' ),
694
  'append' => '%'
695
- ),
696
- 'transition' => array(
697
  'title' => __( 'Transition', 'responsive-lightbox' ),
698
  'section' => 'responsive_lightbox_basicslider_gallery',
699
  'type' => 'select',
700
  'description' => __( 'Transition type to use, or no transitions.', 'responsive-lightbox' ),
701
- 'options' => array(
702
  'none' => __( 'None', 'responsive-lightbox' ),
703
  'fade' => __( 'Fade', 'responsive-lightbox' ),
704
  'horizontal' => __( 'Horizontal', 'responsive-lightbox' ),
705
  'vertical' => __( 'Vertical', 'responsive-lightbox' ),
706
  'kenburns' => __( 'Ken Burns', 'responsive-lightbox' )
707
- )
708
- ),
709
- 'kenburns_zoom' => array(
710
  'title' => __( 'Ken Burns Zoom', 'responsive-lightbox' ),
711
  'section' => 'responsive_lightbox_basicslider_gallery',
712
  'type' => 'number',
713
  'min' => 0,
714
  'description' => __( 'Max zoom level use for the Ken Burns transition.', 'responsive-lightbox' ),
715
  'append' => '%'
716
- ),
717
- 'speed' => array(
718
  'title' => __( 'Transition Speed', 'responsive-lightbox' ),
719
  'section' => 'responsive_lightbox_basicslider_gallery',
720
  'type' => 'number',
721
  'min' => 0,
722
  'description' => __( 'The time the transition takes to complete.', 'responsive-lightbox' ),
723
  'append' => 'ms'
724
- ),
725
- 'easing' => array(
726
  'title' => __( 'Easing Effect', 'responsive-lightbox' ),
727
  'section' => 'responsive_lightbox_basicslider_gallery',
728
  'type' => 'select',
729
  'description' => __( 'The easing effect to use for the selected transition.', 'responsive-lightbox' ),
730
- 'options' => array(
731
  'linear' => 'linear',
732
  'swing' => 'swing',
733
  'easeInQuad' => 'easeInQuad',
@@ -760,193 +766,203 @@ class Responsive_Lightbox_Settings {
760
  'easeInBounce' => 'easeInBounce',
761
  'easeOutBounce' => 'easeOutBounce',
762
  'easeInOutBounce' => 'easeInOutBounce'
763
- )
764
- ),
765
- 'continuous' => array(
766
  'title' => __( 'Continuous', 'responsive-lightbox' ),
767
  'section' => 'responsive_lightbox_basicslider_gallery',
768
  'type' => 'boolean',
769
  'label' => __( 'Whether the slider should run continuously (seamless transition between the first and last slides).', 'responsive-lightbox' )
770
- ),
771
- 'use_css' => array(
772
  'title' => __( 'Use CSS', 'responsive-lightbox' ),
773
  'section' => 'responsive_lightbox_basicslider_gallery',
774
  'type' => 'boolean',
775
  'label' => __( 'Whether the slider should use CSS transitions. If the user\'s browser doesn\'t support CSS transitions the slider will fallback to jQuery.', 'responsive-lightbox' )
776
- ),
777
- 'slideshow' => array(
778
  'title' => __( 'Slideshow', 'responsive-lightbox' ),
779
  'section' => 'responsive_lightbox_basicslider_gallery',
780
  'type' => 'boolean',
781
  'label' => __( 'Whether the slider should run automatically on load.', 'responsive-lightbox' )
782
- ),
783
- 'slideshow_direction' => array(
784
  'title' => __( 'Slideshow Direction', 'responsive-lightbox' ),
785
  'section' => 'responsive_lightbox_basicslider_gallery',
786
  'type' => 'select',
787
  'description' => __( 'Which direction the slider should move in if in slideshow mode.', 'responsive-lightbox' ),
788
- 'options' => array(
789
  'next' => __( 'Next', 'responsive-lightbox' ),
790
  'prev' => __( 'Previous', 'responsive-lightbox' )
791
- )
792
- ),
793
- 'slideshow_hover' => array(
794
  'title' => __( 'Slideshow Hover', 'responsive-lightbox' ),
795
  'section' => 'responsive_lightbox_basicslider_gallery',
796
  'type' => 'boolean',
797
  'label' => __( 'Whether the slideshow should pause automatically on hover.', 'responsive-lightbox' )
798
- ),
799
- 'slideshow_hover_delay' => array(
800
  'title' => __( 'Slideshow Hover Delay', 'responsive-lightbox' ),
801
  'section' => 'responsive_lightbox_basicslider_gallery',
802
  'type' => 'number',
803
  'min' => 0,
804
  'description' => __( 'The delay (if any) before the slider resumes automatically after hover.', 'responsive-lightbox' ),
805
  'append' => 'ms'
806
- ),
807
- 'slideshow_delay' => array(
808
  'title' => __( 'Slideshow Delay', 'responsive-lightbox' ),
809
  'section' => 'responsive_lightbox_basicslider_gallery',
810
  'type' => 'number',
811
  'min' => 0,
812
  'description' => __( 'The delay (if any) before the slider runs automatically on load.', 'responsive-lightbox' ),
813
  'append' => 'ms'
814
- ),
815
- 'slideshow_pause' => array(
816
  'title' => __( 'Slideshow Pause', 'responsive-lightbox' ),
817
  'section' => 'responsive_lightbox_basicslider_gallery',
818
  'type' => 'number',
819
  'min' => 0,
820
  'description' => __( 'The time a slide lasts.', 'responsive-lightbox' ),
821
  'append' => 'ms'
822
- )
823
- )
824
- ),
825
- 'basicmasonry_gallery' => array(
826
  'option_group' => 'responsive_lightbox_basicmasonry_gallery',
827
  'option_name' => 'responsive_lightbox_basicmasonry_gallery',
828
- 'sections' => array(
829
- 'responsive_lightbox_basicmasonry_gallery' => array(
830
  'title' => __( 'Basic Masonry Gallery Settings', 'responsive-lightbox' )
831
- )
832
- ),
833
  'prefix' => 'rl',
834
- 'fields' => array(
835
- 'screen_size_columns' => array(
836
  'title' => __( 'Screen sizes', 'responsive-lightbox' ),
837
  'section' => 'responsive_lightbox_basicmasonry_gallery',
838
  'type' => 'multiple',
839
  'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
840
- 'fields' => array(
841
- 'columns_lg' => array(
842
  'type' => 'number',
843
  'min' => 0,
844
  'max' => 6,
845
  'default' => 4,
846
  'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
847
- ),
848
- 'columns_md' => array(
849
  'type' => 'number',
850
  'min' => 0,
851
  'max' => 6,
852
  'default' => 3,
853
  'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
854
- ),
855
- 'columns_sm' => array(
856
  'type' => 'number',
857
  'min' => 0,
858
  'max' => 6,
859
  'default' => 2,
860
  'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
861
- ),
862
- 'columns_xs' => array(
863
  'type' => 'number',
864
  'min' => 0,
865
  'max' => 6,
866
  'default' => 2,
867
  'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
868
- )
869
- ),
870
- ),
871
- 'gutter' => array(
872
  'title' => __( 'Gutter', 'responsive-lightbox' ),
873
  'section' => 'responsive_lightbox_basicmasonry_gallery',
874
  'type' => 'number',
875
  'description' => __( 'Horizontal space between gallery items.', 'responsive-lightbox' ),
876
  'append' => 'px'
877
- ),
878
- 'margin' => array(
879
  'title' => __( 'Margin', 'responsive-lightbox' ),
880
  'section' => 'responsive_lightbox_basicmasonry_gallery',
881
  'type' => 'number',
882
  'description' => __( 'Vertical space between gallery items.', 'responsive-lightbox' ),
883
  'append' => 'px'
884
- ),
885
- 'origin_left' => array(
886
  'title' => __( 'Origin Left', 'responsive-lightbox' ),
887
  'section' => 'responsive_lightbox_basicmasonry_gallery',
888
  'type' => 'boolean',
889
  'label' => __( 'Enable left-to-right layouts.', 'responsive-lightbox' ),
890
  'description' => __( 'Controls the horizontal flow of the layout. By default, item elements start positioning at the left. Uncheck it for right-to-left layouts.', 'responsive-lightbox' )
891
- ),
892
- 'origin_top' => array(
893
  'title' => __( 'Origin Top', 'responsive-lightbox' ),
894
  'section' => 'responsive_lightbox_basicmasonry_gallery',
895
  'type' => 'boolean',
896
  'label' => __( 'Enable top-to-bottom layouts.', 'responsive-lightbox' ),
897
  'description' => __( 'Controls the vetical flow of the layout. By default, item elements start positioning at the top. Uncheck it for bottom-up layouts.', 'responsive-lightbox' )
898
- )
899
- )
900
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
901
  );
902
 
903
- $this->tabs = apply_filters( 'rl_settings_tabs', array(
904
- 'settings' => array(
905
- 'name' => __( 'General', 'responsive-lightbox' ),
906
- 'key' => 'responsive_lightbox_settings',
907
- 'submit' => 'save_rl_settings',
908
- 'reset' => 'reset_rl_settings'
909
- ),
910
- 'configuration' => array(
911
- 'name' => __( 'Lightboxes', 'responsive-lightbox' ),
912
- 'key' => 'responsive_lightbox_configuration',
913
- 'submit' => 'save_' . $this->settings['configuration']['prefix'] . '_configuration',
914
- 'reset' => 'reset_' . $this->settings['configuration']['prefix'] . '_configuration',
915
- 'sections' => $scripts,
916
- 'default_section' => $rl->options['settings']['script']
917
- ),
918
- 'basicgrid_gallery' => array(
919
- 'name' => __( 'Basic Grid', 'responsive-lightbox' ),
920
- 'key' => 'responsive_lightbox_basicgrid_gallery',
921
- 'submit' => 'save_rl_basicgrid_gallery',
922
- 'reset' => 'reset_rl_basicgrid_gallery'
923
- ),
924
- 'basicslider_gallery' => array(
925
- 'name' => __( 'Basic Slider', 'responsive-lightbox' ),
926
- 'key' => 'responsive_lightbox_basiclider_gallery',
927
- 'submit' => 'save_rl_basiclider_gallery',
928
- 'reset' => 'reset_rl_basiclider_gallery'
929
- ),
930
- 'basicmasonry_gallery' => array(
931
- 'name' => __( 'Basic Masonry', 'responsive-lightbox' ),
932
- 'key' => 'responsive_lightbox_basicmasonry_gallery',
933
- 'submit' => 'save_rl_basicmasonry_gallery',
934
- 'reset' => 'reset_rl_basicmasonry_gallery'
935
- )
936
- ) );
937
-
938
  $tabs_copy = $this->tabs;
939
  $tab_key = '';
940
- $section_key = '';
941
 
942
  // set current tab and section
943
- if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
944
  global $pagenow;
945
 
 
 
 
946
  // check settings page
947
- if ( $pagenow === 'options.php' || ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $this->tabs + array( 'gallery' => '', 'addons' => '' ) ) ) . ')$/', $_GET['page'], $tabs ) === 1 ) ) {
 
948
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
949
- $section_key = isset( $_REQUEST['section'] ) ? esc_attr( $_REQUEST['section'] ) : ( ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '' );
 
 
 
950
  }
951
  }
952
 
@@ -954,7 +970,8 @@ class Responsive_Lightbox_Settings {
954
  $gallery_types = $rl->gallery_types;
955
 
956
  // remove default gallery
957
- unset( $gallery_types['default'] );
 
958
 
959
  // get available galleries
960
  $gallery_types = apply_filters( 'rl_gallery_types', $gallery_types );
@@ -969,7 +986,7 @@ class Responsive_Lightbox_Settings {
969
 
970
  // backward compatibility, remove from tabs
971
  $gallery_tabs = array_intersect( array_keys( $this->tabs ), array_keys( $gallery_types ) );
972
- $galleries = array();
973
 
974
  if ( ! empty( $gallery_tabs ) ) {
975
  // unset tabs if exist
@@ -983,46 +1000,49 @@ class Responsive_Lightbox_Settings {
983
  $gallery_sections[$key] = $gallery['name'];
984
  }
985
 
986
- if ( $tab_key == 'gallery' )
987
- $section_key = isset( $_REQUEST['section'] ) ? esc_attr( $_REQUEST['section'] ) : ( in_array( $rl->options['settings']['default_gallery'] . '_gallery', array_keys( $gallery_sections ) ) ? $rl->options['settings']['default_gallery'] . '_gallery' : key( $gallery_sections ) );
988
-
989
- $this->tabs['gallery'] = array(
990
- 'name' => __( 'Galleries', 'responsive-lightbox' ),
991
- 'key' => 'responsive_lightbox_' . $section_key,
992
- 'submit' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['submit'] : 'save_' . $section_key . '_configuration',
993
- 'reset' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['reset'] : 'reset_rl_' . $section_key,
994
- 'sections' => $gallery_sections,
995
- 'default_section' => $section_key
996
- );
997
- }
998
-
999
- $this->tabs['builder'] = array(
1000
- 'name' => __( 'Builder', 'responsive-lightbox' ),
1001
- 'key' => 'responsive_lightbox_builder',
1002
- 'submit' => 'save_rl_builder',
1003
- 'reset' => 'reset_rl_builder'
1004
- );
1005
-
1006
- $this->tabs['folders'] = array(
1007
- 'name' => __( 'Folders', 'responsive-lightbox' ),
1008
- 'key' => 'responsive_lightbox_folders',
1009
- 'submit' => 'save_rl_folders',
1010
- 'reset' => 'reset_rl_folders'
1011
- );
1012
 
1013
- $this->tabs['capabilities'] = array(
1014
- 'name' => __( 'Capabilities', 'responsive-lightbox' ),
1015
- 'key' => 'responsive_lightbox_capabilities',
1016
- 'submit' => 'save_rl_capabilities',
1017
- 'reset' => 'reset_rl_capabilities'
1018
- );
 
 
 
1019
 
1020
- $this->tabs['remote_library'] = array(
1021
- 'name' => __( 'Remote Library', 'responsive-lightbox' ),
1022
- 'key' => 'responsive_lightbox_remote_library',
1023
- 'submit' => 'save_rl_remote_library',
1024
- 'reset' => 'reset_rl_remote_library'
1025
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
 
1027
  $this->tabs = apply_filters( 'rl_settings_tabs_extra', $this->tabs );
1028
 
@@ -1030,29 +1050,28 @@ class Responsive_Lightbox_Settings {
1030
  if ( isset( $this->tabs['licenses'] ) ) {
1031
  unset( $this->tabs['licenses'] );
1032
 
1033
- $this->tabs['licenses'] = array(
1034
- 'name' => __( 'Licenses', 'responsive-lightbox' ),
1035
- 'key' => 'responsive_lightbox_licenses',
1036
- 'submit' => 'save_rl_licenses',
1037
- 'reset' => 'reset_rl_licenses'
1038
- );
1039
  }
1040
 
1041
- $this->tabs['addons'] = array(
1042
- 'name' => __( 'Add-ons', 'responsive-lightbox' ),
1043
- 'key' => 'responsive_lightbox_configuration',
1044
- 'callback' => array( $this, 'addons_tab_cb' )
1045
- );
1046
 
1047
- if ( isset( $this->tabs[$tab_key]['sections'][$section_key] ) && empty( $this->tabs[$tab_key]['sections']['responsive_lightbox_' . $tab_key]['title'] ) ) {
1048
  $this->settings[$tab_key]['sections']['responsive_lightbox_' . $tab_key]['title'] = sprintf( __( '%s Settings', 'responsive-lightbox' ), $this->tabs[$tab_key]['sections'][$section_key] );
1049
- }
1050
 
1051
  switch ( ! empty( $section_key ) ? $section_key : $rl->options['settings']['script'] ) {
1052
  case 'swipebox':
1053
  $this->settings['configuration']['prefix'] = 'rl_sb';
1054
- $this->settings['configuration']['fields'] = array(
1055
- 'animation' => array(
1056
  'title' => __( 'Animation type', 'responsive-lightbox' ),
1057
  'section' => 'responsive_lightbox_configuration',
1058
  'type' => 'radio',
@@ -1060,68 +1079,68 @@ class Responsive_Lightbox_Settings {
1060
  'description' => __( 'Select a method of applying a lightbox effect.', 'responsive-lightbox' ),
1061
  'options' => $this->scripts['swipebox']['animations'],
1062
  'parent' => 'swipebox'
1063
- ),
1064
- 'force_png_icons' => array(
1065
  'title' => __( 'Force PNG icons', 'responsive-lightbox' ),
1066
  'section' => 'responsive_lightbox_configuration',
1067
  'type' => 'boolean',
1068
  'label' => __( 'Enable this if you\'re having problems with navigation icons not visible on some devices.', 'responsive-lightbox' ),
1069
  'parent' => 'swipebox'
1070
- ),
1071
- 'hide_close_mobile' => array(
1072
  'title' => __( 'Hide close on mobile', 'responsive-lightbox' ),
1073
  'section' => 'responsive_lightbox_configuration',
1074
  'type' => 'boolean',
1075
  'label' => __( 'Hide the close button on mobile devices.', 'responsive-lightbox' ),
1076
  'parent' => 'swipebox'
1077
- ),
1078
- 'remove_bars_mobile' => array(
1079
  'title' => __( 'Remove bars on mobile', 'responsive-lightbox' ),
1080
  'section' => 'responsive_lightbox_configuration',
1081
  'type' => 'boolean',
1082
  'label' => __( 'Hide the top and bottom bars on mobile devices.', 'responsive-lightbox' ),
1083
  'parent' => 'swipebox'
1084
- ),
1085
- 'hide_bars' => array(
1086
  'title' => __( 'Top and bottom bars', 'responsive-lightbox' ),
1087
  'section' => 'responsive_lightbox_configuration',
1088
  'type' => 'multiple',
1089
- 'fields' => array(
1090
- 'hide_bars' => array(
1091
  'type' => 'boolean',
1092
  'label' => __( 'Hide top and bottom bars after a period of time.', 'responsive-lightbox' ),
1093
  'parent' => 'swipebox'
1094
- ),
1095
- 'hide_bars_delay' => array(
1096
  'type' => 'number',
1097
  'description' => __( 'Enter the time after which the top and bottom bars will be hidden (when hiding is enabled).', 'responsive-lightbox' ),
1098
  'append' => 'ms',
1099
  'parent' => 'swipebox'
1100
- )
1101
- )
1102
- ),
1103
- 'video_max_width' => array(
1104
  'title' => __( 'Video max width', 'responsive-lightbox' ),
1105
  'section' => 'responsive_lightbox_configuration',
1106
  'type' => 'number',
1107
  'description' => __( 'Enter the max video width in a lightbox.', 'responsive-lightbox' ),
1108
  'append' => 'px',
1109
  'parent' => 'swipebox'
1110
- ),
1111
- 'loop_at_end' => array(
1112
  'title' => __( 'Loop at end', 'responsive-lightbox' ),
1113
  'section' => 'responsive_lightbox_configuration',
1114
  'type' => 'boolean',
1115
  'label' => __( 'True will return to the first image after the last image is reached.', 'responsive-lightbox' ),
1116
  'parent' => 'swipebox'
1117
- ),
1118
- );
1119
  break;
1120
 
1121
  case 'prettyphoto':
1122
  $this->settings['configuration']['prefix'] = 'rl_pp';
1123
- $this->settings['configuration']['fields'] = array(
1124
- 'animation_speed' => array(
1125
  'title' => __( 'Animation speed', 'responsive-lightbox' ),
1126
  'section' => 'responsive_lightbox_configuration',
1127
  'type' => 'radio',
@@ -1129,33 +1148,33 @@ class Responsive_Lightbox_Settings {
1129
  'description' => __( 'Select animation speed for lightbox effect.', 'responsive-lightbox' ),
1130
  'options' => $this->scripts['prettyphoto']['animation_speeds'],
1131
  'parent' => 'prettyphoto'
1132
- ),
1133
- 'slideshow' => array(
1134
  'title' => __( 'Slideshow', 'responsive-lightbox' ),
1135
  'section' => 'responsive_lightbox_configuration',
1136
  'type' => 'multiple',
1137
- 'fields' => array(
1138
- 'slideshow' => array(
1139
  'type' => 'boolean',
1140
  'label' => __( 'Display images as slideshow', 'responsive-lightbox' ),
1141
  'parent' => 'prettyphoto'
1142
- ),
1143
- 'slideshow_delay' => array(
1144
  'type' => 'number',
1145
  'description' => __( 'Enter time (in miliseconds).', 'responsive-lightbox' ),
1146
  'append' => 'ms',
1147
  'parent' => 'prettyphoto'
1148
- )
1149
- )
1150
- ),
1151
- 'slideshow_autoplay' => array(
1152
  'title' => __( 'Slideshow autoplay', 'responsive-lightbox' ),
1153
  'section' => 'responsive_lightbox_configuration',
1154
  'type' => 'boolean',
1155
  'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
1156
  'parent' => 'prettyphoto'
1157
- ),
1158
- 'opacity' => array(
1159
  'title' => __( 'Opacity', 'responsive-lightbox' ),
1160
  'section' => 'responsive_lightbox_configuration',
1161
  'type' => 'range',
@@ -1163,206 +1182,206 @@ class Responsive_Lightbox_Settings {
1163
  'min' => 0,
1164
  'max' => 100,
1165
  'parent' => 'prettyphoto'
1166
- ),
1167
- 'show_title' => array(
1168
  'title' => __( 'Show title', 'responsive-lightbox' ),
1169
  'section' => 'responsive_lightbox_configuration',
1170
  'type' => 'boolean',
1171
  'label' => __( 'Display image title.', 'responsive-lightbox' ),
1172
  'parent' => 'prettyphoto'
1173
- ),
1174
- 'allow_resize' => array(
1175
  'title' => __( 'Allow resize big images', 'responsive-lightbox' ),
1176
  'section' => 'responsive_lightbox_configuration',
1177
  'type' => 'boolean',
1178
  'label' => __( 'Resize the photos bigger than viewport.', 'responsive-lightbox' ),
1179
  'parent' => 'prettyphoto'
1180
- ),
1181
- 'allow_expand' => array(
1182
  'title' => __( 'Allow expand', 'responsive-lightbox' ),
1183
  'section' => 'responsive_lightbox_configuration',
1184
  'type' => 'boolean',
1185
  'label' => __( 'Allow expanding images.', 'responsive-lightbox' ),
1186
  'parent' => 'prettyphoto'
1187
- ),
1188
- 'width' => array(
1189
  'title' => __( 'Video width', 'responsive-lightbox' ),
1190
  'section' => 'responsive_lightbox_configuration',
1191
  'type' => 'number',
1192
  'append' => 'px',
1193
  'parent' => 'prettyphoto'
1194
- ),
1195
- 'height' => array(
1196
  'title' => __( 'Video height', 'responsive-lightbox' ),
1197
  'section' => 'responsive_lightbox_configuration',
1198
  'type' => 'number',
1199
  'append' => 'px',
1200
  'parent' => 'prettyphoto'
1201
- ),
1202
- 'theme' => array(
1203
  'title' => __( 'Theme', 'responsive-lightbox' ),
1204
  'section' => 'responsive_lightbox_configuration',
1205
  'type' => 'radio',
1206
  'description' => __( 'Select the theme for lightbox effect.', 'responsive-lightbox' ),
1207
  'options' => $this->scripts['prettyphoto']['themes'],
1208
  'parent' => 'prettyphoto'
1209
- ),
1210
- 'horizontal_padding' => array(
1211
  'title' => __( 'Horizontal padding', 'responsive-lightbox' ),
1212
  'section' => 'responsive_lightbox_configuration',
1213
  'type' => 'number',
1214
  'append' => 'px',
1215
  'parent' => 'prettyphoto'
1216
- ),
1217
- 'hide_flash' => array(
1218
  'title' => __( 'Hide Flash', 'responsive-lightbox' ),
1219
  'section' => 'responsive_lightbox_configuration',
1220
  'type' => 'boolean',
1221
  'label' => __( 'Hide all the flash objects on a page. Enable this if flash appears over prettyPhoto.', 'responsive-lightbox' ),
1222
  'parent' => 'prettyphoto'
1223
- ),
1224
- 'wmode' => array(
1225
  'title' => __( 'Flash Window Mode (wmode)', 'responsive-lightbox' ),
1226
  'section' => 'responsive_lightbox_configuration',
1227
  'type' => 'radio',
1228
  'description' => __( 'Select flash window mode.', 'responsive-lightbox' ),
1229
  'options' => $this->scripts['prettyphoto']['wmodes'],
1230
  'parent' => 'prettyphoto'
1231
- ),
1232
- 'video_autoplay' => array(
1233
  'title' => __( 'Video autoplay', 'responsive-lightbox' ),
1234
  'section' => 'responsive_lightbox_configuration',
1235
  'type' => 'boolean',
1236
  'label' => __( 'Automatically start videos.', 'responsive-lightbox' ),
1237
  'parent' => 'prettyphoto'
1238
- ),
1239
- 'modal' => array(
1240
  'title' => __( 'Modal', 'responsive-lightbox' ),
1241
  'section' => 'responsive_lightbox_configuration',
1242
  'type' => 'boolean',
1243
  'label' => __( 'If set to true, only the close button will close the window.', 'responsive-lightbox' ),
1244
  'parent' => 'prettyphoto'
1245
- ),
1246
- 'deeplinking' => array(
1247
  'title' => __( 'Deeplinking', 'responsive-lightbox' ),
1248
  'section' => 'responsive_lightbox_configuration',
1249
  'type' => 'boolean',
1250
  'label' => __( 'Allow prettyPhoto to update the url to enable deeplinking.', 'responsive-lightbox' ),
1251
  'parent' => 'prettyphoto'
1252
- ),
1253
- 'overlay_gallery' => array(
1254
  'title' => __( 'Overlay gallery', 'responsive-lightbox' ),
1255
  'section' => 'responsive_lightbox_configuration',
1256
  'type' => 'boolean',
1257
  'label' => __( 'If enabled, a gallery will overlay the fullscreen image on mouse over.', 'responsive-lightbox' ),
1258
  'parent' => 'prettyphoto'
1259
- ),
1260
- 'keyboard_shortcuts' => array(
1261
  'title' => __( 'Keyboard shortcuts', 'responsive-lightbox' ),
1262
  'section' => 'responsive_lightbox_configuration',
1263
  'type' => 'boolean',
1264
  'label' => __( 'Set to false if you open forms inside prettyPhoto.', 'responsive-lightbox' ),
1265
  'parent' => 'prettyphoto'
1266
- ),
1267
- 'social' => array(
1268
  'title' => __( 'Social (Twitter, Facebook)', 'responsive-lightbox' ),
1269
  'section' => 'responsive_lightbox_configuration',
1270
  'type' => 'boolean',
1271
  'label' => __( 'Display links to Facebook and Twitter.', 'responsive-lightbox' ),
1272
  'parent' => 'prettyphoto'
1273
- ),
1274
- );
1275
  break;
1276
 
1277
  case 'fancybox':
1278
  $this->settings['configuration']['prefix'] = 'rl_fb';
1279
- $this->settings['configuration']['fields'] = array(
1280
- 'modal' => array(
1281
  'title' => __( 'Modal', 'responsive-lightbox' ),
1282
  'section' => 'responsive_lightbox_configuration',
1283
  'type' => 'boolean',
1284
  'label' => __( 'When true, "overlayShow" is set to true and "hideOnOverlayClick", "hideOnContentClick", "enableEscapeButton", "showCloseButton" are set to false.', 'responsive-lightbox' ),
1285
  'parent' => 'fancybox'
1286
- ),
1287
- 'show_overlay' => array(
1288
  'title' => __( 'Show overlay', 'responsive-lightbox' ),
1289
  'section' => 'responsive_lightbox_configuration',
1290
  'type' => 'boolean',
1291
  'label' => __( 'Toggle overlay.', 'responsive-lightbox' ),
1292
  'parent' => 'fancybox'
1293
- ),
1294
- 'show_close_button' => array(
1295
  'title' => __( 'Show close button', 'responsive-lightbox' ),
1296
  'section' => 'responsive_lightbox_configuration',
1297
  'type' => 'boolean',
1298
  'label' => __( 'Toggle close button.', 'responsive-lightbox' ),
1299
  'parent' => 'fancybox'
1300
- ),
1301
- 'enable_escape_button' => array(
1302
  'title' => __( 'Enable escape button', 'responsive-lightbox' ),
1303
  'section' => 'responsive_lightbox_configuration',
1304
  'type' => 'boolean',
1305
  'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
1306
  'parent' => 'fancybox'
1307
- ),
1308
- 'hide_on_overlay_click' => array(
1309
  'title' => __( 'Hide on overlay click', 'responsive-lightbox' ),
1310
  'section' => 'responsive_lightbox_configuration',
1311
  'type' => 'boolean',
1312
  'label' => __( 'Toggle if clicking the overlay should close FancyBox.', 'responsive-lightbox' ),
1313
  'parent' => 'fancybox'
1314
- ),
1315
- 'hide_on_content_click' => array(
1316
  'title' => __( 'Hide on content click', 'responsive-lightbox' ),
1317
  'section' => 'responsive_lightbox_configuration',
1318
  'type' => 'boolean',
1319
  'label' => __( 'Toggle if clicking the content should close FancyBox.', 'responsive-lightbox' ),
1320
  'parent' => 'fancybox'
1321
- ),
1322
- 'cyclic' => array(
1323
  'title' => __( 'Cyclic', 'responsive-lightbox' ),
1324
  'section' => 'responsive_lightbox_configuration',
1325
  'type' => 'boolean',
1326
  'label' => __( 'When true, galleries will be cyclic, allowing you to keep pressing next/back.', 'responsive-lightbox' ),
1327
  'parent' => 'fancybox'
1328
- ),
1329
- 'show_nav_arrows' => array(
1330
  'title' => __( 'Show nav arrows', 'responsive-lightbox' ),
1331
  'section' => 'responsive_lightbox_configuration',
1332
  'type' => 'boolean',
1333
  'label' => __( 'Toggle navigation arrows.', 'responsive-lightbox' ),
1334
  'parent' => 'fancybox'
1335
- ),
1336
- 'auto_scale' => array(
1337
  'title' => __( 'Auto scale', 'responsive-lightbox' ),
1338
  'section' => 'responsive_lightbox_configuration',
1339
  'type' => 'boolean',
1340
  'label' => __( 'If true, FancyBox is scaled to fit in viewport.', 'responsive-lightbox' ),
1341
  'parent' => 'fancybox'
1342
- ),
1343
- 'scrolling' => array(
1344
  'title' => __( 'Scrolling (in/out)', 'responsive-lightbox' ),
1345
  'section' => 'responsive_lightbox_configuration',
1346
  'type' => 'radio',
1347
  'description' => __( 'Set the overflow CSS property to create or hide scrollbars.', 'responsive-lightbox' ),
1348
  'options' => $this->scripts['fancybox']['scrollings'],
1349
  'parent' => 'fancybox'
1350
- ),
1351
- 'center_on_scroll' => array(
1352
  'title' => __( 'Center on scroll', 'responsive-lightbox' ),
1353
  'section' => 'responsive_lightbox_configuration',
1354
  'type' => 'boolean',
1355
  'label' => __( 'When true, FancyBox is centered while scrolling page.', 'responsive-lightbox' ),
1356
  'parent' => 'fancybox'
1357
- ),
1358
- 'opacity' => array(
1359
  'title' => __( 'Opacity', 'responsive-lightbox' ),
1360
  'section' => 'responsive_lightbox_configuration',
1361
  'type' => 'boolean',
1362
  'label' => __( 'When true, transparency of content is changed for elastic transitions.', 'responsive-lightbox' ),
1363
  'parent' => 'fancybox'
1364
- ),
1365
- 'overlay_opacity' => array(
1366
  'title' => __( 'Overlay opacity', 'responsive-lightbox' ),
1367
  'section' => 'responsive_lightbox_configuration',
1368
  'type' => 'range',
@@ -1370,429 +1389,429 @@ class Responsive_Lightbox_Settings {
1370
  'min' => 0,
1371
  'max' => 100,
1372
  'parent' => 'fancybox'
1373
- ),
1374
- 'overlay_color' => array(
1375
  'title' => __( 'Overlay color', 'responsive-lightbox' ),
1376
  'section' => 'responsive_lightbox_configuration',
1377
  'type' => 'color_picker',
1378
  'label' => __( 'Color of the overlay.', 'responsive-lightbox' ),
1379
  'parent' => 'fancybox'
1380
- ),
1381
- 'title_show' => array(
1382
  'title' => __( 'Title show', 'responsive-lightbox' ),
1383
  'section' => 'responsive_lightbox_configuration',
1384
  'type' => 'boolean',
1385
  'label' => __( 'Toggle title.', 'responsive-lightbox' ),
1386
  'parent' => 'fancybox'
1387
- ),
1388
- 'title_position' => array(
1389
  'title' => __( 'Title position', 'responsive-lightbox' ),
1390
  'section' => 'responsive_lightbox_configuration',
1391
  'type' => 'radio',
1392
  'description' => __( 'The position of title.', 'responsive-lightbox' ),
1393
  'options' => $this->scripts['fancybox']['positions'],
1394
  'parent' => 'fancybox'
1395
- ),
1396
- 'transitions' => array(
1397
  'title' => __( 'Transition (in/out)', 'responsive-lightbox' ),
1398
  'section' => 'responsive_lightbox_configuration',
1399
  'type' => 'radio',
1400
  'description' => __( 'The transition type.', 'responsive-lightbox' ),
1401
  'options' => $this->scripts['fancybox']['transitions'],
1402
  'parent' => 'fancybox'
1403
- ),
1404
- 'easings' => array(
1405
  'title' => __( 'Easings (in/out)', 'responsive-lightbox' ),
1406
  'section' => 'responsive_lightbox_configuration',
1407
  'type' => 'radio',
1408
  'description' => __( 'Easing used for elastic animations.', 'responsive-lightbox' ),
1409
  'options' => $this->scripts['fancybox']['easings'],
1410
  'parent' => 'fancybox'
1411
- ),
1412
- 'speeds' => array(
1413
  'title' => __( 'Speed (in/out)', 'responsive-lightbox' ),
1414
  'section' => 'responsive_lightbox_configuration',
1415
  'type' => 'number',
1416
  'description' => __( 'Speed of the fade and elastic transitions, in milliseconds.', 'responsive-lightbox' ),
1417
  'append' => 'ms',
1418
  'parent' => 'fancybox'
1419
- ),
1420
- 'change_speed' => array(
1421
  'title' => __( 'Change speed', 'responsive-lightbox' ),
1422
  'section' => 'responsive_lightbox_configuration',
1423
  'type' => 'number',
1424
  'description' => __( 'Speed of resizing when changing gallery items, in milliseconds.', 'responsive-lightbox' ),
1425
  'append' => 'ms',
1426
  'parent' => 'fancybox'
1427
- ),
1428
- 'change_fade' => array(
1429
  'title' => __( 'Change fade', 'responsive-lightbox' ),
1430
  'section' => 'responsive_lightbox_configuration',
1431
  'type' => 'number',
1432
  'description' => __( 'Speed of the content fading while changing gallery items.', 'responsive-lightbox' ),
1433
  'append' => 'ms',
1434
  'parent' => 'fancybox'
1435
- ),
1436
- 'padding' => array(
1437
  'title' => __( 'Padding', 'responsive-lightbox' ),
1438
  'section' => 'responsive_lightbox_configuration',
1439
  'type' => 'number',
1440
  'description' => __( 'Space between FancyBox wrapper and content.', 'responsive-lightbox' ),
1441
  'append' => 'px',
1442
  'parent' => 'fancybox'
1443
- ),
1444
- 'margin' => array(
1445
  'title' => __( 'Margin', 'responsive-lightbox' ),
1446
  'section' => 'responsive_lightbox_configuration',
1447
  'type' => 'number',
1448
  'description' => __( 'Space between viewport and FancyBox wrapper.', 'responsive-lightbox' ),
1449
  'append' => 'px',
1450
  'parent' => 'fancybox'
1451
- ),
1452
- 'video_width' => array(
1453
  'title' => __( 'Video width', 'responsive-lightbox' ),
1454
  'section' => 'responsive_lightbox_configuration',
1455
  'type' => 'number',
1456
  'description' => __( 'Width of the video.', 'responsive-lightbox' ),
1457
  'append' => 'px',
1458
  'parent' => 'fancybox'
1459
- ),
1460
- 'video_height' => array(
1461
  'title' => __( 'Video height', 'responsive-lightbox' ),
1462
  'section' => 'responsive_lightbox_configuration',
1463
  'type' => 'number',
1464
  'description' => __( 'Height of the video.', 'responsive-lightbox' ),
1465
  'append' => 'px',
1466
  'parent' => 'fancybox'
1467
- ),
1468
- );
1469
  break;
1470
 
1471
  case 'nivo':
1472
  $this->settings['configuration']['prefix'] = 'rl_nv';
1473
- $this->settings['configuration']['fields'] = array(
1474
- 'effect' => array(
1475
  'title' => __( 'Effect', 'responsive-lightbox' ),
1476
  'section' => 'responsive_lightbox_configuration',
1477
  'type' => 'radio',
1478
  'description' => __( 'The effect to use when showing the lightbox.', 'responsive-lightbox' ),
1479
  'options' => $this->scripts['nivo']['effects'],
1480
  'parent' => 'nivo'
1481
- ),
1482
- 'keyboard_nav' => array(
1483
  'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
1484
  'section' => 'responsive_lightbox_configuration',
1485
  'type' => 'boolean',
1486
  'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
1487
  'parent' => 'nivo'
1488
- ),
1489
- 'click_overlay_to_close' => array(
1490
  'title' => __( 'Click overlay to close', 'responsive-lightbox' ),
1491
  'section' => 'responsive_lightbox_configuration',
1492
  'type' => 'boolean',
1493
  'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
1494
  'parent' => 'nivo'
1495
- ),
1496
- 'error_message' => array(
1497
  'title' => __( 'Error message', 'responsive-lightbox' ),
1498
  'section' => 'responsive_lightbox_configuration',
1499
  'type' => 'text',
1500
  'class' => 'large-text',
1501
  'label' => __( 'Error message if the content cannot be loaded.', 'responsive-lightbox' ),
1502
  'parent' => 'nivo'
1503
- ),
1504
- );
1505
  break;
1506
 
1507
  case 'imagelightbox':
1508
  $this->settings['configuration']['prefix'] = 'rl_il';
1509
- $this->settings['configuration']['fields'] = array(
1510
- 'animation_speed' => array(
1511
  'title' => __( 'Animation speed', 'responsive-lightbox' ),
1512
  'section' => 'responsive_lightbox_configuration',
1513
  'type' => 'number',
1514
  'description' => __( 'Animation speed.', 'responsive-lightbox' ),
1515
  'append' => 'ms',
1516
  'parent' => 'imagelightbox'
1517
- ),
1518
- 'preload_next' => array(
1519
  'title' => __( 'Preload next image', 'responsive-lightbox' ),
1520
  'section' => 'responsive_lightbox_configuration',
1521
  'type' => 'boolean',
1522
  'label' => __( 'Silently preload the next image.', 'responsive-lightbox' ),
1523
  'parent' => 'imagelightbox'
1524
- ),
1525
- 'enable_keyboard' => array(
1526
  'title' => __( 'Enable keyboard keys', 'responsive-lightbox' ),
1527
  'section' => 'responsive_lightbox_configuration',
1528
  'type' => 'boolean',
1529
  'label' => __( 'Enable keyboard shortcuts (arrows Left/Right and Esc).', 'responsive-lightbox' ),
1530
  'parent' => 'imagelightbox'
1531
- ),
1532
- 'quit_on_end' => array(
1533
  'title' => __( 'Quit after last image', 'responsive-lightbox' ),
1534
  'section' => 'responsive_lightbox_configuration',
1535
  'type' => 'boolean',
1536
  'label' => __( 'Quit after viewing the last image.', 'responsive-lightbox' ),
1537
  'parent' => 'imagelightbox'
1538
- ),
1539
- 'quit_on_image_click' => array(
1540
  'title' => __( 'Quit on image click', 'responsive-lightbox' ),
1541
  'section' => 'responsive_lightbox_configuration',
1542
  'type' => 'boolean',
1543
  'label' => __( 'Quit when the viewed image is clicked.', 'responsive-lightbox' ),
1544
  'parent' => 'imagelightbox'
1545
- ),
1546
- 'quit_on_document_click' => array(
1547
  'title' => __( 'Quit on anything click', 'responsive-lightbox' ),
1548
  'section' => 'responsive_lightbox_configuration',
1549
  'type' => 'boolean',
1550
  'label' => __( 'Quit when anything but the viewed image is clicked.', 'responsive-lightbox' ),
1551
  'parent' => 'imagelightbox'
1552
- ),
1553
- );
1554
  break;
1555
 
1556
  case 'tosrus':
1557
  $this->settings['configuration']['prefix'] = 'rl_tr';
1558
- $this->settings['configuration']['fields'] = array(
1559
- 'effect' => array(
1560
  'title' => __( 'Transition effect', 'responsive-lightbox' ),
1561
  'section' => 'responsive_lightbox_configuration',
1562
  'type' => 'radio',
1563
  'description' => __( 'What effect to use for the transition.', 'responsive-lightbox' ),
1564
- 'options' => array(
1565
  'slide' => __( 'slide', 'responsive-lightbox' ),
1566
  'fade' => __( 'fade', 'responsive-lightbox' )
1567
- ),
1568
  'parent' => 'tosrus'
1569
- ),
1570
- 'infinite' => array(
1571
  'title' => __( 'Infinite loop', 'responsive-lightbox' ),
1572
  'section' => 'responsive_lightbox_configuration',
1573
  'type' => 'boolean',
1574
  'label' => __( 'Whether or not to slide back to the first slide when the last has been reached.', 'responsive-lightbox' ),
1575
  'parent' => 'tosrus'
1576
- ),
1577
- 'keys' => array(
1578
  'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
1579
  'section' => 'responsive_lightbox_configuration',
1580
  'type' => 'boolean',
1581
  'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
1582
  'parent' => 'tosrus'
1583
- ),
1584
- 'autoplay' => array(
1585
  'title' => __( 'Autoplay', 'responsive-lightbox' ),
1586
  'section' => 'responsive_lightbox_configuration',
1587
  'type' => 'multiple',
1588
- 'fields' => array(
1589
- 'autoplay' => array(
1590
  'type' => 'boolean',
1591
  'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
1592
  'parent' => 'tosrus'
1593
- ),
1594
- 'timeout' => array(
1595
  'type' => 'number',
1596
  'description' => __( 'The timeout between sliding to the next slide in milliseconds.', 'responsive-lightbox' ),
1597
  'append' => 'ms',
1598
  'parent' => 'tosrus'
1599
- )
1600
- )
1601
- ),
1602
- 'pause_on_hover' => array(
1603
  'title' => __( 'Pause on hover', 'responsive-lightbox' ),
1604
  'section' => 'responsive_lightbox_configuration',
1605
  'type' => 'boolean',
1606
  'label' => __( 'Whether or not to pause on hover.', 'responsive-lightbox' ),
1607
  'parent' => 'tosrus'
1608
- ),
1609
- 'pagination' => array(
1610
  'title' => __( 'Pagination', 'responsive-lightbox' ),
1611
  'section' => 'responsive_lightbox_configuration',
1612
  'type' => 'multiple',
1613
- 'fields' => array(
1614
- 'pagination' => array(
1615
  'type' => 'boolean',
1616
  'label' => __( 'Whether or not to add a pagination.', 'responsive-lightbox' ),
1617
  'parent' => 'tosrus'
1618
- ),
1619
- 'pagination_type' => array(
1620
  'type' => 'radio',
1621
  'description' => __( 'What type of pagination to use.', 'responsive-lightbox' ),
1622
- 'options' => array(
1623
  'bullets' => __( 'Bullets', 'responsive-lightbox' ),
1624
  'thumbnails' => __( 'Thumbnails', 'responsive-lightbox' )
1625
- ),
1626
  'parent' => 'tosrus'
1627
- )
1628
- )
1629
- ),
1630
- 'close_on_click' => array(
1631
  'title' => __( 'Overlay close', 'responsive-lightbox' ),
1632
  'section' => 'responsive_lightbox_configuration',
1633
  'type' => 'boolean',
1634
  'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
1635
  'parent' => 'tosrus'
1636
- )
1637
- );
1638
  break;
1639
 
1640
  case 'featherlight':
1641
  $this->settings['configuration']['prefix'] = 'rl_fl';
1642
- $this->settings['configuration']['fields'] = array(
1643
- 'open_speed' => array(
1644
  'title' => __( 'Opening speed', 'responsive-lightbox' ),
1645
  'section' => 'responsive_lightbox_configuration',
1646
  'type' => 'number',
1647
  'description' => __( 'Duration of opening animation.', 'responsive-lightbox' ),
1648
  'append' => 'ms',
1649
  'parent' => 'featherlight'
1650
- ),
1651
- 'close_speed' => array(
1652
  'title' => __( 'Closing speed', 'responsive-lightbox' ),
1653
  'section' => 'responsive_lightbox_configuration',
1654
  'type' => 'number',
1655
  'description' => __( 'Duration of closing animation.', 'responsive-lightbox' ),
1656
  'append' => 'ms',
1657
  'parent' => 'featherlight'
1658
- ),
1659
- 'close_on_click' => array(
1660
  'title' => __( 'Close on click', 'responsive-lightbox' ),
1661
  'section' => 'responsive_lightbox_configuration',
1662
  'type' => 'radio',
1663
  'label' => __( 'Select how to close lightbox.', 'responsive-lightbox' ),
1664
- 'options' => array(
1665
  'background' => __( 'background', 'responsive-lightbox' ),
1666
  'anywhere' => __( 'anywhere', 'responsive-lightbox' ),
1667
  'false' => __( 'false', 'responsive-lightbox' )
1668
- ),
1669
  'parent' => 'featherlight'
1670
- ),
1671
- 'close_on_esc' => array(
1672
  'title' => __( 'Close on Esc', 'responsive-lightbox' ),
1673
  'section' => 'responsive_lightbox_configuration',
1674
  'type' => 'boolean',
1675
  'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
1676
  'parent' => 'featherlight'
1677
- ),
1678
- 'gallery_fade_in' => array(
1679
  'title' => __( 'Gallery fade in', 'responsive-lightbox' ),
1680
  'section' => 'responsive_lightbox_configuration',
1681
  'type' => 'number',
1682
  'description' => __( 'Animation speed when image is loaded.', 'responsive-lightbox' ),
1683
  'append' => 'ms',
1684
  'parent' => 'featherlight'
1685
- ),
1686
- 'gallery_fade_out' => array(
1687
  'title' => __( 'Gallery fade out', 'responsive-lightbox' ),
1688
  'section' => 'responsive_lightbox_configuration',
1689
  'type' => 'number',
1690
  'description' => __( 'Animation speed before image is loaded.', 'responsive-lightbox' ),
1691
  'append' => 'ms',
1692
  'parent' => 'featherlight'
1693
- )
1694
- );
1695
  break;
1696
 
1697
  case 'magnific':
1698
  $this->settings['configuration']['prefix'] = 'rl_mp';
1699
- $this->settings['configuration']['fields'] = array(
1700
- 'disable_on' => array(
1701
  'title' => __( 'Disable on', 'responsive-lightbox' ),
1702
  'section' => 'responsive_lightbox_configuration',
1703
  'type' => 'number',
1704
  'description' => __( 'If window width is less than the number in this option lightbox will not be opened and the default behavior of the element will be triggered. Set to 0 to disable behavior.', 'responsive-lightbox' ),
1705
  'append' => 'px',
1706
  'parent' => 'magnific'
1707
- ),
1708
- 'mid_click' => array(
1709
  'title' => __( 'Middle click', 'responsive-lightbox' ),
1710
  'section' => 'responsive_lightbox_configuration',
1711
  'type' => 'boolean',
1712
  'label' => __( 'If option enabled, lightbox is opened if the user clicked on the middle mouse button, or click with Command/Ctrl key.', 'responsive-lightbox' ),
1713
  'parent' => 'magnific'
1714
- ),
1715
- 'preloader' => array(
1716
  'title' => __( 'Preloader', 'responsive-lightbox' ),
1717
  'section' => 'responsive_lightbox_configuration',
1718
  'type' => 'boolean',
1719
  'label' => __( 'If option enabled, it\'s always present in DOM only text inside of it changes.', 'responsive-lightbox' ),
1720
  'parent' => 'magnific'
1721
- ),
1722
- 'close_on_content_click' => array(
1723
  'title' => __( 'Close on content click', 'responsive-lightbox' ),
1724
  'section' => 'responsive_lightbox_configuration',
1725
  'type' => 'boolean',
1726
  'label' => __( 'Close popup when user clicks on content of it. It\'s recommended to enable this option when you have only image in popup.', 'responsive-lightbox' ),
1727
  'parent' => 'magnific'
1728
- ),
1729
- 'close_on_background_click' => array(
1730
  'title' => __( 'Close on background click', 'responsive-lightbox' ),
1731
  'section' => 'responsive_lightbox_configuration',
1732
  'type' => 'boolean',
1733
  'label' => __( 'Close the popup when user clicks on the dark overlay.', 'responsive-lightbox' ),
1734
  'parent' => 'magnific'
1735
- ),
1736
- 'close_button_inside' => array(
1737
  'title' => __( 'Close button inside', 'responsive-lightbox' ),
1738
  'section' => 'responsive_lightbox_configuration',
1739
  'type' => 'boolean',
1740
  'label' => __( 'If enabled, Magnific Popup will put close button inside content of popup.', 'responsive-lightbox' ),
1741
  'parent' => 'magnific'
1742
- ),
1743
- 'show_close_button' => array(
1744
  'title' => __( 'Show close button', 'responsive-lightbox' ),
1745
  'section' => 'responsive_lightbox_configuration',
1746
  'type' => 'boolean',
1747
  'label' => __( 'Controls whether the close button will be displayed or not.', 'responsive-lightbox' ),
1748
  'parent' => 'magnific'
1749
- ),
1750
- 'enable_escape_key' => array(
1751
  'title' => __( 'Enable escape key', 'responsive-lightbox' ),
1752
  'section' => 'responsive_lightbox_configuration',
1753
  'type' => 'boolean',
1754
  'label' => __( 'Controls whether pressing the escape key will dismiss the active popup or not.', 'responsive-lightbox' ),
1755
  'parent' => 'magnific'
1756
- ),
1757
- 'align_top' => array(
1758
  'title' => __( 'Align top', 'responsive-lightbox' ),
1759
  'section' => 'responsive_lightbox_configuration',
1760
  'type' => 'boolean',
1761
  'label' => __( 'If set to true popup is aligned to top instead of to center.', 'responsive-lightbox' ),
1762
  'parent' => 'magnific'
1763
- ),
1764
- 'fixed_content_position' => array(
1765
  'title' => __( 'Content position type', 'responsive-lightbox' ),
1766
  'section' => 'responsive_lightbox_configuration',
1767
  'type' => 'select',
1768
  'description' => __( 'Popup content position. If set to "auto" popup will automatically disable this option when browser doesn\'t support fixed position properly.', 'responsive-lightbox' ),
1769
- 'options' => array(
1770
  'auto' => __( 'Auto', 'responsive-lightbox' ),
1771
  'true' => __( 'Fixed', 'responsive-lightbox' ),
1772
  'false' => __( 'Absolute', 'responsive-lightbox' )
1773
- ),
1774
  'parent' => 'magnific'
1775
- ),
1776
- 'fixed_background_position' => array(
1777
  'title' => __( 'Fixed background position', 'responsive-lightbox' ),
1778
  'section' => 'responsive_lightbox_configuration',
1779
  'type' => 'select',
1780
  'description' => __( 'Dark transluscent overlay content position.', 'responsive-lightbox' ),
1781
- 'options' => array(
1782
  'auto' => __( 'Auto', 'responsive-lightbox' ),
1783
  'true' => __( 'Fixed', 'responsive-lightbox' ),
1784
  'false' => __( 'Absolute', 'responsive-lightbox' )
1785
- ),
1786
  'parent' => 'magnific'
1787
- ),
1788
- 'auto_focus_last' => array(
1789
  'title' => __( 'Auto focus last', 'responsive-lightbox' ),
1790
  'section' => 'responsive_lightbox_configuration',
1791
  'type' => 'boolean',
1792
  'label' => __( 'If set to true last focused element before popup showup will be focused after popup close.', 'responsive-lightbox' ),
1793
  'parent' => 'magnific'
1794
- )
1795
- );
1796
  break;
1797
 
1798
  default:
@@ -1811,7 +1830,7 @@ class Responsive_Lightbox_Settings {
1811
  * @return void
1812
  */
1813
  public function remote_library_providers_description() {
1814
- echo '<p class="description">' . sprintf( __( 'Below you\'ll find a list of available remote media libraries. If you\'re looking for Pixabay, Pexels, Instagram and other integrations please check the <a href="%s" target="_blank">Remote Library Pro addon</a>.', 'responsive-lightbox' ), 'https://dfactory.eu/products/remote-library-pro/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=addon' ) . '</p>';
1815
  }
1816
 
1817
  /**
@@ -1826,7 +1845,7 @@ class Responsive_Lightbox_Settings {
1826
  add_menu_page( __( 'General', 'responsive-lightbox' ), __( 'Lightbox', 'responsive-lightbox' ), $capability, 'responsive-lightbox-settings', '', 'dashicons-format-image', '57.1' );
1827
 
1828
  foreach ( $this->tabs as $key => $options ) {
1829
- add_submenu_page( 'responsive-lightbox-settings', $options['name'], $options['name'], $capability, 'responsive-lightbox-' . $key , array( $this, 'options_page' ) );
1830
  }
1831
  }
1832
 
@@ -1836,12 +1855,20 @@ class Responsive_Lightbox_Settings {
1836
  * @return void
1837
  */
1838
  public function options_page() {
 
 
 
1839
  // check settings page
1840
- if ( isset( $_GET['page'] ) && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $this->tabs ) ) . ')$/', $_GET['page'], $tabs ) !== 1 )
1841
  return;
1842
 
1843
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
1844
- $section_key = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : ( ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '' );
 
 
 
 
 
1845
 
1846
  // assign main instance
1847
  $rl = Responsive_Lightbox();
@@ -1861,27 +1888,27 @@ class Responsive_Lightbox_Settings {
1861
 
1862
  // hidden h2 tag is needed to display info box properly when saving or resetting settings
1863
  echo '
1864
- <h2 class="hidden">' . __( 'Responsive Lightbox & Gallery', 'responsive-lightbox' ) . ' - ' . $this->tabs[$tab_key]['name'] . '</h2>' . '
1865
  <h2 class="nav-tab-wrapper">';
1866
 
1867
  foreach ( $this->tabs as $key => $options ) {
1868
  echo '
1869
- <a class="nav-tab ' . ( $tab_key == $key ? 'nav-tab-active' : '' ) . '" href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-' . $key ) ) . '">' . $options['name'] . '</a>';
1870
  }
1871
 
1872
  echo '
1873
  </h2>
1874
  <div class="responsive-lightbox-settings">
1875
  <div class="df-credits">
1876
- <h3 class="hndle">' . __( 'Responsive Lightbox & Gallery', 'responsive-lightbox' ) . ' ' . $rl->defaults['version'] . '</h3>
1877
  <div class="inside">
1878
- <h4 class="inner">' . __( 'Need support?', 'responsive-lightbox' ) . '</h4>
1879
- <p class="inner">' . sprintf( __( 'If you are having problems with this plugin, please browse it\'s <a href="%s" target="_blank">Documentation</a> or talk about them in the <a href="%s" target="_blank">Support forum</a>', 'responsive-lightbox' ), 'https://www.dfactory.eu/docs/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=docs', 'https://www.dfactory.eu/support/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=support' ) . '</p>
1880
  <hr />
1881
- <h4 class="inner">' . __( 'Do you like this plugin?', 'responsive-lightbox' ) . '</h4>
1882
- <p class="inner">' . sprintf( __( '<a href="%s" target="_blank">Rate it 5</a> on WordPress.org', 'responsive-lightbox' ), 'https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5' ) . '<br />' .
1883
- sprintf( __( 'Blog about it & link to the <a href="%s" target="_blank">plugin page</a>.', 'responsive-lightbox' ), 'https://dfactory.eu/plugins/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=blog-about' ) . '<br />' .
1884
- sprintf( __( 'Check out our other <a href="%s" target="_blank">WordPress plugins</a>.', 'responsive-lightbox' ), 'https://dfactory.eu/plugins/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=other-plugins' ) . '
1885
  </p>
1886
  <hr />
1887
  <p class="df-link inner"><a href="https://www.dfactory.eu/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="Digital Factory"><img src="//rlg-53eb.kxcdn.com/df-black-sm.png' . '" alt="Digital Factory" /></a></p>
@@ -1891,17 +1918,16 @@ class Responsive_Lightbox_Settings {
1891
 
1892
  // views
1893
  if ( ! empty( $this->tabs[$tab_key]['sections'] ) ) {
1894
- $views = $this->tabs[$tab_key]['sections'];
1895
 
1896
  echo '<ul class="subsubsub">';
1897
 
1898
- foreach ( $views as $key => $name ) {
1899
- $view = '<a href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-' . $tab_key . '&section=' . $key ) ) . '" class="' . ( $key == $section_key ? 'current' : '' ) . '">' . $name . '</a>';
1900
- $views[$key] = "\t<li class='$key'>$view";
1901
  }
1902
 
1903
- echo implode( " |</li>\n", $views ) . "</li>\n";
1904
- echo '</ul><input type="hidden" name="section" value="' . $section_key . '" /><br class="clear">';
1905
  }
1906
 
1907
  // tab content callback
@@ -1919,12 +1945,12 @@ class Responsive_Lightbox_Settings {
1919
  echo '<p class="submit">';
1920
 
1921
  if ( ! empty( $this->tabs[$tab_key]['submit'] ) ) {
1922
- submit_button( '', array( 'primary', 'save-' . $tab_key ), $this->tabs[$tab_key]['submit'], false );
1923
  echo ' ';
1924
  }
1925
 
1926
  if ( ! empty( $this->tabs[$tab_key]['reset'] ) )
1927
- submit_button( __( 'Reset to defaults', 'responsive-lightbox' ), array( 'secondary', 'reset-responsive-lightbox-settings reset-' . $tab_key ), $this->tabs[$tab_key]['reset'], false );
1928
 
1929
  echo '</p>';
1930
  }
@@ -1954,83 +1980,93 @@ class Responsive_Lightbox_Settings {
1954
  // assign main instance
1955
  $rl = Responsive_Lightbox();
1956
 
1957
- foreach ( $this->settings as $setting_id => $setting ) {
 
 
 
 
 
 
 
1958
  // set key
1959
  $setting_key = $setting_id;
1960
  $setting_id = 'responsive_lightbox_' . $setting_id;
1961
 
1962
  // add new capability to manage options
1963
- add_filter( 'option_page_capability_' . $setting_id, array( $this, 'manage_options_capability' ) );
1964
 
1965
  // register setting
1966
- register_setting(
1967
- esc_attr( $setting_id ),
1968
- ! empty( $setting['option_name'] ) ? esc_attr( $setting['option_name'] ) : $setting_id,
1969
- ! empty( $setting['callback'] ) ? $setting['callback'] : array( $this, 'validate_settings' )
1970
- );
1971
 
1972
  // register sections
1973
  if ( ! empty( $setting['sections'] ) && is_array( $setting['sections'] ) ) {
1974
- foreach ( $setting['sections'] as $section_id => $section ) {
 
 
1975
  add_settings_section(
1976
- esc_attr( $section_id ),
1977
  ! empty( $section['title'] ) ? esc_html( $section['title'] ) : '',
1978
  ! empty( $section['callback'] ) ? $section['callback'] : '',
1979
- ! empty( $section['page'] ) ? esc_attr( $section['page'] ) : $section_id
1980
  );
1981
  }
1982
  }
1983
 
1984
  // register fields
1985
  if ( ! empty( $setting['fields'] ) && is_array( $setting['fields'] ) ) {
1986
- foreach ( $setting['fields'] as $field_id => $field ) {
 
 
1987
  // prefix field id?
1988
  $field_key = $field_id;
1989
  $field_id = ( ! empty( $setting['prefix'] ) ? $setting['prefix'] . '_' : '' ) . $field_id;
1990
 
1991
  // field args
1992
- $args = array(
1993
- 'id' => ! empty( $field['id'] ) ? $field['id'] : $field_id,
1994
- 'class' => ! empty( $field['class'] ) ? $field['class'] : '',
1995
- 'name' => $setting['option_name'] . ( ! empty( $field['parent'] ) ? '[' . $field['parent'] . ']' : '' ) . '[' . $field_key . ']',
1996
- 'type' => ! empty( $field['type'] ) ? $field['type'] : 'text',
1997
- 'label' => ! empty( $field['label'] ) ? $field['label'] : '',
1998
- 'description' => ! empty( $field['description'] ) ? $field['description'] : '',
1999
- 'disabled' => isset( $field['disabled'] ) ? (bool) $field['disabled'] : false,
2000
- 'append' => ! empty( $field['append'] ) ? esc_html( $field['append'] ) : '',
2001
- 'prepend' => ! empty( $field['prepend'] ) ? esc_html( $field['prepend'] ) : '',
2002
- 'min' => isset( $field['min'] ) ? (int) $field['min'] : '',
2003
- 'max' => isset( $field['max'] ) ? (int) $field['max'] : '',
2004
- 'options' => ! empty( $field['options'] ) ? $field['options'] : '',
2005
- 'fields' => ! empty( $field['fields'] ) ? $field['fields'] : '',
2006
- 'after_field' => ! empty( $field['after_field'] ) ? $field['after_field'] : '',
2007
- 'default' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $rl->defaults[$setting_key][$field['parent']][$field_key] : $rl->defaults[$setting_key][$field_key], $field['type'] ) ),
2008
- 'value' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $rl->options[$setting_key][$field['parent']][$field_key] : ( isset( $rl->options[$setting_key][$field_key] ) ? $rl->options[$setting_key][$field_key] : $rl->defaults[$setting_key][$field_key] ), $field['type'] ) ),
2009
- 'label_for' => $field_id,
2010
- 'classname' => ! empty( $field['classname'] ) ? $field['classname'] : '',
2011
- 'callback' => ! empty( $field['callback'] ) ? $field['callback'] : '',
2012
- 'return' => false
2013
- );
2014
 
2015
  if ( $args['type'] === 'multiple' ) {
2016
  foreach ( $args['fields'] as $subfield_id => $subfield ) {
2017
- $args['fields'][$subfield_id] = wp_parse_args( $subfield, array(
2018
- 'id' => $field_id . '-' . $subfield_id,
2019
- 'class' => ! empty( $subfield['class'] ) ? $subfield['class'] : '',
2020
- 'name' => $setting['option_name'] . ( ! empty( $subfield['parent'] ) ? '[' . $subfield['parent'] . ']' : '' ) . '[' . $subfield_id . ']',
2021
- 'default' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $rl->defaults[$setting_key][$subfield['parent']][$subfield_id] : $rl->defaults[$setting_key][$subfield_id], $subfield['type'] ),
2022
- 'value' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $rl->options[$setting_key][$subfield['parent']][$subfield_id] : $rl->options[$setting_key][$subfield_id], $subfield['type'] ),
2023
- 'return' => true
2024
- ) );
 
 
 
2025
  }
2026
  }
2027
 
2028
  add_settings_field(
2029
- esc_attr( $field_id ),
2030
  ! empty( $field['title'] ) ? esc_html( $field['title'] ) : '',
2031
- array( $this, 'render_field' ),
2032
- ! empty( $field['page'] ) ? esc_attr( $field['page'] ) : $setting_id,
2033
- ! empty( $field['section'] ) ? esc_attr( $field['section'] ) : '',
2034
  $args
2035
  );
2036
  }
@@ -2038,35 +2074,19 @@ class Responsive_Lightbox_Settings {
2038
  }
2039
 
2040
  // licenses
2041
- $extensions = apply_filters( 'rl_settings_licenses', array() );
2042
 
2043
  if ( $extensions ) {
2044
  // add new capability to manage licenses
2045
- add_filter( 'option_page_capability_responsive_lightbox_licenses', array( $this, 'manage_options_capability' ) );
2046
 
2047
  // register setting
2048
- register_setting(
2049
- 'responsive_lightbox_licenses',
2050
- 'responsive_lightbox_licenses',
2051
- array( $this, 'validate_licenses' )
2052
- );
2053
-
2054
- add_settings_section(
2055
- 'responsive_lightbox_licenses',
2056
- __( 'Licenses', 'responsive-lightbox' ),
2057
- array( $this, 'licenses_section_cb' ),
2058
- 'responsive_lightbox_licenses'
2059
- );
2060
 
2061
  foreach ( $extensions as $id => $extension ) {
2062
- add_settings_field(
2063
- esc_attr( $id ),
2064
- $extension['name'],
2065
- array( $this, 'license_field_cb' ),
2066
- 'responsive_lightbox_licenses',
2067
- 'responsive_lightbox_licenses',
2068
- $extension
2069
- );
2070
  }
2071
  }
2072
  }
@@ -2079,32 +2099,32 @@ class Responsive_Lightbox_Settings {
2079
  */
2080
  public function render_field( $args ) {
2081
  if ( empty( $args ) || ! is_array( $args ) )
2082
- return;
2083
 
2084
  $html = '';
2085
 
2086
  switch ( $args['type'] ) {
2087
  case 'boolean':
2088
- $html .= '<label><input id="' . $args['id'] . '" type="checkbox" name="' . $args['name'] . '" value="1" ' . checked( (bool) $args['value'], true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $args['label'] . '</label>';
2089
  break;
2090
 
2091
  case 'radio':
2092
  foreach ( $args['options'] as $key => $name ) {
2093
- $html .= '<label><input id="' . $args['id'] . '-' . $key . '" type="radio" name="' . $args['name'] . '" value="' . $key . '" ' . checked( $key, $args['value'], false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $name . '</label> ';
2094
  }
2095
  break;
2096
 
2097
  case 'checkbox':
2098
  foreach ( $args['options'] as $key => $name ) {
2099
- $html .= '<label><input id="' . $args['id'] . '-' . $key . '" type="checkbox" name="' . $args['name'] . '[' . $key . ']" value="1" ' . checked( in_array( $key, $args['value'] ), true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . $name . '</label> ';
2100
  }
2101
  break;
2102
 
2103
  case 'select':
2104
- $html .= '<select id="' . $args['id'] . '" name="' . $args['name'] . '" value="' . esc_attr( $args['value'] ) . '" ' . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . '/>';
2105
 
2106
  foreach ( $args['options'] as $key => $name ) {
2107
- $html .= '<option value="' . $key . '" ' . selected( $args['value'], $key, false ) . '>' . $name . '</option>';
2108
  }
2109
 
2110
  $html .= '</select>';
@@ -2119,6 +2139,7 @@ class Responsive_Lightbox_Settings {
2119
 
2120
  foreach ( $args['fields'] as $subfield_id => $subfield_args ) {
2121
  $html .= $this->render_field( $subfield_args ) . ( $count < $count_fields ? '<br />' : '' );
 
2122
  $count++;
2123
  }
2124
  }
@@ -2127,24 +2148,24 @@ class Responsive_Lightbox_Settings {
2127
  break;
2128
 
2129
  case 'range':
2130
- $html .= '<input id="' . $args['id'] . '" type="range" name="' . $args['name'] . '" value="' . (int) $args['value'] . '" min="' . $args['min'] . '" max="' . $args['max'] . '" oninput="this.form.' . $args['id'] . '_range.value=this.value" />';
2131
- $html .= '<output name="' . $args['id'] . '_range">' . (int) $args['value'] . '</output>';
2132
  break;
2133
 
2134
  case 'color_picker':
2135
- $html .= '<input id="' . $args['id'] . '" class="color-picker" type="text" value="' . esc_attr( $args['value'] ) . '" name="' . $args['name'] . '" data-default-color="' . $args['default'] . '" />';
2136
  break;
2137
 
2138
  case 'number':
2139
- $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
2140
- $html .= '<input id="' . $args['id'] . '" type="number" value="' . (int) $args['value'] . '" name="' . $args['name'] . '" />';
2141
- $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
2142
  break;
2143
 
2144
  case 'button':
2145
- $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
2146
- $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-tour' ) ) . '" id="' . $args['id'] . '" class="button ' . ( ! empty( $args['classname'] ) ? esc_attr( $args['classname'] ) : 'button-secondary' ) . '">' . esc_html( $args['label'] ) . '</a>';
2147
- $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
2148
  break;
2149
 
2150
  case 'custom':
@@ -2153,16 +2174,16 @@ class Responsive_Lightbox_Settings {
2153
 
2154
  case 'text':
2155
  default :
2156
- $html .= ( ! empty( $args['prepend'] ) ? '<span>' . $args['prepend'] . '</span> ' : '' );
2157
- $html .= '<input id="' . $args['id'] . '" class="' . $args['class'] . '" type="text" value="' . esc_attr( $args['value'] ) . '" name="' . $args['name'] . '" />';
2158
- $html .= ( ! empty( $args['append'] ) ? ' <span>' . $args['append'] . '</span>' : '' );
2159
  }
2160
 
2161
  if ( ! empty ( $args['after_field'] ) )
2162
- $html .= $args['after_field'];
2163
 
2164
  if ( ! empty ( $args['description'] ) )
2165
- $html .= '<p class="description">' . $args['description'] . '</p>';
2166
 
2167
  if ( ! empty( $args['return'] ) )
2168
  return $html;
@@ -2178,7 +2199,7 @@ class Responsive_Lightbox_Settings {
2178
  * @param array $args
2179
  * @return mixed
2180
  */
2181
- public function sanitize_field( $value = null, $type = '', $args = array() ) {
2182
  if ( is_null( $value ) )
2183
  return null;
2184
 
@@ -2189,11 +2210,11 @@ class Responsive_Lightbox_Settings {
2189
  break;
2190
 
2191
  case 'checkbox':
2192
- $value = is_array( $value ) && ! empty( $value ) ? array_map( 'sanitize_text_field', $value ) : array();
2193
  break;
2194
 
2195
  case 'radio':
2196
- $value = is_array( $value ) ? false : sanitize_text_field( $value );
2197
  break;
2198
 
2199
  case 'textarea':
@@ -2202,7 +2223,9 @@ class Responsive_Lightbox_Settings {
2202
  break;
2203
 
2204
  case 'color_picker':
2205
- if ( empty( $value ) || preg_match( '/^#[a-f0-9]{6}$/i', $value ) !== 1 )
 
 
2206
  $value = '#666666';
2207
  break;
2208
 
@@ -2227,12 +2250,11 @@ class Responsive_Lightbox_Settings {
2227
  // validate custom events
2228
  if ( $args['setting_id'] === 'settings' ) {
2229
  if ( $args['field_id'] === 'enable_custom_events' && $args['subfield_id'] === 'custom_events' )
2230
- $value = preg_replace( '/[^a-z0-9 ]/i', '', $value );
2231
  } elseif ( $args['setting_id'] === 'builder' ) {
2232
  if ( $args['field_id'] === 'permalink' || $args['field_id'] === 'permalink_categories' || $args['field_id'] === 'permalink_tags' )
2233
  $value = sanitize_title( $value );
2234
  }
2235
-
2236
  }
2237
  case 'select':
2238
  default:
@@ -2257,8 +2279,11 @@ class Responsive_Lightbox_Settings {
2257
  if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', $rl->options['capabilities']['active'] ? 'edit_lightbox_settings' : 'manage_options' ) ) )
2258
  return $input;
2259
 
 
 
 
2260
  // check page
2261
- if ( ! isset( $_POST['option_page'] ) || ! ( $option_page = esc_attr( $_POST['option_page'] ) ) )
2262
  return $input;
2263
 
2264
  foreach ( $this->settings as $id => $setting ) {
@@ -2266,7 +2291,7 @@ class Responsive_Lightbox_Settings {
2266
 
2267
  if ( $key ) {
2268
  // set key
2269
- $setting_id = $id;
2270
  break;
2271
  }
2272
  }
@@ -2276,7 +2301,7 @@ class Responsive_Lightbox_Settings {
2276
  return $input;
2277
 
2278
  // save settings
2279
- if ( isset( $_POST['save' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
2280
  if ( $this->settings[$setting_id]['fields'] ) {
2281
  foreach ( $this->settings[$setting_id]['fields'] as $field_id => $field ) {
2282
  if ( $field['type'] === 'multiple' ) {
@@ -2306,9 +2331,9 @@ class Responsive_Lightbox_Settings {
2306
  if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['parent'] ) ) {
2307
  $field_parent = $this->settings[$setting_id]['fields'][$field_id]['parent'];
2308
 
2309
- $input[$field_parent][$field_id] = isset( $input[$field_parent][$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_parent][$field_id], $field['type'], $args ) ) : $this->sanitize_field( $input[$field_parent][$field_id], $field['type'], $args ) ) : ( in_array( $field['type'], array( 'boolean', 'checkbox' ) ) ? false : $rl->defaults[$setting_id][$field_parent][$field_id] );
2310
  } else {
2311
- $input[$field_id] = isset( $input[$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_id], $field['type'], $args ) ) : $this->sanitize_field( $input[$field_id], $field['type'], $args ) ) : ( in_array( $field['type'], array( 'boolean', 'checkbox' ) ) ? false : $rl->defaults[$setting_id][$field_id] );
2312
  }
2313
  }
2314
  }
@@ -2330,7 +2355,7 @@ class Responsive_Lightbox_Settings {
2330
 
2331
  if ( $setting_id === 'remote_library' )
2332
  $input = apply_filters( 'rl_remote_library_settings', $input );
2333
- } elseif ( isset( $_POST['reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
2334
  if ( $setting_id === 'configuration' ) {
2335
  $script = key( $input );
2336
 
@@ -2344,7 +2369,7 @@ class Responsive_Lightbox_Settings {
2344
  } else
2345
  $input = $rl->defaults[$setting_id];
2346
 
2347
- add_settings_error( 'reset_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id, 'settings_restored', __( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
2348
  }
2349
 
2350
  return $input;
@@ -2401,7 +2426,7 @@ class Responsive_Lightbox_Settings {
2401
  }
2402
  }
2403
 
2404
- add_settings_error( 'reset_rl_capabilities', 'settings_restored', __( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
2405
  }
2406
 
2407
  return $input;
@@ -2425,7 +2450,7 @@ class Responsive_Lightbox_Settings {
2425
  <table class="widefat fixed posts">
2426
  <thead>
2427
  <tr>
2428
- <th>' . __( 'Role', 'responsive-lightbox' ) . '</th>';
2429
 
2430
  foreach ( $editable_roles as $role_name => $role_info ) {
2431
  $html .= '<th>' . esc_html( isset( $wp_roles->role_names[$role_name] ) ? translate_user_role( $wp_roles->role_names[$role_name] ) : $role_name ) . '</th>';
@@ -2441,7 +2466,7 @@ class Responsive_Lightbox_Settings {
2441
  foreach ( Responsive_Lightbox()->capabilities as $cap_role => $cap_label ) {
2442
  $html .= '
2443
  <tr' . ( ( $i++ % 2 === 0 ) ? ' class="alternate"' : '' ) . '>
2444
- <td>' . esc_html( __( $cap_label, 'responsive-lightbox' ) ) . '</td>';
2445
 
2446
  foreach ( $editable_roles as $role_name => $role_info ) {
2447
  // get user role
@@ -2471,20 +2496,20 @@ class Responsive_Lightbox_Settings {
2471
  */
2472
  private function addons_tab_cb() {
2473
  ?>
2474
- <h3><?php _e( 'Add-ons / Extensions', 'responsive-lightbox' ); ?></h3>
2475
- <p class="description"><?php _e( 'Enhance your website with these beautiful, easy to use extensions, designed with Responsive Lightbox & Gallery integration in mind.', 'responsive-lightbox' ); ?></p>
2476
  <br />
2477
  <?php
2478
- if ( ( $cache = get_transient( 'responsive_lightbox_addons_feed' ) ) === false ) {
2479
- $url = 'https://dfactory.eu/?feed=addons&product=responsive-lightbox';
2480
 
2481
- $feed = wp_remote_get( esc_url_raw( $url ), array( 'sslverify' => false ) );
 
2482
 
2483
  if ( ! is_wp_error( $feed ) ) {
2484
  if ( isset( $feed['body'] ) && strlen( $feed['body'] ) > 0 )
2485
  $cache = wp_remote_retrieve_body( $feed );
2486
  } else
2487
- $cache = '<div class="error"><p>' . __( 'There was an error retrieving the extensions list from the server. Please try again later.', 'responsive-lightbox' ) . '</div>';
2488
  }
2489
 
2490
  echo $cache;
@@ -2496,7 +2521,7 @@ class Responsive_Lightbox_Settings {
2496
  * @return void
2497
  */
2498
  public function licenses_section_cb() {
2499
- ?><p class="description"><?php _e( 'A list of licenses for your Responsive Lightbox & Gallery extensions.', 'responsive-lightbox' ); ?></p><?php
2500
  }
2501
 
2502
  /**
@@ -2509,15 +2534,15 @@ class Responsive_Lightbox_Settings {
2509
  $licenses = get_option( 'responsive_lightbox_licenses' );
2510
 
2511
  if ( ! empty( $licenses ) ) {
2512
- $license = isset( $licenses[$args['id']]['license'] ) ? esc_attr( $licenses[$args['id']]['license'] ) : '';
2513
  $status = ! empty( $licenses[$args['id']]['status'] );
2514
  } else {
2515
  $license = '';
2516
  $status = false;
2517
  } ?>
2518
  <fieldset class="rl_license rl_license-<?php echo esc_attr( $args['id'] ); ?>">
2519
- <input type="text" class="regular-text" name="responsive_lightbox_licenses[<?php echo esc_attr( $args['id'] ); ?>][license]" value="<?php echo $license; ?>"><span class="dashicons <?php echo ( $status ? 'dashicons-yes' : 'dashicons-no' ); ?>"></span>
2520
- <p class="description"><?php printf( __( 'Enter your license key to activate %s extension and enable automatic upgrade notices.', 'responsive-lightbox' ), $args['name'] ); ?></p>
2521
  </fieldset>
2522
  <?php
2523
  }
@@ -2533,16 +2558,21 @@ class Responsive_Lightbox_Settings {
2533
  if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', Responsive_Lightbox()->options['capabilities']['active'] ? 'edit_lightbox_settings' : 'manage_options' ) ) )
2534
  return $input;
2535
 
 
 
 
2536
  // check page
2537
- if ( ! isset( $_POST['option_page'] ) || ! ( $option_page = esc_attr( $_POST['option_page'] ) ) )
2538
  return $input;
2539
 
 
 
2540
  // check data
2541
- if ( ! isset( $_POST['responsive_lightbox_licenses'] ) || ! is_array( $_POST['responsive_lightbox_licenses'] ) )
2542
  return $input;
2543
 
2544
  // get extension licenses
2545
- $extensions = apply_filters( 'rl_settings_licenses', array() );
2546
 
2547
  if ( empty( $extensions ) )
2548
  return $input;
@@ -2550,21 +2580,21 @@ class Responsive_Lightbox_Settings {
2550
  // save settings
2551
  if ( isset( $_POST['save_rl_licenses'] ) ) {
2552
  $licenses = get_option( 'responsive_lightbox_licenses' );
2553
- $statuses = array( 'updated' => 0, 'error' => 0 );
2554
 
2555
  foreach ( $extensions as $extension ) {
2556
- if ( ! isset( $_POST['responsive_lightbox_licenses'][$extension['id']] ) )
2557
  continue;
2558
 
2559
- $license = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['responsive_lightbox_licenses'][$extension['id']]['license'] );
2560
- $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] ) ? true : false;
2561
 
2562
  // request data
2563
- $request_args = array(
2564
- 'action' => 'activate_license',
2565
- 'license' => trim( $license ),
2566
- 'item_name' => $extension['item_name']
2567
- );
2568
 
2569
  // request
2570
  $response = $this->license_request( $request_args );
@@ -2592,26 +2622,29 @@ class Responsive_Lightbox_Settings {
2592
 
2593
  // success notice
2594
  if ( $statuses['updated'] > 0 )
2595
- add_settings_error( 'rl_licenses_settings', 'license_activated', sprintf( _n( '%s license successfully activated.', '%s licenses successfully activated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ), 'updated' );
2596
 
2597
  // failed notice
2598
  if ( $statuses['error'] > 0 )
2599
- add_settings_error( 'rl_licenses_settings', 'license_activation_failed', sprintf( _n( '%s license activation failed.', '%s licenses activation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ), 'error' );
2600
  } elseif ( isset( $_POST['reset_rl_licenses'] ) ) {
2601
  $licenses = get_option( 'responsive_lightbox_licenses' );
2602
- $statuses = array( 'updated' => 0, 'error' => 0 );
 
 
 
2603
 
2604
  foreach ( $extensions as $extension ) {
2605
  $license = ! empty( $licenses ) && isset( $licenses[$extension['id']]['license'] ) ? $licenses[$extension['id']]['license'] : '';
2606
- $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] ) ? true : false;
2607
 
2608
  if ( $status === true || ( $status === false && ! empty( $license ) ) ) {
2609
  // request data
2610
- $request_args = array(
2611
- 'action' => 'deactivate_license',
2612
- 'license' => trim( $license ),
2613
- 'item_name' => $extension['item_name']
2614
- );
2615
 
2616
  // request
2617
  $response = $this->license_request( $request_args );
@@ -2627,6 +2660,7 @@ class Responsive_Lightbox_Settings {
2627
  if ( $license_data->license == 'deactivated' ) {
2628
  $input[$extension['id']]['license'] = '';
2629
  $input[$extension['id']]['status'] = false;
 
2630
  $statuses['updated']++;
2631
  } else
2632
  $statuses['error']++;
@@ -2636,11 +2670,11 @@ class Responsive_Lightbox_Settings {
2636
 
2637
  // success notice
2638
  if ( $statuses['updated'] > 0 )
2639
- add_settings_error( 'rl_licenses_settings', 'license_deactivated', sprintf( _n( '%s license successfully deactivated.', '%s licenses successfully deactivated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ), 'updated' );
2640
 
2641
  // failed notice
2642
  if ( $statuses['error'] > 0 )
2643
- add_settings_error( 'rl_licenses_settings', 'license_deactivation_failed', sprintf( _n( '%s license deactivation failed.', '%s licenses deactivation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ), 'error' );
2644
  }
2645
 
2646
  return $input;
@@ -2654,15 +2688,15 @@ class Responsive_Lightbox_Settings {
2654
  */
2655
  private function license_request( $args ) {
2656
  // data to send in our API request
2657
- $api_params = array(
2658
  'edd_action' => $args['action'],
2659
- 'license' => $args['license'],
2660
  'item_name' => urlencode( $args['item_name'] ),
2661
  // 'item_id' => $args['item_id'],
2662
  'url' => home_url(),
2663
  'timeout' => 60,
2664
  'sslverify' => false
2665
- );
2666
 
2667
  // call the custom API
2668
  $response = wp_remote_get( add_query_arg( $api_params, 'http://dfactory.eu' ) );
12
  */
13
  class Responsive_Lightbox_Settings {
14
 
15
+ public $settings = [];
16
+ public $tabs = [];
17
+ public $scripts = [];
18
 
19
  /**
20
  * Class constructor.
26
  Responsive_Lightbox()->settings = $this;
27
 
28
  // actions
29
+ add_action( 'admin_init', [ $this, 'register_settings' ] );
30
+ add_action( 'admin_menu', [ $this, 'admin_menu_options' ] );
31
+ add_action( 'after_setup_theme', [ $this, 'load_defaults' ] );
32
+ add_action( 'init', [ $this, 'init_builder' ] );
33
  }
34
 
35
  /**
40
  public function init_builder() {
41
  // add categories
42
  if ( Responsive_Lightbox()->options['builder']['gallery_builder'] && Responsive_Lightbox()->options['builder']['categories'] && Responsive_Lightbox()->options['builder']['archives'] ) {
43
+ $terms = get_terms( [ 'taxonomy' => 'rl_category', 'hide_empty' => false ] );
44
 
45
  if ( ! empty( $terms ) ) {
46
  foreach ( $terms as $term ) {
65
  // assign main instance
66
  $rl = Responsive_Lightbox();
67
 
68
+ $this->scripts = apply_filters(
69
+ 'rl_settings_scripts',
70
+ [
71
+ 'swipebox' => [
72
+ 'name' => __( 'SwipeBox', 'responsive-lightbox' ),
73
+ 'animations' => [
74
+ 'css' => __( 'CSS', 'responsive-lightbox' ),
75
+ 'jquery' => __( 'jQuery', 'responsive-lightbox' )
76
+ ],
77
+ 'supports' => [ 'title' ]
78
+ ],
79
+ 'prettyphoto' => [
80
+ 'name' => __( 'prettyPhoto', 'responsive-lightbox' ),
81
+ 'animation_speeds' => [
82
+ 'slow' => __( 'slow', 'responsive-lightbox' ),
83
+ 'normal' => __( 'normal', 'responsive-lightbox' ),
84
+ 'fast' => __( 'fast', 'responsive-lightbox' )
85
+ ],
86
+ 'themes' => [
87
+ 'pp_default' => __( 'default', 'responsive-lightbox' ),
88
+ 'light_rounded' => __( 'light rounded', 'responsive-lightbox' ),
89
+ 'dark_rounded' => __( 'dark rounded', 'responsive-lightbox' ),
90
+ 'light_square' => __( 'light square', 'responsive-lightbox' ),
91
+ 'dark_square' => __( 'dark square', 'responsive-lightbox' ),
92
+ 'facebook' => __( 'facebook', 'responsive-lightbox' )
93
+ ],
94
+ 'wmodes' => [
95
+ 'window' => __( 'window', 'responsive-lightbox' ),
96
+ 'transparent' => __( 'transparent', 'responsive-lightbox' ),
97
+ 'opaque' => __( 'opaque', 'responsive-lightbox' ),
98
+ 'direct' => __( 'direct', 'responsive-lightbox' ),
99
+ 'gpu' => __( 'gpu', 'responsive-lightbox' )
100
+ ],
101
+ 'supports' => [ 'inline', 'iframe', 'ajax', 'title', 'caption' ]
102
+ ],
103
+ 'fancybox' => [
104
+ 'name' => __( 'FancyBox', 'responsive-lightbox' ),
105
+ 'transitions' => [
106
+ 'elastic' => __( 'elastic', 'responsive-lightbox' ),
107
+ 'fade' => __( 'fade', 'responsive-lightbox' ),
108
+ 'none' => __( 'none', 'responsive-lightbox' )
109
+ ],
110
+ 'scrollings' => [
111
+ 'auto' => __( 'auto', 'responsive-lightbox' ),
112
+ 'yes' => __( 'yes', 'responsive-lightbox' ),
113
+ 'no' => __( 'no', 'responsive-lightbox' )
114
+ ],
115
+ 'easings' => [
116
+ 'swing' => __( 'swing', 'responsive-lightbox' ),
117
+ 'linear' => __( 'linear', 'responsive-lightbox' )
118
+ ],
119
+ 'positions' => [
120
+ 'outside' => __( 'outside', 'responsive-lightbox' ),
121
+ 'inside' => __( 'inside', 'responsive-lightbox' ),
122
+ 'over' => __( 'over', 'responsive-lightbox' )
123
+ ],
124
+ 'supports' => [ 'inline', 'iframe', 'ajax', 'title' ]
125
+ ],
126
+ 'nivo' => [
127
+ 'name' => __( 'Nivo Lightbox', 'responsive-lightbox' ),
128
+ 'effects' => [
129
+ 'fade' => __( 'fade', 'responsive-lightbox' ),
130
+ 'fadeScale' => __( 'fade scale', 'responsive-lightbox' ),
131
+ 'slideLeft' => __( 'slide left', 'responsive-lightbox' ),
132
+ 'slideRight' => __( 'slide right', 'responsive-lightbox' ),
133
+ 'slideUp' => __( 'slide up', 'responsive-lightbox' ),
134
+ 'slideDown' => __( 'slide down', 'responsive-lightbox' ),
135
+ 'fall' => __( 'fall', 'responsive-lightbox' )
136
+ ],
137
+ 'supports' => [ 'inline', 'iframe', 'ajax', 'title' ]
138
+ ],
139
+ 'imagelightbox' => [
140
+ 'name' => __( 'Image Lightbox', 'responsive-lightbox' ),
141
+ 'supports' => []
142
+ ],
143
+ 'tosrus' => [
144
+ 'name' => __( 'TosRUs', 'responsive-lightbox' ),
145
+ 'supports' => [ 'inline', 'title' ]
146
+ ],
147
+ 'featherlight' => [
148
+ 'name' => __( 'Featherlight', 'responsive-lightbox' ),
149
+ 'supports' => [ 'inline', 'iframe', 'ajax' ]
150
+ ],
151
+ 'magnific' => [
152
+ 'name' => __( 'Magnific Popup', 'responsive-lightbox' ),
153
+ 'supports' => [ 'inline', 'iframe', 'ajax', 'title', 'caption' ]
154
+ ]
155
+ ]
156
+ );
157
+
158
+ $this->image_titles = [
159
  'default' => __( 'None', 'responsive-lightbox' ),
160
  'title' => __( 'Image Title', 'responsive-lightbox' ),
161
  'caption' => __( 'Image Caption', 'responsive-lightbox' ),
162
  'alt' => __( 'Image Alt Text', 'responsive-lightbox' ),
163
  'description' => __( 'Image Description', 'responsive-lightbox' )
164
+ ];
165
 
166
  // get scripts
167
  foreach ( $this->scripts as $key => $value ) {
169
  }
170
 
171
  // get image sizes
172
+ $sizes = apply_filters(
173
+ 'image_size_names_choose',
174
+ [
175
+ 'thumbnail' => __( 'Thumbnail', 'responsive-lightbox' ),
176
+ 'medium' => __( 'Medium', 'responsive-lightbox' ),
177
+ 'large' => __( 'Large', 'responsive-lightbox' ),
178
+ 'full' => __( 'Full Size', 'responsive-lightbox' )
179
+ ]
180
+ );
181
 
182
  // prepare galeries
183
+ $galleries = $builder_galleries = wp_parse_args( apply_filters( 'rl_gallery_types', [] ), $rl->gallery_types );
184
 
185
  unset( $builder_galleries['default'] );
186
 
187
+ $this->settings = [
188
+ 'settings' => [
189
  'option_group' => 'responsive_lightbox_settings',
190
  'option_name' => 'responsive_lightbox_settings',
191
+ 'sections' => [
192
+ 'responsive_lightbox_settings' => [
193
  'title' => __( 'General Settings', 'responsive-lightbox' )
194
+ ]
195
+ ],
196
  'prefix' => 'rl',
197
+ 'fields' => [
198
+ 'tour' => [
199
  'title' => __( 'Introduction Tour', 'responsive-lightbox' ),
200
  'section' => 'responsive_lightbox_settings',
201
  'type' => 'button',
202
  'label' => __( 'Start Tour', 'responsive-lightbox' ),
203
  'description' => __( 'Take this tour to quickly learn about the use of this plugin.', 'responsive-lightbox' ),
204
  'classname' => 'button-primary button-hero',
205
+ ],
206
+ 'script' => [
207
  'title' => __( 'Default lightbox', 'responsive-lightbox' ),
208
  'section' => 'responsive_lightbox_settings',
209
  'type' => 'select',
210
  'label' => '',
211
+ 'description' => sprintf( __( 'Select your preferred ligthbox effect script or get our <a href="%s">premium extensions</a>.', 'responsive-lightbox' ), wp_nonce_url( add_query_arg( [ 'action' => 'rl-hide-notice' ], admin_url( 'admin.php?page=responsive-lightbox-addons' ) ), 'rl_action', 'rl_nonce' ) ),
212
  'options' => $scripts
213
+ ],
214
+ 'selector' => [
215
  'title' => __( 'Selector', 'responsive-lightbox' ),
216
  'section' => 'responsive_lightbox_settings',
217
  'type' => 'text',
218
  'description' => __( 'Enter the rel selector lightbox effect will be applied to.', 'responsive-lightbox' )
219
+ ],
220
+ 'image_links' => [
221
  'title' => __( 'Images', 'responsive-lightbox' ),
222
  'section' => 'responsive_lightbox_settings',
223
  'type' => 'boolean',
224
  'label' => __( 'Enable lightbox for WordPress image links.', 'responsive-lightbox' )
225
+ ],
226
+ 'image_title' => [
227
  'title' => __( 'Single image title', 'responsive-lightbox' ),
228
  'section' => 'responsive_lightbox_settings',
229
  'type' => 'select',
230
  'description' => __( 'Select title for single images.', 'responsive-lightbox' ),
231
  'options' => $this->image_titles
232
+ ],
233
+ 'image_caption' => [
234
  'title' => __( 'Single image caption', 'responsive-lightbox' ),
235
  'section' => 'responsive_lightbox_settings',
236
  'type' => 'select',
237
  'description' => __( 'Select caption for single images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ),
238
  'options' => $this->image_titles
239
+ ],
240
+ 'images_as_gallery' => [
241
  'title' => __( 'Single images as gallery', 'responsive-lightbox' ),
242
  'section' => 'responsive_lightbox_settings',
243
  'type' => 'boolean',
244
  'label' => __( 'Display single post images as a gallery.', 'responsive-lightbox' )
245
+ ],
246
+ 'galleries' => [
247
  'title' => __( 'Galleries', 'responsive-lightbox' ),
248
  'section' => 'responsive_lightbox_settings',
249
  'type' => 'boolean',
250
  'label' => __( 'Enable lightbox for WordPress image galleries.', 'responsive-lightbox' )
251
+ ],
252
+ 'default_gallery' => [
253
  'title' => __( 'WordPress gallery', 'responsive-lightbox' ),
254
  'section' => 'responsive_lightbox_settings',
255
  'type' => 'select',
256
  'description' => __( 'Select your preferred default WordPress gallery style.', 'responsive-lightbox' ),
257
  'options' => $galleries
258
+ ],
259
+ 'builder_gallery' => [
260
  'title' => __( 'Builder gallery', 'responsive-lightbox' ),
261
  'section' => 'responsive_lightbox_settings',
262
  'type' => 'select',
263
  'description' => __( 'Select your preferred default builder gallery style.', 'responsive-lightbox' ),
264
  'options' => $builder_galleries
265
+ ],
266
+ 'default_woocommerce_gallery' => [
267
  'title' => __( 'WooCommerce gallery', 'responsive-lightbox' ),
268
  'section' => 'responsive_lightbox_settings',
269
  'type' => 'select',
270
  'disabled' => ! class_exists( 'WooCommerce' ),
271
  'description' => __( 'Select your preferred gallery style for WooCommerce product gallery.', 'responsive-lightbox' ),
272
  'options' => $galleries
273
+ ],
274
+ 'gallery_image_size' => [
275
  'title' => __( 'Gallery image size', 'responsive-lightbox' ),
276
  'section' => 'responsive_lightbox_settings',
277
  'type' => 'select',
278
  'description' => __( 'Select image size for gallery image links.', 'responsive-lightbox' ),
279
  'options' => $sizes
280
+ ],
281
+ 'gallery_image_title' => [
282
  'title' => __( 'Gallery image title', 'responsive-lightbox' ),
283
  'section' => 'responsive_lightbox_settings',
284
  'type' => 'select',
285
  'description' => __( 'Select title for the gallery images.', 'responsive-lightbox' ),
286
  'options' => $this->image_titles
287
+ ],
288
+ 'gallery_image_caption' => [
289
  'title' => __( 'Gallery image caption', 'responsive-lightbox' ),
290
  'section' => 'responsive_lightbox_settings',
291
  'type' => 'select',
292
  'description' => __( 'Select caption for the gallery images (if supported by selected lightbox and/or gallery).', 'responsive-lightbox' ),
293
  'options' => $this->image_titles
294
+ ],
295
+ 'videos' => [
296
  'title' => __( 'Videos', 'responsive-lightbox' ),
297
  'section' => 'responsive_lightbox_settings',
298
  'type' => 'boolean',
299
  'label' => __( 'Enable lightbox for YouTube and Vimeo video links.', 'responsive-lightbox' )
300
+ ],
301
+ 'widgets' => [
302
  'title' => __( 'Widgets', 'responsive-lightbox' ),
303
  'section' => 'responsive_lightbox_settings',
304
  'type' => 'boolean',
305
  'label' => __( 'Enable lightbox for widgets content.', 'responsive-lightbox' )
306
+ ],
307
+ 'comments' => [
308
  'title' => __( 'Comments', 'responsive-lightbox' ),
309
  'section' => 'responsive_lightbox_settings',
310
  'type' => 'boolean',
311
  'label' => __( 'Enable lightbox for comments content.', 'responsive-lightbox' )
312
+ ],
313
+ 'force_custom_gallery' => [
314
  'title' => __( 'Force lightbox', 'responsive-lightbox' ),
315
  'section' => 'responsive_lightbox_settings',
316
  'type' => 'boolean',
317
  'label' => __( 'Try to force lightbox for custom WP gallery replacements, like Jetpack or Visual Composer galleries.', 'responsive-lightbox' )
318
+ ],
319
+ 'woocommerce_gallery_lightbox' => [
320
  'title' => __( 'WooCommerce lightbox', 'responsive-lightbox' ),
321
  'section' => 'responsive_lightbox_settings',
322
  'type' => 'boolean',
323
  'label' => __( 'Replace WooCommerce product gallery lightbox.', 'responsive-lightbox' ),
324
  'disabled' => ! class_exists( 'WooCommerce' ) || Responsive_Lightbox()->options['settings']['default_woocommerce_gallery'] !== 'default'
325
+ ],
326
+ 'enable_custom_events' => [
327
  'title' => __( 'Custom events', 'responsive-lightbox' ),
328
  'section' => 'responsive_lightbox_settings',
329
  'type' => 'multiple',
330
+ 'fields' => [
331
+ 'enable_custom_events' => [
332
  'type' => 'boolean',
333
  'label' => __( 'Enable triggering lightbox on custom jQuery events.', 'responsive-lightbox' )
334
+ ],
335
+ 'custom_events' => [
336
  'type' => 'text',
337
  'description' => __( 'Enter a space separated list of events.', 'responsive-lightbox' )
338
+ ]
339
+ ]
340
+ ],
341
+ 'loading_place' => [
342
  'title' => __( 'Loading place', 'responsive-lightbox' ),
343
  'section' => 'responsive_lightbox_settings',
344
  'type' => 'radio',
345
  'description' => __( 'Select where all the lightbox scripts should be placed.', 'responsive-lightbox' ),
346
+ 'options' => [
347
  'header' => __( 'Header', 'responsive-lightbox' ),
348
  'footer' => __( 'Footer', 'responsive-lightbox' )
349
+ ]
350
+ ],
351
+ 'conditional_loading' => [
352
  'title' => __( 'Conditional loading', 'responsive-lightbox' ),
353
  'section' => 'responsive_lightbox_settings',
354
  'type' => 'boolean',
355
  'label' => __( 'Enable to load scripts and styles only on pages that have images or galleries in post content.', 'responsive-lightbox' )
356
+ ],
357
+ 'deactivation_delete' => [
358
  'title' => __( 'Delete data', 'responsive-lightbox' ),
359
  'section' => 'responsive_lightbox_settings',
360
  'type' => 'boolean',
361
  'label' => __( 'Delete all plugin settings on deactivation.', 'responsive-lightbox' ),
362
  'description' => __( 'Enable this to delete all plugin settings and also delete all plugin capabilities from all users on deactivation.', 'responsive-lightbox' )
363
+ ]
364
+ ]
365
+ ],
366
+ 'builder' => [
367
  'option_group' => 'responsive_lightbox_builder',
368
  'option_name' => 'responsive_lightbox_builder',
369
+ 'sections' => [
370
+ 'responsive_lightbox_builder' => [
371
  'title' => __( 'Gallery Builder Settings', 'responsive-lightbox' )
372
+ ]
373
+ ],
374
  'prefix' => 'rl',
375
+ 'fields' => [
376
+ 'gallery_builder' => [
377
  'title' => __( 'Gallery Builder', 'responsive-lightbox' ),
378
  'section' => 'responsive_lightbox_builder',
379
  'type' => 'boolean',
380
  'label' => __( 'Enable advanced gallery builder.', 'responsive-lightbox' )
381
+ ],
382
+ 'categories' => [
383
  'title' => __( 'Categories', 'responsive-lightbox' ),
384
  'section' => 'responsive_lightbox_builder',
385
  'type' => 'boolean',
386
  'label' => __( 'Enable Gallery Categories.', 'responsive-lightbox' ),
387
  'description' => __( 'Enable if you want to use Gallery Categories.', 'responsive-lightbox' )
388
+ ],
389
+ 'tags' => [
390
  'title' => __( 'Tags', 'responsive-lightbox' ),
391
  'section' => 'responsive_lightbox_builder',
392
  'type' => 'boolean',
393
  'label' => __( 'Enable Gallery Tags.', 'responsive-lightbox' ),
394
  'description' => __( 'Enable if you want to use Gallery Tags.', 'responsive-lightbox' )
395
+ ],
396
+ 'permalink' => [
397
  'title' => __( 'Gallery Permalink', 'responsive-lightbox' ),
398
  'section' => 'responsive_lightbox_builder',
399
  'type' => 'text',
400
+ 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink'] ) ) . '</strong>/</code><br />' . esc_html__( 'Enter gallery page slug.', 'responsive-lightbox' )
401
+ ],
402
+ 'permalink_categories' => [
403
  'title' => __( 'Categories Permalink', 'responsive-lightbox' ),
404
  'section' => 'responsive_lightbox_builder',
405
  'type' => 'text',
406
+ 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink_categories'] ) ) . '</strong>/</code><br />' . esc_html__( 'Enter gallery categories archive page slug.', 'responsive-lightbox' )
407
+ ],
408
+ 'permalink_tags' => [
409
  'title' => __( 'Tags Permalink', 'responsive-lightbox' ),
410
  'section' => 'responsive_lightbox_builder',
411
  'type' => 'text',
412
+ 'description' => '<code>' . site_url() . '/<strong>' . untrailingslashit( esc_html( $rl->options['builder']['permalink_tags'] ) ) . '</strong>/</code><br />' . esc_html__( 'Enter gallery tags archive page slug.', 'responsive-lightbox' )
413
+ ],
414
+ 'archives' => [
415
  'title' => __( 'Archives', 'responsive-lightbox' ),
416
  'section' => 'responsive_lightbox_builder',
417
  'type' => 'boolean',
418
  'label' => __( 'Enable gallery archives.', 'responsive-lightbox' )
419
+ ],
420
+ 'archives_category' => [
421
  'title' => __( 'Archives category', 'responsive-lightbox' ),
422
  'section' => 'responsive_lightbox_builder',
423
  'type' => 'select',
424
  'description' => __( 'Select category for gallery archives.', 'responsive-lightbox' ),
425
+ 'options' => [
426
  'all' => __( 'All', 'responsive-lightbox' )
427
+ ]
428
+ ]
429
+ ]
430
+ ],
431
+ 'folders' => [
432
  'option_group' => 'responsive_lightbox_folders',
433
  'option_name' => 'responsive_lightbox_folders',
434
+ 'sections' => [
435
+ 'responsive_lightbox_folders' => [
436
  'title' => __( 'Folders Settings', 'responsive-lightbox' )
437
+ ]
438
+ ],
439
  'prefix' => 'rl',
440
+ 'fields' => [
441
+ 'active' => [
442
  'title' => __( 'Folders', 'responsive-lightbox' ),
443
  'section' => 'responsive_lightbox_folders',
444
  'type' => 'boolean',
445
  'label' => __( 'Enable media folders.', 'responsive-lightbox' )
446
+ ],
447
+ 'media_taxonomy' => [
448
  'title' => __( 'Media taxonomy', 'responsive-lightbox' ),
449
  'section' => 'responsive_lightbox_folders',
450
  'type' => 'select',
451
  'description' => __( 'Select media taxonomy.', 'responsive-lightbox' ) . '<br />' . __( 'If you have ever used custom media taxonomies you may try to <a id="rl_folders_load_old_taxonomies" href="#">load and use them.</a>', 'responsive-lightbox' ),
452
  'after_field' => '<span class="spinner rl-spinner"></span>',
453
+ 'options' => [ $rl->options['folders']['media_taxonomy'] => $rl->options['folders']['media_taxonomy'] . ' (' . __( 'Folders', 'responsive-lightbox' ) . ')' ]
454
+ ],
455
+ 'media_tags' => [
456
  'title' => __( 'Media tags', 'responsive-lightbox' ),
457
  'section' => 'responsive_lightbox_folders',
458
  'type' => 'boolean',
459
  'label' => __( 'Enable media tags.', 'responsive-lightbox' ),
460
  'description' => __( 'Enable if you want to use media tags.', 'responsive-lightbox' )
461
+ ],
462
+ 'show_in_menu' => [
463
  'title' => __( 'Show in menu', 'responsive-lightbox' ),
464
  'section' => 'responsive_lightbox_folders',
465
  'type' => 'boolean',
466
  'label' => __( 'Enable to show the taxonomy in the admin menu.', 'responsive-lightbox' )
467
+ ],
468
+ 'folders_removal' => [
469
  'title' => __( 'Subfolder removal', 'responsive-lightbox' ),
470
  'section' => 'responsive_lightbox_folders',
471
  'type' => 'boolean',
472
  'label' => __( 'Select to remove subfolders when parent folder is deleted.', 'responsive-lightbox' )
473
+ ],
474
+ 'jstree_wholerow' => [
475
  'title' => __( 'Whole row', 'responsive-lightbox' ),
476
  'section' => 'responsive_lightbox_folders',
477
  'type' => 'boolean',
478
  'label' => __( 'Enable to highlight folder\'s row as a clickable area.', 'responsive-lightbox' )
479
+ ]
480
+ ]
481
+ ],
482
+ 'remote_library' => [
483
  'option_group' => 'responsive_lightbox_remote_library',
484
  'option_name' => 'responsive_lightbox_remote_library',
485
+ 'sections' => [
486
+ 'responsive_lightbox_remote_library' => [
487
  'title' => __( 'Remote Library Settings', 'responsive-lightbox' )
488
+ ],
489
+ 'responsive_lightbox_remote_library_providers' => [
490
  'title' => __( 'Media Providers', 'responsive-lightbox' ),
491
  'page' => 'responsive_lightbox_remote_library',
492
+ 'callback' => [ $this, 'remote_library_providers_description' ]
493
+ ]
494
+ ],
495
  'prefix' => 'rl',
496
+ 'fields' => [
497
+ 'active' => [
498
  'title' => __( 'Remote Library', 'responsive-lightbox' ),
499
  'section' => 'responsive_lightbox_remote_library',
500
  'type' => 'boolean',
501
  'label' => __( 'Enable remote libraries.', 'responsive-lightbox' ),
502
  'description' => __( 'Check this to enable remote access to the following image libraries.', 'responsive-lightbox' )
503
+ ],
504
+ 'caching' => [
505
  'title' => __( 'Caching', 'responsive-lightbox' ),
506
  'section' => 'responsive_lightbox_remote_library',
507
  'type' => 'boolean',
508
  'label' => __( 'Enable remote library requests caching.', 'responsive-lightbox' )
509
+ ],
510
+ 'cache_expiry' => [
511
  'title' => __( 'Cache expiry', 'responsive-lightbox' ),
512
  'section' => 'responsive_lightbox_remote_library',
513
  'type' => 'number',
514
  'min' => 1,
515
  'description' => __( 'Enter the cache expiry time.', 'responsive-lightbox' ),
516
  'append' => __( 'hour(s)', 'responsive-lightbox' )
517
+ ]
518
+ ]
519
+ ],
520
+ 'configuration' => [
521
  'option_group' => 'responsive_lightbox_configuration',
522
  'option_name' => 'responsive_lightbox_configuration',
523
+ 'sections' => [
524
+ 'responsive_lightbox_configuration' => [
525
  'title' => sprintf( __( '%s Settings', 'responsive-lightbox' ), ( isset( $this->scripts[$rl->options['settings']['script']]['name'] ) ? $this->scripts[$rl->options['settings']['script']]['name'] : $this->scripts[$rl->defaults['settings']['script']]['name'] ) )
526
+ ],
527
+ ],
528
  'prefix' => 'rl',
529
+ 'fields' => []
530
+ ],
531
+ 'capabilities' => [
532
  'option_group' => 'responsive_lightbox_capabilities',
533
  'option_name' => 'responsive_lightbox_capabilities',
534
+ 'callback' => [ $this, 'validate_capabilities' ],
535
+ 'sections' => [
536
+ 'responsive_lightbox_capabilities_fields' => [
537
  'title' => __( 'Capabilities Settings', 'responsive-lightbox' ),
538
  'page' => 'responsive_lightbox_capabilities'
539
+ ],
540
+ 'responsive_lightbox_capabilities' => [
541
+ 'callback' => [ $this, 'capabilities_table' ]
542
+ ]
543
+ ],
544
  'prefix' => 'rl',
545
+ 'fields' => [
546
+ 'active' => [
547
  'title' => __( 'Capabilities', 'responsive-lightbox' ),
548
  'section' => 'responsive_lightbox_capabilities_fields',
549
  'type' => 'boolean',
550
  'label' => __( 'Enable advanced capability management.', 'responsive-lightbox' ),
551
  'description' => __( 'Check this to enable access to plugin features for selected user roles.', 'responsive-lightbox' )
552
+ ]
553
+ ]
554
+ ],
555
+ 'basicgrid_gallery' => [
556
  'option_group' => 'responsive_lightbox_basicgrid_gallery',
557
  'option_name' => 'responsive_lightbox_basicgrid_gallery',
558
+ 'sections' => [
559
+ 'responsive_lightbox_basicgrid_gallery' => [
560
  'title' => __( 'Basic Grid Gallery Settings', 'responsive-lightbox' )
561
+ ]
562
+ ],
563
  'prefix' => 'rl',
564
+ 'fields' => [
565
+ 'screen_size_columns' => [
566
  'title' => __( 'Screen sizes', 'responsive-lightbox' ),
567
  'section' => 'responsive_lightbox_basicgrid_gallery',
568
  'type' => 'multiple',
569
  'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
570
+ 'fields' => [
571
+ 'columns_lg' => [
572
  'type' => 'number',
573
  'min' => 0,
574
  'max' => 6,
575
  'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
576
+ ],
577
+ 'columns_md' => [
578
  'type' => 'number',
579
  'min' => 0,
580
  'max' => 6,
581
  'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
582
+ ],
583
+ 'columns_sm' => [
584
  'type' => 'number',
585
  'min' => 0,
586
  'max' => 6,
587
  'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
588
+ ],
589
+ 'columns_xs' => [
590
  'type' => 'number',
591
  'min' => 0,
592
  'max' => 6,
593
  'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
594
+ ]
595
+ ]
596
+ ],
597
+ 'gutter' => [
598
  'title' => __( 'Gutter', 'responsive-lightbox' ),
599
  'section' => 'responsive_lightbox_basicgrid_gallery',
600
  'type' => 'number',
601
  'min' => 0,
602
  'description' => __( 'Set the pixel width between the columns and rows.', 'responsive-lightbox' ),
603
  'append' => 'px'
604
+ ],
605
+ 'force_height' => [
606
  'title' => __( 'Force height', 'responsive-lightbox' ),
607
  'section' => 'responsive_lightbox_basicgrid_gallery',
608
  'type' => 'boolean',
609
  'label' => __( 'Enable to force the thumbnail row height.', 'responsive-lightbox' )
610
+ ],
611
+ 'row_height' => [
612
  'title' => __( 'Row height', 'responsive-lightbox' ),
613
  'section' => 'responsive_lightbox_basicgrid_gallery',
614
  'type' => 'number',
615
  'min' => 50,
616
  'description' => __( 'Enter the thumbnail row height in pixels (used if Force height is enabled). Defaults to 150px.', 'responsive-lightbox' ),
617
  'append' => 'px'
618
+ ]
619
+ ]
620
+ ],
621
+ 'basicslider_gallery' => [
622
  'option_group' => 'responsive_lightbox_basicslider_gallery',
623
  'option_name' => 'responsive_lightbox_basicslider_gallery',
624
+ 'sections' => [
625
+ 'responsive_lightbox_basicslider_gallery' => [
626
  'title' => __( 'Basic Slider Gallery Settings', 'responsive-lightbox' )
627
+ ]
628
+ ],
629
  'prefix' => 'rl',
630
+ 'fields' => [
631
+ 'adaptive_height' => [
632
  'title' => __( 'Adaptive Height', 'responsive-lightbox' ),
633
  'section' => 'responsive_lightbox_basicslider_gallery',
634
  'type' => 'boolean',
635
  'label' => __( 'The slider height should change on the fly according to the current slide.', 'responsive-lightbox' )
636
+ ],
637
+ 'loop' => [
638
  'title' => __( 'Loop', 'responsive-lightbox' ),
639
  'section' => 'responsive_lightbox_basicslider_gallery',
640
  'type' => 'boolean',
641
  'label' => __( 'Whether the slider should loop (i.e. the first slide goes to the last, the last slide goes to the first).', 'responsive-lightbox' )
642
+ ],
643
+ 'captions' => [
644
  'title' => __( 'Captions Position', 'responsive-lightbox' ),
645
  'section' => 'responsive_lightbox_basicslider_gallery',
646
  'type' => 'select',
647
  'description' => __( 'Specifies the position of captions or no captions at all.', 'responsive-lightbox' ),
648
+ 'options' => [
649
  'none' => __( 'None', 'responsive-lightbox' ),
650
  'overlay' => __( 'Overlay', 'responsive-lightbox' ),
651
  'below' => __( 'Below', 'responsive-lightbox' )
652
+ ]
653
+ ],
654
+ 'init_single' => [
655
  'title' => __( 'Single Image Slider', 'responsive-lightbox' ),
656
  'section' => 'responsive_lightbox_basicslider_gallery',
657
  'type' => 'boolean',
658
  'label' => __( 'Whether the slider should initialize even if there is only one slide element.', 'responsive-lightbox' )
659
+ ],
660
+ 'responsive' => [
661
  'title' => __( 'Responsive', 'responsive-lightbox' ),
662
  'section' => 'responsive_lightbox_basicslider_gallery',
663
  'type' => 'boolean',
664
  'label' => __( 'Whether the slider should be responsive.', 'responsive-lightbox' )
665
+ ],
666
+ 'preload' => [
667
  'title' => __( 'Preload', 'responsive-lightbox' ),
668
  'section' => 'responsive_lightbox_basicslider_gallery',
669
  'type' => 'select',
670
  'description' => __( 'Elements that are preloaded before slider shows.', 'responsive-lightbox' ),
671
+ 'options' => [
672
  'all' => __( 'All', 'responsive-lightbox' ),
673
  'visible' => __( 'Only visible', 'responsive-lightbox' )
674
+ ]
675
+ ],
676
+ 'pager' => [
677
  'title' => __( 'Pager', 'responsive-lightbox' ),
678
  'section' => 'responsive_lightbox_basicslider_gallery',
679
  'type' => 'boolean',
680
  'label' => __( 'Whether the slider should have a pager.', 'responsive-lightbox' )
681
+ ],
682
+ 'controls' => [
683
  'title' => __( 'Controls', 'responsive-lightbox' ),
684
  'section' => 'responsive_lightbox_basicslider_gallery',
685
  'type' => 'boolean',
686
  'label' => __( 'Whether the slider should have controls (next, previous arrows).', 'responsive-lightbox' )
687
+ ],
688
+ 'hide_on_end' => [
689
  'title' => __( 'Hide Controls on End', 'responsive-lightbox' ),
690
  'section' => 'responsive_lightbox_basicslider_gallery',
691
  'type' => 'boolean',
692
  'label' => __( 'Hide the previous or next control when it reaches the first or last slide respectively.', 'responsive-lightbox' )
693
+ ],
694
+ 'slide_margin' => [
695
  'title' => __( 'Slide Margin', 'responsive-lightbox' ),
696
  'section' => 'responsive_lightbox_basicslider_gallery',
697
  'type' => 'number',
698
  'min' => 0,
699
  'description' => __( 'The spacing between slides.', 'responsive-lightbox' ),
700
  'append' => '%'
701
+ ],
702
+ 'transition' => [
703
  'title' => __( 'Transition', 'responsive-lightbox' ),
704
  'section' => 'responsive_lightbox_basicslider_gallery',
705
  'type' => 'select',
706
  'description' => __( 'Transition type to use, or no transitions.', 'responsive-lightbox' ),
707
+ 'options' => [
708
  'none' => __( 'None', 'responsive-lightbox' ),
709
  'fade' => __( 'Fade', 'responsive-lightbox' ),
710
  'horizontal' => __( 'Horizontal', 'responsive-lightbox' ),
711
  'vertical' => __( 'Vertical', 'responsive-lightbox' ),
712
  'kenburns' => __( 'Ken Burns', 'responsive-lightbox' )
713
+ ]
714
+ ],
715
+ 'kenburns_zoom' => [
716
  'title' => __( 'Ken Burns Zoom', 'responsive-lightbox' ),
717
  'section' => 'responsive_lightbox_basicslider_gallery',
718
  'type' => 'number',
719
  'min' => 0,
720
  'description' => __( 'Max zoom level use for the Ken Burns transition.', 'responsive-lightbox' ),
721
  'append' => '%'
722
+ ],
723
+ 'speed' => [
724
  'title' => __( 'Transition Speed', 'responsive-lightbox' ),
725
  'section' => 'responsive_lightbox_basicslider_gallery',
726
  'type' => 'number',
727
  'min' => 0,
728
  'description' => __( 'The time the transition takes to complete.', 'responsive-lightbox' ),
729
  'append' => 'ms'
730
+ ],
731
+ 'easing' => [
732
  'title' => __( 'Easing Effect', 'responsive-lightbox' ),
733
  'section' => 'responsive_lightbox_basicslider_gallery',
734
  'type' => 'select',
735
  'description' => __( 'The easing effect to use for the selected transition.', 'responsive-lightbox' ),
736
+ 'options' => [
737
  'linear' => 'linear',
738
  'swing' => 'swing',
739
  'easeInQuad' => 'easeInQuad',
766
  'easeInBounce' => 'easeInBounce',
767
  'easeOutBounce' => 'easeOutBounce',
768
  'easeInOutBounce' => 'easeInOutBounce'
769
+ ]
770
+ ],
771
+ 'continuous' => [
772
  'title' => __( 'Continuous', 'responsive-lightbox' ),
773
  'section' => 'responsive_lightbox_basicslider_gallery',
774
  'type' => 'boolean',
775
  'label' => __( 'Whether the slider should run continuously (seamless transition between the first and last slides).', 'responsive-lightbox' )
776
+ ],
777
+ 'use_css' => [
778
  'title' => __( 'Use CSS', 'responsive-lightbox' ),
779
  'section' => 'responsive_lightbox_basicslider_gallery',
780
  'type' => 'boolean',
781
  'label' => __( 'Whether the slider should use CSS transitions. If the user\'s browser doesn\'t support CSS transitions the slider will fallback to jQuery.', 'responsive-lightbox' )
782
+ ],
783
+ 'slideshow' => [
784
  'title' => __( 'Slideshow', 'responsive-lightbox' ),
785
  'section' => 'responsive_lightbox_basicslider_gallery',
786
  'type' => 'boolean',
787
  'label' => __( 'Whether the slider should run automatically on load.', 'responsive-lightbox' )
788
+ ],
789
+ 'slideshow_direction' => [
790
  'title' => __( 'Slideshow Direction', 'responsive-lightbox' ),
791
  'section' => 'responsive_lightbox_basicslider_gallery',
792
  'type' => 'select',
793
  'description' => __( 'Which direction the slider should move in if in slideshow mode.', 'responsive-lightbox' ),
794
+ 'options' => [
795
  'next' => __( 'Next', 'responsive-lightbox' ),
796
  'prev' => __( 'Previous', 'responsive-lightbox' )
797
+ ]
798
+ ],
799
+ 'slideshow_hover' => [
800
  'title' => __( 'Slideshow Hover', 'responsive-lightbox' ),
801
  'section' => 'responsive_lightbox_basicslider_gallery',
802
  'type' => 'boolean',
803
  'label' => __( 'Whether the slideshow should pause automatically on hover.', 'responsive-lightbox' )
804
+ ],
805
+ 'slideshow_hover_delay' => [
806
  'title' => __( 'Slideshow Hover Delay', 'responsive-lightbox' ),
807
  'section' => 'responsive_lightbox_basicslider_gallery',
808
  'type' => 'number',
809
  'min' => 0,
810
  'description' => __( 'The delay (if any) before the slider resumes automatically after hover.', 'responsive-lightbox' ),
811
  'append' => 'ms'
812
+ ],
813
+ 'slideshow_delay' => [
814
  'title' => __( 'Slideshow Delay', 'responsive-lightbox' ),
815
  'section' => 'responsive_lightbox_basicslider_gallery',
816
  'type' => 'number',
817
  'min' => 0,
818
  'description' => __( 'The delay (if any) before the slider runs automatically on load.', 'responsive-lightbox' ),
819
  'append' => 'ms'
820
+ ],
821
+ 'slideshow_pause' => [
822
  'title' => __( 'Slideshow Pause', 'responsive-lightbox' ),
823
  'section' => 'responsive_lightbox_basicslider_gallery',
824
  'type' => 'number',
825
  'min' => 0,
826
  'description' => __( 'The time a slide lasts.', 'responsive-lightbox' ),
827
  'append' => 'ms'
828
+ ]
829
+ ]
830
+ ],
831
+ 'basicmasonry_gallery' => [
832
  'option_group' => 'responsive_lightbox_basicmasonry_gallery',
833
  'option_name' => 'responsive_lightbox_basicmasonry_gallery',
834
+ 'sections' => [
835
+ 'responsive_lightbox_basicmasonry_gallery' => [
836
  'title' => __( 'Basic Masonry Gallery Settings', 'responsive-lightbox' )
837
+ ]
838
+ ],
839
  'prefix' => 'rl',
840
+ 'fields' => [
841
+ 'screen_size_columns' => [
842
  'title' => __( 'Screen sizes', 'responsive-lightbox' ),
843
  'section' => 'responsive_lightbox_basicmasonry_gallery',
844
  'type' => 'multiple',
845
  'description' => __( 'Number of columns in a gallery depending on the device screen size. (if greater than 0 overrides the Columns option)', 'responsive-lightbox' ),
846
+ 'fields' => [
847
+ 'columns_lg' => [
848
  'type' => 'number',
849
  'min' => 0,
850
  'max' => 6,
851
  'default' => 4,
852
  'append' => __( 'large devices / desktops (&ge;1200px)', 'responsive-lightbox' )
853
+ ],
854
+ 'columns_md' => [
855
  'type' => 'number',
856
  'min' => 0,
857
  'max' => 6,
858
  'default' => 3,
859
  'append' => __( 'medium devices / desktops (&ge;992px)', 'responsive-lightbox' )
860
+ ],
861
+ 'columns_sm' => [
862
  'type' => 'number',
863
  'min' => 0,
864
  'max' => 6,
865
  'default' => 2,
866
  'append' => __( 'small devices / tablets (&ge;768px)', 'responsive-lightbox' )
867
+ ],
868
+ 'columns_xs' => [
869
  'type' => 'number',
870
  'min' => 0,
871
  'max' => 6,
872
  'default' => 2,
873
  'append' => __( 'extra small devices / phones (<768px)', 'responsive-lightbox' )
874
+ ]
875
+ ]
876
+ ],
877
+ 'gutter' => [
878
  'title' => __( 'Gutter', 'responsive-lightbox' ),
879
  'section' => 'responsive_lightbox_basicmasonry_gallery',
880
  'type' => 'number',
881
  'description' => __( 'Horizontal space between gallery items.', 'responsive-lightbox' ),
882
  'append' => 'px'
883
+ ],
884
+ 'margin' => [
885
  'title' => __( 'Margin', 'responsive-lightbox' ),
886
  'section' => 'responsive_lightbox_basicmasonry_gallery',
887
  'type' => 'number',
888
  'description' => __( 'Vertical space between gallery items.', 'responsive-lightbox' ),
889
  'append' => 'px'
890
+ ],
891
+ 'origin_left' => [
892
  'title' => __( 'Origin Left', 'responsive-lightbox' ),
893
  'section' => 'responsive_lightbox_basicmasonry_gallery',
894
  'type' => 'boolean',
895
  'label' => __( 'Enable left-to-right layouts.', 'responsive-lightbox' ),
896
  'description' => __( 'Controls the horizontal flow of the layout. By default, item elements start positioning at the left. Uncheck it for right-to-left layouts.', 'responsive-lightbox' )
897
+ ],
898
+ 'origin_top' => [
899
  'title' => __( 'Origin Top', 'responsive-lightbox' ),
900
  'section' => 'responsive_lightbox_basicmasonry_gallery',
901
  'type' => 'boolean',
902
  'label' => __( 'Enable top-to-bottom layouts.', 'responsive-lightbox' ),
903
  'description' => __( 'Controls the vetical flow of the layout. By default, item elements start positioning at the top. Uncheck it for bottom-up layouts.', 'responsive-lightbox' )
904
+ ]
905
+ ]
906
+ ]
907
+ ];
908
+
909
+ $this->tabs = apply_filters(
910
+ 'rl_settings_tabs',
911
+ [
912
+ 'settings' => [
913
+ 'name' => __( 'General', 'responsive-lightbox' ),
914
+ 'key' => 'responsive_lightbox_settings',
915
+ 'submit' => 'save_rl_settings',
916
+ 'reset' => 'reset_rl_settings'
917
+ ],
918
+ 'configuration' => [
919
+ 'name' => __( 'Lightboxes', 'responsive-lightbox' ),
920
+ 'key' => 'responsive_lightbox_configuration',
921
+ 'submit' => 'save_' . $this->settings['configuration']['prefix'] . '_configuration',
922
+ 'reset' => 'reset_' . $this->settings['configuration']['prefix'] . '_configuration',
923
+ 'sections' => $scripts,
924
+ 'default_section' => $rl->options['settings']['script']
925
+ ],
926
+ 'basicgrid_gallery' => [
927
+ 'name' => __( 'Basic Grid', 'responsive-lightbox' ),
928
+ 'key' => 'responsive_lightbox_basicgrid_gallery',
929
+ 'submit' => 'save_rl_basicgrid_gallery',
930
+ 'reset' => 'reset_rl_basicgrid_gallery'
931
+ ],
932
+ 'basicslider_gallery' => [
933
+ 'name' => __( 'Basic Slider', 'responsive-lightbox' ),
934
+ 'key' => 'responsive_lightbox_basiclider_gallery',
935
+ 'submit' => 'save_rl_basiclider_gallery',
936
+ 'reset' => 'reset_rl_basiclider_gallery'
937
+ ],
938
+ 'basicmasonry_gallery' => [
939
+ 'name' => __( 'Basic Masonry', 'responsive-lightbox' ),
940
+ 'key' => 'responsive_lightbox_basicmasonry_gallery',
941
+ 'submit' => 'save_rl_basicmasonry_gallery',
942
+ 'reset' => 'reset_rl_basicmasonry_gallery'
943
+ ]
944
+ ]
945
  );
946
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
  $tabs_copy = $this->tabs;
948
  $tab_key = '';
949
+ $section_key = isset( $_REQUEST['section'] ) ? sanitize_key( $_REQUEST['section'] ) : '';
950
 
951
  // set current tab and section
952
+ if ( is_admin() && ! wp_doing_ajax() ) {
953
  global $pagenow;
954
 
955
+ // check page
956
+ $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
957
+
958
  // check settings page
959
+ if ( $pagenow === 'options.php' || ( $pagenow == 'admin.php' && $page && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $this->tabs + [ 'gallery' => '', 'addons' => '' ] ) ) . ')$/', $page, $tabs ) === 1 ) ) {
960
+ // set tab key
961
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
962
+
963
+ // set section key
964
+ if ( ! $section_key )
965
+ $section_key = ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '';
966
  }
967
  }
968
 
970
  $gallery_types = $rl->gallery_types;
971
 
972
  // remove default gallery
973
+ if ( isset( $gallery_types['default'] ) )
974
+ unset( $gallery_types['default'] );
975
 
976
  // get available galleries
977
  $gallery_types = apply_filters( 'rl_gallery_types', $gallery_types );
986
 
987
  // backward compatibility, remove from tabs
988
  $gallery_tabs = array_intersect( array_keys( $this->tabs ), array_keys( $gallery_types ) );
989
+ $galleries = [];
990
 
991
  if ( ! empty( $gallery_tabs ) ) {
992
  // unset tabs if exist
1000
  $gallery_sections[$key] = $gallery['name'];
1001
  }
1002
 
1003
+ if ( $tab_key == 'gallery' ) {
1004
+ if ( ! $section_key ) {
1005
+ $section_key = in_array( $rl->options['settings']['default_gallery'] . '_gallery', array_keys( $gallery_sections ) ) ? $rl->options['settings']['default_gallery'] . '_gallery' : key( $gallery_sections );
1006
+ }
1007
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
 
1009
+ $this->tabs['gallery'] = [
1010
+ 'name' => __( 'Galleries', 'responsive-lightbox' ),
1011
+ 'key' => 'responsive_lightbox_' . $section_key,
1012
+ 'submit' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['submit'] : 'save_' . $section_key . '_configuration',
1013
+ 'reset' => array_key_exists( $section_key, $tabs_copy ) ? $tabs_copy[$section_key]['reset'] : 'reset_rl_' . $section_key,
1014
+ 'sections' => $gallery_sections,
1015
+ 'default_section' => $section_key
1016
+ ];
1017
+ }
1018
 
1019
+ $this->tabs['builder'] = [
1020
+ 'name' => __( 'Builder', 'responsive-lightbox' ),
1021
+ 'key' => 'responsive_lightbox_builder',
1022
+ 'submit' => 'save_rl_builder',
1023
+ 'reset' => 'reset_rl_builder'
1024
+ ];
1025
+
1026
+ $this->tabs['folders'] = [
1027
+ 'name' => __( 'Folders', 'responsive-lightbox' ),
1028
+ 'key' => 'responsive_lightbox_folders',
1029
+ 'submit' => 'save_rl_folders',
1030
+ 'reset' => 'reset_rl_folders'
1031
+ ];
1032
+
1033
+ $this->tabs['capabilities'] = [
1034
+ 'name' => __( 'Capabilities', 'responsive-lightbox' ),
1035
+ 'key' => 'responsive_lightbox_capabilities',
1036
+ 'submit' => 'save_rl_capabilities',
1037
+ 'reset' => 'reset_rl_capabilities'
1038
+ ];
1039
+
1040
+ $this->tabs['remote_library'] = [
1041
+ 'name' => __( 'Remote Library', 'responsive-lightbox' ),
1042
+ 'key' => 'responsive_lightbox_remote_library',
1043
+ 'submit' => 'save_rl_remote_library',
1044
+ 'reset' => 'reset_rl_remote_library'
1045
+ ];
1046
 
1047
  $this->tabs = apply_filters( 'rl_settings_tabs_extra', $this->tabs );
1048
 
1050
  if ( isset( $this->tabs['licenses'] ) ) {
1051
  unset( $this->tabs['licenses'] );
1052
 
1053
+ $this->tabs['licenses'] = [
1054
+ 'name' => __( 'Licenses', 'responsive-lightbox' ),
1055
+ 'key' => 'responsive_lightbox_licenses',
1056
+ 'submit' => 'save_rl_licenses',
1057
+ 'reset' => 'reset_rl_licenses'
1058
+ ];
1059
  }
1060
 
1061
+ $this->tabs['addons'] = [
1062
+ 'name' => __( 'Add-ons', 'responsive-lightbox' ),
1063
+ 'key' => 'responsive_lightbox_configuration',
1064
+ 'callback' => [ $this, 'addons_tab_cb' ]
1065
+ ];
1066
 
1067
+ if ( isset( $this->tabs[$tab_key]['sections'][$section_key] ) && empty( $this->tabs[$tab_key]['sections']['responsive_lightbox_' . $tab_key]['title'] ) )
1068
  $this->settings[$tab_key]['sections']['responsive_lightbox_' . $tab_key]['title'] = sprintf( __( '%s Settings', 'responsive-lightbox' ), $this->tabs[$tab_key]['sections'][$section_key] );
 
1069
 
1070
  switch ( ! empty( $section_key ) ? $section_key : $rl->options['settings']['script'] ) {
1071
  case 'swipebox':
1072
  $this->settings['configuration']['prefix'] = 'rl_sb';
1073
+ $this->settings['configuration']['fields'] = [
1074
+ 'animation' => [
1075
  'title' => __( 'Animation type', 'responsive-lightbox' ),
1076
  'section' => 'responsive_lightbox_configuration',
1077
  'type' => 'radio',
1079
  'description' => __( 'Select a method of applying a lightbox effect.', 'responsive-lightbox' ),
1080
  'options' => $this->scripts['swipebox']['animations'],
1081
  'parent' => 'swipebox'
1082
+ ],
1083
+ 'force_png_icons' => [
1084
  'title' => __( 'Force PNG icons', 'responsive-lightbox' ),
1085
  'section' => 'responsive_lightbox_configuration',
1086
  'type' => 'boolean',
1087
  'label' => __( 'Enable this if you\'re having problems with navigation icons not visible on some devices.', 'responsive-lightbox' ),
1088
  'parent' => 'swipebox'
1089
+ ],
1090
+ 'hide_close_mobile' => [
1091
  'title' => __( 'Hide close on mobile', 'responsive-lightbox' ),
1092
  'section' => 'responsive_lightbox_configuration',
1093
  'type' => 'boolean',
1094
  'label' => __( 'Hide the close button on mobile devices.', 'responsive-lightbox' ),
1095
  'parent' => 'swipebox'
1096
+ ],
1097
+ 'remove_bars_mobile' => [
1098
  'title' => __( 'Remove bars on mobile', 'responsive-lightbox' ),
1099
  'section' => 'responsive_lightbox_configuration',
1100
  'type' => 'boolean',
1101
  'label' => __( 'Hide the top and bottom bars on mobile devices.', 'responsive-lightbox' ),
1102
  'parent' => 'swipebox'
1103
+ ],
1104
+ 'hide_bars' => [
1105
  'title' => __( 'Top and bottom bars', 'responsive-lightbox' ),
1106
  'section' => 'responsive_lightbox_configuration',
1107
  'type' => 'multiple',
1108
+ 'fields' => [
1109
+ 'hide_bars' => [
1110
  'type' => 'boolean',
1111
  'label' => __( 'Hide top and bottom bars after a period of time.', 'responsive-lightbox' ),
1112
  'parent' => 'swipebox'
1113
+ ],
1114
+ 'hide_bars_delay' => [
1115
  'type' => 'number',
1116
  'description' => __( 'Enter the time after which the top and bottom bars will be hidden (when hiding is enabled).', 'responsive-lightbox' ),
1117
  'append' => 'ms',
1118
  'parent' => 'swipebox'
1119
+ ]
1120
+ ]
1121
+ ],
1122
+ 'video_max_width' => [
1123
  'title' => __( 'Video max width', 'responsive-lightbox' ),
1124
  'section' => 'responsive_lightbox_configuration',
1125
  'type' => 'number',
1126
  'description' => __( 'Enter the max video width in a lightbox.', 'responsive-lightbox' ),
1127
  'append' => 'px',
1128
  'parent' => 'swipebox'
1129
+ ],
1130
+ 'loop_at_end' => [
1131
  'title' => __( 'Loop at end', 'responsive-lightbox' ),
1132
  'section' => 'responsive_lightbox_configuration',
1133
  'type' => 'boolean',
1134
  'label' => __( 'True will return to the first image after the last image is reached.', 'responsive-lightbox' ),
1135
  'parent' => 'swipebox'
1136
+ ]
1137
+ ];
1138
  break;
1139
 
1140
  case 'prettyphoto':
1141
  $this->settings['configuration']['prefix'] = 'rl_pp';
1142
+ $this->settings['configuration']['fields'] = [
1143
+ 'animation_speed' => [
1144
  'title' => __( 'Animation speed', 'responsive-lightbox' ),
1145
  'section' => 'responsive_lightbox_configuration',
1146
  'type' => 'radio',
1148
  'description' => __( 'Select animation speed for lightbox effect.', 'responsive-lightbox' ),
1149
  'options' => $this->scripts['prettyphoto']['animation_speeds'],
1150
  'parent' => 'prettyphoto'
1151
+ ],
1152
+ 'slideshow' => [
1153
  'title' => __( 'Slideshow', 'responsive-lightbox' ),
1154
  'section' => 'responsive_lightbox_configuration',
1155
  'type' => 'multiple',
1156
+ 'fields' => [
1157
+ 'slideshow' => [
1158
  'type' => 'boolean',
1159
  'label' => __( 'Display images as slideshow', 'responsive-lightbox' ),
1160
  'parent' => 'prettyphoto'
1161
+ ],
1162
+ 'slideshow_delay' => [
1163
  'type' => 'number',
1164
  'description' => __( 'Enter time (in miliseconds).', 'responsive-lightbox' ),
1165
  'append' => 'ms',
1166
  'parent' => 'prettyphoto'
1167
+ ]
1168
+ ]
1169
+ ],
1170
+ 'slideshow_autoplay' => [
1171
  'title' => __( 'Slideshow autoplay', 'responsive-lightbox' ),
1172
  'section' => 'responsive_lightbox_configuration',
1173
  'type' => 'boolean',
1174
  'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
1175
  'parent' => 'prettyphoto'
1176
+ ],
1177
+ 'opacity' => [
1178
  'title' => __( 'Opacity', 'responsive-lightbox' ),
1179
  'section' => 'responsive_lightbox_configuration',
1180
  'type' => 'range',
1182
  'min' => 0,
1183
  'max' => 100,
1184
  'parent' => 'prettyphoto'
1185
+ ],
1186
+ 'show_title' => [
1187
  'title' => __( 'Show title', 'responsive-lightbox' ),
1188
  'section' => 'responsive_lightbox_configuration',
1189
  'type' => 'boolean',
1190
  'label' => __( 'Display image title.', 'responsive-lightbox' ),
1191
  'parent' => 'prettyphoto'
1192
+ ],
1193
+ 'allow_resize' => [
1194
  'title' => __( 'Allow resize big images', 'responsive-lightbox' ),
1195
  'section' => 'responsive_lightbox_configuration',
1196
  'type' => 'boolean',
1197
  'label' => __( 'Resize the photos bigger than viewport.', 'responsive-lightbox' ),
1198
  'parent' => 'prettyphoto'
1199
+ ],
1200
+ 'allow_expand' => [
1201
  'title' => __( 'Allow expand', 'responsive-lightbox' ),
1202
  'section' => 'responsive_lightbox_configuration',
1203
  'type' => 'boolean',
1204
  'label' => __( 'Allow expanding images.', 'responsive-lightbox' ),
1205
  'parent' => 'prettyphoto'
1206
+ ],
1207
+ 'width' => [
1208
  'title' => __( 'Video width', 'responsive-lightbox' ),
1209
  'section' => 'responsive_lightbox_configuration',
1210
  'type' => 'number',
1211
  'append' => 'px',
1212
  'parent' => 'prettyphoto'
1213
+ ],
1214
+ 'height' => [
1215
  'title' => __( 'Video height', 'responsive-lightbox' ),
1216
  'section' => 'responsive_lightbox_configuration',
1217
  'type' => 'number',
1218
  'append' => 'px',
1219
  'parent' => 'prettyphoto'
1220
+ ],
1221
+ 'theme' => [
1222
  'title' => __( 'Theme', 'responsive-lightbox' ),
1223
  'section' => 'responsive_lightbox_configuration',
1224
  'type' => 'radio',
1225
  'description' => __( 'Select the theme for lightbox effect.', 'responsive-lightbox' ),
1226
  'options' => $this->scripts['prettyphoto']['themes'],
1227
  'parent' => 'prettyphoto'
1228
+ ],
1229
+ 'horizontal_padding' => [
1230
  'title' => __( 'Horizontal padding', 'responsive-lightbox' ),
1231
  'section' => 'responsive_lightbox_configuration',
1232
  'type' => 'number',
1233
  'append' => 'px',
1234
  'parent' => 'prettyphoto'
1235
+ ],
1236
+ 'hide_flash' => [
1237
  'title' => __( 'Hide Flash', 'responsive-lightbox' ),
1238
  'section' => 'responsive_lightbox_configuration',
1239
  'type' => 'boolean',
1240
  'label' => __( 'Hide all the flash objects on a page. Enable this if flash appears over prettyPhoto.', 'responsive-lightbox' ),
1241
  'parent' => 'prettyphoto'
1242
+ ],
1243
+ 'wmode' => [
1244
  'title' => __( 'Flash Window Mode (wmode)', 'responsive-lightbox' ),
1245
  'section' => 'responsive_lightbox_configuration',
1246
  'type' => 'radio',
1247
  'description' => __( 'Select flash window mode.', 'responsive-lightbox' ),
1248
  'options' => $this->scripts['prettyphoto']['wmodes'],
1249
  'parent' => 'prettyphoto'
1250
+ ],
1251
+ 'video_autoplay' => [
1252
  'title' => __( 'Video autoplay', 'responsive-lightbox' ),
1253
  'section' => 'responsive_lightbox_configuration',
1254
  'type' => 'boolean',
1255
  'label' => __( 'Automatically start videos.', 'responsive-lightbox' ),
1256
  'parent' => 'prettyphoto'
1257
+ ],
1258
+ 'modal' => [
1259
  'title' => __( 'Modal', 'responsive-lightbox' ),
1260
  'section' => 'responsive_lightbox_configuration',
1261
  'type' => 'boolean',
1262
  'label' => __( 'If set to true, only the close button will close the window.', 'responsive-lightbox' ),
1263
  'parent' => 'prettyphoto'
1264
+ ],
1265
+ 'deeplinking' => [
1266
  'title' => __( 'Deeplinking', 'responsive-lightbox' ),
1267
  'section' => 'responsive_lightbox_configuration',
1268
  'type' => 'boolean',
1269
  'label' => __( 'Allow prettyPhoto to update the url to enable deeplinking.', 'responsive-lightbox' ),
1270
  'parent' => 'prettyphoto'
1271
+ ],
1272
+ 'overlay_gallery' => [
1273
  'title' => __( 'Overlay gallery', 'responsive-lightbox' ),
1274
  'section' => 'responsive_lightbox_configuration',
1275
  'type' => 'boolean',
1276
  'label' => __( 'If enabled, a gallery will overlay the fullscreen image on mouse over.', 'responsive-lightbox' ),
1277
  'parent' => 'prettyphoto'
1278
+ ],
1279
+ 'keyboard_shortcuts' => [
1280
  'title' => __( 'Keyboard shortcuts', 'responsive-lightbox' ),
1281
  'section' => 'responsive_lightbox_configuration',
1282
  'type' => 'boolean',
1283
  'label' => __( 'Set to false if you open forms inside prettyPhoto.', 'responsive-lightbox' ),
1284
  'parent' => 'prettyphoto'
1285
+ ],
1286
+ 'social' => [
1287
  'title' => __( 'Social (Twitter, Facebook)', 'responsive-lightbox' ),
1288
  'section' => 'responsive_lightbox_configuration',
1289
  'type' => 'boolean',
1290
  'label' => __( 'Display links to Facebook and Twitter.', 'responsive-lightbox' ),
1291
  'parent' => 'prettyphoto'
1292
+ ]
1293
+ ];
1294
  break;
1295
 
1296
  case 'fancybox':
1297
  $this->settings['configuration']['prefix'] = 'rl_fb';
1298
+ $this->settings['configuration']['fields'] = [
1299
+ 'modal' => [
1300
  'title' => __( 'Modal', 'responsive-lightbox' ),
1301
  'section' => 'responsive_lightbox_configuration',
1302
  'type' => 'boolean',
1303
  'label' => __( 'When true, "overlayShow" is set to true and "hideOnOverlayClick", "hideOnContentClick", "enableEscapeButton", "showCloseButton" are set to false.', 'responsive-lightbox' ),
1304
  'parent' => 'fancybox'
1305
+ ],
1306
+ 'show_overlay' => [
1307
  'title' => __( 'Show overlay', 'responsive-lightbox' ),
1308
  'section' => 'responsive_lightbox_configuration',
1309
  'type' => 'boolean',
1310
  'label' => __( 'Toggle overlay.', 'responsive-lightbox' ),
1311
  'parent' => 'fancybox'
1312
+ ],
1313
+ 'show_close_button' => [
1314
  'title' => __( 'Show close button', 'responsive-lightbox' ),
1315
  'section' => 'responsive_lightbox_configuration',
1316
  'type' => 'boolean',
1317
  'label' => __( 'Toggle close button.', 'responsive-lightbox' ),
1318
  'parent' => 'fancybox'
1319
+ ],
1320
+ 'enable_escape_button' => [
1321
  'title' => __( 'Enable escape button', 'responsive-lightbox' ),
1322
  'section' => 'responsive_lightbox_configuration',
1323
  'type' => 'boolean',
1324
  'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
1325
  'parent' => 'fancybox'
1326
+ ],
1327
+ 'hide_on_overlay_click' => [
1328
  'title' => __( 'Hide on overlay click', 'responsive-lightbox' ),
1329
  'section' => 'responsive_lightbox_configuration',
1330
  'type' => 'boolean',
1331
  'label' => __( 'Toggle if clicking the overlay should close FancyBox.', 'responsive-lightbox' ),
1332
  'parent' => 'fancybox'
1333
+ ],
1334
+ 'hide_on_content_click' => [
1335
  'title' => __( 'Hide on content click', 'responsive-lightbox' ),
1336
  'section' => 'responsive_lightbox_configuration',
1337
  'type' => 'boolean',
1338
  'label' => __( 'Toggle if clicking the content should close FancyBox.', 'responsive-lightbox' ),
1339
  'parent' => 'fancybox'
1340
+ ],
1341
+ 'cyclic' => [
1342
  'title' => __( 'Cyclic', 'responsive-lightbox' ),
1343
  'section' => 'responsive_lightbox_configuration',
1344
  'type' => 'boolean',
1345
  'label' => __( 'When true, galleries will be cyclic, allowing you to keep pressing next/back.', 'responsive-lightbox' ),
1346
  'parent' => 'fancybox'
1347
+ ],
1348
+ 'show_nav_arrows' => [
1349
  'title' => __( 'Show nav arrows', 'responsive-lightbox' ),
1350
  'section' => 'responsive_lightbox_configuration',
1351
  'type' => 'boolean',
1352
  'label' => __( 'Toggle navigation arrows.', 'responsive-lightbox' ),
1353
  'parent' => 'fancybox'
1354
+ ],
1355
+ 'auto_scale' => [
1356
  'title' => __( 'Auto scale', 'responsive-lightbox' ),
1357
  'section' => 'responsive_lightbox_configuration',
1358
  'type' => 'boolean',
1359
  'label' => __( 'If true, FancyBox is scaled to fit in viewport.', 'responsive-lightbox' ),
1360
  'parent' => 'fancybox'
1361
+ ],
1362
+ 'scrolling' => [
1363
  'title' => __( 'Scrolling (in/out)', 'responsive-lightbox' ),
1364
  'section' => 'responsive_lightbox_configuration',
1365
  'type' => 'radio',
1366
  'description' => __( 'Set the overflow CSS property to create or hide scrollbars.', 'responsive-lightbox' ),
1367
  'options' => $this->scripts['fancybox']['scrollings'],
1368
  'parent' => 'fancybox'
1369
+ ],
1370
+ 'center_on_scroll' => [
1371
  'title' => __( 'Center on scroll', 'responsive-lightbox' ),
1372
  'section' => 'responsive_lightbox_configuration',
1373
  'type' => 'boolean',
1374
  'label' => __( 'When true, FancyBox is centered while scrolling page.', 'responsive-lightbox' ),
1375
  'parent' => 'fancybox'
1376
+ ],
1377
+ 'opacity' => [
1378
  'title' => __( 'Opacity', 'responsive-lightbox' ),
1379
  'section' => 'responsive_lightbox_configuration',
1380
  'type' => 'boolean',
1381
  'label' => __( 'When true, transparency of content is changed for elastic transitions.', 'responsive-lightbox' ),
1382
  'parent' => 'fancybox'
1383
+ ],
1384
+ 'overlay_opacity' => [
1385
  'title' => __( 'Overlay opacity', 'responsive-lightbox' ),
1386
  'section' => 'responsive_lightbox_configuration',
1387
  'type' => 'range',
1389
  'min' => 0,
1390
  'max' => 100,
1391
  'parent' => 'fancybox'
1392
+ ],
1393
+ 'overlay_color' => [
1394
  'title' => __( 'Overlay color', 'responsive-lightbox' ),
1395
  'section' => 'responsive_lightbox_configuration',
1396
  'type' => 'color_picker',
1397
  'label' => __( 'Color of the overlay.', 'responsive-lightbox' ),
1398
  'parent' => 'fancybox'
1399
+ ],
1400
+ 'title_show' => [
1401
  'title' => __( 'Title show', 'responsive-lightbox' ),
1402
  'section' => 'responsive_lightbox_configuration',
1403
  'type' => 'boolean',
1404
  'label' => __( 'Toggle title.', 'responsive-lightbox' ),
1405
  'parent' => 'fancybox'
1406
+ ],
1407
+ 'title_position' => [
1408
  'title' => __( 'Title position', 'responsive-lightbox' ),
1409
  'section' => 'responsive_lightbox_configuration',
1410
  'type' => 'radio',
1411
  'description' => __( 'The position of title.', 'responsive-lightbox' ),
1412
  'options' => $this->scripts['fancybox']['positions'],
1413
  'parent' => 'fancybox'
1414
+ ],
1415
+ 'transitions' => [
1416
  'title' => __( 'Transition (in/out)', 'responsive-lightbox' ),
1417
  'section' => 'responsive_lightbox_configuration',
1418
  'type' => 'radio',
1419
  'description' => __( 'The transition type.', 'responsive-lightbox' ),
1420
  'options' => $this->scripts['fancybox']['transitions'],
1421
  'parent' => 'fancybox'
1422
+ ],
1423
+ 'easings' => [
1424
  'title' => __( 'Easings (in/out)', 'responsive-lightbox' ),
1425
  'section' => 'responsive_lightbox_configuration',
1426
  'type' => 'radio',
1427
  'description' => __( 'Easing used for elastic animations.', 'responsive-lightbox' ),
1428
  'options' => $this->scripts['fancybox']['easings'],
1429
  'parent' => 'fancybox'
1430
+ ],
1431
+ 'speeds' => [
1432
  'title' => __( 'Speed (in/out)', 'responsive-lightbox' ),
1433
  'section' => 'responsive_lightbox_configuration',
1434
  'type' => 'number',
1435
  'description' => __( 'Speed of the fade and elastic transitions, in milliseconds.', 'responsive-lightbox' ),
1436
  'append' => 'ms',
1437
  'parent' => 'fancybox'
1438
+ ],
1439
+ 'change_speed' => [
1440
  'title' => __( 'Change speed', 'responsive-lightbox' ),
1441
  'section' => 'responsive_lightbox_configuration',
1442
  'type' => 'number',
1443
  'description' => __( 'Speed of resizing when changing gallery items, in milliseconds.', 'responsive-lightbox' ),
1444
  'append' => 'ms',
1445
  'parent' => 'fancybox'
1446
+ ],
1447
+ 'change_fade' => [
1448
  'title' => __( 'Change fade', 'responsive-lightbox' ),
1449
  'section' => 'responsive_lightbox_configuration',
1450
  'type' => 'number',
1451
  'description' => __( 'Speed of the content fading while changing gallery items.', 'responsive-lightbox' ),
1452
  'append' => 'ms',
1453
  'parent' => 'fancybox'
1454
+ ],
1455
+ 'padding' => [
1456
  'title' => __( 'Padding', 'responsive-lightbox' ),
1457
  'section' => 'responsive_lightbox_configuration',
1458
  'type' => 'number',
1459
  'description' => __( 'Space between FancyBox wrapper and content.', 'responsive-lightbox' ),
1460
  'append' => 'px',
1461
  'parent' => 'fancybox'
1462
+ ],
1463
+ 'margin' => [
1464
  'title' => __( 'Margin', 'responsive-lightbox' ),
1465
  'section' => 'responsive_lightbox_configuration',
1466
  'type' => 'number',
1467
  'description' => __( 'Space between viewport and FancyBox wrapper.', 'responsive-lightbox' ),
1468
  'append' => 'px',
1469
  'parent' => 'fancybox'
1470
+ ],
1471
+ 'video_width' => [
1472
  'title' => __( 'Video width', 'responsive-lightbox' ),
1473
  'section' => 'responsive_lightbox_configuration',
1474
  'type' => 'number',
1475
  'description' => __( 'Width of the video.', 'responsive-lightbox' ),
1476
  'append' => 'px',
1477
  'parent' => 'fancybox'
1478
+ ],
1479
+ 'video_height' => [
1480
  'title' => __( 'Video height', 'responsive-lightbox' ),
1481
  'section' => 'responsive_lightbox_configuration',
1482
  'type' => 'number',
1483
  'description' => __( 'Height of the video.', 'responsive-lightbox' ),
1484
  'append' => 'px',
1485
  'parent' => 'fancybox'
1486
+ ]
1487
+ ];
1488
  break;
1489
 
1490
  case 'nivo':
1491
  $this->settings['configuration']['prefix'] = 'rl_nv';
1492
+ $this->settings['configuration']['fields'] = [
1493
+ 'effect' => [
1494
  'title' => __( 'Effect', 'responsive-lightbox' ),
1495
  'section' => 'responsive_lightbox_configuration',
1496
  'type' => 'radio',
1497
  'description' => __( 'The effect to use when showing the lightbox.', 'responsive-lightbox' ),
1498
  'options' => $this->scripts['nivo']['effects'],
1499
  'parent' => 'nivo'
1500
+ ],
1501
+ 'keyboard_nav' => [
1502
  'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
1503
  'section' => 'responsive_lightbox_configuration',
1504
  'type' => 'boolean',
1505
  'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
1506
  'parent' => 'nivo'
1507
+ ],
1508
+ 'click_overlay_to_close' => [
1509
  'title' => __( 'Click overlay to close', 'responsive-lightbox' ),
1510
  'section' => 'responsive_lightbox_configuration',
1511
  'type' => 'boolean',
1512
  'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
1513
  'parent' => 'nivo'
1514
+ ],
1515
+ 'error_message' => [
1516
  'title' => __( 'Error message', 'responsive-lightbox' ),
1517
  'section' => 'responsive_lightbox_configuration',
1518
  'type' => 'text',
1519
  'class' => 'large-text',
1520
  'label' => __( 'Error message if the content cannot be loaded.', 'responsive-lightbox' ),
1521
  'parent' => 'nivo'
1522
+ ],
1523
+ ];
1524
  break;
1525
 
1526
  case 'imagelightbox':
1527
  $this->settings['configuration']['prefix'] = 'rl_il';
1528
+ $this->settings['configuration']['fields'] = [
1529
+ 'animation_speed' => [
1530
  'title' => __( 'Animation speed', 'responsive-lightbox' ),
1531
  'section' => 'responsive_lightbox_configuration',
1532
  'type' => 'number',
1533
  'description' => __( 'Animation speed.', 'responsive-lightbox' ),
1534
  'append' => 'ms',
1535
  'parent' => 'imagelightbox'
1536
+ ],
1537
+ 'preload_next' => [
1538
  'title' => __( 'Preload next image', 'responsive-lightbox' ),
1539
  'section' => 'responsive_lightbox_configuration',
1540
  'type' => 'boolean',
1541
  'label' => __( 'Silently preload the next image.', 'responsive-lightbox' ),
1542
  'parent' => 'imagelightbox'
1543
+ ],
1544
+ 'enable_keyboard' => [
1545
  'title' => __( 'Enable keyboard keys', 'responsive-lightbox' ),
1546
  'section' => 'responsive_lightbox_configuration',
1547
  'type' => 'boolean',
1548
  'label' => __( 'Enable keyboard shortcuts (arrows Left/Right and Esc).', 'responsive-lightbox' ),
1549
  'parent' => 'imagelightbox'
1550
+ ],
1551
+ 'quit_on_end' => [
1552
  'title' => __( 'Quit after last image', 'responsive-lightbox' ),
1553
  'section' => 'responsive_lightbox_configuration',
1554
  'type' => 'boolean',
1555
  'label' => __( 'Quit after viewing the last image.', 'responsive-lightbox' ),
1556
  'parent' => 'imagelightbox'
1557
+ ],
1558
+ 'quit_on_image_click' => [
1559
  'title' => __( 'Quit on image click', 'responsive-lightbox' ),
1560
  'section' => 'responsive_lightbox_configuration',
1561
  'type' => 'boolean',
1562
  'label' => __( 'Quit when the viewed image is clicked.', 'responsive-lightbox' ),
1563
  'parent' => 'imagelightbox'
1564
+ ],
1565
+ 'quit_on_document_click' => [
1566
  'title' => __( 'Quit on anything click', 'responsive-lightbox' ),
1567
  'section' => 'responsive_lightbox_configuration',
1568
  'type' => 'boolean',
1569
  'label' => __( 'Quit when anything but the viewed image is clicked.', 'responsive-lightbox' ),
1570
  'parent' => 'imagelightbox'
1571
+ ],
1572
+ ];
1573
  break;
1574
 
1575
  case 'tosrus':
1576
  $this->settings['configuration']['prefix'] = 'rl_tr';
1577
+ $this->settings['configuration']['fields'] = [
1578
+ 'effect' => [
1579
  'title' => __( 'Transition effect', 'responsive-lightbox' ),
1580
  'section' => 'responsive_lightbox_configuration',
1581
  'type' => 'radio',
1582
  'description' => __( 'What effect to use for the transition.', 'responsive-lightbox' ),
1583
+ 'options' => [
1584
  'slide' => __( 'slide', 'responsive-lightbox' ),
1585
  'fade' => __( 'fade', 'responsive-lightbox' )
1586
+ ],
1587
  'parent' => 'tosrus'
1588
+ ],
1589
+ 'infinite' => [
1590
  'title' => __( 'Infinite loop', 'responsive-lightbox' ),
1591
  'section' => 'responsive_lightbox_configuration',
1592
  'type' => 'boolean',
1593
  'label' => __( 'Whether or not to slide back to the first slide when the last has been reached.', 'responsive-lightbox' ),
1594
  'parent' => 'tosrus'
1595
+ ],
1596
+ 'keys' => [
1597
  'title' => __( 'Keyboard navigation', 'responsive-lightbox' ),
1598
  'section' => 'responsive_lightbox_configuration',
1599
  'type' => 'boolean',
1600
  'label' => __( 'Enable keyboard navigation (left/right/escape).', 'responsive-lightbox' ),
1601
  'parent' => 'tosrus'
1602
+ ],
1603
+ 'autoplay' => [
1604
  'title' => __( 'Autoplay', 'responsive-lightbox' ),
1605
  'section' => 'responsive_lightbox_configuration',
1606
  'type' => 'multiple',
1607
+ 'fields' => [
1608
+ 'autoplay' => [
1609
  'type' => 'boolean',
1610
  'label' => __( 'Automatically start slideshow.', 'responsive-lightbox' ),
1611
  'parent' => 'tosrus'
1612
+ ],
1613
+ 'timeout' => [
1614
  'type' => 'number',
1615
  'description' => __( 'The timeout between sliding to the next slide in milliseconds.', 'responsive-lightbox' ),
1616
  'append' => 'ms',
1617
  'parent' => 'tosrus'
1618
+ ]
1619
+ ]
1620
+ ],
1621
+ 'pause_on_hover' => [
1622
  'title' => __( 'Pause on hover', 'responsive-lightbox' ),
1623
  'section' => 'responsive_lightbox_configuration',
1624
  'type' => 'boolean',
1625
  'label' => __( 'Whether or not to pause on hover.', 'responsive-lightbox' ),
1626
  'parent' => 'tosrus'
1627
+ ],
1628
+ 'pagination' => [
1629
  'title' => __( 'Pagination', 'responsive-lightbox' ),
1630
  'section' => 'responsive_lightbox_configuration',
1631
  'type' => 'multiple',
1632
+ 'fields' => [
1633
+ 'pagination' => [
1634
  'type' => 'boolean',
1635
  'label' => __( 'Whether or not to add a pagination.', 'responsive-lightbox' ),
1636
  'parent' => 'tosrus'
1637
+ ],
1638
+ 'pagination_type' => [
1639
  'type' => 'radio',
1640
  'description' => __( 'What type of pagination to use.', 'responsive-lightbox' ),
1641
+ 'options' => [
1642
  'bullets' => __( 'Bullets', 'responsive-lightbox' ),
1643
  'thumbnails' => __( 'Thumbnails', 'responsive-lightbox' )
1644
+ ],
1645
  'parent' => 'tosrus'
1646
+ ]
1647
+ ]
1648
+ ],
1649
+ 'close_on_click' => [
1650
  'title' => __( 'Overlay close', 'responsive-lightbox' ),
1651
  'section' => 'responsive_lightbox_configuration',
1652
  'type' => 'boolean',
1653
  'label' => __( 'Enable to close lightbox on overlay click.', 'responsive-lightbox' ),
1654
  'parent' => 'tosrus'
1655
+ ]
1656
+ ];
1657
  break;
1658
 
1659
  case 'featherlight':
1660
  $this->settings['configuration']['prefix'] = 'rl_fl';
1661
+ $this->settings['configuration']['fields'] = [
1662
+ 'open_speed' => [
1663
  'title' => __( 'Opening speed', 'responsive-lightbox' ),
1664
  'section' => 'responsive_lightbox_configuration',
1665
  'type' => 'number',
1666
  'description' => __( 'Duration of opening animation.', 'responsive-lightbox' ),
1667
  'append' => 'ms',
1668
  'parent' => 'featherlight'
1669
+ ],
1670
+ 'close_speed' => [
1671
  'title' => __( 'Closing speed', 'responsive-lightbox' ),
1672
  'section' => 'responsive_lightbox_configuration',
1673
  'type' => 'number',
1674
  'description' => __( 'Duration of closing animation.', 'responsive-lightbox' ),
1675
  'append' => 'ms',
1676
  'parent' => 'featherlight'
1677
+ ],
1678
+ 'close_on_click' => [
1679
  'title' => __( 'Close on click', 'responsive-lightbox' ),
1680
  'section' => 'responsive_lightbox_configuration',
1681
  'type' => 'radio',
1682
  'label' => __( 'Select how to close lightbox.', 'responsive-lightbox' ),
1683
+ 'options' => [
1684
  'background' => __( 'background', 'responsive-lightbox' ),
1685
  'anywhere' => __( 'anywhere', 'responsive-lightbox' ),
1686
  'false' => __( 'false', 'responsive-lightbox' )
1687
+ ],
1688
  'parent' => 'featherlight'
1689
+ ],
1690
+ 'close_on_esc' => [
1691
  'title' => __( 'Close on Esc', 'responsive-lightbox' ),
1692
  'section' => 'responsive_lightbox_configuration',
1693
  'type' => 'boolean',
1694
  'label' => __( 'Toggle if pressing Esc button closes lightbox.', 'responsive-lightbox' ),
1695
  'parent' => 'featherlight'
1696
+ ],
1697
+ 'gallery_fade_in' => [
1698
  'title' => __( 'Gallery fade in', 'responsive-lightbox' ),
1699
  'section' => 'responsive_lightbox_configuration',
1700
  'type' => 'number',
1701
  'description' => __( 'Animation speed when image is loaded.', 'responsive-lightbox' ),
1702
  'append' => 'ms',
1703
  'parent' => 'featherlight'
1704
+ ],
1705
+ 'gallery_fade_out' => [
1706
  'title' => __( 'Gallery fade out', 'responsive-lightbox' ),
1707
  'section' => 'responsive_lightbox_configuration',
1708
  'type' => 'number',
1709
  'description' => __( 'Animation speed before image is loaded.', 'responsive-lightbox' ),
1710
  'append' => 'ms',
1711
  'parent' => 'featherlight'
1712
+ ]
1713
+ ];
1714
  break;
1715
 
1716
  case 'magnific':
1717
  $this->settings['configuration']['prefix'] = 'rl_mp';
1718
+ $this->settings['configuration']['fields'] = [
1719
+ 'disable_on' => [
1720
  'title' => __( 'Disable on', 'responsive-lightbox' ),
1721
  'section' => 'responsive_lightbox_configuration',
1722
  'type' => 'number',
1723
  'description' => __( 'If window width is less than the number in this option lightbox will not be opened and the default behavior of the element will be triggered. Set to 0 to disable behavior.', 'responsive-lightbox' ),
1724
  'append' => 'px',
1725
  'parent' => 'magnific'
1726
+ ],
1727
+ 'mid_click' => [
1728
  'title' => __( 'Middle click', 'responsive-lightbox' ),
1729
  'section' => 'responsive_lightbox_configuration',
1730
  'type' => 'boolean',
1731
  'label' => __( 'If option enabled, lightbox is opened if the user clicked on the middle mouse button, or click with Command/Ctrl key.', 'responsive-lightbox' ),
1732
  'parent' => 'magnific'
1733
+ ],
1734
+ 'preloader' => [
1735
  'title' => __( 'Preloader', 'responsive-lightbox' ),
1736
  'section' => 'responsive_lightbox_configuration',
1737
  'type' => 'boolean',
1738
  'label' => __( 'If option enabled, it\'s always present in DOM only text inside of it changes.', 'responsive-lightbox' ),
1739
  'parent' => 'magnific'
1740
+ ],
1741
+ 'close_on_content_click' => [
1742
  'title' => __( 'Close on content click', 'responsive-lightbox' ),
1743
  'section' => 'responsive_lightbox_configuration',
1744
  'type' => 'boolean',
1745
  'label' => __( 'Close popup when user clicks on content of it. It\'s recommended to enable this option when you have only image in popup.', 'responsive-lightbox' ),
1746
  'parent' => 'magnific'
1747
+ ],
1748
+ 'close_on_background_click' => [
1749
  'title' => __( 'Close on background click', 'responsive-lightbox' ),
1750
  'section' => 'responsive_lightbox_configuration',
1751
  'type' => 'boolean',
1752
  'label' => __( 'Close the popup when user clicks on the dark overlay.', 'responsive-lightbox' ),
1753
  'parent' => 'magnific'
1754
+ ],
1755
+ 'close_button_inside' => [
1756
  'title' => __( 'Close button inside', 'responsive-lightbox' ),
1757
  'section' => 'responsive_lightbox_configuration',
1758
  'type' => 'boolean',
1759
  'label' => __( 'If enabled, Magnific Popup will put close button inside content of popup.', 'responsive-lightbox' ),
1760
  'parent' => 'magnific'
1761
+ ],
1762
+ 'show_close_button' => [
1763
  'title' => __( 'Show close button', 'responsive-lightbox' ),
1764
  'section' => 'responsive_lightbox_configuration',
1765
  'type' => 'boolean',
1766
  'label' => __( 'Controls whether the close button will be displayed or not.', 'responsive-lightbox' ),
1767
  'parent' => 'magnific'
1768
+ ],
1769
+ 'enable_escape_key' => [
1770
  'title' => __( 'Enable escape key', 'responsive-lightbox' ),
1771
  'section' => 'responsive_lightbox_configuration',
1772
  'type' => 'boolean',
1773
  'label' => __( 'Controls whether pressing the escape key will dismiss the active popup or not.', 'responsive-lightbox' ),
1774
  'parent' => 'magnific'
1775
+ ],
1776
+ 'align_top' => [
1777
  'title' => __( 'Align top', 'responsive-lightbox' ),
1778
  'section' => 'responsive_lightbox_configuration',
1779
  'type' => 'boolean',
1780
  'label' => __( 'If set to true popup is aligned to top instead of to center.', 'responsive-lightbox' ),
1781
  'parent' => 'magnific'
1782
+ ],
1783
+ 'fixed_content_position' => [
1784
  'title' => __( 'Content position type', 'responsive-lightbox' ),
1785
  'section' => 'responsive_lightbox_configuration',
1786
  'type' => 'select',
1787
  'description' => __( 'Popup content position. If set to "auto" popup will automatically disable this option when browser doesn\'t support fixed position properly.', 'responsive-lightbox' ),
1788
+ 'options' => [
1789
  'auto' => __( 'Auto', 'responsive-lightbox' ),
1790
  'true' => __( 'Fixed', 'responsive-lightbox' ),
1791
  'false' => __( 'Absolute', 'responsive-lightbox' )
1792
+ ],
1793
  'parent' => 'magnific'
1794
+ ],
1795
+ 'fixed_background_position' => [
1796
  'title' => __( 'Fixed background position', 'responsive-lightbox' ),
1797
  'section' => 'responsive_lightbox_configuration',
1798
  'type' => 'select',
1799
  'description' => __( 'Dark transluscent overlay content position.', 'responsive-lightbox' ),
1800
+ 'options' => [
1801
  'auto' => __( 'Auto', 'responsive-lightbox' ),
1802
  'true' => __( 'Fixed', 'responsive-lightbox' ),
1803
  'false' => __( 'Absolute', 'responsive-lightbox' )
1804
+ ],
1805
  'parent' => 'magnific'
1806
+ ],
1807
+ 'auto_focus_last' => [
1808
  'title' => __( 'Auto focus last', 'responsive-lightbox' ),
1809
  'section' => 'responsive_lightbox_configuration',
1810
  'type' => 'boolean',
1811
  'label' => __( 'If set to true last focused element before popup showup will be focused after popup close.', 'responsive-lightbox' ),
1812
  'parent' => 'magnific'
1813
+ ]
1814
+ ];
1815
  break;
1816
 
1817
  default:
1830
  * @return void
1831
  */
1832
  public function remote_library_providers_description() {
1833
+ echo '<p class="description">' . sprintf( esc_html__( 'Below you\'ll find a list of available remote media libraries. If you\'re looking for Pixabay, Pexels, Instagram and other integrations please check the %s addon.', 'responsive-lightbox' ), '<a href="https://dfactory.eu/products/remote-library-pro/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=addon" target="_blank">Remote Library Pro</a>' ) . '</p>';
1834
  }
1835
 
1836
  /**
1845
  add_menu_page( __( 'General', 'responsive-lightbox' ), __( 'Lightbox', 'responsive-lightbox' ), $capability, 'responsive-lightbox-settings', '', 'dashicons-format-image', '57.1' );
1846
 
1847
  foreach ( $this->tabs as $key => $options ) {
1848
+ add_submenu_page( 'responsive-lightbox-settings', $options['name'], $options['name'], $capability, 'responsive-lightbox-' . $key , [ $this, 'options_page' ] );
1849
  }
1850
  }
1851
 
1855
  * @return void
1856
  */
1857
  public function options_page() {
1858
+ // check page
1859
+ $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
1860
+
1861
  // check settings page
1862
+ if ( $page && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $this->tabs ) ) . ')$/', $page, $tabs ) !== 1 )
1863
  return;
1864
 
1865
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
1866
+
1867
+ // check section
1868
+ $section_key = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : '';
1869
+
1870
+ if ( ! $section_key )
1871
+ $section_key = ! empty( $this->tabs[$tab_key]['default_section'] ) ? $this->tabs[$tab_key]['default_section'] : '';
1872
 
1873
  // assign main instance
1874
  $rl = Responsive_Lightbox();
1888
 
1889
  // hidden h2 tag is needed to display info box properly when saving or resetting settings
1890
  echo '
1891
+ <h2 class="hidden">' . esc_html__( 'Responsive Lightbox & Gallery', 'responsive-lightbox' ) . ' - ' . esc_html( $this->tabs[$tab_key]['name'] ) . '</h2>' . '
1892
  <h2 class="nav-tab-wrapper">';
1893
 
1894
  foreach ( $this->tabs as $key => $options ) {
1895
  echo '
1896
+ <a class="nav-tab ' . ( $tab_key === $key ? 'nav-tab-active' : '' ) . '" href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-' . $key ) ) . '">' . esc_html( $options['name'] ) . '</a>';
1897
  }
1898
 
1899
  echo '
1900
  </h2>
1901
  <div class="responsive-lightbox-settings">
1902
  <div class="df-credits">
1903
+ <h3 class="hndle">' . esc_html__( 'Responsive Lightbox & Gallery', 'responsive-lightbox' ) . ' ' . esc_html( $rl->defaults['version'] ) . '</h3>
1904
  <div class="inside">
1905
+ <h4 class="inner">' . esc_html__( 'Need support?', 'responsive-lightbox' ) . '</h4>
1906
+ <p class="inner">' . sprintf( esc_html__( 'If you are having problems with this plugin, please browse it\'s %s or talk about them in the %s.', 'responsive-lightbox' ), '<a href="https://www.dfactory.eu/docs/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=docs" target="_blank">' . esc_html__( 'Documentation', 'responsive-lightbox' ) . '</a>', '<a href="https://www.dfactory.eu/support/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=support" target="_blank">' . esc_html__( 'Support forum', 'responsive-lightbox' ) . '</a>' ) . '</p>
1907
  <hr />
1908
+ <h4 class="inner">' . esc_html__( 'Do you like this plugin?', 'responsive-lightbox' ) . '</h4>
1909
+ <p class="inner">' . sprintf( esc_html__( '%s on WordPress.org', 'responsive-lightbox' ), '<a href="https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5" target="_blank">' . esc_html__( 'Rate it 5', 'responsive-lightbox' ) . '</a>' ) . '<br />' .
1910
+ sprintf( esc_html__( 'Blog about it & link to the %s.', 'responsive-lightbox' ), '<a href="https://dfactory.eu/plugins/responsive-lightbox/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=blog-about" target="_blank">' . esc_html__( 'plugin page', 'responsive-lightbox' ) . '</a>' ) . '<br />' .
1911
+ sprintf( esc_html__( 'Check out our other %s.', 'responsive-lightbox' ), '<a href="https://dfactory.eu/plugins/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=other-plugins" target="_blank">' . esc_html__( 'WordPress plugins', 'responsive-lightbox' ) . '</a>' ) . '
1912
  </p>
1913
  <hr />
1914
  <p class="df-link inner"><a href="https://www.dfactory.eu/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="Digital Factory"><img src="//rlg-53eb.kxcdn.com/df-black-sm.png' . '" alt="Digital Factory" /></a></p>
1918
 
1919
  // views
1920
  if ( ! empty( $this->tabs[$tab_key]['sections'] ) ) {
1921
+ $list = [];
1922
 
1923
  echo '<ul class="subsubsub">';
1924
 
1925
+ foreach ( $this->tabs[$tab_key]['sections'] as $key => $name ) {
1926
+ $list[$key] = "\t" . '<li class="' . esc_attr( $key ) . '"><a href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-' . $tab_key . '&section=' . $key ) ) . '" class="' . ( $key === $section_key ? 'current' : '' ) . '">' . esc_html( $name ) . '</a>';
 
1927
  }
1928
 
1929
+ echo implode( " |</li>\n", $list ) . "</li>\n";
1930
+ echo '</ul><input type="hidden" name="section" value="' . esc_attr( $section_key ) . '" /><br class="clear">';
1931
  }
1932
 
1933
  // tab content callback
1945
  echo '<p class="submit">';
1946
 
1947
  if ( ! empty( $this->tabs[$tab_key]['submit'] ) ) {
1948
+ submit_button( '', [ 'primary', 'save-' . $tab_key ], $this->tabs[$tab_key]['submit'], false );
1949
  echo ' ';
1950
  }
1951
 
1952
  if ( ! empty( $this->tabs[$tab_key]['reset'] ) )
1953
+ submit_button( __( 'Reset to defaults', 'responsive-lightbox' ), [ 'secondary', 'reset-responsive-lightbox-settings reset-' . $tab_key ], $this->tabs[$tab_key]['reset'], false );
1954
 
1955
  echo '</p>';
1956
  }
1980
  // assign main instance
1981
  $rl = Responsive_Lightbox();
1982
 
1983
+ foreach ( $this->settings as $_setting_id => $setting ) {
1984
+ $setting_id = sanitize_key( $_setting_id );
1985
+
1986
+ if ( ! empty( $setting['option_name'] ) )
1987
+ $option_name = sanitize_key( $setting['option_name'] );
1988
+ else
1989
+ $option_name = $setting_id;
1990
+
1991
  // set key
1992
  $setting_key = $setting_id;
1993
  $setting_id = 'responsive_lightbox_' . $setting_id;
1994
 
1995
  // add new capability to manage options
1996
+ add_filter( 'option_page_capability_' . $setting_id, [ $this, 'manage_options_capability' ] );
1997
 
1998
  // register setting
1999
+ register_setting( $setting_id, $option_name, ! empty( $setting['callback'] ) ? $setting['callback'] : [ $this, 'validate_settings' ] );
 
 
 
 
2000
 
2001
  // register sections
2002
  if ( ! empty( $setting['sections'] ) && is_array( $setting['sections'] ) ) {
2003
+ foreach ( $setting['sections'] as $_section_id => $section ) {
2004
+ $section_id = sanitize_key( $_section_id );
2005
+
2006
  add_settings_section(
2007
+ $section_id,
2008
  ! empty( $section['title'] ) ? esc_html( $section['title'] ) : '',
2009
  ! empty( $section['callback'] ) ? $section['callback'] : '',
2010
+ ! empty( $section['page'] ) ? sanitize_key( $section['page'] ) : $section_id
2011
  );
2012
  }
2013
  }
2014
 
2015
  // register fields
2016
  if ( ! empty( $setting['fields'] ) && is_array( $setting['fields'] ) ) {
2017
+ foreach ( $setting['fields'] as $_field_id => $field ) {
2018
+ $field_id = sanitize_key( $_field_id );
2019
+
2020
  // prefix field id?
2021
  $field_key = $field_id;
2022
  $field_id = ( ! empty( $setting['prefix'] ) ? $setting['prefix'] . '_' : '' ) . $field_id;
2023
 
2024
  // field args
2025
+ $args = [
2026
+ 'id' => ! empty( $field['id'] ) ? $field['id'] : $field_id,
2027
+ 'class' => ! empty( $field['class'] ) ? $field['class'] : '',
2028
+ 'name' => $option_name . ( ! empty( $field['parent'] ) ? '[' . $field['parent'] . ']' : '' ) . '[' . $field_key . ']',
2029
+ 'type' => ! empty( $field['type'] ) ? $field['type'] : 'text',
2030
+ 'label' => ! empty( $field['label'] ) ? $field['label'] : '',
2031
+ 'description' => ! empty( $field['description'] ) ? $field['description'] : '',
2032
+ 'disabled' => isset( $field['disabled'] ) ? (bool) $field['disabled'] : false,
2033
+ 'append' => ! empty( $field['append'] ) ? $field['append'] : '',
2034
+ 'prepend' => ! empty( $field['prepend'] ) ? $field['prepend'] : '',
2035
+ 'min' => isset( $field['min'] ) ? (int) $field['min'] : '',
2036
+ 'max' => isset( $field['max'] ) ? (int) $field['max'] : '',
2037
+ 'options' => ! empty( $field['options'] ) ? $field['options'] : '',
2038
+ 'fields' => ! empty( $field['fields'] ) ? $field['fields'] : '',
2039
+ 'after_field' => ! empty( $field['after_field'] ) ? $field['after_field'] : '',
2040
+ 'default' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $rl->defaults[$setting_key][$field['parent']][$field_key] : $rl->defaults[$setting_key][$field_key], $field['type'] ) ),
2041
+ 'value' => $field['type'] === 'multiple' ? '' : ( $this->sanitize_field( ! empty( $field['parent'] ) ? $rl->options[$setting_key][$field['parent']][$field_key] : ( isset( $rl->options[$setting_key][$field_key] ) ? $rl->options[$setting_key][$field_key] : $rl->defaults[$setting_key][$field_key] ), $field['type'] ) ),
2042
+ 'label_for' => $field_id,
2043
+ 'classname' => ! empty( $field['classname'] ) ? $field['classname'] : '',
2044
+ 'callback' => ! empty( $field['callback'] ) ? $field['callback'] : '',
2045
+ 'return' => false
2046
+ ];
2047
 
2048
  if ( $args['type'] === 'multiple' ) {
2049
  foreach ( $args['fields'] as $subfield_id => $subfield ) {
2050
+ $args['fields'][$subfield_id] = wp_parse_args(
2051
+ $subfield,
2052
+ [
2053
+ 'id' => $field_id . '-' . $subfield_id,
2054
+ 'class' => ! empty( $subfield['class'] ) ? $subfield['class'] : '',
2055
+ 'name' => $option_name . ( ! empty( $subfield['parent'] ) ? '[' . $subfield['parent'] . ']' : '' ) . '[' . $subfield_id . ']',
2056
+ 'default' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $rl->defaults[$setting_key][$subfield['parent']][$subfield_id] : $rl->defaults[$setting_key][$subfield_id], $subfield['type'] ),
2057
+ 'value' => $this->sanitize_field( ! empty( $subfield['parent'] ) ? $rl->options[$setting_key][$subfield['parent']][$subfield_id] : $rl->options[$setting_key][$subfield_id], $subfield['type'] ),
2058
+ 'return' => true
2059
+ ]
2060
+ );
2061
  }
2062
  }
2063
 
2064
  add_settings_field(
2065
+ $field_id,
2066
  ! empty( $field['title'] ) ? esc_html( $field['title'] ) : '',
2067
+ [ $this, 'render_field' ],
2068
+ ! empty( $field['page'] ) ? sanitize_key( $field['page'] ) : $setting_id,
2069
+ ! empty( $field['section'] ) ? sanitize_key( $field['section'] ) : '',
2070
  $args
2071
  );
2072
  }
2074
  }
2075
 
2076
  // licenses
2077
+ $extensions = apply_filters( 'rl_settings_licenses', [] );
2078
 
2079
  if ( $extensions ) {
2080
  // add new capability to manage licenses
2081
+ add_filter( 'option_page_capability_responsive_lightbox_licenses', [ $this, 'manage_options_capability' ] );
2082
 
2083
  // register setting
2084
+ register_setting( 'responsive_lightbox_licenses', 'responsive_lightbox_licenses', [ $this, 'validate_licenses' ] );
2085
+
2086
+ add_settings_section( 'responsive_lightbox_licenses', esc_html__( 'Licenses', 'responsive-lightbox' ), [ $this, 'licenses_section_cb' ], 'responsive_lightbox_licenses' );
 
 
 
 
 
 
 
 
 
2087
 
2088
  foreach ( $extensions as $id => $extension ) {
2089
+ add_settings_field( sanitize_key( $id ), esc_html( $extension['name'] ), [ $this, 'license_field_cb' ], 'responsive_lightbox_licenses', 'responsive_lightbox_licenses', $extension );
 
 
 
 
 
 
 
2090
  }
2091
  }
2092
  }
2099
  */
2100
  public function render_field( $args ) {
2101
  if ( empty( $args ) || ! is_array( $args ) )
2102
+ return '';
2103
 
2104
  $html = '';
2105
 
2106
  switch ( $args['type'] ) {
2107
  case 'boolean':
2108
+ $html .= '<label><input id="' . esc_attr( $args['id'] ) . '" type="checkbox" name="' . esc_attr( $args['name'] ) . '" value="1" ' . checked( (bool) $args['value'], true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . esc_html( $args['label'] ) . '</label>';
2109
  break;
2110
 
2111
  case 'radio':
2112
  foreach ( $args['options'] as $key => $name ) {
2113
+ $html .= '<label><input id="' . esc_attr( $args['id'] . '-' . $key ) . '" type="radio" name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $key ) . '" ' . checked( $key, $args['value'], false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . esc_html( $name ) . '</label> ';
2114
  }
2115
  break;
2116
 
2117
  case 'checkbox':
2118
  foreach ( $args['options'] as $key => $name ) {
2119
+ $html .= '<label><input id="' . esc_attr( $args['id'] . '-' . $key ) . '" type="checkbox" name="' . esc_attr( $args['name'] ) . '[' . esc_attr( $key ) . ']" value="1" ' . checked( in_array( $key, $args['value'] ), true, false ) . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . ' />' . esc_html( $name ) . '</label> ';
2120
  }
2121
  break;
2122
 
2123
  case 'select':
2124
+ $html .= '<select id="' . esc_attr( $args['id'] ) . '" name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" ' . ( isset( $args['disabled'] ) && $args['disabled'] == true ? ' disabled="disabled"' : '' ) . '/>';
2125
 
2126
  foreach ( $args['options'] as $key => $name ) {
2127
+ $html .= '<option value="' . esc_attr( $key ) . '" ' . selected( $args['value'], $key, false ) . '>' . esc_html( $name ) . '</option>';
2128
  }
2129
 
2130
  $html .= '</select>';
2139
 
2140
  foreach ( $args['fields'] as $subfield_id => $subfield_args ) {
2141
  $html .= $this->render_field( $subfield_args ) . ( $count < $count_fields ? '<br />' : '' );
2142
+
2143
  $count++;
2144
  }
2145
  }
2148
  break;
2149
 
2150
  case 'range':
2151
+ $html .= '<input id="' . esc_attr( $args['id'] ) . '" type="range" name="' . esc_attr( $args['name'] ) . '" value="' . (int) $args['value'] . '" min="' . (int) $args['min'] . '" max="' . (int) $args['max'] . '" oninput="this.form.' . esc_attr( $args['id'] ) . '_range.value=this.value" />';
2152
+ $html .= '<output name="' . esc_attr( $args['id'] ) . '_range">' . (int) $args['value'] . '</output>';
2153
  break;
2154
 
2155
  case 'color_picker':
2156
+ $html .= '<input id="' . esc_attr( $args['id'] ) . '" class="color-picker" type="text" value="' . esc_attr( $args['value'] ) . '" name="' . esc_attr( $args['name'] ) . '" data-default-color="' . esc_attr( $args['default'] ) . '" />';
2157
  break;
2158
 
2159
  case 'number':
2160
+ $html .= ( ! empty( $args['prepend'] ) ? '<span>' . esc_html( $args['prepend'] ) . '</span> ' : '' );
2161
+ $html .= '<input id="' . esc_attr( $args['id'] ) . '" type="number" value="' . (int) $args['value'] . '" name="' . esc_attr( $args['name'] ) . '" />';
2162
+ $html .= ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' );
2163
  break;
2164
 
2165
  case 'button':
2166
+ $html .= ( ! empty( $args['prepend'] ) ? '<span>' . esc_html( $args['prepend'] ) . '</span> ' : '' );
2167
+ $html .= '<a href="' . esc_url( admin_url( 'admin.php?page=responsive-lightbox-tour' ) ) . '" id="' . esc_attr( $args['id'] ) . '" class="button ' . ( ! empty( $args['classname'] ) ? esc_attr( $args['classname'] ) : 'button-secondary' ) . '">' . esc_html( $args['label'] ) . '</a>';
2168
+ $html .= ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' );
2169
  break;
2170
 
2171
  case 'custom':
2174
 
2175
  case 'text':
2176
  default :
2177
+ $html .= ( ! empty( $args['prepend'] ) ? '<span>' . esc_html( $args['prepend'] ) . '</span> ' : '' );
2178
+ $html .= '<input id="' . esc_attr( $args['id'] ) . '" class="' . esc_attr( $args['class'] ) . '" type="text" value="' . esc_attr( $args['value'] ) . '" name="' . esc_attr( $args['name'] ) . '" />';
2179
+ $html .= ( ! empty( $args['append'] ) ? ' <span>' . esc_html( $args['append'] ) . '</span>' : '' );
2180
  }
2181
 
2182
  if ( ! empty ( $args['after_field'] ) )
2183
+ $html .= wp_kses_post( $args['after_field'] );
2184
 
2185
  if ( ! empty ( $args['description'] ) )
2186
+ $html .= '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>';
2187
 
2188
  if ( ! empty( $args['return'] ) )
2189
  return $html;
2199
  * @param array $args
2200
  * @return mixed
2201
  */
2202
+ public function sanitize_field( $value = null, $type = '', $args = [] ) {
2203
  if ( is_null( $value ) )
2204
  return null;
2205
 
2210
  break;
2211
 
2212
  case 'checkbox':
2213
+ $value = is_array( $value ) && ! empty( $value ) ? array_map( 'sanitize_key', $value ) : [];
2214
  break;
2215
 
2216
  case 'radio':
2217
+ $value = is_array( $value ) ? false : sanitize_key( $value );
2218
  break;
2219
 
2220
  case 'textarea':
2223
  break;
2224
 
2225
  case 'color_picker':
2226
+ $value = sanitize_hex_color( $value );
2227
+
2228
+ if ( empty( $value ) )
2229
  $value = '#666666';
2230
  break;
2231
 
2250
  // validate custom events
2251
  if ( $args['setting_id'] === 'settings' ) {
2252
  if ( $args['field_id'] === 'enable_custom_events' && $args['subfield_id'] === 'custom_events' )
2253
+ $value = preg_replace( '/[^a-z0-9 ]/i', '', $value );
2254
  } elseif ( $args['setting_id'] === 'builder' ) {
2255
  if ( $args['field_id'] === 'permalink' || $args['field_id'] === 'permalink_categories' || $args['field_id'] === 'permalink_tags' )
2256
  $value = sanitize_title( $value );
2257
  }
 
2258
  }
2259
  case 'select':
2260
  default:
2279
  if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', $rl->options['capabilities']['active'] ? 'edit_lightbox_settings' : 'manage_options' ) ) )
2280
  return $input;
2281
 
2282
+ // check option page
2283
+ $option_page = isset( $_POST['option_page'] ) ? sanitize_key( $_POST['option_page'] ) : '';
2284
+
2285
  // check page
2286
+ if ( ! $option_page )
2287
  return $input;
2288
 
2289
  foreach ( $this->settings as $id => $setting ) {
2291
 
2292
  if ( $key ) {
2293
  // set key
2294
+ $setting_id = sanitize_key( $id );
2295
  break;
2296
  }
2297
  }
2301
  return $input;
2302
 
2303
  // save settings
2304
+ if ( isset( $_POST['save' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
2305
  if ( $this->settings[$setting_id]['fields'] ) {
2306
  foreach ( $this->settings[$setting_id]['fields'] as $field_id => $field ) {
2307
  if ( $field['type'] === 'multiple' ) {
2331
  if ( ! empty( $this->settings[$setting_id]['fields'][$field_id]['parent'] ) ) {
2332
  $field_parent = $this->settings[$setting_id]['fields'][$field_id]['parent'];
2333
 
2334
+ $input[$field_parent][$field_id] = isset( $input[$field_parent][$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_parent][$field_id], $field['type'], $args ) ) : $this->sanitize_field( $input[$field_parent][$field_id], $field['type'], $args ) ) : ( in_array( $field['type'], [ 'boolean', 'checkbox' ] ) ? false : $rl->defaults[$setting_id][$field_parent][$field_id] );
2335
  } else {
2336
+ $input[$field_id] = isset( $input[$field_id] ) ? ( $field['type'] === 'checkbox' ? array_keys( $this->sanitize_field( $input[$field_id], $field['type'], $args ) ) : $this->sanitize_field( $input[$field_id], $field['type'], $args ) ) : ( in_array( $field['type'], [ 'boolean', 'checkbox' ] ) ? false : $rl->defaults[$setting_id][$field_id] );
2337
  }
2338
  }
2339
  }
2355
 
2356
  if ( $setting_id === 'remote_library' )
2357
  $input = apply_filters( 'rl_remote_library_settings', $input );
2358
+ } elseif ( isset( $_POST['reset' . '_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id] ) ) {
2359
  if ( $setting_id === 'configuration' ) {
2360
  $script = key( $input );
2361
 
2369
  } else
2370
  $input = $rl->defaults[$setting_id];
2371
 
2372
+ add_settings_error( 'reset_' . $this->settings[$setting_id]['prefix'] . '_' . $setting_id, 'settings_restored', esc_html__( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
2373
  }
2374
 
2375
  return $input;
2426
  }
2427
  }
2428
 
2429
+ add_settings_error( 'reset_rl_capabilities', 'settings_restored', esc_html__( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' );
2430
  }
2431
 
2432
  return $input;
2450
  <table class="widefat fixed posts">
2451
  <thead>
2452
  <tr>
2453
+ <th>' . esc_html__( 'Role', 'responsive-lightbox' ) . '</th>';
2454
 
2455
  foreach ( $editable_roles as $role_name => $role_info ) {
2456
  $html .= '<th>' . esc_html( isset( $wp_roles->role_names[$role_name] ) ? translate_user_role( $wp_roles->role_names[$role_name] ) : $role_name ) . '</th>';
2466
  foreach ( Responsive_Lightbox()->capabilities as $cap_role => $cap_label ) {
2467
  $html .= '
2468
  <tr' . ( ( $i++ % 2 === 0 ) ? ' class="alternate"' : '' ) . '>
2469
+ <td>' . esc_html__( $cap_label, 'responsive-lightbox' ) . '</td>';
2470
 
2471
  foreach ( $editable_roles as $role_name => $role_info ) {
2472
  // get user role
2496
  */
2497
  private function addons_tab_cb() {
2498
  ?>
2499
+ <h3><?php esc_html_e( 'Add-ons / Extensions', 'responsive-lightbox' ); ?></h3>
2500
+ <p class="description"><?php esc_html_e( 'Enhance your website with these beautiful, easy to use extensions, designed with Responsive Lightbox & Gallery integration in mind.', 'responsive-lightbox' ); ?></p>
2501
  <br />
2502
  <?php
2503
+ $cache = get_transient( 'responsive_lightbox_addons_feed' );
 
2504
 
2505
+ if ( $cache === false ) {
2506
+ $feed = wp_remote_get( 'https://dfactory.eu/?feed=addons&product=responsive-lightbox', [ 'sslverify' => false ] );
2507
 
2508
  if ( ! is_wp_error( $feed ) ) {
2509
  if ( isset( $feed['body'] ) && strlen( $feed['body'] ) > 0 )
2510
  $cache = wp_remote_retrieve_body( $feed );
2511
  } else
2512
+ $cache = '<div class="error"><p>' . esc_html__( 'There was an error retrieving the extensions list from the server. Please try again later.', 'responsive-lightbox' ) . '</p></div>';
2513
  }
2514
 
2515
  echo $cache;
2521
  * @return void
2522
  */
2523
  public function licenses_section_cb() {
2524
+ ?><p class="description"><?php esc_html_e( 'A list of licenses for your Responsive Lightbox & Gallery extensions.', 'responsive-lightbox' ); ?></p><?php
2525
  }
2526
 
2527
  /**
2534
  $licenses = get_option( 'responsive_lightbox_licenses' );
2535
 
2536
  if ( ! empty( $licenses ) ) {
2537
+ $license = isset( $licenses[$args['id']]['license'] ) ? $licenses[$args['id']]['license'] : '';
2538
  $status = ! empty( $licenses[$args['id']]['status'] );
2539
  } else {
2540
  $license = '';
2541
  $status = false;
2542
  } ?>
2543
  <fieldset class="rl_license rl_license-<?php echo esc_attr( $args['id'] ); ?>">
2544
+ <input type="text" class="regular-text" name="responsive_lightbox_licenses[<?php echo esc_attr( $args['id'] ); ?>][license]" value="<?php echo esc_attr( $license ); ?>"><span class="dashicons <?php echo ( $status ? 'dashicons-yes' : 'dashicons-no' ); ?>"></span>
2545
+ <p class="description"><?php echo esc_html( sprintf( __( 'Enter your license key to activate %s extension and enable automatic upgrade notices.', 'responsive-lightbox' ), $args['name'] ) ); ?></p>
2546
  </fieldset>
2547
  <?php
2548
  }
2558
  if ( ! current_user_can( apply_filters( 'rl_lightbox_settings_capability', Responsive_Lightbox()->options['capabilities']['active'] ? 'edit_lightbox_settings' : 'manage_options' ) ) )
2559
  return $input;
2560
 
2561
+ // check option page
2562
+ $option_page = isset( $_POST['option_page'] ) ? sanitize_key( $_POST['option_page'] ) : '';
2563
+
2564
  // check page
2565
+ if ( ! $option_page )
2566
  return $input;
2567
 
2568
+ $rl_licenses = isset( $_POST['responsive_lightbox_licenses'] ) && is_array( $_POST['responsive_lightbox_licenses'] ) ? map_deep( $_POST['responsive_lightbox_licenses'], 'sanitize_key' ) : [];
2569
+
2570
  // check data
2571
+ if ( ! $rl_licenses )
2572
  return $input;
2573
 
2574
  // get extension licenses
2575
+ $extensions = apply_filters( 'rl_settings_licenses', [] );
2576
 
2577
  if ( empty( $extensions ) )
2578
  return $input;
2580
  // save settings
2581
  if ( isset( $_POST['save_rl_licenses'] ) ) {
2582
  $licenses = get_option( 'responsive_lightbox_licenses' );
2583
+ $statuses = [ 'updated' => 0, 'error' => 0 ];
2584
 
2585
  foreach ( $extensions as $extension ) {
2586
+ if ( ! isset( $rl_licenses[$extension['id']] ) )
2587
  continue;
2588
 
2589
+ $license = preg_replace( '/[^a-zA-Z0-9]/', '', $rl_licenses[$extension['id']]['license'] );
2590
+ $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] );
2591
 
2592
  // request data
2593
+ $request_args = [
2594
+ 'action' => 'activate_license',
2595
+ 'license' => $license,
2596
+ 'item_name' => $extension['item_name']
2597
+ ];
2598
 
2599
  // request
2600
  $response = $this->license_request( $request_args );
2622
 
2623
  // success notice
2624
  if ( $statuses['updated'] > 0 )
2625
+ add_settings_error( 'rl_licenses_settings', 'license_activated', esc_html( sprintf( _n( '%s license successfully activated.', '%s licenses successfully activated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ) ), 'updated' );
2626
 
2627
  // failed notice
2628
  if ( $statuses['error'] > 0 )
2629
+ add_settings_error( 'rl_licenses_settings', 'license_activation_failed', esc_html( sprintf( _n( '%s license activation failed.', '%s licenses activation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ) ), 'error' );
2630
  } elseif ( isset( $_POST['reset_rl_licenses'] ) ) {
2631
  $licenses = get_option( 'responsive_lightbox_licenses' );
2632
+ $statuses = [
2633
+ 'updated' => 0,
2634
+ 'error' => 0
2635
+ ];
2636
 
2637
  foreach ( $extensions as $extension ) {
2638
  $license = ! empty( $licenses ) && isset( $licenses[$extension['id']]['license'] ) ? $licenses[$extension['id']]['license'] : '';
2639
+ $status = ! empty( $licenses ) && ! empty( $licenses[$extension['id']]['status'] );
2640
 
2641
  if ( $status === true || ( $status === false && ! empty( $license ) ) ) {
2642
  // request data
2643
+ $request_args = [
2644
+ 'action' => 'deactivate_license',
2645
+ 'license' => trim( $license ),
2646
+ 'item_name' => $extension['item_name']
2647
+ ];
2648
 
2649
  // request
2650
  $response = $this->license_request( $request_args );
2660
  if ( $license_data->license == 'deactivated' ) {
2661
  $input[$extension['id']]['license'] = '';
2662
  $input[$extension['id']]['status'] = false;
2663
+
2664
  $statuses['updated']++;
2665
  } else
2666
  $statuses['error']++;
2670
 
2671
  // success notice
2672
  if ( $statuses['updated'] > 0 )
2673
+ add_settings_error( 'rl_licenses_settings', 'license_deactivated', esc_html( sprintf( _n( '%s license successfully deactivated.', '%s licenses successfully deactivated.', (int) $statuses['updated'], 'responsive-lightbox' ), (int) $statuses['updated'] ) ), 'updated' );
2674
 
2675
  // failed notice
2676
  if ( $statuses['error'] > 0 )
2677
+ add_settings_error( 'rl_licenses_settings', 'license_deactivation_failed', esc_html( sprintf( _n( '%s license deactivation failed.', '%s licenses deactivation failed.', (int) $statuses['error'], 'responsive-lightbox' ), (int) $statuses['error'] ) ), 'error' );
2678
  }
2679
 
2680
  return $input;
2688
  */
2689
  private function license_request( $args ) {
2690
  // data to send in our API request
2691
+ $api_params = [
2692
  'edd_action' => $args['action'],
2693
+ 'license' => sanitize_key( $args['license'] ),
2694
  'item_name' => urlencode( $args['item_name'] ),
2695
  // 'item_id' => $args['item_id'],
2696
  'url' => home_url(),
2697
  'timeout' => 60,
2698
  'sslverify' => false
2699
+ ];
2700
 
2701
  // call the custom API
2702
  $response = wp_remote_get( add_query_arg( $api_params, 'http://dfactory.eu' ) );
includes/class-tour.php CHANGED
@@ -19,9 +19,9 @@ class Responsive_Lightbox_Tour {
19
  */
20
  public function __construct() {
21
  // actions
22
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
23
- add_action( 'admin_init', array( $this, 'init_tour' ) );
24
- add_action( 'wp_ajax_rl-ignore-tour', array( $this, 'ignore_tour' ) );
25
  }
26
 
27
  /**
@@ -49,8 +49,8 @@ class Responsive_Lightbox_Tour {
49
  }
50
 
51
  if ( (int) get_transient( 'rl_active_tour' ) === 1 ) {
52
- add_action( 'admin_enqueue_scripts', array( $this, 'tour_scripts_styles' ) );
53
- add_action( 'admin_print_footer_scripts', array( $this, 'start_tour' ) );
54
  }
55
  }
56
 
@@ -65,14 +65,9 @@ class Responsive_Lightbox_Tour {
65
  global $pagenow;
66
 
67
  if ( $pagenow === 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] === 'responsive-lightbox-tour' )
68
- add_submenu_page( 'responsive-lightbox-settings', '', '', apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ), 'responsive-lightbox-tour', array( $this, 'temporary_submenu' ) );
69
  }
70
 
71
- /**
72
- *
73
- */
74
- function temporary_submenu() {}
75
-
76
  /**
77
  * Load pointer scripts.
78
  *
@@ -98,167 +93,163 @@ class Responsive_Lightbox_Tour {
98
  public function start_tour() {
99
  global $pagenow;
100
 
101
- $pointer = array();
102
  $rl = Responsive_Lightbox();
103
 
 
 
 
 
 
 
 
 
 
104
  // galleries
105
  if ( $pagenow === 'edit.php' ) {
106
- if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' && $rl->options['builder']['gallery_builder'] ) {
107
- $pointer = array(
108
- 'content' => '<h3>' . __( 'Gallery Builder', 'responsive-lightbox' ) . '</h3>' .
109
- '<p>' . __( 'This is an advanced gallery builder. Here you can see a preview of all created galleries along with their settings, such as the name, type, source of images, author or date of publication. You can also add a new gallery, edit existing ones or quickly copy the code allowing its use on the site.', 'responsive-lightbox' ) . '</p>',
110
- 'button2' => __( 'Next', 'responsive-lightbox' ),
111
- 'id' => '#wpbody-content h1'
112
- );
113
 
114
  // next categories?
115
  if ( $rl->options['builder']['categories'] )
116
- $pointer['function'] = 'window.location="' . admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ) . '";';
117
  // next tags?
118
  elseif ( $rl->options['builder']['tags'] )
119
- $pointer['function'] = 'window.location="' . admin_url( 'edit-tags.php?taxonomy=rl_tag&post_type=rl_gallery' ) . '";';
120
  // or settings?
121
  else
122
- $pointer['function'] = 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-settings' ) . '";';
123
  }
124
  // gallery taxonomies
125
  } elseif ( $pagenow === 'edit-tags.php' ) {
126
- if ( isset( $_GET['taxonomy'], $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' ) {
127
- if ( $_GET['taxonomy'] === 'rl_category' ) {
128
- $pointer = array(
129
- 'content' => '<h3>' . __( 'Gallery Categories', 'responsive-lightbox' ) . '</h3>' .
130
- '<p>' . __( 'Gallery categories allow you to arrange galleries into individual groups that you can potentially use. Here you can create, name and edit them. However, assigning the gallery to the category takes place on the gallery editing screen.', 'responsive-lightbox' ) . '</p>',
131
- 'button2' => __( 'Next', 'responsive-lightbox' ),
132
- 'id' => '#wpbody-content h1'
133
- );
134
 
135
  // next tags?
136
  if ( $rl->options['builder']['tags'] )
137
- $pointer['function'] = 'window.location="' . admin_url( 'edit-tags.php?taxonomy=rl_tag&post_type=rl_gallery' ) . '";';
138
  // or settings?
139
  else
140
- $pointer['function'] = 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-settings' ) . '";';
141
- } elseif ( $_GET['taxonomy'] === 'rl_tag' ) {
142
- $pointer = array(
143
- 'content' => '<h3>' . __( 'Gallery Tags', 'responsive-lightbox' ) . '</h3>' .
144
- '<p>' . __( 'Gallery tags, like categories, allow you to arrange galleries into groups. You can think of them as keywords, which you can use to further specify your galleries. Here you can create, name and edit them.', 'responsive-lightbox' ) . '</p>',
145
- 'button2' => __( 'Next', 'responsive-lightbox' ),
146
- 'id' => '#wpbody-content h1',
147
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-settings' ) . '";'
148
- );
149
  }
150
  }
151
  // settings
152
- } elseif ( $pagenow === 'admin.php' && isset( $_GET['page'] ) ) {
153
-
154
  // general
155
- if ( $_GET['page'] === 'responsive-lightbox-settings' ) {
156
- $pointer = array(
157
- 'content' => '<h3>' . __( 'General Settings', 'responsive-lightbox' ) . '</h3>' .
158
- '<p>' . __( "Here are the main settings for Responsive Lightbox & Gallery. They allow you to specify general rules of the plugin's operation and technical parameters of the lightbox effect and gallery. For example - you can choose your favorite lightbox effect, specify for which elements it will automatically launch and set its parameters. You can also choose the default gallery and its settings.", 'responsive-lightbox' ) . '</p>',
159
- 'button2' => __( 'Next', 'responsive-lightbox' ),
160
- 'id' => '#wpbody-content .wrap .nav-tab-active',
161
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-configuration' ) . '";'
162
- );
163
  // lightboxes
164
- } elseif ( $_GET['page'] === 'responsive-lightbox-configuration' ) {
165
- $pointer = array(
166
- 'content' => '<h3>' . __( 'Lightboxes Settings', 'responsive-lightbox' ) . '</h3>' .
167
- '<p>' . __( 'Each lightbox has different look, possibilities and parameters. Here is a list of available lightbox effects along with their settings. After entering the tab you can see the settings of the currently selected lightbox, but you can also modify or restore the settings of the others.', 'responsive-lightbox' ) . '</p>',
168
- 'button2' => __( 'Next', 'responsive-lightbox' ),
169
- 'id' => '#wpbody-content .wrap .nav-tab-active',
170
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-gallery' ) . '";'
171
- );
172
  // galleries
173
- } elseif ( $_GET['page'] === 'responsive-lightbox-gallery' ) {
174
- $pointer = array(
175
- 'content' => '<h3>' . __( 'Gallery Settings', 'responsive-lightbox' ) . '</h3>' .
176
- '<p>' . __( "This is the screen of the default gallery settings. As in the case of lightbox effects, there is a list of available galleries and their parameters. After entering the tab you can see the settings of the currently selected gallery. You can modify and adjust them to your needs or restore it's default settings.", 'responsive-lightbox' ) . '</p>',
177
- 'button2' => __( 'Next', 'responsive-lightbox' ),
178
- 'id' => '#wpbody-content .wrap .nav-tab-active',
179
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-builder' ) . '";'
180
- );
181
  // builder
182
- } elseif ( $_GET['page'] === 'responsive-lightbox-builder' ) {
183
- $pointer = array(
184
- 'content' => '<h3>' . __( 'Builder Settings', 'responsive-lightbox' ) . '</h3>' .
185
- '<p>' . __( 'You can use the galleries in many ways - insert them into posts using the Add Gallery button, insert manually using shortcodes or add to the theme using functions. But you can also display them in archives just like other post types. Use these settings to specify the functionality of the gallery builder like categories, tags, archives and permalinks.', 'responsive-lightbox' ) . '</p>',
186
  'button2' => __( 'Next', 'responsive-lightbox' ),
187
  'id' => '#wpbody-content .wrap .nav-tab-active',
188
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-folders' ) . '";'
189
- );
190
  // media folders
191
- } elseif ( $_GET['page'] === 'responsive-lightbox-folders' ) {
192
- $pointer = array(
193
- 'content' => '<h3>' . __( 'Folders Settings', 'responsive-lightbox' ) . '</h3>' .
194
- '<p>' . __( 'Responsive Lithbox & Gallery comes with an optional Media Folders feature that extends your WordPress Media Library with visual folders. It allows you to organize your attachments in a folder tree structure. Move, copy, rename and delete files and folders with a nice drag and drop interface.', 'responsive-lightbox' ) . '</p>',
195
- 'button2' => __( 'Next', 'responsive-lightbox' ),
196
- 'id' => '#wpbody-content .wrap .nav-tab-active',
197
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-capabilities' ) . '";'
198
- );
199
  // capabilities
200
- } elseif ( $_GET['page'] === 'responsive-lightbox-capabilities' ) {
201
- $pointer = array(
202
- 'content' => '<h3>' . __( 'Capabilities Settings', 'responsive-lightbox' ) . '</h3>' .
203
- '<p>' . __( 'Capabilities give you the ability to control what users can and cannot do within the plugin. By default only the Administrator role allows a user to perform all possible capabilities. But you can fine tune these settings to match your specific requirements.', 'responsive-lightbox' ) . '</p>',
204
- 'button2' => __( 'Next', 'responsive-lightbox' ),
205
- 'id' => '#wpbody-content .wrap .nav-tab-active',
206
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-remote_library' ) . '";'
207
- );
208
  // remote library
209
- } elseif ( $_GET['page'] === 'responsive-lightbox-remote_library' ) {
210
- // get additional plugins based on tabs
211
- $plugins = array_values( array_diff( array_keys( $rl->settings->tabs ), array( 'settings', 'configuration', 'gallery', 'builder', 'folders', 'remote_library', 'capabilities', 'licenses', 'addons' ) ) );
212
-
213
- if ( ! empty( $plugins ) ) {
214
- // get first plugin tab key
215
- $plugin_key = $plugins[0];
216
- } else
217
- $plugin_key = 'addons';
218
-
219
- $pointer = array(
220
- 'content' => '<h3>' . __( 'Remote Library Settings', 'responsive-lightbox' ) . '</h3>' .
221
- '<p>' . __( 'Are you looking for free royalty free public domain and CC0-Licensed images for your website? Or you need to access your images stored in photo-sharing apps? Remote Library allows you to use images from multiple sources like Unsplash, Pixabay, Flickr or Instagram directly in your WordPress Media Manager. Now you can create galleries, browse, insert and import images as never before.', 'responsive-lightbox' ) . '</p>',
222
- 'button2' => __( 'Next', 'responsive-lightbox' ),
223
- 'id' => '#wpbody-content .wrap .nav-tab-active',
224
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-' . $plugin_key ) . '";'
225
- );
226
-
227
  // licenses
228
- } elseif ( $_GET['page'] === 'responsive-lightbox-licenses' ) {
229
- $pointer = array(
230
- 'content' => '<h3>' . __( 'License Settings', 'responsive-lightbox' ) . '</h3>' .
231
- '<p>' . __( 'This section contains a list of currently installed premium extensions. Activate your licenses to have access to automatic updates from your site. To activate the license, copy and paste the license key for the extension and save the changes. Available license keys can be found on your account on our website.', 'responsive-lightbox' ) . '</p>',
232
- 'button2' => __( 'Next', 'responsive-lightbox' ),
233
- 'id' => '#wpbody-content .wrap .nav-tab-active',
234
- 'function' => 'window.location="' . admin_url( 'admin.php?page=responsive-lightbox-addons' ) . '";'
235
- );
236
  // addons
237
- } elseif ( $_GET['page'] === 'responsive-lightbox-addons' ) {
238
- $pointer = array(
239
- 'content' => '<h3>' . __( 'Add-ons', 'responsive-lightbox' ) . '</h3>' .
240
- '<p>' . __( 'Responsive Lightbox & Gallery is more than that. Do you need a beautiful lightbox effect, integration with social media, an attractive image gallery? Among our products you will surely find something for yourself. Boost your creativity and enhance your website with these beautiful, easy to use extensions, designed with Responsive Lightbox & Gallery integration in mind.', 'responsive-lightbox' ) . '</p>',
241
- 'button2' => '',
242
- 'id' => '#wpbody-content .wrap .nav-tab-active',
243
- 'function' => ''
244
- );
245
  // plugins related tabs
246
  } else
247
- $pointer = apply_filters( 'rl_tour_pointer', array(), esc_attr( $_GET['page'] ) );
248
  }
249
 
250
  // valid pointer?
251
  if ( ! empty( $pointer ) ) {
252
- $valid_pointer = array(
253
- 'content' => $pointer['content'],
254
- 'position' => array(
255
- 'edge' => 'top',
256
- 'align' => is_rtl() ? 'right' : 'left'
257
- ),
258
- 'pointerWidth' => 400,
 
 
 
 
 
 
259
  );
260
-
261
- $this->print_scripts( $pointer['id'], $valid_pointer, __( 'Close', 'responsive-lightbox' ), $pointer['button2'], $pointer['function'] );
262
  }
263
  }
264
 
@@ -268,28 +259,28 @@ class Responsive_Lightbox_Tour {
268
  * @return void
269
  */
270
  public function ignore_tour() {
271
- if ( isset( $_POST['rl_nonce'] ) && wp_verify_nonce( $_POST['rl_nonce'], 'rl-ignore-tour' ) !== false )
272
  delete_transient( 'rl_active_tour' );
273
 
274
  exit;
275
  }
276
 
277
  /**
278
- * Prints the pointer script
279
  *
280
  * @return void
281
  */
282
- public function print_scripts( $selector, $options, $button1, $button2 = false, $button2_function = '', $button1_function = '' ) {
283
  ?>
284
  <script type="text/javascript">
285
  //<![CDATA[
286
  ( function( $ ) {
287
  // ready event
288
  $( function() {
289
- var rl_pointer_options = <?php echo json_encode( $options ); ?>,
290
- setup;
291
 
292
- function rl_set_ignore( option, hide, nonce ) {
293
  $.post( ajaxurl, {
294
  action: 'rl-ignore-tour',
295
  rl_nonce: nonce
@@ -298,13 +289,12 @@ class Responsive_Lightbox_Tour {
298
  $( '#' + hide ).hide();
299
  $( '#hidden_ignore_' + option ).val( 'ignore' );
300
  }
301
- }
302
- );
303
  }
304
 
305
- rl_pointer_options = $.extend( rl_pointer_options, {
306
  buttons: function( event, t ) {
307
- var button = $( '<a id="rl-pointer-close" style="margin-left: 5px;" class="button-secondary">' + '<?php echo $button1; ?>' + '</a>' );
308
 
309
  button.on( 'click.pointer', function() {
310
  t.element.pointer( 'close' );
@@ -316,23 +306,23 @@ class Responsive_Lightbox_Tour {
316
  } );
317
 
318
  setup = function() {
319
- $( '<?php echo $selector; ?>' ).pointer( rl_pointer_options ).pointer( 'open' );
320
 
321
  <?php if ( $button2 ) { ?>
322
 
323
- $( '#rl-pointer-close' ).after( '<a id="pointer-primary" class="button-primary">' + '<?php echo $button2; ?>' + '</a>' );
324
  $( '#pointer-primary' ).on( 'click', function() {
325
- <?php echo $button2_function; ?>
326
  } );
327
 
328
  <?php } ?>
329
 
330
  $( '#rl-pointer-close' ).on( 'click', function() {
331
- rl_set_ignore( 'tour', 'wp-pointer-0', '<?php echo esc_js( wp_create_nonce( 'rl-ignore-tour' ) ); ?>' );
332
  } );
333
  };
334
 
335
- if ( rl_pointer_options.position && rl_pointer_options.position.defer_loading )
336
  $( window ).on( 'load.wp-pointers', setup );
337
  else
338
  $( document ).ready( setup );
@@ -342,4 +332,4 @@ class Responsive_Lightbox_Tour {
342
  </script>
343
  <?php
344
  }
345
- }
19
  */
20
  public function __construct() {
21
  // actions
22
+ add_action( 'admin_menu', [ $this, 'admin_menu' ] );
23
+ add_action( 'admin_init', [ $this, 'init_tour' ] );
24
+ add_action( 'wp_ajax_rl-ignore-tour', [ $this, 'ignore_tour' ] );
25
  }
26
 
27
  /**
49
  }
50
 
51
  if ( (int) get_transient( 'rl_active_tour' ) === 1 ) {
52
+ add_action( 'admin_enqueue_scripts', [ $this, 'tour_scripts_styles' ] );
53
+ add_action( 'admin_print_footer_scripts', [ $this, 'start_tour' ] );
54
  }
55
  }
56
 
65
  global $pagenow;
66
 
67
  if ( $pagenow === 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] === 'responsive-lightbox-tour' )
68
+ add_submenu_page( 'responsive-lightbox-settings', '', '', apply_filters( 'rl_lightbox_settings_capability', 'manage_options' ), 'responsive-lightbox-tour', function() {} );
69
  }
70
 
 
 
 
 
 
71
  /**
72
  * Load pointer scripts.
73
  *
93
  public function start_tour() {
94
  global $pagenow;
95
 
96
+ $pointer = [];
97
  $rl = Responsive_Lightbox();
98
 
99
+ // get page
100
+ $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
101
+
102
+ // get post type
103
+ $post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : '';
104
+
105
+ // get taxonomy
106
+ $taxonomy = isset( $_GET['taxonomy'] ) ? sanitize_key( $_GET['taxonomy'] ) : '';
107
+
108
  // galleries
109
  if ( $pagenow === 'edit.php' ) {
110
+ if ( $post_type && $post_type === 'rl_gallery' && $rl->options['builder']['gallery_builder'] ) {
111
+ $pointer = [
112
+ 'content' => '<h3>' . esc_html__( 'Gallery Builder', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'This is an advanced gallery builder. Here you can see a preview of all created galleries along with their settings, such as the name, type, source of images, author or date of publication. You can also add a new gallery, edit existing ones or quickly copy the code allowing its use on the site.', 'responsive-lightbox' ) . '</p>',
113
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
114
+ 'id' => '#wpbody-content h1'
115
+ ];
 
116
 
117
  // next categories?
118
  if ( $rl->options['builder']['categories'] )
119
+ $pointer['function'] = 'window.location="' . esc_url_raw( admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ) ) . '";';
120
  // next tags?
121
  elseif ( $rl->options['builder']['tags'] )
122
+ $pointer['function'] = 'window.location="' . esc_url_raw( admin_url( 'edit-tags.php?taxonomy=rl_tag&post_type=rl_gallery' ) ) . '";';
123
  // or settings?
124
  else
125
+ $pointer['function'] = 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ) . '";';
126
  }
127
  // gallery taxonomies
128
  } elseif ( $pagenow === 'edit-tags.php' ) {
129
+ if ( $post_type && $taxonomy && $post_type === 'rl_gallery' ) {
130
+ if ( $taxonomy === 'rl_category' ) {
131
+ $pointer = [
132
+ 'content' => '<h3>' . esc_html__( 'Gallery Categories', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Gallery categories allow you to arrange galleries into individual groups that you can potentially use. Here you can create, name and edit them. However, assigning the gallery to the category takes place on the gallery editing screen.', 'responsive-lightbox' ) . '</p>',
133
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
134
+ 'id' => '#wpbody-content h1'
135
+ ];
 
136
 
137
  // next tags?
138
  if ( $rl->options['builder']['tags'] )
139
+ $pointer['function'] = 'window.location="' . esc_url_raw( admin_url( 'edit-tags.php?taxonomy=rl_tag&post_type=rl_gallery' ) ) . '";';
140
  // or settings?
141
  else
142
+ $pointer['function'] = 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ) . '";';
143
+ } elseif ( $taxonomy === 'rl_tag' ) {
144
+ $pointer = [
145
+ 'content' => '<h3>' . esc_html__( 'Gallery Tags', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Gallery tags, like categories, allow you to arrange galleries into groups. You can think of them as keywords, which you can use to further specify your galleries. Here you can create, name and edit them.', 'responsive-lightbox' ) . '</p>',
146
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
147
+ 'id' => '#wpbody-content h1',
148
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ) . '";'
149
+ ];
 
150
  }
151
  }
152
  // settings
153
+ } elseif ( $pagenow === 'admin.php' && $page ) {
 
154
  // general
155
+ if ( $page === 'responsive-lightbox-settings' ) {
156
+ $pointer = [
157
+ 'content' => '<h3>' . esc_html__( 'General Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( "Here are the main settings for Responsive Lightbox & Gallery. They allow you to specify general rules of the plugin's operation and technical parameters of the lightbox effect and gallery. For example - you can choose your favorite lightbox effect, specify for which elements it will automatically launch and set its parameters. You can also choose the default gallery and its settings.", 'responsive-lightbox' ) . '</p>',
158
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
159
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
160
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-configuration' ) ) . '";'
161
+ ];
 
162
  // lightboxes
163
+ } elseif ( $page === 'responsive-lightbox-configuration' ) {
164
+ $pointer = [
165
+ 'content' => '<h3>' . esc_html__( 'Lightboxes Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Each lightbox has different look, possibilities and parameters. Here is a list of available lightbox effects along with their settings. After entering the tab you can see the settings of the currently selected lightbox, but you can also modify or restore the settings of the others.', 'responsive-lightbox' ) . '</p>',
166
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
167
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
168
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-gallery' ) ) . '";'
169
+ ];
 
170
  // galleries
171
+ } elseif ( $page === 'responsive-lightbox-gallery' ) {
172
+ $pointer = [
173
+ 'content' => '<h3>' . esc_html__( 'Galleries Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( "This is the screen of the default gallery settings. As in the case of lightbox effects, there is a list of available galleries and their parameters. After entering the tab you can see the settings of the currently selected gallery. You can modify and adjust them to your needs or restore it's default settings.", 'responsive-lightbox' ) . '</p>',
174
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
175
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
176
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-builder' ) ) . '";'
177
+ ];
 
178
  // builder
179
+ } elseif ( $page === 'responsive-lightbox-builder' ) {
180
+ $pointer = [
181
+ 'content' => '<h3>' . esc_html__( 'Builder Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'You can use the galleries in many ways - insert them into posts using the Add Gallery button, insert manually using shortcodes or add to the theme using functions. But you can also display them in archives just like other post types. Use these settings to specify the functionality of the gallery builder like categories, tags, archives and permalinks.', 'responsive-lightbox' ) . '</p>',
 
182
  'button2' => __( 'Next', 'responsive-lightbox' ),
183
  'id' => '#wpbody-content .wrap .nav-tab-active',
184
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-folders' ) ) . '";'
185
+ ];
186
  // media folders
187
+ } elseif ( $page === 'responsive-lightbox-folders' ) {
188
+ $pointer = [
189
+ 'content' => '<h3>' . esc_html__( 'Folders Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Responsive Lithbox & Gallery comes with an optional Media Folders feature that extends your WordPress Media Library with visual folders. It allows you to organize your attachments in a folder tree structure. Move, copy, rename and delete files and folders with a nice drag and drop interface.', 'responsive-lightbox' ) . '</p>',
190
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
191
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
192
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-capabilities' ) ) . '";'
193
+ ];
 
194
  // capabilities
195
+ } elseif ( $page === 'responsive-lightbox-capabilities' ) {
196
+ $pointer = [
197
+ 'content' => '<h3>' . esc_html__( 'Capabilities Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Capabilities give you the ability to control what users can and cannot do within the plugin. By default only the Administrator role allows a user to perform all possible capabilities. But you can fine tune these settings to match your specific requirements.', 'responsive-lightbox' ) . '</p>',
198
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
199
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
200
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-remote_library' ) ) . '";'
201
+ ];
 
202
  // remote library
203
+ } elseif ( $page === 'responsive-lightbox-remote_library' ) {
204
+ // get tabs
205
+ $tabs = array_keys( $rl->settings->tabs );
206
+
207
+ // get current tab index
208
+ $tab_index = (int) array_search( 'remote_library', $tabs, true );
209
+
210
+ $pointer = [
211
+ 'content' => '<h3>' . esc_html__( 'Remote Library Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Are you looking for free royalty free public domain and CC0-Licensed images for your website? Or you need to access your images stored in photo-sharing apps? Remote Library allows you to use images from multiple sources like Unsplash, Pixabay, Flickr or Instagram directly in your WordPress Media Manager. Now you can create galleries, browse, insert and import images as never before.', 'responsive-lightbox' ) . '</p>',
212
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
213
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
214
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-' . $tabs[$tab_index + 1] ) ) . '";'
215
+ ];
 
 
 
 
 
216
  // licenses
217
+ } elseif ( $page === 'responsive-lightbox-licenses' ) {
218
+ $pointer = [
219
+ 'content' => '<h3>' . esc_html__( 'Licenses Settings', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'This section contains a list of currently installed premium extensions. Activate your licenses to have access to automatic updates from your site. To activate the license, copy and paste the license key for the extension and save the changes. Available license keys can be found on your account on our website.', 'responsive-lightbox' ) . '</p>',
220
+ 'button2' => __( 'Next', 'responsive-lightbox' ),
221
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
222
+ 'function' => 'window.location="' . esc_url_raw( admin_url( 'admin.php?page=responsive-lightbox-addons' ) ) . '";'
223
+ ];
 
224
  // addons
225
+ } elseif ( $page === 'responsive-lightbox-addons' ) {
226
+ $pointer = [
227
+ 'content' => '<h3>' . esc_html__( 'Add-ons', 'responsive-lightbox' ) . '</h3><p>' . esc_html__( 'Responsive Lightbox & Gallery is more than that. Do you need a beautiful lightbox effect, integration with social media, an attractive image gallery? Among our products you will surely find something for yourself. Boost your creativity and enhance your website with these beautiful, easy to use extensions, designed with Responsive Lightbox & Gallery integration in mind.', 'responsive-lightbox' ) . '</p>',
228
+ 'button2' => '',
229
+ 'id' => '#wpbody-content .wrap .nav-tab-active',
230
+ 'function' => ''
231
+ ];
 
232
  // plugins related tabs
233
  } else
234
+ $pointer = apply_filters( 'rl_tour_pointer', [], $page );
235
  }
236
 
237
  // valid pointer?
238
  if ( ! empty( $pointer ) ) {
239
+ $this->print_scripts(
240
+ $pointer['id'],
241
+ [
242
+ 'content' => $pointer['content'],
243
+ 'pointerWidth' => 400,
244
+ 'position' => [
245
+ 'edge' => 'top',
246
+ 'align' => is_rtl() ? 'right' : 'left'
247
+ ]
248
+ ],
249
+ __( 'Close', 'responsive-lightbox' ),
250
+ $pointer['button2'],
251
+ $pointer['function']
252
  );
 
 
253
  }
254
  }
255
 
259
  * @return void
260
  */
261
  public function ignore_tour() {
262
+ if ( isset( $_POST['rl_nonce'] ) && ctype_alnum( $_POST['rl_nonce'] ) && wp_verify_nonce( $_POST['rl_nonce'], 'rl-ignore-tour' ) !== false )
263
  delete_transient( 'rl_active_tour' );
264
 
265
  exit;
266
  }
267
 
268
  /**
269
+ * Print the pointer script.
270
  *
271
  * @return void
272
  */
273
+ public function print_scripts( $selector, $options, $button1, $button2 = false, $function = '' ) {
274
  ?>
275
  <script type="text/javascript">
276
  //<![CDATA[
277
  ( function( $ ) {
278
  // ready event
279
  $( function() {
280
+ var rlPointerOptions = <?php echo json_encode( $options ); ?>;
281
+ var setup;
282
 
283
+ function rlSetIgnore( option, hide, nonce ) {
284
  $.post( ajaxurl, {
285
  action: 'rl-ignore-tour',
286
  rl_nonce: nonce
289
  $( '#' + hide ).hide();
290
  $( '#hidden_ignore_' + option ).val( 'ignore' );
291
  }
292
+ } );
 
293
  }
294
 
295
+ rlPointerOptions = $.extend( rlPointerOptions, {
296
  buttons: function( event, t ) {
297
+ var button = $( '<a id="rl-pointer-close" style="margin-left: 5px;" class="button-secondary">' + '<?php esc_html_e( $button1 ); ?>' + '</a>' );
298
 
299
  button.on( 'click.pointer', function() {
300
  t.element.pointer( 'close' );
306
  } );
307
 
308
  setup = function() {
309
+ $( '<?php echo esc_js( $selector ); ?>' ).pointer( rlPointerOptions ).pointer( 'open' );
310
 
311
  <?php if ( $button2 ) { ?>
312
 
313
+ $( '#rl-pointer-close' ).after( '<a id="pointer-primary" class="button-primary">' + '<?php esc_html_e( $button2 ); ?>' + '</a>' );
314
  $( '#pointer-primary' ).on( 'click', function() {
315
+ <?php echo $function; ?>
316
  } );
317
 
318
  <?php } ?>
319
 
320
  $( '#rl-pointer-close' ).on( 'click', function() {
321
+ rlSetIgnore( 'tour', 'wp-pointer-0', '<?php echo esc_js( wp_create_nonce( 'rl-ignore-tour' ) ); ?>' );
322
  } );
323
  };
324
 
325
+ if ( rlPointerOptions.position && rlPointerOptions.position.defer_loading )
326
  $( window ).on( 'load.wp-pointers', setup );
327
  else
328
  $( document ).ready( setup );
332
  </script>
333
  <?php
334
  }
335
+ }
includes/class-welcome.php CHANGED
@@ -19,9 +19,9 @@ class Responsive_Lightbox_Welcome_Page {
19
  */
20
  public function __construct() {
21
  // actions
22
- add_action( 'admin_menu', array( $this, 'admin_menus' ) );
23
- add_action( 'admin_head', array( $this, 'admin_head' ) );
24
- add_action( 'admin_init', array( $this, 'welcome' ) );
25
  }
26
 
27
  /**
@@ -31,8 +31,9 @@ class Responsive_Lightbox_Welcome_Page {
31
  */
32
  public function admin_menus() {
33
  $welcome_page_title = __( 'Welcome to Responsive Lightbox & Gallery', 'responsive-lightbox' );
 
34
  // about
35
- $about = add_dashboard_page( $welcome_page_title, $welcome_page_title, 'manage_options', 'responsive-lightbox-about', array( $this, 'about_screen' ) );
36
  }
37
 
38
  /**
@@ -53,21 +54,19 @@ class Responsive_Lightbox_Welcome_Page {
53
  // get plugin version
54
  $plugin_version = substr( get_option( 'responsive_lightbox_version' ), 0, 3 );
55
  ?>
56
- <h2 style="text-align: left; font-size: 29px; padding-bottom: 0;"><?php _e( 'Welcome to', 'responsive-lightbox' ); ?></h2>
57
- <h1 style="margin-top: 0;"><?php printf( __( 'Responsive Lightbox & Gallery %s', 'responsive-lightbox' ), $plugin_version ); ?></h1>
58
 
59
  <div class="about-text">
60
- <?php
61
- printf( __( 'Thank you for choosing Responsive Lightbox & Gallery - the most popular lightbox plugin and a powerful gallery builder for WordPress.', 'responsive-lightbox' ), $plugin_version );
62
- ?>
63
  </div>
64
 
65
- <div class="rl-badge" style="position: absolute; top: 0; right: 0; box-shadow: 0 1px 3px rgba(0,0,0,.1); max-width: 180px;"><img src="<?php echo RESPONSIVE_LIGHTBOX_URL . '/images/logo-rl.png'; ?>" width="180" height="180" /></div>
66
 
67
  <div class="changelog">
68
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-tour' ) ); ?>" class="button button-primary button-hero"><?php _e( 'Start Tour', 'responsive-lightbox' ); ?></a>
69
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ); ?>" class="button button-hero"><?php _e( 'Settings', 'responsive-lightbox' ); ?></a>
70
- <a href="https://dfactory.eu/products/responsive-lightbox-gallery-extensions/?utm_source=responsive-lightbox-welcome&utm_medium=button&utm_campaign=dfactory-plugins" class="button button-hero" target="_blank"><?php _e( 'Addons', 'responsive-lightbox' ); ?></a>
71
  </div>
72
 
73
  <hr />
@@ -86,30 +85,30 @@ class Responsive_Lightbox_Welcome_Page {
86
  <?php $this->intro(); ?>
87
 
88
  <div class="feature-section">
89
- <h2><?php _e( 'Advanced Gallery Builder', 'responsive-lightbox' ); ?></h2>
90
- <p><?php _e( 'Responsive Lightbox & Gallery comes with a powerful gallery builder right out of the box that lets you manage galleries the same way you manage posts and pages on your WordPress website. You can add images to your gallery, adjust its settings and lightbox scripts, and configure its display options.', 'responsive-lightbox' ); ?></p>
91
- <img src="<?php echo RESPONSIVE_LIGHTBOX_URL . '/images/welcome.png'; ?>" />
92
  </div>
93
 
94
  <div class="feature-section">
95
- <h2><?php _e( 'Multiple Lightbox Effects', 'responsive-lightbox' ); ?></h2>
96
- <p><?php _e( "Responsive Lightbox & Gallery gives you the control to beautify your images, videos, and galleries using lightbox scripts that look great on all devices. We've got everything from lightweight, functional lightboxes to heavy-customizable, fancy ones.", 'responsive-lightbox' ); ?></p>
97
  </div>
98
 
99
  <div class="feature-section">
100
- <h2><?php _e( 'Easy Setup', 'responsive-lightbox' ); ?></h2>
101
- <p><?php _e( 'A lot goes into making a good first impression - especially when your site is doing all the talking. Responsive Lightbox & Gallery automatically adds lightbox effects to all of your image galleries, image links, and video links so you can sit back and relax while we make sure your website looks its best.', 'responsive-lightbox' ); ?></p>
102
  </div>
103
 
104
  <div class="feature-section">
105
- <h2><?php _e( 'Powerful Addons', 'responsive-lightbox' ); ?></h2>
106
- <p><?php printf( __( 'Responsive Lightbox & Gallery enhances your site by making its images and galleries look visually appealing to your site users. And when you want to kick things up a notch you can pair the free, core plugin with <del>one of 10</del> one of 12 <a href="%s" target="_blank">premium extensions.</a>', 'responsive-lightbox' ), 'https://dfactory.eu/products/responsive-lightbox-gallery-extensions/' ); ?></p>
107
  </div>
108
 
109
  <hr />
110
 
111
  <div class="return-to-dashboard">
112
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ); ?>"><?php _e( 'Go to Settings', 'responsive-lightbox' ); ?></a>
113
  </div>
114
 
115
  </div>
@@ -122,7 +121,6 @@ class Responsive_Lightbox_Welcome_Page {
122
  * @return void
123
  */
124
  public function welcome() {
125
-
126
  // bail if no activation redirect transient is set
127
  if ( ! get_transient( 'rl_activation_redirect' ) )
128
  return;
@@ -134,7 +132,7 @@ class Responsive_Lightbox_Welcome_Page {
134
  if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) )
135
  return;
136
 
137
- if ( (isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action']) && (isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'responsive-lightbox.php' )) )
138
  return;
139
 
140
  wp_safe_redirect( admin_url( 'index.php?page=responsive-lightbox-about' ) );
19
  */
20
  public function __construct() {
21
  // actions
22
+ add_action( 'admin_menu', [ $this, 'admin_menus' ] );
23
+ add_action( 'admin_head', [ $this, 'admin_head' ] );
24
+ add_action( 'admin_init', [ $this, 'welcome' ] );
25
  }
26
 
27
  /**
31
  */
32
  public function admin_menus() {
33
  $welcome_page_title = __( 'Welcome to Responsive Lightbox & Gallery', 'responsive-lightbox' );
34
+
35
  // about
36
+ $about = add_dashboard_page( $welcome_page_title, $welcome_page_title, 'manage_options', 'responsive-lightbox-about', [ $this, 'about_screen' ] );
37
  }
38
 
39
  /**
54
  // get plugin version
55
  $plugin_version = substr( get_option( 'responsive_lightbox_version' ), 0, 3 );
56
  ?>
57
+ <h2 style="text-align: left; font-size: 29px; padding-bottom: 0;"><?php esc_html_e( 'Welcome to', 'responsive-lightbox' ); ?></h2>
58
+ <h1 style="margin-top: 0;"><?php printf( esc_html__( 'Responsive Lightbox & Gallery %s', 'responsive-lightbox' ), $plugin_version ); ?></h1>
59
 
60
  <div class="about-text">
61
+ <?php esc_html__( 'Thank you for choosing Responsive Lightbox & Gallery - the most popular lightbox plugin and a powerful gallery builder for WordPress.', 'responsive-lightbox' ); ?>
 
 
62
  </div>
63
 
64
+ <div class="rl-badge" style="position: absolute; top: 0; right: 0; box-shadow: 0 1px 3px rgba(0,0,0,.1); max-width: 180px;"><img src="<?php echo esc_url( RESPONSIVE_LIGHTBOX_URL . '/images/logo-rl.png' ); ?>" width="180" height="180" /></div>
65
 
66
  <div class="changelog">
67
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-tour' ) ); ?>" class="button button-primary button-hero"><?php esc_html_e( 'Start Tour', 'responsive-lightbox' ); ?></a>
68
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ); ?>" class="button button-hero"><?php esc_html_e( 'Settings', 'responsive-lightbox' ); ?></a>
69
+ <a href="https://dfactory.eu/products/responsive-lightbox-gallery-extensions/?utm_source=responsive-lightbox-welcome&utm_medium=button&utm_campaign=dfactory-plugins" class="button button-hero" target="_blank"><?php esc_html_e( 'Addons', 'responsive-lightbox' ); ?></a>
70
  </div>
71
 
72
  <hr />
85
  <?php $this->intro(); ?>
86
 
87
  <div class="feature-section">
88
+ <h2><?php esc_html_e( 'Advanced Gallery Builder', 'responsive-lightbox' ); ?></h2>
89
+ <p><?php esc_html_e( 'Responsive Lightbox & Gallery comes with a powerful gallery builder right out of the box that lets you manage galleries the same way you manage posts and pages on your WordPress website. You can add images to your gallery, adjust its settings and lightbox scripts, and configure its display options.', 'responsive-lightbox' ); ?></p>
90
+ <img src="<?php echo esc_url( RESPONSIVE_LIGHTBOX_URL . '/images/welcome.png' ); ?>" />
91
  </div>
92
 
93
  <div class="feature-section">
94
+ <h2><?php esc_html_e( 'Multiple Lightbox Effects', 'responsive-lightbox' ); ?></h2>
95
+ <p><?php esc_html_e( "Responsive Lightbox & Gallery gives you the control to beautify your images, videos, and galleries using lightbox scripts that look great on all devices. We've got everything from lightweight, functional lightboxes to heavy-customizable, fancy ones.", 'responsive-lightbox' ); ?></p>
96
  </div>
97
 
98
  <div class="feature-section">
99
+ <h2><?php esc_html_e( 'Easy Setup', 'responsive-lightbox' ); ?></h2>
100
+ <p><?php esc_html_e( 'A lot goes into making a good first impression - especially when your site is doing all the talking. Responsive Lightbox & Gallery automatically adds lightbox effects to all of your image galleries, image links, and video links so you can sit back and relax while we make sure your website looks its best.', 'responsive-lightbox' ); ?></p>
101
  </div>
102
 
103
  <div class="feature-section">
104
+ <h2><?php esc_html_e( 'Powerful Addons', 'responsive-lightbox' ); ?></h2>
105
+ <p><?php printf( __( 'Responsive Lightbox & Gallery enhances your site by making its images and galleries look visually appealing to your site users. And when you want to kick things up a notch you can pair the free, core plugin with <del>one of 10</del> one of 13 <a href="%s" target="_blank">premium extensions.</a>', 'responsive-lightbox' ), 'https://dfactory.eu/products/responsive-lightbox-gallery-extensions/?utm_source=responsive-lightbox-welcome&utm_medium=link&utm_campaign=dfactory-plugins' ); ?></p>
106
  </div>
107
 
108
  <hr />
109
 
110
  <div class="return-to-dashboard">
111
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=responsive-lightbox-settings' ) ); ?>"><?php esc_html_e( 'Go to Settings', 'responsive-lightbox' ); ?></a>
112
  </div>
113
 
114
  </div>
121
  * @return void
122
  */
123
  public function welcome() {
 
124
  // bail if no activation redirect transient is set
125
  if ( ! get_transient( 'rl_activation_redirect' ) )
126
  return;
132
  if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) )
133
  return;
134
 
135
+ if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' === $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'responsive-lightbox.php' ) ) )
136
  return;
137
 
138
  wp_safe_redirect( admin_url( 'index.php?page=responsive-lightbox-about' ) );
includes/class-widgets.php CHANGED
@@ -19,7 +19,7 @@ class Responsive_Lightbox_Widgets {
19
  */
20
  public function __construct() {
21
  // actions
22
- add_action( 'widgets_init', array( $this, 'register_widgets' ) );
23
  }
24
 
25
  /**
@@ -40,11 +40,11 @@ class Responsive_Lightbox_Widgets {
40
  */
41
  class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
42
 
43
- private $rlg_defaults = array();
44
- private $rlg_orders = array();
45
- private $rlg_order_types = array();
46
- private $rlg_image_sizes = array();
47
- private $rlg_gallery_types = array();
48
 
49
  /**
50
  * Class constructor.
@@ -55,13 +55,13 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
55
  parent::__construct(
56
  'Responsive_Lightbox_Gallery_Widget',
57
  __( 'Gallery', 'responsive-lightbox' ),
58
- array(
59
  'description' => __( 'Displays an image gallery.', 'responsive-lightbox' ),
60
  'classname' => 'rl-gallery-widget'
61
- )
62
  );
63
 
64
- $this->rlg_defaults = array(
65
  'title' => __( 'Gallery', 'responsive-lightbox' ),
66
  'orderby' => 'menu_order',
67
  'order' => 'asc',
@@ -70,34 +70,34 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
70
  'type' => 'none',
71
  'atts' => '',
72
  'ids' => ''
73
- );
74
 
75
- $this->rlg_orders = array(
76
  'menu_order' => __( 'Menu order', 'responsive-lightbox' ),
77
  'title' => __( 'Title', 'responsive-lightbox' ),
78
  'post_date' => __( 'Image date', 'responsive-lightbox' ),
79
  'ID' => __( 'ID', 'responsive-lightbox' ),
80
  'rand' => __( 'Random', 'responsive-lightbox' )
81
- );
82
 
83
- $this->rlg_order_types = array(
84
  'asc' => __( 'Ascending', 'responsive-lightbox' ),
85
  'desc' => __( 'Descending', 'responsive-lightbox' )
86
- );
87
 
88
  $gallery_types = apply_filters( 'rl_gallery_types', Responsive_Lightbox()->gallery_types );
89
 
90
  if ( ! empty( $gallery_types ) ) {
91
  $this->rlg_gallery_types = array_merge(
92
- array(
93
  'none' => __( 'None', 'responsive-lightbox' ),
94
  'default' => __( 'Default', 'responsive-lightbox' )
95
- ),
96
  $gallery_types
97
  );
98
  }
99
 
100
- $this->rlg_image_sizes = array_merge( array( 'full' ), get_intermediate_image_sizes() );
101
 
102
  sort( $this->rlg_image_sizes, SORT_STRING );
103
  }
@@ -112,8 +112,36 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
112
  public function widget( $args, $instance ) {
113
  $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
114
 
115
- $html = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? $instance['title'] : '' ) . $args['after_title'];
116
- $html .= do_shortcode( '[gallery link="file" columns="' . $instance['columns'] . '" size="' . $instance['size'] . '" ' . ( $instance['type'] !== 'none' ? 'type="' . $instance['type'] . '"' : '' ) . ' ids="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '" orderby="' . $instance['orderby'] . '" order="' . $instance['order'] . '"' . ( $instance['atts'] !== '' ? ' ' . $instance['atts'] : '' ) . ']' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  $html .= $args['after_widget'];
118
 
119
  echo apply_filters( 'rl_gallery_widget_html', $html, $instance );
@@ -125,19 +153,19 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
125
  * @return void
126
  */
127
  public function form( $instance ) {
128
- $attachments = ! empty( $instance['ids'] ) ? array_filter( explode( ',', $instance['ids'] ) ) : array();
129
 
130
  $html = '
131
  <div class="rl-gallery-widget-container">
132
  <p>
133
- <label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'responsive-lightbox' ) . ':</label>
134
  <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rlg_defaults['title'] ) . '" />
135
  </p>
136
  <div id="' . $this->get_field_id( 'gallery' ) . '" class="rl-gallery-widget' . ( ! empty( $attachments ) ? ' has-image' : '' ) . '">
137
  <input type="hidden" class="rl-gallery-ids" id="' . $this->get_field_id( 'ids' ) . '" name="' . $this->get_field_name( 'ids' ) . '" value="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '">';
138
 
139
  $html .= '
140
- <a href="#" class="rl-gallery-widget-select button button-secondary">' . __( 'Select images', 'responsive-lightbox' ) . '</a>
141
  <div class="rl-gallery-widget-content">
142
  <ul id="' . $this->get_field_id( 'gallery-images' ) . '" class="rl-gallery-images">';
143
 
@@ -147,9 +175,9 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
147
  continue;
148
 
149
  $html .= '
150
- <li class="rl-gallery-image" data-attachment_id="' . absint( $attachment_id ) . '">
151
  <div class="rl-gallery-inner">' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '</div>
152
- <div class="rl-gallery-actions"><a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' . __( 'Delete image', 'responsive-lightbox' ) . '"></a></div>
153
  </li>';
154
  }
155
  }
@@ -162,7 +190,7 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
162
 
163
  if ( ! empty( $this->rlg_gallery_types ) ) {
164
  $html .= '
165
- <label for="' . $this->get_field_id( 'type' ) . '">' . __( 'Gallery type', 'responsive-lightbox' ) . ':</label>
166
  <select id="' . $this->get_field_id( 'type' ) . '" class="widefat" name="' . $this->get_field_name( 'type' ) . '">';
167
 
168
  foreach ( $this->rlg_gallery_types as $id => $type ) {
@@ -172,12 +200,12 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
172
 
173
  $html .= '
174
  </select>
175
- </p>
176
- <p>';
177
  }
178
 
179
  $html .= '
180
- <label for="' . $this->get_field_id( 'orderby' ) . '">' . __( 'Order by', 'responsive-lightbox' ) . ':</label>
181
  <select id="' . $this->get_field_id( 'orderby' ) . '" class="widefat" name="' . $this->get_field_name( 'orderby' ) . '">';
182
 
183
  foreach ( $this->rlg_orders as $id => $orderby ) {
@@ -187,9 +215,9 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
187
 
188
  $html .= '
189
  </select>
190
- </p>
191
- <p>
192
- <label for="' . $this->get_field_id( 'order' ) . '">' . __( 'Order', 'responsive-lightbox' ) . ':</label>
193
  <select id="' . $this->get_field_id( 'order' ) . '" class="widefat" name="' . $this->get_field_name( 'order' ) . '">';
194
 
195
  foreach ( $this->rlg_order_types as $id => $order ) {
@@ -199,9 +227,9 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
199
 
200
  $html .= '
201
  </select>
202
- </p>
203
- <p>
204
- <label for="' . $this->get_field_id( 'size' ) . '">' . __( 'Image size', 'responsive-lightbox' ) . ':</label>
205
  <select id="' . $this->get_field_id( 'size' ) . '" class="widefat" name="' . $this->get_field_name( 'size' ) . '">';
206
 
207
  foreach ( $this->rlg_image_sizes as $size ) {
@@ -211,15 +239,15 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
211
 
212
  $html .= '
213
  </select>
214
- </p>
215
- <p>
216
- <label for="' . $this->get_field_id( 'columns' ) . '">' . __( 'Number of columns', 'responsive-lightbox' ) . ':</label>
217
- <input id="' . $this->get_field_id( 'columns' ) . '" class="small-text" name="' . $this->get_field_name( 'columns' ) . '" type="number" min="0" value="' . esc_attr( isset( $instance['columns'] ) ? $instance['columns'] : $this->rlg_defaults['columns'] ) . '" />
218
- </p>
219
- <p>
220
- <label for="' . $this->get_field_id( 'atts' ) . '">' . __( 'Custom attributes', 'responsive-lightbox' ) . ':</label>
221
  <br />
222
- <textarea id="' . $this->get_field_id( 'atts' ) . '" class="widefat" name="' . $this->get_field_name( 'atts' ) . '">' . esc_textarea( isset( $instance['atts'] ) ? $instance['atts'] : $this->rlg_defaults['atts'] ) . '</textarea><span class="description">' . __( 'Custom gallery shortcode attributes (optional).', 'responsive-lightbox' ) . '</span>
223
  </p>
224
  </div>';
225
 
@@ -235,36 +263,34 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
235
  */
236
  public function update( $new_instance, $old_instance ) {
237
  // title
238
- $old_instance['title'] = array_key_exists( 'title', $new_instance ) ? trim( $new_instance['title'] ) : $this->rlg_defaults['title'];
239
 
240
  // order by
241
- $old_instance['orderby'] = array_key_exists( 'orderby', $new_instance ) && array_key_exists( $new_instance['orderby'], $this->rlg_orders ) ? $new_instance['orderby'] : $this->rlg_defaults['orderby'];
242
 
243
  // order
244
- $old_instance['order'] = array_key_exists( 'order', $new_instance ) && array_key_exists( $new_instance['order'], $this->rlg_order_types ) ? $new_instance['order'] : $this->rlg_defaults['order'];
245
 
246
  // image size
247
- $old_instance['size'] = array_key_exists( 'size', $new_instance ) && in_array( $new_instance['size'], $this->rlg_image_sizes, true ) ? $new_instance['size'] : $this->rlg_defaults['size'];
248
 
249
  // gallery type
250
- $old_instance['type'] = array_key_exists( 'type', $new_instance ) && array_key_exists( $new_instance['type'], $this->rlg_gallery_types ) ? $new_instance['type'] : $this->rlg_defaults['type'];
251
 
252
  // number of columns
253
- $old_instance['columns'] = array_key_exists( 'columns', $new_instance ) ? ( ( $columns = (int) $new_instance['columns'] ) > 0 ? $columns : $this->rlg_defaults['columns'] ) : $this->rlg_defaults['columns'];
254
 
255
  // image ids
256
- if ( array_key_exists( 'ids', $new_instance ) && ! empty( $new_instance['ids'] ) ) {
257
  // get unique and non empty attachment ids only
258
- $attachment_ids = array_unique( array_filter( array_map( 'intval', explode( ',', $new_instance['ids'] ) ) ) );
259
-
260
- $old_instance['ids'] = implode( ',', $attachment_ids );
261
  } else
262
  $old_instance['ids'] = $this->rlg_defaults['ids'];
263
 
264
  // custom attributes
265
- $atts = preg_replace( '/\s+/', ' ', trim( str_replace( array( "\r\n", "\n\r", "\n", "\r" ), '', array_key_exists( 'atts', $new_instance ) ? $new_instance['atts'] : $this->rlg_defaults['atts'] ) ) );
266
 
267
- $new_atts = array();
268
 
269
  if ( $atts !== '' ) {
270
  $atts_exp = explode( '" ', $atts );
@@ -279,7 +305,7 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
279
  foreach ( $atts_exp as $id => $attribute ) {
280
  $check = $attribute . ( $last === $id ? '' : '"' );
281
 
282
- if ( preg_match( '/^[a-z0-9_-]+=\"(.+)\"$/', $check ) === 1 )
283
  $new_atts[] = $check;
284
  }
285
  }
@@ -301,11 +327,11 @@ class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
301
  */
302
  class Responsive_Lightbox_Image_Widget extends WP_Widget {
303
 
304
- private $rli_defaults = array();
305
- private $rli_text_positions = array();
306
- private $rli_link_to = array();
307
- private $rli_aligns = array();
308
- private $rli_image_sizes = array();
309
 
310
  /**
311
  * Class constructor.
@@ -316,13 +342,13 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
316
  parent::__construct(
317
  'Responsive_Lightbox_Image_Widget',
318
  __( 'Image', 'responsive-lightbox' ),
319
- array(
320
  'description' => __( 'Displays a single image.', 'responsive-lightbox' ),
321
  'classname' => 'rl-image-widget'
322
- )
323
  );
324
 
325
- $this->rli_defaults = array(
326
  'title' => __( 'Image', 'responsive-lightbox' ),
327
  'image_id' => 0,
328
  'responsive' => true,
@@ -333,30 +359,31 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
333
  'text' => '',
334
  'autobr' => false,
335
  'text_position' => 'below_image',
336
- 'text_align' => 'none',
337
- );
338
 
339
- $this->rli_text_positions = array(
340
- 'below_image' => __( 'Below the image', 'responsive-lightbox' ),
341
  'above_image' => __( 'Above the image', 'responsive-lightbox' )
342
- );
343
 
344
- $this->rli_link_to = array(
345
  'none' => __( 'None', 'responsive-lightbox' ),
346
  'file' => __( 'Media File', 'responsive-lightbox' ),
347
  'post' => __( 'Attachment Page', 'responsive-lightbox' ),
348
  'custom' => __( 'Custom URL', 'responsive-lightbox' )
349
- );
350
 
351
- $this->rli_aligns = array(
352
  'none' => __( 'None', 'responsive-lightbox' ),
353
  'left' => __( 'Left', 'responsive-lightbox' ),
354
  'center' => __( 'Center', 'responsive-lightbox' ),
355
  'right' => __( 'Right', 'responsive-lightbox' ),
356
  'justify' => __( 'Justify', 'responsive-lightbox' )
357
- );
 
 
358
 
359
- $this->rli_image_sizes = array_merge( array( 'full' ), get_intermediate_image_sizes() );
360
  sort( $this->rli_image_sizes, SORT_STRING );
361
  }
362
 
@@ -368,17 +395,6 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
368
  * @return void
369
  */
370
  public function widget( $args, $instance ) {
371
- $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
372
- $title = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? $instance['title'] : '' ) . $args['after_title'];
373
-
374
- if ( $instance['autobr'] === true ) {
375
- $text = wpautop( $instance['text'] );
376
- } else {
377
- $text = html_entity_decode( $instance['text'], ENT_QUOTES, 'UTF-8' );
378
- }
379
-
380
- $image = wp_get_attachment_image_src( $instance['image_id'], $instance['size'], false );
381
-
382
  switch ( $instance['link_to'] ) {
383
  case 'file':
384
  $file = wp_get_attachment_image_src( $instance['image_id'], 'full', false );
@@ -396,46 +412,56 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
396
  case 'none':
397
  default:
398
  $href = '';
399
- break;
400
  }
401
 
 
402
  if ( $instance['image_align'] === 'left' )
403
- $image_align = ' style="float: left;"';
404
  elseif ( $instance['image_align'] === 'center' )
405
- $image_align = ' style="margin-left: auto; margin-right: auto; display: block;"';
406
  elseif ( $instance['image_align'] === 'right' )
407
- $image_align = ' style="float: right;"';
408
  else
409
  $image_align = '';
410
 
 
411
  if ( $instance['text_align'] === 'left' )
412
- $text_align = ' style="text-align: left; display: block;"';
413
  elseif ( $instance['text_align'] === 'center' )
414
- $text_align = ' style="text-align: center; display: block;"';
415
  elseif ( $instance['text_align'] === 'right' )
416
- $text_align = ' style="text-align: right; display: block;"';
417
  elseif ( $instance['text_align'] === 'justify' )
418
- $text_align = ' style="text-align: justify; display: block;"';
419
  else
420
  $text_align = '';
421
 
 
 
422
 
423
- $text_position = $instance['text_position'];
424
  $width = $instance['responsive'] === false ? $image[1] : '100%';
425
  $height = $instance['responsive'] === false ? $image[2] : 'auto';
426
  $post = get_post( $instance['image_id'] );
427
  $image_title = isset( $post->post_title ) ? $post->post_title : '';
428
  $alt = (string) get_post_meta( $instance['image_id'], '_wp_attachment_image_alt', true );
 
429
 
430
- $html = $title;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
 
432
- if ( $text_position === 'below_image' ) {
433
- $html .= ($href !== '' ? '<a href="' . $href . '" class="rl-image-widget-link">' : '') . '<img class="rl-image-widget-image" src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" title="' . $image_title . '" alt="' . $alt . '"' . $image_align . ' />' . ($href !== '' ? '</a>' : '');
434
- $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
435
- } else {
436
- $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
437
- $html .= ($href !== '' ? '<a href="' . $href . '" class="rl-image-widget-link">' : '') . '<img class="rl-image-widget-image" src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" title="' . $image_title . '" alt="' . $alt . '"' . $image_align . ' />' . ($href !== '' ? '</a>' : '');
438
- }
439
  $html .= $args['after_widget'];
440
 
441
  echo apply_filters( 'rl_image_widget_html', $html, $instance );
@@ -447,7 +473,7 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
447
  * @return void
448
  */
449
  public function form( $instance ) {
450
- $image_id = (int) (isset( $instance['image_id'] ) ? $instance['image_id'] : $this->rli_defaults['image_id']);
451
  $image = '';
452
 
453
  if ( ! empty( $image_id ) )
@@ -459,98 +485,99 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
459
  $html = '
460
  <div class="rl-image-widget-container">
461
  <p>
462
- <label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'responsive-lightbox' ) . '</label>
463
  <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rli_defaults['title'] ) . '" />
464
  </p>
465
  <div class="rl-image-widget' . ( ! empty( $image_id ) ? ' has-image' : '' ) . '">
466
- <input class="rl-image-widget-image-id" type="hidden" name="' . $this->get_field_name( 'image_id' ) . '" value="' . $image_id . '" />
467
- <a href="#" class="rl-image-widget-select button button-secondary">' . __( 'Select image', 'responsive-lightbox' ) . '</a>
468
  <div class="rl-image-widget-content">';
469
- if ( ! empty( $image ) ) {
 
470
  $html .= $image;
471
- }
472
  $html .= '
473
  </div>
474
  </div>
475
  <p>
476
- <input id="' . $this->get_field_id( 'responsive' ) . '" type="checkbox" name="' . $this->get_field_name( 'responsive' ) . '" value="" ' . checked( true, (isset( $instance['responsive'] ) ? $instance['responsive'] : $this->rli_defaults['responsive'] ), false ) . ' /> <label for="' . $this->get_field_id( 'responsive' ) . '">' . __( 'Force responsive', 'responsive-lightbox' ) . '</label>
477
  </p>';
478
 
479
  $html .= '
480
  <p>
481
- <label for="' . $this->get_field_id( 'size' ) . '">' . __( 'Size', 'responsive-lightbox' ) . '</label>
482
  <select class="rl-image-size-select widefat" id="' . $this->get_field_id( 'size' ) . '" name="' . $this->get_field_name( 'size' ) . '">';
483
 
484
- $size_type = (isset( $instance['size'] ) ? $instance['size'] : $this->rli_defaults['size']);
485
 
486
  foreach ( $this->rli_image_sizes as $size ) {
487
  $html .= '
488
- <option value="' . esc_attr( $size ) . '" ' . selected( $size, $size_type, false ) . '>' . $size . '</option>';
489
  }
490
 
491
  $html .= '
492
  </select>
493
  </p>
494
  <p>
495
- <label for="' . $this->get_field_id( 'link_to' ) . '">' . __( 'Link to', 'responsive-lightbox' ) . '</label>
496
  <select class="rl-image-link-to widefat" id="' . $this->get_field_id( 'link_to' ) . '" name="' . $this->get_field_name( 'link_to' ) . '">';
497
 
498
- $link_type = (isset( $instance['link_to'] ) ? $instance['link_to'] : $this->rli_defaults['link_to']);
499
 
500
  foreach ( $this->rli_link_to as $id => $type ) {
501
  $html .= '
502
- <option value="' . esc_attr( $id ) . '" ' . selected( $id, $link_type, false ) . '>' . $type . '</option>';
503
  }
504
 
505
  $html .= '
506
  </select>
507
  </p>
508
- <p class="rl-image-link-url"' . ($link_type === 'custom' ? '' : ' style="display: none;"') . '>
509
- <label for="' . $this->get_field_id( 'link_custom_url' ) . '">' . __( 'URL', 'responsive-lightbox' ) . '</label>
510
  <input id="' . $this->get_field_id( 'link_custom_url' ) . '" class="widefat" name="' . $this->get_field_name( 'link_custom_url' ) . '" type="text" value="' . esc_attr( isset( $instance['link_custom_url'] ) ? $instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] ) . '" />
511
  </p>';
512
 
513
  $html .= '
514
  <p>
515
- <label for="' . $this->get_field_id( 'image_align' ) . '">' . __( 'Image align', 'responsive-lightbox' ) . '</label>
516
  <select id="' . $this->get_field_id( 'image_align' ) . '" class="widefat" name="' . $this->get_field_name( 'image_align' ) . '">';
517
 
518
  foreach ( $this->rli_aligns as $id => $image_align ) {
519
- if ( $id != 'justify' )
520
  $html .= '
521
- <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['image_align'] ) ? $instance['image_align'] : $this->rli_defaults['image_align'] ), false ) . '>' . $image_align . '</option>';
522
  }
523
 
524
  $html .= '
525
  </select>
526
  </p>
527
  <p>
528
- <label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'responsive-lightbox' ) . '</label>
529
- <textarea id="' . $this->get_field_id( 'text' ) . '" class="widefat" name="' . $this->get_field_name( 'text' ) . '" rows="4">' . (isset( $instance['text'] ) ? $instance['text'] : $this->rli_defaults['text']) . '</textarea>
530
  </p>
531
  <p>
532
- <input id="' . $this->get_field_id( 'autobr' ) . '" type="checkbox" name="' . $this->get_field_name( 'autobr' ) . '" value="" ' . checked( true, (isset( $instance['autobr'] ) ? $instance['autobr'] : $this->rli_defaults['autobr'] ), false ) . ' /> <label for="' . $this->get_field_id( 'autobr' ) . '">' . __( 'Automatically add paragraphs', 'responsive-lightbox' ) . '</label>
533
  </p>';
534
 
535
- $html .= '
536
  <p>
537
- <label for="' . $this->get_field_id( 'text_position' ) . '">' . __( 'Text position', 'responsive-lightbox' ) . '</label>
538
  <select id="' . $this->get_field_id( 'text_position' ) . '" class="widefat" name="' . $this->get_field_name( 'text_position' ) . '">';
539
 
540
  foreach ( $this->rli_text_positions as $id => $text_position ) {
541
  $html .= '
542
- <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_position'] ) ? $instance['text_position'] : $this->rli_defaults['text_position'] ), false ) . '>' . $text_position . '</option>';
543
  }
544
 
545
  $html .= '
546
  </select>
547
  </p>
548
- <label for="' . $this->get_field_id( 'text_align' ) . '">' . __( 'Text align', 'responsive-lightbox' ) . '</label>
549
  <select id="' . $this->get_field_id( 'text_align' ) . '" class="widefat" name="' . $this->get_field_name( 'text_align' ) . '">';
550
 
551
  foreach ( $this->rli_aligns as $id => $text_align ) {
552
  $html .= '
553
- <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_align'] ) ? $instance['text_align'] : $this->rli_defaults['text_align'] ), false ) . '>' . $text_align . '</option>';
554
  }
555
 
556
  $html .= '
@@ -569,17 +596,26 @@ class Responsive_Lightbox_Image_Widget extends WP_Widget {
569
  * @return array
570
  */
571
  public function update( $new_instance, $old_instance ) {
 
 
 
 
 
 
 
 
 
 
 
 
572
  $old_instance['title'] = sanitize_text_field( isset( $new_instance['title'] ) ? $new_instance['title'] : $this->rli_defaults['title'] );
573
- $old_instance['image_id'] = (int) (isset( $new_instance['image_id'] ) ? $new_instance['image_id'] : $this->rli_defaults['image_id']);
574
- $old_instance['responsive'] = isset( $new_instance['responsive'] ) ? true : false;
575
- $old_instance['size'] = (isset( $new_instance['size'] ) && in_array( $new_instance['size'], $this->rli_image_sizes, true ) ? $new_instance['size'] : $this->rli_defaults['size']);
576
- $old_instance['link_to'] = (isset( $new_instance['link_to'] ) && in_array( $new_instance['link_to'], array_keys( $this->rli_link_to ), true ) ? $new_instance['link_to'] : $this->rli_defaults['link_to']);
577
- $old_instance['link_custom_url'] = esc_url( isset( $new_instance['link_custom_url'] ) ? $new_instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] );
578
- $old_instance['image_align'] = (isset( $new_instance['image_align'] ) && in_array( $new_instance['image_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['image_align'] : $this->rli_defaults['image_align']);
579
- $old_instance['text'] = wp_kses_post( isset( $new_instance['text'] ) ? $new_instance['text'] : $this->rli_defaults['text'] );
580
- $old_instance['autobr'] = isset( $new_instance['autobr'] ) ? true : false;
581
- $old_instance['text_position'] = (isset( $new_instance['text_position'] ) && in_array( $new_instance['text_position'], array_keys( $this->rli_text_positions ), true ) ? $new_instance['text_position'] : $this->rli_defaults['text_position']);
582
- $old_instance['text_align'] = (isset( $new_instance['text_align'] ) && in_array( $new_instance['text_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['text_align'] : $this->rli_defaults['text_align']);
583
 
584
  return $old_instance;
585
  }
19
  */
20
  public function __construct() {
21
  // actions
22
+ add_action( 'widgets_init', [ $this, 'register_widgets' ] );
23
  }
24
 
25
  /**
40
  */
41
  class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
42
 
43
+ private $rlg_defaults = [];
44
+ private $rlg_orders = [];
45
+ private $rlg_order_types = [];
46
+ private $rlg_image_sizes = [];
47
+ private $rlg_gallery_types = [];
48
 
49
  /**
50
  * Class constructor.
55
  parent::__construct(
56
  'Responsive_Lightbox_Gallery_Widget',
57
  __( 'Gallery', 'responsive-lightbox' ),
58
+ [
59
  'description' => __( 'Displays an image gallery.', 'responsive-lightbox' ),
60
  'classname' => 'rl-gallery-widget'
61
+ ]
62
  );
63
 
64
+ $this->rlg_defaults = [
65
  'title' => __( 'Gallery', 'responsive-lightbox' ),
66
  'orderby' => 'menu_order',
67
  'order' => 'asc',
70
  'type' => 'none',
71
  'atts' => '',
72
  'ids' => ''
73
+ ];
74
 
75
+ $this->rlg_orders = [
76
  'menu_order' => __( 'Menu order', 'responsive-lightbox' ),
77
  'title' => __( 'Title', 'responsive-lightbox' ),
78
  'post_date' => __( 'Image date', 'responsive-lightbox' ),
79
  'ID' => __( 'ID', 'responsive-lightbox' ),
80
  'rand' => __( 'Random', 'responsive-lightbox' )
81
+ ];
82
 
83
+ $this->rlg_order_types = [
84
  'asc' => __( 'Ascending', 'responsive-lightbox' ),
85
  'desc' => __( 'Descending', 'responsive-lightbox' )
86
+ ];
87
 
88
  $gallery_types = apply_filters( 'rl_gallery_types', Responsive_Lightbox()->gallery_types );
89
 
90
  if ( ! empty( $gallery_types ) ) {
91
  $this->rlg_gallery_types = array_merge(
92
+ [
93
  'none' => __( 'None', 'responsive-lightbox' ),
94
  'default' => __( 'Default', 'responsive-lightbox' )
95
+ ],
96
  $gallery_types
97
  );
98
  }
99
 
100
+ $this->rlg_image_sizes = array_merge( [ 'full' ], get_intermediate_image_sizes() );
101
 
102
  sort( $this->rlg_image_sizes, SORT_STRING );
103
  }
112
  public function widget( $args, $instance ) {
113
  $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
114
 
115
+ $html = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? esc_html( $instance['title'] ) : '' ) . $args['after_title'];
116
+
117
+ $atts = [];
118
+
119
+ // escape atts
120
+ if ( $instance['atts'] !== '' ) {
121
+ $atts_exp = explode( '" ', $instance['atts'] );
122
+
123
+ if ( ! empty( $atts_exp ) ) {
124
+ end( $atts_exp );
125
+
126
+ $last = key( $atts_exp );
127
+
128
+ reset( $atts_exp );
129
+
130
+ foreach ( $atts_exp as $id => $attribute ) {
131
+ $check = $attribute . ( $last === $id ? '' : '"' );
132
+
133
+ if ( preg_match( '/^([a-z0-9_-]+)=\"(.+?)\"$/', $check, $matches ) === 1 )
134
+ $atts[] = $matches[1] . '="' . esc_attr( $matches[2] ) . '"';
135
+ }
136
+ }
137
+ }
138
+
139
+ if ( ! empty( $atts ) )
140
+ $instance['atts'] = implode( ' ', $atts );
141
+ else
142
+ $instance['atts'] = '';
143
+
144
+ $html .= do_shortcode( '[gallery link="file" columns="' . (int) $instance['columns'] . '" size="' . esc_attr( $instance['size'] ) . '" ' . ( $instance['type'] !== 'none' ? 'type="' . esc_attr( $instance['type'] ) . '"' : '' ) . ' ids="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '" orderby="' . esc_attr( $instance['orderby'] ) . '" order="' . esc_attr( $instance['order'] ) . '"' . ( $instance['atts'] !== '' ? ' ' . $instance['atts'] : '' ) . ']' );
145
  $html .= $args['after_widget'];
146
 
147
  echo apply_filters( 'rl_gallery_widget_html', $html, $instance );
153
  * @return void
154
  */
155
  public function form( $instance ) {
156
+ $attachments = ! empty( $instance['ids'] ) ? array_filter( explode( ',', $instance['ids'] ) ) : [];
157
 
158
  $html = '
159
  <div class="rl-gallery-widget-container">
160
  <p>
161
+ <label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Title', 'responsive-lightbox' ) . ':</label>
162
  <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rlg_defaults['title'] ) . '" />
163
  </p>
164
  <div id="' . $this->get_field_id( 'gallery' ) . '" class="rl-gallery-widget' . ( ! empty( $attachments ) ? ' has-image' : '' ) . '">
165
  <input type="hidden" class="rl-gallery-ids" id="' . $this->get_field_id( 'ids' ) . '" name="' . $this->get_field_name( 'ids' ) . '" value="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '">';
166
 
167
  $html .= '
168
+ <a href="#" class="rl-gallery-widget-select button button-secondary">' . esc_html__( 'Select images', 'responsive-lightbox' ) . '</a>
169
  <div class="rl-gallery-widget-content">
170
  <ul id="' . $this->get_field_id( 'gallery-images' ) . '" class="rl-gallery-images">';
171
 
175
  continue;
176
 
177
  $html .= '
178
+ <li class="rl-gallery-image" data-attachment_id="' . (int) $attachment_id . '">
179
  <div class="rl-gallery-inner">' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '</div>
180
+ <div class="rl-gallery-actions"><a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' . esc_attr__( 'Delete image', 'responsive-lightbox' ) . '"></a></div>
181
  </li>';
182
  }
183
  }
190
 
191
  if ( ! empty( $this->rlg_gallery_types ) ) {
192
  $html .= '
193
+ <label for="' . $this->get_field_id( 'type' ) . '">' . esc_html__( 'Gallery type', 'responsive-lightbox' ) . ':</label>
194
  <select id="' . $this->get_field_id( 'type' ) . '" class="widefat" name="' . $this->get_field_name( 'type' ) . '">';
195
 
196
  foreach ( $this->rlg_gallery_types as $id => $type ) {
200
 
201
  $html .= '
202
  </select>
203
+ </p>
204
+ <p>';
205
  }
206
 
207
  $html .= '
208
+ <label for="' . $this->get_field_id( 'orderby' ) . '">' . esc_html__( 'Order by', 'responsive-lightbox' ) . ':</label>
209
  <select id="' . $this->get_field_id( 'orderby' ) . '" class="widefat" name="' . $this->get_field_name( 'orderby' ) . '">';
210
 
211
  foreach ( $this->rlg_orders as $id => $orderby ) {
215
 
216
  $html .= '
217
  </select>
218
+ </p>
219
+ <p>
220
+ <label for="' . $this->get_field_id( 'order' ) . '">' . esc_html__( 'Order', 'responsive-lightbox' ) . ':</label>
221
  <select id="' . $this->get_field_id( 'order' ) . '" class="widefat" name="' . $this->get_field_name( 'order' ) . '">';
222
 
223
  foreach ( $this->rlg_order_types as $id => $order ) {
227
 
228
  $html .= '
229
  </select>
230
+ </p>
231
+ <p>
232
+ <label for="' . $this->get_field_id( 'size' ) . '">' . esc_html__( 'Image size', 'responsive-lightbox' ) . ':</label>
233
  <select id="' . $this->get_field_id( 'size' ) . '" class="widefat" name="' . $this->get_field_name( 'size' ) . '">';
234
 
235
  foreach ( $this->rlg_image_sizes as $size ) {
239
 
240
  $html .= '
241
  </select>
242
+ </p>
243
+ <p>
244
+ <label for="' . $this->get_field_id( 'columns' ) . '">' . esc_html__( 'Number of columns', 'responsive-lightbox' ) . ':</label>
245
+ <input id="' . $this->get_field_id( 'columns' ) . '" class="small-text" name="' . $this->get_field_name( 'columns' ) . '" type="number" min="0" value="' . (int) ( isset( $instance['columns'] ) ? $instance['columns'] : $this->rlg_defaults['columns'] ) . '" />
246
+ </p>
247
+ <p>
248
+ <label for="' . $this->get_field_id( 'atts' ) . '">' . esc_html__( 'Custom gallery shortcode attributes', 'responsive-lightbox' ) . ':</label>
249
  <br />
250
+ <textarea id="' . $this->get_field_id( 'atts' ) . '" class="widefat" name="' . $this->get_field_name( 'atts' ) . '">' . esc_textarea( isset( $instance['atts'] ) ? $instance['atts'] : $this->rlg_defaults['atts'] ) . '</textarea>
251
  </p>
252
  </div>';
253
 
263
  */
264
  public function update( $new_instance, $old_instance ) {
265
  // title
266
+ $old_instance['title'] = sanitize_text_field( isset( $new_instance['title'] ) ? trim( $new_instance['title'] ) : $this->rlg_defaults['title'] );
267
 
268
  // order by
269
+ $old_instance['orderby'] = isset( $new_instance['orderby'] ) && array_key_exists( $new_instance['orderby'], $this->rlg_orders ) ? $new_instance['orderby'] : $this->rlg_defaults['orderby'];
270
 
271
  // order
272
+ $old_instance['order'] = isset( $new_instance['order'] ) && array_key_exists( $new_instance['order'], $this->rlg_order_types ) ? $new_instance['order'] : $this->rlg_defaults['order'];
273
 
274
  // image size
275
+ $old_instance['size'] = isset( $new_instance['size'] ) && in_array( $new_instance['size'], $this->rlg_image_sizes, true ) ? $new_instance['size'] : $this->rlg_defaults['size'];
276
 
277
  // gallery type
278
+ $old_instance['type'] = isset( $new_instance['type'] ) && array_key_exists( $new_instance['type'], $this->rlg_gallery_types ) ? $new_instance['type'] : $this->rlg_defaults['type'];
279
 
280
  // number of columns
281
+ $old_instance['columns'] = isset( $new_instance['columns'] ) ? ( ( $columns = (int) $new_instance['columns'] ) > 0 ? $columns : $this->rlg_defaults['columns'] ) : $this->rlg_defaults['columns'];
282
 
283
  // image ids
284
+ if ( ! empty( $new_instance['ids'] ) && is_string( $new_instance['ids'] ) ) {
285
  // get unique and non empty attachment ids only
286
+ $old_instance['ids'] = implode( ',', array_unique( array_filter( array_map( 'intval', explode( ',', $new_instance['ids'] ) ) ) ) );
 
 
287
  } else
288
  $old_instance['ids'] = $this->rlg_defaults['ids'];
289
 
290
  // custom attributes
291
+ $atts = sanitize_textarea_field( preg_replace( '/\s+/', ' ', trim( str_replace( [ "\r\n", "\n\r", "\n", "\r" ], ' ', isset( $new_instance['atts'] ) ? $new_instance['atts'] : $this->rlg_defaults['atts'] ) ) ) );
292
 
293
+ $new_atts = [];
294
 
295
  if ( $atts !== '' ) {
296
  $atts_exp = explode( '" ', $atts );
305
  foreach ( $atts_exp as $id => $attribute ) {
306
  $check = $attribute . ( $last === $id ? '' : '"' );
307
 
308
+ if ( preg_match( '/^[a-z0-9_-]+=\"(.+?)\"$/', $check ) === 1 )
309
  $new_atts[] = $check;
310
  }
311
  }
327
  */
328
  class Responsive_Lightbox_Image_Widget extends WP_Widget {
329
 
330
+ private $rli_defaults = [];
331
+ private $rli_text_positions = [];
332
+ private $rli_link_to = [];
333
+ private $rli_aligns = [];
334
+ private $rli_image_sizes = [];
335
 
336
  /**
337
  * Class constructor.
342
  parent::__construct(
343
  'Responsive_Lightbox_Image_Widget',
344
  __( 'Image', 'responsive-lightbox' ),
345
+ [
346
  'description' => __( 'Displays a single image.', 'responsive-lightbox' ),
347
  'classname' => 'rl-image-widget'
348
+ ]
349
  );
350
 
351
+ $this->rli_defaults = [
352
  'title' => __( 'Image', 'responsive-lightbox' ),
353
  'image_id' => 0,
354
  'responsive' => true,
359
  'text' => '',
360
  'autobr' => false,
361
  'text_position' => 'below_image',
362
+ 'text_align' => 'none'
363
+ ];
364
 
365
+ $this->rli_text_positions = [
366
+ 'below_image' => __( 'Below the image', 'responsive-lightbox' ),
367
  'above_image' => __( 'Above the image', 'responsive-lightbox' )
368
+ ];
369
 
370
+ $this->rli_link_to = [
371
  'none' => __( 'None', 'responsive-lightbox' ),
372
  'file' => __( 'Media File', 'responsive-lightbox' ),
373
  'post' => __( 'Attachment Page', 'responsive-lightbox' ),
374
  'custom' => __( 'Custom URL', 'responsive-lightbox' )
375
+ ];
376
 
377
+ $this->rli_aligns = [
378
  'none' => __( 'None', 'responsive-lightbox' ),
379
  'left' => __( 'Left', 'responsive-lightbox' ),
380
  'center' => __( 'Center', 'responsive-lightbox' ),
381
  'right' => __( 'Right', 'responsive-lightbox' ),
382
  'justify' => __( 'Justify', 'responsive-lightbox' )
383
+ ];
384
+
385
+ $this->rli_image_sizes = array_merge( [ 'full' ], get_intermediate_image_sizes() );
386
 
 
387
  sort( $this->rli_image_sizes, SORT_STRING );
388
  }
389
 
395
  * @return void
396
  */
397
  public function widget( $args, $instance ) {
 
 
 
 
 
 
 
 
 
 
 
398
  switch ( $instance['link_to'] ) {
399
  case 'file':
400
  $file = wp_get_attachment_image_src( $instance['image_id'], 'full', false );
412
  case 'none':
413
  default:
414
  $href = '';
 
415
  }
416
 
417
+ // image align
418
  if ( $instance['image_align'] === 'left' )
419
+ $image_align = 'float: left;';
420
  elseif ( $instance['image_align'] === 'center' )
421
+ $image_align = 'margin-left: auto; margin-right: auto; display: block;';
422
  elseif ( $instance['image_align'] === 'right' )
423
+ $image_align = 'float: right;';
424
  else
425
  $image_align = '';
426
 
427
+ // text align
428
  if ( $instance['text_align'] === 'left' )
429
+ $text_align = 'text-align: left; display: block;';
430
  elseif ( $instance['text_align'] === 'center' )
431
+ $text_align = 'text-align: center; display: block;';
432
  elseif ( $instance['text_align'] === 'right' )
433
+ $text_align = 'text-align: right; display: block;';
434
  elseif ( $instance['text_align'] === 'justify' )
435
+ $text_align = 'text-align: justify; display: block;';
436
  else
437
  $text_align = '';
438
 
439
+ // get image data
440
+ $image = wp_get_attachment_image_src( $instance['image_id'], $instance['size'], false );
441
 
 
442
  $width = $instance['responsive'] === false ? $image[1] : '100%';
443
  $height = $instance['responsive'] === false ? $image[2] : 'auto';
444
  $post = get_post( $instance['image_id'] );
445
  $image_title = isset( $post->post_title ) ? $post->post_title : '';
446
  $alt = (string) get_post_meta( $instance['image_id'], '_wp_attachment_image_alt', true );
447
+ $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
448
 
449
+ // start output
450
+ $html = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? esc_html( $instance['title'] ) : '' ) . $args['after_title'];
451
+
452
+ if ( $instance['autobr'] === true )
453
+ $escaped_text = wpautop( esc_html( $instance['text'] ) );
454
+ else
455
+ $escaped_text = esc_html( $instance['text'] );
456
+
457
+ $container_html = '<div class="rl-image-widget-text" style="' . esc_attr( $text_align ) . '">' . $escaped_text . '</div>';
458
+ $image_html = ( $href !== '' ? '<a href="' . esc_url( $href ) . '" class="rl-image-widget-link">' : '' ) . '<img class="rl-image-widget-image" src="' . esc_url( $image[0] ) . '" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" title="' . esc_attr( $image_title ) . '" alt="' . esc_attr( $alt ) . '" style="' . esc_attr( $image_align ) . '" />' . ( $href !== '' ? '</a>' : '' );
459
+
460
+ if ( $instance['text_position'] === 'below_image' )
461
+ $html .= $image_html . $container_html;
462
+ else
463
+ $html .= $container_html . $image_html;
464
 
 
 
 
 
 
 
 
465
  $html .= $args['after_widget'];
466
 
467
  echo apply_filters( 'rl_image_widget_html', $html, $instance );
473
  * @return void
474
  */
475
  public function form( $instance ) {
476
+ $image_id = (int) ( isset( $instance['image_id'] ) ? $instance['image_id'] : $this->rli_defaults['image_id'] );
477
  $image = '';
478
 
479
  if ( ! empty( $image_id ) )
485
  $html = '
486
  <div class="rl-image-widget-container">
487
  <p>
488
+ <label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Title', 'responsive-lightbox' ) . '</label>
489
  <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rli_defaults['title'] ) . '" />
490
  </p>
491
  <div class="rl-image-widget' . ( ! empty( $image_id ) ? ' has-image' : '' ) . '">
492
+ <input class="rl-image-widget-image-id" type="hidden" name="' . $this->get_field_name( 'image_id' ) . '" value="' . (int) $image_id . '" />
493
+ <a href="#" class="rl-image-widget-select button button-secondary">' . esc_html__( 'Select image', 'responsive-lightbox' ) . '</a>
494
  <div class="rl-image-widget-content">';
495
+
496
+ if ( ! empty( $image ) )
497
  $html .= $image;
498
+
499
  $html .= '
500
  </div>
501
  </div>
502
  <p>
503
+ <input id="' . $this->get_field_id( 'responsive' ) . '" type="checkbox" name="' . $this->get_field_name( 'responsive' ) . '" value="responsive" ' . checked( true, ( isset( $instance['responsive'] ) ? $instance['responsive'] : $this->rli_defaults['responsive'] ), false ) . ' /> <label for="' . $this->get_field_id( 'responsive' ) . '">' . esc_html__( 'Force responsive', 'responsive-lightbox' ) . '</label>
504
  </p>';
505
 
506
  $html .= '
507
  <p>
508
+ <label for="' . $this->get_field_id( 'size' ) . '">' . esc_html__( 'Size', 'responsive-lightbox' ) . '</label>
509
  <select class="rl-image-size-select widefat" id="' . $this->get_field_id( 'size' ) . '" name="' . $this->get_field_name( 'size' ) . '">';
510
 
511
+ $size_type = ( isset( $instance['size'] ) ? $instance['size'] : $this->rli_defaults['size'] );
512
 
513
  foreach ( $this->rli_image_sizes as $size ) {
514
  $html .= '
515
+ <option value="' . esc_attr( $size ) . '" ' . selected( $size, $size_type, false ) . '>' . esc_html( $size ) . '</option>';
516
  }
517
 
518
  $html .= '
519
  </select>
520
  </p>
521
  <p>
522
+ <label for="' . $this->get_field_id( 'link_to' ) . '">' . esc_html__( 'Link to', 'responsive-lightbox' ) . '</label>
523
  <select class="rl-image-link-to widefat" id="' . $this->get_field_id( 'link_to' ) . '" name="' . $this->get_field_name( 'link_to' ) . '">';
524
 
525
+ $link_type = ( isset( $instance['link_to'] ) ? $instance['link_to'] : $this->rli_defaults['link_to'] );
526
 
527
  foreach ( $this->rli_link_to as $id => $type ) {
528
  $html .= '
529
+ <option value="' . esc_attr( $id ) . '" ' . selected( $id, $link_type, false ) . '>' . esc_html( $type ) . '</option>';
530
  }
531
 
532
  $html .= '
533
  </select>
534
  </p>
535
+ <p class="rl-image-link-url"' . ( $link_type === 'custom' ? '' : ' style="display: none;"' ) . '>
536
+ <label for="' . $this->get_field_id( 'link_custom_url' ) . '">' . esc_html__( 'URL', 'responsive-lightbox' ) . '</label>
537
  <input id="' . $this->get_field_id( 'link_custom_url' ) . '" class="widefat" name="' . $this->get_field_name( 'link_custom_url' ) . '" type="text" value="' . esc_attr( isset( $instance['link_custom_url'] ) ? $instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] ) . '" />
538
  </p>';
539
 
540
  $html .= '
541
  <p>
542
+ <label for="' . $this->get_field_id( 'image_align' ) . '">' . esc_html__( 'Image align', 'responsive-lightbox' ) . '</label>
543
  <select id="' . $this->get_field_id( 'image_align' ) . '" class="widefat" name="' . $this->get_field_name( 'image_align' ) . '">';
544
 
545
  foreach ( $this->rli_aligns as $id => $image_align ) {
546
+ if ( $id !== 'justify' )
547
  $html .= '
548
+ <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['image_align'] ) ? $instance['image_align'] : $this->rli_defaults['image_align'] ), false ) . '>' . esc_html( $image_align ) . '</option>';
549
  }
550
 
551
  $html .= '
552
  </select>
553
  </p>
554
  <p>
555
+ <label for="' . $this->get_field_id( 'text' ) . '">' . esc_html__( 'Text', 'responsive-lightbox' ) . '</label>
556
+ <textarea id="' . $this->get_field_id( 'text' ) . '" class="widefat" name="' . $this->get_field_name( 'text' ) . '" rows="4">' . esc_html( isset( $instance['text'] ) ? $instance['text'] : $this->rli_defaults['text'] ) . '</textarea>
557
  </p>
558
  <p>
559
+ <input id="' . $this->get_field_id( 'autobr' ) . '" type="checkbox" name="' . $this->get_field_name( 'autobr' ) . '" value="autobr" ' . checked( true, ( isset( $instance['autobr'] ) ? $instance['autobr'] : $this->rli_defaults['autobr'] ), false ) . ' /> <label for="' . $this->get_field_id( 'autobr' ) . '">' . esc_html__( 'Automatically add paragraphs', 'responsive-lightbox' ) . '</label>
560
  </p>';
561
 
562
+ $html .= '
563
  <p>
564
+ <label for="' . $this->get_field_id( 'text_position' ) . '">' . esc_html__( 'Text position', 'responsive-lightbox' ) . '</label>
565
  <select id="' . $this->get_field_id( 'text_position' ) . '" class="widefat" name="' . $this->get_field_name( 'text_position' ) . '">';
566
 
567
  foreach ( $this->rli_text_positions as $id => $text_position ) {
568
  $html .= '
569
+ <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['text_position'] ) ? $instance['text_position'] : $this->rli_defaults['text_position'] ), false ) . '>' . esc_html( $text_position ) . '</option>';
570
  }
571
 
572
  $html .= '
573
  </select>
574
  </p>
575
+ <label for="' . $this->get_field_id( 'text_align' ) . '">' . esc_html__( 'Text align', 'responsive-lightbox' ) . '</label>
576
  <select id="' . $this->get_field_id( 'text_align' ) . '" class="widefat" name="' . $this->get_field_name( 'text_align' ) . '">';
577
 
578
  foreach ( $this->rli_aligns as $id => $text_align ) {
579
  $html .= '
580
+ <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['text_align'] ) ? $instance['text_align'] : $this->rli_defaults['text_align'] ), false ) . '>' . esc_html( $text_align ) . '</option>';
581
  }
582
 
583
  $html .= '
596
  * @return array
597
  */
598
  public function update( $new_instance, $old_instance ) {
599
+ // whitelists
600
+ $old_instance['size'] = isset( $new_instance['size'] ) && in_array( $new_instance['size'], $this->rli_image_sizes, true ) ? $new_instance['size'] : $this->rli_defaults['size'];
601
+ $old_instance['link_to'] = isset( $new_instance['link_to'] ) && in_array( $new_instance['link_to'], array_keys( $this->rli_link_to ), true ) ? $new_instance['link_to'] : $this->rli_defaults['link_to'];
602
+ $old_instance['image_align'] = isset( $new_instance['image_align'] ) && in_array( $new_instance['image_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['image_align'] : $this->rli_defaults['image_align'];
603
+ $old_instance['text_position'] = isset( $new_instance['text_position'] ) && in_array( $new_instance['text_position'], array_keys( $this->rli_text_positions ), true ) ? $new_instance['text_position'] : $this->rli_defaults['text_position'];
604
+ $old_instance['text_align'] = isset( $new_instance['text_align'] ) && in_array( $new_instance['text_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['text_align'] : $this->rli_defaults['text_align'];
605
+
606
+ // booleands
607
+ $old_instance['responsive'] = ! empty( $new_instance['responsive'] );
608
+ $old_instance['autobr'] = ! empty( $new_instance['autobr'] );
609
+
610
+ // texts
611
  $old_instance['title'] = sanitize_text_field( isset( $new_instance['title'] ) ? $new_instance['title'] : $this->rli_defaults['title'] );
612
+ $old_instance['text'] = isset( $new_instance['text'] ) ? wp_kses_post( $new_instance['text'] ) : $this->rli_defaults['text'];
613
+
614
+ // integers
615
+ $old_instance['image_id'] = isset( $new_instance['image_id'] ) ? (int) $new_instance['image_id'] : $this->rli_defaults['image_id'];
616
+
617
+ // urls
618
+ $old_instance['link_custom_url'] = isset( $new_instance['link_custom_url'] ) ? esc_url( $new_instance['link_custom_url'] ) : $this->rli_defaults['link_custom_url'];
 
 
 
619
 
620
  return $old_instance;
621
  }
includes/functions.php CHANGED
@@ -15,15 +15,15 @@ if ( ! defined( 'ABSPATH' ) )
15
  * @param array $args Shortcode arguments
16
  * @return void
17
  */
18
- function rl_gallery( $args = array() ) {
19
- $defaults = array(
20
  'id' => 0
21
- );
22
 
23
  // merge defaults with arguments
24
  $args = array_merge( $defaults, $args );
25
 
26
- // parse ID
27
  $args['id'] = (int) $args['id'];
28
 
29
  // is it gallery?
@@ -37,7 +37,7 @@ function rl_gallery( $args = array() ) {
37
  * Get gallery shortcode images - wrapper.
38
  *
39
  * @param array $args Gallery arguments
40
- * @return array Gallery images
41
  */
42
  function rl_get_gallery_shortcode_images( $args ) {
43
  return Responsive_Lightbox()->frontend->get_gallery_shortcode_images( $args );
@@ -47,7 +47,7 @@ function rl_get_gallery_shortcode_images( $args ) {
47
  * Get gallery fields - wrapper.
48
  *
49
  * @param string $type Gallery type
50
- * @return array Gallery fields
51
  */
52
  function rl_get_gallery_fields( $type ) {
53
  return Responsive_Lightbox()->frontend->get_gallery_fields( $type );
@@ -59,7 +59,7 @@ function rl_get_gallery_fields( $type ) {
59
  * @param array $fields Gallery fields
60
  * @param array $shortcode_atts Gallery shortcode attributes
61
  * @param bool $gallery Whether is it rl_gallery shortcode
62
- * @return array All combined field attributes
63
  */
64
  function rl_get_gallery_fields_atts( $fields, $shortcode_atts, $gallery = true ) {
65
  return Responsive_Lightbox()->frontend->get_gallery_fields_atts( $fields, $shortcode_atts, $gallery );
@@ -70,7 +70,7 @@ function rl_get_gallery_fields_atts( $fields, $shortcode_atts, $gallery = true )
70
  *
71
  * @param int $gallery_id Gallery ID
72
  * @param array $args Gellery args
73
- * @return array Gallery images
74
  */
75
  function rl_get_gallery_images( $gallery_id, $args ) {
76
  if ( did_action( 'init' ) )
@@ -90,9 +90,9 @@ function rl_add_lightbox( $content ) {
90
  }
91
 
92
  /**
93
- * Get attachment id by url.
94
  *
95
- * @param string $url
96
  * @return int
97
  */
98
  function rl_get_attachment_id_by_url( $url ) {
@@ -100,10 +100,10 @@ function rl_get_attachment_id_by_url( $url ) {
100
  }
101
 
102
  /**
103
- * Get image size by url.
104
  *
105
- * @param string $url Image url
106
- * @return string
107
  */
108
  function rl_get_image_size_by_url( $url ) {
109
  return Responsive_Lightbox()->frontend->get_image_size_by_url( $url );
15
  * @param array $args Shortcode arguments
16
  * @return void
17
  */
18
+ function rl_gallery( $args = [] ) {
19
+ $defaults = [
20
  'id' => 0
21
+ ];
22
 
23
  // merge defaults with arguments
24
  $args = array_merge( $defaults, $args );
25
 
26
+ // parse id
27
  $args['id'] = (int) $args['id'];
28
 
29
  // is it gallery?
37
  * Get gallery shortcode images - wrapper.
38
  *
39
  * @param array $args Gallery arguments
40
+ * @return array
41
  */
42
  function rl_get_gallery_shortcode_images( $args ) {
43
  return Responsive_Lightbox()->frontend->get_gallery_shortcode_images( $args );
47
  * Get gallery fields - wrapper.
48
  *
49
  * @param string $type Gallery type
50
+ * @return array
51
  */
52
  function rl_get_gallery_fields( $type ) {
53
  return Responsive_Lightbox()->frontend->get_gallery_fields( $type );
59
  * @param array $fields Gallery fields
60
  * @param array $shortcode_atts Gallery shortcode attributes
61
  * @param bool $gallery Whether is it rl_gallery shortcode
62
+ * @return array
63
  */
64
  function rl_get_gallery_fields_atts( $fields, $shortcode_atts, $gallery = true ) {
65
  return Responsive_Lightbox()->frontend->get_gallery_fields_atts( $fields, $shortcode_atts, $gallery );
70
  *
71
  * @param int $gallery_id Gallery ID
72
  * @param array $args Gellery args
73
+ * @return array
74
  */
75
  function rl_get_gallery_images( $gallery_id, $args ) {
76
  if ( did_action( 'init' ) )
90
  }
91
 
92
  /**
93
+ * Get attachment id by URL.
94
  *
95
+ * @param string $url Image URL
96
  * @return int
97
  */
98
  function rl_get_attachment_id_by_url( $url ) {
100
  }
101
 
102
  /**
103
+ * Get image size by URL.
104
  *
105
+ * @param string $url Image URL
106
+ * @return array
107
  */
108
  function rl_get_image_size_by_url( $url ) {
109
  return Responsive_Lightbox()->frontend->get_image_size_by_url( $url );
includes/providers/class-flickr.php CHANGED
@@ -49,10 +49,10 @@ class Responsive_Lightbox_Remote_Library_Flickr extends Responsive_Lightbox_Remo
49
  */
50
  public function render_field() {
51
  echo '
52
- <p><label><input id="rl_flickr_active" class="rl-media-provider-expandable" type="checkbox" name="responsive_lightbox_remote_library[flickr][active]" value="1" ' . checked( $this->rl->options['remote_library']['flickr']['active'], true, false ) . ' />' . __( 'Enable Flickr.', 'responsive-lightbox' ) . '</label></p>
53
  <div class="rl-media-provider-options"' . ( $this->rl->options['remote_library']['flickr']['active'] ? '' : ' style="display: none;"' ) . '>
54
- <p><input id="rl_flickr_api_key" class="large-text" placeholder="' . __( 'API key', 'responsive-lightbox' ) . '" type="text" value="' . $this->rl->options['remote_library']['flickr']['api_key'] . '" name="responsive_lightbox_remote_library[flickr][api_key]"></p>
55
- <p class="description">' . sprintf( __( 'Provide your <a href="%s">Flickr API key</a>.', 'responsive-lightbox' ), 'https://www.flickr.com/services/apps/create/' ) . '</p>
56
  </div>';
57
  }
58
 
@@ -70,7 +70,12 @@ class Responsive_Lightbox_Remote_Library_Flickr extends Responsive_Lightbox_Remo
70
  $input['flickr']['active'] = isset( $_POST['responsive_lightbox_remote_library']['flickr']['active'] );
71
 
72
  // api key
73
- $input['flickr']['api_key'] = preg_replace( '/[^0-9a-zA-Z\-.]/', '', $_POST['responsive_lightbox_remote_library']['flickr']['api_key'] );
 
 
 
 
 
74
  }
75
 
76
  return $input;
@@ -241,22 +246,22 @@ class Responsive_Lightbox_Remote_Library_Flickr extends Responsive_Lightbox_Remo
241
  $imagedata = [
242
  'id' => 0,
243
  'link' => '',
244
- 'source' => $source,
245
- 'title' => $result['title'],
246
  'caption' => $this->get_attribution( 'Flickr', $source, $result['ownername'], 'https://www.flickr.com/photos/' . $result['owner'] ),
247
- 'description' => $result['description']['_content'],
248
- 'alt' => $result['tags'],
249
- 'url' => $large[0],
250
- 'width' => $large[1],
251
- 'height' => $large[2],
252
- 'orientation' => $large[2] > $large[1] ? 'portrait' : 'landscape',
253
- 'thumbnail_url' => $small[0],
254
- 'thumbnail_width' => $small[1],
255
- 'thumbnail_height' => $small[2],
256
- 'thumbnail_orientation' => $small[2] > $small[1] ? 'portrait' : 'landscape',
257
  'media_provider' => 'flickr',
258
- 'filename' => basename( $large[0] ),
259
- 'dimensions' => $large[1] . ' x ' . $large[2],
260
  'type' => 'image'
261
  ];
262
 
49
  */
50
  public function render_field() {
51
  echo '
52
+ <p><label><input id="rl_flickr_active" class="rl-media-provider-expandable" type="checkbox" name="responsive_lightbox_remote_library[flickr][active]" value="1" ' . checked( $this->rl->options['remote_library']['flickr']['active'], true, false ) . ' />' . esc_html__( 'Enable Flickr.', 'responsive-lightbox' ) . '</label></p>
53
  <div class="rl-media-provider-options"' . ( $this->rl->options['remote_library']['flickr']['active'] ? '' : ' style="display: none;"' ) . '>
54
+ <p><input id="rl_flickr_api_key" class="large-text" placeholder="' . esc_attr__( 'API key', 'responsive-lightbox' ) . '" type="text" value="' . esc_attr( $this->rl->options['remote_library']['flickr']['api_key'] ) . '" name="responsive_lightbox_remote_library[flickr][api_key]"></p>
55
+ <p class="description">' . sprintf( esc_html__( 'Provide your %s key.', 'responsive-lightbox' ), '<a href="https://www.flickr.com/services/apps/create/">Flickr API</a>' ) . '</p>
56
  </div>';
57
  }
58
 
70
  $input['flickr']['active'] = isset( $_POST['responsive_lightbox_remote_library']['flickr']['active'] );
71
 
72
  // api key
73
+ if ( isset( $_POST['responsive_lightbox_remote_library']['flickr']['api_key'] ) )
74
+ $api_key = preg_replace( '/[^0-9a-zA-Z\-.]/', '', $_POST['responsive_lightbox_remote_library']['flickr']['api_key'] );
75
+ else
76
+ $api_key = '';
77
+
78
+ $input['flickr']['api_key'] = $api_key;
79
  }
80
 
81
  return $input;
246
  $imagedata = [
247
  'id' => 0,
248
  'link' => '',
249
+ 'source' => esc_url_raw( $source ),
250
+ 'title' => sanitize_text_field( $result['title'] ),
251
  'caption' => $this->get_attribution( 'Flickr', $source, $result['ownername'], 'https://www.flickr.com/photos/' . $result['owner'] ),
252
+ 'description' => ! empty( $result['description']['_content'] ) ? sanitize_text_field( $result['description']['_content'] ) : '',
253
+ 'alt' => sanitize_text_field( $result['tags'] ),
254
+ 'url' => esc_url_raw( $large[0] ),
255
+ 'width' => (int) $large[1],
256
+ 'height' => (int) $large[2],
257
+ 'orientation' => (int) $large[2] > (int) $large[1] ? 'portrait' : 'landscape',
258
+ 'thumbnail_url' => esc_url_raw( $small[0] ),
259
+ 'thumbnail_width' => (int) $small[1],
260
+ 'thumbnail_height' => (int) $small[2],
261
+ 'thumbnail_orientation' => (int) $small[2] > (int) $small[1] ? 'portrait' : 'landscape',
262
  'media_provider' => 'flickr',
263
+ 'filename' => basename( sanitize_file_name( $large[0] ) ),
264
+ 'dimensions' => (int) $large[1] . ' x ' . (int) $large[2],
265
  'type' => 'image'
266
  ];
267
 
includes/providers/class-unsplash.php CHANGED
@@ -49,11 +49,13 @@ class Responsive_Lightbox_Remote_Library_Unsplash extends Responsive_Lightbox_Re
49
  */
50
  public function render_field() {
51
  echo '
52
- <p><label><input id="rl_unsplash_active" class="rl-media-provider-expandable" type="checkbox" name="responsive_lightbox_remote_library[unsplash][active]" value="1" ' . checked( $this->rl->options['remote_library']['unsplash']['active'], true, false ) . ' />' . __( 'Enable Unsplash.', 'responsive-lightbox' ) . '</label></p>
53
  <div class="rl-media-provider-options"' . ( $this->rl->options['remote_library']['unsplash']['active'] ? '' : ' style="display: none;"' ) . '>
54
- <p><input id="rl_unsplash_api_key" class="large-text" placeholder="' . __( 'Access key', 'responsive-lightbox' ) . '" type="text" value="' . $this->rl->options['remote_library']['unsplash']['api_key'] . '" name="responsive_lightbox_remote_library[unsplash][api_key]"></p>
55
- <p class="description">' . sprintf( __( 'Provide your <a href="%s">Unsplash API key</a>.', 'responsive-lightbox' ), 'https://unsplash.com/oauth/applications/new' ) . '</p>
56
  </div>';
 
 
57
  }
58
 
59
  /**
@@ -70,7 +72,12 @@ class Responsive_Lightbox_Remote_Library_Unsplash extends Responsive_Lightbox_Re
70
  $input['unsplash']['active'] = isset( $_POST['responsive_lightbox_remote_library']['unsplash']['active'] );
71
 
72
  // api key
73
- $input['unsplash']['api_key'] = preg_replace( '/[^0-9a-zA-Z\-.]/', '', $_POST['responsive_lightbox_remote_library']['unsplash']['api_key'] );
 
 
 
 
 
74
  }
75
 
76
  return $input;
@@ -195,21 +202,21 @@ class Responsive_Lightbox_Remote_Library_Unsplash extends Responsive_Lightbox_Re
195
  $imagedata = [
196
  'id' => 0,
197
  'link' => '',
198
- 'source' => $result['links']['html'],
199
- 'title' => $result['id'],
200
  'caption' => $this->get_attribution( 'Unsplash', $result['links']['html'], $result['user']['name'], $result['user']['links']['html'] ),
201
- 'description' => ! empty( $result['description'] ) ? $result['description'] : '',
202
  'alt' => '',
203
- 'url' => $result['urls']['raw'],
204
  'width' => $width,
205
  'height' => $height,
206
  'orientation' => $height > $width ? 'portrait' : 'landscape',
207
- 'thumbnail_url' => $result['urls']['small'],
208
  'thumbnail_width' => $thumbnail_width,
209
  'thumbnail_height' => $thumbnail_height,
210
  'thumbnail_orientation' => $thumbnail_height > $thumbnail_width ? 'portrait' : 'landscape',
211
  'media_provider' => 'unsplash',
212
- 'filename' => basename( $result['urls']['raw'] ),
213
  'dimensions' => $width . ' x ' . $height,
214
  'type' => 'image'
215
  ];
49
  */
50
  public function render_field() {
51
  echo '
52
+ <p><label><input id="rl_unsplash_active" class="rl-media-provider-expandable" type="checkbox" name="responsive_lightbox_remote_library[unsplash][active]" value="1" ' . checked( $this->rl->options['remote_library']['unsplash']['active'], true, false ) . ' />' . esc_html__( 'Enable Unsplash.', 'responsive-lightbox' ) . '</label></p>
53
  <div class="rl-media-provider-options"' . ( $this->rl->options['remote_library']['unsplash']['active'] ? '' : ' style="display: none;"' ) . '>
54
+ <p><input id="rl_unsplash_api_key" class="large-text" placeholder="' . esc_attr__( 'Access key', 'responsive-lightbox' ) . '" type="text" value="' . esc_attr( $this->rl->options['remote_library']['unsplash']['api_key'] ) . '" name="responsive_lightbox_remote_library[unsplash][api_key]"></p>
55
+ <p class="description">' . sprintf( esc_html__( 'Provide your %s key.', 'responsive-lightbox' ), '<a href="https://unsplash.com/oauth/applications/new">Unsplash API</a>' ) . '</p>
56
  </div>';
57
+
58
+
59
  }
60
 
61
  /**
72
  $input['unsplash']['active'] = isset( $_POST['responsive_lightbox_remote_library']['unsplash']['active'] );
73
 
74
  // api key
75
+ if ( isset( $_POST['responsive_lightbox_remote_library']['unsplash']['api_key'] ) )
76
+ $api_key = preg_replace( '/[^0-9a-zA-Z\-.]/', '', $_POST['responsive_lightbox_remote_library']['unsplash']['api_key'] );
77
+ else
78
+ $api_key = '';
79
+
80
+ $input['unsplash']['api_key'] = $api_key;
81
  }
82
 
83
  return $input;
202
  $imagedata = [
203
  'id' => 0,
204
  'link' => '',
205
+ 'source' => esc_url_raw( $result['links']['html'] ),
206
+ 'title' => sanitize_text_field( $result['id'] ),
207
  'caption' => $this->get_attribution( 'Unsplash', $result['links']['html'], $result['user']['name'], $result['user']['links']['html'] ),
208
+ 'description' => ! empty( $result['description'] ) ? sanitize_text_field( $result['description'] ) : '',
209
  'alt' => '',
210
+ 'url' => esc_url_raw( $result['urls']['raw'] ),
211
  'width' => $width,
212
  'height' => $height,
213
  'orientation' => $height > $width ? 'portrait' : 'landscape',
214
+ 'thumbnail_url' => esc_url_raw( $result['urls']['small'] ),
215
  'thumbnail_width' => $thumbnail_width,
216
  'thumbnail_height' => $thumbnail_height,
217
  'thumbnail_orientation' => $thumbnail_height > $thumbnail_width ? 'portrait' : 'landscape',
218
  'media_provider' => 'unsplash',
219
+ 'filename' => basename( sanitize_file_name( $result['urls']['raw'] ) ),
220
  'dimensions' => $width . ' x ' . $height,
221
  'type' => 'image'
222
  ];
includes/providers/class-wikimedia.php CHANGED
@@ -56,7 +56,7 @@ class Responsive_Lightbox_Remote_Library_Wikimedia extends Responsive_Lightbox_R
56
  */
57
  public function render_field() {
58
  echo '
59
- <p><label><input id="rl_wikimedia_active" type="checkbox" name="responsive_lightbox_remote_library[wikimedia][active]" value="1" ' . checked( $this->rl->options['remote_library']['wikimedia']['active'], true, false ) . ' />' . __( 'Enable Wikimedia.', 'responsive-lightbox' ) . '</label></p>';
60
  }
61
 
62
  /**
@@ -195,11 +195,11 @@ class Responsive_Lightbox_Remote_Library_Wikimedia extends Responsive_Lightbox_R
195
  * @return array|false
196
  */
197
  public function sanitize_result( $result ) {
198
- // allow only JPG, PNG and GIF images
199
  if ( preg_match( '/\.(jpe?g|gif|png)$/i', $result['url'] ) !== 1 )
200
  return false;
201
 
202
- // get part of an URL
203
  $url = explode( 'https://upload.wikimedia.org/wikipedia/commons/', $result['url'] );
204
 
205
  // set dimensions
@@ -243,21 +243,21 @@ class Responsive_Lightbox_Remote_Library_Wikimedia extends Responsive_Lightbox_R
243
  $imagedata = [
244
  'id' => 0,
245
  'link' => '',
246
- 'source' => $result['descriptionshorturl'],
247
- 'title' => $result['title'],
248
  'caption' => $this->get_attribution( 'Wikimedia', $result['descriptionshorturl'] ),
249
- 'description' => isset( $result['extmetadata']['ImageDescription']['value'] ) ? $result['extmetadata']['ImageDescription']['value'] : '',
250
- 'alt' => isset( $result['extmetadata']['Categories']['value'] ) ? str_replace( '|', ', ', $result['extmetadata']['Categories']['value'] ) : '',
251
- 'url' => $result['url'],
252
  'width' => $width,
253
  'height' => $height,
254
  'orientation' => $height > $width ? 'portrait' : 'landscape',
255
- 'thumbnail_url' => $thumbnail_url,
256
  'thumbnail_width' => $thumbnail_width,
257
  'thumbnail_height' => $thumbnail_height,
258
  'thumbnail_orientation' => $thumbnail_height > $thumbnail_width ? 'portrait' : 'landscape',
259
  'media_provider' => 'wikimedia',
260
- 'filename' => $result['name'],
261
  'dimensions' => $width . ' x ' . $height,
262
  'type' => 'image'
263
  ];
56
  */
57
  public function render_field() {
58
  echo '
59
+ <p><label><input id="rl_wikimedia_active" type="checkbox" name="responsive_lightbox_remote_library[wikimedia][active]" value="1" ' . checked( $this->rl->options['remote_library']['wikimedia']['active'], true, false ) . ' />' . esc_html__( 'Enable Wikimedia.', 'responsive-lightbox' ) . '</label></p>';
60
  }
61
 
62
  /**
195
  * @return array|false
196
  */
197
  public function sanitize_result( $result ) {
198
+ // allow only jpg, png and gif images
199
  if ( preg_match( '/\.(jpe?g|gif|png)$/i', $result['url'] ) !== 1 )
200
  return false;
201
 
202
+ // get part of an url
203
  $url = explode( 'https://upload.wikimedia.org/wikipedia/commons/', $result['url'] );
204
 
205
  // set dimensions
243
  $imagedata = [
244
  'id' => 0,
245
  'link' => '',
246
+ 'source' => esc_url_raw( $result['descriptionshorturl'] ),
247
+ 'title' => sanitize_text_field( $result['title'] ),
248
  'caption' => $this->get_attribution( 'Wikimedia', $result['descriptionshorturl'] ),
249
+ 'description' => isset( $result['extmetadata']['ImageDescription']['value'] ) ? sanitize_text_field( $result['extmetadata']['ImageDescription']['value'] ) : '',
250
+ 'alt' => isset( $result['extmetadata']['Categories']['value'] ) ? str_replace( '|', ', ', sanitize_text_field( $result['extmetadata']['Categories']['value'] ) ) : '',
251
+ 'url' => esc_url_raw( $result['url'] ),
252
  'width' => $width,
253
  'height' => $height,
254
  'orientation' => $height > $width ? 'portrait' : 'landscape',
255
+ 'thumbnail_url' => esc_url_raw( $thumbnail_url ),
256
  'thumbnail_width' => $thumbnail_width,
257
  'thumbnail_height' => $thumbnail_height,
258
  'thumbnail_orientation' => $thumbnail_height > $thumbnail_width ? 'portrait' : 'landscape',
259
  'media_provider' => 'wikimedia',
260
+ 'filename' => sanitize_file_name( $result['name'] ),
261
  'dimensions' => $width . ' x ' . $height,
262
  'type' => 'image'
263
  ];
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: dfactory
3
  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.1
7
- Stable tag: 2.4.2
8
  Requires PHP: 5.4
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
@@ -140,6 +140,12 @@ Responsive Lightbox and Gallery plugin comes with many styles and effects alread
140
 
141
  == Changelog ==
142
 
 
 
 
 
 
 
143
  = 2.4.2 =
144
  * Fix: Potential XSS vulnerabilities related to settings validation
145
  * Fix: Missing image alt attribute
@@ -502,5 +508,5 @@ Initial release
502
 
503
  == Upgrade Notice ==
504
 
505
- = 2.4.2 =
506
- * Fix: Potential XSS vulnerabilities related to settings validation
3
  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.1.1
7
+ Stable tag: 2.4.3
8
  Requires PHP: 5.4
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
140
 
141
  == Changelog ==
142
 
143
+ = 2.4.3 =
144
+ * Fix: General sanitization and validation overhaul
145
+ * Fix: Displaying legacy gallery and image widgets
146
+ * Fix: Getting colors for media folders
147
+ * Fix: Assigning terms to media folders
148
+
149
  = 2.4.2 =
150
  * Fix: Potential XSS vulnerabilities related to settings validation
151
  * Fix: Missing image alt attribute
508
 
509
  == Upgrade Notice ==
510
 
511
+ = 2.4.3 =
512
+ * Fix: General sanitization and validation overhaul
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.2
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.2
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.2',
308
  'activation_date' => ''
309
  ];
310
  public $options = [];
@@ -734,7 +734,7 @@ class Responsive_Lightbox {
734
  $current_time = time();
735
 
736
  if ( $this->options['settings']['update_version'] < $current_update ) {
737
- // check version, if update ver is lower than plugin ver, set update notice to true
738
  $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_version' => $current_update, 'update_notice' => true ] );
739
 
740
  update_option( 'responsive_lightbox_settings', $this->options['settings'] );
@@ -755,8 +755,8 @@ class Responsive_Lightbox {
755
  $activation_date = get_option( 'responsive_lightbox_activation_date' );
756
 
757
  if ( (int) $this->options['settings']['update_delay_date'] === 0 ) {
758
- if ( $activation_date + 1209600 > $current_time )
759
- $this->options['settings']['update_delay_date'] = $activation_date + 1209600;
760
  else
761
  $this->options['settings']['update_delay_date'] = $current_time;
762
 
@@ -764,7 +764,7 @@ class Responsive_Lightbox {
764
  }
765
 
766
  if ( ( ! empty( $this->options['settings']['update_delay_date'] ) ? (int) $this->options['settings']['update_delay_date'] : $current_time ) <= $current_time )
767
- $this->add_notice( sprintf( __( "Hey, you've been using <strong>Responsive Lightbox & Gallery</strong> for more than %s", 'responsive-lightbox' ), human_time_diff( $activation_date, $current_time ) ) . '<br />' . __( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation.', 'responsive-lightbox' ) . '<br /><br />' . __( 'Your help is much appreciated. Thank you very much', 'responsive-lightbox' ) . ' ~ <strong>Bartosz Arendt</strong>, ' . sprintf( __( 'founder of <a href="%s" target="_blank">dFactory</a> plugins.', 'responsive-lightbox' ), 'https://dfactory.eu/' ) . '<br /><br />' . sprintf( __( '<a href="%s" class="rl-dismissible-notice" target="_blank" rel="noopener">Ok, you deserve it</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice rl-delay-notice" rel="noopener">Nope, maybe later</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice" rel="noopener">I already did</a>', 'responsive-lightbox' ), 'https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5#new-post' ), 'notice notice-info is-dismissible rl-notice' );
768
  }
769
  }
770
 
@@ -777,14 +777,17 @@ class Responsive_Lightbox {
777
  if ( ! current_user_can( 'install_plugins' ) )
778
  return;
779
 
780
- if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'rl_dismiss_notice' ) ) {
781
- $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] );
 
 
 
782
 
783
  switch ( $notice_action ) {
784
  // delay notice
785
  case 'delay':
786
  // set delay period to 1 week from now
787
- $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_delay_date' => time() + 1209600 ] );
788
  update_option( 'responsive_lightbox_settings', $this->options['settings'] );
789
  break;
790
 
@@ -830,7 +833,7 @@ class Responsive_Lightbox {
830
  public function display_notice() {
831
  foreach( $this->notices as $notice ) {
832
  echo '
833
- <div class="' . $notice['status'] . '">
834
  ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
835
  ' . $notice['html'] . '
836
  ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
@@ -862,7 +865,7 @@ class Responsive_Lightbox {
862
  $.post( ajaxurl, {
863
  action: 'rl_dismiss_notice',
864
  notice_action: notice_action,
865
- url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
866
  nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>'
867
  } );
868
 
@@ -927,10 +930,10 @@ class Responsive_Lightbox {
927
  }
928
 
929
  // put settings link at start
930
- array_unshift( $links, sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-settings', __( 'Settings', 'responsive-lightbox' ) ) );
931
 
932
  // add add-ons link
933
- $links[] = sprintf( '<a href="%s" style="color: green;">%s</a>', admin_url( 'admin.php' ) . '?page=responsive-lightbox-addons', __( 'Add-ons', 'responsive-lightbox' ) );
934
  }
935
 
936
  return $links;
@@ -953,7 +956,7 @@ class Responsive_Lightbox {
953
  <div id="rl-deactivation-container">
954
  <div id="rl-deactivation-body">
955
  <div class="rl-deactivation-options">
956
- <p><em>' . __( "We're sorry to see you go. Could you please tell us what happened?", 'responsive-lightbox' ) . '</em></p>
957
  <ul>';
958
 
959
  foreach ( [
@@ -965,7 +968,7 @@ class Responsive_Lightbox {
965
  '6' => __( 'Other', 'responsive-lightbox' )
966
  ] as $option => $text ) {
967
  echo '
968
- <li><label><input type="radio" name="rl_deactivation_option" value="' . $option . '" ' . checked( '6', $option, false ) . ' />' . esc_html( $text ) . '</label></li>';
969
  }
970
 
971
  echo '
@@ -976,9 +979,9 @@ class Responsive_Lightbox {
976
  </div>
977
  </div>
978
  <div id="rl-deactivation-footer">
979
- <a href="" class="button rl-deactivate-plugin-cancel">' . __( 'Cancel', 'responsive-lightbox' ) . '</a>
980
- <a href="' . $this->deactivaion_url . '" class="button button-secondary rl-deactivate-plugin-simple">' . __( 'Deactivate', 'responsive-lightbox' ) . '</a>
981
- <a href="' . $this->deactivaion_url . '" class="button button-primary right rl-deactivate-plugin-data">' . __( 'Deactivate & Submit', 'responsive-lightbox' ) . '</a>
982
  <span class="spinner"></span>
983
  </div>
984
  </div>
@@ -991,13 +994,20 @@ class Responsive_Lightbox {
991
  * @return void
992
  */
993
  public function deactivate_plugin() {
 
 
 
 
 
 
 
994
  // check permissions
995
  if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'rl-deactivate-plugin' ) === false )
996
  return;
997
 
998
  if ( isset( $_POST['option_id'] ) ) {
999
  $option_id = (int) $_POST['option_id'];
1000
- $other = esc_html( $_POST['other'] );
1001
 
1002
  // avoid fake submissions
1003
  if ( $option_id == 6 && $other == '' )
@@ -1061,10 +1071,6 @@ class Responsive_Lightbox {
1061
 
1062
  $this->remote_library = new Responsive_Lightbox_Remote_Library();
1063
 
1064
- // simple html dom
1065
- if ( ! function_exists( 'file_get_html' ) )
1066
- include_once( RESPONSIVE_LIGHTBOX_PATH . 'library/simplehtmldom/simple_html_dom.php' );
1067
-
1068
  // include providers
1069
  include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' );
1070
  include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' );
@@ -1257,10 +1263,13 @@ class Responsive_Lightbox {
1257
  // get settings
1258
  $settings = Responsive_Lightbox()->settings;
1259
 
 
 
 
1260
  // settings?
1261
- if ( isset( $_GET['page'] ) && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $settings->tabs ) ) . ')$/', $_GET['page'], $tabs ) === 1 ) {
1262
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
1263
- $section_key = isset( $_GET['section'] ) ? esc_attr( $_GET['section'] ) : ( ! empty( $settings->tabs[$tab_key]['default_section'] ) ? $settings->tabs[$tab_key]['default_section'] : '' );
1264
 
1265
  $breadcrumbs[] = [
1266
  'url' => admin_url( 'admin.php?page=responsive-lightbox-settings' ),
@@ -1328,51 +1337,56 @@ class Responsive_Lightbox {
1328
  'name' => __( 'New gallery', 'responsive-lightbox' )
1329
  ];
1330
  // gallery taxonomies
1331
- } elseif ( in_array( $pagenow, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' ) {
1332
- $breadcrumbs[] = [
1333
- 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1334
- 'name' => __( 'Galleries', 'responsive-lightbox' )
1335
- ];
1336
 
1337
- // categories
1338
- if ( $_GET['taxonomy'] === 'rl_category' ) {
1339
- // new category
1340
- if ( $pagenow === 'term.php' ) {
1341
- $breadcrumbs[] = [
1342
- 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1343
- 'name' => __( 'Categories', 'responsive-lightbox' )
1344
- ];
1345
-
1346
- $breadcrumbs[] = [
1347
- 'url' => '',
1348
- 'name' => __( 'Edit category', 'responsive-lightbox' )
1349
- ];
1350
- // categories listing
1351
- } else {
1352
- $breadcrumbs[] = [
1353
- 'url' => '',
1354
- 'name' => __( 'Categories', 'responsive-lightbox' )
1355
- ];
1356
- }
1357
- // tags
1358
- } elseif ( $_GET['taxonomy'] === 'rl_tag' ) {
1359
- // new tag
1360
- if ( $pagenow === 'term.php' ) {
1361
- $breadcrumbs[] = [
1362
- 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1363
- 'name' => __( 'Tags', 'responsive-lightbox' )
1364
- ];
1365
 
1366
- $breadcrumbs[] = [
1367
- 'url' => '',
1368
- 'name' => __( 'Edit tag', 'responsive-lightbox' )
1369
- ];
1370
- // tags listing
1371
- } else {
1372
- $breadcrumbs[] = [
1373
- 'url' => '',
1374
- 'name' => __( 'Tags', 'responsive-lightbox' )
1375
- ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1376
  }
1377
  }
1378
  }
@@ -1417,9 +1431,9 @@ class Responsive_Lightbox {
1417
  [
1418
  'relation' => 'OR',
1419
  [
1420
- 'taxonomy' => 'rl_category',
1421
- 'field' => 'slug',
1422
- 'terms' => $this->options['builder']['archives_category']
1423
  ]
1424
  ]
1425
  );
@@ -1683,8 +1697,12 @@ class Responsive_Lightbox {
1683
  ]
1684
  );
1685
  // taxonomies?
1686
- } elseif ( in_array( $page, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) && $_GET['post_type'] === 'rl_gallery' )
1687
- wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
 
 
 
 
1688
  }
1689
 
1690
  /**
@@ -2159,7 +2177,7 @@ class Responsive_Lightbox {
2159
  }
2160
 
2161
  // gallery style
2162
- wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), [], Responsive_Lightbox()->defaults['version'] );
2163
  }
2164
 
2165
  /**
@@ -2173,27 +2191,32 @@ class Responsive_Lightbox {
2173
  }
2174
 
2175
  /**
2176
- * Helper: convert hex color to rgb color.
2177
  *
2178
- * @param type $color
2179
- * @return array
2180
  */
2181
  public function hex2rgb( $color ) {
2182
- if ( $color[0] == '#' )
 
 
 
 
2183
  $color = substr( $color, 1 );
2184
 
2185
- if ( strlen( $color ) == 6 )
 
 
 
 
2186
  list( $r, $g, $b ) = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
2187
- elseif ( strlen( $color ) == 3 )
 
2188
  list( $r, $g, $b ) = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
2189
  else
2190
  return false;
2191
 
2192
- $r = hexdec( $r );
2193
- $g = hexdec( $g );
2194
- $b = hexdec( $b );
2195
-
2196
- return [ $r, $g, $b ];
2197
  }
2198
  }
2199
 
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.3
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.3
47
  */
48
  class Responsive_Lightbox {
49
 
304
  'origin_left' => true,
305
  'origin_top' => true
306
  ],
307
+ 'version' => '2.4.3',
308
  'activation_date' => ''
309
  ];
310
  public $options = [];
734
  $current_time = time();
735
 
736
  if ( $this->options['settings']['update_version'] < $current_update ) {
737
+ // check version, if update version is lower than plugin version, set update notice to true
738
  $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_version' => $current_update, 'update_notice' => true ] );
739
 
740
  update_option( 'responsive_lightbox_settings', $this->options['settings'] );
755
  $activation_date = get_option( 'responsive_lightbox_activation_date' );
756
 
757
  if ( (int) $this->options['settings']['update_delay_date'] === 0 ) {
758
+ if ( $activation_date + 2 * WEEK_IN_SECONDS > $current_time )
759
+ $this->options['settings']['update_delay_date'] = $activation_date + 2 * WEEK_IN_SECONDS;
760
  else
761
  $this->options['settings']['update_delay_date'] = $current_time;
762
 
764
  }
765
 
766
  if ( ( ! empty( $this->options['settings']['update_delay_date'] ) ? (int) $this->options['settings']['update_delay_date'] : $current_time ) <= $current_time )
767
+ $this->add_notice( sprintf( __( "Hey, you've been using <strong>Responsive Lightbox & Gallery</strong> for more than %s", 'responsive-lightbox' ), human_time_diff( $activation_date, $current_time ) ) . '<br />' . esc_html__( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation.', 'responsive-lightbox' ) . '<br /><br />' . esc_html__( 'Your help is much appreciated. Thank you very much', 'responsive-lightbox' ) . ' ~ <strong>Bartosz Arendt</strong>, ' . sprintf( __( 'founder of <a href="%s" target="_blank">dFactory</a> plugins.', 'responsive-lightbox' ), 'https://dfactory.eu/' ) . '<br /><br />' . sprintf( __( '<a href="%s" class="rl-dismissible-notice" target="_blank" rel="noopener">Ok, you deserve it</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice rl-delay-notice" rel="noopener">Nope, maybe later</a><br /><a href="javascript:void(0);" class="rl-dismissible-notice" rel="noopener">I already did</a>', 'responsive-lightbox' ), 'https://wordpress.org/support/plugin/responsive-lightbox/reviews/?filter=5#new-post' ), 'notice notice-info is-dismissible rl-notice' );
768
  }
769
  }
770
 
777
  if ( ! current_user_can( 'install_plugins' ) )
778
  return;
779
 
780
+ if ( isset( $_REQUEST['nonce'] ) && ctype_alnum( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], 'rl_dismiss_notice' ) ) {
781
+ $notice_action = isset( $_REQUEST['notice_action'] ) ? sanitize_key( $_REQUEST['notice_action'] ) : '';
782
+
783
+ if ( empty( $notice_action ) || $notice_action === 'hide' )
784
+ $notice_action = 'hide';
785
 
786
  switch ( $notice_action ) {
787
  // delay notice
788
  case 'delay':
789
  // set delay period to 1 week from now
790
+ $this->options['settings'] = array_merge( $this->options['settings'], [ 'update_delay_date' => time() + 2 * WEEK_IN_SECONDS ] );
791
  update_option( 'responsive_lightbox_settings', $this->options['settings'] );
792
  break;
793
 
833
  public function display_notice() {
834
  foreach( $this->notices as $notice ) {
835
  echo '
836
+ <div class="' . esc_attr( $notice['status'] ) . '">
837
  ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
838
  ' . $notice['html'] . '
839
  ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
865
  $.post( ajaxurl, {
866
  action: 'rl_dismiss_notice',
867
  notice_action: notice_action,
868
+ url: '<?php echo esc_url_raw( admin_url( 'admin-ajax.php' ) ); ?>',
869
  nonce: '<?php echo wp_create_nonce( 'rl_dismiss_notice' ); ?>'
870
  } );
871
 
930
  }
931
 
932
  // put settings link at start
933
+ array_unshift( $links, sprintf( '<a href="%s">%s</a>', esc_url_raw( admin_url( 'admin.php' ) ) . '?page=responsive-lightbox-settings', __( 'Settings', 'responsive-lightbox' ) ) );
934
 
935
  // add add-ons link
936
+ $links[] = sprintf( '<a href="%s" style="color: green;">%s</a>', esc_url_raw( admin_url( 'admin.php' ) ) . '?page=responsive-lightbox-addons', __( 'Add-ons', 'responsive-lightbox' ) );
937
  }
938
 
939
  return $links;
956
  <div id="rl-deactivation-container">
957
  <div id="rl-deactivation-body">
958
  <div class="rl-deactivation-options">
959
+ <p><em>' . esc_html__( "We're sorry to see you go. Could you please tell us what happened?", 'responsive-lightbox' ) . '</em></p>
960
  <ul>';
961
 
962
  foreach ( [
968
  '6' => __( 'Other', 'responsive-lightbox' )
969
  ] as $option => $text ) {
970
  echo '
971
+ <li><label><input type="radio" name="rl_deactivation_option" value="' . (int) $option . '" ' . checked( '6', $option, false ) . ' />' . esc_html( $text ) . '</label></li>';
972
  }
973
 
974
  echo '
979
  </div>
980
  </div>
981
  <div id="rl-deactivation-footer">
982
+ <a href="" class="button rl-deactivate-plugin-cancel">' . esc_html__( 'Cancel', 'responsive-lightbox' ) . '</a>
983
+ <a href="' . esc_url( $this->deactivaion_url ) . '" class="button button-secondary rl-deactivate-plugin-simple">' . esc_html__( 'Deactivate', 'responsive-lightbox' ) . '</a>
984
+ <a href="' . esc_url( $this->deactivaion_url ) . '" class="button button-primary right rl-deactivate-plugin-data">' . esc_html__( 'Deactivate & Submit', 'responsive-lightbox' ) . '</a>
985
  <span class="spinner"></span>
986
  </div>
987
  </div>
994
  * @return void
995
  */
996
  public function deactivate_plugin() {
997
+ // no nonce?
998
+ if ( ! isset( $_POST['nonce'] ) )
999
+ return;
1000
+
1001
+ if ( ! ctype_alnum( $_POST['nonce'] ) )
1002
+ return;
1003
+
1004
  // check permissions
1005
  if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'rl-deactivate-plugin' ) === false )
1006
  return;
1007
 
1008
  if ( isset( $_POST['option_id'] ) ) {
1009
  $option_id = (int) $_POST['option_id'];
1010
+ $other = sanitize_text_field( $_POST['other'] );
1011
 
1012
  // avoid fake submissions
1013
  if ( $option_id == 6 && $other == '' )
1071
 
1072
  $this->remote_library = new Responsive_Lightbox_Remote_Library();
1073
 
 
 
 
 
1074
  // include providers
1075
  include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-flickr.php' );
1076
  include_once( RESPONSIVE_LIGHTBOX_PATH . 'includes/providers/class-unsplash.php' );
1263
  // get settings
1264
  $settings = Responsive_Lightbox()->settings;
1265
 
1266
+ // get page
1267
+ $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
1268
+
1269
  // settings?
1270
+ if ( $page && preg_match( '/^responsive-lightbox-(' . implode( '|', array_keys( $settings->tabs ) ) . ')$/', $page, $tabs ) === 1 ) {
1271
  $tab_key = isset( $tabs[1] ) ? $tabs[1] : 'settings';
1272
+ $section_key = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : ( ! empty( $settings->tabs[$tab_key]['default_section'] ) ? $settings->tabs[$tab_key]['default_section'] : '' );
1273
 
1274
  $breadcrumbs[] = [
1275
  'url' => admin_url( 'admin.php?page=responsive-lightbox-settings' ),
1337
  'name' => __( 'New gallery', 'responsive-lightbox' )
1338
  ];
1339
  // gallery taxonomies
1340
+ } elseif ( in_array( $pagenow, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) ) {
1341
+ $post_type = sanitize_key( $_GET['post_type'] );
1342
+ $taxonomy = sanitize_key( $_GET['taxonomy'] );
 
 
1343
 
1344
+ if ( $post_type === 'rl_gallery' ) {
1345
+ $breadcrumbs[] = [
1346
+ 'url' => admin_url( 'edit.php?post_type=rl_gallery' ),
1347
+ 'name' => __( 'Galleries', 'responsive-lightbox' )
1348
+ ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1349
 
1350
+ // categories
1351
+ if ( $taxonomy === 'rl_category' ) {
1352
+ // new category
1353
+ if ( $pagenow === 'term.php' ) {
1354
+ $breadcrumbs[] = [
1355
+ 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1356
+ 'name' => __( 'Categories', 'responsive-lightbox' )
1357
+ ];
1358
+
1359
+ $breadcrumbs[] = [
1360
+ 'url' => '',
1361
+ 'name' => __( 'Edit category', 'responsive-lightbox' )
1362
+ ];
1363
+ // categories listing
1364
+ } else {
1365
+ $breadcrumbs[] = [
1366
+ 'url' => '',
1367
+ 'name' => __( 'Categories', 'responsive-lightbox' )
1368
+ ];
1369
+ }
1370
+ // tags
1371
+ } elseif ( $taxonomy === 'rl_tag' ) {
1372
+ // new tag
1373
+ if ( $pagenow === 'term.php' ) {
1374
+ $breadcrumbs[] = [
1375
+ 'url' => admin_url( 'edit-tags.php?taxonomy=rl_category&post_type=rl_gallery' ),
1376
+ 'name' => __( 'Tags', 'responsive-lightbox' )
1377
+ ];
1378
+
1379
+ $breadcrumbs[] = [
1380
+ 'url' => '',
1381
+ 'name' => __( 'Edit tag', 'responsive-lightbox' )
1382
+ ];
1383
+ // tags listing
1384
+ } else {
1385
+ $breadcrumbs[] = [
1386
+ 'url' => '',
1387
+ 'name' => __( 'Tags', 'responsive-lightbox' )
1388
+ ];
1389
+ }
1390
  }
1391
  }
1392
  }
1431
  [
1432
  'relation' => 'OR',
1433
  [
1434
+ 'taxonomy' => 'rl_category',
1435
+ 'field' => 'slug',
1436
+ 'terms' => $this->options['builder']['archives_category']
1437
  ]
1438
  ]
1439
  );
1697
  ]
1698
  );
1699
  // taxonomies?
1700
+ } elseif ( in_array( $page, [ 'edit-tags.php', 'term.php' ], true ) && isset( $_GET['taxonomy'], $_GET['post_type'] ) ) {
1701
+ $post_type = sanitize_key( $_GET['post_type'] );
1702
+
1703
+ if ( $post_type === 'rl_gallery' )
1704
+ wp_enqueue_style( 'responsive-lightbox-admin', RESPONSIVE_LIGHTBOX_URL . '/css/admin.css', [], $this->defaults['version'] );
1705
+ }
1706
  }
1707
 
1708
  /**
2177
  }
2178
 
2179
  // gallery style
2180
+ wp_register_style( 'responsive-lightbox-gallery', plugins_url( 'css/gallery.css', __FILE__ ), [], Responsive_Lightbox()->defaults['version'] );
2181
  }
2182
 
2183
  /**
2191
  }
2192
 
2193
  /**
2194
+ * Convert HEX to RGB color.
2195
  *
2196
+ * @param string $color
2197
+ * @return bool|array
2198
  */
2199
  public function hex2rgb( $color ) {
2200
+ if ( ! is_string( $color ) )
2201
+ return false;
2202
+
2203
+ // with hash?
2204
+ if ( $color[0] === '#' )
2205
  $color = substr( $color, 1 );
2206
 
2207
+ if ( sanitize_hex_color_no_hash( $color ) !== $color )
2208
+ return false;
2209
+
2210
+ // 6 hex digits?
2211
+ if ( strlen( $color ) === 6 )
2212
  list( $r, $g, $b ) = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
2213
+ // 3 hex digits?
2214
+ elseif ( strlen( $color ) === 3 )
2215
  list( $r, $g, $b ) = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
2216
  else
2217
  return false;
2218
 
2219
+ return [ 'r' => hexdec( $r ), 'g' => hexdec( $g ), 'b' => hexdec( $b ) ];
 
 
 
 
2220
  }
2221
  }
2222