fipamo/app/Http/Controllers/RSSController.php

110 lines
4 KiB
PHP
Raw Normal View History

<?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";
}
//grabs feature image or vid and tosses it in the description
$media = explode(",", $item['feature']);
$file = '';
if ($media[0] == null || $media[0] == '') {
$file = $global['background'];
} else {
$file = $media[0];
}
$ext = pathinfo($file, PATHINFO_EXTENSION);
$url = $global['base_url'] . $file;
if ($ext != 'mp4') {
$top = "<img src='{$url}'/>";
} else {
$top = " <video><source src='{$url}' /></video>";
}
$feedContent .= "
<item>
<title>{$title}</title>
<link>{$link}</link>
<guid>{$global['base_url']}/rss/feed/item/{$item['uuid']}</guid>
<pubDate>{$date}</pubDate>
2025-05-20 18:29:50 -06:00
<description><![CDATA[{$top}<br/>]]><![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>");
**/
}
}