File: D:/HostingSpaces/SBogers104/angeliekly.nl/app/Komma/Posts/PostController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Posts;
use Komma\Blocks\BlockService;
use Komma\LanguageService;
use Komma\Pages\PageService;
class PostController extends \BaseController
{
public $data;
protected $pageService;
protected $blockService;
protected $postService;
public $languageService;
public function __construct(PageService $pageService, BlockService $blockService, PostService $postService, LanguageService $languageService)
{
parent::__construct();
$this->pageService = $pageService;
$this->blockService = $blockService;
$this->postService = $postService;
$this->languageService = $languageService;
}
//Overview page
public function index(){
//Check if language matches the url before loading content
$this->languageService->checkRouteWithSetLanguage();
//get content of page and get all page links
$page = $this->pageService->getPageByCodeName('blog');
$links = $this->pageService->getAllRoutes();
$this->storePaginationInSession();
//Check if category is selected or url is blog/{category}
if(\Session::get('routeCategory', null) == null){
$activeCategory = \Input::get('category');
\Session::put('category', null);
}
else{
$activeCategory = \Session::get('routeCategory');
\Session::forget('routeCategory');
}
//Get the blog items with pagination and with specific category if set
if(isset($activeCategory)) $posts = $this->postService->getPostsByCategory($activeCategory);
else $posts = $this->postService->getAllPosts();
$this->postService->makeCarbonDate($posts);
return \View::make('layouts.pages.postOverview')
->with('page', $page)
->with('links', $links)
->with('posts', $posts)
->with('activeCategory', $activeCategory);
}
public function ajaxPosts($category = null){
$page = $this->pageService->getPageByCodeName('blog');
$links = $this->pageService->getAllRoutes();
$this->storePaginationInSession();
if(isset($category)){
$posts = $this->postService->getPostsByCategory($category);
\Session::put('category', $category);
}
else{
$posts = $this->postService->getAllPosts();
\Session::forget('category');
}
$this->postService->makeCarbonDate($posts);
$view = \View::make('layouts.ajax.postOverview')
->with('page', $page)
->with('links', $links)
->with('posts', $posts)
->with('activeCategory', $category)
->render();
return json_encode([
'metaTitle' => $page->translation->meta_title,
'metaDescription' => $page->translation->meta_description,
'content' => $view,
]);
}
public function show($postId){
//Check if language matches the url before loading content
$this->languageService->checkRouteWithSetLanguage();
//Load post content and translation of this post
$page = $this->postService->getPost($postId);
$links = $this->pageService->getAllRoutes();
$page->translation->meta_description = strip_tags($page->translation->meta_description);
$relativePosts = $this->postService->getRelativePosts($page);
return \View::make('layouts.pages.postDetail')
->with('page', $page)
->with('links', $links)
->with('relevantPosts', $relativePosts);
}
public function ajaxPost($postId, $ajax_url){
//Check if language matches the url before loading content
$this->languageService->checkRouteWithSetLanguage();
//Load post content and translation of this post
$page = $this->postService->getPost($postId);
$links = $this->pageService->getAllRoutes();
$relativePosts = $this->postService->getRelativePosts($page);
$page->ajax = true;
$page->url = $ajax_url;
$view = \View::make('layouts.ajax.postDetail')
->with('page', $page)
->with('links', $links)
->with('relevantPosts', $relativePosts)
->render();
// After loading from overview to article forget the current page counter
// So when navigation by previous and next it will be forgotten when returning to overview
\Session::forget('current_page');
return json_encode([
'metaTitle' => $page->translation->meta_title,
'metaDescription' => strip_tags($page->translation->meta_description),
'content' => $view,
]);
}
private function storePaginationInSession(){
//Get page count session
$currentPage = \Input::get('page');
if( isset($currentPage)) \Session::put('current_page', \Input::get('page'));
else \Session::put('current_page', 1);
}
}