diff options
-rw-r--r-- | modules/comment/controllers/admin_comments.php | 3 | ||||
-rw-r--r-- | modules/comment/controllers/comments.php | 15 | ||||
-rw-r--r-- | modules/comment/helpers/comment.php | 9 |
3 files changed, 25 insertions, 2 deletions
diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 68ede43d..c4bdb92b 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -126,6 +126,9 @@ class Admin_Comments_Controller extends Admin_Controller { $comment->state = $state; $comment->save(); module::event("comment_updated", $orig, $comment); + if ($orig->state == "published" || $comment->state == "published") { + module::event("item_related_update", $comment->item); + } } } diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 998ed1ac..1b936671 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -59,7 +59,20 @@ class Comments_Controller extends REST_Controller { access::required("view", $item); $form = comment::get_add_form($item); - if ($form->validate()) { + $valid = $form->validate(); + if ($valid) { + if (user::active()->guest && !$form->add_comment->inputs["name"]->value) { + $form->add_comment->inputs["name"]->add_error("missing", 1); + $valid = false; + } + + if (!$form->add_comment->text->value) { + $form->add_comment->text->add_error("missing", 1); + $valid = false; + } + } + + if ($valid) { $comment = comment::create( $item, user::active(), $form->add_comment->text->value, diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 329d5ba3..6e204ace 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -59,9 +59,13 @@ class comment_Core { $comment->server_remote_addr = substr($input->server("REMOTE_ADDR"), 0, 32); $comment->server_remote_host = substr($input->server("REMOTE_HOST"), 0, 64); $comment->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16); - $comment->save(); + module::event("comment_created", $comment); + if ($comment->state == "published") { + module::event("item_related_update", $comment->item()); + } + return $comment; } @@ -87,7 +91,10 @@ class comment_Core { $group->inputs["name"]->value($active->full_name)->disabled("disabled"); $group->email->value($active->email)->disabled("disabled"); $group->url->value($active->url)->disabled("disabled"); + } else { + $group->inputs["name"]->error_messages("missing", t("You must provide a name")); } + $group->text->error_messages("missing", t("You must provide a comment")); return $form; } |