From 1af221b25f9973a8f57d9d45f3817d68332600da Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 14:53:45 +0200 Subject: [PATCH] release 0.9 --- CHANGELOG.md | 5 +++ README.md | 4 +-- _define.php | 6 ++-- dcstore.xml | 6 ++-- src/Backend.php | 12 +++---- src/BackendBehaviors.php | 71 +++++++++++++++++++++------------------- src/My.php | 28 +++------------- src/Settings.php | 21 +++--------- src/Uninstall.php | 10 +++--- 9 files changed, 67 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eb72d9..8fea088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ dev - [ ] add update from external repositories +0.9 - 2023.07.30 +- require Dotclear 2.27 +- require PHP 8.1+ +- update to Dotclear 2.27-dev + 0.8 - 2023.04.29 - require Dotclear 2.26 - require PHP 8.1+ diff --git a/README.md b/README.md index 593af32..dd1833d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/tweakStores) [![License](https://img.shields.io/github/license/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/blob/master/LICENSE) @@ -19,7 +19,7 @@ It helps devs to manage dcstore.xml file. _tweakStores_ requires: * superadmin permissions - * Dotclear 2.26 + * Dotclear 2.27 * PHP 8.1+ ## USAGE diff --git a/_define.php b/_define.php index 8c1a451..cc80868 100644 --- a/_define.php +++ b/_define.php @@ -18,11 +18,11 @@ $this->registerModule( 'Tweak stores', 'Helper to manage external repositories', 'Jean-Christian Denis and Contributors', - '0.8', + '0.9', [ - 'requires' => [ + 'requires' => [ ['php', '8.1'], - ['core', '2.26'], + ['core', '2.27'], ], 'permissions' => null, 'type' => 'plugin', diff --git a/dcstore.xml b/dcstore.xml index b9813c6..d938306 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Tweak stores - 0.8 + 0.9 Jean-Christian Denis and Contributors Helper to manage external repositories - https://github.com/JcDenis/tweakStores/releases/download/v0.8/plugin-tweakStores.zip - 2.26 + https://github.com/JcDenis/tweakStores/releases/download/v0.9/plugin-tweakStores.zip + 2.27 https://plugins.dotaddict.org/dc2/details/tweakStores https://github.com/JcDenis/tweakStores diff --git a/src/Backend.php b/src/Backend.php index 3ae630a..19e4ca6 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,22 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\tweakStores; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index d9ab4d2..0be0d67 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -17,7 +17,10 @@ namespace Dotclear\Plugin\tweakStores; use dcCore; use dcModuleDefine; use dcModules; -use dcPage; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\File\Files; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -42,15 +45,27 @@ use Exception; class BackendBehaviors { - /** @var array List of notice messages */ + /** @var array List of notice messages */ private static $notice = []; - /** @var array List of failed messages */ + /** @var array List of failed messages */ private static $failed = []; + /** @var Settings Module settings */ + private static $settings; + + private static function settings(): Settings + { + if (!(self::$settings instanceof Settings)) { + self::$settings = new Settings(); + } + + return self::$settings; + } + public static function packmanBeforeCreatePackage(array $module): void { - if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get(My::id())->get('packman')) { + if (self::settings()->packman) { return; } @@ -58,64 +73,54 @@ class BackendBehaviors $modules = $module['type'] == 'theme' ? dcCore::app()->themes : dcCore::app()->plugins; $define = $modules->getDefine($module['id']); - self::writeXML($define, dcCore::app()->blog->settings->get(My::id())->get('file_pattern')); + self::writeXML($define, self::settings()->file_pattern); } public static function modulesToolsHeaders(bool $is_theme): string { - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { - return ''; - } - //save settings (before page header sent) if (!empty($_POST['tweakstore_save'])) { try { - $s = new Settings(); - foreach ($s->dump() as $key => $value) { - $s->set($key, $_POST['ts_' . $key] ?? $value); + foreach (self::settings()->dump() as $key => $value) { + self::settings()->set($key, $_POST['ts_' . $key] ?? $value); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Configuration successfully updated') ); - dcCore::app()->adminurl?->redirect($is_theme ? 'admin.blog.theme' : 'admin.plugins', ['tab' => My::id()]); + dcCore::app()->admin->url->redirect($is_theme ? 'admin.blog.theme' : 'admin.plugins', ['tab' => My::id()]); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } return - dcPage::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) . - dcPage::jsModuleLoad(My::id() . '/js/backend.js') . + Page::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) . + My::jsLoad('backend') . ( !dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? '' : - dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) . - dcPage::jsModuleLoad(My::id() . '/js/cms.js') + Page::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) . + My::jsLoad('cms') ); } public static function pluginsToolsTabsV2(): void { - self::modulesToolsTabs(dcCore::app()->plugins, (string) dcCore::app()->adminurl?->get('admin.plugins')); + self::modulesToolsTabs(dcCore::app()->plugins, (string) dcCore::app()->admin->url->get('admin.plugins')); } public static function themesToolsTabsV2(): void { - self::modulesToolsTabs(dcCore::app()->themes, (string) dcCore::app()->adminurl?->get('admin.blog.theme')); + self::modulesToolsTabs(dcCore::app()->themes, (string) dcCore::app()->admin->url->get('admin.blog.theme')); } private static function modulesToolsTabs(dcModules $modules, string $page_url): void { - if (is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { - return; - } - // settings - $s = new Settings(); $page_url .= '#' . My::id(); $user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); $user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); - $file_pattern = $s->file_pattern; + $file_pattern = self::settings()->file_pattern; $local_content = $distant_content = ''; // load module @@ -153,14 +158,14 @@ class BackendBehaviors } // generate local module xml content - $local_content = self::generateXML($module, $s->file_pattern); + $local_content = self::generateXML($module, self::settings()->file_pattern); // write dcstore.xml file if (!empty($_POST['tweakstore_write'])) { if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) { dcCore::app()->error->add(__('Password verification failed')); } else { - self::writeXML($module, $s->file_pattern); + self::writeXML($module, self::settings()->file_pattern); if (!empty(self::$failed)) { dcCore::app()->error->add(implode(' ', self::$failed)); } @@ -207,7 +212,7 @@ class BackendBehaviors '' . ( !$user_ui_colorsyntax ? '' : - dcPage::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme) + Page::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme) ) ) . ''; @@ -243,7 +248,7 @@ class BackendBehaviors '' . ( !$user_ui_colorsyntax ? '' : - dcPage::jsRunCodeMirror('editor', 'local_content', 'dotclear', $user_ui_colorsyntax_theme) + Page::jsRunCodeMirror('editor', 'local_content', 'dotclear', $user_ui_colorsyntax_theme) ); if ($module->get('root_writable') @@ -275,20 +280,20 @@ class BackendBehaviors // settings '
' . '

' . sprintf(__('%s configuration'), My::name()) . '

' . - (empty($s->file_pattern) ? '

' . __('You must configure zip file pattern to complete xml code automatically.') . '

' : '') . + (empty(self::settings()->file_pattern) ? '

' . __('You must configure zip file pattern to complete xml code automatically.') . '

' : '') . (new Div())->items([ // s_file_pattern (new Para())->items([ (new Label(__('Predictable URL to zip file on the external repository')))->for('ts_file_pattern'), - (new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value($s->file_pattern), + (new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value(self::settings()->file_pattern), ]), (new Note())->text(__('You can use widcard like %author%, %type%, %id%, %version%.'))->class('form-note'), (new Note())->text(__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'))->class('form-note'), (new Note())->text(__('Note: on github, you must create a release and join to it the module zip file.'))->class('form-note'), // s_packman (new Para())->items([ - (new Checkbox('ts_packman', $s->packman))->value(1), + (new Checkbox('ts_packman', self::settings()->packman))->value(1), (new Label(__('Enable packman behaviors'), Label::OUTSIDE_LABEL_AFTER))->for('ts_packman')->class('classic'), ]), (new Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'), diff --git a/src/My.php b/src/My.php index 10209f7..f0c6116 100644 --- a/src/My.php +++ b/src/My.php @@ -15,35 +15,15 @@ declare(strict_types=1); namespace Dotclear\Plugin\tweakStores; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { - /** - * This module id. - */ - public static function id(): string + public static function checkCustomContext(int $context): ?bool { - return basename(dirname(__DIR__)); - } - - /** - * This module name. - */ - public static function name(): string - { - $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name'); - - return __(is_string($name) ? $name : self::id()); - } - - /** - * This module path. - */ - public static function path(): string - { - return dirname(__DIR__); + return $context === My::BACKEND ? dcCore::app()->auth->isSuperAdmin() : null; } } diff --git a/src/Settings.php b/src/Settings.php index 8b2e128..9873002 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -14,9 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\tweakStores; -use dcCore; -use Exception; - class Settings { // Enable plugin pacKman behavior @@ -30,14 +27,8 @@ class Settings */ public function __construct() { - if (is_null(dcCore::app()->blog)) { - throw new Exception('blog is not set'); - } - - $s = dcCore::app()->blog->settings->get(My::id()); - - $this->packman = (bool) ($s->get('packman') ?? false); - $this->file_pattern = (string) ($s->get('file_pattern') ?? ''); + $this->packman = (bool) (My::settings()->get('packman') ?? false); + $this->file_pattern = (string) (My::settings()->get('file_pattern') ?? ''); } /** @@ -50,13 +41,9 @@ class Settings */ public function set(string $key, mixed $value): bool { - if (is_null(dcCore::app()->blog)) { - throw new Exception('blog is not set'); - } - if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { - dcCore::app()->blog->settings->get(My::id())->drop($key); - dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); + My::settings()->drop($key); + My::settings()->put($key, $value, gettype($this->{$key}), '', true, true); return true; } diff --git a/src/Uninstall.php b/src/Uninstall.php index 4b5f12d..4918d51 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\tweakStores; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Plugin\Uninstaller\Uninstaller; -class Uninstall extends dcNsProcess +class Uninstall extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN'); - - return static::$init; + return self::status(My::checkContext(My::UNINSTALL)); } public static function process(): bool { - if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { return false; }