| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class SlideshowSEPluginSlideshowSettingsHandler handles all database/settings interactions for the slideshows. |
| 4 |
* |
| 5 |
* @since 2.1.20 |
| 6 |
* @author Stefan Boonstra |
| 7 |
*/ |
| 8 |
class SlideshowSEPluginSlideshowSettingsHandler |
| 9 |
{ |
| 10 |
/** @var string $nonceAction */ |
| 11 |
static $nonceAction = 'slideshow-jquery-image-gallery-nonceAction'; |
| 12 |
/** @var string $nonceName */ |
| 13 |
static $nonceName = 'slideshow-jquery-image-gallery-nonceName'; |
| 14 |
|
| 15 |
/** @var string $settingsKey */ |
| 16 |
static $settingsKey = 'settings'; |
| 17 |
/** @var string $styleSettingsKey */ |
| 18 |
static $styleSettingsKey = 'styleSettings'; |
| 19 |
/** @var string $slidesKey */ |
| 20 |
static $slidesKey = 'slides'; |
| 21 |
|
| 22 |
/** @var array $settings Used for caching by slideshow ID */ |
| 23 |
static $settings = array(); |
| 24 |
/** @var array $styleSettings Used for caching by slideshow ID */ |
| 25 |
static $styleSettings = array(); |
| 26 |
/** @var array $slides Used for caching by slideshow ID */ |
| 27 |
static $slides = array(); |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns all settings that belong to the passed post ID retrieved from |
| 31 |
* database, merged with default values from getDefaults(). Does not merge |
| 32 |
* if mergeDefaults is false. |
| 33 |
* |
| 34 |
* If all data (including field information and description) is needed, |
| 35 |
* set fullDefinition to true. See getDefaults() documentation for returned |
| 36 |
* values. mergeDefaults must be true for this option to have any effect. |
| 37 |
* |
| 38 |
* If enableCache is set to true, results are saved into local storage for |
| 39 |
* more efficient use. If data was already stored, cached data will be |
| 40 |
* returned, unless $enableCache is set to false. Settings will not be |
| 41 |
* cached. |
| 42 |
* |
| 43 |
* @since 2.1.20 |
| 44 |
* @param int $slideshowId |
| 45 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 46 |
* @param boolean $enableCache (optional, defaults to true) |
| 47 |
* @param boolean $mergeDefaults (optional, defaults to true) |
| 48 |
* @return mixed $settings |
| 49 |
*/ |
| 50 |
static function getAllSettings($slideshowId, $fullDefinition = false, $enableCache = true, $mergeDefaults = true) |
| 51 |
{ |
| 52 |
$settings = array(); |
| 53 |
$settings[self::$settingsKey] = self::getSettings($slideshowId, $fullDefinition, $enableCache, $mergeDefaults); |
| 54 |
$settings[self::$styleSettingsKey] = self::getStyleSettings($slideshowId, $fullDefinition, $enableCache, $mergeDefaults); |
| 55 |
$settings[self::$slidesKey] = self::getSlides($slideshowId, $enableCache); |
| 56 |
|
| 57 |
return $settings; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Returns settings retrieved from database. |
| 62 |
* |
| 63 |
* For a full description of the parameters, see getAllSettings(). |
| 64 |
* |
| 65 |
* @since 2.1.20 |
| 66 |
* @param int $slideshowId |
| 67 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 68 |
* @param boolean $enableCache (optional, defaults to true) |
| 69 |
* @param boolean $mergeDefaults (optional, defaults to true) |
| 70 |
* @return mixed $settings |
| 71 |
*/ |
| 72 |
static function getSettings($slideshowId, $fullDefinition = false, $enableCache = true, $mergeDefaults = true) |
| 73 |
{ |
| 74 |
if (!is_numeric($slideshowId) || |
| 75 |
empty($slideshowId)) |
| 76 |
{ |
| 77 |
return array(); |
| 78 |
} |
| 79 |
|
| 80 |
// Set caching to false and merging defaults to true when $fullDefinition is set to true |
| 81 |
if ($fullDefinition) |
| 82 |
{ |
| 83 |
$enableCache = false; |
| 84 |
$mergeDefaults = true; |
| 85 |
} |
| 86 |
|
| 87 |
// If no cache is set, or cache is disabled |
| 88 |
if (!isset(self::$settings[$slideshowId]) || |
| 89 |
empty(self::$settings[$slideshowId]) || |
| 90 |
!$enableCache) |
| 91 |
{ |
| 92 |
// Meta data |
| 93 |
$settingsMeta = get_post_meta( |
| 94 |
$slideshowId, |
| 95 |
self::$settingsKey, |
| 96 |
true |
| 97 |
); |
| 98 |
|
| 99 |
if (!$settingsMeta || |
| 100 |
!is_array($settingsMeta)) |
| 101 |
{ |
| 102 |
$settingsMeta = array(); |
| 103 |
} |
| 104 |
|
| 105 |
// If the settings should be merged with the defaults as a full definition, place each setting in an array referenced by 'value'. |
| 106 |
if ($fullDefinition) |
| 107 |
{ |
| 108 |
foreach ($settingsMeta as $key => $value) |
| 109 |
{ |
| 110 |
$settingsMeta[$key] = array('value' => $value); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
// Get defaults |
| 115 |
$defaults = array(); |
| 116 |
|
| 117 |
if ($mergeDefaults) |
| 118 |
{ |
| 119 |
$defaults = self::getDefaultSettings($fullDefinition); |
| 120 |
} |
| 121 |
|
| 122 |
// Merge with defaults, recursively if a the full definition is required |
| 123 |
if ($fullDefinition) |
| 124 |
{ |
| 125 |
$settings = array_merge_recursive( |
| 126 |
$defaults, |
| 127 |
$settingsMeta |
| 128 |
); |
| 129 |
} |
| 130 |
else |
| 131 |
{ |
| 132 |
$settings = array_merge( |
| 133 |
$defaults, |
| 134 |
$settingsMeta |
| 135 |
); |
| 136 |
} |
| 137 |
|
| 138 |
// Cache if cache is enabled |
| 139 |
if ($enableCache) |
| 140 |
{ |
| 141 |
self::$settings[$slideshowId] = $settings; |
| 142 |
} |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
// Get cached settings |
| 147 |
$settings = self::$settings[$slideshowId]; |
| 148 |
} |
| 149 |
|
| 150 |
// Return |
| 151 |
return $settings; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Returns style settings retrieved from database. |
| 156 |
* |
| 157 |
* For a full description of the parameters, see getAllSettings(). |
| 158 |
* |
| 159 |
* @since 2.1.20 |
| 160 |
* @param int $slideshowId |
| 161 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 162 |
* @param boolean $enableCache (optional, defaults to true) |
| 163 |
* @param boolean $mergeDefaults (optional, defaults to true) |
| 164 |
* @return mixed $settings |
| 165 |
*/ |
| 166 |
static function getStyleSettings($slideshowId, $fullDefinition = false, $enableCache = true, $mergeDefaults = true) |
| 167 |
{ |
| 168 |
if (!is_numeric($slideshowId) || |
| 169 |
empty($slideshowId)) |
| 170 |
{ |
| 171 |
return array(); |
| 172 |
} |
| 173 |
|
| 174 |
// Set caching to false and merging defaults to true when $fullDefinition is set to true |
| 175 |
if ($fullDefinition) |
| 176 |
{ |
| 177 |
$enableCache = false; |
| 178 |
$mergeDefaults = true; |
| 179 |
} |
| 180 |
|
| 181 |
// If no cache is set, or cache is disabled |
| 182 |
if (!isset(self::$styleSettings[$slideshowId]) || |
| 183 |
empty(self::$styleSettings[$slideshowId]) || |
| 184 |
!$enableCache) |
| 185 |
{ |
| 186 |
// Meta data |
| 187 |
$styleSettingsMeta = get_post_meta( |
| 188 |
$slideshowId, |
| 189 |
self::$styleSettingsKey, |
| 190 |
true |
| 191 |
); |
| 192 |
|
| 193 |
if (!$styleSettingsMeta || |
| 194 |
!is_array($styleSettingsMeta)) |
| 195 |
{ |
| 196 |
$styleSettingsMeta = array(); |
| 197 |
} |
| 198 |
|
| 199 |
// If the settings should be merged with the defaults as a full definition, place each setting in an array referenced by 'value'. |
| 200 |
if ($fullDefinition) |
| 201 |
{ |
| 202 |
foreach ($styleSettingsMeta as $key => $value) |
| 203 |
{ |
| 204 |
$styleSettingsMeta[$key] = array('value' => $value); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
// Get defaults |
| 209 |
$defaults = array(); |
| 210 |
|
| 211 |
if ($mergeDefaults) |
| 212 |
{ |
| 213 |
$defaults = self::getDefaultStyleSettings($fullDefinition); |
| 214 |
} |
| 215 |
|
| 216 |
// Merge with defaults, recursively if a the full definition is required |
| 217 |
if ($fullDefinition) |
| 218 |
{ |
| 219 |
$styleSettings = array_merge_recursive( |
| 220 |
$defaults, |
| 221 |
$styleSettingsMeta |
| 222 |
); |
| 223 |
} |
| 224 |
else |
| 225 |
{ |
| 226 |
$styleSettings = array_merge( |
| 227 |
$defaults, |
| 228 |
$styleSettingsMeta |
| 229 |
); |
| 230 |
} |
| 231 |
|
| 232 |
// Cache if cache is enabled |
| 233 |
if ($enableCache) |
| 234 |
{ |
| 235 |
self::$styleSettings[$slideshowId] = $styleSettings; |
| 236 |
} |
| 237 |
} |
| 238 |
else |
| 239 |
{ |
| 240 |
// Get cached settings |
| 241 |
$styleSettings = self::$styleSettings[$slideshowId]; |
| 242 |
} |
| 243 |
|
| 244 |
// Return |
| 245 |
return $styleSettings; |
| 246 |
} |
| 247 |
|
| 248 |
/** |
| 249 |
* Returns slides retrieved from database. |
| 250 |
* |
| 251 |
* For a full description of the parameters, see getAllSettings(). |
| 252 |
* |
| 253 |
* @since 2.1.20 |
| 254 |
* @param int $slideshowId |
| 255 |
* @param boolean $enableCache (optional, defaults to true) |
| 256 |
* @return mixed $settings |
| 257 |
*/ |
| 258 |
static function getSlides($slideshowId, $enableCache = true) |
| 259 |
{ |
| 260 |
if (!is_numeric($slideshowId) || |
| 261 |
empty($slideshowId)) |
| 262 |
{ |
| 263 |
return array(); |
| 264 |
} |
| 265 |
|
| 266 |
// If no cache is set, or cache is disabled |
| 267 |
if (!isset(self::$slides[$slideshowId]) || |
| 268 |
empty(self::$slides[$slideshowId]) || |
| 269 |
!$enableCache) |
| 270 |
{ |
| 271 |
// Meta data |
| 272 |
$slides = get_post_meta( |
| 273 |
$slideshowId, |
| 274 |
self::$slidesKey, |
| 275 |
true |
| 276 |
); |
| 277 |
} |
| 278 |
else |
| 279 |
{ |
| 280 |
// Get cached settings |
| 281 |
$slides = self::$slides[$slideshowId]; |
| 282 |
} |
| 283 |
|
| 284 |
// Sort slides by order ID |
| 285 |
if (is_array($slides)) |
| 286 |
{ |
| 287 |
ksort($slides); |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
$slides = array(); |
| 292 |
} |
| 293 |
|
| 294 |
// Return |
| 295 |
return array_values($slides); |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* Get new settings from $_POST variable and merge them with |
| 300 |
* the old and default settings. |
| 301 |
* |
| 302 |
* @since 2.1.20 |
| 303 |
* @param int $postId |
| 304 |
* @return int $postId |
| 305 |
*/ |
| 306 |
static function save($postId) |
| 307 |
{ |
| 308 |
// Verify nonce, check if user has sufficient rights and return on auto-save. |
| 309 |
if (get_post_type($postId) != SlideshowSEPluginPostType::$postType || |
| 310 |
(!isset($_POST[self::$nonceName]) || !wp_verify_nonce($_POST[self::$nonceName], self::$nonceAction)) || |
| 311 |
!current_user_can('slideshow-jquery-image-gallery-edit-slideshows', $postId) || |
| 312 |
(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) |
| 313 |
{ |
| 314 |
return $postId; |
| 315 |
} |
| 316 |
|
| 317 |
// Old settings |
| 318 |
$oldSettings = self::getSettings($postId); |
| 319 |
$oldStyleSettings = self::getStyleSettings($postId); |
| 320 |
|
| 321 |
// Get new settings from $_POST, making sure they're arrays |
| 322 |
$newPostSettings = $newPostStyleSettings = $newPostSlides = array(); |
| 323 |
|
| 324 |
if (isset($_POST[self::$settingsKey]) && |
| 325 |
is_array($_POST[self::$settingsKey])) |
| 326 |
{ |
| 327 |
$newPostSettings = sanitize_text_field($_POST[self::$settingsKey]); |
| 328 |
} |
| 329 |
|
| 330 |
if (isset($_POST[self::$styleSettingsKey]) && |
| 331 |
is_array($_POST[self::$styleSettingsKey])) |
| 332 |
{ |
| 333 |
$newPostStyleSettings = sanitize_text_field($_POST[self::$styleSettingsKey]); |
| 334 |
} |
| 335 |
|
| 336 |
if (isset($_POST[self::$slidesKey]) && |
| 337 |
is_array($_POST[self::$slidesKey])) |
| 338 |
{ |
| 339 |
$newPostSlides = sanitize_text_field($_POST[self::$slidesKey]); |
| 340 |
} |
| 341 |
|
| 342 |
// Merge new settings with its old values |
| 343 |
$newSettings = array_merge( |
| 344 |
$oldSettings, |
| 345 |
$newPostSettings |
| 346 |
); |
| 347 |
|
| 348 |
// Merge new style settings with its old values |
| 349 |
$newStyleSettings = array_merge( |
| 350 |
$oldStyleSettings, |
| 351 |
$newPostStyleSettings |
| 352 |
); |
| 353 |
|
| 354 |
// Save settings |
| 355 |
update_post_meta($postId, self::$settingsKey, $newSettings); |
| 356 |
update_post_meta($postId, self::$styleSettingsKey, $newStyleSettings); |
| 357 |
update_post_meta($postId, self::$slidesKey, $newPostSlides); |
| 358 |
|
| 359 |
// Return |
| 360 |
return $postId; |
| 361 |
} |
| 362 |
|
| 363 |
/** |
| 364 |
* Returns an array of all defaults. The array will be returned |
| 365 |
* like this: |
| 366 |
* array([settingsKey] => array([settingName] => [settingValue])) |
| 367 |
* |
| 368 |
* If all default data (including field information and description) |
| 369 |
* is needed, set fullDefinition to true. Data in the full definition is |
| 370 |
* build up as follows: |
| 371 |
* array([settingsKey] => array([settingName] => array('type' => [inputType], 'value' => [value], 'default' => [default], 'description' => [description], 'options' => array([options]), 'dependsOn' => array([dependsOn], [onValue]), 'group' => [groupName]))) |
| 372 |
* |
| 373 |
* Finally, when you require the defaults as they were programmed in, |
| 374 |
* set this parameter to false. When set to true, the database will |
| 375 |
* first be consulted for user-customized defaults. Defaults to true. |
| 376 |
* |
| 377 |
* @since 2.1.20 |
| 378 |
* @param mixed $key (optional, defaults to null, getting all keys) |
| 379 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 380 |
* @param boolean $fromDatabase (optional, defaults to true) |
| 381 |
* @return mixed $data |
| 382 |
*/ |
| 383 |
static function getAllDefaults($key = null, $fullDefinition = false, $fromDatabase = true) |
| 384 |
{ |
| 385 |
$data = array(); |
| 386 |
$data[self::$settingsKey] = self::getDefaultSettings($fullDefinition, $fromDatabase); |
| 387 |
$data[self::$styleSettingsKey] = self::getDefaultStyleSettings($fullDefinition, $fromDatabase); |
| 388 |
|
| 389 |
return $data; |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Returns an array of setting defaults. |
| 394 |
* |
| 395 |
* For a full description of the parameters, see getAllDefaults(). |
| 396 |
* |
| 397 |
* @since 2.1.20 |
| 398 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 399 |
* @param boolean $fromDatabase (optional, defaults to true) |
| 400 |
* @return mixed $data |
| 401 |
*/ |
| 402 |
static function getDefaultSettings($fullDefinition = false, $fromDatabase = true) |
| 403 |
{ |
| 404 |
// Much used data for translation |
| 405 |
$yes = __('Yes', 'slideshow-se'); |
| 406 |
$no = __('No', 'slideshow-se'); |
| 407 |
|
| 408 |
// Default values |
| 409 |
$data = array( |
| 410 |
'animation' => 'slide', |
| 411 |
'slideSpeed' => '1', |
| 412 |
'descriptionSpeed' => '0.4', |
| 413 |
'intervalSpeed' => '5', |
| 414 |
'slidesPerView' => '1', |
| 415 |
'maxWidth' => '0', |
| 416 |
'aspectRatio' => '3:1', |
| 417 |
'height' => '200', |
| 418 |
'imageBehaviour' => 'natural', |
| 419 |
'showDescription' => 'true', |
| 420 |
'hideDescription' => 'true', |
| 421 |
'preserveSlideshowDimensions' => 'false', |
| 422 |
'enableResponsiveness' => 'true', |
| 423 |
'play' => 'true', |
| 424 |
'loop' => 'true', |
| 425 |
'pauseOnHover' => 'true', |
| 426 |
'controllable' => 'true', |
| 427 |
'hideNavigationButtons' => 'false', |
| 428 |
'showPagination' => 'true', |
| 429 |
'hidePagination' => 'true', |
| 430 |
'controlPanel' => 'false', |
| 431 |
'hideControlPanel' => 'true', |
| 432 |
'waitUntilLoaded' => 'true', |
| 433 |
'showLoadingIcon' => 'true', |
| 434 |
'random' => 'false', |
| 435 |
'avoidFilter' => 'true' |
| 436 |
); |
| 437 |
|
| 438 |
// Read defaults from database and merge with $data, when $fromDatabase is set to true |
| 439 |
if ($fromDatabase) |
| 440 |
{ |
| 441 |
$data = array_merge( |
| 442 |
$data, |
| 443 |
$customData = get_option(SlideshowSEPluginGeneralSettings::$defaultSettings, array()) |
| 444 |
); |
| 445 |
} |
| 446 |
|
| 447 |
// Full definition |
| 448 |
if ($fullDefinition) |
| 449 |
{ |
| 450 |
$descriptions = array( |
| 451 |
'animation' => __('Animation used for transition between slides', 'slideshow-se'), |
| 452 |
'slideSpeed' => __('Number of seconds the slide takes to slide in', 'slideshow-se'), |
| 453 |
'descriptionSpeed' => __('Number of seconds the description takes to slide in', 'slideshow-se'), |
| 454 |
'intervalSpeed' => __('Seconds between changing slides', 'slideshow-se'), |
| 455 |
'slidesPerView' => __('Number of slides to fit into one slide', 'slideshow-se'), |
| 456 |
'maxWidth' => __('Maximum width. When maximum width is 0, maximum width is ignored', 'slideshow-se'), |
| 457 |
'aspectRatio' => sprintf('<a href="' . str_replace('%', '%%', __('http://en.wikipedia.org/wiki/Aspect_ratio_(image)', 'slideshow-se')) . '" title="' . __('More info', 'slideshow-se') . '" target="_blank">' . __('Proportional relationship%s between slideshow\'s width and height (width:height)', 'slideshow-se'), '</a>'), |
| 458 |
'height' => __('Slideshow\'s height', 'slideshow-se'), |
| 459 |
'imageBehaviour' => __('Image behaviour', 'slideshow-se'), |
| 460 |
'preserveSlideshowDimensions' => __('Shrink slideshow\'s height when width shrinks', 'slideshow-se'), |
| 461 |
'enableResponsiveness' => __('Enable responsiveness (Shrink slideshow\'s width when page\'s width shrinks)', 'slideshow-se'), |
| 462 |
'showDescription' => __('Show title and description', 'slideshow-se'), |
| 463 |
'hideDescription' => __('Hide description box, pop up when mouse hovers over', 'slideshow-se'), |
| 464 |
'play' => __('Automatically slide to the next slide', 'slideshow-se'), |
| 465 |
'loop' => __('Return to the beginning of the slideshow after last slide', 'slideshow-se'), |
| 466 |
'pauseOnHover' => __('Pause slideshow when mouse hovers over', 'slideshow-se'), |
| 467 |
'controllable' => __('Activate navigation buttons', 'slideshow-se'), |
| 468 |
'hideNavigationButtons' => __('Hide navigation buttons, show when mouse hovers over', 'slideshow-se'), |
| 469 |
'showPagination' => __('Activate pagination', 'slideshow-se'), |
| 470 |
'hidePagination' => __('Hide pagination, show when mouse hovers over', 'slideshow-se'), |
| 471 |
'controlPanel' => __('Activate control panel (play and pause button)', 'slideshow-se'), |
| 472 |
'hideControlPanel' => __('Hide control panel, show when mouse hovers over', 'slideshow-se'), |
| 473 |
'waitUntilLoaded' => __('Wait until the next slide has loaded before showing it', 'slideshow-se'), |
| 474 |
'showLoadingIcon' => __('Show a loading icon until the first slide appears', 'slideshow-se'), |
| 475 |
'random' => __('Randomize slides', 'slideshow-se'), |
| 476 |
'avoidFilter' => sprintf(__('Avoid content filter (disable if \'%s\' is shown)', 'slideshow-se'), SlideshowSEPluginShortcode::$bookmark) |
| 477 |
); |
| 478 |
|
| 479 |
$data = array( |
| 480 |
'animation' => array('type' => 'select', 'default' => $data['animation'] , 'description' => $descriptions['animation'] , 'group' => __('Animation', 'slideshow-se') , 'options' => array('slide' => __('Slide Left', 'slideshow-se'), 'slideRight' => __('Slide Right', 'slideshow-se'), 'slideUp' => __('Slide Up', 'slideshow-se'), 'slideDown' => __('Slide Down', 'slideshow-se'), 'crossFade' => __('Cross Fade', 'slideshow-se'), 'directFade' => __('Direct Fade', 'slideshow-se'), 'fade' => __('Fade', 'slideshow-se'), 'random' => __('Random Animation', 'slideshow-se'))), |
| 481 |
'slideSpeed' => array('type' => 'text' , 'default' => $data['slideSpeed'] , 'description' => $descriptions['slideSpeed'] , 'group' => __('Animation', 'slideshow-se')), |
| 482 |
'descriptionSpeed' => array('type' => 'text' , 'default' => $data['descriptionSpeed'] , 'description' => $descriptions['descriptionSpeed'] , 'group' => __('Animation', 'slideshow-se')), |
| 483 |
'intervalSpeed' => array('type' => 'text' , 'default' => $data['intervalSpeed'] , 'description' => $descriptions['intervalSpeed'] , 'group' => __('Animation', 'slideshow-se')), |
| 484 |
'slidesPerView' => array('type' => 'text' , 'default' => $data['slidesPerView'] , 'description' => $descriptions['slidesPerView'] , 'group' => __('Display', 'slideshow-se')), |
| 485 |
'maxWidth' => array('type' => 'text' , 'default' => $data['maxWidth'] , 'description' => $descriptions['maxWidth'] , 'group' => __('Display', 'slideshow-se')), |
| 486 |
'aspectRatio' => array('type' => 'text' , 'default' => $data['aspectRatio'] , 'description' => $descriptions['aspectRatio'] , 'group' => __('Display', 'slideshow-se') , 'dependsOn' => array('settings[preserveSlideshowDimensions]', 'true')), |
| 487 |
'height' => array('type' => 'text' , 'default' => $data['height'] , 'description' => $descriptions['height'] , 'group' => __('Display', 'slideshow-se') , 'dependsOn' => array('settings[preserveSlideshowDimensions]', 'false')), |
| 488 |
'imageBehaviour' => array('type' => 'select', 'default' => $data['imageBehaviour'] , 'description' => $descriptions['imageBehaviour'] , 'group' => __('Display', 'slideshow-se') , 'options' => array('natural' => __('Natural and centered', 'slideshow-se'), 'crop' => __('Crop to fit', 'slideshow-se'), 'stretch' => __('Stretch to fit', 'slideshow-se'))), |
| 489 |
'preserveSlideshowDimensions' => array('type' => 'radio' , 'default' => $data['preserveSlideshowDimensions'], 'description' => $descriptions['preserveSlideshowDimensions'], 'group' => __('Display', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[enableResponsiveness]', 'true')), |
| 490 |
'enableResponsiveness' => array('type' => 'radio' , 'default' => $data['enableResponsiveness'] , 'description' => $descriptions['enableResponsiveness'] , 'group' => __('Display', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 491 |
'showDescription' => array('type' => 'radio' , 'default' => $data['showDescription'] , 'description' => $descriptions['showDescription'] , 'group' => __('Display', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 492 |
'hideDescription' => array('type' => 'radio' , 'default' => $data['hideDescription'] , 'description' => $descriptions['hideDescription'] , 'group' => __('Display', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[showDescription]', 'true')), |
| 493 |
'play' => array('type' => 'radio' , 'default' => $data['play'] , 'description' => $descriptions['play'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 494 |
'loop' => array('type' => 'radio' , 'default' => $data['loop'] , 'description' => $descriptions['loop'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 495 |
'pauseOnHover' => array('type' => 'radio' , 'default' => $data['loop'] , 'description' => $descriptions['pauseOnHover'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 496 |
'controllable' => array('type' => 'radio' , 'default' => $data['controllable'] , 'description' => $descriptions['controllable'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 497 |
'hideNavigationButtons' => array('type' => 'radio' , 'default' => $data['hideNavigationButtons'] , 'description' => $descriptions['hideNavigationButtons'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[controllable]', 'true')), |
| 498 |
'showPagination' => array('type' => 'radio' , 'default' => $data['showPagination'] , 'description' => $descriptions['showPagination'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 499 |
'hidePagination' => array('type' => 'radio' , 'default' => $data['hidePagination'] , 'description' => $descriptions['hidePagination'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[showPagination]', 'true')), |
| 500 |
'controlPanel' => array('type' => 'radio' , 'default' => $data['controlPanel'] , 'description' => $descriptions['controlPanel'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no)), |
| 501 |
'hideControlPanel' => array('type' => 'radio' , 'default' => $data['hideControlPanel'] , 'description' => $descriptions['hideControlPanel'] , 'group' => __('Control', 'slideshow-se') , 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[controlPanel]', 'true')), |
| 502 |
'waitUntilLoaded' => array('type' => 'radio' , 'default' => $data['waitUntilLoaded'] , 'description' => $descriptions['waitUntilLoaded'] , 'group' => __('Miscellaneous', 'slideshow-se'), 'options' => array('true' => $yes, 'false' => $no)), |
| 503 |
'showLoadingIcon' => array('type' => 'radio' , 'default' => $data['showLoadingIcon'] , 'description' => $descriptions['showLoadingIcon'] , 'group' => __('Miscellaneous', 'slideshow-se'), 'options' => array('true' => $yes, 'false' => $no) , 'dependsOn' => array('settings[waitUntilLoaded]', 'true')), |
| 504 |
'random' => array('type' => 'radio' , 'default' => $data['random'] , 'description' => $descriptions['random'] , 'group' => __('Miscellaneous', 'slideshow-se'), 'options' => array('true' => $yes, 'false' => $no)), |
| 505 |
'avoidFilter' => array('type' => 'radio' , 'default' => $data['avoidFilter'] , 'description' => $descriptions['avoidFilter'] , 'group' => __('Miscellaneous', 'slideshow-se'), 'options' => array('true' => $yes, 'false' => $no)) |
| 506 |
); |
| 507 |
} |
| 508 |
|
| 509 |
// Return |
| 510 |
return $data; |
| 511 |
} |
| 512 |
|
| 513 |
/** |
| 514 |
* Returns an array of style setting defaults. |
| 515 |
* |
| 516 |
* For a full description of the parameters, see getAllDefaults(). |
| 517 |
* |
| 518 |
* @since 2.1.20 |
| 519 |
* @param boolean $fullDefinition (optional, defaults to false) |
| 520 |
* @param boolean $fromDatabase (optional, defaults to true) |
| 521 |
* @return mixed $data |
| 522 |
*/ |
| 523 |
static function getDefaultStyleSettings($fullDefinition = false, $fromDatabase = true) |
| 524 |
{ |
| 525 |
// Default style settings |
| 526 |
$data = array( |
| 527 |
'style' => 'style-light.css' |
| 528 |
); |
| 529 |
|
| 530 |
// Read defaults from database and merge with $data, when $fromDatabase is set to true |
| 531 |
if ($fromDatabase) |
| 532 |
{ |
| 533 |
$data = array_merge( |
| 534 |
$data, |
| 535 |
$customData = get_option(SlideshowSEPluginGeneralSettings::$defaultStyleSettings, array()) |
| 536 |
); |
| 537 |
} |
| 538 |
|
| 539 |
// Full definition |
| 540 |
if ($fullDefinition) |
| 541 |
{ |
| 542 |
$data = array( |
| 543 |
'style' => array('type' => 'select', 'default' => $data['style'], 'description' => __('The style used for this slideshow', 'slideshow-se'), 'options' => SlideshowSEPluginGeneralSettings::getStylesheets()), |
| 544 |
); |
| 545 |
} |
| 546 |
|
| 547 |
// Return |
| 548 |
return $data; |
| 549 |
} |
| 550 |
|
| 551 |
/** |
| 552 |
* Returns an HTML inputField of the input setting. |
| 553 |
* |
| 554 |
* This function expects the setting to be in the 'fullDefinition' |
| 555 |
* format that the getDefaults() and getSettings() methods both |
| 556 |
* return. |
| 557 |
* |
| 558 |
* @since 2.1.20 |
| 559 |
* @param string $settingsKey |
| 560 |
* @param string $settingsName |
| 561 |
* @param mixed $settings |
| 562 |
* @param bool $hideDependentValues (optional, defaults to true) |
| 563 |
* @return mixed $inputField |
| 564 |
*/ |
| 565 |
static function getInputField($settingsKey, $settingsName, $settings, $hideDependentValues = true) |
| 566 |
{ |
| 567 |
if (!is_array($settings) || |
| 568 |
empty($settings) || |
| 569 |
empty($settingsName)) |
| 570 |
{ |
| 571 |
return null; |
| 572 |
} |
| 573 |
|
| 574 |
$inputField = ''; |
| 575 |
$name = $settingsKey . '[' . $settingsName . ']'; |
| 576 |
$displayValue = (!isset($settings['value']) || (empty($settings['value']) && !is_numeric($settings['value'])) ? $settings['default'] : $settings['value']); |
| 577 |
$class = ((isset($settings['dependsOn']) && $hideDependentValues)? 'depends-on-field-value ' . $settings['dependsOn'][0] . ' ' . $settings['dependsOn'][1] . ' ': '') . $settingsKey . '-' . $settingsName; |
| 578 |
|
| 579 |
switch($settings['type']) |
| 580 |
{ |
| 581 |
case 'text': |
| 582 |
|
| 583 |
$inputField .= '<input |
| 584 |
type="text" |
| 585 |
name="' . $name . '" |
| 586 |
class="' . $class . '" |
| 587 |
value="' . $displayValue . '" |
| 588 |
/>'; |
| 589 |
|
| 590 |
break; |
| 591 |
|
| 592 |
case 'textarea': |
| 593 |
|
| 594 |
$inputField .= '<textarea |
| 595 |
name="' . $name . '" |
| 596 |
class="' . $class . '" |
| 597 |
rows="20" |
| 598 |
cols="60" |
| 599 |
>' . $displayValue . '</textarea>'; |
| 600 |
|
| 601 |
break; |
| 602 |
|
| 603 |
case 'select': |
| 604 |
|
| 605 |
$inputField .= '<select name="' . $name . '" class="' . $class . '">'; |
| 606 |
|
| 607 |
foreach ($settings['options'] as $optionKey => $optionValue) |
| 608 |
{ |
| 609 |
$inputField .= '<option value="' . $optionKey . '" ' . selected($displayValue, $optionKey, false) . '> |
| 610 |
' . $optionValue . ' |
| 611 |
</option>'; |
| 612 |
} |
| 613 |
|
| 614 |
$inputField .= '</select>'; |
| 615 |
|
| 616 |
break; |
| 617 |
|
| 618 |
case 'radio': |
| 619 |
|
| 620 |
foreach ($settings['options'] as $radioKey => $radioValue) |
| 621 |
{ |
| 622 |
$inputField .= '<label style="padding-right: 10px;"><input |
| 623 |
type="radio" |
| 624 |
name="' . $name . '" |
| 625 |
class="' . $class . '" |
| 626 |
value="' . $radioKey . '" ' . |
| 627 |
checked($displayValue, $radioKey, false) . |
| 628 |
' />' . $radioValue . '</label>'; |
| 629 |
} |
| 630 |
|
| 631 |
break; |
| 632 |
|
| 633 |
default: |
| 634 |
|
| 635 |
$inputField = null; |
| 636 |
|
| 637 |
break; |
| 638 |
}; |
| 639 |
|
| 640 |
// Return |
| 641 |
return $inputField; |
| 642 |
} |
| 643 |
} |