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()
|
|
|
|
{
|
|
|
|
$extraInfos = $this->getExtraInfos();
|
2022-08-06 23:46:28 +03:00
|
|
|
$title = e($extraInfos['name']);
|
|
|
|
$uri = e($extraInfos['uri']);
|
|
|
|
$donationUri = e($extraInfos['donationUri']);
|
2021-06-25 22:45:25 +03:00
|
|
|
$donationsAllowed = Configuration::getConfig('admin', 'donations');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-06-20 00:09:08 +03:00
|
|
|
// Dynamically build buttons for all formats (except HTML)
|
2022-07-06 13:14:04 +03:00
|
|
|
$formatFactory = new FormatFactory();
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-06-20 00:09:08 +03:00
|
|
|
$buttons = '';
|
2019-11-09 20:43:21 +03:00
|
|
|
$links = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-07-06 13:14:04 +03:00
|
|
|
foreach ($formatFactory->getFormatNames() as $format) {
|
2022-08-06 23:46:28 +03:00
|
|
|
if ($format === 'Html') {
|
2019-06-20 00:09:08 +03:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
$queryString = $_SERVER['QUERY_STRING'];
|
|
|
|
$query = str_ireplace('format=Html', 'format=' . $format, htmlentities($queryString));
|
|
|
|
$buttons .= sprintf('<a href="./?%s"><button class="rss-feed">%s</button></a>', $query, $format) . "\n";
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-07-06 13:14:04 +03:00
|
|
|
$mime = $formatFactory->create($format)->getMimeType();
|
2022-08-06 23:46:28 +03:00
|
|
|
$links .= sprintf('<link href="./?%s" title="%s" rel="alternate" type="%s">', $query, $format, $mime) . "\n";
|
2019-06-20 00:09:08 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-06-25 22:45:25 +03:00
|
|
|
if ($donationUri !== '' && $donationsAllowed) {
|
2022-08-06 23:46:28 +03:00
|
|
|
$str = sprintf(
|
|
|
|
'<a href="%s" target="_blank"><button class="highlight">Donate to maintainer</button></a>',
|
|
|
|
$donationUri
|
|
|
|
);
|
|
|
|
$buttons .= $str;
|
|
|
|
$str1 = sprintf(
|
|
|
|
'<link href="%s target="_blank"" title="Donate to Maintainer" rel="alternate">',
|
|
|
|
$donationUri
|
|
|
|
);
|
|
|
|
$links .= $str1;
|
2021-06-25 22:45:25 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$entries = '';
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($this->getItems() as $item) {
|
2022-08-06 23:46:28 +03:00
|
|
|
if ($item->getAuthor()) {
|
|
|
|
$entryAuthor = sprintf('<br /><p class="author">by: %s</p>', $item->getAuthor());
|
|
|
|
} else {
|
|
|
|
$entryAuthor = '';
|
|
|
|
}
|
|
|
|
$entryTitle = sanitize_html(strip_tags($item->getTitle()));
|
2018-12-27 00:41:32 +03:00
|
|
|
$entryUri = $item->getURI() ?: $uri;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-03-22 22:41:13 +03:00
|
|
|
$entryDate = '';
|
2018-12-27 00:41:32 +03:00
|
|
|
if ($item->getTimestamp()) {
|
2022-03-22 22:41:13 +03:00
|
|
|
$entryDate = sprintf(
|
|
|
|
'<time datetime="%s">%s</time>',
|
|
|
|
date('Y-m-d H:i:s', $item->getTimestamp()),
|
|
|
|
date('Y-m-d H:i:s', $item->getTimestamp())
|
|
|
|
);
|
2016-09-10 22:01:02 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 22:01:02 +03:00
|
|
|
$entryContent = '';
|
2018-12-27 00:41:32 +03:00
|
|
|
if ($item->getContent()) {
|
2022-08-06 23:46:28 +03:00
|
|
|
$str2 = sprintf('<div class="content">%s</div>', sanitize_html($item->getContent()));
|
|
|
|
$entryContent = $str2;
|
2016-09-10 22:01:02 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures = '';
|
2018-12-27 00:41:32 +03:00
|
|
|
if (!empty($item->getEnclosures())) {
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures = '<div class="attachments"><p>Attachments:</p>';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-12-27 00:41:32 +03:00
|
|
|
foreach ($item->getEnclosures() as $enclosure) {
|
2022-04-09 00:14:43 +03:00
|
|
|
$template = '<li class="enclosure"><a href="%s" rel="noopener noreferrer nofollow">%s</a></li>';
|
2022-08-06 23:46:28 +03:00
|
|
|
$url = sanitize_html($enclosure);
|
2022-04-09 00:14:43 +03:00
|
|
|
$anchorText = substr($url, strrpos($url, '/') + 1);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-09 00:14:43 +03:00
|
|
|
$entryEnclosures .= sprintf($template, $url, $anchorText);
|
2016-11-13 00:04:42 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures .= '</div>';
|
2016-11-09 20:59:17 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-07-16 13:32:24 +03:00
|
|
|
$entryCategories = '';
|
2018-12-27 00:41:32 +03:00
|
|
|
if (!empty($item->getCategories())) {
|
2018-07-16 13:32:24 +03:00
|
|
|
$entryCategories = '<div class="categories"><p>Categories:</p>';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-12-27 00:41:32 +03:00
|
|
|
foreach ($item->getCategories() as $category) {
|
2018-07-16 13:32:24 +03:00
|
|
|
$entryCategories .= '<li class="category">'
|
2022-08-06 23:46:28 +03:00
|
|
|
. sanitize_html($category)
|
2018-07-16 13:32:24 +03:00
|
|
|
. '</li>';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-07-16 13:32:24 +03:00
|
|
|
$entryCategories .= '</div>';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$entries .= <<<EOD
|
2013-08-11 15:30:41 +04:00
|
|
|
|
2016-08-03 21:07:49 +03:00
|
|
|
<section class="feeditem">
|
2016-09-10 21:41:11 +03:00
|
|
|
<h2><a class="itemtitle" href="{$entryUri}">{$entryTitle}</a></h2>
|
2022-03-22 22:41:13 +03:00
|
|
|
{$entryDate}
|
2016-09-10 21:41:11 +03:00
|
|
|
{$entryAuthor}
|
|
|
|
{$entryContent}
|
2016-11-13 00:04:42 +03:00
|
|
|
{$entryEnclosures}
|
2018-07-16 13:32:24 +03:00
|
|
|
{$entryCategories}
|
2016-08-03 21:07:49 +03:00
|
|
|
</section>
|
2013-08-11 15:30:41 +04:00
|
|
|
|
|
|
|
EOD;
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2013-08-11 15:30:41 +04:00
|
|
|
|
2016-11-07 22:49:44 +03:00
|
|
|
$charset = $this->getCharset();
|
2016-09-10 21:41:11 +03:00
|
|
|
$toReturn = <<<EOD
|
2014-05-28 18:57:30 +04:00
|
|
|
<!DOCTYPE html>
|
2013-08-11 15:30:41 +04:00
|
|
|
<html>
|
2014-05-28 18:57:30 +04:00
|
|
|
<head>
|
2016-11-07 22:49:44 +03:00
|
|
|
<meta charset="{$charset}">
|
2019-06-21 22:22:21 +03:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2016-09-10 21:41:11 +03:00
|
|
|
<title>{$title}</title>
|
2017-03-21 23:31:10 +03:00
|
|
|
<link href="static/HtmlFormat.css" rel="stylesheet">
|
2019-06-25 19:39:28 +03:00
|
|
|
<link rel="icon" type="image/png" href="static/favicon.png">
|
2019-11-09 20:43:21 +03:00
|
|
|
{$links}
|
2016-09-10 21:41:11 +03:00
|
|
|
<meta name="robots" content="noindex, follow">
|
2014-05-28 18:57:30 +04:00
|
|
|
</head>
|
|
|
|
<body>
|
2016-09-10 21:41:11 +03:00
|
|
|
<h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
|
|
|
|
<div class="buttons">
|
|
|
|
<a href="./#bridge-{$_GET['bridge']}"><button class="backbutton">← back to rss-bridge</button></a>
|
2019-06-20 00:09:08 +03:00
|
|
|
{$buttons}
|
2016-09-10 21:41:11 +03:00
|
|
|
</div>
|
2013-08-11 15:30:41 +04:00
|
|
|
{$entries}
|
2014-05-28 18:57:30 +04:00
|
|
|
</body>
|
2013-08-11 15:30:41 +04:00
|
|
|
</html>
|
|
|
|
EOD;
|
|
|
|
|
2016-11-07 22:49:44 +03:00
|
|
|
// Remove invalid characters
|
|
|
|
ini_set('mbstring.substitute_character', 'none');
|
|
|
|
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
2016-09-10 21:41:11 +03:00
|
|
|
return $toReturn;
|
|
|
|
}
|
2014-05-28 18:57:30 +04:00
|
|
|
}
|