diff --git a/xExtension-ShareByEmail/Controllers/shareByEmailController.php b/xExtension-ShareByEmail/Controllers/shareByEmailController.php index 77d08fca..d721a737 100644 --- a/xExtension-ShareByEmail/Controllers/shareByEmailController.php +++ b/xExtension-ShareByEmail/Controllers/shareByEmailController.php @@ -57,6 +57,9 @@ public function shareAction(): void { Minz_View::appendStyle($this->extension->getFileUrl('shareByEmail.css')); } $this->view->to = ''; + if ($this->extension instanceof ShareByEmailExtension) { + $this->view->to = htmlspecialchars($this->extension->getDefaultRecipient(), ENT_COMPAT, 'UTF-8'); + } $this->view->subject = _t('shareByEmail.share.form.subject_default'); $this->view->content = _t( 'shareByEmail.share.form.content_default', diff --git a/xExtension-ShareByEmail/README.md b/xExtension-ShareByEmail/README.md index d1a0ffb2..6acac455 100644 --- a/xExtension-ShareByEmail/README.md +++ b/xExtension-ShareByEmail/README.md @@ -12,8 +12,11 @@ After the installation the `Email` sharing service will added to the list of ava You will have to configure the mailing system in FreshRSS. [See the documentation](https://freshrss.github.io/FreshRSS/en/admins/05_Configuring_email_validation.html#configure-the-smtp-server) +Optionally, you can set a default recipient in the extension configuration, which will prefill the “To” field of the sharing form. + ## Changelog +- 0.5.0 Optional default recipient to prefill the sharing form - 0.3.2 With the new feature, Turkish language deficiencies have been corrected. - 0.3.0 detail information about the mail system shown in the extension config - 0.2.3 Turkish language support added diff --git a/xExtension-ShareByEmail/configure.phtml b/xExtension-ShareByEmail/configure.phtml index ac30a38b..c8291b65 100644 --- a/xExtension-ShareByEmail/configure.phtml +++ b/xExtension-ShareByEmail/configure.phtml @@ -1,5 +1,6 @@
@@ -15,3 +16,31 @@ declare(strict_types=1);

+ +
+ + +
+ +
+ +

+
+
+ +
+
+ + +
+
+
diff --git a/xExtension-ShareByEmail/extension.php b/xExtension-ShareByEmail/extension.php index 48a32c11..a7707ed8 100644 --- a/xExtension-ShareByEmail/extension.php +++ b/xExtension-ShareByEmail/extension.php @@ -25,9 +25,42 @@ public function init(): void { spl_autoload_register(array($this, 'loader')); } + /** + * @throws FreshRSS_Context_Exception + */ #[\Override] public function handleConfigureAction(): void { $this->registerTranslates(); + + if (Minz_Request::isPost()) { + $defaultRecipient = Minz_Request::paramString('share_by_email_default_recipient', plaintext: true); + if ($defaultRecipient !== '' && !self::isValidEmailAddress($defaultRecipient)) { + Minz_Request::bad(_t('user.email.feedback.invalid'), [ + 'c' => 'extension', + 'a' => 'configure', + 'params' => [ + 'e' => $this->getName(), + ], + ]); + return; + } + FreshRSS_Context::userConf()->_attribute('share_by_email_default_recipient', $defaultRecipient); + FreshRSS_Context::userConf()->save(); + } + } + + /** + * @throws FreshRSS_Context_Exception + */ + public function getDefaultRecipient(): string { + return FreshRSS_Context::userConf()->attributeString('share_by_email_default_recipient') ?? ''; + } + + private static function isValidEmailAddress(string $email): bool { + $mailer = new PHPMailer\PHPMailer\PHPMailer(); + $mailer->CharSet = 'utf-8'; + $punyemail = $mailer->punyencodeAddress($email); + return PHPMailer\PHPMailer\PHPMailer::validateAddress($punyemail, 'html5'); } public function loader(string $class_name): void { diff --git a/xExtension-ShareByEmail/i18n/de/shareByEmail.php b/xExtension-ShareByEmail/i18n/de/shareByEmail.php index d8961df8..0c2eea1b 100755 --- a/xExtension-ShareByEmail/i18n/de/shareByEmail.php +++ b/xExtension-ShareByEmail/i18n/de/shareByEmail.php @@ -19,6 +19,8 @@ 'intro' => 'Diesen Artikel per Mail versenden: “%s”', 'title' => 'Einen Artikel per Mail teilen.', 'manage' => [ + 'default_recipient' => 'Standard-Empfänger', + 'default_recipient_help' => 'Füllt das Feld „An“ beim Teilen eines Artikels vor. Leer lassen, um keinen Standard-Empfänger zu verwenden.', 'mailer' => 'E-Mail-Versand', 'mail' => 'via PHP mail()', 'smtp' => 'via SMTP (versendet von %s)', diff --git a/xExtension-ShareByEmail/i18n/en/shareByEmail.php b/xExtension-ShareByEmail/i18n/en/shareByEmail.php index 49c8784c..8ae22f38 100644 --- a/xExtension-ShareByEmail/i18n/en/shareByEmail.php +++ b/xExtension-ShareByEmail/i18n/en/shareByEmail.php @@ -19,6 +19,8 @@ 'intro' => 'You are about to share this article by email: “%s”', 'title' => 'Share an article by email', 'manage' => [ + 'default_recipient' => 'Default recipient', + 'default_recipient_help' => 'Prefills the “To” field when sharing an article. Leave empty to have no default recipient.', 'mailer' => 'Mailing system', 'mail' => 'PHP mail()', 'smtp' => 'SMTP (send from %s)', diff --git a/xExtension-ShareByEmail/i18n/fr/shareByEmail.php b/xExtension-ShareByEmail/i18n/fr/shareByEmail.php index 9343f357..4d3be13d 100644 --- a/xExtension-ShareByEmail/i18n/fr/shareByEmail.php +++ b/xExtension-ShareByEmail/i18n/fr/shareByEmail.php @@ -19,6 +19,8 @@ 'intro' => 'Vous êtes sur le point de partager cet article par courriel : « %s »', 'title' => 'Partager un article par courriel', 'manage' => [ + 'default_recipient' => 'Destinataire par défaut', + 'default_recipient_help' => 'Pré-remplit le champ « Pour » lors du partage d’un article. Laisser vide pour ne pas avoir de destinataire par défaut.', 'mailer' => 'Système de messagerie', 'mail' => 'PHP mail()', 'smtp' => 'SMTP (envoyer en tant que %s)', diff --git a/xExtension-ShareByEmail/i18n/tr/shareByEmail.php b/xExtension-ShareByEmail/i18n/tr/shareByEmail.php index b2cca3ff..fbcfccc4 100644 --- a/xExtension-ShareByEmail/i18n/tr/shareByEmail.php +++ b/xExtension-ShareByEmail/i18n/tr/shareByEmail.php @@ -19,6 +19,8 @@ 'intro' => 'Bu makaleyi e-posta yoluyla paylaşmak üzeresiniz: “%s”', 'title' => 'Bir makaleyi e-posta ile paylaşın', 'manage' => [ + 'default_recipient' => 'Varsayılan alıcı', + 'default_recipient_help' => 'Bir makale paylaşılırken “Kime” alanını önceden doldurur. Varsayılan alıcı istemiyorsanız boş bırakın.', 'mailer' => 'Mail sistemi', 'mail' => 'PHP mail()', 'smtp' => 'SMTP (%s kaynağından gönder)', diff --git a/xExtension-ShareByEmail/metadata.json b/xExtension-ShareByEmail/metadata.json index e8bba61e..3e1befc7 100644 --- a/xExtension-ShareByEmail/metadata.json +++ b/xExtension-ShareByEmail/metadata.json @@ -2,7 +2,7 @@ "name": "Share By Email", "author": "Marien Fressinaud", "description": "Improve the sharing by email system.", - "version": "0.4.0", + "version": "0.5.0", "entrypoint": "ShareByEmail", "type": "user" }