Пример #1
0
 /**
  * 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'));
 }
Пример #2
0
 /**
  * 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 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'));
 }