Project Steve Guttenberg

Using Akismet with PSG

Posted by Gavin on Friday, January 5, 2007 (Link)

Akismet is a web service that provides spam filtering for blog comments, forum posts and wiki edits. It's free for personal use but commercial users pay a $5 monthly license fee. I just wrote a simple plugin for PSG to support Akismet filtering of comment posts, using the PHP class developed by Alex Potsides.

The code in PSG that allows for this plugin (and the previous plugin for captchas.net) is currently only available in CVS, but we're due to release a new version soon, so stay tuned for the next release. Together, these two plugins have completely eliminated all comment spam on the sites I run, so I thoroughly recommend making use of them.

<?php

require_once('PHP5Akismet.0.2/Akismet.class.php');

$GLOBALS[conf][comment_post_validate_function] = 'akismetValidate';
$GLOBALS[conf][akismet_key] = '<your akismet API key>';

function 
akismetValidate($comment) {
  global 
$conf;
  
$akismet = new Akismet(
    
sprintf('http://%s%s'$_SERVER[SERVER_NAME], $_SERVER[SCRIPT_NAME]),
    
$conf[akismet_key]
  );
  
$akismet->setCommentAuthor($comment[name]);
  
$akismet->setCommentAuthorEmail($comment[email]);
  
$akismet->setCommentAuthorURL($comment[url]);
  
$akismet->setCommentContent($comment[body]);
  
$akismet->setPermalink(sprintf(
    
'http://%s%s',
    
$_SERVER[SERVER_NAME],
    
articleUri($_REQUEST[id])
  ));
  return (
$akismet->isCommentSpam() ? false true);
}

?>

<< Previous: Using captchas with Project Steve GuttenbergNext: PSG's fifth anniversary >>

[ Archives | Search | Syndicate ]
© 2008 ProjectSteveGuttenberg.org.