2016-03-28 14:47:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Holds the news controller.
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
2016-09-10 15:05:54 +00:00
|
|
|
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
|
2016-03-28 14:47:43 +00:00
|
|
|
use Sakura\Config;
|
|
|
|
use Sakura\News\Category;
|
|
|
|
use Sakura\News\Post;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* News controller.
|
|
|
|
* @package Sakura
|
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
|
|
|
*/
|
|
|
|
class NewsController extends Controller
|
|
|
|
{
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Shows all posts in a specific category.
|
|
|
|
* @param string $category
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-03-28 14:47:43 +00:00
|
|
|
public function category($category = '')
|
|
|
|
{
|
|
|
|
// Check if the category is set
|
|
|
|
if ($category === '') {
|
|
|
|
// Fetch the default category from the config
|
2016-07-26 17:29:53 +00:00
|
|
|
$category = config('general.news');
|
2016-03-28 14:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the category object
|
|
|
|
$category = new Category($category);
|
|
|
|
|
|
|
|
if (!$category->posts()) {
|
2016-09-10 15:05:54 +00:00
|
|
|
throw new HttpRouteNotFoundException();
|
2016-03-28 14:47:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-10 15:05:54 +00:00
|
|
|
return view('news/category', compact('category'));
|
2016-03-28 14:47:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Returns a news post.
|
|
|
|
* @param int $id
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-03-28 14:47:43 +00:00
|
|
|
public function post($id = 0)
|
|
|
|
{
|
|
|
|
// Create the post object
|
|
|
|
$post = new Post($id);
|
|
|
|
|
|
|
|
if (!$post->id) {
|
2016-09-10 15:05:54 +00:00
|
|
|
throw new HttpRouteNotFoundException();
|
2016-03-28 14:47:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-10 15:05:54 +00:00
|
|
|
return view('news/post', compact('post'));
|
2016-03-28 14:47:43 +00:00
|
|
|
}
|
|
|
|
}
|