[TASK] Updates serendipity_event_mailer: Prepend body option, force sending mails, fixed striptag label

This commit is contained in:
Garvin Hicking 2019-12-03 14:25:03 +01:00
parent d7b4e93292
commit 15bc67ce8d
5 changed files with 170 additions and 105 deletions

View File

@ -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

View File

@ -16,6 +16,9 @@
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden'); @define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'An alle Redakteure schicken'); @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_KEEPSTRIPTAGS', '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_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)');

View File

@ -16,6 +16,9 @@
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden'); @define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'An alle Redakteure schicken'); @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_KEEPSTRIPTAGS', '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_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)');

View File

@ -21,6 +21,8 @@
@define('PLUGIN_EVENT_MAILER_SENDING', 'Sending'); @define('PLUGIN_EVENT_MAILER_SENDING', 'Sending');
@define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Send this entry via E-Mail'); @define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Send this entry via E-Mail');
@define('PLUGIN_EVENT_MAILER_SENDTOALL', 'Send to all authors'); @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_KEEPSTRIPTAGS', '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_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)');

View File

@ -19,7 +19,7 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_MAILER_DESC); $propbag->add('description', PLUGIN_EVENT_MAILER_DESC);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Sebastian Nohn, Kristian Koehntopp, Garvin Hicking'); $propbag->add('author', 'Sebastian Nohn, Kristian Koehntopp, Garvin Hicking');
$propbag->add('version', '1.54'); $propbag->add('version', '1.60');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '1.6', 'serendipity' => '1.6',
'smarty' => '2.6.7', 'smarty' => '2.6.7',
@ -28,10 +28,11 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('event_hooks', array( $propbag->add('event_hooks', array(
'backend_publish' => true, 'backend_publish' => true,
'backend_display' => true, 'backend_display' => true,
'backend_save' => true,
)); ));
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED')); $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); $propbag->add('configuration', $config);
} }
@ -128,6 +129,13 @@ class serendipity_event_mailer extends serendipity_event
$propbag->add('default', 'false'); $propbag->add('default', 'false');
break; break;
case 'mailerbody':
$propbag->add('type', 'text');
$propbag->add('name', PLUGIN_EVENT_MAILER_MAILTEXT);
$propbag->add('description', '');
$propbag->add('default', '');
break;
default: default:
return false; return false;
} }
@ -139,53 +147,10 @@ class serendipity_event_mailer extends serendipity_event
$title = $this->title; $title = $this->title;
} }
function event_hook($event, &$bag, &$eventData, $addData = null) function sendMail($eventData)
{ {
global $serendipity; global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'backend_display':
if (isset($serendipity['POST']['properties']['mailto'])) {
$mailto = $serendipity['POST']['properties']['mailto'];
} else {
$mailto = $this->get_config('mailto');
}
if (isset($serendipity['POST']['properties']['sendentry_all'])) {
$sendtoall = $serendipity['POST']['properties']['sendentry_all'];
} else {
$sendtoall = serendipity_db_bool($this->get_config('sendtoall'));
}
?>
<fieldset class="entryproperties">
<span class="wrap_legend"><legend><?php echo PLUGIN_EVENT_MAILER_NAME; ?></legend></span>
<div class="form_check">
<input id="properties_sendentry" type="checkbox" name="serendipity[properties][sendentry]" value="true" checked="checked">
<label title="<?php echo PLUGIN_EVENT_MAILER_SENDING; ?>" for="properties_sendentry"><?php echo PLUGIN_EVENT_MAILER_ISTOSENDIT; ?></label>
</div>
<div class="form_field">
<label title="<?php echo PLUGIN_EVENT_MAILER_RECIPIENT; ?>" for="properties_mailto"><?php echo PLUGIN_EVENT_MAILER_RECIPIENTS; ?></label>
<input id="properties_mailto" type="text" name="serendipity[properties][mailto]" value="<?php echo serendipity_specialchars($mailto); ?>">
</div>
<div class="form_check">
<input id="sendall" type="checkbox" value="true" name="serendipity[properties][sendentry_all]" <?php echo ($sendtoall ? 'checked="checked"': ''); ?>>
<label title="<?php echo PLUGIN_EVENT_MAILER_SENDTOALL; ?>" for="sendall"><?php echo PLUGIN_EVENT_MAILER_SENDTOALL; ?></label>
</div>
</fieldset>
<?php
break;
case 'backend_publish':
if (isset($serendipity['POST']['properties']) && !isset($serendipity['POST']['properties']['sendentry'])) {
echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
} else {
$mails = explode(' ', str_replace(',', '', $this->get_config('mailto'))); $mails = explode(' ', str_replace(',', '', $this->get_config('mailto')));
$to = array(); $to = array();
foreach($mails AS $mailto) { foreach($mails AS $mailto) {
@ -245,6 +210,10 @@ class serendipity_event_mailer extends serendipity_event
break; break;
} }
if (!empty($serendipity['POST']['properties']['mailerbody'])) {
$mail['body'] = $serendipity['POST']['properties']['mailerbody'] . "\n" . $mail['body'];
}
if (isset($serendipity['POST']['properties']['mailto'])) { if (isset($serendipity['POST']['properties']['mailto'])) {
$mails = explode(' ', str_replace(',', '', $serendipity['POST']['properties']['mailto'])); $mails = explode(' ', str_replace(',', '', $serendipity['POST']['properties']['mailto']));
foreach($mails as $mailto) { foreach($mails as $mailto) {
@ -261,11 +230,11 @@ class serendipity_event_mailer extends serendipity_event
if (serendipity_db_bool($this->get_config('striptags', 'false'))) { if (serendipity_db_bool($this->get_config('striptags', 'false'))) {
if (serendipity_db_bool($this->get_config('keepstriptags', 'true'))) { if (serendipity_db_bool($this->get_config('keepstriptags', 'true'))) {
$mail['body'] = preg_replace('§<a[^>]+href=["\']([^"\']*)["\'][^>]*>([^<]*)</a>§i', "$2 [$1]", $mail['body']); $mail['body'] = preg_replace('@<a[^>]+href=["\']([^"\']*)["\'][^>]*>([^<]*)</a>@i', "$2 [$1]", $mail['body']);
$mail['body'] = preg_replace('§<img[^>]+src=["\']([^"\']*)["\'][^>]*>§i', "[" . IMAGE . ": $1]", $mail['body']); $mail['body'] = preg_replace('@<img[^>]+src=["\']([^"\']*)["\'][^>]*>@i', "[" . IMAGE . ": $1]", $mail['body']);
} else { } else {
$mail['body'] = preg_replace('§<a[^>]+href=["\']([^"\']*)["\'][^>]*>([^<]*)</a>§i', "", $mail['body']); $mail['body'] = preg_replace('@<a[^>]+href=["\']([^"\']*)["\'][^>]*>([^<]*)</a>@i', "", $mail['body']);
$mail['body'] = preg_replace('§<img[^>]+src=["\']([^"\']*)["\'][^>]*>§i', "", $mail['body']); $mail['body'] = preg_replace('@<img[^>]+src=["\']([^"\']*)["\'][^>]*>@i', "", $mail['body']);
} }
$mail['body'] = strip_tags($mail['body']); $mail['body'] = strip_tags($mail['body']);
} }
@ -281,6 +250,87 @@ class serendipity_event_mailer extends serendipity_event
} }
} }
} }
function event_hook($event, &$bag, &$eventData, $addData = null)
{
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'backend_display':
if (isset($serendipity['POST']['properties']['mailto'])) {
$mailto = $serendipity['POST']['properties']['mailto'];
} else {
$mailto = $this->get_config('mailto');
}
if (isset($serendipity['POST']['properties']['sendentry_all'])) {
$sendtoall = $serendipity['POST']['properties']['sendentry_all'];
} else {
$sendtoall = serendipity_db_bool($this->get_config('sendtoall'));
}
if (isset($serendipity['POST']['properties']['mailerbody'])) {
$mailerbody = $serendipity['POST']['properties']['mailerbody'];
} else {
$mailerbody = $this->get_config('mailerbody');
}
?>
<fieldset class="entryproperties">
<span class="wrap_legend"><legend><?php echo PLUGIN_EVENT_MAILER_NAME; ?></legend></span>
<div class="form_check">
<input id="properties_sendentry" type="checkbox" name="serendipity[properties][sendentry]" value="true" checked="checked">
<label title="<?php echo PLUGIN_EVENT_MAILER_SENDING; ?>" for="properties_sendentry"><?php echo PLUGIN_EVENT_MAILER_ISTOSENDIT; ?></label>
</div>
<div class="form_field">
<label title="<?php echo PLUGIN_EVENT_MAILER_RECIPIENT; ?>" for="properties_mailto"><?php echo PLUGIN_EVENT_MAILER_RECIPIENTS; ?></label>
<input id="properties_mailto" type="text" name="serendipity[properties][mailto]" value="<?php echo serendipity_specialchars($mailto); ?>">
</div>
<div class="form_check">
<input id="sendall" type="checkbox" value="true" name="serendipity[properties][sendentry_all]" <?php echo ($sendtoall ? 'checked="checked"': ''); ?>>
<label title="<?php echo PLUGIN_EVENT_MAILER_SENDTOALL; ?>" for="sendall"><?php echo PLUGIN_EVENT_MAILER_SENDTOALL; ?></label>
</div>
<?php if (!serendipity_db_bool($eventData['isdraft'])) { // Only show this for entries that are published ?>
<div class="form_check">
<input id="forcesend" type="checkbox" value="true" name="serendipity[properties][forcesend]">
<label title="<?php echo PLUGIN_EVENT_MAILER_FORCESEND; ?>" for="forcesend"><?php echo PLUGIN_EVENT_MAILER_FORCESEND; ?></label>
<br />
<em><?php echo PLUGIN_EVENT_MAILER_FORCESEND_DESC; ?></em>
</div>
<?php } ?>
<div class="form_check">
<label for="mailerbody"><?= PLUGIN_EVENT_MAILER_MAILTEXT; ?></label>
<textarea id="mailerbody" rows="5" name="serendipity[properties][mailerbody]" ><?php echo serendipity_specialchars($mailerbody); ?></textarea>
</div>
</fieldset>
<?php
break;
case 'backend_save':
if (serendipity_db_bool($eventData['isdraft'])) {
// Never send e-mails for drafts.
return true;
}
if (isset($serendipity['POST']['properties']['forcesend']) && $serendipity['POST']['properties']['forcesend']) {
$this->sendMail($eventData);
} else {
echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
}
break;
case 'backend_publish':
if (isset($serendipity['POST']['properties']) && !isset($serendipity['POST']['properties']['sendentry'])) {
echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
} else {
$this->sendMail($eventData);
}
break; break;
default: default:
@ -295,4 +345,3 @@ class serendipity_event_mailer extends serendipity_event
} }
/* vim: set sts=4 ts=4 expandtab : */ /* vim: set sts=4 ts=4 expandtab : */
?>