Add RSS feed for bookmarks

This commit is contained in:
Frédéric Guillot 2013-08-09 22:23:57 -04:00
parent f1dafc5f57
commit a79228195f
7 changed files with 75 additions and 6 deletions

46
feed.php Normal file
View File

@ -0,0 +1,46 @@
<?php
require 'common.php';
require 'vendor/PicoTools/Helper.php';
require 'vendor/PicoFarad/Response.php';
require 'vendor/PicoFarad/Request.php';
require 'vendor/PicoFeed/Writers/Atom.php';
use PicoFarad\Response;
use PicoFarad\Request;
use PicoFeed\Writers\Atom;
// Check token
$feed_token = Model\get_config_value('feed_token');
$request_token = Request\param('token');
if ($feed_token !== $request_token) {
Response\text('Access Forbidden', 403);
}
// Load translations
$language = Model\get_config_value('language') ?: 'en_US';
if ($language !== 'en_US') PicoTools\Translator\load($language);
// Build Feed
$writer = new Atom;
$writer->title = t('Bookmarks').' - Miniflux';
$writer->site_url = Helper\get_current_base_url();
$writer->feed_url = $writer->site_url.'feed.php?token='.urlencode($feed_token);
$bookmarks = Model\get_bookmarks();
foreach ($bookmarks as $bookmark) {
$article = Model\get_item($bookmark['id']);
$writer->items[] = array(
'id' => $article['id'],
'title' => $article['title'],
'updated' => $article['updated'],
'url' => $article['url'],
'content' => $article['content'],
);
}
Response\xml($writer->execute());

View File

@ -1,6 +1,7 @@
<?php <?php
return array( return array(
'Bookmarks RSS Feed:' => 'Flux RSS des favoris :',
'updated just now' => 'mis à jour à l\'instant', 'updated just now' => 'mis à jour à l\'instant',
'checked at' => 'vérifié le', 'checked at' => 'vérifié le',
'never updated after creation' => 'jamais mis à jour après la création', 'never updated after creation' => 'jamais mis à jour après la création',

View File

@ -25,7 +25,7 @@ use PicoFeed\Reader;
use PicoFeed\Export; use PicoFeed\Export;
const DB_VERSION = 13; const DB_VERSION = 14;
const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net';
const LIMIT_ALL = -1; const LIMIT_ALL = -1;
@ -752,7 +752,7 @@ function get_config()
{ {
return \PicoTools\singleton('db') return \PicoTools\singleton('db')
->table('config') ->table('config')
->columns('username', 'language', 'autoflush', 'nocontent', 'items_per_page', 'theme', 'api_token') ->columns('username', 'language', 'autoflush', 'nocontent', 'items_per_page', 'theme', 'api_token', 'feed_token')
->findOne(); ->findOne();
} }

View File

@ -3,6 +3,12 @@
namespace Schema; namespace Schema;
function version_14($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN feed_token TEXT DEFAULT "'.\Model\generate_api_token().'"');
}
function version_13($pdo) function version_13($pdo)
{ {
$pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1'); $pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1');

View File

@ -40,6 +40,9 @@
<div class="alert alert-normal"> <div class="alert alert-normal">
<h3><?= t('API') ?></h3> <h3><?= t('API') ?></h3>
<ul> <ul>
<li><?= t('Bookmarks RSS Feed:') ?>
<a href="<?= Helper\get_current_base_url().'feed.php?token='.urlencode($values['feed_token']) ?>" target="_blank"><?= Helper\get_current_base_url().'feed.php?token='.urlencode($values['feed_token']) ?></a>
</li>
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url().'jsonrpc.php' ?></strong></li> <li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url().'jsonrpc.php' ?></strong></li>
<li><?= t('API username:') ?> <strong><?= Helper\escape($values['username']) ?></strong></li> <li><?= t('API username:') ?> <strong><?= Helper\escape($values['username']) ?></strong></li>
<li><?= t('API token:') ?> <strong><?= Helper\escape($values['api_token']) ?></strong></li> <li><?= t('API token:') ?> <strong><?= Helper\escape($values['api_token']) ?></strong></li>

View File

@ -63,7 +63,13 @@ class Atom extends \PicoFeed\Writer
$entry->appendChild($this->dom->createElement('title', $item['title'])); $entry->appendChild($this->dom->createElement('title', $item['title']));
// <id/> // <id/>
if (isset($item['id'])) {
$entry->appendChild($this->dom->createElement('id', $item['id']));
}
else {
$entry->appendChild($this->dom->createElement('id', $item['url'])); $entry->appendChild($this->dom->createElement('id', $item['url']));
}
// <updated/> // <updated/>
$this->addUpdated($entry, isset($item['updated']) ? $item['updated'] : ''); $this->addUpdated($entry, isset($item['updated']) ? $item['updated'] : '');

View File

@ -73,9 +73,16 @@ class Rss20 extends \PicoFeed\Writer
$entry->appendChild($this->dom->createElement('link', $item['url'])); $entry->appendChild($this->dom->createElement('link', $item['url']));
// <guid/> // <guid/>
if (isset($item['id'])) {
$guid = $this->dom->createElement('guid', $item['id']);
$guid->setAttribute('isPermaLink', 'false');
$entry->appendChild($guid);
}
else {
$guid = $this->dom->createElement('guid', $item['url']); $guid = $this->dom->createElement('guid', $item['url']);
$guid->setAttribute('isPermaLink', 'true'); $guid->setAttribute('isPermaLink', 'true');
$entry->appendChild($guid); $entry->appendChild($guid);
}
// <pubDate/> // <pubDate/>
$this->addPubDate($entry, isset($item['updated']) ? $item['updated'] : ''); $this->addPubDate($entry, isset($item['updated']) ? $item['updated'] : '');