Exemplo n.º 1
0
 private function loadLatestPost($numberOfPost)
 {
     $posts = Post::with('categories')->isPublished()->orderBy('published_at', 'desc')->take($numberOfPost)->get();
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->property('postPage'), $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->property('categoryPage'), $this->controller);
         });
     });
     return $posts;
 }
Exemplo n.º 2
0
 protected function listPosts()
 {
     $category = $this->category ? $this->category->id : null;
     /*
      * List all the posts, eager load their categories
      */
     $posts = BlogPost::with('categories')->listFrontEnd(['sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage'), 'category' => $category]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
     });
     return $posts;
 }
Exemplo n.º 3
0
 protected function loadPosts()
 {
     /*
      * List all the posts, eager load their categories
      */
     $posts = Post::with('tags')->whereHas('tags', function ($tag) {
         $tag->whereSlug($this->property('slug'));
     })->listFrontEnd(['page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage')]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
     });
     return $posts;
 }
Exemplo n.º 4
0
 /**
  * Load the most related posts based on associated tags
  *
  * @return Collection
  */
 protected function loadRelatedPosts()
 {
     $post = Post::with('tags')->whereSlug($this->property('slug'))->first();
     if (!$post->tags->count()) {
         return;
     }
     $tagIds = $post->tags->lists('id');
     // a collection of related posts
     $query = Post::isPublished()->where('id', '<>', $post->id)->whereHas('tags', function ($tag) use($tagIds) {
         $tag->whereIn('id', $tagIds);
     })->with('tags');
     $orderBy = DB::raw('(
         select count(*) from `rahman_blogtags_posts_tags`
         where `rahman_blogtags_posts_tags`.`post_id` = `rainlab_blog_posts`.`id`
         and `rahman_blogtags_posts_tags`.`tag_id` in (' . implode(', ', $tagIds) . '))');
     // order by most related tags
     $query->orderby($orderBy, 'desc');
     if ($take = intVal($this->property('results'))) {
         $query->take($take);
     }
     return $query->get();
 }
Exemplo n.º 5
0
 protected function listPosts($monthSlug)
 {
     $thisMonthInt = date('n', strtotime($monthSlug));
     $thisYearInt = date('Y', strtotime($monthSlug));
     $thisMonthTime = mktime(0, 0, 0, $thisMonthInt, 1, $thisYearInt);
     $thisMonthDays = date('t', $thisMonthTime);
     $monthBegin = date('Y-m-01 00:00:00', $thisMonthTime);
     $monthEnd = date('Y-m-' . $thisMonthDays . ' 00:00:00', $thisMonthTime);
     /*
      * List all the posts, eager load their categories
      */
     $posts = BlogPost::with('categories')->where('published_at', '>', $monthBegin)->where('published_at', '<', $monthEnd)->listFrontEnd(['page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage')]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
     });
     return $posts;
 }
 /**
  * @see RainLab\Blog\Components\Posts::prepareVars()
  * @return mixed
  */
 protected function listPosts()
 {
     // get posts in excluded category
     $blockedPosts = [];
     $categories = BlogCategory::with(['posts' => function ($q) {
         $q->select('post_id');
     }])->whereIn('id', $this->property('excludeCategories'))->get();
     $categories->each(function ($item) use(&$blockedPosts) {
         $item->posts->each(function ($item) use(&$blockedPosts) {
             $blockedPosts[] = $item->post_id;
         });
     });
     // Filter posts
     $posts = BlogPost::with(['categories' => function ($q) {
         $q->whereNotIn('id', $this->property('excludeCategories'));
     }])->whereNotIn('id', $blockedPosts)->where(function ($q) {
         $q->where('title', 'LIKE', "%{$this->searchTerm}%")->orWhere('content', 'LIKE', "%{$this->searchTerm}%")->orWhere('excerpt', 'LIKE', "%{$this->searchTerm}%");
     });
     // filter categories
     $cat = Input::get('cat');
     if ($cat) {
         $cat = is_array($cat) ? $cat : [$cat];
         $posts->filterCategories($cat);
     }
     // List all the posts that match search terms, eager load their categories
     $posts = $posts->listFrontEnd(['page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage')]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
         // apply highlight of search result
         if ($this->property('hightlight')) {
             $searchTerm = preg_quote($this->searchTerm, '|');
             // apply highlight
             $post->title = preg_replace('|(' . $searchTerm . ')|i', '<mark>$1</mark>', $post->title);
             $post->excerpt = preg_replace('|(' . $searchTerm . ')|i', '<mark>$1</mark>', $post->excerpt);
             $post->content_html = preg_replace('~(?![^<>]*>)(' . $searchTerm . ')~ism', '<mark>$1</mark>', $post->content_html);
         }
     });
     return $posts;
 }
