Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-10-14 22:50:58

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

[request] email article author and 'moderator' each comment

I have a scenario where it is helpful that each author (on a community blog site) recieve notification of comments on their blog article. This behavior is easily set up in Admin Preferences. However, this community site has elected a ‘moderator’ to follow the comments on the site for every author since the author’s themselves have neither the time, nor the knowhow to make moderated comments visible.

I am interested in a plugin that would allow me to add a “comment moderator” email address for notification of the comments to be emailed to in addition to the blog author.

Is this possible, is this difficult, :)

Thank you.

Matthew


Offline

#2 2006-10-14 23:28:37

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [request] email article author and 'moderator' each comment

You can do it with a plugin that uses the same callback_event as anti-comment-spam plugins. Downside of that may be that if your plugin is executed before the anti-spam plugins, a notification is sent for spammy comments, which are then rejected by the plugins that analyse them later on. Ideally you’d have a plugin use a callback_event that is executed after all the anti-spam plugins have done their work, but there isn’t one available.

The only remaining difficulty is in predicting the ID of the comment, before it is inserted into the database/table. Because no table locking is done here, the ID could be wrong if multiple comments are submitted at the exact same time.

register_callback('abc_mail_comment','comment.save');

function abc_mail_comment($foo, $bar)
{
        global $sitename;

        $mod_name = 'Moderator name';
        $mod_email = 'moderator_email@example.com';

        $row = getRow("SHOW TABLE STATUS LIKE '".PFX."txp_discuss'");
        $discussid = $row['Auto_increment'];

        extract(getComment());
        $parentid = assert_int($parentid);
        $discussid = assert_int($discussid);
        $article = safe_row("Section, Posted, ID, url_title, AuthorID, Title", "textpattern", "ID = $parentid");
        extract($article);

        $out = gTxt('greeting')." $mod_name,\r\n\r\n";
        $out .= str_replace('{title}',$Title,gTxt('comment_recorded'))."\r\n";
        $out .= permlinkurl_id($parentid)."\r\n";
        $out .= hu.'textpattern/index.php?event=discuss&step=discuss_edit&discussid='.$discussid."\r\n";
        $out .= "\r\n";
        $out .= gTxt('comment_name').": $name\r\n";
        $out .= gTxt('comment_email').": $email\r\n";
        $out .= gTxt('comment_web').": $web\r\n";
        $out .= gTxt('comment_comment').": $message";

        $subject = strtr(gTxt('comment_received'),array('{site}' => $sitename, '{title}' => $Title));

        $success = txpMail($mod_email, $subject, $out, $email);
}

This has a hardcoded name/email of the moderator, assuming you don’t mind editing the name/email in the plugin code. Having an input field for moderator name/email in the preferences or extensions tab would be a bit more work.

Note: I didn’t test the code shown above.

Last edited by ruud (2006-10-15 00:04:49)

Offline

#3 2006-10-15 01:55:52

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: [request] email article author and 'moderator' each comment

Ruud,

I’ve enjoyed watching you go through things with svn through the mailing list. Thanks for having a look at this.

Couple of questions here:

1. Does the code you provide here tackle the pre-spam comment issues you bring up above? I didn’t gather whether that remained a problem or not? Although I personally have never received spam in my comments, and I’ve only heard of it happening very rarely becuase of comment preview.
2. If I wan’t to use this code, I’m assuming I’ll need to compile it, but after some searching, and really not knowing where to start, I couldn’t find instructions for how to do that so that the plugin is insertable into the plugins field in the plugins tab.

Thanks :)

Matthew


Offline

#4 2006-10-15 05:26:41

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: [request] email article author and 'moderator' each comment

Didn’t try it, but here’s the compiled plugin:

