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
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
use JsonRPC\Exception\AuthenticationFailureException;
|
|
|
|
use JsonRPC\MiddlewareInterface;
|
2013-07-28 21:44:51 +02:00
|
|
|
use JsonRPC\Server;
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Handler;
|
2016-08-25 03:17:58 +02:00
|
|
|
use Miniflux\Model;
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Session\SessionStorage;
|
|
|
|
|
|
|
|
class AuthMiddleware implements MiddlewareInterface
|
|
|
|
{
|
|
|
|
public function execute($username, $password, $procedureName)
|
|
|
|
{
|
|
|
|
$user = Model\User\get_user_by_token('api_token', $password);
|
|
|
|
if (empty($user)) {
|
|
|
|
throw new AuthenticationFailureException('Wrong credentials!');
|
|
|
|
}
|
2013-07-28 21:44:51 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
SessionStorage::getInstance()->setUser($user);
|
|
|
|
}
|
|
|
|
}
|
2013-07-28 21:44:51 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
$server = new Server();
|
|
|
|
$server->getMiddlewareHandler()->withMiddleware(new AuthMiddleware());
|
2016-08-06 02:27:09 +02:00
|
|
|
$procedureHandler = $server->getProcedureHandler();
|
|
|
|
|
2015-04-18 17:42:10 +02:00
|
|
|
// Get version
|
2016-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('getVersion', 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-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('getFeeds', function () {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
$feeds = Model\Feed\get_feeds($user_id);
|
2016-05-08 21:53:45 +02:00
|
|
|
|
2015-12-24 15:34:55 +01:00
|
|
|
foreach ($feeds as &$feed) {
|
2016-12-26 15:44:53 +01:00
|
|
|
$feed['groups'] = Model\Group\get_feed_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-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('getFeed', function ($feed_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Feed\get_feed($user_id, $feed_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add a new feed
|
2016-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('createFeed', function ($url) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
list($feed_id,) = Handler\Feed\create_feed($user_id, $url);
|
2015-04-10 23:34:07 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
if ($feed_id > 0) {
|
|
|
|
return $feed_id;
|
|
|
|
}
|
2013-07-28 21:44:51 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
return false;
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Delete a feed
|
2016-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('deleteFeed', function ($feed_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Feed\remove_feed($user_id, $feed_id);
|
2016-07-25 21:46:01 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Refresh a feed
|
|
|
|
$procedureHandler->withCallback('refreshFeed', function ($feed_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Handler\Feed\update_feed($user_id, $feed_id);
|
2016-07-25 21:46:01 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Get all items
|
|
|
|
$procedureHandler->withCallback('getItems', function ($since_id = null, array $item_ids = array(), $offset = 50) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Item\get_items($user_id, $since_id, $item_ids, $offset);
|
2016-07-25 21:46:01 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Get one item
|
|
|
|
$procedureHandler->withCallback('getItem', function ($item_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Item\get_item($user_id, $item_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Change items status
|
|
|
|
$procedureHandler->withCallback('changeItemsStatus', function (array $item_ids, $status) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Item\change_item_ids_status($user_id, $item_ids, $status);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add a bookmark
|
2016-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('addBookmark', function ($item_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Bookmark\set_flag($user_id, $item_id, 1);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Remove a bookmark
|
2016-12-26 15:44:53 +01:00
|
|
|
$procedureHandler->withCallback('removeBookmark', function ($item_id) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Bookmark\set_flag($user_id, $item_id, 0);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Get all groups
|
|
|
|
$procedureHandler->withCallback('getGroups', function () {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Group\get_all($user_id);
|
2013-07-28 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Add a new group
|
|
|
|
$procedureHandler->withCallback('createGroup', function ($title) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Group\create_group($user_id, $title);
|
2014-02-15 20:09:50 +01:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Add/Update groups for a feed
|
|
|
|
$procedureHandler->withCallback('setFeedGroups', function ($feed_id, $group_ids) {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Group\update_feed_groups($user_id, $feed_id, $group_ids);
|
2014-02-15 20:09:50 +01:00
|
|
|
});
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
// Get favicons
|
|
|
|
$procedureHandler->withCallback('getFavicons', function () {
|
|
|
|
$user_id = SessionStorage::getInstance()->getUserId();
|
|
|
|
return Model\Favicon\get_favicons_with_data_url($user_id);
|
2014-02-15 20:09:50 +01:00
|
|
|
});
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
echo $server->execute();
|