mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-04 10:04:54 +02:00
refactor: format rendering (#4229)
This commit is contained in:
parent
c849576c93
commit
6516e31c1b
12 changed files with 25 additions and 50 deletions
|
@ -14,9 +14,9 @@ class AtomFormat extends FormatAbstract
|
|||
protected const ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
protected const MRSS_NS = 'http://search.yahoo.com/mrss/';
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
$document = new \DomDocument('1.0', $this->getCharset());
|
||||
$document = new \DomDocument('1.0', 'UTF-8');
|
||||
$document->formatOutput = true;
|
||||
|
||||
$feedUrl = get_current_url();
|
||||
|
@ -86,8 +86,6 @@ class AtomFormat extends FormatAbstract
|
|||
$author->appendChild($authorName);
|
||||
$authorName->appendChild($document->createTextNode($feedAuthor));
|
||||
|
||||
|
||||
|
||||
foreach ($this->getItems() as $item) {
|
||||
$itemArray = $item->toArray();
|
||||
$entryTimestamp = $item->getTimestamp();
|
||||
|
@ -204,10 +202,6 @@ class AtomFormat extends FormatAbstract
|
|||
}
|
||||
|
||||
$xml = $document->saveXML();
|
||||
|
||||
// Remove invalid characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$xml = mb_convert_encoding($xml, $this->getCharset(), 'UTF-8');
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ class HtmlFormat extends FormatAbstract
|
|||
{
|
||||
const MIME_TYPE = 'text/html';
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
// This query string is url encoded
|
||||
$queryString = $_SERVER['QUERY_STRING'];
|
||||
|
@ -52,16 +52,12 @@ class HtmlFormat extends FormatAbstract
|
|||
|
||||
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
|
||||
'bridge_name' => $bridgeName,
|
||||
'charset' => $this->getCharset(),
|
||||
'title' => $feedArray['name'],
|
||||
'formats' => $formats,
|
||||
'uri' => $feedArray['uri'],
|
||||
'items' => $items,
|
||||
'donation_uri' => $donationUri,
|
||||
]);
|
||||
// Remove invalid characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$html = mb_convert_encoding($html, $this->getCharset(), 'UTF-8');
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class JsonFormat extends FormatAbstract
|
|||
'uid',
|
||||
];
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
$feedArray = $this->getFeed();
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ class MrssFormat extends FormatAbstract
|
|||
protected const ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
protected const MRSS_NS = 'http://search.yahoo.com/mrss/';
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
$document = new \DomDocument('1.0', $this->getCharset());
|
||||
$document = new \DomDocument('1.0', 'UTF-8');
|
||||
$document->formatOutput = true;
|
||||
|
||||
$feed = $document->createElement('rss');
|
||||
|
@ -198,9 +198,6 @@ class MrssFormat extends FormatAbstract
|
|||
}
|
||||
|
||||
$xml = $document->saveXML();
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$xml = mb_convert_encoding($xml, $this->getCharset(), 'UTF-8');
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,13 @@ class PlaintextFormat extends FormatAbstract
|
|||
{
|
||||
const MIME_TYPE = 'text/plain';
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
$feed = $this->getFeed();
|
||||
foreach ($this->getItems() as $item) {
|
||||
$feed['items'][] = $item->toArray();
|
||||
}
|
||||
$text = print_r($feed, true);
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$text = mb_convert_encoding($text, $this->getCharset(), 'UTF-8');
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ class SfeedFormat extends FormatAbstract
|
|||
{
|
||||
const MIME_TYPE = 'text/plain';
|
||||
|
||||
public function stringify()
|
||||
public function render(): string
|
||||
{
|
||||
$text = '';
|
||||
foreach ($this->getItems() as $item) {
|
||||
|
@ -26,13 +26,6 @@ class SfeedFormat extends FormatAbstract
|
|||
);
|
||||
}
|
||||
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$text = mb_convert_encoding(
|
||||
$text,
|
||||
$this->getCharset(),
|
||||
'UTF-8'
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue