Example #1
0
 /**
  * @param Topic $topic
  *
  * @return bool
  */
 public function deleteTopic(Topic $topic)
 {
     if ($topic->deleted_at == null) {
         $topic->forum->decrement('num_topics');
         $topic->forum->decrement('num_posts', $topic->num_posts);
         if ($topic->user_id > 0) {
             $topic->author->decrement('num_topics');
         }
         $success = $topic->delete();
         if ($success) {
             if ($topic->last_post_id == $topic->forum->last_post_id) {
                 $this->forumRepository->updateLastPost($topic->forum);
             }
         }
         return $success;
     } else {
         // First we need to remove old foreign keys - otherwise we can't delete posts
         $topic->update(['first_post_id' => null, 'last_post_id' => null]);
         // Now delete the posts for this topic
         $this->postRepository->deletePostsForTopic($topic);
         // Don't forget the polls
         if ($topic->has_poll) {
             $this->pollRepository->remove($topic->poll);
         }
         // And finally delete the topic
         $topic->forceDelete();
     }
     return true;
 }
Example #2
0
 /**
  * @param mixed $content
  * @param array $options
  *
  * @return mixed
  */
 public function apply($content, array $options = [])
 {
     if ($this->supports($content, $options)) {
         $forum = $this->forumRepository->find($options['forum_id']);
         $this->moveTopic($content, $forum);
     }
 }
Example #3
0
 /**
  * @return RenderableInterface[]
  */
 public function fields()
 {
     $forums = $this->forumRepository->all();
     $options = [];
     foreach ($forums as $forum) {
         $options[$forum->id] = $forum->title;
     }
     return [(new Field('select', 'forum_id', trans('moderation.move_topic_forum_id_name'), trans('moderation.move_topic_forum_id_description')))->setOptions($options)];
 }
Example #4
0
 /**
  * @return \Illuminate\View\View
  */
 public function index()
 {
     // Forum permissions are checked in "getIndexTree"
     $forumsList = $this->forumRepository->getIndexTree();
     $forums = [];
     $makeLists = function (&$forums, &$list, $tab = '') use(&$makeLists) {
         foreach ($list as $forum) {
             $forums[$forum->id] = $tab . $forum->title;
             if (!empty($forum->children)) {
                 $makeLists($forums, $forum->children, $tab . '    ');
             }
         }
     };
     $makeLists($forums, $forumsList);
     return view('search.index', compact('forums'));
 }
Example #5
0
 /**
  * Shows a specific forum.
  *
  * @param Request $request
  * @param string  $slug    The slug of the forum to show.
  *
  * @param int     $id      The ID of the forum to show.
  *
  * @return \Illuminate\View\View
  */
 public function show(Request $request, $slug = '', $id = 0)
 {
     // Forum permissions are checked in "find"
     $forum = $this->forumRepository->find($id);
     // Load last post information for child forums
     $forum->load(['children.lastPost', 'children.lastPost.topic', 'children.lastPostAuthor']);
     if (!$forum) {
         throw new ForumNotFoundException();
     }
     $this->breadcrumbs->setCurrentRoute('forums.show', $forum);
     // Build the order by/dir parts
     $allowed = ['lastpost', 'replies', 'startdate', 'title'];
     $orderBy = $request->get('orderBy', 'lastpost');
     if (!in_array($orderBy, $allowed)) {
         $orderBy = 'lastpost';
     }
     $orderDir = $request->get('orderDir', 'desc');
     if ($orderDir != 'asc' && $orderDir != 'desc') {
         $orderDir = 'desc';
     }
     // We need to know how to build the url...
     $urlDirs = ['lastpost' => 'desc', 'replies' => 'desc', 'startdate' => 'desc', 'title' => 'asc'];
     if ($orderDir == 'desc' && $urlDirs[$orderBy] == 'desc') {
         $urlDirs[$orderBy] = 'asc';
     } elseif ($orderDir == 'asc' && $urlDirs[$orderBy] == 'asc') {
         $urlDirs[$orderBy] = 'desc';
     }
     $topics = $this->topicRepository->allForForum($forum, $orderBy, $orderDir);
     $topics->appends(['orderBy' => $orderBy, 'orderDir' => $orderDir]);
     return view('forum.show', compact('forum', 'topics', 'orderBy', 'orderDir', 'urlDirs'));
 }
