From 7ff97c0c7b60d8273f241c851decd2dd1e8e860b Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Wed, 19 Jun 2019 23:09:08 +0200 Subject: [PATCH] [HtmlFormat] Dynamically build buttons for other feed formats Adding or removing feed formats from the "formats/" directory currently has no effect on the buttons shown in the HTML format. This can cause errors if users press one of the buttons for a format that is no longer available on the server. This commit changes the behavior to dynamically add buttons based on the available formats. Syndication feeds, however, are no longer supported as they require knowledge about the content type, which is not known without further changes to the formats API (may be added later if there is a demand). Closes #942 --- formats/HtmlFormat.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 052bedc5..fefabf03 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -4,8 +4,21 @@ class HtmlFormat extends FormatAbstract { $extraInfos = $this->getExtraInfos(); $title = htmlspecialchars($extraInfos['name']); $uri = htmlspecialchars($extraInfos['uri']); - $atomquery = str_replace('format=Html', 'format=Atom', htmlentities($_SERVER['QUERY_STRING'])); - $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING'])); + + // 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; + } $entries = ''; foreach($this->getItems() as $item) { @@ -84,16 +97,13 @@ EOD; {$title} - -

{$title}

- - + {$buttons}
{$entries} @@ -113,4 +123,10 @@ EOD; return parent::display(); } + + private function buildButton($format, $query) { + return << +EOD; + } }