/**
  * Display sitemap.xml
  *
  * @return Response
  */
 public function index()
 {
     $sitemap = App::make("sitemap");
     if (!$sitemap->isCached()) {
         // main page
         $home = URL::to('/');
         $sitemap->add($home, date('c', time()), '1.0', 'daily');
         $perPage = 15;
         // tags
         foreach (config('sitemap.tags') as $tag => $label) {
             $url = route('tag', $tag);
             $sitemap->add($url, date('c', time()), '0.7', 'weekly');
             // pages of tag
             $pages = ceil(Article::byTag($tag)->count() / $perPage);
             if ($pages > 1) {
                 for ($page = 2; $page <= $pages; $page++) {
                     $sitemap->add("{$url}/page/{$page}", date('c', time()), '0.7', 'weekly');
                 }
             }
         }
         // all posts
         $posts = Article::all();
         foreach ($posts as $post) {
             if ($post->path) {
                 $url = route('post', $post->path);
             } else {
                 $url = route('post_by_id', $post->id);
             }
             $date = max(strtotime($post->created_at), strtotime($post->updated_at));
             $sitemap->add($url, date('c', $date), '0.9', 'daily');
         }
         // archive pages
         $pages = ceil(count($posts) / $perPage);
         if ($pages > 1) {
             for ($page = 2; $page <= $pages; $page++) {
                 $sitemap->add("{$home}/page/{$page}", date('c', time()), '0.8', 'daily');
             }
         }
     }
     return $sitemap->render('xml');
 }
 public function show($tag, Request $request)
 {
     $article = Article::byTag($tag);
     return view('article.show', compact('article', 'tag'));
 }
 public function tag(Request $request, $tag, $page = 1)
 {
     // changing pagination page from route param
     Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     // getting articles
     $articles = Article::byTag($tag)->paginate();
     // changing routing in rendered pagination view
     $pagination_view = $articles->render();
     // from "/tag/$tag/?page=$page" to "/tag/$tag/page/$page"
     $pagination_view = preg_replace('|/(page/\\d+/?)?\\?page=(\\d+)|', '/page/$2', $pagination_view);
     // replace "/tag/$tag/page/1" to "/tag/$tag"
     $pagination_view = str_replace('/page/1"', '"', $pagination_view);
     //redirect from $_GET paging to new routing
     $_page = $request->get('page');
     if ($_page && (string) abs($_page) === $_page) {
         if ($_page == 1) {
             return redirect(route('tag', $tag));
         }
         return redirect(route('tag_paged', [$tag, $_page]));
     }
     $page_title = 'Блог веб разработчика: ' . $tag;
     $view = $request->ajax() ? 'articles.index-content' : 'articles.index';
     if (!$articles->count()) {
         abort(404);
     }
     // image for og meta
     $tag_image = url('/images/logo.png');
     foreach ($articles as $article) {
         $found_image = $article->getImageUrl();
         if ($found_image != $tag_image) {
             $tag_image = $found_image;
             break;
         }
     }
     return response()->view($view, compact('articles', 'page_title', 'pagination_view', 'page', 'tag', 'tag_image'))->withCookie($this->rating_cookie($request));
 }