2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Article;
|
|
|
|
use Jonnybarnes\IndieWeb\Numbers;
|
|
|
|
|
|
|
|
class ArticlesController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show all articles (with pagination).
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
|
|
|
public function showAllArticles($year = null, $month = null)
|
|
|
|
{
|
|
|
|
$articles = Article::where('published', '1')
|
2017-02-15 15:21:14 +00:00
|
|
|
->date($year, $month)
|
|
|
|
->orderBy('updated_at', 'desc')
|
|
|
|
->simplePaginate(5);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-02-15 15:21:14 +00:00
|
|
|
return view('articles', compact('articles'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a single article.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
|
|
|
public function singleArticle($year, $month, $slug)
|
|
|
|
{
|
|
|
|
$article = Article::where('titleurl', $slug)->first();
|
|
|
|
if ($article->updated_at->year != $year || $article->updated_at->month != $month) {
|
|
|
|
throw new \Exception;
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:21:14 +00:00
|
|
|
return view('article', compact('article'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We only have the ID, work out post title, year and month
|
|
|
|
* and redirect to it.
|
|
|
|
*
|
|
|
|
* @return \Illuminte\Routing\RedirectResponse redirect
|
|
|
|
*/
|
|
|
|
public function onlyIdInUrl($inURLId)
|
|
|
|
{
|
|
|
|
$numbers = new Numbers();
|
|
|
|
$realId = $numbers->b60tonum($inURLId);
|
|
|
|
$article = Article::findOrFail($realId);
|
|
|
|
|
|
|
|
return redirect($article->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the RSS feed.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function makeRSS()
|
|
|
|
{
|
|
|
|
$articles = Article::where('published', '1')->orderBy('updated_at', 'desc')->get();
|
|
|
|
$buildDate = $articles->first()->updated_at->toRssString();
|
|
|
|
|
2017-02-15 15:21:14 +00:00
|
|
|
return response()
|
|
|
|
->view('rss', compact('articles', 'buildDate'), 200)
|
|
|
|
->header('Content-Type', 'application/rss+xml');
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
}
|