示例#1
0
 public static function getTagFeed($slug = null)
 {
     $tag = Tag::where('slug', '=', $slug)->first();
     if ($tag) {
         return Post::isPublished()->where('categories_id', '=', $category->id)->orderBy('published_at', 'desc');
     }
 }
 protected function getOrCreateTag($tagname)
 {
     $tag = TagModel::where('name', 'like', $tagname)->first();
     if ($tag == null) {
         $slug = strtolower(str_replace(' ', '-', $tagname));
         $tag = TagModel::create(array('name' => $tagname, 'slug' => $slug));
     }
     return $tag;
 }
示例#3
0
 private static function getTagRenderUrl($theme, $item)
 {
     $tag = Tag::where('name', $item->reference)->first();
     $page = CmsPage::loadCached($theme, $item->cmsPage);
     // Always check if the page can be resolved
     if (!$page) {
         return;
     }
     $url = null;
     if (!$tag) {
         $options = ['filter' => null, 'slug' => null];
     } else {
         $options = ['filter' => 'tag', 'slug' => $tag->slug];
     }
     // Generate the URL
     $url = CmsPage::url($page->getBaseFileName(), $options, false);
     $url = URL::to(Str::lower(RouterHelper::normalizeUrl($url))) . '/';
     return $url;
 }
 protected function loadPosts()
 {
     //\Log::info($this->parentPage);
     if ($this->parentPage != '') {
         $parent = $this->parentPage;
         $BlogPosts = BlogPost::where('parent', $parent);
     } else {
         $BlogPosts = new BlogPost();
     }
     $BlogPosts = $BlogPosts->isPublished();
     /*
      * Preset Fitlers
      * First we cycle through all possible preset filtering
      * @type - category,tag,author,date-time
      */
     if ($this->property('filter_type') == 'category') {
         $category_name = $this->property('filter_value');
         $category = CategoryModel::whereRaw("LOWER(name) = '{$category_name}'")->first();
         if ($category) {
             $catID = $category->id;
         } else {
             $catID = '#';
         }
         $BlogPosts->filterByCategory($catID);
     }
     if ($this->property('filter_type') == 'tag') {
         $tag = TagModel::where('name', '=', $this->property('filter_value'))->first();
         return $tag->posts()->paginate($this->property('postsPerPage'));
     }
     if ($this->property('filter_type') == 'author') {
         $author = BackendUserModel::findUserByLogin($this->property('filter_value'));
         if ($author) {
             $author_id = $author->id;
         } else {
             $author_id = '#';
         }
         $BlogPosts->filterByAuthor($author_id);
     }
     /*
      * Filter Request
      * Next we cycle through all possible request filters
      * @type - category,tag,author,canonical
      * (canonical requires additional different page vars /:year?/:month?/)
      */
     if ($this->param('filter')) {
         if ($this->param('filter') !== 'category' && !$this->param('slug')) {
             $slug = $this->param('filter');
             $type = 'category';
         } else {
             $type = $this->param('filter');
             $slug = $this->param('slug');
         }
         $slug = $slug;
         $slug = strtolower($slug);
         $slug = str_replace('-', ' ', $slug);
         $slug = str_replace('%20', ' ', $slug);
         if ($type == 'category') {
             $this->page['blogCurrentCategorySlug'] = $slug;
             $category = CategoryModel::whereRaw("LOWER(name) = '{$slug}'")->first();
             if ($category) {
                 $catID = $category->id;
             } else {
                 $catID = '#';
             }
             $BlogPosts->filterByCategory($catID);
         } elseif ($type == 'tag') {
             $this->page['blogCurrentTagSlug'] = $slug;
             $tag = TagModel::where('name', '=', $slug)->first();
             if ($tag) {
                 return $tag->posts()->paginate($this->property('postsPerPage'));
             }
             return false;
         } elseif ($type == 'author') {
             $author = BackendUserModel::findUserByLogin($slug);
             if ($author) {
                 $author_id = $author->id;
             } else {
                 $author_id = '#';
             }
             $BlogPosts->filterByAuthor($author_id);
         } elseif ($type == 'search') {
             $this->page['search_slug'] = $slug;
             $BlogPosts->filterBySearch($slug);
         } elseif ($type == 'cannonical') {
             $y = $this->param('year');
             $m = $this->param('month');
             $BlogPosts->filterByDate($y, $m);
         } else {
             $component = $this->addComponent('Radiantweb\\Problog\\Components\\Post', 'proBlogPost', array('slug' => $slug));
             $component->onRun();
             $this->render_post = $this->page['render_post'] = $slug;
             return $this->render_post;
         }
     }
     /*
      * no filters, we go get all
      */
     $posts = $BlogPosts->orderBy('published_at', 'desc')->paginate($this->property('postsPerPage'), $this->currentPage);
     //$queries = DB::getQueryLog();
     //$last_query = end($queries);
     //\Log::info($last_query);
     return $posts;
 }