aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/DisplayAction.php8
-rw-r--r--bridges/NintendoBridge.php1
-rw-r--r--formats/HtmlFormat.php51
-rw-r--r--lib/BridgeCard.php2
-rw-r--r--templates/html-format.html.php25
5 files changed, 47 insertions, 40 deletions
diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php
index ed063825..24bdefe1 100644
--- a/actions/DisplayAction.php
+++ b/actions/DisplayAction.php
@@ -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();
diff --git a/bridges/NintendoBridge.php b/bridges/NintendoBridge.php
index 1c2ef71a..1c4ecf2b 100644
--- a/bridges/NintendoBridge.php
+++ b/bridges/NintendoBridge.php
@@ -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 = [
diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php
index 93c824b3..1e2f60e6 100644
--- a/formats/HtmlFormat.php
+++ b/formats/HtmlFormat.php
@@ -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');
diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php
index c4677b9d..d15ac865 100644
--- a/lib/BridgeCard.php
+++ b/lib/BridgeCard.php
@@ -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(),
diff --git a/templates/html-format.html.php b/templates/html-format.html.php
index 3b0fe6fe..bc95c5d0 100644
--- a/templates/html-format.html.php
+++ b/templates/html-format.html.php
@@ -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): ?>