preview for Dotclear 2.26

This commit is contained in:
Jean-Christian Denis 2023-03-11 17:00:15 +01:00
parent 07335f420e
commit 83fa868c91
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
13 changed files with 131 additions and 207 deletions

View file

@ -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 0.3.1 - 2023.01.07
- fix previously introduced unix bug - fix previously introduced unix bug

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/testMail)](https://github.com/JcDenis/testMail/releases) [![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) [![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) [![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) [![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) [![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: **testMail** requires:
* super admin permission * super admin permission
* Dotclear 2.24 * Dotclear 2.26
## USAGE ## USAGE

View file

@ -1,18 +0,0 @@
<?php
/**
* @brief testMail, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
$admin = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Admin']);
if ($admin::init()) {
$admin::process();
}

View file

@ -12,9 +12,6 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
// can not use namespace as it is included inside a class method,
// and also can be included in third party plugins class methods.
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -25,7 +22,7 @@ $this->registerModule(
'Osku and contributors', 'Osku and contributors',
'0.3.1', '0.3.1',
[ [
'requires' => [['core', '2.24']], 'requires' => [['core', '2.26']],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__), 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),

View file

@ -1,22 +0,0 @@
<?php
/**
* @brief testMail, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
$prepend = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Prepend']);
if (!class_exists($prepend)) {
require __DIR__ . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Prepend.php';
if ($prepend::init()) {
$prepend::process();
}
}

View file

@ -6,7 +6,7 @@
<author>Osku and contributors</author> <author>Osku and contributors</author>
<desc>Send a simple mail from admin</desc> <desc>Send a simple mail from admin</desc>
<file>https://github.com/JcDenis/testMail/releases/download/v0.3.1/plugin-testMail.zip</file> <file>https://github.com/JcDenis/testMail/releases/download/v0.3.1/plugin-testMail.zip</file>
<da:dcmin>2.24</da:dcmin> <da:dcmin>2.26</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/testMail</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/testMail</da:details>
<da:support>https://github.com/JcDenis/testMail</da:support> <da:support>https://github.com/JcDenis/testMail</da:support>
</module> </module>

View file

@ -1,19 +0,0 @@
<?php
/**
* @brief testMail, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
$manage = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Manage']);
if ($manage::init()) {
$manage::process();
$manage::render();
}

View file

@ -14,5 +14,5 @@ l10n::$locales['Mail successuffly sent.'] = 'Mail envoyer avec succès.';
l10n::$locales['Mailto:'] = 'Envoyer à :'; l10n::$locales['Mailto:'] = 'Envoyer à :';
l10n::$locales['Subject:'] = 'Sujet :'; l10n::$locales['Subject:'] = 'Sujet :';
l10n::$locales['Active mail headers'] = 'Activer les entêtes de mail'; l10n::$locales['Active mail headers'] = 'Activer les entêtes de mail';
l10n::$locales['Mail test'] = 'Mail test'; l10n::$locales['Mail test'] = 'Testeur de mail';
l10n::$locales['Send a simple mail from admin'] = 'Envoyer un simple mail depuis l\'admin'; l10n::$locales['Send a simple mail from admin'] = 'Envoyer un simple mail depuis l\'admin';

View file

@ -1,9 +1,9 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: testMail 0.2.1\n" "Project-Id-Version: testMail 0.3.1\n"
"POT-Creation-Date: \n" "POT-Creation-Date: \n"
"PO-Revision-Date: 2023-01-05T23:44:36+00:00\n" "PO-Revision-Date: 2023-03-11T15:55:03+00:00\n"
"Last-Translator: Jean-Christian Denis\n" "Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -26,7 +26,7 @@ msgid "Active mail headers"
msgstr "Activer les entêtes de mail" msgstr "Activer les entêtes de mail"
msgid "Mail test" msgid "Mail test"
msgstr "Mail test" msgstr "Testeur de mail"
msgid "Send a simple mail from admin" msgid "Send a simple mail from admin"
msgstr "Envoyer un simple mail depuis l'admin" msgstr "Envoyer un simple mail depuis l'admin"

View file

@ -17,34 +17,32 @@ namespace Dotclear\Plugin\testMail;
/* dotclear ns */ /* dotclear ns */
use dcAdmin; use dcAdmin;
use dcCore; use dcCore;
use dcNsProcess;
use dcPage; use dcPage;
class Admin class Backend extends dcNsProcess
{ {
private static $pid = '';
protected static $init = false;
public static function init(): bool public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) { if (defined('DC_CONTEXT_ADMIN')) {
self::$pid = basename(dirname(__DIR__)); dcPage::checkSuper();
self::$init = true; self::$init = true;
} }
return self::$init; return self::$init;
} }
public static function process(): ?bool public static function process(): bool
{ {
if (!self::$init) { if (!self::$init) {
return false; return false;
} }
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
dcCore::app()->plugins->moduleInfo(self::$pid, 'name'), My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . self::$pid), dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(self::$pid . '/icon.svg'), dcPage::getPF(My::id() . '/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . self::$pid)) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );

View file

@ -14,82 +14,66 @@ declare(strict_types=1);
namespace Dotclear\Plugin\testMail; namespace Dotclear\Plugin\testMail;
/* dotclear ns */
use dcAdminNotices;
use dcCore; use dcCore;
use dcNsProcess;
use dcPage; use dcPage;
use Dotclear\Helper\Html\Form\{
/* clearbricks ns */ Checkbox,
use form; Div,
use html; Form,
Input,
Label,
Para,
Submit,
Textarea
};
use Exception;
use http; use http;
use mail; use mail;
use text; use text;
/* php */ class Manage extends dcNsProcess
use Exception;
class Manage
{ {
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 public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) { if (defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper(); dcPage::checkSuper();
self::$pid = basename(dirname(__DIR__));
self::$init = true; self::$init = true;
} }
return self::$init; return self::$init;
} }
public static function process(): ?bool public static function process(): bool
{ {
if (!self::$init) { if (!self::$init) {
return false; return false;
} }
$headers = [
'From: ' . mail::B64Header(dcCore::app()->blog->name) .
'<no-reply@' . str_replace('http://', '', http::getHost()) . ' >',
'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']); $active_headers = !empty($_POST['active_headers']);
self::$mail_to = $_POST['mail_to'] ?? ''; $mail_to = $_POST['mail_to'] ?? '';
self::$mail_subject = $_POST['mail_subject'] ?? ''; $mail_subject = $_POST['mail_subject'] ?? '';
self::$mail_content = $_POST['mail_content'] ?? ''; $mail_content = $_POST['mail_content'] ?? '';
if (!empty(self::$mail_content) || !empty(self::$mail_to)) { if (!empty($mail_content) || !empty($mail_to)) {
try { try {
if (!text::isEmail(self::$mail_to)) { if (!text::isEmail($mail_to)) {
throw new Exception(__('You must provide a valid email address.')); 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.')); 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) { if ($active_headers) {
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content, $headers); mail::sendMail($mail_to, $mail_subject, $mail_content, self::getHeaders());
} else { } else {
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content); mail::sendMail($mail_to, $mail_subject, $mail_content);
} }
dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.')); dcPage::addSuccessNotice(__('Mail successuffly sent.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
@ -97,50 +81,59 @@ class Manage
} }
} }
return null; return true;
} }
public static function render(): void public static function render(): void
{ {
echo dcpage::openModule(My::name());
'<html><head><title>' .
dcCore::app()->plugins->moduleInfo(self::$pid, 'name') .
'</title></head><body>' .
echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('System') => '', __('System') => '',
dcCore::app()->plugins->moduleInfo(self::$pid, 'name') => '', My::name() => '',
]) . ]) .
dcPage::notices() . ' dcPage::notices() .
<div id="mail_testor"> (new Div('mail_testor'))->items([
<form method="post" action="' . dcCore::app()->admin->getPageURL() . '"> (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();
<p><label for="mail_to">' . __('Mailto:') . ' ' . dcPage::closeModule();
form::field('mail_to', 30, 255, self::$mail_to, 'maximal') . }
'</label></p>
<p><label for="mail_subject">' . __('Subject:') . ' ' . private static function getHeaders(): array
form::field('mail_subject', 30, 255, self::$mail_subject, 'maximal') . {
'</label></p> return [
'From: ' . mail::B64Header(dcCore::app()->blog->name) .
<p>' . __('Content:') . '</p> '<no-reply@' . str_replace('http://', '', http::getHost()) . ' >',
<p class="area">' . 'Content-Type: text/HTML; charset=UTF-8;' .
form::textarea('mail_content', 50, 7, html::escapeHTML(self::$mail_content)) . ' 'X-Originating-IP: ' . http::realIP(),
</p> 'X-Mailer: ' . My::X_MAILER,
'X-Blog-Id: ' . mail::B64Header(dcCore::app()->blog->id),
<p><label class="classic" for="active_headers">' . 'X-Blog-Name: ' . mail::B64Header(dcCore::app()->blog->name),
form::checkbox('active_headers', 1, self::$active_headers) . ' ' . 'X-Blog-Url: ' . mail::B64Header(dcCore::app()->blog->url),
__('Active mail headers') . ];
'</label></p>
<p class="border-top">' .
'<input type="submit" value="' . __('Save') . ' (s)" accesskey="s" name="save" /> ' .
dcCore::app()->formNonce() . '</p>' .
'</form>
</div>
</body></html>';
} }
} }

38
src/My.php Normal file
View file

@ -0,0 +1,38 @@
<?php
/**
* @brief testMail, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\testMail;
use dcCore;
class My
{
public const X_MAILER = 'Dotclear';
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View file

@ -1,49 +0,0 @@
<?php
/**
* @brief testMail, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\testMail;
/* clearbricks ns */
use Clearbricks;
class Prepend
{
private const LIBS = [
'Admin',
'Manage',
];
protected static $init = false;
public static function init(): bool
{
self::$init = defined('DC_RC_PATH');
return self::$init;
}
public static function process(): ?bool
{
if (!self::$init) {
return false;
}
foreach (self::LIBS as $lib) {
Clearbricks::lib()->autoload([
__NAMESPACE__ . '\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php',
]);
}
return true;
}
}