From 0e80faf4fab7a763c3749a8ed383738d1c78ef20 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 6 Jan 2023 00:33:13 +0100 Subject: [PATCH] NS playground: fill structure --- _admin.php | 7 ++ _prepend.php | 11 +++ inc/Admin.php | 60 ++++++++++------ inc/Manage.php | 180 +++++++++++++++++++++++++++++------------------- inc/Prepend.php | 38 ++++++++++ index.php | 8 +++ 6 files changed, 215 insertions(+), 89 deletions(-) create mode 100644 _admin.php create mode 100644 _prepend.php create mode 100644 inc/Prepend.php create mode 100644 index.php diff --git a/_admin.php b/_admin.php new file mode 100644 index 0000000..9f13439 --- /dev/null +++ b/_admin.php @@ -0,0 +1,7 @@ +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() -); diff --git a/inc/Manage.php b/inc/Manage.php index d3201b6..c3980f5 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -10,82 +10,124 @@ * @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 = [ - '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), -]; +/* dotclear ns */ +use dcAdminNotices; +use dcCore; +use dcPage; -$active_headers = !empty($_POST['active_headers']); -$mail_to = $_POST['mail_to'] ?? ''; -$mail_subject = $_POST['mail_subject'] ?? ''; -$mail_content = $_POST['mail_content'] ?? ''; +/* clearbricks ns */ +use form; +use html; +use http; +use mail; +use text; -if (!empty($mail_content) || !empty($mail_to)) { - try { - if (!text::isEmail($mail_to)) { - throw new Exception(__('You must provide a valid email address.')); +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; } - if ($mail_content == '') { - throw new Exception(__('You must provide a content.')); - } + return self::$init; + } - $mail_subject = mail::B64Header($mail_subject); - - if ($active_headers) { - mail::sendMail($mail_to, $mail_subject, $mail_content, $headers); - } else { - mail::sendMail($mail_to, $mail_subject, $mail_content); + public static function process(): ?bool + { + if (!self::$init) { + return false; } - dcAdminNotices::addSuccessNotice(__('Mail successuffly sent.')); - dcCore::app()->adminurl->redirect('admin.plugin.testMail'); - } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + $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'] ?? ''; + + 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 '' . __('Mail test') . '' . + dcPage::breadcrumb([__('System') => '', __('Mail test') => '']) . + dcPage::notices() . ' + +
+
+ +

+ +

+ +

' . __('Content:') . '

+

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

+ +

+ +

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

' . + '
+
+ + '; } } - -echo '' . __('Mail test') . '' . -dcPage::breadcrumb([__('System') => '', __('Mail test') => '']) . -dcPage::notices() . ' - -
-
- -

- -

- -

' . __('Content:') . '

-

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

- -

- -

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

' . -'
-
- -'; diff --git a/inc/Prepend.php b/inc/Prepend.php new file mode 100644 index 0000000..317e1e0 --- /dev/null +++ b/inc/Prepend.php @@ -0,0 +1,38 @@ +autoload([ + implode('\\', ['Dotclear','Plugin', basename(__NAMESAPCE__), $lib]) => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php' + ]); + } + + return true; + } +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..045048a --- /dev/null +++ b/index.php @@ -0,0 +1,8 @@ +