slides
11 months ago
Image.php
3 months ago
Settings.php
1 month ago
Slideshows.php
1 month ago
Themes.php
2 months ago
bootstrap.php
3 years ago
Settings.php
203 lines
| 1 | <?php |
| 2 | |
| 3 | if (!defined('ABSPATH')) { |
| 4 | die('No direct access.'); |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class to handle individual slideshow settings |
| 9 | */ |
| 10 | class MetaSlider_Slideshow_Settings |
| 11 | { |
| 12 | /** |
| 13 | * Themes class |
| 14 | * |
| 15 | * @var object | bool |
| 16 | */ |
| 17 | private $settings; |
| 18 | |
| 19 | /** |
| 20 | * Constructor |
| 21 | * |
| 22 | * @param string|null $slideshow_id The settings object |
| 23 | */ |
| 24 | public function __construct($slideshow_id = null) |
| 25 | { |
| 26 | $this->settings = get_post_meta($slideshow_id, 'ml-slider_settings', true); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns settings |
| 31 | * |
| 32 | * @return object |
| 33 | */ |
| 34 | public function get_settings() |
| 35 | { |
| 36 | return $this->settings ? $this->settings : self::defaults(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns a single setting |
| 41 | * |
| 42 | * @param string $setting A single setting name |
| 43 | * |
| 44 | * @return mixed|WP_error The setting result or an error object |
| 45 | */ |
| 46 | public function get_single($setting) |
| 47 | { |
| 48 | return isset($this->settings[$setting]) ? $this->settings[$setting] : new WP_Error('invalid_setting', 'The setting was not found', array('status' => 404)); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the default settings |
| 53 | * |
| 54 | * @return array |
| 55 | */ |
| 56 | public static function defaults() |
| 57 | { |
| 58 | $defaults = array( |
| 59 | 'title' => __('New Slideshow', 'ml-slider'), |
| 60 | 'type' => 'flex', |
| 61 | 'random' => false, |
| 62 | 'cssClass' => '', |
| 63 | 'printCss' => true, |
| 64 | 'printJs' => true, |
| 65 | 'width' => 700, |
| 66 | 'height' => 300, |
| 67 | 'spw' => 7, |
| 68 | 'sph' => 5, |
| 69 | 'delay' => 3000, |
| 70 | 'sDelay' => 30, |
| 71 | 'opacity' => 0.7, |
| 72 | 'titleSpeed' => 500, |
| 73 | 'effect' => 'slide', |
| 74 | 'extra_effect' => 'none', |
| 75 | 'navigation' => true, |
| 76 | 'filmstrip_delay' => 7000, |
| 77 | 'filmstrip_animationSpeed' => 600, |
| 78 | 'links' => true, |
| 79 | 'hoverPause' => true, |
| 80 | 'theme' => 'none', |
| 81 | 'direction' => 'horizontal', |
| 82 | 'reverse' => false, |
| 83 | 'keyboard' => true, |
| 84 | 'touch' => true, |
| 85 | 'animationSpeed' => 600, |
| 86 | 'prevText' => __('Previous', 'ml-slider'), |
| 87 | 'nextText' => __('Next', 'ml-slider'), |
| 88 | 'slices' => 15, |
| 89 | 'center' => false, |
| 90 | 'smartCrop' => true, |
| 91 | 'smartCropSource' => 'slideshow', |
| 92 | 'imageWidth' => 400, |
| 93 | 'imageHeight' => 400, |
| 94 | 'cropMultiply' => 1, |
| 95 | 'smoothHeight' => false, |
| 96 | 'carouselMode' => false, |
| 97 | 'infiniteLoop' => false, |
| 98 | 'carouselMargin' => 5, |
| 99 | 'minItems' => 2, |
| 100 | 'maxItems' => 0, |
| 101 | 'forceHeight' => false, |
| 102 | 'firstSlideFadeIn' => false, |
| 103 | 'easing' => 'linear', |
| 104 | 'autoPlay' => true, |
| 105 | 'loop' => 'continuously', |
| 106 | 'thumb_width' => 150, |
| 107 | 'thumb_height' => 100, |
| 108 | 'responsive_thumbs' => true, |
| 109 | 'thumb_min_width' => 100, |
| 110 | 'thumb_layout' => 'grid', |
| 111 | 'fullWidth' => true, |
| 112 | 'forceFullWidth' => false, |
| 113 | 'fullWidthTarget' => 'body', |
| 114 | 'noConflict' => true, |
| 115 | 'mobileArrows_smartphone' => false, |
| 116 | 'mobileArrows_tablet' => false, |
| 117 | 'mobileArrows_laptop' => false, |
| 118 | 'mobileArrows_desktop' => false, |
| 119 | 'mobileNavigation_smartphone' => false, |
| 120 | 'mobileNavigation_tablet' => false, |
| 121 | 'mobileNavigation_laptop' => false, |
| 122 | 'mobileNavigation_desktop' => false, |
| 123 | 'mobileCaption_smartphone' => false, |
| 124 | 'mobileCaption_tablet' => false, |
| 125 | 'mobileCaption_laptop' => false, |
| 126 | 'mobileCaption_desktop' => false, |
| 127 | 'mobileSlideshow_smartphone' => false, |
| 128 | 'mobileSlideshow_tablet' => false, |
| 129 | 'mobileSlideshow_laptop' => false, |
| 130 | 'mobileSlideshow_desktop' => false, |
| 131 | 'ariaLive' => true, |
| 132 | 'ariaCurrent' => true, |
| 133 | 'tabIndex' => true, |
| 134 | 'pausePlay' => false, |
| 135 | 'progressBar' => false, |
| 136 | 'loading' => false, |
| 137 | 'lazyLoad' => false, |
| 138 | 'playText' => '', |
| 139 | 'pauseText' => '', |
| 140 | 'container' => false, |
| 141 | 'container_background' => 'rgba(255,255,255,0)', |
| 142 | 'containerPadding_top' => 10, |
| 143 | 'containerPadding_right' => 10, |
| 144 | 'containerPadding_bottom' => 10, |
| 145 | 'containerPadding_left' => 10, |
| 146 | 'containerMargin_top' => 10, |
| 147 | 'containerMargin_bottom' => 30, |
| 148 | 'navStep' => 1 |
| 149 | ); |
| 150 | $defaults = apply_filters('metaslider_default_parameters', $defaults); |
| 151 | $overrides = get_option('metaslider_default_settings'); |
| 152 | return is_array($overrides) ? array_merge($defaults, $overrides) : $defaults; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Convert 'on' or 'off' to boolean values |
| 157 | * |
| 158 | * @since 3.92 |
| 159 | * |
| 160 | * @param array $settings Slideshow settings |
| 161 | * |
| 162 | * @return array |
| 163 | */ |
| 164 | public static function adjust_settings($settings) |
| 165 | { |
| 166 | // Convert submitted checkbox values from 'on' or 'off' to boolean values in string format (e.g. true becomes 'true') |
| 167 | $checkboxes = array('noConflict', 'fullWidth', 'forceFullWidth', 'hoverPause', 'reverse', 'printCss', 'printJs', 'smoothHeight', 'center', 'carouselMode', 'autoPlay', 'firstSlideFadeIn', 'responsive_thumbs', 'keyboard', 'touch', 'infiniteLoop', 'mobileArrows_smartphone', 'mobileArrows_tablet','mobileArrows_laptop', 'mobileArrows_desktop', 'mobileNavigation_smartphone', 'mobileNavigation_tablet', 'mobileNavigation_laptop', 'mobileNavigation_desktop', 'mobileCaption_smartphone', 'mobileCaption_tablet', 'mobileCaption_laptop', 'mobileCaption_desktop', 'mobileSlideshow_smartphone', 'mobileSlideshow_tablet', 'mobileSlideshow_laptop', 'mobileSlideshow_desktop', 'ariaLive', 'tabIndex', 'pausePlay', 'showPlayText', 'ariaCurrent', 'progressBar', 'loading', 'lazyLoad', 'forceHeight', 'lightbox', 'container'); |
| 168 | |
| 169 | foreach ($checkboxes as $checkbox) { |
| 170 | $settings[$checkbox] = (isset($settings[$checkbox]) && 'on' == $settings[$checkbox]) ? 'true' : 'false'; |
| 171 | } |
| 172 | |
| 173 | /* Convert submitted dropdown values from 'on' or 'off' to boolean values in string format (e.g. true becomes 'true') and sanitize the rest |
| 174 | * Reason is these settings have true/false + string options, so is better to handle all as strings |
| 175 | * Keep original value if is different to 'on' and 'off'. |
| 176 | * We include actual booleans in $map just in case. */ |
| 177 | $dropdowns = array('effect', 'cropMultiply', 'direction', 'easing', 'links', 'navigation', 'smartCrop', 'random', 'loop', 'layer_scaling'); |
| 178 | |
| 179 | foreach ($dropdowns as $dropdown) { |
| 180 | if (isset($settings[$dropdown])) { |
| 181 | $map = array( |
| 182 | 'on' => 'true', |
| 183 | 'off' => 'false', |
| 184 | true => 'true', |
| 185 | false => 'false' |
| 186 | ); |
| 187 | $settings[$dropdown] = $map[$settings[$dropdown]] ?? sanitize_text_field($settings[$dropdown]); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Sanitize text fields |
| 192 | $texts = array('cssClass', 'nextText', 'prevText', 'playText', 'pauseText'); |
| 193 | |
| 194 | foreach ($texts as $text) { |
| 195 | if (isset($settings[$text])) { |
| 196 | $settings[$text] = sanitize_text_field($settings[$text]); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return $settings; |
| 201 | } |
| 202 | } |
| 203 |