Changes to the comment module to support spam filtering. Basically added two columns to the comment table. The url of the author's web site(default null) and a flag to indicate that the comment is visible (default true).

The comment block has changed to only display comments that are visible.

And there is code added to call the spam_filter helper if the spam_filter module is installed.
This commit is contained in:
Tim Almdal
2008-12-29 19:37:19 +00:00
parent 3c0be5156b
commit 95f1440ef2
6 changed files with 100 additions and 17 deletions

View File

@@ -36,27 +36,65 @@ class comment_Core {
* @param string $email author's email
* @param string $text comment body
* @param integer $item_id id of parent item
* @param string $url author's url
* @return Comment_Model
*/
static function create($author, $email, $text, $item_id) {
static function create($author, $email, $text, $item_id, $url) {
$comment = ORM::factory("comment");
$comment->author = $author;
$comment->email = $email;
$comment->text = $text;
$comment->item_id = $item_id;
$comment->url = $url;
$comment->created = time();
// @todo Figure out how to mock up the test of the spam_filter
if (module::is_installed("spam_filter") && !TEST_MODE) {
spam_filter::verify_comment($comment);
} else {
$comment->visible = true;
}
$comment->save();
module::event("comment_created", $comment);
return $comment;
}
/**
* Update an existing comment.
* @param Comment_Model $comment
* @param string $author author's name
* @param string $email author's email
* @param string $text comment body
* @param string $url author's url
* @return Comment_Model
*/
static function update($comment, $author, $email, $text, $url) {
$comment->author = $author;
$comment->email = $email;
$comment->text = $text;
$comment->url = $url;
// @todo Figure out how to mock up the test of the spam_filter
if (module::is_installed("spam_filter") && !TEST_MODE) {
spam_filter::verify_comment($comment);
}
$comment->save();
if ($comment->saved) {
module::event("comment_updated", $comment);
}
return $comment;
}
static function get_add_form($item) {
$form = new Forge("comments", "", "post");
$group = $form->group("add_comment")->label(_("Add comment"));
$group->input("author") ->label(_("Author")) ->id("gAuthor");
$group->input("email") ->label(_("Email")) ->id("gEmail");
$group->input("url") ->label(_("Website")) ->id("gUrl");
$group->textarea("text")->label(_("Text")) ->id("gText");
$group->hidden("item_id")->value($item->id);
$group->submit(_("Add"));
@@ -69,6 +107,7 @@ class comment_Core {
$group = $form->group("edit_comment")->label(_("Edit comment"));
$group->input("author") ->label(_("Author")) ->id("gAuthor") ->value($comment->author);
$group->input("email") ->label(_("Email")) ->id("gEmail") ->value($comment->email);
$group->input("url") ->label(_("Website")) ->id("gUrl") ->value($comment->url);
$group->textarea("text")->label(_("Text")) ->id("gText") ->value($comment->text);
$group->submit(_("Edit"));
$form->add_rules_from($comment);