custom

Spam comments are annoying and sometimes looking at comment allowed by Akismet or some other anti-spam service you think – I’m sure I would do better. It is just so hard to get the plumbing in or I would made my very own solution. With BlogEngine.Net 1.6 it is not, you can easily implement your own anti-spam filter or add existing if you like it more than built-in Akismet. Here is how.

First, open BE 1.6 solution in VS or VWD or whichever tool you are using to work with source code in .NET. Create new class in the App_Code folder, I called mine SpamBlocker. This class should implement ICustomFilter interface, it has just 4 members and looks like this:

namespace BlogEngine.Core
{
    public interface ICustomFilter
    {
        bool Initialize();
        bool Check(Comment comment);
        void Report(Comment comment);
        bool FallThrough { get; }
    }
}

Below is very simple implementation. It based on idea that most reliable way to identify spam is to check if comment contains link to site selling products or services and known for hiring spammers to push their ads all over the internet.

using System.Collections.Specialized;
using BlogEngine.Core;

public class SpamBlocker : ICustomFilter
{
    private static bool _passThrough = true;

    static StringCollection MockService()
    {
        StringCollection spammers = new StringCollection();

        spammers.Add("conference-call-providers.co.uk");
        spammers.Add("telebisyonserye.info");
        spammers.Add("qmw.com.au");

        return spammers;
    }

    public bool Initialize()
    {
        if(MockService().Count > 0) return true;
        return false;
    }

    public bool Check(Comment comment)
    {
        bool spam = false;

        foreach (string s in MockService())
        {
            if(comment.Content.Contains(s))
            {
                spam = true;
                break;
            }
        }

        _passThrough = (spam) ? false : true;
        return spam;
    }

    public void Report(Comment comment)
    {
        if(comment.IsApproved)
        {
            foreach (string s in MockService())
            {
                if(comment.Content.Contains(s))
                {
                    MockService().Remove(s);
                }
            }
        }
    }

    public bool FallThrough
    {
        get { return _passThrough; }
    }
}

Mock service has few sites that spammers promote. Obviously, you would have to put some more work here for real deal, but for now it will do. All we need is a way to identify spam. For the sake of this example, if comment mentions any of these sites – it is spam.

Now lets go over each method and explore what it does.

Initialize() – here you can verify that service is running, do authentication or any other kind of required verification. If return true, that means you are ready to handle comments. We just check if we have any spam sites in the list, if we do – good to go.

Check(Comment comment) – this is where you do your custom thing checking if comment is spam. BlogEngine will pass comment to this method, so you can examine all it’s properties. For simplicity, we check if comment has reference to any of spam sites in the list. If it has, we return “true” meaning that comment is spam and set fall through to false (more on it later).

Report(Comment comment) – this is a way to provide feedback to the service, so that you can make it smarter and identify spam better. If blogger restores comment marked by SpamBlocker as spam, we remove it from the list of spam sites. In the real world, here you can examine comment and try to figure out why you did a mistake marking it as spam or verifying that it is not spam and try to put more smarts in your service/filter.

FallThrough – blog might run several custom filters, and we need a way for them to play well together. When fall through set to true, you saying “I think it is spam/not spam, but I’m ok with others to check on it and provide second opinion”. In this case, last judge wins – so the order in which you set filters to run (priority) is important.

filters spamfolder

Here we pretty sure that when comment has spam site in it – it is spam. So we set fall through to false, telling BlogEngine that, in this case, we want to be the ultimate judge and don’t pass comment to other custom services down the list.

If you go and make a comment with one of those sites in the comment body, it will be rejected by SpamBlocker. So here you have it – your very own custom anti-spam filter in 60 lines of code. Ok, it’ll be much more lines when you done with custom logic to identify spam, and you might even implement web service and make it available to other BlogEngine users for this. But handle it on BlogEngien side is a snap.

One more thing, if you want blogger to be able turn your service on and off, you can easily do so by implementing it as extension, just the way Akismet is implemented in BlogEngine. Then, blogger can turn it off without removing it from the web site all together. I hope you’ll try it for yourself, and good luck fighting those nasty spam comments.

Share/Save/Bookmark
Signature

be16 After few delays new version of BlogEngine.Net has been released. Although this release is mostly incremental with minimum breaking changes, there are quite a few improvements, enhancements and bug fixes to make it worthwhile for those stuck on previous versions to upgrade. Upgrade instructions can be found here, and you can download new version from the project site on CodePlex.

  • Centralized Comment Management
  • Automated Comment Spam Filtering with ability to plug-in custom Filtering modules
  • Multiple Widget Zones (details)
  • Referrers data and Blogroll items now stored in Database when using the DB blog provider.
  • Unsubscribe Link in Comment Notification Emails
  • Referrer Data can be Stored for more than 7 days.
  • Blogroll items can now be Ordered.
  • Newsletter Widget more Intelligent - Emails sent when a post is going from an Unpublished to Published state.
  • Twitter Widget - New options and improvements
  • Page Slugs now saved in Database.
  • New Logging system to Track events and errors.
  • Unhandled Exception Handling
  • Fixes to Comment Notification Emails not being sent out correctly in some cases.
  • Outgoing Email improvements
  • Many other improvements and fixes.
