PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.5.4
Responsive Lightbox & Gallery v2.5.4
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / includes / class-remote-library.php
responsive-lightbox / includes Last commit date
providers 1 year ago class-fast-image.php 2 years ago class-folders.php 7 months ago class-frontend.php 7 months ago class-galleries.php 7 months ago class-multilang.php 2 years ago class-remote-library-api.php 1 year ago class-remote-library.php 1 year ago class-settings.php 1 year ago class-tour.php 2 years ago class-welcome.php 2 years ago class-widgets.php 2 years ago functions.php 3 years ago
class-remote-library.php
672 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Responsive Lightbox Remote Library class.
8 *
9 * @class Responsive_Lightbox_Remote_Library
10 */
11 class Responsive_Lightbox_Remote_Library {
12
13 public $providers = [];
14 private $image_formats = [
15 'bmp' => 'image/bmp',
16 'gif' => 'image/gif',
17 'jpe' => 'image/jpeg',
18 'jpeg' => 'image/jpeg',
19 'jpg' => 'image/jpeg',
20 'png' => 'image/png',
21 'tif' => 'image/tiff',
22 'tiff' => 'image/tiff',
23 'webp' => 'image/webp'
24 ];
25
26 /**
27 * Class constructor.
28 *
29 * @return void
30 */
31 public function __construct() {
32 // is remote library active?
33 if ( ! Responsive_Lightbox()->options['remote_library']['active'] )
34 return;
35
36 // actions
37 add_action( 'wp_ajax_rl_remote_library_query', [ $this, 'ajax_query_media' ] );
38 add_action( 'wp_ajax_rl_upload_image', [ $this, 'ajax_upload_image' ] );
39 add_action( 'admin_enqueue_scripts', [ $this, 'remote_library_scripts' ] );
40
41 // add filter to send new data to editor
42 add_filter( 'image_send_to_editor', [ $this, 'send_image_to_editor' ], 21, 8 );
43 }
44
45 /**
46 * Hidden field with response data for gallery preview.
47 *
48 * @param array $args Field arguments
49 * @return string
50 */
51 public function remote_library_response_data( $args ) {
52 // get main instance
53 $rl = Responsive_Lightbox();
54
55 // get active providers
56 $providers = $this->get_active_providers();
57
58 $html = '';
59
60 // any providers?
61 if ( ! empty( $providers ) ) {
62 foreach ( $providers as $provider ) {
63 // get provider
64 $provider = $rl->providers[$provider];
65
66 // add response data arguments if needed
67 if ( ! empty( $provider['response_args'] ) ) {
68 $response = $provider['instance']->get_response_data();
69
70 foreach ( $provider['response_args'] as $arg ) {
71 if ( array_key_exists( $arg, $response ) ) {
72 $html .= '<span id="' . esc_attr( 'rl_' . $args['tab_id'] . '_' . $args['menu_item'] . '_' . $args['field'] . '_' . $provider['slug'] . '_' . $arg ) . '" class="rl-response-data" data-value="' . esc_attr( base64_encode( wp_json_encode( $response[$arg] ) ) ) . '" data-name="' . esc_attr( $arg ) . '" data-provider="' . esc_attr( $provider['slug'] ) . '"></span>';
73 }
74 }
75 }
76 }
77 }
78
79 return $html;
80 }
81
82 /**
83 * Send updated image data to editor.
84 *
85 * @param string $html The image HTML markup to send
86 * @param int $id The attachment ID
87 * @param string $caption The image caption
88 * @param string $title The image title
89 * @param string $align The image alignment
90 * @param string $url The image source URL
91 * @param string|array $size Size of image
92 * @param string $alt The image alternative text.
93 * @return string
94 */
95 function send_image_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
96 if ( $id === Responsive_Lightbox()->galleries->maybe_generate_thumbnail() && isset( $_POST['attachment'] ) && is_array( $_POST['attachment'] ) ) {
97 $attachment = wp_unslash( $_POST['attachment'] );
98
99 if ( isset( $attachment['remote_library_image'], $attachment['width'], $attachment['height'] ) ) {
100 $html = preg_replace( '/src=(\'|")(.*?)(\'|")/', 'src="' . ( ! empty( $attachment['rl_url'] ) ? esc_url( $attachment['rl_url'] ) : $url ) . '"', $html );
101 $html = preg_replace( '/width=(\'|")(.*?)(\'|")/', 'width="' . (int) $attachment['width'] . '"', $html );
102 $html = preg_replace( '/height=(\'|")(.*?)(\'|")/', 'height="' . (int) $attachment['height'] . '"', $html );
103 $html = preg_replace( '/(\s)?id="attachment_' . (int) $id . '"/', '', $html );
104 $html = preg_replace( '/(\s)?wp-image-' . (int) $id . '/', '', $html );
105 }
106 }
107
108 return $html;
109 }
110
111 /**
112 * Get all available providers.
113 *
114 * @return array
115 */
116 public function get_providers() {
117 return (array) apply_filters( 'rl_get_providers', Responsive_Lightbox()->providers );
118 }
119
120 /**
121 * Get all active providers.
122 *
123 * @return array
124 */
125 public function get_active_providers() {
126 $providers = $this->get_providers();
127 $active_providers = [];
128
129 foreach ( $providers as $provider => $data ) {
130 if ( Responsive_Lightbox()->options['remote_library'][$provider]['active'] )
131 $active_providers[] = $provider;
132 }
133
134 return (array) apply_filters( 'rl_get_active_providers', $active_providers );
135 }
136
137 /**
138 * Check whether provider is active.
139 *
140 * @param string $provider Media provider
141 * @return bool
142 */
143 public function is_active_provider( $provider ) {
144 $providers = $this->get_providers();
145 $rl = Responsive_Lightbox();
146
147 return (bool) apply_filters( 'rl_is_active_provider', array_key_exists( $provider, $rl->options['remote_library'] ) && $rl->options['remote_library'][$provider]['active'], $provider );
148 }
149
150 /**
151 * Scripts and styles for media frame.
152 *
153 * @global string $wp_version
154 * @global string $pagenow
155 *
156 * @return void
157 */
158 public function remote_library_scripts() {
159 global $wp_version;
160 global $pagenow;
161
162 // display only for post edit pages
163 if ( ! ( ( $pagenow === 'post.php' || $pagenow === 'post-new.php' ) || ( version_compare( $wp_version, '5.8', '>=' ) && ( $pagenow === 'widgets.php' || $pagenow === 'customize.php' ) ) ) )
164 return;
165
166 // get main instance
167 $rl = Responsive_Lightbox();
168
169 wp_enqueue_script( 'responsive-lightbox-remote-library-media', RESPONSIVE_LIGHTBOX_URL . '/js/admin-media.js', [ 'jquery', 'media-models', 'underscore' ], $rl->defaults['version'] );
170
171 // prepare script data
172 $script_data = [
173 'thumbnailID' => $rl->galleries->maybe_generate_thumbnail(),
174 'postID' => get_the_ID(),
175 'providers' => $this->get_providers(),
176 'providersActive' => $this->get_active_providers(),
177 'allProviders' => esc_html__( 'All providers', 'responsive-lightbox' ),
178 'uploadAndInsert' => esc_html__( 'Upload and Insert', 'responsive-lightbox' ),
179 'uploadAndSelect' => esc_html__( 'Upload and Select', 'responsive-lightbox' ),
180 'filterByremoteLibrary' => esc_html__( 'Filter by remote library', 'responsive-lightbox' ),
181 'getUploadNonce' => wp_create_nonce( 'rl-remote-library-upload-image' )
182 ];
183
184 wp_add_inline_script( 'responsive-lightbox-remote-library-media', 'var rlRemoteLibraryMedia = ' . wp_json_encode( $script_data ) . ";\n", 'before' );
185
186 // enqueue gallery
187 $rl->galleries->enqueue_gallery_scripts_styles();
188 }
189
190 /**
191 * AJAX media query action.
192 *
193 * @return void
194 */
195 public function ajax_query_media() {
196 $data = stripslashes_deep( $_POST );
197 $results = [
198 'last' => false,
199 'images' => [],
200 'data' => []
201 ];
202
203 if ( isset( $data['media_provider'], $data['media_search'], $data['media_page'] ) ) {
204 $data['media_provider'] = sanitize_key( $data['media_provider'] );
205
206 if ( $data['media_provider'] === 'all' || $this->is_active_provider( $data['media_provider'] ) ) {
207 $data['preview_page'] = (int) $data['media_page'];
208 $data['preview_per_page'] = 20;
209
210 // get images
211 $results['images'] = $this->get_remote_library_images( $data );
212
213 // get main instance
214 $rl = Responsive_Lightbox();
215
216 // single provider?
217 if ( $data['media_provider'] !== 'all' ) {
218 // get provider
219 $provider = $rl->providers[$data['media_provider']];
220
221 // add response data arguments if needed
222 if ( ! empty( $provider['response_args'] ) ) {
223 $response = $provider['instance']->get_response_data();
224
225 foreach ( $provider['response_args'] as $arg ) {
226 if ( array_key_exists( $arg, $response ) )
227 $results['data'][$provider['slug']][$arg] = base64_encode( wp_json_encode( $response[$arg] ) );
228 }
229 }
230 } else {
231 // get active providers
232 $providers = $this->get_active_providers();
233
234 if ( ! empty( $providers ) ) {
235 foreach ( $providers as $provider ) {
236 // get provider
237 $provider = $rl->providers[$provider];
238
239 // add response data arguments if needed
240 if ( ! empty( $provider['response_args'] ) ) {
241 $response = $provider['instance']->get_response_data();
242
243 foreach ( $provider['response_args'] as $arg ) {
244 if ( array_key_exists( $arg, $response ) )
245 $results['data'][$provider['slug']][$arg] = base64_encode( wp_json_encode( $response[$arg] ) );
246 }
247 }
248 }
249 }
250 }
251
252 if ( ! empty( $results['images'] ) ) {
253 // create WP compatible attachments
254 $results['images'] = $this->create_wp_remote_attachments( $results['images'], $data );
255
256 // handle last page if needed
257 $results['last'] = apply_filters( 'rl_remote_library_query_last_page', false, $results, $data );
258 } else
259 $results['last'] = true;
260 }
261 }
262
263 // send data
264 wp_send_json( $results );
265 }
266
267 /**
268 * AJAX upload image action.
269 *
270 * @return void
271 */
272 public function ajax_upload_image() {
273 // clear post data
274 $data = stripslashes_deep( $_POST );
275
276 // default result
277 $result = [
278 'id' => 0,
279 'full' => [ '', 0, 0, false ],
280 'error' => false,
281 'message' => ''
282 ];
283
284 // verified upload?
285 if ( current_user_can( 'upload_files' ) && isset( $data['rlnonce'], $data['image'], $data['post_id'] ) && wp_verify_nonce( $data['rlnonce'], 'rl-remote-library-upload-image' ) ) {
286 // include required files if needed
287 if ( ! function_exists( 'media_handle_upload' ) )
288 require_once( path_join( ABSPATH, 'wp-admin/includes/media.php' ) );
289
290 if ( ! function_exists( 'wp_handle_upload' ) )
291 require_once( path_join( ABSPATH, 'wp-admin/includes/file.php' ) );
292
293 // get media provider
294 $media_provider = ! empty( $data['image']['media_provider'] ) ? sanitize_key( $data['image']['media_provider'] ) : '';
295
296 // get active providers
297 $providers = $this->get_active_providers();
298
299 if ( in_array( $media_provider, $providers, true ) ) {
300 // get image formats
301 $image_formats = $this->get_allowed_image_formats( $media_provider );
302
303 if ( ! empty( $data['image']['url'] ) && ! empty( $data['image']['mime'] ) && ! empty( $data['image']['subtype'] ) && array_key_exists( $data['image']['subtype'], $image_formats ) ) {
304 // get image url
305 $image_url = esc_url_raw( $data['image']['url'] );
306
307 // get allowed hosts
308 $hosts = $this->get_allowed_hosts( $media_provider );
309
310 if ( ! empty( $hosts ) ) {
311 $valid_host = false;
312
313 // get image host
314 $image_host = parse_url( $image_url, PHP_URL_HOST );
315
316 // check allowed hosts
317 foreach ( $hosts as $host ) {
318 // invalid host?
319 if ( strpos( $image_host, $host ) !== false ) {
320 $valid_host = true;
321
322 // no need to check rest of the hosts
323 break;
324 }
325 }
326 } else
327 $valid_host = true;
328
329 if ( $valid_host ) {
330 // get image as binary data
331 $response = wp_safe_remote_get( $image_url );
332
333 // no errors?
334 if ( ! is_wp_error( $response ) ) {
335 // get sanitized file name
336 $file_name = sanitize_file_name( pathinfo( $data['image']['name'], PATHINFO_BASENAME ) );
337
338 // get file extension
339 $file_ext = pathinfo( $file_name, PATHINFO_EXTENSION );
340
341 // no extension?
342 if ( $file_ext === '' || ! array_key_exists( $file_ext, $image_formats ) ) {
343 $file_name .= '.jpg';
344 $file_ext = 'jpg';
345 }
346
347 // simple mime checking
348 $check = wp_check_filetype( $file_name );
349
350 if ( $check['type'] === $data['image']['mime'] && $check['ext'] !== false && array_key_exists( $file_ext, $image_formats ) ) {
351 // get image binary data
352 $image_bits = wp_remote_retrieve_body( $response );
353
354 // upload image
355 $uploaded_image = wp_upload_bits( $file_name, null, $image_bits, current_time( 'Y/m' ) );
356
357 if ( isset( $uploaded_image['error'] ) && $uploaded_image['error'] ) {
358 $result['error'] = true;
359 $result['message'] = $uploaded_image['error'];
360 } else {
361 // get file name
362 $file_name = pathinfo( $uploaded_image['file'], PATHINFO_BASENAME );
363
364 // simulate upload
365 $_FILES['rl-remote-image'] = [
366 'error' => 0,
367 'name' => $file_name,
368 'tmp_name' => $uploaded_image['file'],
369 'size' => filesize( $uploaded_image['file'] )
370 ];
371
372 // get post id
373 $post_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
374
375 // more reliable mime type checking
376 $check = wp_check_filetype_and_ext( $uploaded_image['file'], $file_name );
377
378 // correct mime type and extension?
379 if ( strpos( $data['image']['mime'], 'image/' ) === 0 && $check['type'] === $data['image']['mime'] && $check['ext'] !== false && wp_get_image_mime( $uploaded_image['file'] ) === $check['type'] ) {
380 // upload image, wp handle sanitization and validation here
381 $attachment_id = media_handle_upload(
382 'rl-remote-image',
383 $post_id,
384 [
385 'post_title' => empty( $data['image']['title'] ) ? $file_name : $data['image']['title'],
386 'post_content' => empty( $data['image']['description'] ) ? '' : $data['image']['description'],
387 'post_excerpt' => empty( $data['image']['caption'] ) ? '' : $data['image']['caption']
388 ],
389 [
390 'action' => 'rl_remote_library_handle_upload',
391 'test_form' => false
392 ]
393 );
394
395 // upload success?
396 if ( ! is_wp_error( $attachment_id ) ) {
397 add_post_meta( $attachment_id, '_wp_attachment_image_alt', empty( $data['image']['alt'] ) ? '' : $data['image']['alt'] );
398
399 $result['id'] = $attachment_id;
400 $result['full'] = wp_get_attachment_image_src( $attachment_id, 'full' );
401 } else {
402 $result['error'] = true;
403 $result['message'] = $attachment_id->get_error_message();
404 }
405 // file still exists?
406 } elseif ( file_exists( $uploaded_image['file'] ) ) {
407 $result['error'] = true;
408 $result['message'] = __( 'Invalid MIME type', 'responsive-lightbox' );
409
410 // delete file
411 wp_delete_file( $uploaded_image['file'] );
412 }
413 }
414 } else {
415 $result['error'] = true;
416 $result['message'] = __( 'Invalid image type', 'responsive-lightbox' );
417 }
418 } else {
419 $result['error'] = true;
420 $result['message'] = $response->get_error_message();
421 }
422 } else {
423 $result['error'] = true;
424 $result['message'] = __( 'Invalid host', 'responsive-lightbox' );
425 }
426 } else {
427 $result['error'] = true;
428 $result['message'] = __( 'Missing or invalid image data', 'responsive-lightbox' );
429 }
430 } else {
431 $result['error'] = true;
432 $result['message'] = __( 'Invalid media provider', 'responsive-lightbox' );
433 }
434 } else {
435 $result['error'] = true;
436 $result['message'] = __( 'Access denied', 'responsive-lightbox' );
437 }
438
439 // send data
440 wp_send_json( $result );
441 }
442
443 /**
444 * Create WP compatible attachments for JavaScript.
445 *
446 * @param array $results Requested images
447 * @param array $args Additional arguments
448 * @return array
449 */
450 public function create_wp_remote_attachments( $results, $args ) {
451 // get current user
452 $user = wp_get_current_user();
453
454 // copy results
455 $copy = $results;
456
457 // get current time
458 $time = current_time( 'timestamp' );
459
460 // get date format
461 $date_format = get_option( 'date_format' );
462
463 // format date
464 $date = date_i18n( __( 'F j Y' ), $time );
465
466 // $result is already sanitized by specific provider sanitize_result function
467 foreach ( $results as $no => $result ) {
468 // make sure those attributes are strings
469 $copy[$no]['caption'] = (string) $result['caption'];
470 $copy[$no]['description'] = (string) $result['description'];
471 $copy[$no]['title'] = (string) $result['title'];
472 $copy[$no]['filename'] = $copy[$no]['name'] = (string) $result['filename'];
473
474 // rest of attributes
475 $copy[$no]['id'] = 'rl-attachment-' . ( ( $args['preview_page'] - 1 ) * $args['preview_per_page'] + $no ) . '-' . $args['media_provider'];
476 $copy[$no]['remote_library_image'] = true;
477 $copy[$no]['author'] = $user->ID;
478 $copy[$no]['authorName'] = esc_html( $user->user_login );
479 $copy[$no]['can'] = [
480 'save' => true,
481 'remove' => false
482 ];
483 $copy[$no]['compat'] = '';
484 $copy[$no]['date'] = $time;
485 $copy[$no]['dateFormatted'] = $date;
486 $copy[$no]['delete'] = '';
487 $copy[$no]['edit'] = '';
488 $copy[$no]['update'] = '';
489 $copy[$no]['filesizeHumanReadable'] = '';
490 $copy[$no]['filesizeInBytes'] = 0;
491 $copy[$no]['icon'] = '';
492 $copy[$no]['link'] = $result['url'];
493 $copy[$no]['menuOrder'] = 0;
494 $copy[$no]['meta'] = false;
495
496 // check extension
497 $file_ext = pathinfo( $result['url'], PATHINFO_EXTENSION );
498
499 // get image formats
500 $image_formats = $this->get_allowed_image_formats( $args['media_provider'] );
501
502 if ( array_key_exists( $file_ext, $image_formats ) ) {
503 $copy[$no]['mime'] = $image_formats[$file_ext];
504 $copy[$no]['subtype'] = $file_ext;
505 } else {
506 $copy[$no]['mime'] = 'image/jpeg';
507 $copy[$no]['subtype'] = 'jpg';
508 }
509
510 $copy[$no]['modified'] = $time;
511 $copy[$no]['nonces'] = [
512 'delete' => '',
513 'edit' => '',
514 'update' => ''
515 ];
516 $copy[$no]['orientation'] = $result['orientation'];
517 $copy[$no]['status'] = 'inherit';
518 $copy[$no]['type'] = 'image';
519 $copy[$no]['uploadedTo'] = 0;
520 $copy[$no]['uploadedToLink'] = '';
521 $copy[$no]['uploadedToTitle'] = '';
522 $copy[$no]['sizes'] = [
523 'medium' => [
524 'height' => $result['thumbnail_height'],
525 'width' => $result['thumbnail_width'],
526 'orientation' => $result['thumbnail_orientation'],
527 'url' => $result['thumbnail_url']
528 ],
529 'full' => [
530 'height' => $result['height'],
531 'width' => $result['width'],
532 'orientation' => $result['orientation'],
533 'url' => $result['url']
534 ]
535 ];
536 }
537
538 return (array) apply_filters( 'rl_remote_library_wp_attachments', $copy, $args );
539 }
540
541 /**
542 * Remote library media query.
543 *
544 * @param array $args
545 * @return array
546 */
547 public function get_remote_library_images( $args ) {
548 $args = stripslashes_deep( $args );
549
550 // search phrase
551 if ( isset( $args['media_search'] ) )
552 $args['media_search'] = strtolower( trim( $args['media_search'] ) );
553 else
554 $args['media_search'] = '';
555
556 // media provider
557 if ( isset( $args['media_provider'] ) )
558 $args['media_provider'] = trim( $args['media_provider'] );
559 else
560 $args['media_provider'] = 'all';
561
562 // page number
563 if ( isset( $args['preview_page'] ) )
564 $args['preview_page'] = (int) $args['preview_page'];
565 else
566 $args['preview_page'] = 1;
567
568 // number of images per page
569 if ( isset( $args['preview_per_page'] ) )
570 $args['preview_per_page'] = (int) $args['preview_per_page'];
571 else
572 $args['preview_per_page'] = 20;
573
574 // get active providers
575 $providers = $this->get_active_providers();
576
577 // prepare valid providers
578 $valid_providers = [];
579
580 if ( $args['media_provider'] === 'all' )
581 $valid_providers = $providers;
582 elseif ( in_array( $args['media_provider'], $providers, true ) )
583 $valid_providers[] = $args['media_provider'];
584
585 $results = [];
586
587 // any valid providers?
588 if ( ! empty( $valid_providers ) ) {
589 // get main instance
590 $rl = Responsive_Lightbox();
591
592 foreach ( $valid_providers as $provider_name ) {
593 if ( ! empty( $args['response_data'][$provider_name] ) ) {
594 // get provider
595 $provider = $rl->providers[$provider_name];
596
597 if ( ! empty( $provider['response_args'] ) ) {
598 foreach ( $provider['response_args'] as $arg ) {
599 if ( array_key_exists( $arg, $args['response_data'][$provider_name] ) ) {
600 $base64 = base64_decode( $args['response_data'][$provider_name][$arg] );
601
602 if ( ! empty( $base64 ) )
603 $args['response_data'][$provider_name][$arg] = json_decode( $base64, true );
604 }
605 }
606 }
607 }
608
609 // get results
610 $results = apply_filters( 'rl_remote_library_query', $results, $args['media_search'], $provider_name, $args );
611
612 // number of results
613 $nor = count( $results );
614
615 // more than requested images?
616 if ( $nor > $args['preview_per_page'] ) {
617 // get part of images
618 $results = array_slice( $results, 0, $args['preview_per_page'], true );
619
620 break;
621 // same amount of images?
622 } elseif ( $nor === $args['preview_per_page'] )
623 break;
624 }
625 }
626
627 return $results;
628 }
629
630 /**
631 * Get allowed hosts.
632 *
633 * @param string $provider
634 * @return array
635 */
636 public function get_allowed_hosts( $provider ) {
637 // get active providers
638 $providers = $this->get_active_providers();
639
640 if ( in_array( $provider, $providers, true ) ) {
641 // get available provider host
642 $hosts = Responsive_Lightbox()->providers[$provider]['instance']->get_allowed_hosts();
643 } else
644 $hosts = [];
645
646 return $hosts;
647 }
648
649 /**
650 * Get allowed image formats.
651 *
652 * @param string $provider
653 * @return array
654 */
655 public function get_allowed_image_formats( $provider = 'all' ) {
656 if ( $provider === 'all' ) {
657 $image_formats = $this->image_formats;
658 } else {
659 // get active providers
660 $providers = $this->get_active_providers();
661
662 if ( in_array( $provider, $providers, true ) ) {
663 // get available provider image formats
664 $image_formats = Responsive_Lightbox()->providers[$provider]['instance']->get_allowed_formats();
665 } else
666 $image_formats = [];
667 }
668
669 return $image_formats;
670 }
671 }
672