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 loadArchive() { $this->page['min_date'] = BlogPost::min('published_at'); if ($this->property('parent') == '') { return BlogPost::where('published', 1)->orderBy('published_at', 'desc')->get(); } else { $parent = $this->property('parent'); return BlogPost::where('parent', $parent)->where('published', 1)->orderBy('published_at', 'desc')->get(); } }
protected function updateEvent($data) { $post = BasePost::where('id', $data['event_id'])->first(); if ($post->available == 0) { return false; } else { $post->decrement('available'); $post->save(); return true; } }
public function getPost() { if ($this->post !== null) { return $this->post; } $this->post = PostModel::where('promoted', '1')->where('categories_id', 2)->first(); if (is_null($this->post)) { return \Response::make($this->controller->run('404'), 404); } else { return $this->post; } }
public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { $plural = null; if (count($checkedIds) > 1) { $plural = 's'; } foreach ($checkedIds as $postId) { if (!($post = Post::find($postId))) { continue; } $post->delete(); } Flash::success('Blog' . $plural . ' Successfully Deleted.'); } return $this->listRefresh(); }
public function onRefreshPreview() { $data = post('Post'); $previewHtml = Post::formatHtml($data['content'], true); return ['preview' => $previewHtml]; }
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; }
public function getPost() { if ($this->post !== null) { return $this->post; } $this->post = PostModel::where('slug', '=', $this->param('slug'))->first(); if (is_null($this->post)) { return \Response::make($this->controller->run('404'), 404); } else { return $this->post; } }
/** * Get the post's excerpt if available * otherwise fall back to a limited content string. * * @param $post * * @return string */ private function getSummary($post) { $excerpt = $post->excerpt; if (mb_strlen(trim($excerpt))) { return $excerpt; } $content = $post->content; if (Settings::get('markdownMode')) { $content = Post::formatHtml($content); } return $content; }
public static function clonePost($post) { /* * first we make a new product useing all data */ $new_post = new Post(); $new_post->fill($post->attributes); $new_post->id = null; // Unset the primary key on the clone instead $new_post->save(); /* * next we get all price breaks * and create new ones using our new * product model ID */ $tags = $post->tags; foreach ($tags as $tag) { $data = [$new_post->id, $tag->id]; DB::insert("INSERT INTO radiantweb_blog_post_tags (post_id,tag_id) VALUES (?,?)", $data); } /* * next we get all product images * and create new ones using our new * product model ID */ $featured_images = $post->featured_images; foreach ($featured_images as $featured_image) { $data = [$featured_image->disk_name, $featured_image->file_name, $featured_image->file_size, $featured_image->content_type, $featured_image->title, $featured_image->description, $featured_image->field, $new_post->id, $featured_image->attachment_type, $featured_image->is_public, $featured_image->sort_order, $featured_image->created_at, $featured_image->updated_at]; DB::insert("INSERT INTO system_files (\n disk_name,\n file_name,\n file_size,\n content_type,\n title,\n description,\n field,\n attachment_id,\n attachment_type,\n is_public,\n sort_order,\n created_at,\n updated_at\n ) values (?,?,?,?,?,?,?,?,?,?,?,?,?)", $data); } }