Example #6
0
 /**
  * Restore a topic
  *
  * @param Topic $topic The topic to restore
  *
  * @return mixed
  */
 public function restoreTopic(Topic $topic)
 {
     $topic->forum->increment('num_topics');
     $topic->forum->increment('num_posts', $topic->num_posts);
     if ($topic->user_id > 0) {
         $topic->author->increment('num_topics');
     }
     $success = $topic->restore();
     if ($success) {
         if ($topic->last_post_id > $topic->forum->last_post_id) {
             $this->forumRepository->updateLastPost($topic->forum, $topic->lastPost);
         }
     }
     return $success;
 }
Example #7
0
 /**
  * Restore a post
  *
  * @param Post $post The post to restore
  *
  * @return mixed
  */
 public function restorePost(Post $post)
 {
     $post->topic->increment('num_posts');
     $post->topic->forum->increment('num_posts');
     if ($post->user_id > 0) {
         $post->author->increment('num_posts');
     }
     $success = $post->restore();
     if ($success) {
         if ($post->id > $post->topic->last_post_id) {
             $post->topic->update(['last_post_id' => $post->id]);
         }
         if ($post->id > $post->topic->forum->last_post_id) {
             $this->forumRepository->updateLastPost($post->topic->forum, $post);
         }
     }
     return $success;
 }
Example #8
0
 /**
  * @param int              $forumId
  * @param Request          $request
  * @param MessageFormatter $formatter
  *
  * @return \Illuminate\View\View
  */
 public function create($forumId, Request $request, MessageFormatter $formatter)
 {
     // Forum permissions are checked in "find"
     $forum = $this->forumRepository->find($forumId);
     if (!$forum) {
         throw new ForumNotFoundException();
     }
     $this->breadcrumbs->setCurrentRoute('topics.create', $forum);
     $username = trans('general.guest');
     $preview = null;
     if ($request->has('content')) {
         if (!$this->guard->check()) {
             $userId = null;
             $username = $request->get('username');
         } else {
             $userId = $this->guard->user()->id;
             $username = $this->guard->user()->name;
         }
         $preview = new Post(['user_id' => $userId, 'username' => $username, 'content' => $request->get('content'), 'content_parsed' => $formatter->parse($request->get('content'), [MessageFormatter::ME_USERNAME => $this->guard->user()->name]), 'created_at' => new \DateTime()]);
     }
     return view('topic.create', compact('forum', 'preview', 'username'));
 }
Example #9
0
 /**
  * @param Topic $topic
  * @param Forum $forum
  */
 public function moveTopicToForum(Topic $topic, Forum $forum)
 {
     $this->cache->forget('forums.index_tree');
     $this->cache->forget('forums.all');
     return $this->decoratedRepository->moveTopicToForum($topic, $forum);
 }
Example #10
0
 /**
  * @param string $route
  * @param array  $parameters
  *
  * @return array
  */
 private function getWioData($route, array $parameters)
 {
     $data = array();
     switch ($route) {
         case 'forums.show':
             $forum = $this->forumRepository->find($parameters['id']);
             // Either the forum has been deleted or this user doesn't have permission to view it
             if ($forum != null) {
                 $data['forum'] = e($forum->title);
             } else {
                 $data['langString'] = 'forums.invalid';
             }
             break;
         case 'topics.show':
         case 'topics.reply':
         case 'topics.quote':
         case 'topics.reply.post':
         case 'topics.edit':
         case 'topics.delete':
         case 'topics.restore':
             $topic = $this->topicRepository->find($parameters['id']);
             // Either the topic has been deleted or this user doesn't have permission to view it
             if ($topic != null) {
                 $data['topic'] = e($topic->title);
                 $data['url'] = route('topics.show', [$parameters['slug'], $parameters['id']]);
             } else {
                 $data['langString'] = 'topics.invalid';
             }
             break;
         case 'topics.create':
             $forum = $this->forumRepository->find($parameters['forumId']);
             // Either the forum has been deleted or this user doesn't have permission to view it
             if ($forum != null) {
                 $data['forum'] = e($forum->title);
                 $data['url'] = route('forums.show', [$forum->slug, $forum->id]);
             } else {
                 $data['langString'] = 'forums.invalid';
             }
             break;
         case 'search.post':
         case 'search.results':
             $data['url'] = route('search');
             break;
         case 'user.profile':
             $user = $this->userRepository->find($parameters['id']);
             if ($user != null) {
                 $data['user'] = e($user->name);
                 $data['url'] = route('user.profile', [$user->name, $user->id]);
             } else {
                 $data['langString'] = 'user.invalid';
             }
             break;
         case 'conversations.index':
         case 'conversations.compose':
         case 'conversations.read':
         case 'conversations.reply':
         case 'conversations.leave':
         case 'conversations.newParticipant':
             $data['langString'] = 'conversations';
             break;
     }
     // TODO: Here's a nice place for a plugin hook
     return $data;
 }