92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\Data\SettingsService;
|
|
use Carbon\Carbon;
|
|
|
|
class RSSController extends Controller
|
|
{
|
|
protected PageRepositoryInterface $pages;
|
|
protected SettingsService $settings;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepo,
|
|
SettingsService $settingsService,
|
|
) {
|
|
$this->settings = $settingsService;
|
|
$this->pages = $pageRepo;
|
|
}
|
|
|
|
public function getFeed(Request $request)
|
|
{
|
|
$pages = $this->pages->getAll();
|
|
$global = $this->settings->getGlobal();
|
|
$feedContent = "<?xml version='1.0' encoding='ISO-8859-1'?>
|
|
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
|
|
<channel>
|
|
<title>{$global['title']}</title>
|
|
<atom:link href='{$global['base_url']}/rss/feed/' rel='self' type='application/rss+xml' />
|
|
<link>{$global['base_url']}</link>
|
|
<description>Feed @ {$global['title']}</description>
|
|
<language>en-us</language>";
|
|
|
|
// Loop over the content and add it to the feed
|
|
foreach ($pages as $item) {
|
|
$title = urldecode($item['title']);
|
|
$html = urldecode($item['html']);
|
|
$updatedAt = Carbon::parse($item['rawUpdated']);
|
|
$date = $updatedAt->format('D, d M Y H:i:s O');
|
|
$link = $global['base_url'] . "/" . $item['path'] . "/" . $item['slug'];
|
|
if ($global['dynamicRender'] != "true") {
|
|
$link = $link . ".html";
|
|
}
|
|
$feedContent .= "
|
|
<item>
|
|
<title>{$title}</title>
|
|
<link>{$link}</link>
|
|
<guid>{$global['base_url']}/rss/feed/item/{$item['uuid']}</guid>
|
|
<pubDate>{$date}</pubDate>
|
|
<description><![CDATA[{$html}]]></description>
|
|
</item>";
|
|
}
|
|
|
|
$feedContent .= "
|
|
</channel>
|
|
</rss>";
|
|
|
|
return response($feedContent, 200)->header('Content-Type', 'application/rss+xml');
|
|
/**
|
|
//set up feed info
|
|
header("Content-Type: text/xml");
|
|
echo("<?xml version='1.0' encoding='ISO-8859-1'?>");
|
|
echo("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>");
|
|
echo("<channel>");
|
|
echo("<title>" . $global['title'] . "</title>");
|
|
echo("<link>" . $global['base_url'] . "</link>");
|
|
echo("<description>The Feed for " . $global['title'] . "</description>");
|
|
|
|
//item loop start
|
|
|
|
foreach ($pages as $item) {
|
|
echo("<item id='" . $item['id'] . "'>");
|
|
echo("<title>" . urldecode($item['title']) . "</title>");
|
|
echo("<link>" . $global['base_url'] . "/rss/feed/item/" . $item['uuid'] . "</link>");
|
|
echo("<guid>" . $global['base_url'] . "/rss/feed/item/" . $item['uuid'] . "</guid>");
|
|
echo("<displayDate>" . $item['updated'] . "</displayDate>");
|
|
echo("<pubDate>" . $item['created'] . "</pubDate>");
|
|
echo("<description> <![CDATA[" . $item['html'] . "]]></description>");
|
|
echo("<author>" . $item['author'] . "</author>");
|
|
echo("</item>");
|
|
}
|
|
|
|
//item loop end
|
|
|
|
//close it up
|
|
echo("</channel>");
|
|
echo("</rss>");
|
|
**/
|
|
}
|
|
}
|