serendipity_event_mailer: (useful) addition

Creating and modifying plugins.
Post Reply
JWalker
Regular
Posts: 177
Joined: Mon Sep 12, 2005 4:14 pm
Location: Botevgrad, Bulgaria
Contact:

serendipity_event_mailer: (useful) addition

Post by JWalker »

Hello,

I made an addition to s9y_event_mailer that I hope is useful. At the time of publishing new entry the user has no option to decide to send or not to send the entry via e-mail (the user may want to not send this particular entry ...). Now I added a checkbox in extended properties area, just before the edit control with the emails list that is checked by default. The user may, if he wants to, uncheck it and the entry will not be sent. Instead a message will be issued that informs the user that the entry was not sent, because he have decided so.

Here is the zip file with the changed files only, serendipity_event_mailer.php and lang_eng.inc.php.

The changes in serendipity_event_mailer.php are in function event_hook.
1) case 'backend_display':, additions to <fieldset> tag (first <input> and <label> pair):

Code: Select all

<fieldset style="margin: 5px">
    <legend><?php echo PLUGIN_EVENT_MAILER_NAME; ?></legend>
    <input type="checkbox" name="serendipity[properties][sendentry]" id="properties_sendentry" value="true" checked="checked" />
    <label title="<?php echo PLUGIN_EVENT_MAILER_SENDING; ?>" for="properties_sendentry"> <?php echo PLUGIN_EVENT_MAILER_ISTOSENDIT; ?>  </label><br />
    <label title="<?php echo PLUGIN_EVENT_MAILER_RECIPIENT; ?>" for="properties_mailto"> <?php echo PLUGIN_EVENT_MAILER_RECIPIENTS; ?>  </label> 
    <input type="text" name="serendipity[properties][mailto]" id="properties_mailto" value="<?php echo htmlspecialchars($mailto); ?>" />
</fieldset>
2) case 'backend_publish': Added if statement that checks the value of the checkbox. The 'true' part simply emits a message that the entry was not sent and 'else' part contains the existing code, that sends the mail:

Code: Select all

if ($serendipity['POST']['properties']['sendentry'] == false) {
    echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
} else {
    ...... sending email here ....
}
return true;
lang_en.inc.php contains three new strings.
Ivan Cenov
OKTO-7 Co., Botevgrad
Bulgaria
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: serendipity_event_mailer: (useful) addition

Post by garvinhicking »

That looks good, do you want to commit?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
JWalker
Regular
Posts: 177
Joined: Mon Sep 12, 2005 4:14 pm
Location: Botevgrad, Bulgaria
Contact:

Post by JWalker »

Yes, I will commit, just waited to hear opinions. I saw several  's that are redundant -- will remove them, test and if OK -- commit.

Christmas time - I wish to all Serendipity peoples all the best :) :)
Ivan Cenov
OKTO-7 Co., Botevgrad
Bulgaria
JWalker
Regular
Posts: 177
Joined: Mon Sep 12, 2005 4:14 pm
Location: Botevgrad, Bulgaria
Contact:

Post by JWalker »

....comitted -- it's there
Ivan Cenov
OKTO-7 Co., Botevgrad
Bulgaria
hmesker
Regular
Posts: 29
Joined: Wed Jul 27, 2005 7:34 pm
Contact:

Post by hmesker »

This feature works nice, except when I use PopFetcher to harvest entries from a Pop mail account - in that case the option 'Send this entry via E-Mail' seems to be swiched off and I always get the message 'This entry was not sent via E-Mail because you decided to not send it'. How can I change this to default on?

Best wishes,

Harmen.
JWalker
Regular
Posts: 177
Joined: Mon Sep 12, 2005 4:14 pm
Location: Botevgrad, Bulgaria
Contact:

Post by JWalker »

Hello,

Sending mail is controlled by $serendipity['POST']['properties']['sendentry'] in serendipity_event_mailer.php:

Code: Select all

case 'backend_publish':
    if ($serendipity['POST']['properties']['sendentry'] == false) {
        echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
    } else {
................ sending mail here ................
    }
This flag gets its value in the <fieldset> in the edit entry form (page), in the same serendipity_event_mailer.php file.

Now in popfetcher, because there is no such edit form, there is no $serendipity['POST']['properties']['sendentry'] variable and above if expression evaluates to true and executes echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';

Try to change this line in serendipity_event_mailer.php:

Code: Select all

if ($serendipity['POST']['properties']['sendentry'] == false) {
to

Code: Select all

if (!empty($serendipity['POST']['properties']['sendentry']) && $serendipity['POST']['properties']['sendentry'] == false) {
I think though, this is not the perfect solution and there should be something cleaner.

Regards.
Ivan Cenov
OKTO-7 Co., Botevgrad
Bulgaria
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I committed a new version of the plugin with a fix similar to yours!

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
JWalker
Regular
Posts: 177
Joined: Mon Sep 12, 2005 4:14 pm
Location: Botevgrad, Bulgaria
Contact:

Post by JWalker »

Hi,

Code: Select all

if (isset($serendipity['POST']['properties']) && !isset($serendipity['POST']['properties']['sendentry'])) {
Hm, I think that if

Code: Select all

- isset($serendipity['POST']['properties'] == true
- !isset($serendipity['POST']['properties']['sendentry']) == false
- $serendipity['POST']['properties']['sendentry'] == false
this will send the entry but it should not do that.
What about this, will it work ?

Code: Select all

if (isset($serendipity['POST']['properties']) && isset($serendipity['POST']['properties']['sendentry']) && $serendipity['POST']['properties']['sendentry'] == false) {
So, it will send always except when explicitly user denied by clearing the checkbox.

Regards,
Ivan Cenov
OKTO-7 Co., Botevgrad
Bulgaria
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

When the checkbox is not checked, the value is not submitted in the HTTP response. So a checkbox HTTP input field can never have the value "false". It can only either be set (in which case the value does not matter) or be unsert...

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply