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)         {

        }

    } }

Author

Jason Prothero

comments powered by Disqus
back to top