class-settings-addons.php
4 months ago
class-settings-base.php
5 months ago
class-settings-builder.php
5 months ago
class-settings-capabilities.php
5 months ago
class-settings-folders.php
4 months ago
class-settings-galleries.php
5 months ago
class-settings-general.php
5 months ago
class-settings-licenses.php
4 months ago
class-settings-lightboxes.php
4 months ago
class-settings-remote-library.php
5 months ago
class-settings-remote-library.php
145 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsive Lightbox Remote Library Settings |
| 4 | * |
| 5 | * @package Responsive_Lightbox |
| 6 | */ |
| 7 | |
| 8 | // exit if accessed directly |
| 9 | if ( ! defined( 'ABSPATH' ) ) |
| 10 | exit; |
| 11 | |
| 12 | /** |
| 13 | * Responsive Lightbox Remote Library Settings class. |
| 14 | * |
| 15 | * @class Responsive_Lightbox_Settings_Remote_Library |
| 16 | */ |
| 17 | class Responsive_Lightbox_Settings_Remote_Library extends Responsive_Lightbox_Settings_Base { |
| 18 | |
| 19 | /** |
| 20 | * Tab key identifier. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | const TAB_KEY = 'remote_library'; |
| 25 | |
| 26 | /** |
| 27 | * Get priority for settings data filter. |
| 28 | * |
| 29 | * @return int |
| 30 | */ |
| 31 | protected function get_settings_data_priority() { |
| 32 | return 100; // load late to catch provider fields |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Validate settings for Remote Library tab. |
| 37 | * |
| 38 | * Handles field sanitization and applies filter for provider extensions. |
| 39 | * |
| 40 | * @param array $input Input data from form submission. |
| 41 | * @return array Validated data. |
| 42 | */ |
| 43 | public function validate( $input ) { |
| 44 | // check if this is a reset operation |
| 45 | if ( $this->is_reset_request() ) { |
| 46 | $input = $this->merge_with_defaults( [] ); |
| 47 | add_settings_error( 'reset_rl_remote_library', 'settings_restored', esc_html__( 'Settings restored to defaults.', 'responsive-lightbox' ), 'updated' ); |
| 48 | return $input; |
| 49 | } |
| 50 | |
| 51 | // sanitize all fields |
| 52 | $input = $this->sanitize_fields( $input, 'remote_library' ); |
| 53 | |
| 54 | // apply filter for provider extensions |
| 55 | $input = apply_filters( 'rl_remote_library_settings', $input ); |
| 56 | |
| 57 | return $input; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Provide settings data for this tab. |
| 62 | * |
| 63 | * @param array $data Settings data. |
| 64 | * @return array |
| 65 | */ |
| 66 | public function settings_data( $data ) { |
| 67 | // get main instance |
| 68 | $rl = Responsive_Lightbox(); |
| 69 | |
| 70 | // base fields for remote library settings section |
| 71 | $base_fields = [ |
| 72 | 'active' => [ |
| 73 | 'title' => __( 'Remote Library', 'responsive-lightbox' ), |
| 74 | 'type' => 'boolean', |
| 75 | 'label' => __( 'Enable remote libraries.', 'responsive-lightbox' ), |
| 76 | 'description' => __( 'Check this to enable remote access to the following image libraries.', 'responsive-lightbox' ) |
| 77 | ], |
| 78 | 'max_image_size' => [ |
| 79 | 'title' => __( 'Max Image Size', 'responsive-lightbox' ), |
| 80 | 'type' => 'number', |
| 81 | 'min' => 1, |
| 82 | 'description' => __( 'Maximum allowed image size for remote downloads.', 'responsive-lightbox' ), |
| 83 | 'append' => __( 'MB', 'responsive-lightbox' ) |
| 84 | ], |
| 85 | 'caching' => [ |
| 86 | 'title' => __( 'Caching', 'responsive-lightbox' ), |
| 87 | 'type' => 'boolean', |
| 88 | 'label' => __( 'Enable remote library requests caching.', 'responsive-lightbox' ) |
| 89 | ], |
| 90 | 'cache_expiry' => [ |
| 91 | 'title' => '', |
| 92 | 'type' => 'number', |
| 93 | 'min' => 1, |
| 94 | 'description' => __( 'Enter the cache expiry time.', 'responsive-lightbox' ), |
| 95 | 'append' => __( 'hour(s)', 'responsive-lightbox' ), |
| 96 | 'logic' => [ 'field' => 'caching', 'operator' => 'is', 'value' => 'true' ], |
| 97 | 'animation' => 'slide' |
| 98 | ] |
| 99 | ]; |
| 100 | |
| 101 | // get provider fields from new filter (preferred method for extensions) |
| 102 | $provider_fields = apply_filters( 'rl_remote_library_provider_fields', [] ); |
| 103 | |
| 104 | // fallback: get provider fields from legacy settings (for backward compatibility) |
| 105 | if ( empty( $provider_fields ) && $rl->settings->has_setting_tab( 'remote_library' ) ) { |
| 106 | $remote_fields = $rl->settings->get_setting_fields( 'remote_library' ); |
| 107 | foreach ( $remote_fields as $field_id => $field ) { |
| 108 | // skip base fields, only get provider fields (those with section = providers) |
| 109 | if ( isset( $field['section'] ) && $field['section'] === 'responsive_lightbox_remote_library_providers' ) { |
| 110 | $provider_fields[$field_id] = $field; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | $data[self::TAB_KEY] = [ |
| 116 | 'option_name' => 'responsive_lightbox_remote_library', |
| 117 | 'option_group' => 'responsive_lightbox_remote_library', |
| 118 | 'validate' => [ $this, 'validate' ], |
| 119 | 'sections' => [ |
| 120 | 'responsive_lightbox_remote_library' => [ |
| 121 | 'title' => __( 'Remote Library Settings', 'responsive-lightbox' ), |
| 122 | 'description' => '', |
| 123 | 'fields' => $base_fields |
| 124 | ], |
| 125 | 'responsive_lightbox_remote_library_providers' => [ |
| 126 | 'title' => __( 'Media Providers', 'responsive-lightbox' ), |
| 127 | 'callback' => [ $this, 'remote_library_providers_description' ], |
| 128 | 'fields' => $provider_fields |
| 129 | ] |
| 130 | ] |
| 131 | ]; |
| 132 | |
| 133 | return $data; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Remote Library Media Providers description. |
| 138 | * |
| 139 | * @return void |
| 140 | */ |
| 141 | public function remote_library_providers_description() { |
| 142 | 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="http://www.dfactory.co/products/remote-library-pro/?utm_source=responsive-lightbox-settings&utm_medium=link&utm_campaign=addon" target="_blank">Remote Library Pro</a>' ) . '</p>'; |
| 143 | } |
| 144 | } |
| 145 |