This commit is contained in:
Dag 2024-03-31 03:38:42 +02:00 committed by GitHub
parent 24e429969f
commit 545dc969d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 40 deletions

View file

@ -51,7 +51,6 @@ class DisplayAction implements ActionInterface
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400); return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400);
} }
if ( if (
Configuration::getConfig('proxy', 'url') Configuration::getConfig('proxy', 'url')
&& Configuration::getConfig('proxy', 'by_bridge') && Configuration::getConfig('proxy', 'by_bridge')
@ -62,8 +61,6 @@ class DisplayAction implements ActionInterface
} }
$bridge = $bridgeFactory->create($bridgeClassName); $bridge = $bridgeFactory->create($bridgeClassName);
$formatFactory = new FormatFactory();
$format = $formatFactory->create($format);
$response = $this->createResponse($request, $bridge, $format); $response = $this->createResponse($request, $bridge, $format);
@ -93,7 +90,7 @@ class DisplayAction implements ActionInterface
return $response; return $response;
} }
private function createResponse(Request $request, BridgeAbstract $bridge, FormatAbstract $format) private function createResponse(Request $request, BridgeAbstract $bridge, string $format)
{ {
$items = []; $items = [];
$feed = []; $feed = [];
@ -157,6 +154,9 @@ class DisplayAction implements ActionInterface
} }
} }
$formatFactory = new FormatFactory();
$format = $formatFactory->create($format);
$format->setItems($items); $format->setItems($items);
$format->setFeed($feed); $format->setFeed($feed);
$now = time(); $now = time();

View file

@ -4,7 +4,6 @@ class NintendoBridge extends XPathAbstract
{ {
const NAME = 'Nintendo Software Updates'; const NAME = 'Nintendo Software Updates';
const URI = 'https://www.nintendo.co.uk/Support/Welcome-to-Nintendo-Support-11593.html'; const URI = 'https://www.nintendo.co.uk/Support/Welcome-to-Nintendo-Support-11593.html';
const DONATION_URI = '';
const DESCRIPTION = self::NAME; const DESCRIPTION = self::NAME;
const MAINTAINER = 'Niehztog'; const MAINTAINER = 'Niehztog';
const PARAMETERS = [ const PARAMETERS = [

View file

@ -6,34 +6,26 @@ class HtmlFormat extends FormatAbstract
public function stringify() public function stringify()
{ {
// This query string comes in already url decoded
$queryString = $_SERVER['QUERY_STRING']; $queryString = $_SERVER['QUERY_STRING'];
$feedArray = $this->getFeed(); $feedArray = $this->getFeed();
$formatFactory = new FormatFactory(); $formatFactory = new FormatFactory();
$buttons = []; $formats = [];
$linkTags = [];
foreach ($formatFactory->getFormatNames() as $formatName) { // Create all formats (except HTML)
// Dynamically build buttons for all formats (except HTML) $formatNames = $formatFactory->getFormatNames();
foreach ($formatNames as $formatName) {
if ($formatName === 'Html') { if ($formatName === 'Html') {
continue; continue;
} }
$formatUrl = '?' . str_ireplace('format=Html', 'format=' . $formatName, htmlentities($queryString)); // The format url is relative, but should be absolute in order to help feed readers.
$buttons[] = [ $formatUrl = '?' . str_ireplace('format=Html', 'format=' . $formatName, $queryString);
'href' => $formatUrl, $formatObject = $formatFactory->create($formatName);
'value' => $formatName, $formats[] = [
]; 'url' => $formatUrl,
$format = $formatFactory->create($formatName); 'name' => $formatName,
$linkTags[] = [ 'type' => $formatObject->getMimeType(),
'href' => $formatUrl,
'title' => $formatName,
'type' => $format->getMimeType(),
];
}
if (Configuration::getConfig('admin', 'donations') && $feedArray['donationUri']) {
$buttons[] = [
'href' => e($feedArray['donationUri']),
'value' => 'Donate to maintainer',
]; ];
} }
@ -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', [ $html = render_template(__DIR__ . '/../templates/html-format.html.php', [
'charset' => $this->getCharset(), 'charset' => $this->getCharset(),
'title' => $feedArray['name'], 'title' => $feedArray['name'],
'linkTags' => $linkTags, 'formats' => $formats,
'uri' => $feedArray['uri'], 'uri' => $feedArray['uri'],
'buttons' => $buttons,
'items' => $items, 'items' => $items,
'donation_uri' => $donationUri,
]); ]);
// Remove invalid characters // Remove invalid characters
ini_set('mbstring.substitute_character', 'none'); ini_set('mbstring.substitute_character', 'none');

View file

@ -78,7 +78,7 @@ final class BridgeCard
$card .= sprintf('<label class="showless" for="showmore-%s">Show less</label>', $bridgeClassName); $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( $card .= sprintf(
'<p class="maintainer">%s ~ <a href="%s">Donate</a></p>', '<p class="maintainer">%s ~ <a href="%s">Donate</a></p>',
$bridge->getMaintainer(), $bridge->getMaintainer(),

View file

@ -8,12 +8,13 @@
<link href="static/style.css?2023-03-24" rel="stylesheet"> <link href="static/style.css?2023-03-24" rel="stylesheet">
<link rel="icon" type="image/png" href="static/favicon.png"> <link rel="icon" type="image/png" href="static/favicon.png">
<?php foreach ($linkTags as $link): ?> <?php foreach ($formats as $format): ?>
<link <link
href="<?= $link['href'] ?>" href="<?= e($format['url']) ?>"
title="<?= $link['title'] ?>" title="<?= e($format['name']) ?>"
rel="alternate" rel="alternate"
type="<?= $link['type'] ?>" type="<?= e($format['type']) ?>"
> >
<?php endforeach; ?> <?php endforeach; ?>
@ -33,11 +34,21 @@
<button class="backbutton"> back to rss-bridge</button> <button class="backbutton"> back to rss-bridge</button>
</a> </a>
<?php foreach ($buttons as $button): ?> <?php foreach ($formats as $format): ?>
<a href="<?= $button['href'] ?>"> <a href="<?= e($format['url']) ?>">
<button class="rss-feed"><?= $button['value'] ?></button> <button class="rss-feed">
<?= e($format['name']) ?>
</button>
</a> </a>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($donation_uri): ?>
<a href="<?= e($donation_uri) ?>">
<button class="rss-feed">
Donate to maintainer
</button>
</a>
<?php endif; ?>
</div> </div>
<?php foreach ($items as $item): ?> <?php foreach ($items as $item): ?>