Remember the days before spam? A CakePHP Model for Akismet
Posted by Felix Geisendörfer, on Jul 05, 2006 - in PHP & CakePHP » DataSources, Models & Behaviors
Deprecated post
The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.
Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.
Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).
Note: I did a little Online Demo for the stuff explained below, you might want to check it out.
"Remember the days before spam", that's what it reads when you vist akismet.com, and I have to admit, no, I don't remember them ; ). Spam has been an issue for me ever since I got my first email adress. But nowdays spam scripts not only spam standardized applications like wordpress, no, they also try to figure out how to spam your personal contact/guesbook/whatever forms and are pretty good at it.
Here on ThinkingPHP.org, I get about 40~100 spam comments every day, tendency increasing. So at some point the manual deletion and blacklist filters didn't cut it any longer. Gladly, Daniel Hofstetter (Cake Baker) pointed me to a wonderful wordpress plugin called Akismet, which also is a service, dedicated to eliminate spam.
So far I've been really impressed with it. The plugin/service already filtered out 4149 spam comments for me, with no false-positives in them. Only 2 comments made it through their filters. That's a 99,95% accuracy. Truly Amazing! But now here is the best thing, their API is open to the public, and everybody can get a free key over at wordpress.com. However, if you are working on a commercial application you should checkout their restrictions / prices regarding the Commercial Use of API Keys.
Today I finally found the time to get around to write a CakePHP Web Model for their service. It bases on my Web Model class from the Web Model package I'm maintaining. Integration and usage are as simple as it get's. You just download the Web Model, put it in /app/web_model.php and then download the Akismet Model and put it in /app/models/akismet.php.
Now that you have done this, checking a comment for spam is as easy as this:
-
class AkismetTestController extends AppController
-
{
-
var $name = 'AkismetTest';
-
-
function beforeFilter()
-
{
-
$this->Akismet->apiKey = 'your-api-key';
-
}
-
-
function index()
-
{
-
'comment_author_email' => 'i-spam@mcirosoft.com',
-
'comment_author' => 'Viagra rocks, dude!');
-
$result = $this->Akismet->checkComment($comment);
-
-
debug($result);
-
// If the comment is Spam, $result == 'true', if not
-
// $result == 'false'.
-
}
-
}
For a complete list of $comment options, see: http://akismet.com/development/api/#comment-check.
The Model also allows you to manually mark comments as spam and to report false positives. Just take a look at the code , it's pretty self explanatory I hope.
So, I'd be happy to get some feedback from those people who struggle(d) with spam on their (cakephp) sites like I did. Good Luck in the war against spam ; )!
--Felix Geisendörfer aka the_undefined