Inheritance: extends Base
示例#1
0
文件: NewTopic.php 项目: fluxbb/core
 /**
  * Run the action and return a response for the user.
  *
  * @return array
  */
 protected function run()
 {
     $slug = $this->get('slug');
     $category = $this->categories->findBySlug($slug);
     $creator = User::current();
     $now = Carbon::now();
     $conversation = (object) ['poster' => $creator->username, 'title' => $this->get('subject'), 'posted' => $now, 'last_post' => $now, 'last_poster' => $creator->username, 'category_slug' => $category->slug];
     $post = new Post(['poster' => $creator->username, 'poster_id' => $creator->id, 'message' => $this->get('message'), 'posted' => $now]);
     $this->categories->addNewTopic($category, $conversation, $post->toArray());
     $this->raise(new UserHasPosted($creator, $post));
 }
示例#2
0
 protected function handleRequest(Request $request)
 {
     $pid = \Route::input('id');
     // Fetch some info about the topic
     $topic = Post::with('author', 'topic')->findOrFail($pid);
     $this->data['post'] = $post;
     $this->data['action'] = trans('fluxbb::forum.edit_post');
 }
示例#3
0
文件: EditPost.php 项目: fluxbb/core
 protected function run()
 {
     $pid = $this->get('id');
     $post = Post::with('author', 'topic')->findOrFail($pid);
     $creator = User::current();
     $post->fill(['message' => $this->get('message'), 'edited' => Carbon::now(), 'edited_by' => $creator->username]);
     $post->save();
     $this->raise(new PostWasEdited($post, $creator));
     return ['post' => $post];
 }
示例#4
0
 protected function handleRequest(Request $request)
 {
     $pid = \Route::input('id');
     // If a post ID is specified we determine topic ID and page number so we can show the correct message
     $this->post = Post::findOrFail($pid);
     // Determine on which page the post is located
     $numPosts = Post::where('topic_id', '=', $this->post->topic_id)->where('posted', '<', $this->post->posted)->count('id') + 1;
     $dispPosts = User::current()->dispPosts();
     $this->page = ceil($numPosts / $dispPosts);
 }
示例#5
0
 public function get_post($pid)
 {
     // If a post ID is specified we determine topic ID and page number so we can show the correct message
     $post = Post::where('id', '=', $pid)->select(array('topic_id', 'posted'))->first();
     if ($post === NULL) {
         return \Event::first('404');
     }
     $tid = $post->topic_id;
     $posted = $post->posted;
     // Determine on what page the post is located (depending on $forum_user['disp_posts'])
     $num_posts = Post::where('topic_id', '=', $tid)->where('posted', '<', $posted)->count('id') + 1;
     $disp_posts = $this->user()->dispPosts();
     $p = ceil($num_posts / $disp_posts);
     // FIXME: second parameter for $page number
     return $this->get_topic($tid);
 }
示例#6
0
 public function put_topic($fid)
 {
     $forum = Forum::with(array('perms'))->where('id', '=', $fid)->first();
     if ($forum === NULL) {
         return \Event::first('404');
     }
     // TODO: Flood protection
     $rules = array('req_subject' => 'required|max:70', 'req_message' => 'required');
     // TODO: More validation
     if (\Auth::isGuest()) {
         if (Config::enabled('p_force_guest_email') || \Input::get('email') != '') {
             $rules['req_email'] = 'required|email';
         }
         // TODO: banned email
     }
     $validation = $this->make_validator(Input::all(), $rules);
     if ($validation->fails()) {
         return \Redirect::to_action('fluxbb::posting@topic', array($fid))->with_input()->with_errors($validation);
     }
     $topic_data = array('poster' => User::current()->username, 'subject' => \Input::get('req_subject'), 'posted' => \Request::time(), 'last_post' => \Request::time(), 'last_poster' => User::current()->username, 'sticky' => \Input::get('stick_topic') ? '1' : '0', 'forum_id' => $fid);
     if (\Auth::isGuest()) {
         $topic_data['poster'] = $topic_data['last_poster'] = \Input::get('req_username');
     }
     // Create the topic
     $topic = Topic::create($topic_data);
     // To subscribe or not to subscribe
     $topic->subscribe(\Input::get('subscribe'));
     $post_data = array('poster' => User::current()->username, 'poster_id' => User::current()->id, 'poster_ip' => \Request::ip(), 'message' => \Input::get('req_message'), 'hide_smilies' => \Input::get('hide_smilies') ? '1' : '0', 'posted' => \Request::time(), 'topic_id' => $topic->id);
     if (\Auth::isGuest()) {
         $post_data['poster'] = \Input::get('req_username');
         $post_data['poster_email'] = Config::enabled('p_force_guest_email') ? \Input::get('req_email') : \Input::get('email');
     }
     // Create the post ("topic post")
     $post = Post::create($post_data);
     // Update the topic with last_post_id
     $topic->last_post_id = $topic->first_post_id = $post->id;
     $topic->save();
     // Update forum (maybe $forum->update_forum() ?)
     $forum->num_posts += 1;
     $forum->num_topics += 1;
     $forum->last_post = $topic->last_post;
     $forum->last_post_id = $topic->last_post_id;
     $forum->last_poster = $topic->last_poster;
     $forum->save();
     // TODO: update_search_index();
     // If the posting user is logged in, increment his/her post count
     $user = User::current();
     if (\Auth::isAuthed()) {
         $user->num_posts += 1;
         $user->last_post = \Request::time();
         $user->save();
         // TODO: Promote this user to a new group if enabled
     } else {
         $user->online()->update(array('last_post' => \Request::time()));
     }
     return \Redirect::to_action('fluxbb::topic', array($topic->id))->with('message', trans('fluxbb::topic.topic_added'));
 }
示例#7
0
 public function addReply(Post $post)
 {
     $post->topic()->associate($this);
     $this->lastPost()->associate($post);
     $this->forum->lastPost()->associate($post);
 }
示例#8
0
 public function isValid(Post $post)
 {
     $rules = ['message' => 'required'];
     return $this->validation->make($post->getAttributes(), $rules)->passes();
 }
示例#9
0
 protected function handleRequest(Request $request)
 {
     $pid = \Route::input('id');
     $this->post = Post::with('author', 'topic')->findOrFail($pid);
     $this->message = $request->input('req_message');
 }