Add RSS feed for bookmarks
This commit is contained in:
parent
f1dafc5f57
commit
a79228195f
46
feed.php
Normal file
46
feed.php
Normal 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());
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'Bookmarks RSS Feed:' => 'Flux RSS des favoris :',
|
||||
'updated just now' => 'mis à jour à l\'instant',
|
||||
'checked at' => 'vérifié le',
|
||||
'never updated after creation' => 'jamais mis à jour après la création',
|
||||
|
@ -25,7 +25,7 @@ use PicoFeed\Reader;
|
||||
use PicoFeed\Export;
|
||||
|
||||
|
||||
const DB_VERSION = 13;
|
||||
const DB_VERSION = 14;
|
||||
const HTTP_USERAGENT = 'Miniflux - http://miniflux.net';
|
||||
const LIMIT_ALL = -1;
|
||||
|
||||
@ -752,7 +752,7 @@ function get_config()
|
||||
{
|
||||
return \PicoTools\singleton('db')
|
||||
->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();
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,12 @@
|
||||
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)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1');
|
||||
|
@ -40,6 +40,9 @@
|
||||
<div class="alert alert-normal">
|
||||
<h3><?= t('API') ?></h3>
|
||||
<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 username:') ?> <strong><?= Helper\escape($values['username']) ?></strong></li>
|
||||
<li><?= t('API token:') ?> <strong><?= Helper\escape($values['api_token']) ?></strong></li>
|
||||
|
6
vendor/PicoFeed/Writers/Atom.php
vendored
6
vendor/PicoFeed/Writers/Atom.php
vendored
@ -63,7 +63,13 @@ class Atom extends \PicoFeed\Writer
|
||||
$entry->appendChild($this->dom->createElement('title', $item['title']));
|
||||
|
||||
// <id/>
|
||||
if (isset($item['id'])) {
|
||||
$entry->appendChild($this->dom->createElement('id', $item['id']));
|
||||
}
|
||||
else {
|
||||
$entry->appendChild($this->dom->createElement('id', $item['url']));
|
||||
}
|
||||
|
||||
|
||||
// <updated/>
|
||||
$this->addUpdated($entry, isset($item['updated']) ? $item['updated'] : '');
|
||||
|
7
vendor/PicoFeed/Writers/Rss20.php
vendored
7
vendor/PicoFeed/Writers/Rss20.php
vendored
@ -73,9 +73,16 @@ class Rss20 extends \PicoFeed\Writer
|
||||
$entry->appendChild($this->dom->createElement('link', $item['url']));
|
||||
|
||||
// <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->setAttribute('isPermaLink', 'true');
|
||||
$entry->appendChild($guid);
|
||||
}
|
||||
|
||||
// <pubDate/>
|
||||
$this->addPubDate($entry, isset($item['updated']) ? $item['updated'] : '');
|
||||
|
Loading…
Reference in New Issue
Block a user