/** * Show profile of a user * GET /profiles/{slug} */ public function getProfile($slug) { $user = $this->user->bySlug($slug); if (!$user) { return App::abort(404); } return View::make('users.profile', compact('user')); }
/** * Show home page * GET / */ public function getIndex() { $perPage = Config::get('site.snippetsPerPage'); $snippets = $this->snippet->byPage($perPage); $topSnippetContributors = $this->user->getTopSnippetContributors(); $mostViewedSnippets = $this->snippet->getMostViewed(10); $tags = $this->tag->all(); return View::make('website.pages.index', compact('snippets', 'topSnippetContributors', 'mostViewedSnippets', 'tags')); }
/** * Show home page * GET / */ public function getIndex() { $page = Input::get('page', 1); // Candidate for config item $perPage = 10; $pagiData = $this->snippet->byPage($page, $perPage); $snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); $topSnippetContributors = $this->user->getTopSnippetContributors(); $mostViewedSnippets = $this->snippet->getMostViewed(10); $tags = $this->tag->all(); return View::make('website.pages.index', compact('snippets', 'topSnippetContributors', 'mostViewedSnippets', 'tags')); }
/** * Show an individual snippet * GET /snippets/{slug} */ public function getShow($slug) { $snippet = $this->snippet->bySlug($slug); if (!$snippet) { return App::abort(404); } $user = Auth::user(); $has_starred = !empty($user) ? $user->hasStarred($snippet->id) : false; # increment hit count $snippet->incrementHits(); $tags = $this->tag->all(); $topSnippetContributors = $this->user->getTopSnippetContributors(); return View::make('snippets.show', compact('snippet', 'has_starred', 'tags', 'topSnippetContributors')); }
/** * Show listing of snippets filtered by a tag * GET /tags/{slug} */ public function getShow($slug) { $page = Input::get('page', 1); // Candidate for config item $perPage = 30; $pagiData = $this->snippet->byTag($slug, $page, $perPage); if (!$pagiData->tag) { return App::abort(404); } $tag = $pagiData->tag; $snippets = Paginator::make($pagiData->items, $pagiData->totalItems, $perPage); $tags = $this->tag->all(); $topSnippetContributors = $this->user->getTopSnippetContributors(); return View::make('tags.snippets', compact('snippets', 'tag', 'tags', 'topSnippetContributors')); }
/** * Show the snippet edit form * GET /members/snippets/{slug}/edit */ public function getEdit($slug) { $snippet = $this->snippet->bySlug($slug, $all = true); // validate that the user updating the snippet is the snippet author if (!$snippet->isTheAuthor(Auth::user())) { return App::abort(404); } $tags = $this->tag->all()->lists('name', 'id'); return View::make('member.snippets.edit', compact('snippet', 'tags')); }
/** * Show an individual snippet * GET /snippets/{slug} * @param $slug * @return */ public function getShow($slug) { $snippet = $this->snippet->bySlug($slug); if (!$snippet) { return App::abort(404); } $user = Auth::user(); $has_starred = !empty($user) ? $user->hasStarred($snippet->id) : false; # check cookie readlist $cookieName = md5('snippet.readlist'); $cookieJson = Cookie::get($cookieName); $cookieArray = json_decode($cookieJson); if (is_null($cookieArray) or !in_array($snippet->id, $cookieArray)) { # increment hit count if snippet id not exist cookie $snippet->incrementHits(); # put cookie the snippet id $cookieArray[] = $snippet->id; # attached all cookies for one week. Cookie::queue($cookieName, json_encode($cookieArray), 10080); } $tags = $this->tag->all(); $topSnippetContributors = $this->user->getTopSnippetContributors(); return View::make('snippets.show', compact('snippet', 'has_starred', 'tags', 'topSnippetContributors')); }