From c95d414ef63ca37118f1f660880cd58b4480c414 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Tue, 4 Feb 2025 20:47:44 +0300 Subject: [PATCH] misc(emailer): Use constants for email types (#1794) --- library/includes/init_bb.php | 3 +++ src/Emailer.php | 16 ++++++++++++---- src/IndexNow.php | 3 +++ src/Updater.php | 8 ++++---- styles/templates/admin/admin_mass_email.tpl | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index ed97788f3..05d51880c 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -309,6 +309,9 @@ define('HTML_DISABLED', ' disabled '); define('HTML_READONLY', ' readonly '); define('HTML_SELECTED', ' selected '); +define('EMAIL_TYPE_HTML', 'text/html'); +define('EMAIL_TYPE_TEXT', 'text/plain'); + // $GPC define('KEY_NAME', 0); // position in $GPC['xxx'] define('DEF_VAL', 1); diff --git a/src/Emailer.php b/src/Emailer.php index 1b9b9d751..f1162eb36 100644 --- a/src/Emailer.php +++ b/src/Emailer.php @@ -9,6 +9,8 @@ namespace TorrentPier; +use Exception; + use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mailer\Transport\SendmailTransport; @@ -119,6 +121,7 @@ class Emailer * @param string $email_format * * @return bool + * @throws Exception */ public function send(string $email_format = 'text/plain'): bool { @@ -176,10 +179,15 @@ class Emailer $message->getHeaders() ->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply'); - if ($email_format == 'text/html') { - $message->html($this->message); - } else { - $message->text($this->message); + switch ($email_format) { + case EMAIL_TYPE_HTML: + $message->html($this->message); + break; + case EMAIL_TYPE_TEXT: + $message->text($this->message); + break; + default: + throw new Exception('Unknown email format: ' . $email_format); } /** Send message */ diff --git a/src/IndexNow.php b/src/IndexNow.php index 87511d17b..e0e2ad9a1 100644 --- a/src/IndexNow.php +++ b/src/IndexNow.php @@ -50,6 +50,9 @@ class IndexNow 'naver' => 'searchadvisor.naver.com' ]; + /** + * IndexNow constructor + */ public function __construct() { global $bb_cfg; diff --git a/src/Updater.php b/src/Updater.php index c27242d09..f41277239 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -130,14 +130,14 @@ class Updater } /** - * Returns information of latest TorrentPier version + * Returns information of latest TorrentPier version available * - * @param bool $allowRC + * @param bool $allowPreReleases * @return array */ - public function getLastVersion(bool $allowRC = true): array + public function getLastVersion(bool $allowPreReleases = true): array { - if (!$allowRC) { + if (!$allowPreReleases) { foreach ($this->jsonResponse as $index) { if (isset($index['prerelease']) && $index['prerelease']) { continue; diff --git a/styles/templates/admin/admin_mass_email.tpl b/styles/templates/admin/admin_mass_email.tpl index ecc623f21..8a5846241 100644 --- a/styles/templates/admin/admin_mass_email.tpl +++ b/styles/templates/admin/admin_mass_email.tpl @@ -16,8 +16,8 @@ {L_MASS_EMAIL_MESSAGE_TYPE}