Example #1
0
 /**
  * @param mixed $content
  * @param array $options
  *
  * @return mixed
  */
 public function apply($content, array $options = [])
 {
     if ($this->supports($content, $options)) {
         $topic = $this->topicRepository->find($options['topic_id']);
         $this->move($content, $topic);
     }
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $topics = $this->topicRepository->all();
     if (!$topics) {
         // TODO: respond with error
     }
     return $this->respondWithCollection($topics, new TopicTransformer());
 }
Example #3
0
 /**
  * @param string        $topicSlug
  * @param int           $topicId
  * @param CreateRequest $createRequest
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postEdit($topicSlug, $topicId, CreateRequest $createRequest)
 {
     $topic = $this->topicRepository->find($topicId);
     if (!$topic) {
         throw new TopicNotFoundException();
     }
     if (!$topic->has_poll) {
         throw new PollNotFoundException();
     }
     $poll = $topic->poll;
     $pollPresenter = app()->make('MyBB\\Core\\Presenters\\Poll', [$poll]);
     $options = [];
     $i = 0;
     foreach ($createRequest->input('option') as $option) {
         if ($option && is_scalar($option)) {
             $options[] = ['option' => $option, 'votes' => 0];
             if (isset($pollPresenter->options[$i]['votes'])) {
                 $options[$i]['votes'] = $pollPresenter->options[$i]['votes'];
             }
             ++$i;
         }
     }
     $pollDetails = ['question' => $createRequest->input('question'), 'num_options' => count($options), 'options' => $options, 'is_closed' => (bool) $createRequest->input('is_closed'), 'is_multiple' => (bool) $createRequest->input('is_multiple'), 'is_public' => (bool) $createRequest->input('is_public'), 'max_options' => (int) $createRequest->input('maxoptions')];
     if ($createRequest->input('endAt')) {
         $poll['end_at'] = new \DateTime($createRequest->input('endAt'));
     }
     $poll->update($pollDetails);
     if ($poll) {
         return redirect()->route('topics.show', ['slug' => $topic->slug, 'id' => $topic->id]);
     }
     return redirect()->route('polls.edit')->withInput()->withErrors(['error' => trans('error.error_editing_poll')]);
 }
Example #4
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 #5
0
 /**
  * @param string $slug
  * @param int    $id
  * @param int    $postId
  *
  * @return \Exception|\Illuminate\Http\RedirectResponse
  */
 public function restore($slug = '', $id = 0, $postId = 0)
 {
     // Forum permissions are checked in "find"
     $topic = $this->topicRepository->find($id);
     $post = $this->postRepository->find($postId);
     if (!$post || !$topic || $post['topic_id'] != $topic['id'] || !$post['deleted_at'] && !$topic['deleted_at']) {
         throw new PostNotFoundException();
     }
     if ($post['id'] == $topic['first_post_id']) {
         $this->topicRepository->restoreTopic($topic);
     } else {
         $this->postRepository->restorePost($post);
     }
     if ($topic) {
         return redirect()->route('topics.showPost', ['slug' => $topic->slug, 'id' => $topic->id, 'postId' => $post->id]);
     }
     return redirect()->route('topics.showPost', ['slug' => $slug, 'id' => $id, 'postId' => $postId])->withErrors([trans('errors.error_deleting_topic')]);
 }
Example #6
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;
 }