NS playground: fill structure
This commit is contained in:
parent
7a7f9f4bc3
commit
0e80faf4fa
7
_admin.php
Normal file
7
_admin.php
Normal 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
11
_prepend.php
Normal 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();
|
||||
}
|
||||
}
|
@ -1,22 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief testMail, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Osku and contributors
|
||||
*
|
||||
* @copyright Jean-Crhistian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
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']),
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\testMail;
|
||||
|
||||
/* dotclear ns */
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
|
||||
class Admin
|
||||
{
|
||||
private static $name = '';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
144
inc/Manage.php
144
inc/Manage.php
@ -10,13 +10,47 @@
|
||||
* @copyright Jean-Crhistian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
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) .
|
||||
'<no-reply@' . str_replace('http://', '', http::getHost()) . ' >',
|
||||
'Content-Type: text/HTML; charset=UTF-8;' .
|
||||
@ -25,67 +59,75 @@ $headers = [
|
||||
'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']);
|
||||
$mail_to = $_POST['mail_to'] ?? '';
|
||||
$mail_subject = $_POST['mail_subject'] ?? '';
|
||||
$mail_content = $_POST['mail_content'] ?? '';
|
||||
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($mail_content) || !empty($mail_to)) {
|
||||
if (!empty(self::$mail_content) || !empty(self::$mail_to)) {
|
||||
try {
|
||||
if (!text::isEmail($mail_to)) {
|
||||
if (!text::isEmail(self::$mail_to)) {
|
||||
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.'));
|
||||
}
|
||||
|
||||
$mail_subject = mail::B64Header($mail_subject);
|
||||
$mail_subject = mail::B64Header(self::$mail_subject);
|
||||
|
||||
if ($active_headers) {
|
||||
mail::sendMail($mail_to, $mail_subject, $mail_content, $headers);
|
||||
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content, $headers);
|
||||
} else {
|
||||
mail::sendMail($mail_to, $mail_subject, $mail_content);
|
||||
mail::sendMail(self::$mail_to, $mail_subject, self::$mail_content);
|
||||
}
|
||||
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) {
|
||||
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
38
inc/Prepend.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user