2017-06-04 19:06:22 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-06-04 19:06:22 +01:00
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2022-07-09 10:08:26 +01:00
|
|
|
|
use App\Models\Article;
|
|
|
|
|
use App\Models\Note;
|
2020-06-20 16:47:39 +01:00
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2019-10-27 16:29:15 +00:00
|
|
|
|
use Illuminate\Http\Response;
|
2017-06-04 19:06:22 +01:00
|
|
|
|
|
|
|
|
|
class FeedsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Returns the blog RSS feed.
|
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
|
public function blogRss(): Response
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
$articles = Article::where('published', '1')->latest('updated_at')->take(20)->get();
|
|
|
|
|
$buildDate = $articles->first()->updated_at->toRssString();
|
|
|
|
|
|
|
|
|
|
return response()
|
2023-04-20 17:34:06 +01:00
|
|
|
|
->view('articles.rss', compact('articles', 'buildDate'))
|
|
|
|
|
->header('Content-Type', 'application/rss+xml; charset=utf-8');
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the blog Atom feed.
|
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
|
public function blogAtom(): Response
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
$articles = Article::where('published', '1')->latest('updated_at')->take(20)->get();
|
|
|
|
|
|
|
|
|
|
return response()
|
2023-04-20 17:34:06 +01:00
|
|
|
|
->view('articles.atom', compact('articles'))
|
|
|
|
|
->header('Content-Type', 'application/atom+xml; charset=utf-8');
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the notes RSS feed.
|
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
|
public function notesRss(): Response
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
$notes = Note::latest()->take(20)->get();
|
|
|
|
|
$buildDate = $notes->first()->updated_at->toRssString();
|
|
|
|
|
|
|
|
|
|
return response()
|
2023-04-20 17:34:06 +01:00
|
|
|
|
->view('notes.rss', compact('notes', 'buildDate'))
|
|
|
|
|
->header('Content-Type', 'application/rss+xml; charset=utf-8');
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the notes Atom feed.
|
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
|
public function notesAtom(): Response
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
$notes = Note::latest()->take(20)->get();
|
|
|
|
|
|
|
|
|
|
return response()
|
2023-04-20 17:34:06 +01:00
|
|
|
|
->view('notes.atom', compact('notes'))
|
|
|
|
|
->header('Content-Type', 'application/atom+xml; charset=utf-8');
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
|
/** @todo sort out return type for json responses */
|
|
|
|
|
|
2017-06-04 19:06:22 +01:00
|
|
|
|
/**
|
|
|
|
|
* Returns the blog JSON feed.
|
|
|
|
|
*/
|
2020-08-09 15:54:10 +01:00
|
|
|
|
public function blogJson(): array
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
$articles = Article::where('published', '1')->latest('updated_at')->take(20)->get();
|
|
|
|
|
$data = [
|
|
|
|
|
'version' => 'https://jsonfeed.org/version/1',
|
|
|
|
|
'title' => 'The JSON Feed for ' . config('app.display_name') . '’s blog',
|
|
|
|
|
'home_page_url' => config('app.url') . '/blog',
|
|
|
|
|
'feed_url' => config('app.url') . '/blog/feed.json',
|
2017-06-05 15:40:38 +00:00
|
|
|
|
'items' => [],
|
2017-06-04 19:06:22 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($articles as $key => $article) {
|
|
|
|
|
$data['items'][$key] = [
|
|
|
|
|
'id' => config('app.url') . $article->link,
|
|
|
|
|
'title' => $article->title,
|
|
|
|
|
'url' => config('app.url') . $article->link,
|
|
|
|
|
'content_html' => $article->main,
|
|
|
|
|
'date_published' => $article->created_at->tz('UTC')->toRfc3339String(),
|
|
|
|
|
'date_modified' => $article->updated_at->tz('UTC')->toRfc3339String(),
|
|
|
|
|
'author' => [
|
2017-06-05 15:40:38 +00:00
|
|
|
|
'name' => config('app.display_name'),
|
|
|
|
|
],
|
2017-06-04 19:06:22 +01:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the notes JSON feed.
|
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
|
public function notesJson(): array
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2022-11-24 21:44:57 +00:00
|
|
|
|
$notes = Note::latest()->with('media')->take(20)->get();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$data = [
|
|
|
|
|
'version' => 'https://jsonfeed.org/version/1',
|
|
|
|
|
'title' => 'The JSON Feed for ' . config('app.display_name') . '’s notes',
|
|
|
|
|
'home_page_url' => config('app.url') . '/notes',
|
|
|
|
|
'feed_url' => config('app.url') . '/notes/feed.json',
|
2017-06-05 15:40:38 +00:00
|
|
|
|
'items' => [],
|
2017-06-04 19:06:22 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($notes as $key => $note) {
|
|
|
|
|
$data['items'][$key] = [
|
|
|
|
|
'id' => $note->longurl,
|
|
|
|
|
'url' => $note->longurl,
|
2018-04-12 18:15:42 +01:00
|
|
|
|
'content_html' => $note->content,
|
2017-06-04 19:06:22 +01:00
|
|
|
|
'date_published' => $note->created_at->tz('UTC')->toRfc3339String(),
|
|
|
|
|
'date_modified' => $note->updated_at->tz('UTC')->toRfc3339String(),
|
|
|
|
|
'author' => [
|
2017-06-05 15:40:38 +00:00
|
|
|
|
'name' => config('app.display_name'),
|
|
|
|
|
],
|
2017-06-04 19:06:22 +01:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2020-06-20 16:47:39 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the blog JF2 feed.
|
|
|
|
|
*/
|
|
|
|
|
public function blogJf2(): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$articles = Article::where('published', '1')->latest('updated_at')->take(20)->get();
|
|
|
|
|
$items = [];
|
|
|
|
|
foreach ($articles as $article) {
|
|
|
|
|
$items[] = [
|
|
|
|
|
'type' => 'entry',
|
|
|
|
|
'published' => $article->created_at,
|
|
|
|
|
'uid' => config('app.url') . $article->link,
|
|
|
|
|
'url' => config('app.url') . $article->link,
|
|
|
|
|
'content' => [
|
|
|
|
|
'text' => $article->main,
|
|
|
|
|
'html' => $article->html,
|
|
|
|
|
],
|
|
|
|
|
'post-type' => 'article',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'type' => 'feed',
|
|
|
|
|
'name' => 'Blog feed for ' . config('app.name'),
|
|
|
|
|
'url' => url('/blog'),
|
|
|
|
|
'author' => [
|
|
|
|
|
'type' => 'card',
|
|
|
|
|
'name' => config('user.displayname'),
|
|
|
|
|
'url' => config('app.longurl'),
|
|
|
|
|
],
|
|
|
|
|
'children' => $items,
|
|
|
|
|
], 200, [
|
|
|
|
|
'Content-Type' => 'application/jf2feed+json',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the notes JF2 feed.
|
|
|
|
|
*/
|
|
|
|
|
public function notesJf2(): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$notes = Note::latest()->take(20)->get();
|
|
|
|
|
$items = [];
|
|
|
|
|
foreach ($notes as $note) {
|
|
|
|
|
$items[] = [
|
|
|
|
|
'type' => 'entry',
|
|
|
|
|
'published' => $note->created_at,
|
|
|
|
|
'uid' => $note->longurl,
|
|
|
|
|
'url' => $note->longurl,
|
|
|
|
|
'content' => [
|
|
|
|
|
'text' => $note->getRawOriginal('note'),
|
|
|
|
|
'html' => $note->note,
|
|
|
|
|
],
|
|
|
|
|
'post-type' => 'note',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'type' => 'feed',
|
|
|
|
|
'name' => 'Notes feed for ' . config('app.name'),
|
|
|
|
|
'url' => url('/notes'),
|
|
|
|
|
'author' => [
|
|
|
|
|
'type' => 'card',
|
|
|
|
|
'name' => config('user.displayname'),
|
|
|
|
|
'url' => config('app.longurl'),
|
|
|
|
|
],
|
|
|
|
|
'children' => $items,
|
|
|
|
|
], 200, [
|
|
|
|
|
'Content-Type' => 'application/jf2feed+json',
|
|
|
|
|
]);
|
|
|
|
|
}
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|