From 83fa868c91f3f4666a00c3924178739d43dcfc14 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 11 Mar 2023 17:00:15 +0100 Subject: [PATCH] preview for Dotclear 2.26 --- CHANGELOG.md | 6 ++ README.md | 4 +- _admin.php | 18 ----- _define.php | 5 +- _prepend.php | 22 ------ dcstore.xml | 2 +- index.php | 19 ----- locales/fr/main.lang.php | 2 +- locales/fr/main.po | 6 +- src/Backend.php | 18 +++-- src/Manage.php | 149 +++++++++++++++++++-------------------- src/My.php | 38 ++++++++++ src/Prepend.php | 49 ------------- 13 files changed, 131 insertions(+), 207 deletions(-) delete mode 100644 _admin.php delete mode 100644 _prepend.php delete mode 100644 index.php create mode 100644 src/My.php delete mode 100644 src/Prepend.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d51ffb5..2a86f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +0.4 - 2023.03.11 +* update to Dotclear 2.26 +* use abstract plugin id and name +* use dcPage open/close methods +* use new Form helpers + 0.3.1 - 2023.01.07 - fix previously introduced unix bug diff --git a/README.md b/README.md index f576960..17e64c8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/testMail)](https://github.com/JcDenis/testMail/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/testMail)](https://github.com/JcDenis/testMail/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/testMail)](https://github.com/JcDenis/testMail/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/testMail) [![License](https://img.shields.io/github/license/JcDenis/testMail)](https://github.com/JcDenis/testMail/blob/master/LICENSE) @@ -19,7 +19,7 @@ It helps dev to test dotclear mail system. **testMail** requires: * super admin permission - * Dotclear 2.24 + * Dotclear 2.26 ## USAGE diff --git a/_admin.php b/_admin.php deleted file mode 100644 index 4cbd1de..0000000 --- a/_admin.php +++ /dev/null @@ -1,18 +0,0 @@ -registerModule( 'Osku and contributors', '0.3.1', [ - 'requires' => [['core', '2.24']], + 'requires' => [['core', '2.26']], 'permissions' => null, 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/' . basename(__DIR__), diff --git a/_prepend.php b/_prepend.php deleted file mode 100644 index f500181..0000000 --- a/_prepend.php +++ /dev/null @@ -1,22 +0,0 @@ -Osku and contributors Send a simple mail from admin https://github.com/JcDenis/testMail/releases/download/v0.3.1/plugin-testMail.zip - 2.24 + 2.26 https://plugins.dotaddict.org/dc2/details/testMail https://github.com/JcDenis/testMail diff --git a/index.php b/index.php deleted file mode 100644 index 8ccdc0e..0000000 --- a/index.php +++ /dev/null @@ -1,19 +0,0 @@ -menu[dcAdmin::MENU_PLUGINS]->addItem( - dcCore::app()->plugins->moduleInfo(self::$pid, 'name'), - dcCore::app()->adminurl->get('admin.plugin.' . self::$pid), - dcPage::getPF(self::$pid . '/icon.svg'), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . self::$pid)) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + 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() ); diff --git a/src/Manage.php b/src/Manage.php index 662c5c2..d069f0d 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,82 +14,66 @@ declare(strict_types=1); namespace Dotclear\Plugin\testMail; -/* dotclear ns */ -use dcAdminNotices; use dcCore; +use dcNsProcess; use dcPage; - -/* clearbricks ns */ -use form; -use html; +use Dotclear\Helper\Html\Form\{ + Checkbox, + Div, + Form, + Input, + Label, + Para, + Submit, + Textarea +}; +use Exception; use http; use mail; use text; -/* php */ -use Exception; - -class Manage +class Manage extends dcNsProcess { - private static $active_headers = false; - private static $mail_to = ''; - private static $mail_subject = ''; - private static $mail_content = ''; - private static $pid = ''; - protected static $init = false; - public static function init(): bool { if (defined('DC_CONTEXT_ADMIN')) { dcPage::checkSuper(); - - self::$pid = basename(dirname(__DIR__)); self::$init = true; } return self::$init; } - public static function process(): ?bool + public static function process(): bool { if (!self::$init) { return false; } - $headers = [ - 'From: ' . mail::B64Header(dcCore::app()->blog->name) . - '', - 'Content-Type: text/HTML; charset=UTF-8;' . - 'X-Originating-IP: ' . http::realIP(), - 'X-Mailer: Dotclear', - 'X-Blog-Id: ' . mail::B64Header(dcCore::app()->blog->id), - 'X-Blog-Name: ' . mail::B64Header(dcCore::app()->blog->name), - 'X-Blog-Url: ' . mail::B64Header(dcCore::app()->blog->url), - ]; - self::$active_headers = !empty($_POST['active_headers']); - self::$mail_to = $_POST['mail_to'] ?? ''; - self::$mail_subject = $_POST['mail_subject'] ?? ''; - self::$mail_content = $_POST['mail_content'] ?? ''; + $active_headers = !empty($_POST['active_headers']); + $mail_to = $_POST['mail_to'] ?? ''; + $mail_subject = $_POST['mail_subject'] ?? ''; + $mail_content = $_POST['mail_content'] ?? ''; - if (!empty(self::$mail_content) || !empty(self::$mail_to)) { + if (!empty($mail_content) || !empty($mail_to)) { try { - if (!text::isEmail(self::$mail_to)) { + if (!text::isEmail($mail_to)) { throw new Exception(__('You must provide a valid email address.')); } - if (self::$mail_content == '') { + if ($mail_content == '') { throw new Exception(__('You must provide a content.')); } - $mail_subject = mail::B64Header(self::$mail_subject); + $mail_subject = mail::B64Header($mail_subject); - if (self::$active_headers) { - mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content, $headers); + if ($active_headers) { + mail::sendMail($mail_to, $mail_subject, $mail_content, self::getHeaders()); } else { - mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content); + mail::sendMail($mail_to, $mail_subject, $mail_content); } - dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid); + dcPage::addSuccessNotice(__('Mail successuffly sent.')); + dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); return true; } catch (Exception $e) { @@ -97,50 +81,59 @@ class Manage } } - return null; + return true; } public static function render(): void { + dcpage::openModule(My::name()); + echo - '' . - dcCore::app()->plugins->moduleInfo(self::$pid, 'name') . - '' . - dcPage::breadcrumb([ - __('System') => '', - dcCore::app()->plugins->moduleInfo(self::$pid, 'name') => '', + __('System') => '', + My::name() => '', ]) . - dcPage::notices() . ' + dcPage::notices() . -
-
+ (new Div('mail_testor'))->items([ + (new Form('mail_form'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([ + (new Para())->items([ + (new Label(__('Mailto:')))->for('mail_to'), + (new Input('mail_to'))->class('maximal')->size(30)->maxlenght(255)->value(''), + ]), + (new Para())->items([ + (new Label(__('Subject:')))->for('mail_subject'), + (new Input('mail_subject'))->class('maximal')->size(30)->maxlenght(255)->value(''), + ]), + (new Para())->items([ + (new Label(__('Content:')))->for('mail_content'), + (new Textarea('mail_content', ''))->class('maximal')->cols(50)->rows(7), + ]), + (new Para())->items([ + (new Checkbox('active_headers', false))->value(1), + (new Label(__('Active mail headers')))->for('active_headers')->class('classic'), + ]), + (new Para())->items([ + (new Submit('save'))->accesskey('s')->value(__('Send')), + dcCore::app()->formNonce(false), + ]), + ]), + ])->render(); -

+ dcPage::closeModule(); + } -

- -

' . __('Content:') . '

-

' . - form::textarea('mail_content', 50, 7, html::escapeHTML(self::$mail_content)) . ' -

- -

- -

' . - ' ' . - - dcCore::app()->formNonce() . '

' . - '
-
- - '; + private static function getHeaders(): array + { + return [ + 'From: ' . mail::B64Header(dcCore::app()->blog->name) . + '', + 'Content-Type: text/HTML; charset=UTF-8;' . + 'X-Originating-IP: ' . http::realIP(), + 'X-Mailer: ' . My::X_MAILER, + 'X-Blog-Id: ' . mail::B64Header(dcCore::app()->blog->id), + 'X-Blog-Name: ' . mail::B64Header(dcCore::app()->blog->name), + 'X-Blog-Url: ' . mail::B64Header(dcCore::app()->blog->url), + ]; } } diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..f59d6c0 --- /dev/null +++ b/src/My.php @@ -0,0 +1,38 @@ +plugins->moduleInfo(self::id(), 'name')); + } +} diff --git a/src/Prepend.php b/src/Prepend.php deleted file mode 100644 index 9621049..0000000 --- a/src/Prepend.php +++ /dev/null @@ -1,49 +0,0 @@ -autoload([ - __NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php', - ]); - } - - return true; - } -}