Email comment notifications, body text, signature (experts)

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
User avatar
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Email comment notifications, body text, signature (experts)

Post by johncanary » Fri Aug 08, 2008 6:52 am

Hi,

As I am reading through the thread "Future of S9Y" I decided
to put my enhancement for email notifications in a new thread (here).

Problem:

* Notification email for a comment, does not contain the text of the comment.
* Missing signature (required in some jurisdictions [just to play safe])

Solution:

You need to change 2 files!
* Some constants in the language file. Use YOUR address not the example
address here.
* One php function
* Watch out, since my code here is based on S9Y 1.1.2. There might be
some differences.

Code: Select all

<?php
/*
    based on S9Y 1.1.2
*/

/*
    .../lang/UTF-8/serendipity_lang_en.inc.php
*/

//...
@define('NEW_COMMENT_TO_SUBSCRIBED_ENTRY', 'New comment to subscribed entry "%s"');
@define('SUBSCRIPTION_MAIL', "Hello %s,\n\nA new comment was made to the entry you are monitoring on \"%s\", entitled \"%s\"\n\n*Comments* (by %s): \"%s\"\n\nYou can find the entry here: %s\n\nYou can unsubscribe by clicking on this link: %s\n");
@define('SUBSCRIPTION_TRACKBACK_MAIL', "Hello %s,\n\nA new trackback was added to the entry you are monitoring on \"%s\", entitled \"%s\"\n\n*Comments* (by %s): \"%s\"\n\nYou can find the entry here: %s\n\nYou can unsubscribe by clicking on this link: %s\n");
@define('SIGNATURE', "\n-- \n%s, John Doe, 250 E 62th Street #14A,\nNew York, NY10015, USA\n\nDisclaimer: This email has been automatically generated from\na comment submission. The content should not be regarded\nas approved by the blog owner.\n\nPowered by Serendipity. The best blog around, you can use it too.\nCheck out <http://s9y.org> to find out how.");
//...


/*
    .../include/functions_comments.inc.php

*/

function serendipity_mailSubscribers($entry_id, $poster, $posterMail, $title, $fromEmail = 'none@example.com', $cid = null) {
    global $serendipity;

    $entryURI = serendipity_archiveURL($entry_id, $title, 'baseURL') . ($cid > 0 ? '#c' . $cid : '');
    $subject =  sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $title);

    $pgsql_insert = '';
    $mysql_insert = '';
    if ($serendipity['dbType'] == 'postgres') {
        $pgsql_insert = 'DISTINCT ON (email)';
    } else {
        $mysql_insert = 'GROUP BY email';
    }


    $sql = "SELECT $pgsql_insert author, email, type, body
            FROM {$serendipity['dbPrefix']}comments
            WHERE entry_id = '". (int)$entry_id ."'
              AND email <> '" . serendipity_db_escape_string($posterMail) . "'
              AND email <> ''
              AND subscribed = 'true' $mysql_insert";
    $subscribers = serendipity_db_query($sql);

    if (!is_array($subscribers)) {
        return;
    }

    foreach ($subscribers as $subscriber) {
        if ($subscriber['type'] == 'TRACKBACK') {
            $text = sprintf(
                      SUBSCRIPTION_TRACKBACK_MAIL,

                      $subscriber['author'],
                      $serendipity['blogTitle'],
                      $title,
                      $poster,
                      $subscriber['body'],
                      $entryURI,
                      serendipity_rewriteURL('unsubscribe/' . urlencode($subscriber['email']) . '/' . (int)$entry_id, 'baseURL')
            );
        } else {
            $text = sprintf(
                      SUBSCRIPTION_MAIL,

                      $subscriber['author'],
                      $serendipity['blogTitle'],
                      $title,
                      $poster,
                      $subscriber['body'],
                      $entryURI,
                      serendipity_rewriteURL('unsubscribe/' . urlencode($subscriber['email']) . '/' . (int)$entry_id, 'baseURL')
            );
        }

        serendipity_sendMail($subscriber['email'], $subject, $text, $fromEmail);
    }
}
?>


Yours
John
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Email comment notifications, body text, signature (exper

Post by garvinhicking » Fri Aug 08, 2008 9:55 am

Hi!

I added a todo to make this smarty template based to the s9y 1.4 todo list.

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/

User avatar
Bodehase
Regular
Posts: 36
Joined: Wed Aug 27, 2008 2:29 am
Contact:

Post by Bodehase » Sat Oct 11, 2008 11:37 pm

@johncanary: Are you sure this is working?

Because your code selects in the sql statement the emailaddresses of the posters that should receive a email. If you select in this statement also the body of the comment, then this is not the comments the last poster added.

Or am i completely wrong?
Weblog: Bodehase
s9y-Plugin: ebayauctions 0.9.1 beta

User avatar
Bodehase
Regular
Posts: 36
Joined: Wed Aug 27, 2008 2:29 am
Contact:

Post by Bodehase » Sat Oct 11, 2008 11:40 pm

BTW, question to Garvin: shouldn't this sql-statement include a check if the poster is already approved?
Weblog: Bodehase
s9y-Plugin: ebayauctions 0.9.1 beta

Post Reply