miniflux-legacy/jsonrpc.php

231 lines
6.4 KiB
PHP
Raw Normal View History

2013-07-28 21:44:51 +02:00
<?php
2016-08-19 03:02:49 +02:00
require __DIR__.'/app/common.php';
2013-07-28 21:44:51 +02:00
use JsonRPC\Server;
2016-08-25 03:17:58 +02:00
use Miniflux\Model;
2013-07-28 21:44:51 +02:00
2016-05-08 21:53:45 +02:00
$server = new Server();
2013-07-28 21:44:51 +02:00
$server->authentication(array(
2016-08-25 03:17:58 +02:00
Model\Config\get('username') => Model\Config\get('api_token')
2013-07-28 21:44:51 +02:00
));
2016-08-06 02:27:09 +02:00
$procedureHandler = $server->getProcedureHandler();
2015-04-18 17:42:10 +02:00
// Get version
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('app.version', function () {
2015-04-18 17:42:10 +02:00
return array('version' => APP_VERSION);
});
2013-07-28 21:44:51 +02:00
// Get all feeds
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.list', function () {
2015-12-24 15:34:55 +01:00
$feeds = Model\Feed\get_all();
2016-05-08 21:53:45 +02:00
if (empty($feeds)) {
return array();
2015-12-24 15:34:55 +01:00
}
2016-05-08 21:53:45 +02:00
2015-12-24 15:34:55 +01:00
$groups = Model\Group\get_feeds_map();
foreach ($feeds as &$feed) {
2015-12-25 08:17:49 +01:00
$feed_id = $feed['id'];
$feed['feed_group_ids'] = array();
if (isset($groups[$feed_id])) {
$feed['feed_group_ids'] = $groups[$feed_id];
}
2015-12-24 15:34:55 +01:00
}
return $feeds;
2013-07-28 21:44:51 +02:00
});
// Get one feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.info', function ($feed_id) {
2015-12-24 15:34:55 +01:00
$result = Model\Feed\get($feed_id);
$result['feed_group_ids'] = Model\Group\get_feed_group_ids($feed_id);
return $result;
2013-07-28 21:44:51 +02:00
});
// Add a new feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.create', function($url) {
try {
$result = Model\Feed\create($url);
2016-05-08 21:53:45 +02:00
} catch (Exception $e) {
$result = false;
}
Model\Config\write_debug();
2013-07-28 21:44:51 +02:00
return $result;
});
// Delete a feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.delete', function($feed_id) {
return Model\Feed\remove($feed_id);
2013-07-28 21:44:51 +02:00
});
2013-08-29 00:17:16 +02:00
// Delete all feeds
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.delete_all', function() {
return Model\Feed\remove_all();
2013-08-29 00:17:16 +02:00
});
// Enable a feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.enable', function($feed_id) {
return Model\Feed\enable($feed_id);
});
// Disable a feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.disable', function($feed_id) {
return Model\Feed\disable($feed_id);
});
2013-07-28 21:44:51 +02:00
// Update a feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('feed.update', function($feed_id) {
return Model\Feed\refresh($feed_id);
2013-07-28 21:44:51 +02:00
});
2015-12-24 15:34:55 +01:00
// Get all groups
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.list', function () {
2015-12-24 15:34:55 +01:00
return Model\Group\get_all();
});
// Add a new group
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.create', function($title) {
2016-07-29 03:11:58 +02:00
return Model\Group\create($title);
});
// Get assoc array of group ids with assigned feeds ids
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.map', function() {
2016-07-29 03:11:58 +02:00
return Model\Group\get_map();
});
// Get the id of a group
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.id', function($title) {
2016-07-29 03:11:58 +02:00
return Model\Group\get_group_id($title);
});
// Get all feed ids assigned to a group
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.feeds', function($group_id) {
2016-07-29 03:11:58 +02:00
return Model\Group\get_feeds_by_group($group_id);
});
2016-07-29 03:11:58 +02:00
// Add groups to feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.add', function($feed_id, $group_ids) {
2016-07-29 03:11:58 +02:00
return Model\Group\add($feed_id, $group_ids);
});
2016-07-29 03:11:58 +02:00
// Remove groups from feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.remove', function($feed_id, $group_ids) {
2016-07-29 03:11:58 +02:00
return Model\Group\remove($feed_id, $group_ids);
});
2016-07-29 03:11:58 +02:00
// Remove all groups from feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.remove_all', function($feed_id) {
2016-07-29 03:11:58 +02:00
return Model\Group\remove_all($feed_id);
});
2016-07-29 03:11:58 +02:00
// Update feed group associations
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('group.update_feed_groups', function($feed_id, $group_ids, $create_group = '') {
2016-07-29 03:11:58 +02:00
return Model\Group\update_feed_groups($feed_id, $group_ids, $create_group);
});
2013-07-28 21:44:51 +02:00
// Get all items for a specific feed
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.feed.list', function ($feed_id, $offset = null, $limit = null) {
2016-08-19 03:53:59 +02:00
return Model\ItemFeed\get_all_items($feed_id, $offset, $limit);
2013-07-28 21:44:51 +02:00
});
// Count all feed items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.feed.count', function ($feed_id) {
2016-08-19 03:53:59 +02:00
return Model\ItemFeed\count_items($feed_id);
2013-07-28 21:44:51 +02:00
});
// Get all bookmark items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.bookmark.list', function ($offset = null, $limit = null) {
2016-08-19 03:44:36 +02:00
return Model\Bookmark\get_all_items($offset, $limit);
2013-07-28 21:44:51 +02:00
});
// Count bookmarks
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.bookmark.count', function () {
2016-08-19 03:44:36 +02:00
return Model\Bookmark\count_items();
2013-07-28 21:44:51 +02:00
});
// Add a bookmark
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.bookmark.create', function ($item_id) {
2016-08-19 03:44:36 +02:00
return Model\Bookmark\set_flag($item_id, 1);
2013-07-28 21:44:51 +02:00
});
// Remove a bookmark
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.bookmark.delete', function ($item_id) {
2016-08-19 03:44:36 +02:00
return Model\Bookmark\set_flag($item_id, 0);
2013-07-28 21:44:51 +02:00
});
// Get all unread items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.list_unread', function ($offset = null, $limit = null) {
2015-08-15 03:33:39 +02:00
return Model\Item\get_all_by_status('unread', array(), $offset, $limit);
2013-07-28 21:44:51 +02:00
});
// Count all unread items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.count_unread', function () {
return Model\Item\count_by_status('unread');
2013-07-28 21:44:51 +02:00
});
// Get all read items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.list_read', function ($offset = null, $limit = null) {
2015-08-15 03:33:39 +02:00
return Model\Item\get_all_by_status('read', array(), $offset, $limit);
2013-07-28 21:44:51 +02:00
});
// Count all read items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.count_read', function () {
return Model\Item\count_by_status('read');
2013-07-28 21:44:51 +02:00
});
// Get one item
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.info', function ($item_id) {
return Model\Item\get($item_id);
2013-07-28 21:44:51 +02:00
});
// Delete an item
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.delete', function($item_id) {
return Model\Item\set_removed($item_id);
2013-07-28 21:44:51 +02:00
});
// Mark item as read
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.mark_as_read', function($item_id) {
return Model\Item\set_read($item_id);
2013-07-28 21:44:51 +02:00
});
// Mark item as unread
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.mark_as_unread', function($item_id) {
return Model\Item\set_unread($item_id);
2013-07-28 21:44:51 +02:00
});
// Change the status of list of items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.set_list_status', function($status, array $items) {
return Model\Item\set_status($status, $items);
});
2013-07-28 21:44:51 +02:00
// Flush all read items
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.flush', function() {
return Model\Item\mark_all_as_removed();
2013-07-28 21:44:51 +02:00
});
// Mark all unread items as read
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.mark_all_as_read', function() {
return Model\Item\mark_all_as_read();
2013-07-28 21:44:51 +02:00
});
// Get all items with the content
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.get_all', function() {
return Model\Item\get_all();
});
// Get all items since a date
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.get_all_since', function($timestamp) {
return Model\Item\get_all_since($timestamp);
});
// Get all items id and status
2016-08-06 02:27:09 +02:00
$procedureHandler->withCallback('item.get_all_status', function() {
return Model\Item\get_all_status();
});
echo $server->execute();