diff --git a/CHANGELOG.md b/CHANGELOG.md index a4fccc6..ba2b868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2023.07.29 +- require Dotclear 2.27 +- require php 8.1+ +- update to Dotclear 2.27-dev + 2023.05.29 - require dotclear 2.26 - require php 8.1+ diff --git a/README.md b/README.md index 3bc3d97..b023745 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/pacKman)](https://github.com/JcDenis/pacKman/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/pacKman)](https://github.com/JcDenis/pacKman/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/pacKman)](https://github.com/JcDenis/pacKman/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/pacKman) [![License](https://img.shields.io/github/license/JcDenis/pacKman)](https://github.com/JcDenis/pacKman/blob/master/LICENSE) @@ -20,7 +20,7 @@ themes and plugins from Dotclear administration pages. pacKman requires: * Super administrator permissions - * Dotclear 2.26 + * Dotclear 2.27 * PHP 8.1+ * A writable cache directory * A writable directory to put packages. (can be VAR dir) diff --git a/_define.php b/_define.php index 6015d71..db8cd5e 100644 --- a/_define.php +++ b/_define.php @@ -20,11 +20,11 @@ $this->registerModule( 'Packages repository', 'Manage your Dotclear packages', 'Jean-Christian Denis', - '2023.05.29', + '2023.07.29', [ 'requires' => [ ['php', '8.1'], - ['core', '2.26'], + ['core', '2.27'], ], 'permissions' => null, 'type' => 'plugin', diff --git a/dcstore.xml b/dcstore.xml index 31beb41..a0f428a 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Packages repository - 2023.05.29 + 2023.07.29 Jean-Christian Denis Manage your Dotclear packages - https://github.com/JcDenis/pacKman/releases/download/v2023.05.29/plugin-pacKman.zip - 2.26 + https://github.com/JcDenis/pacKman/releases/download/v2023.07.29/plugin-pacKman.zip + 2.27 https://plugins.dotaddict.org/dc2/details/pacKman https://github.com/JcDenis/pacKman diff --git a/src/Backend.php b/src/Backend.php index 2dcf16d..90561ff 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,46 +14,35 @@ declare(strict_types=1); namespace Dotclear\Plugin\pacKman; -use dcAdmin; use dcCore; -use dcFavorites; -use dcPage; -use dcNsProcess; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\Favorites; -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init == defined('DC_CONTEXT_ADMIN') - && 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; } - dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { + My::addBackendMenuItem(); + + dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), [], '#packman-repository-repository'), - 'small-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], - 'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), //'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); }); - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '#packman-repository-repository', - [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], - preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth?->isSuperAdmin() - ); - return true; } } diff --git a/src/Config.php b/src/Config.php index 56c156a..2fb7f51 100644 --- a/src/Config.php +++ b/src/Config.php @@ -15,8 +15,8 @@ declare(strict_types=1); namespace Dotclear\Plugin\pacKman; use dcCore; -use dcPage; -use dcNsProcess; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\Notices; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -30,19 +30,16 @@ use Dotclear\Helper\Html\Form\{ }; use Exception; -class Config extends dcNsProcess +class Config extends Process { public static function init(): bool { - static::$init == defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth?->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::CONFIG)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -62,10 +59,10 @@ class Config extends dcNsProcess } } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Configuration has been successfully updated.') ); - dcCore::app()->adminurl?->redirect('admin.plugins', [ + dcCore::app()->admin->url->redirect('admin.plugins', [ 'module' => My::id(), 'conf' => '1', 'redir' => dcCore::app()->admin->__get('list')->getRedir(), @@ -79,7 +76,7 @@ class Config extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } diff --git a/src/Install.php b/src/Install.php index 68ea6a5..f7c2d75 100644 --- a/src/Install.php +++ b/src/Install.php @@ -16,22 +16,19 @@ namespace Dotclear\Plugin\pacKman; use dcCore; use dcNamespace; -use dcNsProcess; +use Dotclear\Core\Process; use Exception; -class Install extends dcNsProcess +class Install extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - - return static::$init; + return self::status(My::checkContext(My::INSTALL)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/Manage.php b/src/Manage.php index d5cfad2..2d2f529 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -16,9 +16,12 @@ namespace Dotclear\Plugin\pacKman; /* dotclear ns */ use dcCore; -use dcPage; use dcThemes; -use dcNsProcess; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\File\Files; use Dotclear\Helper\Html\Form\{ Div, @@ -27,19 +30,16 @@ use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Network\Http; use Exception; -class Manage extends dcNsProcess +class Manage extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth?->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::MANAGE)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -104,14 +104,14 @@ class Manage extends dcNsProcess Http::head(404, 'Not Found'); exit; } elseif (!empty($action) && !$is_editable) { - dcPage::addErrorNotice( + Notices::addErrorNotice( __('No modules selected.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type); + My::redirect([], '#packman-' . $type); } # Pack @@ -140,14 +140,14 @@ class Manage extends dcNsProcess dcCore::app()->callBehavior('packmanAfterCreatePackage', $module->dump()); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Package successfully created.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type); + My::redirect([], '#packman-' . $type); } # Delete @@ -155,7 +155,7 @@ class Manage extends dcNsProcess $del_success = false; foreach ($_POST['modules'] as $root => $id) { if (!file_exists($root) || !Files::isDeletable($root)) { - dcPage::addWarningNotice(sprintf(__('Undeletable file "%s"', $root))); + Notices::addWarningNotice(sprintf(__('Undeletable file "%s"', $root))); } else { $del_success = true; } @@ -164,7 +164,7 @@ class Manage extends dcNsProcess } if ($del_success) { - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Package successfully deleted.') ); } @@ -172,7 +172,7 @@ class Manage extends dcNsProcess if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); + My::redirect([], '#packman-repository-' . $type); } # Install @@ -192,14 +192,14 @@ class Manage extends dcNsProcess dcCore::app()->callBehavior('packmanAfterInstallPackage', $type, $id, $root); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Package successfully installed.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); + My::redirect([], '#packman-repository-' . $type); } # Copy @@ -218,14 +218,14 @@ class Manage extends dcNsProcess ); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Package successfully copied.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); + My::redirect([], '#packman-repository-' . $type); } # Move @@ -245,14 +245,14 @@ class Manage extends dcNsProcess unlink($root); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Package successfully moved.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); + My::redirect([], '#packman-repository-' . $type); } } } catch (Exception $e) { @@ -264,7 +264,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } @@ -295,21 +295,21 @@ class Manage extends dcNsProcess } # Display - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsPageTabs() . - dcPage::jsModuleLoad(My::id() . '/js/backend.js') . + Page::jsPageTabs() . + My::jsLoad('backend') . # --BEHAVIOR-- packmanAdminHeader dcCore::app()->callBehavior('packmanAdminHeader') ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', ]) . - dcPage::notices(); + Notices::GetNotices(); if (dcCore::app()->error->flag() || !$is_configured || !$is_plugins_configured || !$is_themes_configured) { echo @@ -377,7 +377,7 @@ class Manage extends dcNsProcess # --BEHAVIOR-- packmanAdminTabs dcCore::app()->callBehavior('packmanAdminTabs'); - dcPage::helpBlock('pacKman'); - dcPage::closeModule(); + Page::helpBlock('pacKman'); + Page::closeModule(); } } diff --git a/src/My.php b/src/My.php index 7cf1013..cbf14ea 100644 --- a/src/My.php +++ b/src/My.php @@ -15,11 +15,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\pacKman; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var array Excluded files */ public const EXCLUDED_FILES = [ @@ -35,29 +36,8 @@ class My '_disabled', ]; - /** - * 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 dcCore::app()->auth->isSuperAdmin(); } } diff --git a/src/Settings.php b/src/Settings.php index 5d1808d..f90b61a 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\pacKman; -use dcCore; - class Settings { // Remove comments from files @@ -50,7 +48,7 @@ class Settings */ public function __construct() { - $s = dcCore::app()->blog?->settings->get(My::id()); + $s = My::settings(); $this->pack_nocomment = (bool) ($s?->get('pack_nocomment') ?? false); $this->pack_fixnewline = (bool) ($s?->get('pack_fixnewline') ?? false); @@ -79,8 +77,8 @@ class Settings public function writeSetting(string $key, mixed $value): bool { 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 69b8ba0..6c28a10 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\pacKman; 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; } diff --git a/src/Utils.php b/src/Utils.php index bc2cc3e..1a9153e 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -140,7 +140,7 @@ class Utils (new Text('h3', $title)), (new Form('packman-form-' . $type)) ->method('post') - ->action('plugin.php') + ->action(My::manageUrl()) ->fields([ (new Para(null, 'table')) ->class('clear') @@ -163,13 +163,13 @@ class Utils ->class('checkboxes-helpers'), (new Para()) ->items([ - (new Hidden(['redir'], Html::escapeHTML($_REQUEST['redir'] ?? ''))), - (new Hidden(['p'], My::id())), - (new Hidden(['type'], $type)), - (new Hidden(['action'], 'packup')), (new Submit(['packup'])) ->value(__('Pack up selected modules')), - dcCore::app()->formNonce(false), + ... My::hiddenFields([ + 'type' => $type, + 'action' => 'packup', + 'redir' => Html::escapeHTML($_REQUEST['redir'] ?? ''), + ]), ]), ]), ]) @@ -279,7 +279,7 @@ class Utils (new Text('h3', $title)), (new Form('packman-form-repository-' . $type)) ->method('post') - ->action('plugin.php') + ->action(My::manageUrl()) ->fields([ (new Para(null, 'table')) ->class('clear') @@ -311,10 +311,10 @@ class Utils ->items($combo_action), (new Submit(['packup'])) ->value(__('ok')), - (new Hidden(['p'], My::id())), - (new Hidden(['tab'], 'repository')), - (new Hidden(['type'], $type)), - dcCore::app()->formNonce(false), + ... My::hiddenFields([ + 'tab' => 'repository', + 'type' => $type, + ]), ]), ]), ])