YTo5OntzOjQ6Im5hbWUiO3M6MjE6ImFiY19yZWdpc3Rlcl9jYWxsYmFjayI7czo2OiJhdXRob3IiO3M6NDoicnV1ZCI7czoxMDoiYXV0aG9yX3VyaSI7czo2MToiaHR0cDovL2ZvcnVtLnRleHRwYXR0ZXJuLmNvbS92aWV3dG9waWMucGhwP3BpZD0xMjc5NDcjcDEyNzk0NyI7czo3OiJ2ZXJzaW9uIjtzOjM6IjAuMSI7czoxMToiZGVzY3JpcHRpb24iO3M6MDoiIjtzOjQ6ImhlbHAiO3M6MDoiIjtzOjQ6ImNvZGUiO3M6MTMxMjoicmVnaXN0ZXJfY2FsbGJhY2soJ2FiY19tYWlsX2NvbW1lbnQn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Vzc19lZGl0JmRpc2N1c3NpZD0nLiRkaXNjdXNzaWQuIlxyXG4iOw0KICAgICAgICAkb3V0IC49ICJcclxuIjsNCiAgICAgICAgJG91dCAuPSBnVHh0KCdjb21tZW50X25hbWUnKS4iOiAkbmFtZVxyXG4iOw0KICAgICAgICAkb3V0IC49IGdUeHQoJ2NvbW1lbnRfZW1haWwnKS4iOiAkZW1haWxcclxuIjsNCiAgICAgICAgJG91dCAuPSBnVHh0KCdjb21tZW50X3dlYicpLiI6ICR3ZWJcclxuIjsNCiAgICAgICAgJG91dCAuPSBnVHh0KCdjb21tZW50X2NvbW1lbnQnKS4iOiAkbWVzc2FnZSI7DQoNCiAgICAgICAgJHN1YmplY3QgPSBzdHJ0cihnVHh0KCdjb21tZW50X3JlY2VpdmVkJyksYXJyYXkoJ3tzaXRlfScgPT4gJHNpdGVuYW1lLCAne3RpdGxlfScgPT4gJFRpdGxlKSk7DQoNCiAgICAgICAgJHN1Y2Nlc3MgPSB0eHBNYWlsKCRtb2RfZW1haWwsICRzdWJqZWN0LCAkb3V0LCAkZW1haWwpOw0KfSI7czo0OiJ0eXBlIjtzOjE6IjAiO3M6MzoibWQ1IjtzOjMyOiJmN2VmMGNhZTlhMzZhN2E4YTE1MjQ4ZjQ1ZDBkYmQ2ZiI7fQ==

Offline

#5 2006-10-15 08:42:27

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [request] email article author and 'moderator' each comment

1. It doesn’t tackle the pre-spam thing. To do that, you’d have to bypass some of the core TXP code for comments, but (and I’m not sure if that’s even possible) that would also mean duplicating a lot of that code in this plugin. This is a trade-off between simplicity and functionality.
2. You can use <a href=“http://forum.textpattern.com/viewtopic.php?id=10330”>zem’s plugin template</a> for that. Or someone will do it for you as jm did ;)

Might as well do it officially here with my own prefix (instead of abc) and a help page included:

# rvm_mail_comments v0.1
# Mail all comments to dedicated moderator(s)
# Ruud van Melick
# http://vanmelick.com/
# License: GPLv2 or later

# ......................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# ......................................................................

