diff options
Diffstat (limited to 'modules/comment/helpers')
-rw-r--r-- | modules/comment/helpers/comment.php | 41 | ||||
-rw-r--r-- | modules/comment/helpers/comment_block.php | 1 | ||||
-rw-r--r-- | modules/comment/helpers/comment_installer.php | 6 |
3 files changed, 47 insertions, 1 deletions
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 3006d73d..92a9e54c 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -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); diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index 7d132646..9231dcd6 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -32,6 +32,7 @@ class comment_block_Core { $view = new View("comments.html"); $view->comments = ORM::factory("comment") ->where("item_id", $theme->item()->id) + ->where("visible", 1) ->orderby("created", "ASC") ->find_all(); diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index be8b2a14..f203d940 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -30,9 +30,15 @@ class comment_installer { `text` text, `created` int(9) NOT NULL, `item_id` int(9) NOT NULL, + `url` varchar(255) default NULL, + `visible` tinyint(1) default 1, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + if (module::is_installed("spam_filter")) { + spam_filter_installer::add_fields(); + } + module::set_version("comment", 1); } } |