author_id = $author->id; $comment->guest_email = $guest_email; $comment->guest_name = $guest_name; $comment->guest_url = $guest_url; $comment->item_id = $item->id; $comment->text = $text; $comment->state = "published"; // These values are useful for spam fighting, so save them with the comment. $input = Input::instance(); $comment->server_http_accept = $input->server("HTTP_ACCEPT"); $comment->server_http_accept_charset = $input->server("SERVER_HTTP_ACCEPT_CHARSET"); $comment->server_http_accept_encoding = $input->server("HTTP_ACCEPT_ENCODING"); $comment->server_http_accept_language = $input->server("HTTP_ACCEPT_LANGUAGE"); $comment->server_http_connection = $input->server("HTTP_CONNECTION"); $comment->server_http_host = $input->server("HTTP_HOST"); $comment->server_http_referer = $input->server("HTTP_REFERER"); $comment->server_http_user_agent = $input->server("HTTP_USER_AGENT"); $comment->server_query_string = $input->server("QUERY_STRING"); $comment->server_remote_addr = $input->server("REMOTE_ADDR"); $comment->server_remote_host = $input->server("REMOTE_HOST"); $comment->server_remote_port = $input->server("REMOTE_PORT"); $comment->save(); module::event("comment_created", $comment); return $comment; } static function get_add_form($item) { $form = new Forge("comments", "", "post"); $group = $form->group("add_comment")->label(t("Add comment")); $group->input("name") ->label(t("Name")) ->id("gAuthor"); $group->input("email") ->label(t("Email (hidden)")) ->id("gEmail"); $group->input("url") ->label(t("Website (hidden)"))->id("gUrl"); $group->textarea("text")->label(t("Comment")) ->id("gText"); $group->hidden("item_id")->value($item->id); $group->submit(t("Add")); // Forge will try to reload any pre-seeded values upon validation if it's a post request, so // force validation before seeding values. // @todo make that an option in Forge if (request::method() == "post") { $form->validate(); } $active = user::active(); if (!$active->guest) { $group->inputs["name"]->value($active->full_name)->disabled("disabled"); $group->email->value($active->email)->disabled("disabled"); $group->url->value($active->url)->disabled("disabled"); } return $form; } static function get_edit_form($comment) { $form = new Forge("comments/{$comment->id}?_method=put", "", "post"); $group = $form->group("edit_comment")->label(t("Edit comment")); $group->input("name") ->label(t("Author")) ->id("gAuthor"); $group->input("email") ->label(t("Email (hidden)")) ->id("gEmail"); $group->input("url") ->label(t("Website (hidden)"))->id("gUrl"); $group->textarea("text")->label(t("Comment")) ->id("gText"); $group->submit(t("Edit")); $group->text = $comment->text; $author = $comment->author(); if ($author->guest) { $group->inputs["name"]->value = $comment->guest_name; $group->email = $comment->guest_email; $group->url = $comment->guest_url; } else { $group->inputs["name"]->value($author->full_name)->disabled("disabled"); $group->email->value($author->email)->disabled("disabled"); $group->url->value($author->url)->disabled("disabled"); } return $form; } }