/
minimus
/
simple-view
Обзор
Документация
Войти
/
minimus
/
simple-view
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
plugin/sv-tools.php
109 строк
5 KB
minimus
feat: SV Admin Class
21 июл 2026, 14:27
21 июл 2026, 14:27
32b7aa3
Код
Авторство
О чём код?
<?php if (!defined('ABSPATH')) { exit; } if (!class_exists("SvTools")) { class SvTools { private array $settings = []; public array $defaultSettings = []; public function __construct() { $this->defaultSettings = self::getDefaultSettings(); } private function getDefaultSettings(): array { return [ 'majorVersion' => 2, 'delOptions' => 'false', 'delTables' => true, 'galleriesPerPage' => '15', 'itemsPerPage' => '15', 'galleryDir' => '', 'galleryURL' => '', 'gCodeBefore' => '<div class="gallery-container">', 'gCodeAfter' => '</div>', 'iCodeBefore' => '', 'iCodeAfter' => '', 'autoThumbnail' => 'true', 'thumbBigSize' => '120', 'thumbSuffix' => '-thumb', 'thumb_padding' => '0', 'thumb_margins' => '5', 'thumb_border_width' => '1', 'thumb_border_color' => '000000' ]; } public function getSettings(): array { if (count($this->settings) === 0) { $this->settings = get_option("SimpleViewPluginOptions", $this->defaultSettings); } return $this->settings; } public function setSettings(array $settings): void { update_option("SimpleViewPluginOptions", $settings, true); } public function removeSettings(): void { delete_option("SimpleViewPluginOptions"); } public function convertOptions(array $options): ?array { if (!$options) return null; return [ 'majorVersion' => $options['majorVersion'] ?? 2, 'delOptions' => $options['delOptions'] === 'true', 'delTables' => $options['delTables'], 'galleriesPerPage' => (int)$options['galleriesPerPage'], 'itemsPerPage' => (int)$options['itemsPerPage'], 'galleryDir' => $options['galleryDir'], 'galleryURL' => $options['galleryURL'], 'gCodeBefore' => $options['gCodeBefore'] === '<p style="text-align: center;">' ? '<div class="gallery-container">' : $options['gCodeBefore'], 'gCodeAfter' => $options['gCodeAfter'] === '</p>' ? '</div>' : $options['gCodeAfter'], 'iCodeBefore' => $options['iCodeBefore'], 'iCodeAfter' => $options['iCodeAfter'], 'autoThumbnail' => $options['autoThumbnail'] === 'true', 'thumbBigSize' => (int)$options['thumbBigSize'], 'thumbSuffix' => $options['thumbSuffix'], 'thumbPadding' => (int)$options['thumb_padding'], 'thumbMargins' => (int)$options['thumb_margins'], 'thumbBorderWidth' => (int)$options['thumb_border_width'], 'thumbBorderColor' => preg_match('/^#.{3,8}/i', $options['thumb_border_color']) ? $options['thumb_border_color'] : '#' . $options['thumb_border_color'] ]; } public function convertToOptions(array $settings): ?array { if (!$settings) return null; return [ 'majorVersion' => $settings['majorVersion'], 'delOptions' => !!$settings['delOptions'] ? 'true' : 'false', 'delTables' => $settings['delTables'], 'galleriesPerPage' => (string)$settings['galleriesPerPage'], 'itemsPerPage' => (string)$settings['itemsPerPage'], 'galleryDir' => $settings['galleryDir'], 'galleryURL' => $settings['galleryURL'], 'gCodeBefore' => $settings['gCodeBefore'] ?? '', 'gCodeAfter' => $settings['gCodeAfter'] ?? '', 'iCodeBefore' => $settings['iCodeBefore'], 'iCodeAfter' => $settings['iCodeAfter'], 'autoThumbnail' => !!$settings['autoThumbnail'] ? 'true' : 'false', 'thumbBigSize' => (string)$settings['thumbBigSize'], 'thumbSuffix' => $settings['thumbSuffix'], 'thumb_padding' => (string)$settings['thumbPadding'], 'thumb_margins' => (string)$settings['thumbMargins'], 'thumb_border_width' => (string)$settings['thumbBorderWidth'], 'thumb_border_color' => $settings['thumbBorderColor'] ]; } } }