2013-08-11 15:30:41 +04:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
class HtmlFormat extends FormatAbstract
|
|
|
|
{
|
2019-10-31 21:00:12 +03:00
|
|
|
const MIME_TYPE = 'text/html';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-08-23 18:34:06 +03:00
|
|
|
public function render(): string
|
2016-09-10 21:41:11 +03:00
|
|
|
{
|
2024-04-06 19:07:45 +03:00
|
|
|
// This query string is url encoded
|
2023-09-25 23:32:15 +03:00
|
|
|
$queryString = $_SERVER['QUERY_STRING'];
|
|
|
|
|
2024-08-22 01:33:35 +03:00
|
|
|
// TODO: this should be the proper bridge short name and not user provided string
|
|
|
|
$bridgeName = $_GET['bridge'];
|
|
|
|
|
2024-01-09 22:18:33 +03:00
|
|
|
$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) {
|
2024-01-25 18:06:24 +03:00
|
|
|
if ($formatName === 'Html') {
|
2019-06-20 00:09:08 +03:00
|
|
|
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(),
|
2022-10-16 13:03:57 +03:00
|
|
|
];
|
2021-06-25 22:45:25 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-10-16 13:03:57 +03:00
|
|
|
$items = [];
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($this->getItems() as $item) {
|
2022-10-16 13:03:57 +03:00
|
|
|
$items[] = [
|
2024-01-09 22:18:33 +03:00
|
|
|
'url' => $item->getURI() ?: $feedArray['uri'],
|
2022-10-16 13:03:57 +03:00
|
|
|
'title' => $item->getTitle() ?? '(no title)',
|
|
|
|
'timestamp' => $item->getTimestamp(),
|
|
|
|
'author' => $item->getAuthor(),
|
|
|
|
'content' => $item->getContent() ?? '',
|
|
|
|
'enclosures' => $item->getEnclosures(),
|
|
|
|
'categories' => $item->getCategories(),
|
|
|
|
];
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
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'];
|
|
|
|
}
|
|
|
|
|
2022-10-16 13:03:57 +03:00
|
|
|
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
|
2024-08-22 01:33:35 +03:00
|
|
|
'bridge_name' => $bridgeName,
|
2024-03-31 04:38:42 +03:00
|
|
|
'title' => $feedArray['name'],
|
|
|
|
'formats' => $formats,
|
|
|
|
'uri' => $feedArray['uri'],
|
|
|
|
'items' => $items,
|
|
|
|
'donation_uri' => $donationUri,
|
2022-10-16 13:03:57 +03:00
|
|
|
]);
|
2023-09-25 23:32:15 +03:00
|
|
|
return $html;
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2014-05-28 18:57:30 +04:00
|
|
|
}
|