From b13e0e78e1feca13cc532e312ade487b2cba784e Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 28 Jul 2023 23:14:07 +0200 Subject: [PATCH] release 1.2 --- CHANGELOG.md | 5 +++ README.md | 4 +-- _define.php | 4 +-- dcstore.xml | 6 ++-- src/Backend.php | 39 ++++++--------------- src/Manage.php | 89 +++++++++++++++++++++-------------------------- src/My.php | 31 +++-------------- src/Prepend.php | 12 +++---- src/Uninstall.php | 10 +++--- 9 files changed, 74 insertions(+), 126 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9146ddc..7fc23f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ dev - [ ] orphan media cleaner - [ ] move to plugin maintenance +1.2 - 2023.07.28 +- require dotclear 2.27 +- require php 8.1+ +- update to dotclear 2.27-dev + 1.1 - 2023.05.13 - require dotclear 2.26 - require php 8.1+ diff --git a/README.md b/README.md index 6803745..bfff75e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/dcAdvancedCleaner)](https://github.com/JcDenis/dcAdvancedCleaner/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/dcAdvancedCleaner)](https://github.com/JcDenis/dcAdvancedCleaner/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/dcAdvancedCleaner)](https://github.com/JcDenis/dcAdvancedCleaner/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/dcAdvancedCleaner) [![License](https://img.shields.io/github/license/JcDenis/dcAdvancedCleaner)](https://github.com/JcDenis/dcAdvancedCleaner/blob/master/LICENSE) @@ -20,7 +20,7 @@ settings, tables, cache, etc... _dcAdvancedCleaner_ requires: * Permissions superadmin - * Dotclear 2.26 + * Dotclear 2.27 * PHP >= 8.1 * Plugin Uninstaller diff --git a/_define.php b/_define.php index 1959e2f..3784951 100644 --- a/_define.php +++ b/_define.php @@ -18,11 +18,11 @@ $this->registerModule( 'Advanced cleaner', 'Make a huge cleaning of dotclear', 'Jean-Christian Denis and Contributors', - '1.1', + '1.2', [ 'requires' => [ ['php', '8.1'], - ['core', '2.26'], + ['core', '2.27'], ['Uninstaller', '0.8'], ], 'permissions' => null, diff --git a/dcstore.xml b/dcstore.xml index f28a63c..a46ebc9 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Advanced cleaner - 1.1 + 1.2 Jean-Christian Denis and Contributors Make a huge cleaning of dotclear - https://github.com/JcDenis/dcAdvancedCleaner/releases/download/v1.1/plugin-dcAdvancedCleaner.zip - 2.26 + https://github.com/JcDenis/dcAdvancedCleaner/releases/download/v1.2/plugin-dcAdvancedCleaner.zip + 2.27 https://plugins.dotaddict.org/dc2/details/dcAdvancedCleaner https://github.com/JcDenis/dcAdvancedCleaner diff --git a/src/Backend.php b/src/Backend.php index 07b89ee..13c4cbd 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,51 +14,32 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcAdvancedCleaner; -use dcAdmin; use dcCore; -use dcFavorites; -use dcNsProcess; -use dcMenu; -use dcPage; +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'); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { return false; } - if (!is_null(dcCore::app()->auth) - && !is_null(dcCore::app()->adminurl) - && (dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu) - ) { - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', - $_SERVER['REQUEST_URI'] - ), - dcCore::app()->auth->isSuperAdmin() - ); - } + My::addBackendMenuItem(); dcCore::app()->addBehaviors([ - 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { + 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), - 'large-icon' => dcPage::getPF(My::id() . '/icon-big.svg'), + 'url' => My::manageURL(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), //'permissions' => dcCore::app()->auth?->isSuperAdmin(), ]); }, diff --git a/src/Manage.php b/src/Manage.php index 1058fdc..2c10be2 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcAdvancedCleaner; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -32,19 +35,16 @@ use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Html; 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 || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { return false; } @@ -55,10 +55,10 @@ class Manage extends dcNsProcess } if (!empty($_POST['option-action'])) { - dcCore::app()->blog?->settings->get(My::id())->dropEvery( + My::settings()->dropEvery( 'dcproperty_hide' ); - dcCore::app()->blog?->settings->get(My::id())->put( + My::settings()->put( 'dcproperty_hide', !empty($_POST['dcproperty_hide']), 'boolean', @@ -66,11 +66,8 @@ class Manage extends dcNsProcess true, true ); - dcPage::addSuccessNotice(__('Configuration successfully updated.')); - dcCore::app()->adminurl?->redirect( - 'admin.plugin.' . My::id(), - ['part' => $vars->cleaner->id] - ); + Notices::addSuccessNotice(__('Configuration successfully updated.')); + My::redirect(['part' => $vars->cleaner->id]); } if (!empty($vars->entries) && !empty($vars->action)) { @@ -89,11 +86,8 @@ class Manage extends dcNsProcess } } - dcPage::addSuccessNotice(__('Action successfuly excecuted')); - dcCore::app()->adminurl?->redirect( - 'admin.plugin.' . My::id(), - ['part' => $vars->cleaner->id] - ); + Notices::addSuccessNotice(__('Action successfuly excecuted')); + My::redirect(['part' => $vars->cleaner->id]); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -104,17 +98,17 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } $vars = ManageVars::init(); - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsJson('dcAdvancedCleaner', ['confirm_delete' => __('Are you sure you perform these ations?')]) . - dcPage::cssModuleLoad(My::id() . '/css/backend.css') . - dcPage::jsModuleLoad(My::id() . '/js/backend.js') + Page::jsJson('dcAdvancedCleaner', ['confirm_delete' => __('Are you sure you perform these ations?')]) . + My::cssLoad('backend') . + My::jsLoad('backend') ); # --BEHAVIOR-- dcAdvancedCleanerAdminHeader @@ -128,34 +122,34 @@ class Manage extends dcNsProcess // something went wrong ! if (null === $vars->cleaner) { echo - dcPage::breadcrumb($breadcrumb) . - dcPage::notices(); + Page::breadcrumb($breadcrumb) . + Notices::getNotices(); echo (new Text('p', __('There is nothing to display')))->class('error')->render(); - dcPage::closeModule(); + Page::closeModule(); return; } - $breadcrumb[My::name()] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id()); + $breadcrumb[My::name()] = My::manageUrl(); $breadcrumb[$vars->cleaner->name] = ''; if (!empty($vars->related)) { - $breadcrumb[$vars->cleaner->name] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => $vars->cleaner->id]); + $breadcrumb[$vars->cleaner->name] = My::manageUrl(['part' => $vars->cleaner->id]); $breadcrumb[$vars->related] = ''; } echo - dcPage::breadcrumb($breadcrumb) . - dcPage::notices(); + Page::breadcrumb($breadcrumb) . + Notices::getNotices(); if (empty($vars->related)) { echo - (new Form('parts_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ + (new Form('parts_menu'))->method('get')->action(dcCore::app()->admin->getPageURL())->fields([ (new Para())->class('anchor-nav')->items([ (new Label(__('Goto:'), Label::OUTSIDE_LABEL_BEFORE))->for('part')->class('classic'), (new Select(['part', 'select_part']))->default($vars->cleaner->id)->items($vars->combo), (new Submit('go'))->value(__('Ok')), - (new Hidden(['p'], My::id())), + ... My::hiddenFields(), ]), ])->render() . @@ -178,7 +172,7 @@ class Manage extends dcNsProcess } echo - '
' . + '' . '
' . '' . '' . @@ -188,7 +182,7 @@ class Manage extends dcNsProcess foreach ($rs as $key => $value) { $distrib = in_array($value->ns, $vars->cleaner->distributed()); - if ($distrib && dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide')) { + if ($distrib && My::settings()->get('dcproperty_hide')) { continue; } echo @@ -206,7 +200,7 @@ class Manage extends dcNsProcess __('Values from official distribution') . '" />' : '') . '' . '' . ''; } @@ -217,9 +211,8 @@ class Manage extends dcNsProcess (new Label(__('Action on selected rows:'), Label::OUTSIDE_LABEL_BEFORE))->for('select_action'), (new Select(['action', 'select_action']))->items($combo_actions), (new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')), - (new Hidden(['p'], My::id())), (new Hidden(['part'], $vars->cleaner->id)), - dcCore::app()->formNonce(false), + ... My::hiddenFields(), ])->render() . '

' . __('Beware: All actions done here are irreversible and are directly applied') . @@ -228,18 +221,17 @@ class Manage extends dcNsProcess } echo - (new Form('option'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ + (new Form('option'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([ (new Para())->items([ - (new Submit('option-action'))->value(dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide') ? __('Show Dotclear default properties') : __('Hide Dotclear default properties')), - (new Hidden('dcproperty_hide', (string) (int) !dcCore::app()->blog->settings->get(My::id())->get('dcproperty_hide'))), - (new Hidden(['p'], My::id())), + (new Submit('option-action'))->value(My::settings()->get('dcproperty_hide') ? __('Show Dotclear default properties') : __('Hide Dotclear default properties')), + (new Hidden('dcproperty_hide', (string) (int) My::settings()->get('dcproperty_hide'))), (new Hidden(['part'], $vars->cleaner->id)), - dcCore::app()->formNonce(false), + ... My::hiddenFields(), ]), ])->render(); } else { echo - '

' . __('Back') . '

' . + '

' . __('Back') . '

' . '

' . $vars->cleaner->name . ' : ' . $vars->related . '

' . $vars->cleaner->desc . '

'; $distrib = in_array($vars->related, $vars->cleaner->distributed()); @@ -248,7 +240,7 @@ class Manage extends dcNsProcess echo (new Text('p', __('There is nothing to display')))->class('error')->render(); } else { echo - '' . + '' . '
' . '
' . sprintf(__('There are %s entries'), count($rs)) . '
' . __('Name') . '' . __('Objects') . '' . ($has_related ? ' ' . __('Details') . '' : '') . '
' . '' . @@ -271,11 +263,10 @@ class Manage extends dcNsProcess '
' . sprintf(__('There are %s related entries for the group "%s"'), count($rs), $vars->related) . '
' . __('Name') . '' . __('Objects') . '
' . (new Para())->items([ (new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')), - (new Hidden(['p'], My::id())), (new Hidden(['related'], $vars->related)), (new Hidden(['part'], $vars->cleaner->id)), (new Hidden(['action'], 'delete_related')), - dcCore::app()->formNonce(false), + ... My::hiddenFields(), ])->render() . '

' . __('Beware: All actions done here are irreversible and are directly applied') . @@ -284,6 +275,6 @@ class Manage extends dcNsProcess } } - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/My.php b/src/My.php index 2bff745..d873eef 100644 --- a/src/My.php +++ b/src/My.php @@ -15,35 +15,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcAdvancedCleaner; 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 === self::PREPEND ? dcCore::app()->auth->isSuperAdmin() : null; } } diff --git a/src/Prepend.php b/src/Prepend.php index 80441af..769f1ba 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -14,8 +14,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcAdvancedCleaner; -use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Plugin\activityReport\{ Action, ActivityReport, @@ -23,19 +22,16 @@ use Dotclear\Plugin\activityReport\{ }; use Dotclear\Plugin\Uninstaller\Uninstaller; -class Prepend extends dcNsProcess +class Prepend 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::PREPEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/Uninstall.php b/src/Uninstall.php index 9d9f7e1..f3b1104 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcAdvancedCleaner; 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; }