mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-16 21:58:21 +01:00
refactor (#4037)
This commit is contained in:
parent
24e429969f
commit
545dc969d3
@ -51,7 +51,6 @@ class DisplayAction implements ActionInterface
|
||||
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400);
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
Configuration::getConfig('proxy', 'url')
|
||||
&& Configuration::getConfig('proxy', 'by_bridge')
|
||||
@ -62,8 +61,6 @@ class DisplayAction implements ActionInterface
|
||||
}
|
||||
|
||||
$bridge = $bridgeFactory->create($bridgeClassName);
|
||||
$formatFactory = new FormatFactory();
|
||||
$format = $formatFactory->create($format);
|
||||
|
||||
$response = $this->createResponse($request, $bridge, $format);
|
||||
|
||||
@ -93,7 +90,7 @@ class DisplayAction implements ActionInterface
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function createResponse(Request $request, BridgeAbstract $bridge, FormatAbstract $format)
|
||||
private function createResponse(Request $request, BridgeAbstract $bridge, string $format)
|
||||
{
|
||||
$items = [];
|
||||
$feed = [];
|
||||
@ -157,6 +154,9 @@ class DisplayAction implements ActionInterface
|
||||
}
|
||||
}
|
||||
|
||||
$formatFactory = new FormatFactory();
|
||||
$format = $formatFactory->create($format);
|
||||
|
||||
$format->setItems($items);
|
||||
$format->setFeed($feed);
|
||||
$now = time();
|
||||
|
@ -4,7 +4,6 @@ class NintendoBridge extends XPathAbstract
|
||||
{
|
||||
const NAME = 'Nintendo Software Updates';
|
||||
const URI = 'https://www.nintendo.co.uk/Support/Welcome-to-Nintendo-Support-11593.html';
|
||||
const DONATION_URI = '';
|
||||
const DESCRIPTION = self::NAME;
|
||||
const MAINTAINER = 'Niehztog';
|
||||
const PARAMETERS = [
|
||||
|
@ -6,34 +6,26 @@ class HtmlFormat extends FormatAbstract
|
||||
|
||||
public function stringify()
|
||||
{
|
||||
// This query string comes in already url decoded
|
||||
$queryString = $_SERVER['QUERY_STRING'];
|
||||
|
||||
$feedArray = $this->getFeed();
|
||||
$formatFactory = new FormatFactory();
|
||||
$buttons = [];
|
||||
$linkTags = [];
|
||||
foreach ($formatFactory->getFormatNames() as $formatName) {
|
||||
// Dynamically build buttons for all formats (except HTML)
|
||||
$formats = [];
|
||||
|
||||
// Create all formats (except HTML)
|
||||
$formatNames = $formatFactory->getFormatNames();
|
||||
foreach ($formatNames as $formatName) {
|
||||
if ($formatName === 'Html') {
|
||||
continue;
|
||||
}
|
||||
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $formatName, htmlentities($queryString));
|
||||
$buttons[] = [
|
||||
'href' => $formatUrl,
|
||||
'value' => $formatName,
|
||||
];
|
||||
$format = $formatFactory->create($formatName);
|
||||
$linkTags[] = [
|
||||
'href' => $formatUrl,
|
||||
'title' => $formatName,
|
||||
'type' => $format->getMimeType(),
|
||||
];
|
||||
}
|
||||
|
||||
if (Configuration::getConfig('admin', 'donations') && $feedArray['donationUri']) {
|
||||
$buttons[] = [
|
||||
'href' => e($feedArray['donationUri']),
|
||||
'value' => 'Donate to maintainer',
|
||||
// The format url is relative, but should be absolute in order to help feed readers.
|
||||
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $formatName, $queryString);
|
||||
$formatObject = $formatFactory->create($formatName);
|
||||
$formats[] = [
|
||||
'url' => $formatUrl,
|
||||
'name' => $formatName,
|
||||
'type' => $formatObject->getMimeType(),
|
||||
];
|
||||
}
|
||||
|
||||
@ -50,13 +42,18 @@ class HtmlFormat extends FormatAbstract
|
||||
];
|
||||
}
|
||||
|
||||
$donationUri = null;
|
||||
if (Configuration::getConfig('admin', 'donations') && $feedArray['donationUri']) {
|
||||
$donationUri = $feedArray['donationUri'];
|
||||
}
|
||||
|
||||
$html = render_template(__DIR__ . '/../templates/html-format.html.php', [
|
||||
'charset' => $this->getCharset(),
|
||||
'title' => $feedArray['name'],
|
||||
'linkTags' => $linkTags,
|
||||
'uri' => $feedArray['uri'],
|
||||
'buttons' => $buttons,
|
||||
'items' => $items,
|
||||
'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');
|
||||
|
@ -78,7 +78,7 @@ final class BridgeCard
|
||||
|
||||
$card .= sprintf('<label class="showless" for="showmore-%s">Show less</label>', $bridgeClassName);
|
||||
|
||||
if ($bridge->getDonationURI() !== '' && Configuration::getConfig('admin', 'donations')) {
|
||||
if (Configuration::getConfig('admin', 'donations') && $bridge->getDonationURI()) {
|
||||
$card .= sprintf(
|
||||
'<p class="maintainer">%s ~ <a href="%s">Donate</a></p>',
|
||||
$bridge->getMaintainer(),
|
||||
|
@ -8,12 +8,13 @@
|
||||
<link href="static/style.css?2023-03-24" rel="stylesheet">
|
||||
<link rel="icon" type="image/png" href="static/favicon.png">
|
||||
|
||||
<?php foreach ($linkTags as $link): ?>
|
||||
<?php foreach ($formats as $format): ?>
|
||||
|
||||
<link
|
||||
href="<?= $link['href'] ?>"
|
||||
title="<?= $link['title'] ?>"
|
||||
href="<?= e($format['url']) ?>"
|
||||
title="<?= e($format['name']) ?>"
|
||||
rel="alternate"
|
||||
type="<?= $link['type'] ?>"
|
||||
type="<?= e($format['type']) ?>"
|
||||
>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -33,11 +34,21 @@
|
||||
<button class="backbutton">← back to rss-bridge</button>
|
||||
</a>
|
||||
|
||||
<?php foreach ($buttons as $button): ?>
|
||||
<a href="<?= $button['href'] ?>">
|
||||
<button class="rss-feed"><?= $button['value'] ?></button>
|
||||
<?php foreach ($formats as $format): ?>
|
||||
<a href="<?= e($format['url']) ?>">
|
||||
<button class="rss-feed">
|
||||
<?= e($format['name']) ?>
|
||||
</button>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($donation_uri): ?>
|
||||
<a href="<?= e($donation_uri) ?>">
|
||||
<button class="rss-feed">
|
||||
Donate to maintainer
|
||||
</button>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php foreach ($items as $item): ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user