Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions xExtension-ShareByEmail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions xExtension-ShareByEmail/configure.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types=1);
/** @var ShareByEmailExtension $this */
?>

<div class="form-group">
Expand All @@ -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>
33 changes: 33 additions & 0 deletions xExtension-ShareByEmail/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions xExtension-ShareByEmail/i18n/de/shareByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'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)',
Expand Down
2 changes: 2 additions & 0 deletions xExtension-ShareByEmail/i18n/en/shareByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'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)',
Expand Down
2 changes: 2 additions & 0 deletions xExtension-ShareByEmail/i18n/fr/shareByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'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)',
Expand Down
2 changes: 2 additions & 0 deletions xExtension-ShareByEmail/i18n/tr/shareByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'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)',
Expand Down
2 changes: 1 addition & 1 deletion xExtension-ShareByEmail/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}