Inheritance: extends Illuminate\Database\Eloquent\Model
Example #1
0
 public function testIssuesWithKeywordAsTitle()
 {
     $topic = new Topic();
     $topic->forum_id = config('osu.forum.help_forum_ids')[0];
     $topic->topic_title = 'invalid herp a derp';
     $this->assertEquals([], $topic->issues());
 }
Example #2
0
 public function lastTopic($withSubforums = true)
 {
     if ($this->lastTopic === null) {
         $this->lastTopic = [Topic::whereIn('forum_id', $this->allSubforums())->orderBy('topic_last_post_time', 'desc')->first()];
     }
     return $this->lastTopic[0];
 }
Example #3
0
 public function lastTopic($recursive = true)
 {
     $key = $recursive === true ? 'recursive' : 'current';
     if (isset($this->_lastTopic[$key]) === false) {
         $this->_lastTopic[$key] = Topic::whereIn('forum_id', $recursive ? $this->allSubforums() : [$this->forum_id])->orderBy('topic_last_post_time', 'desc')->first();
     }
     return $this->_lastTopic[$key];
 }
Example #4
0
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     priv_check('ForumPostDelete', $post)->ensureCan();
     $deletedPostPosition = $post->topic->postPosition($post->post_id);
     $post->topic->removePost($post, Auth::user());
     $topic = Topic::find($post->topic_id);
     if ($topic === null) {
         $redirect = route('forum.forums.show', $post->forum);
         return ujs_redirect($redirect);
     }
     return ['postId' => $post->post_id, 'postPosition' => $deletedPostPosition];
 }
Example #5
0
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $this->authorizePost($post->forum, $post->topic);
     if (!$post->canBeDeletedBy(Auth::user())) {
         abort(403);
     }
     $deletedPostPosition = $post->topic->postPosition($post->post_id);
     $post->topic->removePost($post);
     $topic = Topic::find($post->topic_id);
     if ($topic === null) {
         $redirect = route('forum.forums.show', $post->forum);
         return ujs_redirect($redirect);
     }
     return ['postId' => $post->post_id, 'postPosition' => $deletedPostPosition];
 }
 public function store()
 {
     if (Request::hasFile('cover_file') !== true) {
         abort(422);
     }
     $topic = null;
     if (presence(Request::input('topic_id')) !== null) {
         $topic = Topic::findOrFail(Request::input('topic_id'));
         priv_check('ForumTopicEdit', $topic)->ensureCan();
         if ($topic->cover !== null) {
             abort(422);
         }
     }
     try {
         $cover = TopicCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $topic);
     } catch (ImageProcessorException $e) {
         return error_popup($e->getMessage());
     }
     return json_item($cover, new TopicCoverTransformer());
 }
Example #7
0
 public function store()
 {
     if (Request::hasFile('cover_file') !== true) {
         abort(422);
     }
     $topic = null;
     if (presence(Request::input('topic_id')) !== null) {
         $topic = Topic::findOrFail(Request::input('topic_id'));
         $this->authorizePost($topic->forum, $topic);
         if ($topic->canBeEditedBy(Auth::user()) !== true) {
             abort(403);
         }
         if ($topic->cover !== null) {
             abort(422);
         }
     }
     try {
         $cover = TopicCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $topic);
     } catch (ImageProcessorException $e) {
         return error_popup($e->getMessage());
     }
     return fractal_item_array($cover, new TopicCoverTransformer());
 }
Example #8
0
 public function lock($id)
 {
     // FIXME: should be moderator check?
     // And maybe even its own controller or something.
     if (Auth::user()->isAdmin() !== true) {
         abort(403);
     }
     $topic = Topic::findOrFail($id);
     $lock = Request::input('lock') !== '0';
     $topic->lock($lock);
     return ['message' => trans('forum.topics.lock.locked-' . ($lock === true ? '1' : '0'))];
 }
Example #9
0
 public function updatePage($text)
 {
     if ($this->userPage === null) {
         DB::transaction(function () use($text) {
             $topic = Forum\Topic::createNew(Forum\Forum::find(config('osu.user.user_page_forum_id')), "{$this->username}'s user page", $this, $text, false);
             $this->update(['userpage_post_id' => $topic->topic_first_post_id]);
         });
     } else {
         $this->userPage->edit($text, $this);
     }
     return $this->fresh();
 }
Example #10
0
 public function watch($id)
 {
     $topic = Topic::findOrFail($id);
     $state = get_bool(Request::input('watch'));
     $privName = 'ForumTopicWatch' . ($state ? 'Add' : 'Remove');
     $type = 'watch';
     priv_check($privName, $topic)->ensureCan();
     TopicWatch::toggle($topic, Auth::user(), $state);
     switch (Request::input('page')) {
         case 'manage':
             $topics = Topic::watchedByUser(Auth::user())->get();
             $topicReadStatus = TopicTrack::readStatus(Auth::user(), $topics);
             // there's currently only destroy action from watch index
             return js_view('forum.topic_watches.destroy', compact('topic', 'topics', 'topicReadStatus'));
         default:
             return js_view('forum.topics.replace_button', compact('topic', 'type', 'state'));
     }
 }
Example #11
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);
 }
 public function index()
 {
     $topics = Topic::watchedByUser(Auth::user())->get();
     $topicReadStatus = TopicTrack::readStatus(Auth::user(), $topics);
     return view('forum.topic_watches.index', compact('topics', 'topicReadStatus'));
 }
Example #13
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'));
     }
 }
Example #14
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"));
     }
 }