From 0a6db67262dda15e7cb0695380154b49e0c2eed1 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 13 Aug 2023 21:46:39 +0200 Subject: [PATCH] upgrade to Dotclear 2.27 --- src/Backend.php | 29 +++++------------------------ src/Manage.php | 40 +++++++++++++++++----------------------- src/My.php | 28 ++++------------------------ 3 files changed, 26 insertions(+), 71 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index e8fb6ce..c01cb2e 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,41 +14,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\testMail; -/* dotclear ns */ -use dcAdmin; -use dcCore; -use dcNsProcess; -use dcPage; +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; } - // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { - return false; - } - - 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(); return true; } diff --git a/src/Manage.php b/src/Manage.php index b95cb21..1a063a1 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\testMail; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -32,25 +35,16 @@ use Dotclear\Helper\Network\Mail\Mail; use Dotclear\Helper\Text; use Exception; -class Manage extends dcNsProcess +class Manage 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::MANAGE)); } public static function process(): bool { - if (!static::$init) { - return false; - } - - // nullsafe - if (is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return false; } @@ -76,8 +70,8 @@ class Manage extends dcNsProcess } else { Mail::sendMail($mail_to, $mail_subject, $mail_content); } - dcPage::addSuccessNotice(__('Mail successuffly sent.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Mail successuffly sent.')); + My::redirect(); return true; } catch (Exception $e) { @@ -90,24 +84,24 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } - dcpage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('System') => '', My::name() => '', ]) . - dcPage::notices() . + Notices::GetNotices() . (new Div('mail_testor')) ->__call('items', [[ (new Form('mail_form')) ->__call('method', ['post']) - ->__call('action', [dcCore::app()->admin->getPageURL()]) + ->__call('action', [My::manageUrl()]) ->__call('fields', [[ (new Para()) ->__call('items', [[ @@ -151,13 +145,13 @@ class Manage extends dcNsProcess (new Submit('save')) ->__call('accesskey', ['s']) ->__call('value', [__('Send')]), - dcCore::app()->formNonce(false), + ... My::hiddenFields(), ]]), ]]), ]]) ->render(); - dcPage::closeModule(); + Page::closeModule(); } private static function getHeaders(): array diff --git a/src/My.php b/src/My.php index 39d871e..c7d92c1 100644 --- a/src/My.php +++ b/src/My.php @@ -15,38 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\testMail; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string Mailer name */ public const X_MAILER = 'Dotclear'; - /** - * This module id. - */ - public static function id(): string + public static function checkXustomContext(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 defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->isSuperAdmin(); } }