Page 1 of 1

Email comment notifications, body text, signature (experts)

Posted: Fri Aug 08, 2008 6:52 am
by johncanary
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

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

Posted: Fri Aug 08, 2008 9:55 am
by garvinhicking
Hi!

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

Regards,
Garvin

Posted: Sat Oct 11, 2008 11:37 pm
by Bodehase
@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?

Posted: Sat Oct 11, 2008 11:40 pm
by Bodehase
BTW, question to Garvin: shouldn't this sql-statement include a check if the poster is already approved?