public function action_detail($id = 0) { $data["forum"] = Model_Forum::find($id); if ($data["forum"] == null) { Response::redirect("/teachers/forum/"); } if (Input::get("del_id", null) != null) { $del_comment = Model_Comment::find(Input::get("del_id", 0)); if ($del_comment->user_id == $this->user->id) { $del_comment->deleted_at = time(); $del_comment->save(); } } // add if (Input::post("body", "") != "" and Security::check_token()) { // save $comment = Model_Comment::forge(); $comment->body = Input::post("body", ""); $comment->forum_id = $id; $comment->user_id = $this->user->id; $comment->save(); } $data["user"] = $this->user; $view = View::forge("teachers/forum/detail", $data); $this->template->content = $view; }
public function action_create($id = null) { if (Input::post()) { $comment = Model_Comment::forge(array('name' => Auth::instance()->get_screen_name(), 'comment' => Input::post('comment'), 'blog_id' => Input::post('blog_id'))); if ($comment and $comment->save()) { Session::set_flash('success', 'Added comment #' . $comment->id . '.'); Response::redirect('blog/view/' . $comment->blog_id); } else { Session::set_flash('error', 'Could not save comment.'); } } else { $this->template->set_global('blog', $id, false); } $data["subnav"] = array('create' => 'active'); $this->template->title = 'Comments » Create'; $data['form'] = View::forge('comments/_form'); $this->template->content = View::forge('comments/create', $data); }
public function action_create($id = null) { if (Fuel\Core\Input::post()) { $comment = Model_Comment::forge(array('name' => Fuel\Core\Input::post('comment'), 'comment' => Fuel\Core\Input::post('comment'), 'message_id' => Fuel\Core\Input::post('message_id'))); if ($comment and $comment->save()) { Fuel\Core\Session::set_flash('success', 'Added comment #' . $comment->id . '.'); Fuel\Core\Response::redirect('messages/view/' . $comment->message_id); } else { Fuel\Core\Session::set_flash('error', 'Could not save comment'); } } else { $this->template->set_global('message', $id, false); } $data["subnav"] = array('create' => 'active'); $this->template->title = 'Comments » Create'; $data['form'] = View::forge('comments/_form'); $this->template->content = View::forge('comments/create', $data); }
public function action_create($id = null) { if (Input::method() == 'POST') { $val = Model_Comment::validate('create'); if ($val->run()) { $comment = Model_Comment::forge(array('name' => Input::post('name'), 'email' => Input::post('email'), 'website' => Input::post('website'), 'message' => Input::post('message'), 'post_id' => Input::post('post_id'))); if ($comment and $comment->save()) { Session::set_flash('success', 'Added comment #' . $comment->id . '.'); Response::redirect('admin/comments'); } else { Session::set_flash('error', 'Could not save comment.'); } } else { Session::set_flash('error', $val->show_errors()); } } $this->template->title = "Comments"; $this->template->content = View::forge('admin/comments/create'); }
public function action_create() { if (!isset($_SESSION['user_id'])) { return Response::redirect('login'); } if (Input::method() == 'POST') { $val = Model_Comment::validate('create'); if ($val->run()) { $comment = Model_Comment::forge(array('author' => Input::post('author'), 'content' => Input::post('content'), 'entry_id' => Input::post('entry_id'))); if ($comment and $comment->save()) { Response::redirect('entry/view/' . $comment->entry_id); } else { console . log('error', 'Could not save comment.'); } } else { console . log('error', $val->error()); } } $this->template->title = "Comments"; $this->template->content = View::forge('comment/create'); }
public static function save($data = array()) { $comment = Model_Comment::forge($data); return $comment and $comment->save(); }
public function action_detail($id = 0) { $data['pasts'] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", 0)], ["deleted_at", 0]]]); $data["donetrial"] = Model_Lessontime::find("all", ["where" => [["student_id", $this->user->id], ["status", 2], ["language", Input::get("course", -1)], ["deleted_at", 0]]]); $data["forum"] = Model_Forum::find($id); if ($data["forum"] == null) { Response::redirect("/students/forum/"); } if (Input::get("del_id", null) != null) { $del_comment = Model_Comment::find(Input::get("del_id", 0)); if ($del_comment->user_id == $this->user->id) { $del_comment->deleted_at = time(); $del_comment->save(); } } // add if (Input::post("body", "") != "" and Security::check_token()) { // save $comment = Model_Comment::forge(); $comment->body = Input::post("body", ""); $comment->forum_id = $id; $comment->user_id = $this->user->id; $comment->save(); } $data["user"] = $this->user; $view = View::forge("students/forum/detail", $data); $this->template->content = $view; }
public function action_comment($Pid = 0) { //トークンの生成 $this->data['token_key'] = Config::get('security.csrf_token_key'); $this->data['token'] = Security::fetch_token(); //バリデーション $val = Validation::forge(); $val->add('comment', 'コメント')->add_rule('max_length', 200); if (Input::post()) { if (Security::check_token()) { if ($val->run()) { //Commentモデルのオブジェクトを定義 $comment = Model_Comment::forge(); //Commentテーブルに値を格納する $comment->username = Auth::get_screen_name(); $comment->Pid = $Pid; $comment->CoContent = Input::post('comment'); //save処理が行われたら「 post/detail 」にリダイレクト $comment->save(); Profiler::mark('ココ'); $this->data['posts'] = Model_Post::query()->where('Pid', '=', $Pid)->get(); $this->data['comments'] = Model_Comment::query()->where('Pid', '=', $Pid)->get(); $this->action_categorize(); $view = View::forge('post/PostsDetail', $this->data); $view->set_global('error', $this->error, false); } else { Profiler::mark('ココダ'); $this->error = $val->error(); $this->data['posts'] = Model_Post::query()->where('Pid', '=', $Pid)->get(); $this->data['comments'] = Model_Comment::query()->where('Pid', '=', $Pid)->get(); $this->action_categorize(); $view = View::forge('post/PostsDetail', $this->data); Profiler::mark('ココダ'); $view->set_global('error', $this->error, false); } } else { Profiler::mark('CSRFです'); } } return $view; }
public function action_show($slug = false, $snippet = false) { $this->data['snippet'] = $snippet; // Get post by slug $post = $this->data['post'] = Model_Post::query()->where('slug', $slug)->get_one(); if (!$post) { \Messages::error(__('frontend.post.not-found')); \Response::redirect_back(\Router::get('homepage')); } else { // Prepare comment form fieldset $form = \Fieldset::forge('post_comment'); $form->add_model('Blog\\Model_Comment'); $form->add('submit', '', array('type' => 'submit', 'value' => __('submit'), 'class' => 'btn btn-primary')); // If submit comment if (\Input::post('submit')) { $form->validation()->run(); if (!$form->validation()->error()) { // Create and populate the comment object $comment = Model_Comment::forge(); $comment->from_array(array('username' => $form->validated('username'), 'mail' => $form->validated('mail'), 'content' => $form->validated('content'), 'post_id' => $post->id)); if ($comment->save()) { \Messages::success(__('frontend.comment.added')); \Response::redirect_back(\Router::get('show_post', array('segment' => $post->slug))); } else { \Messages::error(__('error')); } } else { // Output validation errors foreach ($form->validation()->error() as $error) { \Messages::error($error); } } } $form->repopulate(); $this->data['form'] = $form; return \Response::forge(\View::forge('frontend/post/show')->set($this->data, null, false)); } }