From 15bc67ce8d0134525adb1621398ba43a70547fa1 Mon Sep 17 00:00:00 2001
From: Garvin Hicking
Date: Tue, 3 Dec 2019 14:25:03 +0100
Subject: [PATCH] [TASK] Updates serendipity_event_mailer: Prepend body option,
force sending mails, fixed striptag label
---
plugins/serendipity_event_mailer/ChangeLog | 8 +
.../UTF-8/lang_de.inc.php | 7 +-
.../serendipity_event_mailer/lang_de.inc.php | 7 +-
.../serendipity_event_mailer/lang_en.inc.php | 8 +-
.../serendipity_event_mailer.php | 245 +++++++++++-------
5 files changed, 170 insertions(+), 105 deletions(-)
create mode 100644 plugins/serendipity_event_mailer/ChangeLog
diff --git a/plugins/serendipity_event_mailer/ChangeLog b/plugins/serendipity_event_mailer/ChangeLog
new file mode 100644
index 00000000..62bff159
--- /dev/null
+++ b/plugins/serendipity_event_mailer/ChangeLog
@@ -0,0 +1,8 @@
+1.60:
+-----
+
+* Add new field to prepend a mail body message for each mail
+
+* Adds checkbox to allow force sending e-mails even when a blog entry is published already
+
+* Fixes missing "Keep stripped tags" description
diff --git a/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php b/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php
index 064810bb..ab76ab6d 100644
--- a/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php
+++ b/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php
@@ -16,6 +16,9 @@
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'An alle Redakteure schicken');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGS', 'Bilder und Hyperlinks beibehalten, wenn HTML entfernt wird?');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGSDESC', 'Gilt nur, wenn HTML entfernt wird. Falls aktiviert, werden Bilder und Hyperlinks in der Mail enthalten bleiben (in eckigen Klammern). Falls deaktiviert, werden alle Bilder und Hyperlinks auch entfernt.');
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGS', 'Bilder und Hyperlinks beibehalten, wenn HTML entfernt wird?');
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGSDESC', 'Gilt nur, wenn HTML entfernt wird. Falls aktiviert, werden Bilder und Hyperlinks in der Mail enthalten bleiben (in eckigen Klammern). Falls deaktiviert, werden alle Bilder und Hyperlinks auch entfernt.');
+@define('PLUGIN_EVENT_MAILER_FORCESEND', 'E-Mail-Versand erzwingen');
+@define('PLUGIN_EVENT_MAILER_FORCESEND_DESC', 'Standardmäßig werden E-Mails nur beim erstmaligen Veröffentlichen eines Artikels versendet.');
+@define('PLUGIN_EVENT_MAILER_MAILTEXT', 'Optionaler Text am Anfang der E-Mail (z.B. eine Grußbotschaft oder Begründung, warum der Blog-Artikel per E-Mail geschickt wird)');
diff --git a/plugins/serendipity_event_mailer/lang_de.inc.php b/plugins/serendipity_event_mailer/lang_de.inc.php
index 75bd5a24..a00a7e7c 100644
--- a/plugins/serendipity_event_mailer/lang_de.inc.php
+++ b/plugins/serendipity_event_mailer/lang_de.inc.php
@@ -16,6 +16,9 @@
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'An alle Redakteure schicken');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGS', 'Bilder und Hyperlinks beibehalten, wenn HTML entfernt wird?');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGSDESC', 'Gilt nur, wenn HTML entfernt wird. Falls aktiviert, werden Bilder und Hyperlinks in der Mail enthalten bleiben (in eckigen Klammern). Falls deaktiviert, werden alle Bilder und Hyperlinks auch entfernt.');
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGS', 'Bilder und Hyperlinks beibehalten, wenn HTML entfernt wird?');
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGSDESC', 'Gilt nur, wenn HTML entfernt wird. Falls aktiviert, werden Bilder und Hyperlinks in der Mail enthalten bleiben (in eckigen Klammern). Falls deaktiviert, werden alle Bilder und Hyperlinks auch entfernt.');
+@define('PLUGIN_EVENT_MAILER_FORCESEND', 'E-Mail-Versand erzwingen');
+@define('PLUGIN_EVENT_MAILER_FORCESEND_DESC', 'Standardmäßig werden E-Mails nur beim erstmaligen Veröffentlichen eines Artikels versendet.');
+@define('PLUGIN_EVENT_MAILER_MAILTEXT', 'Optionaler Text am Anfang der E-Mail (z.B. eine Grußbotschaft oder Begründung, warum der Blog-Artikel per E-Mail geschickt wird)');
diff --git a/plugins/serendipity_event_mailer/lang_en.inc.php b/plugins/serendipity_event_mailer/lang_en.inc.php
index f7a46c9e..bdf55b01 100644
--- a/plugins/serendipity_event_mailer/lang_en.inc.php
+++ b/plugins/serendipity_event_mailer/lang_en.inc.php
@@ -21,6 +21,8 @@
@define('PLUGIN_EVENT_MAILER_SENDING', 'Sending');
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Send this entry via E-Mail');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'Send to all authors');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGS', 'Keep images and hyperlinks when removing html?');
-@define('PLUGIN_EVENT_MAILER_STRIPTAGSDESC', 'Only applies when removing HTML-tags from the mail. If enabled, images and hyperlinks will be put inside the text, when disabled those placeholders will also be removed.');
-
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGS', 'Keep images and hyperlinks when removing html?');
+@define('PLUGIN_EVENT_MAILER_KEEPSTRIPTAGSDESC', 'Only applies when removing HTML-tags from the mail. If enabled, images and hyperlinks will be put inside the text, when disabled those placeholders will also be removed.');
+@define('PLUGIN_EVENT_MAILER_FORCESEND', 'Forces sending an E-Mail on save');
+@define('PLUGIN_EVENT_MAILER_FORCESEND_DESC', 'By default, E-Mails are only sent when publishing an entry for the first time');
+@define('PLUGIN_EVENT_MAILER_MAILTEXT', 'Optional custom text to prepend to the E-Mail (like a greeting or explaining why this entry is being mailed)');
diff --git a/plugins/serendipity_event_mailer/serendipity_event_mailer.php b/plugins/serendipity_event_mailer/serendipity_event_mailer.php
index 61cff4f8..ddb6f974 100644
--- a/plugins/serendipity_event_mailer/serendipity_event_mailer.php
+++ b/plugins/serendipity_event_mailer/serendipity_event_mailer.php
@@ -19,7 +19,7 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_MAILER_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Sebastian Nohn, Kristian Koehntopp, Garvin Hicking');
- $propbag->add('version', '1.54');
+ $propbag->add('version', '1.60');
$propbag->add('requirements', array(
'serendipity' => '1.6',
'smarty' => '2.6.7',
@@ -28,10 +28,11 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('event_hooks', array(
'backend_publish' => true,
'backend_display' => true,
+ 'backend_save' => true,
));
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
- $config = array('what', 'mailto', 'sendtoall', 'includelink', 'striptags', 'convertp', 'keepstriptags');
+ $config = array('what', 'mailto', 'sendtoall', 'includelink', 'striptags', 'keepstriptags', 'convertp', 'mailerbody');
$propbag->add('configuration', $config);
}
@@ -128,6 +129,13 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('default', 'false');
break;
+ case 'mailerbody':
+ $propbag->add('type', 'text');
+ $propbag->add('name', PLUGIN_EVENT_MAILER_MAILTEXT);
+ $propbag->add('description', '');
+ $propbag->add('default', '');
+ break;
+
default:
return false;
}
@@ -139,6 +147,110 @@ class serendipity_event_mailer extends serendipity_event
$title = $this->title;
}
+ function sendMail($eventData)
+ {
+ global $serendipity;
+
+ $mails = explode(' ', str_replace(',', '', $this->get_config('mailto')));
+ $to = array();
+ foreach($mails AS $mailto) {
+ $mailto = trim($mailto);
+ if (!empty($mailto)) {
+ $to[] = $mailto;
+ }
+ }
+
+ $this->performConfig($to);
+ if (is_array($this->data['cat'])) {
+ $selected = array();
+ if (is_array($eventData['categories'])) {
+ foreach($eventData['categories'] AS $idx => $cid) {
+ $selected[$cid] = true;
+ }
+ }
+
+ foreach($this->data['cat'] AS $cid => $cat) {
+ $mailto = trim($this->get_config('category_' . $cid));
+
+ if (!empty($mailto) && isset($selected[$cid])) {
+ $tos = explode(' ', str_replace(',', '', $mailto));
+ foreach($tos AS $mailtopart) {
+ $to[] = trim($mailtopart);
+ }
+ }
+ }
+ }
+
+ if ($serendipity['POST']['properties']['sendentry_all']) {
+ $mails = serendipity_db_query("SELECT DISTINCT email FROM {$serendipity['dbPrefix']}authors");
+ foreach($mails AS $mail) {
+ $to[] = trim($mail['email']);
+ }
+ }
+
+ $mail = array(
+ 'subject' => $eventData['title'],
+ 'body' => $eventData['body'] . $eventData['extended'],
+ // 'from' => $serendipity['blogTitle'] . ' - ' . $eventData['author'] . ' <' . $serendipity['serendipityEmail'] . '>'
+ 'from' => $serendipity['serendipityEmail']
+ );
+
+ switch($this->get_config('what')) {
+ case 'all':
+ $mail['body'] = $eventData['body'] . $eventData['extended'];
+ break;
+ case 'body':
+ $mail['body'] = $eventData['body'];
+ break;
+ case 'extended':
+ $mail['body'] = $eventData['extended'];
+ break;
+ case 'none':
+ $mail['body'] = '';
+ break;
+ }
+
+ if (!empty($serendipity['POST']['properties']['mailerbody'])) {
+ $mail['body'] = $serendipity['POST']['properties']['mailerbody'] . "\n" . $mail['body'];
+ }
+
+ if (isset($serendipity['POST']['properties']['mailto'])) {
+ $mails = explode(' ', str_replace(',', '', $serendipity['POST']['properties']['mailto']));
+ foreach($mails as $mailto) {
+ $mailto = trim($mailto);
+ if (!in_array($mailto, $to)) {
+ $to[] = $mailto;
+ }
+ }
+ }
+
+ if (serendipity_db_bool($this->get_config('convertp', 'false'))) {
+ $mail['body'] = str_replace('