From e1528845d8827716c11322f15a5f9ce1523fd2d7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 25 Sep 2016 15:45:06 +0200 Subject: API subscription/quickadd https://github.com/FreshRSS/FreshRSS/issues/1254 --- CHANGELOG.md | 2 +- p/api/greader.php | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c8dbec9b..a1fe033bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2016-XX-XX FreshRSS 1.6.0-dev * API - * Support for editing feeds and categories from client applications [#1261](https://github.com/FreshRSS/FreshRSS/pull/1261) + * Support for editing feeds and categories from client applications [#1254](https://github.com/FreshRSS/FreshRSS/issues/1254) * Features * Better control of number of entries per page or RSS feed [#1249](https://github.com/FreshRSS/FreshRSS/issues/1249) * Since X hours: `https://freshrss.example/i/?a=rss&hours=3` diff --git a/p/api/greader.php b/p/api/greader.php index e77ef3726..e2d7dc039 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -361,6 +361,23 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' exit('OK'); } +function quickadd($url) { + //logMe("quickadd($url)"); + try { + $feed = FreshRSS_feed_Controller::addFeed($url); + exit(json_encode(array( + 'numResults' => 1, + 'streamId' => $feed->id(), + ))); + } catch (Exception $e) { + logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + die(json_encode(array( + 'numResults' => 0, + 'error' => $e->getMessage(), + ))); + } +} + function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); @@ -531,7 +548,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude $id = basename($streamId); } elseif (strpos($streamId, 'user/-/label/') === 0) { $type = 'c'; - $c_name = basename($streamId); + $c_name = substr($streamId, 13); $categoryDAO = new FreshRSS_CategoryDAO(); $cat = $categoryDAO->searchByName($c_name); $id = $cat == null ? -1 : $cat->id(); @@ -638,7 +655,7 @@ function markAllAsRead($streamId, $olderThanId) { $f_id = basename($streamId); $entryDAO->markReadFeed($f_id, $olderThanId); } elseif (strpos($streamId, 'user/-/label/') === 0) { - $c_name = basename($streamId); + $c_name = substr($streamId, 13); $categoryDAO = new FreshRSS_CategoryDAO(); $cat = $categoryDAO->searchByName($c_name); $entryDAO->markReadCat($cat === null ? -1 : $cat->id(), $olderThanId); @@ -749,6 +766,11 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo subscriptionEdit($streamNames, $titles, $action, $add, $remove); } break; + case 'quickadd': //https://github.com/theoldreader/api + if (isset($_GET['quickadd'])) { + quickadd($_GET['quickadd']); + } + break; } } break; -- cgit v1.2.3