2013-07-28 21:44:51 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-08 20:13:14 +01:00
|
|
|
require __DIR__.'/common.php';
|
2013-07-28 21:44:51 +02:00
|
|
|
|
|
|
|
use JsonRPC\Server;
|
2015-08-15 03:33:39 +02:00
|
|
|
use Model\Config;
|
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(
|
2015-08-15 03:33:39 +02:00
|
|
|
Config\get('username') => Config\get('api_token')
|
2013-07-28 21:44:51 +02:00
|
|
|
));
|
|
|
|
|
2015-04-18 17:42:10 +02:00
|
|
|
// Get version
|
|
|
|
$server->register('app.version', function () {
|
|
|
|
return array('version' => APP_VERSION);
|
|
|
|
});
|
|
|
|
|
2013-07-28 21:44:51 +02:00
|
|
|
// Get all feeds
|
|
|
|
$server->register('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
|
|
|
|
$server->register('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
|
|
|
|
$server->register('feed.create', function($url) {
|
2015-04-10 23:34:07 +02:00
|
|
|
try {
|
|
|
|
$result = Model\Feed\create($url);
|
2016-05-08 21:53:45 +02:00
|
|
|
} catch (Exception $e) {
|
2015-04-10 23:34:07 +02:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
Model\Config\write_debug();
|
2013-07-28 21:44:51 +02:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete a feed
|
|
|
|
$server->register('feed.delete', function($feed_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
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
|
|
|
|
$server->register('feed.delete_all', function() {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Feed\remove_all();
|
2013-08-29 00:17:16 +02:00
|
|
|
});
|
|
|
|
|
2013-08-04 21:15:12 +02:00
|
|
|
// Enable a feed
|
|
|
|
$server->register('feed.enable', function($feed_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Feed\enable($feed_id);
|
2013-08-04 21:15:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Disable a feed
|
|
|
|
$server->register('feed.disable', function($feed_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Feed\disable($feed_id);
|
2013-08-04 21:15:12 +02:00
|
|
|
});
|
|
|
|
|
2013-07-28 21:44:51 +02:00
|
|
|
// Update a feed
|
|
|
|
$server->register('feed.update', function($feed_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
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
|
|
|
|
$server->register('group.list', function () {
|
|
|
|
return Model\Group\get_all();
|
|
|
|
});
|
|
|
|
|
2013-07-28 21:44:51 +02:00
|
|
|
// Get all items for a specific feed
|
|
|
|
$server->register('item.feed.list', function ($feed_id, $offset = null, $limit = null) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\get_all_by_feed($feed_id, $offset, $limit);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Count all feed items
|
|
|
|
$server->register('item.feed.count', function ($feed_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\count_by_feed($feed_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all bookmark items
|
|
|
|
$server->register('item.bookmark.list', function ($offset = null, $limit = null) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\get_bookmarks($offset, $limit);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Count bookmarks
|
|
|
|
$server->register('item.bookmark.count', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\count_bookmarks();
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add a bookmark
|
|
|
|
$server->register('item.bookmark.create', function ($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_bookmark_value($item_id, 1);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Remove a bookmark
|
2013-07-30 04:33:01 +02:00
|
|
|
$server->register('item.bookmark.delete', function ($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_bookmark_value($item_id, 0);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all unread items
|
|
|
|
$server->register('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
|
|
|
|
$server->register('item.count_unread', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\count_by_status('unread');
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all read items
|
|
|
|
$server->register('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
|
|
|
|
$server->register('item.count_read', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\count_by_status('read');
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get one item
|
|
|
|
$server->register('item.info', function ($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\get($item_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Delete an item
|
|
|
|
$server->register('item.delete', function($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_removed($item_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark item as read
|
|
|
|
$server->register('item.mark_as_read', function($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_read($item_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark item as unread
|
2013-07-30 04:33:01 +02:00
|
|
|
$server->register('item.mark_as_unread', function($item_id) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_unread($item_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2013-08-23 03:58:04 +02:00
|
|
|
// Change the status of list of items
|
|
|
|
$server->register('item.set_list_status', function($status, array $items) {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\set_status($status, $items);
|
2013-08-23 03:58:04 +02:00
|
|
|
});
|
|
|
|
|
2013-07-28 21:44:51 +02:00
|
|
|
// Flush all read items
|
|
|
|
$server->register('item.flush', function() {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\mark_all_as_removed();
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark all unread items as read
|
|
|
|
$server->register('item.mark_all_as_read', function() {
|
2013-12-23 02:55:53 +01:00
|
|
|
return Model\Item\mark_all_as_read();
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2014-02-15 20:09:50 +01:00
|
|
|
// Get all items with the content
|
|
|
|
$server->register('item.get_all', function() {
|
2015-04-19 08:08:31 +02:00
|
|
|
return Model\Item\get_all();
|
2014-02-15 20:09:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all items since a date
|
|
|
|
$server->register('item.get_all_since', function($timestamp) {
|
2015-04-19 08:08:31 +02:00
|
|
|
return Model\Item\get_all_since($timestamp);
|
2014-02-15 20:09:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all items id and status
|
|
|
|
$server->register('item.get_all_status', function() {
|
|
|
|
return Model\Item\get_all_status();
|
|
|
|
});
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
echo $server->execute();
|