상속: extends Illuminate\Database\Eloquent\Model
예제 #1
0
 public function reply(HttpRequest $request, $id)
 {
     $topic = Topic::findOrFail($id);
     $this->authorizePost($topic->forum, $topic);
     $this->validate($request, ['body' => 'required']);
     if ($topic->addPost(Auth::user(), Request::input('body'), false)) {
         $posts = Post::where('post_id', $topic->topic_last_post_id)->get();
         $postsPosition = $topic->postsPosition($posts);
         Event::fire(new TopicWasReplied($topic, $posts->last(), Auth::user()));
         return view('forum.topics._posts', compact('posts', 'postsPosition', 'topic'));
     }
 }
예제 #2
0
 public function show($id)
 {
     $postStartId = Request::input('start');
     $postEndId = get_int(Request::input('end'));
     $nthPost = get_int(Request::input('n'));
     $skipLayout = Request::input('skip_layout') === '1';
     $jumpTo = null;
     $topic = Topic::with(['forum.cover', 'pollOptions.votes'])->findOrFail($id);
     priv_check('ForumView', $topic->forum)->ensureCan();
     $posts = $topic->posts();
     if ($postStartId === 'unread') {
         $postStartId = Post::lastUnreadByUser($topic, Auth::user());
     } else {
         $postStartId = get_int($postStartId);
     }
     if ($nthPost !== null) {
         $post = $topic->nthPost($nthPost);
         if ($post) {
             $postStartId = $post->post_id;
         }
     }
     if (!$skipLayout) {
         foreach ([$postStartId, $postEndId, 0] as $jumpPoint) {
             if ($jumpPoint === null) {
                 continue;
             }
             $jumpTo = $jumpPoint;
             break;
         }
     }
     if ($postStartId !== null && !$skipLayout) {
         // move starting post up by ten to avoid hitting
         // page autoloader right after loading the page.
         $postPosition = $topic->postPosition($postStartId);
         $post = $topic->nthPost($postPosition - 10);
         $postStartId = $post->post_id;
     }
     if ($postStartId !== null) {
         $posts = $posts->where('post_id', '>=', $postStartId);
     } elseif ($postEndId !== null) {
         $posts = $posts->where('post_id', '<=', $postEndId)->orderBy('post_id', 'desc');
     }
     $posts = $posts->take(20)->with('topic')->with('user.rank')->with('user.country')->with('user.supports')->get()->sortBy('post_id');
     if ($posts->count() === 0) {
         abort($skipLayout ? 204 : 404);
     }
     $postsPosition = $topic->postsPosition($posts);
     $pollSummary = PollOption::summary($topic, Auth::user());
     Event::fire(new TopicWasViewed($topic, $posts->last(), Auth::user()));
     $template = $skipLayout ? '_posts' : 'show';
     $cover = json_item($topic->cover()->firstOrNew([]), new TopicCoverTransformer());
     $isWatching = TopicWatch::check($topic, Auth::user());
     return view("forum.topics.{$template}", compact('cover', 'isWatching', 'jumpTo', 'pollSummary', 'posts', 'postsPosition', 'topic'));
 }
예제 #3
0
 public function show($id)
 {
     $post = Post::findOrFail($id);
     priv_check('ForumView', $post->forum)->ensureCan();
     return ujs_redirect(post_url($post->topic_id, $post->post_id));
 }
예제 #4
0
 public function description()
 {
     $topic = Topic::find($this->thread_id);
     if ($topic === null) {
         return;
     }
     $post = Post::find($topic->topic_first_post_id);
     // Any description (after the first match) that matches
     // '[-{15}]' within its body doesn't get split anymore,
     // and gets stored in $split[1] anyways
     $split = preg_split('[-{15}]', $post->post_text, 2);
     // Return empty description if the pattern was not found
     // (mostly older beatmapsets)
     $description = $split[1] ?? '';
     return (new \App\Libraries\BBCodeFromDB($description, $post->bbcode_uid, true))->toHTML(true);
 }
예제 #5
0
 public function show($id)
 {
     $post = Post::findOrFail($id);
     $this->authorizeView($post->forum);
     return redirect(post_url($post->topic_id, $post->post_id));
 }
예제 #6
0
 public function reply(HttpRequest $request, $id)
 {
     $topic = Topic::findOrFail($id);
     $this->authorizePost($topic->forum, $topic);
     $this->validate($request, ["body" => "required"]);
     if ($topic->addPost(Auth::user(), Request::input("body"), false)) {
         $posts = Post::where("post_id", $topic->topic_last_post_id)->get();
         $postsPosition = $topic->postsPosition($posts);
         Event::fire(new TopicWasReplied($topic, $posts->last(), Auth::user()));
         return view("forum.topics._posts", compact("posts", "postsPosition", "topic"));
     }
 }