Share/Save/Bookmark
Signature
vote

resultsOne real surprise for me was that not many people use BlogEngine as their sandbox and playground. To me as a developer from the beginning it was mostly a toy and only over time it grew up into something bigger with responsibilities attached, so I’m sort of impressed. It seems like what most folks really want is a stable mature product with great features and scalability built it. There is understandable desire for cool new tech on part of some but most seems really care about how it serve their blogging needs (ye, I know, shocking…). So in the end it looks to me like loud and clear call to power along with demand for more advanced and polished tools and features.

Share/Save/Bookmark
Signature

This poll is not official and may be a little early, but it will provide BlogEngine team with some ideas on where we all, as a community, want to move. Are we looking for Wordpress.net? NewCrazyCool.net? Something in between? Please share your opinions and thoughts, it's all greatly appreciated. More we know, easier it is to make decisions and change gears. You can vote either using poll in the side bar or following the link. Feel free to drop a comment if you think of other options or just want to let everybody know what's on your mind. Don't be too harsh though, it still Christmas ;)

Share/Save/Bookmark
Signature

mailr Thanks to the magic of Metaweblog API and BlogMailr service, you can email posts to BlogEngine just as easily as publishing them from Windows Live Writer, Word or iPhone.  Here is what you need to do. Open personal account with BlogMailr, it only takes few minutes and it is free for personal use. Once your account setup you'll be able to add blogs to it. You have to provide user id and password so that BlogMailr can auto-login and publish posts on your blog. More...

Share/Save/Bookmark
Signature

elmah2

Few days ago I’ve noticed that “error.aspx” becomes quite popular destination on my site. What’s going on? I never run into errors, how do I know what others do to break in? Elmah to the rescue! This little utility specifically designed to run in the background and record any ASP.NET errors so you can review them later at your convenience. If you interested how it all works, check out this excellent article on MSDN, it goes in depth explaining technical details. I’ll focus here on how to set it up with BlogEngine (or any ASP.NET web forms application to that matter). More...

Share/Save/Bookmark
Signature

TitleWhile I’m personally not looking forward to writing posts on the phone, some maniacs out there demand modern blog should have this functionality. Or may be I just needed lame excuse to start writing something that can be used on my new Touch ;) Anyway, I’ve started looking into better way to publish posts from iPhone or Touch than using standard web admin UI. First I checked few apps in the app store but none of them worked well with Metaweblog API (as a mater of fact, none of what I tried worked with BE at all…). In the end I put together this little add-on to BlogEngine. More...

Share/Save/Bookmark
Signature

EasyHardOne of the tools I use a lot on my current project is ClearCase – fine version control overall, but its Windows client sometimes drives me nuts. The problem is that it is unnecessarily complicated, it exposes all functionality it got in very obnoxious way. For example, you’ll get dialog with two check boxes and, if try to select one of them you’ll get an error: “you can’t select this because so-and-so”. Really? If you know I can’t use this – why I’m getting this as an option? Why not show me only what I am able to use? And “features” like this is all over the product, you always get menus loaded with options some of which you will never use and some you can’t use even if you try. Very annoying. May be this is why when I started on comment administration for BlogEngine I was extra sensitive in trying to avoid this behavior. After several different approaches I decided that simplest pyramid-like flow will work best. It starts really simple. More...

Share/Save/Bookmark
Signature

comment-card The Commentor extension for BlogEngine got a lot of positive feedback from community and will become a part of standard BlogEngine install in the next version. As work on moving it under BE umbrella just started and it's not too late to make drastic changes, I'll try to outline here how it is going to look and work and, if you have any suggestions or special demands, feel free to drop a line. Your input is always appreciated!

- First of all, here are three basic usage scenarios: More...

Share/Save/Bookmark
Signature

digsby-3I've got email from user having issues with embedding HTML snippet into BlogEngine's page. Not really sure what was wrong with that tag, because I have never get to test it. Why? Because it is sometimes easier to add simple extension or widget than to deal with row HTML when it comes to BlogEngine. Seriously, it took me way under half an hour following steps in my own simple widget tutorial to put this together, and this is including time spent opening Disby account. More...

Share/Save/Bookmark
Signature
<<  March 2010  >>
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Enhanced with Snapshots

Subscribe to Rtur.net