2022-11-27 22:30:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief testMail, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Osku and contributors
|
|
|
|
*
|
2023-01-05 23:48:09 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
2022-11-27 22:30:13 +00:00
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-01-05 23:33:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\testMail;
|
|
|
|
|
|
|
|
/* dotclear ns */
|
|
|
|
use dcAdminNotices;
|
|
|
|
use dcCore;
|
|
|
|
use dcPage;
|
|
|
|
|
|
|
|
/* clearbricks ns */
|
|
|
|
use form;
|
|
|
|
use html;
|
|
|
|
use http;
|
|
|
|
use mail;
|
|
|
|
use text;
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-07 14:58:28 +00:00
|
|
|
/* php */
|
|
|
|
use Exception;
|
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
class Manage
|
|
|
|
{
|
|
|
|
private static $active_headers = false;
|
2023-01-05 23:48:09 +00:00
|
|
|
private static $mail_to = '';
|
|
|
|
private static $mail_subject = '';
|
|
|
|
private static $mail_content = '';
|
2023-01-07 14:58:28 +00:00
|
|
|
private static $pid = '';
|
2023-01-05 23:48:09 +00:00
|
|
|
protected static $init = false;
|
2023-01-05 23:33:13 +00:00
|
|
|
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
|
|
|
if (defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
dcPage::checkSuper();
|
|
|
|
|
2023-01-07 14:58:28 +00:00
|
|
|
self::$pid = basename(dirname(__DIR__));
|
2023-01-05 23:33:13 +00:00
|
|
|
self::$init = true;
|
2022-11-27 22:30:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
return self::$init;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function process(): ?bool
|
|
|
|
{
|
|
|
|
if (!self::$init) {
|
|
|
|
return false;
|
2022-11-27 22:30:13 +00:00
|
|
|
}
|
2023-01-05 23:33:13 +00:00
|
|
|
$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),
|
|
|
|
];
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
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'] ?? '';
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
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);
|
|
|
|
|
2023-01-07 14:58:28 +00:00
|
|
|
if (self::$active_headers) {
|
2023-01-05 23:33:13 +00:00
|
|
|
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.'));
|
2023-01-07 14:58:28 +00:00
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.' . self::$pid);
|
2023-01-05 23:33:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
2022-11-27 22:30:13 +00:00
|
|
|
}
|
2023-01-05 23:48:09 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
return null;
|
2022-11-27 22:30:13 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
public static function render(): void
|
|
|
|
{
|
2023-01-05 23:48:09 +00:00
|
|
|
echo
|
|
|
|
'<html><head><title>' .
|
2023-01-07 14:58:28 +00:00
|
|
|
dcCore::app()->plugins->moduleInfo(self::$pid, 'name') .
|
2023-01-05 23:48:09 +00:00
|
|
|
'</title></head><body>' .
|
|
|
|
|
|
|
|
dcPage::breadcrumb([
|
2023-01-07 14:58:28 +00:00
|
|
|
__('System') => '',
|
|
|
|
dcCore::app()->plugins->moduleInfo(self::$pid, 'name') => '',
|
2023-01-05 23:48:09 +00:00
|
|
|
]) .
|
2023-01-05 23:33:13 +00:00
|
|
|
dcPage::notices() . '
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<div id="mail_testor">
|
|
|
|
<form method="post" action="' . dcCore::app()->admin->getPageURL() . '">
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<p><label for="mail_to">' . __('Mailto:') . ' ' .
|
|
|
|
form::field('mail_to', 30, 255, self::$mail_to, 'maximal') .
|
|
|
|
'</label></p>
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<p><label for="mail_subject">' . __('Subject:') . ' ' .
|
|
|
|
form::field('mail_subject', 30, 255, self::$mail_subject, 'maximal') .
|
|
|
|
'</label></p>
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<p>' . __('Content:') . '</p>
|
|
|
|
<p class="area">' .
|
2023-01-07 14:58:28 +00:00
|
|
|
form::textarea('mail_content', 50, 7, html::escapeHTML(self::$mail_content)) . '
|
2023-01-05 23:33:13 +00:00
|
|
|
</p>
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<p><label class="classic" for="active_headers">' .
|
|
|
|
form::checkbox('active_headers', 1, self::$active_headers) . ' ' .
|
|
|
|
__('Active mail headers') .
|
|
|
|
'</label></p>
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
<p class="border-top">' .
|
|
|
|
'<input type="submit" value="' . __('Save') . ' (s)" accesskey="s" name="save" /> ' .
|
2022-11-27 22:30:13 +00:00
|
|
|
|
2023-01-05 23:33:13 +00:00
|
|
|
dcCore::app()->formNonce() . '</p>' .
|
|
|
|
'</form>
|
|
|
|
</div>
|
2023-01-05 23:48:09 +00:00
|
|
|
|
|
|
|
</body></html>';
|
2023-01-05 23:33:13 +00:00
|
|
|
}
|
|
|
|
}
|