示例#1
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);
     }
 }
示例#2
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'));
 }
示例#3
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'));
 }
示例#4
0
 /**
  * Get a single forum by ID.
  *
  * @param int $id The ID of the forum.
  *
  * @return mixed
  */
 public function find($id = 0)
 {
     return $this->decoratedRepository->find($id);
 }
示例#5
0
文件: User.php 项目: Adamzynoni/mybb2
 /**
  * @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;
 }