public function action_edit($id = null) { if (!isset($_SESSION['user_id'])) { return Response::redirect('login'); } is_null($id) and Response::redirect('Comment'); if (!($comment = Model_Comment::find($id))) { console . log('error', 'Could not find comment #' . $id); Response::redirect('Comment'); } $val = Model_Comment::validate('edit'); if ($val->run()) { $comment->author = Input::post('author'); $comment->content = Input::post('content'); $comment->entry_id = Input::post('entry_id'); if ($comment->save()) { console . log('success', 'Updated comment #' . $id); Response::redirect('comment'); } else { console . log('error', 'Could not update comment #' . $id); } } else { if (Input::method() == 'POST') { $comment->author = $val->validated('author'); $comment->content = $val->validated('content'); $comment->entry_id = $val->validated('entry_id'); console . log('error', $val->error()); } $this->template->set_global('comment', $comment, false); } $this->template->title = "Comments"; $this->template->content = View::forge('comment/edit'); }
public function action_edit($id = null) { $comment = Model_Comment::find($id); $val = Model_Comment::validate('edit'); if ($val->run()) { $comment->name = Input::post('name'); $comment->email = Input::post('email'); $comment->website = Input::post('website'); $comment->message = Input::post('message'); $comment->post_id = Input::post('post_id'); if ($comment->save()) { Session::set_flash('success', 'Updated comment #' . $id); Response::redirect('admin/comments'); } else { Session::set_flash('error', 'Could not update comment #' . $id); } } else { if (Input::method() == 'POST') { $comment->name = $val->validated('name'); $comment->email = $val->validated('email'); $comment->website = $val->validated('website'); $comment->message = $val->validated('message'); $comment->post_id = $val->validated('post_id'); Session::set_flash('error', $val->show_errors()); } $this->template->set_global('comment', $comment, false); } $this->template->title = "Comments"; $this->template->content = View::forge('admin/comments/edit'); }
private function saveComment(Model_Comment $comment, View_Html $view) { if (isset($_REQUEST['save'])) { $comment->setData($_POST); if (!($errors = $comment->validate())) { $comment->save(); $view->redir('Admin_Article', 'edit', array('id' => $comment->article)); return true; } $view->errors = $errors; } return false; }
private function saveComment(View_Html $view) { if (in_array("comments", $view->article->flags) && $_POST['comment'] === 'save' && !$_POST['comment_url']) { $comment = new Model_Comment($this->getStorage()); $comment->username = nl2br(htmlspecialchars(strip_tags($_POST['comment_username']))); $comment->email = $_POST['comment_email']; $comment->title = nl2br(htmlspecialchars(strip_tags($_POST['comment_title']))); $comment->content = nl2br(htmlspecialchars(strip_tags($_POST['comment_content']))); $comment->article = $view->article->getId(); //$comment->owner = $view->article->owner; //$comment->group = $view->article->group; if (empty($comment->title)) { $comment->title = "Без темы"; } if (!($errors = $comment->validate())) { $comment->save(); $view->redir("Default", "article", array('path' => $view->topic->getPath(), 'article' => $view->article->getId())); return true; } $view->errors = $errors; $view->newComment = $comment; } return false; }