YTo5OntzOjc6InZlcnNpb24iO3M6MzoiMC4xIjtzOjY6ImF1dGhvciI7czoxNToiUnV1ZCB2
YW4gTWVsaWNrIjtzOjEwOiJhdXRob3JfdXJpIjtzOjIxOiJodHRwOi8vdmFubWVsaWNrLmNv
bS8iO3M6MTE6ImRlc2NyaXB0aW9uIjtzOjQzOiJNYWlsIGFsbCBjb21tZW50cyB0byBkZWRp
Y2F0ZWQgbW9kZXJhdG9yKHMpIjtzOjQ6InR5cGUiO2k6MDtzOjQ6Im5hbWUiO3M6MTc6InJ2
bV9tYWlsX2NvbW1lbnRzIjtzOjQ6ImhlbHAiO3M6NTcyOiIJPHA+CkJlZm9yZSBlbmFibGlu
ZyB0aGUgcGx1Z2luLCBlZGl0IHRoZSBwbHVnaW4gc28gdGhlICRtb2RfbmFtZSBhbmQgJG1v
ZF9lbWFpbCB2YXJpYWJsZXMgY29udGFpbiB0aGUgbmFtZSBhbmQgZW1haWwgYWRkcmVzcyBv
ZiB0aGUgZGVkaWNhdGVkIG1vZGVyYXRvci4gRXhhbXBsZToKICA8cHJlPgogICAgJG1vZF9u
YW1lID0gJ0pvaG4gRG9lJzsKICAgICRtb2RfZW1haWwgPSAnam9obkBleGFtcGxlLmNvbSc7
CiAgPC9wcmU+PC9wPgoJPHA+SWYgdGhlcmUgYXJlIG11bHRpcGxlIGRlZGljYXRlZCBtb2Rl
cmF0b3JzLCB1c2UgYSBnZW5lcmljIG5hbWUgYW5kIGEgY29tbWEtc2VwYXJhdGVkIGxpc3Qg
b2YgZW1haWwgYWRkcmVzc2VzOgogIDxwcmU+CiAgICAkbW9kX25hbWUgPSAnTW9kZXJhdG9y
cyc7CiAgICAkbW9kX2VtYWlsID0gJ21vZGVyYXRvckBleGFtcGxlLmNvbSxhbm90aGVybW9k
ZXJhdG9yQGV4YW1wbGUuY29tJzsKICA8L3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QpLiJcclxuIjsKCSRvdXQgLj0gaHUuJ3RleHRwYXR0ZXJuL2luZGV4LnBocD9ldmVu
dD1kaXNjdXNzJnN0ZXA9ZGlzY3Vzc19lZGl0JmRpc2N1c3NpZD0nLiRkaXNjdXNzaWQuIlxy
XG4iOwoJJG91dCAuPSAiXHJcbiI7Cgkkb3V0IC49IGdUeHQoJ2NvbW1lbnRfbmFtZScpLiI6
ICRuYW1lXHJcbiI7Cgkkb3V0IC49IGdUeHQoJ2NvbW1lbnRfZW1haWwnKS4iOiAkZW1haWxc
clxuIjsKCSRvdXQgLj0gZ1R4dCgnY29tbWVudF93ZWInKS4iOiAkd2ViXHJcbiI7Cgkkb3V0
IC49IGdUeHQoJ2NvbW1lbnRfY29tbWVudCcpLiI6ICRtZXNzYWdlIjsKCgkkc3ViamVjdCA9
IHN0cnRyKGdUeHQoJ2NvbW1lbnRfcmVjZWl2ZWQnKSxhcnJheSgne3NpdGV9JyA9PiAkc2l0
ZW5hbWUsICd7dGl0bGV9JyA9PiAkVGl0bGUpKTsKCgkkc3VjY2VzcyA9IHR4cE1haWwoJG1v
ZF9lbWFpbCwgJHN1YmplY3QsICRvdXQsICRlbWFpbCk7Cn0iO3M6MzoibWQ1IjtzOjMyOiIy
NmQ1NDdjMzFhYzRhNzk1MjJhZWQ4YzVhMWQwZGUwYyI7fQ==

Last edited by ruud (2006-10-16 08:19:28)

Offline

#6 2006-10-15 23:55:21

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: [request] email article author and 'moderator' each comment

Ruud,
Thank you,
and Jon Michael, thank you (for all your help).

Much appreciated.

Matthew


Offline

#7 2006-10-16 00:10:08

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: [request] email article author and 'moderator' each comment

Ruud,
1. I could not load your plugin for some reason (badly formed or empty – error), though JM’s version did load.

2. I was able to edit the info just fine, and then was able to make and preview a comment, but upon submittal I got this error.

Fatal error: Call to undefined function assert_int() in /home/.emperior/ma_smith/liberti.artiswork.org/textpattern/lib/txplib_misc.php(527) : eval()'d code on line 14

Any ideas?

:)

Matthew


Offline

#8 2006-10-16 00:43:48

akokskis
Plugin Author
From: Baltimore-ish, USofA
Registered: 2004-11-28
Posts: 230
Website

Re: [request] email article author and 'moderator' each comment

assert_int() is one of the functions that I beleive have been added to the core since 4.0.3 through Ruud’s various patches. So, in order to have this code in your TXP install, you need to either be running a semi recent svn version or wait until 4.0.4 comes out (in theory, early this coming week).


My Photoblog, and my personal site. Got nav? ako_nav.
Thanks for taking the time to look…

— vc3 —

Offline

#9 2006-10-16 00:49:05

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: [request] email article author and 'moderator' each comment

akoksis, Ruud,
I am using 4.0.3 (r1874),

Shall I upgrade to the 4.04 rc1?
I’ll try it I guess and report back.

Last edited by ma_smith (2006-10-16 00:54:43)


Offline

#10 2006-10-16 01:10:27

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: [request] email article author and 'moderator' each comment

Ruud,
Aksoksis,
JM,

success. Thank you.

Matthew


Offline

#11 2006-10-16 08:29:30

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [request] email article author and 'moderator' each comment

Mine works fine as well… if you just copy the plugin code and not the description above. Probably caused by the leading space I had to add to circumvent the textile voodoo happening here on the forum ;)
I’ve split it up in two pieces now. Just paste the bottom part and it should work.

Offline

#12 2006-10-18 05:22:09

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: [request] email article author and 'moderator' each comment

I’m wondering if a plugin is required for this. Couldn’t you just set the person’s email address to be “user@email.com, admin@email.com” it works for me :) Not exactly flexible, but it works!

Offline

Board footer

Powered by FluxBB