SpamCheck library

Some time ago there was a thread in the forums concerning a Spam Check library for Kohana. I can’t find it now but in the thread I made a suggestion for the architecture of such a library. Two weeks ago or so I was bored and created a proof of concept.

Below you can see an example of the library checking the ‘content’ field for links and gives a penalty if there are two many.

$spam=new SpamCheck;
$spam->add_check('links')->set_link_penalty(4)->set_max_links(2); 
$spam->add_field('content','some content');
$score=$spam->check();
if(!$spam->is_spam())
   echo 'no spam';

This example shows usage of giving weights to certain checks and usage of the Akismet library

$spam=new SpamCheck;
$spam->add_check('links',2)->set_max_links(2); 
$spam->add_check('akismet')->setAPIKey('api_key')->setBlogURL('http://blog url');
$spam->set_weight('akismet',1);
$spam->add_field('content','some content');
$score=$spam->check();
if(!$spam->is_spam())
   echo 'no spam';
 
$spam->get_weighted_scores();
$spam->get_scores();

I quite enjoy the extensibility of this library as you can easily add new checks such as other Akismet like API’s, or checks looking for certain words and giving out penalties based on that. How do you like it? Is it any good? If so I can add new functionality :)


3 Responses to “SpamCheck library”

  1. tahlon Says:

    Yep, looks really good. I like it :)

  2. spirit Says:

    Nice indeed! The post you didn’t find is here http://forum.kohanaphp.com/comments.php?DiscussionID=601

    And as Rick pointed out, this aritcle on snook.ca is really interesting for penalty rules http://snook.ca/archives/other/effective_blog_comment_spam_blocker/

  3. neovive Says:

    This looks very useful and promising. Maybe merging this into a SpamCheck module anyone with a config file for the various API keys would work well.

Leave a Comment