ProWorks Blog Rotating Header Image

How to Moderate All Comments in Blog 4 Umbraco

Umbraco Developer TutorialThe cool Blog 4 Umbraco package built by the Umbraco Team is a great package with a few features missing out of the box.  The fact that it is Open Source really rocks because it means we can fill in the gaps.  At ProWorks we have been slowly building on Blog 4 Umbraco and now have a pretty solid plug-in.  It may be time to try to get our changes back into the main branch :) .

Recently, we had a request to have comments be moderated.  That means any comment posted would be initially marked as spam and wouldn’t post live to the site.  The blog owner then has to go into the comments area and manually approve each comment.  I’m not big on this, but for some people its important.

Unfortunately, this doesn’t come out of the box in Blog 4 Umbraco.  Luckily, its easy to do.

To add this functionality all you have to do is add a new class that derives from the SpamChecker class.

I created a new class called “AlwaysMarkSpamChecker.cs” under the “Spam” folder.

The class contained the following code:

using System;
using System.Collections.Generic;
using System.Web;
using Umlaut.Umb.Blog.Interfaces;
using Joel.Net;

namespace Umlaut.Umb.Blog.Spam
{
    public class AlwaysMarkSpamChecker : SpamChecker
    {

        public AlwaysMarkSpamChecker()
        {
            this.ProviderName = "AlwaysSpam";
        }

        public override Boolean Check(int nodeid,
            string UserAgent, string UserIp, string Author,
            string AuthorEmail, string AuthorUrl, string Content)
        {
            return true;
        }

        public override void MarkAsHam(int nodeid, string Author, string AuthorEmail, string AuthorUrl, string Content)
        {

        }

        public override void MarkAsSpam(int nodeid, string Author, string AuthorEmail, string AuthorUrl, string Content)
        {

        }

    }
}

Then I edited the /umbraco/plugins/blog4umbraco/SpamChecker.config file in my Umbraco installation to look like this:

<?xml version="1.0"?>
<SpamChecker assembly="/bin/Umlaut.Umb.Blog" type="Umlaut.Umb.Blog.Spam.AlwaysMarkSpamChecker">
</SpamChecker>

Now when I add a new blog comment it will always be marked as Spam in the Comments tab.

If you have any questions or any problems, let me know!

using System;
using System.Collections.Generic;
using System.Web;
using Umlaut.Umb.Blog.Interfaces;
using Joel.Net;

namespace Umlaut.Umb.Blog.Spam
{
    public class AlwaysMarkSpamChecker : SpamChecker
    {

        public AlwaysMarkSpamChecker()
        {
            this.ProviderName = "AlwaysSpam";
        }

        public override Boolean Check(int nodeid,
            string UserAgent, string UserIp, string Author,
            string AuthorEmail, string AuthorUrl, string Content)
        {
            return true;
        }

        public override void MarkAsHam(int nodeid, string Author, string AuthorEmail, string AuthorUrl, string Content)
        {

        }

        public override void MarkAsSpam(int nodeid, string Author, string AuthorEmail, string AuthorUrl, string Content)
        {

        }

    }
}

8 Comments

  1. [...] This post was mentioned on Twitter by Jason Prothero and ProWorks Corporation, Danielle Potts. Danielle Potts said: RT @proworks – New Blog Post: How to Moderate All Comments in Blog 4 Umbraco http://bit.ly/cMG1zo [...]

  2. Jonas says:

    You’re right, that’s kind of a silly request to begin with.

  3. Jason says:

    Hey Jonas!

    That made me laugh :P

  4. Jonas says:

    Also, I just changed this line:

    in User Control Files/Blog4Umbraco/AjaxCpmmentForm.ascx to provide a more appropriate confirmation. I hope that works. : )

  5. Robert says:

    Very nice extension to the solution I discovered. Well done!

    Although it does seem like a silly request, I needed it for a politician’s website. He wanted to blog, and wanted visitors to comment. The issue was that some visitors would leave ‘unwanted’ comments (obscenity, etc).

    Having the comments moderated allowed us to let the posters reply while eliminating the liability they could cause.

    See, sometimes silly can make sense.

  6. Jason says:

    Robert,

    Glad you found it useful!

    Its not silly in the right cases. I just think its overdone when it doesn’t need to be. And, it creates work.

  7. Ben says:

    I’m just trying to implement this, I’ve added the AlwaysMarkSpamChecker.cs into App_Code of my Umbraco website and amended the SpamChecker.config to whats suggested but all comments on the site still get posted. Am I missing something?

    Do I have to download the source of Blog4Umbraco, make the change there, rebuild and deploy the dll to my Umbraco website for it to work?

    Thanks

  8. Jason says:

    Yes, I rebuilt the blog source to include these changes.

    Is the type getting recognized, or is there an error?

Leave a Reply