/** * @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); } }
/** * @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')]); }
/** * @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')]); }
/** * @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; }