greader.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /**
  3. == Description ==
  4. Server-side API compatible with Google Reader API layer 2
  5. for the FreshRSS project http://freshrss.org
  6. == Credits ==
  7. * 2014-02: Released by Alexandre Alapetite http://alexandre.alapetite.fr
  8. under GNU AGPL 3 license http://www.gnu.org/licenses/agpl-3.0.html
  9. == Documentation ==
  10. * http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  11. * http://web.archive.org/web/20130718025427/http://undoc.in/
  12. * http://ranchero.com/downloads/GoogleReaderAPI-2009.pdf
  13. * http://code.google.com/p/google-reader-api/w/list
  14. * http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/
  15. * https://github.com/noinnion/newsplus/blob/master/extensions/GoogleReaderCloneExtension/src/com/noinnion/android/newsplus/extension/google_reader/GoogleReaderClient.java
  16. * https://github.com/ericmann/gReader-Library/blob/master/greader.class.php
  17. * https://github.com/devongovett/reader
  18. * https://github.com/theoldreader/api
  19. */
  20. require('../../constants.php');
  21. require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
  22. $ORIGINAL_INPUT = file_get_contents('php://input');
  23. $ALL_HEADERS = getallheaders();
  24. $debugInfo = array('date' => date('c'), 'headers' => $ALL_HEADERS, '_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, 'INPUT' => $ORIGINAL_INPUT);
  25. if (PHP_INT_SIZE < 8) { //32-bit
  26. function dec2hex($dec) {
  27. return str_pad(gmp_strval(gmp_init($dec, 10), 16), 16, '0', STR_PAD_LEFT);
  28. }
  29. function hex2dec($hex) {
  30. return gmp_strval(gmp_init($hex, 16), 10);
  31. }
  32. } else { //64-bit
  33. function dec2hex($dec) { //http://code.google.com/p/google-reader-api/wiki/ItemId
  34. return str_pad(dechex($dec), 16, '0', STR_PAD_LEFT);
  35. }
  36. function hex2dec($hex) {
  37. return hexdec($hex);
  38. }
  39. }
  40. function headerVariable($headerName, $varName) {
  41. global $ALL_HEADERS;
  42. if (empty($ALL_HEADERS[$headerName])) {
  43. return null;
  44. }
  45. parse_str($ALL_HEADERS[$headerName], $pairs);
  46. //logMe('headerVariable(' . $headerName . ') => ' . print_r($pairs, true));
  47. return isset($pairs[$varName]) ? $pairs[$varName] : null;
  48. }
  49. function multiplePosts($name) { //https://bugs.php.net/bug.php?id=51633
  50. global $ORIGINAL_INPUT;
  51. $inputs = explode('&', $ORIGINAL_INPUT);
  52. $result = array();
  53. $prefix = $name . '=';
  54. $prefixLength = strlen($prefix);
  55. foreach ($inputs as $input) {
  56. if (strpos($input, $prefix) === 0) {
  57. $result[] = urldecode(substr($input, $prefixLength));
  58. }
  59. }
  60. return $result;
  61. }
  62. class MyPDO extends Minz_ModelPdo {
  63. function prepare($sql) {
  64. return $this->bd->prepare(str_replace('%_', $this->prefix, $sql));
  65. }
  66. }
  67. function logMe($text) {
  68. file_put_contents(LOG_PATH . '/api.log', $text, FILE_APPEND);
  69. }
  70. function badRequest() {
  71. logMe("badRequest()\n");
  72. header('HTTP/1.1 400 Bad Request');
  73. header('Content-Type: text/plain; charset=UTF-8');
  74. die('Bad Request!');
  75. }
  76. function unauthorized() {
  77. logMe("unauthorized()\n");
  78. header('HTTP/1.1 401 Unauthorized');
  79. header('Content-Type: text/plain; charset=UTF-8');
  80. header('Google-Bad-Token: true');
  81. die('Unauthorized!');
  82. }
  83. function notImplemented() {
  84. logMe("notImplemented()\n");
  85. header('HTTP/1.1 501 Not Implemented');
  86. header('Content-Type: text/plain; charset=UTF-8');
  87. die('Not Implemented!');
  88. }
  89. function serviceUnavailable() {
  90. logMe("serviceUnavailable()\n");
  91. header('HTTP/1.1 503 Service Unavailable');
  92. header('Content-Type: text/plain; charset=UTF-8');
  93. die('Service Unavailable!');
  94. }
  95. function checkCompatibility() {
  96. logMe("checkCompatibility()\n");
  97. header('Content-Type: text/plain; charset=UTF-8');
  98. if (!function_exists('getallheaders')) {
  99. die('FAIL getallheaders!');
  100. }
  101. if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) {
  102. die('FAIL 64-bit or GMP extension!');
  103. }
  104. echo 'PASS';
  105. exit();
  106. }
  107. function authorizationToUserConf() {
  108. $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth'); //Input is 'GoogleLogin auth', but PHP replaces spaces by '_' http://php.net/language.variables.external
  109. if ($headerAuth != '') {
  110. $headerAuthX = explode('/', $headerAuth, 2);
  111. if (count($headerAuthX) === 2) {
  112. $user = $headerAuthX[0];
  113. if (ctype_alnum($user)) {
  114. try {
  115. $conf = new FreshRSS_Configuration($user);
  116. } catch (Exception $e) {
  117. logMe($e->getMessage() . "\n");
  118. unauthorized();
  119. }
  120. if ($headerAuthX[1] === sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash)) {
  121. return $conf;
  122. } else {
  123. logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n");
  124. Minz_Log::record('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], Minz_Log::WARNING);
  125. unauthorized();
  126. }
  127. } else {
  128. badRequest();
  129. }
  130. }
  131. }
  132. return null;
  133. }
  134. function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html
  135. logMe('clientLogin(' . $email . ")\n");
  136. if (ctype_alnum($email)) {
  137. if (!function_exists('password_verify')) {
  138. include_once(LIB_PATH . '/password_compat.php');
  139. }
  140. try {
  141. $conf = new FreshRSS_Configuration($email);
  142. } catch (Exception $e) {
  143. logMe($e->getMessage() . "\n");
  144. Minz_Log::record('Invalid API user ' . $email, Minz_Log::WARNING);
  145. unauthorized();
  146. }
  147. if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) {
  148. header('Content-Type: text/plain; charset=UTF-8');
  149. $auth = $email . '/' . sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash);
  150. echo 'SID=', $auth, "\n",
  151. 'Auth=', $auth, "\n";
  152. exit();
  153. } else {
  154. Minz_Log::record('Password API mismatch for user ' . $email, Minz_Log::WARNING);
  155. unauthorized();
  156. }
  157. } else {
  158. badRequest();
  159. }
  160. die();
  161. }
  162. function token($conf) {
  163. //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ https://github.com/ericmann/gReader-Library/blob/master/greader.class.php
  164. logMe('token('. $conf->user . ")\n"); //TODO: Implement real token that expires
  165. $token = str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters
  166. echo $token, "\n";
  167. exit();
  168. }
  169. function checkToken($conf, $token) {
  170. //http://code.google.com/p/google-reader-api/wiki/ActionToken
  171. logMe('checkToken(' . $token . ")\n");
  172. if ($token === str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z')) {
  173. return true;
  174. }
  175. unauthorized();
  176. }
  177. function tagList() {
  178. logMe("tagList()\n");
  179. header('Content-Type: application/json; charset=UTF-8');
  180. $pdo = new MyPDO();
  181. $stm = $pdo->prepare('SELECT c.name FROM `%_category` c');
  182. $stm->execute();
  183. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  184. $tags = array(
  185. array('id' => 'user/-/state/com.google/starred'),
  186. //array('id' => 'user/-/state/com.google/broadcast', 'sortid' => '2'),
  187. );
  188. foreach ($res as $cName) {
  189. $tags[] = array(
  190. 'id' => 'user/-/label/' . $cName,
  191. //'sortid' => $cName,
  192. );
  193. }
  194. echo json_encode(array('tags' => $tags)), "\n";
  195. exit();
  196. }
  197. function subscriptionList() {
  198. logMe("subscriptionList()\n");
  199. header('Content-Type: application/json; charset=UTF-8');
  200. $pdo = new MyPDO();
  201. $stm = $pdo->prepare('SELECT f.id, f.name, f.url, f.website, c.id as c_id, c.name as c_name FROM `%_feed` f
  202. INNER JOIN `%_category` c ON c.id = f.category');
  203. $stm->execute();
  204. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  205. $subscriptions = array();
  206. foreach ($res as $line) {
  207. $subscriptions[] = array(
  208. 'id' => 'feed/' . $line['id'],
  209. 'title' => $line['name'],
  210. 'categories' => array(
  211. array(
  212. 'id' => 'user/-/label/' . $line['c_name'],
  213. 'label' => $line['c_name'],
  214. ),
  215. ),
  216. //'sortid' => $line['name'],
  217. //'firstitemmsec' => 0,
  218. 'url' => $line['url'],
  219. 'htmlUrl' => $line['website'],
  220. //'iconUrl' => '',
  221. );
  222. }
  223. echo json_encode(array('subscriptions' => $subscriptions)), "\n";
  224. exit();
  225. }
  226. function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
  227. logMe("unreadCount()\n");
  228. header('Content-Type: application/json; charset=UTF-8');
  229. $totalUnreads = 0;
  230. $totalLastUpdate = 0;
  231. $categoryDAO = new FreshRSS_CategoryDAO();
  232. foreach ($categoryDAO->listCategories(true, true) as $cat) {
  233. $catLastUpdate = 0;
  234. foreach ($cat->feeds() as $feed) {
  235. $lastUpdate = $feed->lastUpdate();
  236. $unreadcounts[] = array(
  237. 'id' => 'feed/' . $feed->id(),
  238. 'count' => $feed->nbNotRead(),
  239. 'newestItemTimestampUsec' => $lastUpdate . '000000',
  240. );
  241. if ($catLastUpdate < $lastUpdate) {
  242. $catLastUpdate = $lastUpdate;
  243. }
  244. }
  245. $unreadcounts[] = array(
  246. 'id' => 'user/-/label/' . $cat->name(),
  247. 'count' => $cat->nbNotRead(),
  248. 'newestItemTimestampUsec' => $catLastUpdate . '000000',
  249. );
  250. $totalUnreads += $cat->nbNotRead();
  251. if ($totalLastUpdate < $catLastUpdate) {
  252. $totalLastUpdate = $catLastUpdate;
  253. }
  254. }
  255. $unreadcounts[] = array(
  256. 'id' => 'user/-/state/com.google/reading-list',
  257. 'count' => $totalUnreads,
  258. 'newestItemTimestampUsec' => $totalLastUpdate . '000000',
  259. );
  260. echo json_encode(array(
  261. 'max' => $totalUnreads,
  262. 'unreadcounts' => $unreadcounts,
  263. )), "\n";
  264. exit();
  265. }
  266. function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  267. logMe('streamContents(' . $include_target . ")\n");
  268. header('Content-Type: application/json; charset=UTF-8');
  269. $feedDAO = new FreshRSS_FeedDAO();
  270. $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
  271. switch ($path) {
  272. case 'reading-list':
  273. $type = 'A';
  274. break;
  275. case 'starred':
  276. $type = 's';
  277. break;
  278. case 'feed':
  279. $type = 'f';
  280. break;
  281. case 'label':
  282. $type = 'c';
  283. $categoryDAO = new FreshRSS_CategoryDAO();
  284. $cat = $categoryDAO->searchByName($include_target);
  285. $include_target = $cat == null ? -1 : $cat->id();
  286. break;
  287. default:
  288. $type = 'A';
  289. break;
  290. }
  291. switch ($exclude_target) {
  292. case 'user/-/state/com.google/read':
  293. $state = 'not_read';
  294. break;
  295. default:
  296. $state = 'all';
  297. break;
  298. }
  299. if (!empty($continuation)) {
  300. $count++; //Shift by one element
  301. }
  302. $entryDAO = new FreshRSS_EntryDAO();
  303. $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, '', $start_time);
  304. $items = array();
  305. foreach ($entries as $entry) {
  306. $f_id = $entry->feed();
  307. if (isset($arrayFeedCategoryNames[$f_id])) {
  308. $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
  309. $f_name = $arrayFeedCategoryNames[$f_id]['name'];
  310. } else {
  311. $c_name = '_';
  312. $f_name = '_';
  313. }
  314. $item = array(
  315. 'id' => /*'tag:google.com,2005:reader/item/' .*/ dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  316. 'crawlTimeMsec' => substr($entry->id(), 0, -3),
  317. 'timestampUsec' => $entry->id(), //EasyRSS
  318. 'published' => $entry->date(true),
  319. 'title' => $entry->title(),
  320. 'summary' => array('content' => $entry->content()),
  321. 'alternate' => array(
  322. array('href' => $entry->link()),
  323. ),
  324. 'categories' => array(
  325. 'user/-/state/com.google/reading-list',
  326. 'user/-/label/' . $c_name,
  327. ),
  328. 'origin' => array(
  329. 'streamId' => 'feed/' . $f_id,
  330. 'title' => $f_name, //EasyRSS
  331. //'htmlUrl' => $line['f_website'],
  332. ),
  333. );
  334. if ($entry->author() != '') {
  335. $item['author'] = $entry->author();
  336. }
  337. if ($entry->isRead()) {
  338. $item['categories'][] = 'user/-/state/com.google/read';
  339. }
  340. if ($entry->isFavorite()) {
  341. $item['categories'][] = 'user/-/state/com.google/starred';
  342. }
  343. $items[] = $item;
  344. }
  345. if (!empty($continuation)) {
  346. array_shift($items); //Discard first element that was already sent in the previous response
  347. }
  348. $response = array(
  349. 'id' => 'user/-/state/com.google/reading-list',
  350. 'updated' => time(),
  351. 'items' => $items,
  352. );
  353. if ((count($entries) >= $count) && (!empty($entry))) {
  354. $response['continuation'] = $entry->id();
  355. }
  356. echo json_encode($response), "\n";
  357. exit();
  358. }
  359. function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target) { //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  360. logMe('streamContentsItemsIds(' . $streamId . ")\n");
  361. $type = 'A';
  362. $id = '';
  363. if ($streamId === 'user/-/state/com.google/reading-list') {
  364. $type = 'A';
  365. } elseif ('user/-/state/com.google/starred') {
  366. $type = 's';
  367. } elseif (strpos($streamId, 'feed/') === 0) {
  368. $type = 'f';
  369. $id = basename($streamId);
  370. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  371. $type = 'c';
  372. $c_name = basename($streamId);
  373. $categoryDAO = new FreshRSS_CategoryDAO();
  374. $cat = $categoryDAO->searchByName($c_name);
  375. $id = $cat == null ? -1 : $cat->id();
  376. }
  377. switch ($exclude_target) {
  378. case 'user/-/state/com.google/read':
  379. $state = 'not_read';
  380. break;
  381. default:
  382. $state = 'all';
  383. break;
  384. }
  385. $entryDAO = new FreshRSS_EntryDAO();
  386. $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time);
  387. $itemRefs = array();
  388. foreach ($ids as $id) {
  389. $itemRefs[] = array(
  390. 'id' => $id, //64-bit decimal
  391. );
  392. }
  393. echo json_encode(array(
  394. 'itemRefs' => $itemRefs,
  395. )), "\n";
  396. exit();
  397. }
  398. function editTag($e_ids, $a, $r) {
  399. logMe("editTag()\n");
  400. foreach ($e_ids as $i => $e_id) {
  401. $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  402. }
  403. $entryDAO = new FreshRSS_EntryDAO();
  404. switch ($a) {
  405. case 'user/-/state/com.google/read':
  406. $entryDAO->markRead($e_ids, true);
  407. break;
  408. case 'user/-/state/com.google/starred':
  409. $entryDAO->markFavorite($e_ids, true);
  410. break;
  411. /*case 'user/-/state/com.google/tracking-kept-unread':
  412. break;
  413. case 'user/-/state/com.google/like':
  414. break;
  415. case 'user/-/state/com.google/broadcast':
  416. break;*/
  417. }
  418. switch ($r) {
  419. case 'user/-/state/com.google/read':
  420. $entryDAO->markRead($e_ids, false);
  421. break;
  422. case 'user/-/state/com.google/starred':
  423. $entryDAO->markFavorite($e_ids, false);
  424. break;
  425. }
  426. echo 'OK';
  427. exit();
  428. }
  429. function markAllAsRead($streamId, $olderThanId) {
  430. logMe('markAllAsRead(' . $streamId . ")\n");
  431. $entryDAO = new FreshRSS_EntryDAO();
  432. if (strpos($streamId, 'feed/') === 0) {
  433. $f_id = basename($streamId);
  434. $entryDAO->markReadFeed($f_id, $olderThanId);
  435. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  436. $c_name = basename($streamId);
  437. $entryDAO->markReadCatName($c_name, $olderThanId);
  438. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  439. $entryDAO->markReadEntries($olderThanId, false, -1);
  440. }
  441. echo 'OK';
  442. exit();
  443. }
  444. logMe('----------------------------------------------------------------'."\n");
  445. logMe(print_r($debugInfo, true));
  446. $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
  447. $pathInfos = explode('/', $pathInfo);
  448. logMe('pathInfos => ' . print_r($pathInfos, true));
  449. Minz_Configuration::init();
  450. if (!Minz_Configuration::apiEnabled()) {
  451. serviceUnavailable();
  452. }
  453. Minz_Session::init('FreshRSS');
  454. $conf = authorizationToUserConf();
  455. $user = $conf == null ? '' : $conf->user;
  456. logMe('User => ' . $user . "\n");
  457. Minz_Session::_param('currentUser', $user);
  458. if (count($pathInfos) < 3) {
  459. badRequest();
  460. }
  461. elseif ($pathInfos[1] === 'accounts') {
  462. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  463. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  464. }
  465. }
  466. elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  467. if ($user == '') {
  468. unauthorized();
  469. }
  470. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  471. switch ($pathInfos[4]) {
  472. case 'stream':
  473. $exclude_target = isset($_GET['xt']) ? $_GET['xt'] : ''; //xt=[exclude target] : Used to exclude certain items from the feed. For example, using xt=user/-/state/com.google/read will exclude items that the current user has marked as read, or xt=feed/[feedurl] will exclude items from a particular feed (obviously not useful in this request, but xt appears in other listing requests).
  474. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  475. $order = isset($_GET['r']) ? $_GET['r'] : 'd'; //r=[d|n|o] : Sort order of item results. d or n gives items in descending date order, o in ascending order.
  476. $start_time = isset($_GET['ot']) ? intval($_GET['ot']) : 0; //ot=[unix timestamp] : The time from which you want to retrieve items. Only items that have been crawled by Google Reader after this time will be returned.
  477. $continuation = isset($_GET['c']) ? $_GET['c'] : ''; //Continuation token. If a StreamContents response does not represent all items in a timestamp range, it will have a continuation attribute. The same request can be re-issued with the value of that attribute put in this parameter to get more items
  478. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  479. if (isset($pathInfos[7])) {
  480. if ($pathInfos[6] === 'feed') {
  481. $include_target = $pathInfos[7];
  482. StreamContents($pathInfos[6], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  483. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  484. if ($pathInfos[8] === 'state') {
  485. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  486. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  487. $include_target = '';
  488. streamContents($pathInfos[10], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  489. }
  490. }
  491. } elseif ($pathInfos[8] === 'label') {
  492. $include_target = $pathInfos[9];
  493. streamContents($pathInfos[8], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  494. }
  495. }
  496. } else { //EasyRSS
  497. $include_target = '';
  498. streamContents('reading-list', $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  499. }
  500. } elseif ($pathInfos[5] === 'items') {
  501. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  502. $streamId = $_GET['s']; //StreamId for which to fetch the item IDs. The parameter may be repeated to fetch the item IDs from multiple streams at once (more efficient from a backend perspective than multiple requests).
  503. streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target);
  504. }
  505. }
  506. break;
  507. case 'tag':
  508. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  509. $output = isset($_GET['output']) ? $_GET['output'] : '';
  510. if ($output !== 'json') notImplemented();
  511. tagList($_GET['output']);
  512. }
  513. break;
  514. case 'subscription':
  515. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  516. $output = isset($_GET['output']) ? $_GET['output'] : '';
  517. if ($output !== 'json') notImplemented();
  518. subscriptionList($_GET['output']);
  519. }
  520. break;
  521. case 'unread-count':
  522. $output = isset($_GET['output']) ? $_GET['output'] : '';
  523. if ($output !== 'json') notImplemented();
  524. $all = isset($_GET['all']) ? $_GET['all'] : '';
  525. unreadCount($all);
  526. break;
  527. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  528. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  529. checkToken($conf, $token);
  530. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  531. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  532. $e_ids = multiplePosts('i'); //item IDs
  533. editTag($e_ids, $a, $r);
  534. break;
  535. case 'mark-all-as-read':
  536. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  537. checkToken($conf, $token);
  538. $streamId = $_POST['s']; //StreamId
  539. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  540. if (!ctype_digit($ts)) {
  541. $ts = '0';
  542. }
  543. markAllAsRead($streamId, $ts);
  544. break;
  545. case 'token':
  546. Token($conf);
  547. break;
  548. }
  549. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  550. checkCompatibility();
  551. }
  552. badRequest();