Ver código fonte

Merge pull request #1263 from Alkarex/more-api-edit

API subscription/quickadd
Alexandre Alapetite 9 anos atrás
pai
commit
74f9aa310d
2 arquivos alterados com 25 adições e 3 exclusões
  1. 1 1
      CHANGELOG.md
  2. 24 2
      p/api/greader.php

+ 1 - 1
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`

+ 24 - 2
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;