RSS-Bridge / rss-bridge

The RSS feed for websites missing it
https://rss-bridge.org/bridge01/
The Unlicense
7.21k stars 1.03k forks source link

FreshRSS button format #3137

Closed fatuuse closed 1 year ago

fatuuse commented 1 year ago

I made a button of the html-format page to add a atom url to FreshRSS without copy paste.

Feel free to use!

<?php
/**
* Link to pass atom url to FreshRSS
* 
*/

class FreshrssFormat extends FormatAbstract {
    const MIME_TYPE = 'text/html';

    public function stringify(){

        $FRESHRSS_DOMAIN = "https://feeds.example.net";

        $items = $this->getItems();
        $count = count($items);
        #$data = array();
        $extraInfos = $this->getExtraInfos();
        $title = htmlspecialchars($extraInfos['name']);
        $uri = htmlspecialchars($extraInfos['uri']);

        // Dynamically build buttons for all formats (except freshrss)
        $formatFac = new FormatFactory();
        $formatFac->setWorkingDir(PATH_LIB_FORMATS);

        $buttons = '';
        $links = '';

        foreach($formatFac->getFormatNames() as $format) {
            if(strcasecmp($format, 'Freshrss') === 0) {
                continue;
            }

            $query = str_ireplace('format=Freshrss', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING']));

            $buttons .= $this->buildButton($format, $query) . PHP_EOL;

            $mime = $formatFac->create($format)->getMimeType();
            $links .= $this->buildLink($format, $query, $mime) . PHP_EOL;
        }

        $charset = $this->getCharset();

        $query_fresh = (str_ireplace('format=Freshrss', 'format=Atom', ('https://'.$_SERVER['SERVER_NAME'].'/?'.$_SERVER['QUERY_STRING'])));
        $query_freshbutton = rawurlencode($query_fresh);

        $toReturn = <<<EOD
<!DOCTYPE html>
<html>
<head>
    <meta charset="{$charset}">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{$title}</title>
    <link href="static/HtmlFormat.css" rel="stylesheet">
    <link rel="icon" type="image/png" href="static/favicon.png">
    {$links}
    <meta name="robots" content="noindex, follow">
</head>
<body>
    <h1 class="pagetitle"><a href="{$uri}" target="_blank">{$title}</a></h1>
    <div class="buttons">
        <a href="./#bridge-{$_GET['bridge']}"><button class="rss-feed">← back to rss-bridge</button></a>
        {$buttons}
        <br/><br/><br/>
        <a href="{$FRESHRSS_DOMAIN}/i/?c=feed&a=add&url_rss={$query_freshbutton}"><button class="backbutton">Add to FreshRSS</button></a>
    </div>
<br/>
FreshRSS domain: {$FRESHRSS_DOMAIN}<br/>
Feed contains {$count} posts.<br/>
</body>
</html>
EOD;
        return $toReturn;
    }

    private function buildButton($format, $query) {
        return <<<EOD
<a href="./?{$query}"><button class="rss-feed">{$format}</button></a>
EOD;
    }

    private function buildLink($format, $query, $mime) {
        return <<<EOD
<link href="./?{$query}" title="{$format}" rel="alternate" type="{$mime}">

EOD;
    }

}
dvikan commented 1 year ago

This button to an external feed reader is not exactly a format. Maybe something like this instead?

diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php
index 9ee4aeea..5b634820 100644
--- a/formats/HtmlFormat.php
+++ b/formats/HtmlFormat.php
@@ -53,6 +53,20 @@ class HtmlFormat extends FormatAbstract
             'linkTags'  => $linkTags,
             'uri'       => $extraInfos['uri'],
             'buttons'   => $buttons,
+            'readers'   => [
+                [
+                    'name' => 'FreshRSS',
+                    'url' => 'https://feeds.example.net/i/?c=feed&a=add&url_rss=' . $url
+                ],
+                [
+                    'name' => 'Feedly',
+                    'url' => 'https://feedly.com/i/subscription/feed/' . $url,
+                ],
+                [
+                    'name' => 'Inoreader',
+                    'url' => 'https://www.inoreader.com/?add_feed=' . $url,
+                ],
+            ],
             'items'     => $items,
         ]);
         // Remove invalid characters
diff --git a/templates/html-format.html.php b/templates/html-format.html.php
index f8aa4b61..5464f8a2 100644
--- a/templates/html-format.html.php
+++ b/templates/html-format.html.php
@@ -37,6 +37,12 @@
                     <button class="rss-feed"><?= $button['value'] ?></button>
                 </a>
             <?php endforeach; ?>
+
+            <?php foreach ($readers as $reader): ?>
+                <a href="<?= e($reader['url']) ?>">
+                    <button><?= $reader['name'] ?></button>
+                </a>
+            <?php endforeach; ?>
         </div>

kek

Or perhaps a new format FeedReaderFormat which is an html page with links to a bunch of feed readers?

fatuuse commented 1 year ago

The buttons in the top är great! Maybe they could be populated from custom settings in config file?