Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How To: A Simple Way to Moderate Page Comments

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 3063 Views
  • elijahlofgren
    Avatar
    Google Summer of Code Hacker
    222 Posts

    How To: A Simple Way to Moderate Page Comments Link to this post

    Hi Guys,

    I just wanted to share some stuff that I've learned.

    First off, you can enable Page Comments by editing a page, clicking on the "Behaviour" tab, checking the box next to "Allow comments on this page?", and saving the page.

    By default, Page Comments do not have any protection against spam. This means that your pages can become spammed by robots.

    One thing you can do is use the SSAkismet class to use spam detection for comments using http://akismet.com/
    For more info on how to do this see: http://doc.silverstripe.com/doku.php?id=ssakismet

    However, I did not follow the above instructions because I didn't want to rely on a spam filtering service, I wanted to manually approve or delete every single comment by hand.

    First I made it so that new comments are not shown by default. Here's how:
    1. Open cms/code/sitefeatures/PageCommentInterface.php
    2. Find this line:
    $comment->IsSpam = false;
    3. Replace that line with:
    $comment->IsSpam = true;

    Next, I needed to make the "this comment is not spam" link show up and work even though I did not enable SSAkismet. Here's how:
    1. Open cms/code/sitefeatures/PageComment.php
    2. Find these 3 lines:

          if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
             return "PageComment/reportham/$this->ID";
          }

    3. After the above 3 lines, add these 3 lines:

          if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
             return "PageComment/reportham/$this->ID";
          }

    4. Find these 2 lines:

             $comment->setField('IsSpam', false);
             $comment->write();

    5. After those 2 lines, add the following 6 lines:

          } else {
             if (Permission::check('CMS_ACCESS_CMSMain')) {
                $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
                $comment->setField('IsSpam', false);
                $comment->write();
             }

    Ok, thankfully that's all the code changes we will need to make.

    SilverStripe has a built-in RSS feed for Page Comments. You will want to subscribe to it at http://www.example.com/PageComment/rss using your favorite feed reader.

    For example, the URL for my Page Comments feed is: http://www.elijahlofgren.com/silverstripe/PageComment/rss

    Now when you see a new comment show up on your Page Comments RSS feed, you can do the following:
    1. Login to the your SilverStripe CMS Admin Panel.
    2. Visit the URL of the page where the Comment was posted (this will show up as a link in your feed reader)
    3. Add ?showspam=1 to then end of the Page URL, for example:
    www.example.com/your-page/?showspam=1
    4. If the new comment is not spam, them click the "this comment is not spam" link under it and it will start showing up on your page.
    5. If the comment is spam, click the "remove this comment" link under it and it will be deleted.

    There, an easy way to implement comment moderation.

    Enjoy,

    Elijah Lofgren

  • manhog
    Avatar
    2 Posts

    Re: How To: A Simple Way to Moderate Page Comments Link to this post

    (My first post, so hello everyone.)

    Thanks for sharing this, Elijah.

    This method seems pretty straightforward, but is the code you've changed core code? Can I happily hack away without fear of this breaking when SS gets updated?

    Many thanks,
    Alan.

  • elijahlofgren
    Avatar
    Google Summer of Code Hacker
    222 Posts

    Re: How To: A Simple Way to Moderate Page Comments Link to this post

    Hi Alan,

    Welcome to SilverStripe!

    Yes it is core code, so upgrades will be a problem.

    However, it seems that a better method of dealing with spam is coming our way soon http://svn.silverstripe.com/open/modules/cms/trunk/code/sitefeatures/MathSpamProtection.php

    Have a good day,

    Elijah

  • elijahlofgren
    Avatar
    Google Summer of Code Hacker
    222 Posts

    Re: How To: A Simple Way to Moderate Page Comments Link to this post

    I see:

    static $moderate = false;


    is now in http://svn.silverstripe.com/open/modules/cms/trunk/code/sitefeatures/PageComment.php so it looks like SilverStripe 2.1 will come with built-in comment moderation.

    3063 Views
Page: 1
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.