6 Ben Werdmuller, Dec 18 2006
9 Released under the GPL v2
14 // Configuration - enter your Akismet API key and blog URL (including http://) here
15 // See http://akismet.com/commercial/ for more details.
16 $CFG->akismet
->apikey
= "";
17 $CFG->akismet
->blogurl
= "";
20 function akismet_pagesetup() {
21 // TODO: add a menu item to flagged comments
24 // Initialise the database etc
25 function akismet_init() {
27 global $CFG, $function, $db, $METATABLES;
31 TODO: add flagged comments database and interface to manage false positives
34 // Check for the akismet database
35 if (!in_array($CFG->prefix . "akismet_comments", $METATABLES) || !in_array($CFG->prefix . "akismet_comments", $METATABLES)) {
36 if (file_exists($CFG->dirroot . "mod/akismet/$CFG->dbtype.sql")) {
37 modify_database($CFG->dirroot . "mod/akismet/$CFG->dbtype.sql");
39 error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg Akismet plugin. See the mod/akismet directory.");
41 print_continue("index.php");
45 // Register the event: we want to know when a comment is created
47 listen_for_event("comment","create","akismet_vet");
48 listen_for_event("weblog_comment","create","akismet_vet");
52 // Vet comments for spam
53 function akismet_vet($object_type, $event, $object) {
55 global $CFG, $messages;
57 if (($object_type == "comment" ||
$object_type == "weblog_comment") && !empty($CFG->akismet
->apikey
) && !empty($CFG->akismet
->blogurl
)) {
60 @require_once
($CFG->dirroot
. "mod/akismet/PHP5Akismet.0.2/Akismet.class.php");
62 // Get the parent post
63 $post = get_record('weblog_posts','ident',$object->post_id
);
65 // Generate the post URL
66 if (!isset($object->comment_type
)) {
67 $object->comment_type
= "weblog";
69 switch($object->comment_type
) {
71 $url = $CFG->wwwroot
. user_info("username", $post->weblog
) . "/". $object->comment_type
."/" . $post->ident
. ".html";
76 $akismet = new Akismet($CFG->akismet
->blogurl
,$CFG->akismet
->apikey
);
77 $akismet->setCommentAuthor($object->postedname
);
78 $akismet->setCommentAuthorEmail("");
79 $akismet->setCommentAuthorURL("");
80 $akismet->setCommentContent($object->body
);
81 $akismet->setPermalink($url);
83 if ($akismet->isCommentSpam()) {
84 $messages[] = __gettext("Your comment could not be posted.");