Skip to content

Commit 360340e

Browse files
authored
Basic RSS support (#103)
1 parent 1720f50 commit 360340e

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

resources/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
":count Incident": ":count Incident|:count Incidents",
3+
":name RSS Feed": ":name RSS Feed",
34
"Admin": "Admin",
45
"Always Hidden": "Always Hidden",
56
"Always collapsed": "Always collapsed",

resources/views/rss.blade.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?=
2+
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
3+
?>
4+
<rss version="2.0">
5+
<channel>
6+
<title><![CDATA[ {{ __(':name RSS Feed', ['name' => $statusPageName]) }} ]]></title>
7+
<link><![CDATA[ {{ route('cachet.rss') }} ]]></link>
8+
@if($statusAbout)
9+
<description><![CDATA[ {{ $statusAbout }} ]]></description>
10+
@endif
11+
<language>{{ config('app.locale') }}</language>
12+
<pubDate>{{ now()->toRssString() }}</pubDate>
13+
14+
@foreach($incidents as $incident)
15+
<item>
16+
<title>{{ $incident->name }}</title>
17+
<link>{{ route('cachet.status-page.incident', $incident) }}</link>
18+
<description><![CDATA[{!! $incident->message !!}]]></description>
19+
<guid>{{ $incident->guid }}</guid>
20+
<pubDate>{{ $incident->created_at->toRssString() }}</pubDate>
21+
</item>
22+
@endforeach
23+
</channel>
24+
</rss>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Cachet\Http\Controllers;
4+
5+
use Cachet\Models\Incident;
6+
use Cachet\Settings\AppSettings;
7+
use Illuminate\Http\Response;
8+
9+
class RssController
10+
{
11+
/**
12+
* Returns the RSS feed of all incidents.
13+
*/
14+
public function __invoke(AppSettings $appSettings): Response
15+
{
16+
return response()->view('cachet::rss', [
17+
'statusPageName' => $appSettings->name,
18+
'statusAbout' => $appSettings->about,
19+
'incidents' => Incident::query()
20+
->guests()
21+
->with('incidentUpdates')
22+
->orderByDesc('created_at')
23+
->get(),
24+
])->header('Content-Type', 'application/rss+xml');
25+
}
26+
}

src/PendingRouteRegistration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Cachet;
44

55
use Cachet\Http\Controllers\HealthController;
6+
use Cachet\Http\Controllers\RssController;
67
use Cachet\Http\Controllers\Setup\SetupController;
78
use Cachet\Http\Controllers\StatusPage\StatusPageController;
89
use Illuminate\Routing\Router;
@@ -37,6 +38,8 @@ public function register(): void
3738
// @todo subscription routes... subscribe, manage subscriptions, unsubscribe
3839

3940
$router->get('/health', HealthController::class)->name('health');
41+
42+
$router->get('/rss', RssController::class)->name('rss');
4043
});
4144
}
4245

tests/Feature/RssTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Cachet\Models\Incident;
4+
5+
it('can get the rss feed', function () {
6+
$incident = Incident::factory()->create();
7+
8+
$this->get('/status/rss')
9+
->assertOk()
10+
->assertSee($incident->name);
11+
});

0 commit comments

Comments
 (0)