Exemplo n.º 7
0
 /**
  * @see RainLab\Blog\Components\Posts::prepareVars()
  * @return mixed
  */
 protected function listPosts()
 {
     // Filter posts
     $posts = BlogPost::with(['categories' => function ($q) {
         if (!is_null($this->property('excludeCategories'))) {
             $q->whereNotIn('id', $this->property('excludeCategories'));
         }
         if (!is_null($this->property('includeCategories'))) {
             $q->whereIn('id', $this->property('includeCategories'));
         }
     }])->where(function ($q) {
         $q->where('title', 'LIKE', "%{$this->searchTerm}%")->orWhere('content', 'LIKE', "%{$this->searchTerm}%")->orWhere('excerpt', 'LIKE', "%{$this->searchTerm}%");
     });
     // filter categories
     $cat = Input::get('cat');
     if ($cat) {
         $cat = is_array($cat) ? $cat : [$cat];
         $posts->filterCategories($cat);
     }
     // get posts in excluded category
     $blockedPosts = $this->getPostIdsByCategories($this->property('excludeCategories'));
     if (!empty($blockedPosts)) {
         $posts = $posts->whereNotIn('id', $blockedPosts);
     }
     // get only posts from included categories
     $allowedPosts = $this->getPostIdsByCategories($this->property('includeCategories'));
     if (!empty($allowedPosts)) {
         $posts = $posts->whereIn('id', $allowedPosts);
     }
     // List all the posts that match search terms, eager load their categories
     $posts = $posts->listFrontEnd(['page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage')]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
         // apply highlight of search result
         $this->highlight($post);
     });
     return $posts;
 }
Exemplo n.º 8
0
 protected function listPosts()
 {
     $categories = $this->category ? $this->category->id : null;
     // @deprecated remove if year >= 2015
     $deprecatedPage = $this->propertyOrParam('pageParam');
     $deprecatedSortOrder = $this->property('postOrderAttr');
     /*
      * List all the posts, eager load their categories
      */
     $posts = BlogPost::with('categories')->listFrontEnd(['page' => $this->property('pageNumber', $deprecatedPage), 'sort' => $this->property('sortOrder', $deprecatedSortOrder), 'perPage' => $this->property('postsPerPage'), 'categories' => $categories]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
     });
     return $posts;
 }
 /**
  * @see RainLab\Blog\Components\Posts::prepareVars()
  * @return mixed
  */
 protected function listPosts()
 {
     /*
      * List all the posts that match search terms, eager load their categories
      */
     $posts = BlogPost::with('categories')->where('title', 'LIKE', "%{$this->searchTerm}%")->orWhere('content', 'LIKE', "%{$this->searchTerm}%")->orWhere('excerpt', 'LIKE', "%{$this->searchTerm}%")->listFrontEnd(['page' => $this->property('pageNumber'), 'sort' => $this->property('sortOrder'), 'perPage' => $this->property('postsPerPage')]);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
         // apply highlight of search result
         if ($this->property('hightlight')) {
             $searchTerm = preg_quote($this->searchTerm, '|');
             // apply highlight
             $post->title = preg_replace('|(' . $searchTerm . ')|i', '<mark>$1</mark>', $post->title);
             $post->excerpt = preg_replace('|(' . $searchTerm . ')|i', '<mark>$1</mark>', $post->excerpt);
             $post->content_html = preg_replace('~(?![^<>]*>)(' . $searchTerm . ')~ism', '<mark>$1</mark>', $post->content_html);
         }
     });
     return $posts;
 }