10377 Posts in 2193 Topics by 1709 members
| Go to End | Next > | |
| Author | Topic: | 3727 Views |
-
Comment Moderation - Notifications?

20 January 2010 at 3:56am
Hi,
I've done about a dozen SilverStripe implementations and all of my clients are complaining about the lack of email notifications for comment moderation. I agree with them that the lack of this feature is sort of unacceptable, because if you don't enable moderation, your blog will get spammed to Death, and you don't want to have to go into the admin panel every single day just to Check if there are any new comments. I want to be Notified when I have a comment to moderate.
Am I missing something, or is this feature simply just not available? Could anyone offer me any advice on how I could Add it?
Thanks,
Garrett -
Re: Comment Moderation - Notifications?

20 January 2010 at 6:24pm
You could decorate the PageComment object, in the decorator override the onAfterWrite() function to do something like
$email = new Email();
$email->setTo('email@email.com');
$email->setSubject('New Comment');
// .. all the other options
$email->send();So after writing the comment it will trigger the onAfterWrite() when sends that email. You could also do some more fancy things like check page comments are moderatable
-
Re: Comment Moderation - Notifications?

21 January 2010 at 3:00am
Thanks for your reply, @willr, though I'm afraid I don't know enough about the core code to fill in the missing details myself here. Where/what is the decorator override, and where is the onAfterWrite() function?
//Garrett
-
Re: Comment Moderation - Notifications?

21 January 2010 at 9:01am
I haven't tested it but it would be something like this - http://pastie.org/787023. Once you get that code working you could easily extend the Email functionality - eg set a custom template, add the comment to the email or a link to it at least.
You would then add it to page comments like DataObject::add_extension('PageComment', 'CustomPageComment');
Docs
-
Re: Comment Moderation - Notifications?

21 January 2010 at 9:20am
GREAT! Thanks for the fleshing-out, @willr! I will definitely try this out.
//Garrett
-
Re: Comment Moderation - Notifications?

22 January 2010 at 10:58pm
I've implemented the code and tried to extend it with code form http://doc.silverstripe.org/doku.php?id=email. I would like to include a link to the page the comment has been made on in the email.
How can I include the page url information in the email?
mysite/code/PageCommentEmailNotification.php
<?php
class PageCommentEmailNotification extends DataObjectDecorator {
function onAfterWrite() {
$email = new Email();
$email->setTemplate('NewComment');
$email->setTo('email@ddre.ss');
$email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
$email->populateTemplate(Member::currentUser());
$email->populateTemplate(array(
'Comment' => $this->owner->Comment,
));
$email->send();
}
}?>
themes/mytheme/templates/email/NewComment.ss
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style>
p{
font-size: 1.2em;
color: #444;
}
p.comments{
font-size: 1.4em;
color: #222;
padding: 20px;
}
</style>
</head>
<body>
// How can the page url and title be inserted here?
<p>At $Created, $Name posted a new comment on the page <a href="$Page.URL">$Page.Title</a>.</p><p>Their comment:<br/>
$Comment</p>
<p>You can <a href="{$BaseHref}admin/comments/">administrate the comment</a>.</p>
</body>
</html> -
Re: Comment Moderation - Notifications?

12 February 2010 at 12:48am
Hi!
Can’t you use 'Page' => $this->owner->Parent()->Link() in the PopulateTemplate() array?
Hope it helps,
Juan -
Re: Comment Moderation - Notifications?

23 February 2010 at 5:17am
Thanks Juanitou, don't know why I didn't think of using $this->owner->Parent()->... myself. I ended up using:
$email->populateTemplate(array(
'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
'PageTitle' => $this->owner->Parent()->Title,
'Comment' => $this->owner->Comment,
));
| 3727 Views | ||
| Go to Top | Next > |



