Jump to:

10987 Posts in 2724 Topics by 1817 members

All other Modules

SilverStripe Forums » All other Modules » Comment Moderation - Notifications?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 4664 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    Comment Moderation - Notifications? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

    http://doc.silverstripe.org/doku.php?id=dataobjectdecorator

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Comment Moderation - Notifications? Link to this post

    GREAT! Thanks for the fleshing-out, @willr! I will definitely try this out.

    //Garrett

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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>

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Comment Moderation - Notifications? Link to this post

    Hi!

    Can’t you use 'Page' => $this->owner->Parent()->Link() in the PopulateTemplate() array?

    Hope it helps,
    Juan

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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,
             ));

    4664 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.