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;
}
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( public static function init(): bool
__('Mail test'), {
dcCore::app()->adminurl->get('admin.plugin.testMail'), if (defined('DC_CONTEXT_ADMIN')) {
dcPage::getPF('testMail/icon.svg'), self::$name = __('Mail test');
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.testMail')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), 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() dcCore::app()->auth->isSuperAdmin()
); );
return true;
}
}

View File

@ -10,13 +10,47 @@
* @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 */
use dcAdminNotices;
use dcCore;
use dcPage;
/* clearbricks ns */
use form;
use html;
use http;
use mail;
use text;
class Manage
{
private static $active_headers = false;
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;
}
return self::$init;
}
public static function process(): ?bool
{
if (!self::$init) {
return false;
}
$headers = [
'From: ' . mail::B64Header(dcCore::app()->blog->name) . 'From: ' . mail::B64Header(dcCore::app()->blog->name) .
'<no-reply@' . str_replace('http://', '', http::getHost()) . ' >', '<no-reply@' . str_replace('http://', '', http::getHost()) . ' >',
'Content-Type: text/HTML; charset=UTF-8;' . 'Content-Type: text/HTML; charset=UTF-8;' .
@ -25,67 +59,75 @@ $headers = [
'X-Blog-Id: ' . mail::B64Header(dcCore::app()->blog->id), 'X-Blog-Id: ' . mail::B64Header(dcCore::app()->blog->id),
'X-Blog-Name: ' . mail::B64Header(dcCore::app()->blog->name), 'X-Blog-Name: ' . mail::B64Header(dcCore::app()->blog->name),
'X-Blog-Url: ' . mail::B64Header(dcCore::app()->blog->url), 'X-Blog-Url: ' . mail::B64Header(dcCore::app()->blog->url),
]; ];
$active_headers = !empty($_POST['active_headers']); self::$active_headers = !empty($_POST['active_headers']);
$mail_to = $_POST['mail_to'] ?? ''; self::$mail_to = $_POST['mail_to'] ?? '';
$mail_subject = $_POST['mail_subject'] ?? ''; self::$mail_subject = $_POST['mail_subject'] ?? '';
$mail_content = $_POST['mail_content'] ?? ''; self::$mail_content = $_POST['mail_content'] ?? '';
if (!empty($mail_content) || !empty($mail_to)) { if (!empty(self::$mail_content) || !empty(self::$mail_to)) {
try { try {
if (!text::isEmail($mail_to)) { if (!text::isEmail(self::$mail_to)) {
throw new Exception(__('You must provide a valid email address.')); throw new Exception(__('You must provide a valid email address.'));
} }
if ($mail_content == '') { if (self::$mail_content == '') {
throw new Exception(__('You must provide a content.')); throw new Exception(__('You must provide a content.'));
} }
$mail_subject = mail::B64Header($mail_subject); $mail_subject = mail::B64Header(self::$mail_subject);
if ($active_headers) { if ($active_headers) {
mail::sendMail($mail_to, $mail_subject, $mail_content, $headers); mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content, $headers);
} else { } else {
mail::sendMail($mail_to, $mail_subject, $mail_content); mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content);
} }
dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.')); dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.'));
dcCore::app()->adminurl->redirect('admin.plugin.testMail'); dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__NAMESPACE__));
return true;
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); 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();
}