rss-bridge/formats/HtmlFormat.php

64 lines
2.2 KiB
PHP
Raw Normal View History

2013-08-11 15:30:41 +04:00
<?php
class HtmlFormat extends FormatAbstract
{
const MIME_TYPE = 'text/html';
2024-08-23 18:34:06 +03:00
public function render(): string
{
2024-04-06 19:07:45 +03:00
// This query string is url encoded
$queryString = $_SERVER['QUERY_STRING'];
// TODO: this should be the proper bridge short name and not user provided string
$bridgeName = $_GET['bridge'];
$feedArray = $this->getFeed();
2022-07-06 13:14:04 +03:00
$formatFactory = new FormatFactory();
2024-03-31 04:38:42 +03:00
$formats = [];
// Create all formats (except HTML)
$formatNames = $formatFactory->getFormatNames();
foreach ($formatNames as $formatName) {
if ($formatName === 'Html') {
continue;
}
2024-03-31 04:38:42 +03:00
// The format url is relative, but should be absolute in order to help feed readers.
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $formatName, $queryString);
$formatObject = $formatFactory->create($formatName);
$formats[] = [
'url' => $formatUrl,
'name' => $formatName,
'type' => $formatObject->getMimeType(),
];
}
$items = [];
foreach ($this->getItems() as $item) {
$items[] = [
'url' => $item->getURI() ?: $feedArray['uri'],
'title' => $item->getTitle() ?? '(no title)',
'timestamp' => $item->getTimestamp(),
'author' => $item->getAuthor(),
'content' => $item->getContent() ?? '',
'enclosures' => $item->getEnclosures(),
'categories' => $item->getCategories(),
];
}
2013-08-11 15:30:41 +04:00
2024-03-31 04:38:42 +03:00
$donationUri = null;
if (Configuration::getConfig('admin', 'donations') && $feedArray['donationUri']) {
$donationUri = $feedArray['donationUri'];
}
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
'bridge_name' => $bridgeName,
2024-03-31 04:38:42 +03:00
'title' => $feedArray['name'],
'formats' => $formats,
'uri' => $feedArray['uri'],
'items' => $items,
'donation_uri' => $donationUri,
]);
return $html;
}
2014-05-28 18:57:30 +04:00
}