Esempio n. 1
0
 public static function getCategoryFeed($slug = null)
 {
     $category = Category::whereRaw("LOWER(name) = '{$slug}'")->first();
     if ($category) {
         return Post::isPublished()->where('categories_id', '=', $category->id)->orderBy('published_at', 'desc');
     }
 }
Esempio n. 2
0
 public function onRun()
 {
     $this->addCss('/plugins/radiantweb/problog/assets/css/problog_post.css');
     $this->addJs('/plugins/radiantweb/problog/assets/google-code-prettify/prettify.js');
     $this->addJs('/plugins/radiantweb/problog/assets/google-code-prettify/run_prettify.js?skin=sunburst');
     $this->getPost();
     if (!is_null($this->post) && ($this->post->published < 1 && !$this->user())) {
         return \Response::make($this->controller->run('404'), 404);
     }
     if (!is_null($this->post) && !$this->render_category) {
         /* set up metas for this post */
         $this->page['post_item'] = $this->post;
         $this->page->title = $this->post->meta_title ? $this->post->meta_title : $this->post->title;
         $this->page->meta_description = $this->post->meta_description ? $this->post->meta_description : $this->post->excerpt;
         $this->page->meta_keywords = $this->post->meta_keywords;
         $this->page['categories'] = $this->categories = CategoryModel::get();
         if ($this->post) {
             $this->page['author'] = $this->getAuthor($this->post->user_id);
         }
         $this->page['parentPage'] = $this->post->parent;
         $this->page['searchpage'] = $this->property('searchpage');
         $this->page['back'] = Request::header('referer');
         $this->page['url'] = Request::url();
         $settings = ProblogSettingsModel::instance();
         $this->page['sharethis'] = $settings->get('sharethis');
         $this->page['facebook'] = $settings->get('facebook');
         $this->page['twitter'] = $settings->get('twitter');
         $this->page['google'] = $settings->get('google');
         $this->page['embedly'] = $settings->get('embedly');
         if ($this->page['embedly']) {
             $this->addJs('/plugins/radiantweb/problog/assets/js/jquery.embedly.js');
             $this->addJs('/plugins/radiantweb/problog/assets/js/embedly.js');
         }
     }
 }
Esempio n. 3
0
 protected function loadCategories()
 {
     $categories = BlogCategory::orderBy('name');
     if ($this->property('parent') == '') {
         $categories->whereExists(function ($query) {
             $query->select(DB::raw(1))->from('radiantweb_blog_posts')->whereNotNull('radiantweb_blog_posts.published')->where('published', 1)->whereRaw('radiantweb_blog_categories.id = radiantweb_blog_posts.categories_id');
         });
     } else {
         $categories->whereExists(function ($query) {
             $parent = $this->property('parent');
             $query->select(DB::raw(1))->from('radiantweb_blog_posts')->whereNotNull('radiantweb_blog_posts.published')->where('parent', $parent)->where('published', 1)->whereRaw('radiantweb_blog_categories.id = radiantweb_blog_posts.categories_id');
         });
     }
     return $categories->get();
 }
 public function index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         $plural = 'y';
         if (count($checkedIds) > 1) {
             $plural = 'ies';
         }
         foreach ($checkedIds as $categoryId) {
             if (!($category = Category::find($categoryId))) {
                 continue;
             }
             $category->delete();
         }
         Flash::success('Categor' . $plural . ' Successfully Deleted.');
     }
     return $this->listRefresh();
 }
 public function boot()
 {
     Event::listen('pages.menuitem.listTypes', function () {
         return ['problog-category' => 'ProBlog Category', 'all-problog-categories' => 'All ProBlog Categories', 'problog-tag' => 'ProBlog Tag', 'all-problog-tags' => 'All ProBlog Tags'];
     });
     Event::listen('pages.menuitem.getTypeInfo', function ($type) {
         if ($type == 'problog-category' || $type == 'all-problog-categories') {
             return Category::getMenuTypeInfo($type);
         }
         if ($type == 'problog-tag' || $type == 'all-problog-tags') {
             return Tag::getMenuTypeInfo($type);
         }
     });
     Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
         if ($type == 'problog-category' || $type == 'all-problog-categories') {
             return Category::resolveMenuItem($item, $url, $theme);
         }
         if ($type == 'problog-tag' || $type == 'all-problog-tags') {
             return Tag::resolveMenuItem($item, $url, $theme);
         }
     });
 }
 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;
 }
 private static function getBlogCategoryRenderUrls($theme, $item, $allcat = false)
 {
     $page = CmsPage::loadCached($theme, $item->cmsPage);
     $result = [];
     $categories = Category::lists('slug', 'name');
     $pages = [];
     if ($item->nesting > 0) {
         foreach ($categories as $slug => $name) {
             if ($allcat) {
                 $url = CmsPage::url($page->getBaseFileName(), ['filter' => 'category', 'slug' => $slug], false);
                 $url = Str::lower($url) . '/';
                 $pages[] = array('title' => $name, 'url' => $url);
             } else {
                 $category = Category::whereRaw("LOWER(slug) = '{$slug}'")->first();
                 $categoryPages = Post::filterByCategory($category->id)->get();
                 $pageUrl = CmsPage::url($page->getBaseFileName(), ['slug' => $slug], false);
                 $pageUrl = str_replace('/default', '', Str::lower($pageUrl) . '/');
                 foreach ($categoryPages as $cpage) {
                     $pages[] = array('title' => $cpage->title, 'url' => Str::lower($pageUrl) . $cpage->slug . '/');
                 }
             }
         }
     }
     return $pages;
 }
Esempio n. 8
0
 public function run()
 {
     Category::create(['name' => 'Uncategorized', 'slug' => 'uncategorized']);
 }