mirror of
https://github.com/FreshRSS/Extensions.git
synced 2026-11-04 10:48:40 +00:00
[Share By Email] Add an optional default recipient (#558)
Users who mostly share articles with the same address (e.g. their own mailbox or a read-later service) have to type it again every time. Add a "Default recipient" email field to the extension configuration, stored in the `share_by_email_default_recipient` user attribute, and use it to prefill the "To" field of the sharing form. The field can still be edited before sending, and leaving the setting empty keeps the current behaviour. The address is validated with PHPMailer in the same way FreshRSS core validates user email addresses; an invalid address is rejected with the core "invalid email" message and the previous value is kept. Add translations for all supported languages, document the option in the README and bump the extension version to 0.5.0. Fixes #129
This commit is contained in:
1 parent
2e7a8cff78
commit
e1347500dd
9 files changed
+77
-1
No files matched your search
@@ -57,6 +57,9 @@ final class FreshExtension_shareByEmail_Controller extends Minz_ActionController
|
||||
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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/** @var ShareByEmailExtension $this */
|
||||
?>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -15,3 +16,31 @@ declare(strict_types=1);
|
||||
<p class="help"><?= _i('help') ?> <?= _t('shareByEmail.share.manage.help') ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="<?= _url('extension', 'configure', 'e', urlencode($this->getName())) ?>" method="post" data-auto-leave-validation="1">
|
||||
<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
|
||||
|
||||
<div class="form-group">
|
||||
<label class="group-name" for="share_by_email_default_recipient">
|
||||
<?= _t('shareByEmail.share.manage.default_recipient') ?>
|
||||
</label>
|
||||
<div class="group-controls">
|
||||
<input
|
||||
type="email"
|
||||
name="share_by_email_default_recipient"
|
||||
id="share_by_email_default_recipient"
|
||||
class="long"
|
||||
placeholder="alice@example.net"
|
||||
value="<?= htmlspecialchars($this->getDefaultRecipient(), ENT_COMPAT, 'UTF-8') ?>"
|
||||
/>
|
||||
<p class="help"><?= _i('help') ?> <?= _t('shareByEmail.share.manage.default_recipient_help') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group form-actions">
|
||||
<div class="group-controls">
|
||||
<button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button>
|
||||
<button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -25,9 +25,42 @@ final class ShareByEmailExtension extends Minz_Extension {
|
||||
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 {
|
||||
|
||||
@@ -19,6 +19,8 @@ return [
|
||||
'intro' => 'Diesen Artikel per Mail versenden: “<strong>%s</strong>”',
|
||||
'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 <code>mail()</code>',
|
||||
'smtp' => 'via SMTP (versendet von %s)',
|
||||
|
||||
@@ -19,6 +19,8 @@ return [
|
||||
'intro' => 'You are about to share this article by email: “<strong>%s</strong>”',
|
||||
'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 <code>mail()</code>',
|
||||
'smtp' => 'SMTP (send from %s)',
|
||||
|
||||
@@ -19,6 +19,8 @@ return [
|
||||
'intro' => 'Vous êtes sur le point de partager cet article par courriel : « <strong>%s</strong> »',
|
||||
'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 <code>mail()</code>',
|
||||
'smtp' => 'SMTP (envoyer en tant que %s)',
|
||||
|
||||
@@ -19,6 +19,8 @@ return [
|
||||
'intro' => 'Bu makaleyi e-posta yoluyla paylaşmak üzeresiniz: “<strong>%s</strong>”',
|
||||
'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 <code>mail()</code>',
|
||||
'smtp' => 'SMTP (%s kaynağından gönder)',
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in new issue
Block a user