2013-08-11 13:30:41 +02:00
|
|
|
<?php
|
2016-09-10 20:41:11 +02:00
|
|
|
class HtmlFormat extends FormatAbstract {
|
2019-10-31 19:00:12 +01:00
|
|
|
const MIME_TYPE = 'text/html';
|
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
public function stringify(){
|
|
|
|
$extraInfos = $this->getExtraInfos();
|
|
|
|
$title = htmlspecialchars($extraInfos['name']);
|
|
|
|
$uri = htmlspecialchars($extraInfos['uri']);
|
2019-06-19 23:09:08 +02:00
|
|
|
|
|
|
|
// Dynamically build buttons for all formats (except HTML)
|
|
|
|
$formatFac = new FormatFactory();
|
|
|
|
$formatFac->setWorkingDir(PATH_LIB_FORMATS);
|
|
|
|
|
|
|
|
$buttons = '';
|
|
|
|
|
|
|
|
foreach($formatFac->getFormatNames() as $format) {
|
|
|
|
if(strcasecmp($format, 'HTML') === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = str_replace('format=Html', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING']));
|
|
|
|
$buttons .= $this->buildButton($format, $query) . PHP_EOL;
|
|
|
|
}
|
2016-09-10 20:41:11 +02:00
|
|
|
|
|
|
|
$entries = '';
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($this->getItems() as $item) {
|
2018-12-26 22:41:32 +01:00
|
|
|
$entryAuthor = $item->getAuthor() ? '<br /><p class="author">by: ' . $item->getAuthor() . '</p>' : '';
|
|
|
|
$entryTitle = $this->sanitizeHtml(strip_tags($item->getTitle()));
|
|
|
|
$entryUri = $item->getURI() ?: $uri;
|
2016-09-10 21:01:02 +02:00
|
|
|
|
|
|
|
$entryTimestamp = '';
|
2018-12-26 22:41:32 +01:00
|
|
|
if($item->getTimestamp()) {
|
2016-09-10 21:01:02 +02:00
|
|
|
$entryTimestamp = '<time datetime="'
|
2018-12-26 22:41:32 +01:00
|
|
|
. date(DATE_ATOM, $item->getTimestamp())
|
2016-09-10 21:01:02 +02:00
|
|
|
. '">'
|
2018-12-26 22:41:32 +01:00
|
|
|
. date(DATE_ATOM, $item->getTimestamp())
|
2016-09-10 21:01:02 +02:00
|
|
|
. '</time>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$entryContent = '';
|
2018-12-26 22:41:32 +01:00
|
|
|
if($item->getContent()) {
|
2016-09-10 21:01:02 +02:00
|
|
|
$entryContent = '<div class="content">'
|
2018-12-26 22:41:32 +01:00
|
|
|
. $this->sanitizeHtml($item->getContent())
|
2016-09-10 21:01:02 +02:00
|
|
|
. '</div>';
|
|
|
|
}
|
|
|
|
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosures = '';
|
2018-12-26 22:41:32 +01:00
|
|
|
if(!empty($item->getEnclosures())) {
|
2016-11-12 22:04:42 +01:00
|
|
|
$entryEnclosures = '<div class="attachments"><p>Attachments:</p>';
|
|
|
|
|
2018-12-26 22:41:32 +01:00
|
|
|
foreach($item->getEnclosures() as $enclosure) {
|
2016-11-12 22:04:42 +01:00
|
|
|
$url = $this->sanitizeHtml($enclosure);
|
|
|
|
|
|
|
|
$entryEnclosures .= '<li class="enclosure"><a href="'
|
|
|
|
. $url
|
|
|
|
. '">'
|
|
|
|
. substr($url, strrpos($url, '/') + 1)
|
|
|
|
. '</a></li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$entryEnclosures .= '</div>';
|
2016-11-09 18:59:17 +01:00
|
|
|
}
|
|
|
|
|
2018-07-16 12:32:24 +02:00
|
|
|
$entryCategories = '';
|
2018-12-26 22:41:32 +01:00
|
|
|
if(!empty($item->getCategories())) {
|
2018-07-16 12:32:24 +02:00
|
|
|
$entryCategories = '<div class="categories"><p>Categories:</p>';
|
|
|
|
|
2018-12-26 22:41:32 +01:00
|
|
|
foreach($item->getCategories() as $category) {
|
2018-07-16 12:32:24 +02:00
|
|
|
|
|
|
|
$entryCategories .= '<li class="category">'
|
|
|
|
. $this->sanitizeHtml($category)
|
|
|
|
. '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$entryCategories .= '</div>';
|
|
|
|
}
|
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
$entries .= <<<EOD
|
2013-08-11 13:30:41 +02:00
|
|
|
|
2016-08-03 20:07:49 +02:00
|
|
|
<section class="feeditem">
|
2016-09-10 20:41:11 +02:00
|
|
|
<h2><a class="itemtitle" href="{$entryUri}">{$entryTitle}</a></h2>
|
|
|
|
{$entryTimestamp}
|
|
|
|
{$entryAuthor}
|
|
|
|
{$entryContent}
|
2016-11-12 22:04:42 +01:00
|
|
|
{$entryEnclosures}
|
2018-07-16 12:32:24 +02:00
|
|
|
{$entryCategories}
|
2016-08-03 20:07:49 +02:00
|
|
|
</section>
|
2013-08-11 13:30:41 +02:00
|
|
|
|
|
|
|
EOD;
|
2016-09-10 20:41:11 +02:00
|
|
|
}
|
2013-08-11 13:30:41 +02:00
|
|
|
|
2016-11-07 20:49:44 +01:00
|
|
|
$charset = $this->getCharset();
|
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
|
|
|
$toReturn = <<<EOD
|
2014-05-28 16:57:30 +02:00
|
|
|
<!DOCTYPE html>
|
2013-08-11 13:30:41 +02:00
|
|
|
<html>
|
2014-05-28 16:57:30 +02:00
|
|
|
<head>
|
2016-11-07 20:49:44 +01:00
|
|
|
<meta charset="{$charset}">
|
2019-06-21 21:22:21 +02:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2016-09-10 20:41:11 +02:00
|
|
|
<title>{$title}</title>
|
2017-03-21 21:31:10 +01:00
|
|
|
<link href="static/HtmlFormat.css" rel="stylesheet">
|
2019-06-25 18:39:28 +02:00
|
|
|
<link rel="icon" type="image/png" href="static/favicon.png">
|
2016-09-10 20:41:11 +02:00
|
|
|
<meta name="robots" content="noindex, follow">
|
2014-05-28 16:57:30 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
2016-09-10 20:41:11 +02: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-19 23:09:08 +02:00
|
|
|
{$buttons}
|
2016-09-10 20:41:11 +02:00
|
|
|
</div>
|
2013-08-11 13:30:41 +02:00
|
|
|
{$entries}
|
2014-05-28 16:57:30 +02:00
|
|
|
</body>
|
2013-08-11 13:30:41 +02:00
|
|
|
</html>
|
|
|
|
EOD;
|
|
|
|
|
2016-11-07 20:49:44 +01:00
|
|
|
// Remove invalid characters
|
|
|
|
ini_set('mbstring.substitute_character', 'none');
|
|
|
|
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
2016-09-10 20:41:11 +02:00
|
|
|
return $toReturn;
|
|
|
|
}
|
2013-08-11 13:30:41 +02:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
public function display() {
|
|
|
|
$this
|
2019-10-31 19:00:12 +01:00
|
|
|
->setContentType(self::MIME_TYPE . '; charset=' . $this->getCharset())
|
2016-09-10 20:41:11 +02:00
|
|
|
->callContentType();
|
2013-08-11 13:30:41 +02:00
|
|
|
|
2016-09-10 20:41:11 +02:00
|
|
|
return parent::display();
|
|
|
|
}
|
2019-06-19 23:09:08 +02:00
|
|
|
|
|
|
|
private function buildButton($format, $query) {
|
|
|
|
return <<<EOD
|
|
|
|
<a href="./?{$query}"><button class="rss-feed">{$format}</button></a>
|
|
|
|
EOD;
|
|
|
|
}
|
2014-05-28 16:57:30 +02:00
|
|
|
}
|