function postReply() { if (!Auth::check()) { return Redirect::to("/forums"); } $post_id = Input::get("post_id"); if (isset($post_id)) { //Edit logic $post = ForumPost::find(Input::get("post_id")); $user = Auth::user(); if (!$user->canAccessTopic($post->topic_id)) { return "Access denied."; } if ($post->posted_by == $user->id || $user->isStoryteller()) { $body = ForumPost::replaceSpecialTerms(Input::get("body")); $post->body = $body; if ($user->isStoryteller()) { $post->is_storyteller_reply = Input::get("st-reply") == "on" ? 0 : 1; } $post->save(); //Save an edit record $posted_by = Input::get("post-as"); $poster = User::find($posted_by); if (!$poster) { $poster = Auth::user(); } $edit = new ForumEdit(); $edit->post_id = $post->id; $edit->user_id = $poster->id; $edit->save(); if (Input::get("watch") == "on") { $this->subscribeToTopic($post->topic->id); } return Redirect::to($post->topic->getLinkForLastPost($user)); } else { return "Post does not belong to user"; } } else { $user = Auth::user(); $topic_id = Input::get("topic_id"); $body = Input::get("body"); if ($topic_id == null || $body == null) { //Validate. return "failed."; } else { //Ensure this user has access to the forum to which we're trying to post, and the relevant write permission $topic = ForumTopic::find($topic_id); if ($user->canAccessForum($topic->forum_id)) { $forum = $topic->forum; $permission = PermissionDefinition::find($forum->reply_permission); if (!$forum->reply_permission || Auth::user()->hasPermission($permission->name) || Auth::user()->isStoryteller()) { $posted_by = Input::get("post-as"); $poster_id = $posted_by ? $posted_by : $user->id; $body = ForumPost::replaceSpecialTerms($body); $post = $topic->postReply($poster_id, $body); if ($user->isStoryteller()) { $post->is_storyteller_reply = Input::get("st-reply") == "on" ? 0 : 1; $post->save(); } //Mark the thread as incomplete again. $topic->is_complete = false; $topic->save(); $this->messageSubscribers($post); if (Input::get("watch") == "on") { $this->subscribeToTopic($post->topic->id); } //Check for @mentions. $this->alertMentions($poster_id, $body, $topic); return Redirect::to($post->topic->getLinkForLastPost($user)); } else { return 'No write permission'; } } else { return "No access."; } } } }