NS playground: fill structure

This commit is contained in:
Jean-Christian Paul Denis 2023-01-06 00:33:13 +01:00
parent 7a7f9f4bc3
commit 0e80faf4fa
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 215 additions and 89 deletions

7
_admin.php Normal file
View File

@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
$admin = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Admin']);
if ($admin::init()) {
$admin::process();
}

11
_prepend.php Normal file
View File

@ -0,0 +1,11 @@
<?php
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

@ -1,22 +1,42 @@
<?php <?php
/** declare(strict_types=1);
* @brief testMail, a plugin for Dotclear 2
* namespace Dotclear\Plugin\testMail;
* @package Dotclear
* @subpackage Plugin /* dotclear ns */
* use dcAdmin;
* @author Osku and contributors use dcCore;
* use dcPage;
* @copyright Jean-Crhistian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html class Admin
*/ {
if (!defined('DC_CONTEXT_ADMIN')) { private static $name = '';
return null; protected static $init = false;
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
self::$name = __('Mail test');
self::$init = true;
}
return self::$init;
}
public static function process(): ?bool
{
if (!self::$init) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem(
self::$name,
dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__)),
dcPage::getPF(basename(__NAMESPACE__) . '/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__NAMESPACE__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);
return true;
}
} }
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem(
__('Mail test'),
dcCore::app()->adminurl->get('admin.plugin.testMail'),
dcPage::getPF('testMail/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.testMail')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);

View File

@ -10,82 +10,124 @@
* @copyright Jean-Crhistian Denis * @copyright Jean-Crhistian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
}
dcPage::checkSuper(); namespace Dotclear\Plugin\testMail;
$headers = [ /* dotclear ns */
'From: ' . mail::B64Header(dcCore::app()->blog->name) . use dcAdminNotices;
'<no-reply@' . str_replace('http://', '', http::getHost()) . ' >', use dcCore;
'Content-Type: text/HTML; charset=UTF-8;' . use dcPage;
'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),
];
$active_headers = !empty($_POST['active_headers']); /* clearbricks ns */
$mail_to = $_POST['mail_to'] ?? ''; use form;
$mail_subject = $_POST['mail_subject'] ?? ''; use html;
$mail_content = $_POST['mail_content'] ?? ''; use http;
use mail;
use text;
if (!empty($mail_content) || !empty($mail_to)) { class Manage
try { {
if (!text::isEmail($mail_to)) { private static $active_headers = false;
throw new Exception(__('You must provide a valid email address.')); private static $mail_to = '';
private static $mail_subject = '';
private static $mail_content = '';
protected static $init = false;
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper();
self::$init = true;
} }
if ($mail_content == '') { return self::$init;
throw new Exception(__('You must provide a content.')); }
}
$mail_subject = mail::B64Header($mail_subject); public static function process(): ?bool
{
if ($active_headers) { if (!self::$init) {
mail::sendMail($mail_to, $mail_subject, $mail_content, $headers); return false;
} else {
mail::sendMail($mail_to, $mail_subject, $mail_content);
} }
dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.')); $headers = [
dcCore::app()->adminurl->redirect('admin.plugin.testMail'); 'From: ' . mail::B64Header(dcCore::app()->blog->name) .
} catch (Exception $e) { '<no-reply@' . str_replace('http://', '', http::getHost()) . ' >',
dcCore::app()->error->add($e->getMessage()); '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'] ?? '';
if (!empty(self::$mail_content) || !empty(self::$mail_to)) {
try {
if (!text::isEmail(self::$mail_to)) {
throw new Exception(__('You must provide a valid email address.'));
}
if (self::$mail_content == '') {
throw new Exception(__('You must provide a content.'));
}
$mail_subject = mail::B64Header(self::$mail_subject);
if ($active_headers) {
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content, $headers);
} else {
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content);
}
dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__));
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
return null;
}
public static function render(): void
{
echo '<html><head><title>' . __('Mail test') . '</title></head><body>' .
dcPage::breadcrumb([__('System') => '', __('Mail test') => '']) .
dcPage::notices() . '
<div id="mail_testor">
<form method="post" action="' . dcCore::app()->admin->getPageURL() . '">
<p><label for="mail_to">' . __('Mailto:') . ' ' .
form::field('mail_to', 30, 255, self::$mail_to, 'maximal') .
'</label></p>
<p><label for="mail_subject">' . __('Subject:') . ' ' .
form::field('mail_subject', 30, 255, self::$mail_subject, 'maximal') .
'</label></p>
<p>' . __('Content:') . '</p>
<p class="area">' .
form::textarea('mail_content', 50, 7, html::escapeHTML($mail_content)) . '
</p>
<p><label class="classic" for="active_headers">' .
form::checkbox('active_headers', 1, self::$active_headers) . ' ' .
__('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>';
} }
} }
echo '<html><head><title>' . __('Mail test') . '</title></head><body>' .
dcPage::breadcrumb([__('System') => '', __('Mail test') => '']) .
dcPage::notices() . '
<div id="mail_testor">
<form method="post" action="' . dcCore::app()->admin->getPageURL() . '">
<p><label for="mail_to">' . __('Mailto:') . ' ' .
form::field('mail_to', 30, 255, $mail_to, 'maximal') .
'</label></p>
<p><label for="mail_subject">' . __('Subject:') . ' ' .
form::field('mail_subject', 30, 255, $mail_subject, 'maximal') .
'</label></p>
<p>' . __('Content:') . '</p>
<p class="area">' .
form::textarea('mail_content', 50, 7, html::escapeHTML($mail_content)) . '
</p>
<p><label class="classic" for="active_headers">' .
form::checkbox('active_headers', 1, $active_headers) . ' ' .
__('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
inc/Prepend.php Normal file
View File

@ -0,0 +1,38 @@
<?php
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([
implode('\\', ['Dotclear','Plugin', basename(__NAMESAPCE__), $lib]) => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php'
]);
}
return true;
}
}

8
index.php Normal file
View File

@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
$manage = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Manage']);
if ($manage::init()) {
$manage::process();
$manage::render();
}