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
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
public function stringify()
|
|
|
|
{
|
2023-09-25 23:32:15 +03:00
|
|
|
$queryString = $_SERVER['QUERY_STRING'];
|
|
|
|
|
2024-01-09 22:18:33 +03:00
|
|
|
$feedArray = $this->getFeed();
|
2022-07-06 13:14:04 +03:00
|
|
|
$formatFactory = new FormatFactory();
|
2022-10-16 13:03:57 +03:00
|
|
|
$buttons = [];
|
|
|
|
$linkTags = [];
|
2022-07-06 13:14:04 +03:00
|
|
|
foreach ($formatFactory->getFormatNames() as $format) {
|
2022-10-16 13:03:57 +03:00
|
|
|
// Dynamically build buttons for all formats (except HTML)
|
2022-08-06 23:46:28 +03:00
|
|
|
if ($format === 'Html') {
|
2019-06-20 00:09:08 +03:00
|
|
|
continue;
|
|
|
|
}
|
2023-09-25 23:32:15 +03:00
|
|
|
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $format, htmlentities($queryString));
|
2022-10-16 13:03:57 +03:00
|
|
|
$buttons[] = [
|
|
|
|
'href' => $formatUrl,
|
|
|
|
'value' => $format,
|
|
|
|
];
|
|
|
|
$linkTags[] = [
|
|
|
|
'href' => $formatUrl,
|
|
|
|
'title' => $format,
|
|
|
|
'type' => $formatFactory->create($format)->getMimeType(),
|
|
|
|
];
|
2019-06-20 00:09:08 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-01-09 22:18:33 +03:00
|
|
|
if (Configuration::getConfig('admin', 'donations') && $feedArray['donationUri']) {
|
2022-10-16 13:03:57 +03:00
|
|
|
$buttons[] = [
|
2024-01-09 22:18:33 +03:00
|
|
|
'href' => e($feedArray['donationUri']),
|
2022-10-16 13:03:57 +03:00
|
|
|
'value' => 'Donate to maintainer',
|
|
|
|
];
|
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
|
|
|
|
2022-10-16 13:03:57 +03:00
|
|
|
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
|
|
|
|
'charset' => $this->getCharset(),
|
2024-01-09 22:18:33 +03:00
|
|
|
'title' => $feedArray['name'],
|
2022-10-16 13:03:57 +03:00
|
|
|
'linkTags' => $linkTags,
|
2024-01-09 22:18:33 +03:00
|
|
|
'uri' => $feedArray['uri'],
|
2022-10-16 13:03:57 +03:00
|
|
|
'buttons' => $buttons,
|
|
|
|
'items' => $items,
|
|
|
|
]);
|
2016-11-07 22:49:44 +03:00
|
|
|
// Remove invalid characters
|
|
|
|
ini_set('mbstring.substitute_character', 'none');
|
2023-09-25 23:32:15 +03:00
|
|
|
$html = mb_convert_encoding($html, $this->getCharset(), 'UTF-8');
|
|
|
|
return $html;
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2014-05-28 18:57:30 +04:00
|
|
|
}
|