/** * @param Request $request * @return $this */ public function index(Request $request) { $this->breadcrumb->push('Forum', route('forum.home')); $this->pushForumCriteria(); // execute query: get all categories that user can has access $sections = $this->forum->groupBySections(auth()->id(), $request->session()->getId()); // let's cache tags. we don't need to run this query every time $tags = Cache::remember('forum:tags', 60 * 24, function () { return $this->forum->getTagClouds(); }); // create view with online users $viewers = app()->make('Session\\Viewers')->render($request->getRequestUri()); return parent::view('forum.home')->with(compact('sections', 'viewers', 'tags')); }
/** * @param \Coyote\Forum $forum * @param Request $request * @return $this */ public function index($forum, Request $request) { // builds breadcrumb for this category $this->breadcrumb($forum); // create view with online users $viewers = app()->make('Session\\Viewers')->render($request->getRequestUri()); $this->pushForumCriteria(); $forumList = $this->forum->forumList(); $this->topic->pushCriteria(new BelongsToForum($forum->id)); $topics = $this->topic->paginate(auth()->id(), $request->getSession()->getId()); // let's cache tags. we don't need to run this query every time $tags = Cache::remember('forum:tags', 60 * 24, function () { return $this->forum->getTagClouds(); }); return parent::view('forum.category')->with(compact('viewers', 'forumList', 'forum', 'topics', 'tags')); }
/** * @param \Coyote\Forum $forum * @param \Coyote\Topic $topic * @param string $slug * @param Request $request * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function index($forum, $topic, $slug, Request $request) { if ($topic->forum_id !== $forum->id) { return redirect(route('forum.topic', [$forum->path, $topic->id, $topic->path])); } $userId = auth()->id(); $sessionId = $request->session()->getId(); // pobranie daty i godziny ostatniego razu gdy uzytkownik przeczytal ten watek $topicMarkTime = $this->topic->markTime($topic->id, $userId, $sessionId); // pobranie daty i godziny ostatniego razy gdy uzytkownik przeczytal to forum $forumMarkTime = $this->forum->markTime($forum->id, $userId, $sessionId); if ($request->get('view') === 'unread') { if ($topicMarkTime < $topic->last_post_created_at && $forumMarkTime < $topic->last_post_created_at) { $markTime = max($topicMarkTime, $forumMarkTime); if ($markTime) { $postId = $this->post->getFirstUnreadPostId($topic->id, $markTime); if ($postId && $postId !== $topic->first_post_id) { $url = route('forum.topic', [$forum->path, $topic->id, $topic->path]); return response($url) . '?p=' . $postId . '#id' . $postId; } } } } // current page... $page = $request->page; if ($request->has('p')) { $page = $this->post->getPage($request->get('p'), $topic->id); } // magic happens here. get posts for given topic $posts = $this->post->takeForTopic($topic->id, $topic->first_post_id, $userId, $page); $paginate = new LengthAwarePaginator($posts, $topic->replies, 10, $page, ['path' => ' ']); $parser = ['post' => app()->make('Parser\\Post'), 'comment' => app()->make('Parser\\Comment'), 'sig' => app()->make('Parser\\Sig')]; $markTime = null; foreach ($posts as &$post) { // parse post or get it from cache $post->text = $parser['post']->parse($post->text); if ((auth()->guest() || auth()->check() && auth()->user()->allow_sig) && $post->sig) { $post->sig = $parser['sig']->parse($post->sig); } $markTime = $post->created_at; } if ($topicMarkTime < $markTime && $forumMarkTime < $markTime) { $this->topic->markAsRead($topic->id, $forum->id, $markTime, $userId, $sessionId); $isUnread = true; if ($forumMarkTime < $markTime) { $isUnread = $this->topic->isUnread($forum->id, $forumMarkTime, $userId, $sessionId); } if (!$isUnread) { $this->forum->markAsRead($forum->id, $userId, $sessionId); } } $this->breadcrumb($forum); $this->breadcrumb->push($topic->subject, route('forum.topic', [$forum->path, $topic->id, $topic->path])); // create forum list for current user (according to user's privileges) $this->pushForumCriteria(); $forumList = $this->forum->forumList(); $viewers = app('Session\\Viewers')->render($request->getRequestUri()); // let's cache tags. we don't need to run this query every time $tags = Cache::remember('forum:tags', 60 * 24, function () { return $this->forum->getTagClouds(); }); return parent::view('forum.topic')->with(compact('viewers', 'posts', 'forum', 'topic', 'paginate', 'forumList', 'tags')); }