mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-19 17:55:33 +03:00
e21394d2d3
* refactor: html format Fix a few small bugs too * fix * fix * trigger build * striptags instead of encode title
62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
|
|
class HtmlFormat extends FormatAbstract
|
|
{
|
|
const MIME_TYPE = 'text/html';
|
|
|
|
public function stringify()
|
|
{
|
|
$extraInfos = $this->getExtraInfos();
|
|
$formatFactory = new FormatFactory();
|
|
$buttons = [];
|
|
$linkTags = [];
|
|
foreach ($formatFactory->getFormatNames() as $format) {
|
|
// Dynamically build buttons for all formats (except HTML)
|
|
if ($format === 'Html') {
|
|
continue;
|
|
}
|
|
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING']));
|
|
$buttons[] = [
|
|
'href' => $formatUrl,
|
|
'value' => $format,
|
|
];
|
|
$linkTags[] = [
|
|
'href' => $formatUrl,
|
|
'title' => $format,
|
|
'type' => $formatFactory->create($format)->getMimeType(),
|
|
];
|
|
}
|
|
|
|
if (Configuration::getConfig('admin', 'donations') && $extraInfos['donationUri'] !== '') {
|
|
$buttons[] = [
|
|
'href' => e($extraInfos['donationUri']),
|
|
'value' => 'Donate to maintainer',
|
|
];
|
|
}
|
|
|
|
$items = [];
|
|
foreach ($this->getItems() as $item) {
|
|
$items[] = [
|
|
'url' => $item->getURI() ?: $extraInfos['uri'],
|
|
'title' => $item->getTitle() ?? '(no title)',
|
|
'timestamp' => $item->getTimestamp(),
|
|
'author' => $item->getAuthor(),
|
|
'content' => $item->getContent() ?? '',
|
|
'enclosures' => $item->getEnclosures(),
|
|
'categories' => $item->getCategories(),
|
|
];
|
|
}
|
|
|
|
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
|
|
'charset' => $this->getCharset(),
|
|
'title' => $extraInfos['name'],
|
|
'linkTags' => $linkTags,
|
|
'uri' => $extraInfos['uri'],
|
|
'buttons' => $buttons,
|
|
'items' => $items,
|
|
]);
|
|
// Remove invalid characters
|
|
ini_set('mbstring.substitute_character', 'none');
|
|
return mb_convert_encoding($html, $this->getCharset(), 'UTF-8');
|
|
}
|
|
}
|