greader.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. $ok = true;
  99. $ok &= function_exists('getallheaders');
  100. echo $ok ? 'PASS' : 'FAIL';
  101. exit();
  102. }
  103. function authorizationToUserConf() {
  104. $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth'); //Input is 'GoogleLogin auth', but PHP replaces spaces by '_' http://php.net/language.variables.external
  105. if ($headerAuth != '') {
  106. $headerAuthX = explode('/', $headerAuth, 2);
  107. if (count($headerAuthX) === 2) {
  108. $user = $headerAuthX[0];
  109. if (ctype_alnum($user)) {
  110. try {
  111. $conf = new FreshRSS_Configuration($user);
  112. } catch (Exception $e) {
  113. logMe($e->getMessage() . "\n");
  114. unauthorized();
  115. }
  116. if ($headerAuthX[1] === sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash)) {
  117. return $conf;
  118. } else {
  119. logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n");
  120. Minz_Log::record('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], Minz_Log::WARNING);
  121. unauthorized();
  122. }
  123. } else {
  124. badRequest();
  125. }
  126. }
  127. }
  128. return null;
  129. }
  130. function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html
  131. logMe('clientLogin(' . $email . ")\n");
  132. if (ctype_alnum($email)) {
  133. if (!function_exists('password_verify')) {
  134. include_once(LIB_PATH . '/password_compat.php');
  135. }
  136. try {
  137. $conf = new FreshRSS_Configuration($email);
  138. } catch (Exception $e) {
  139. logMe($e->getMessage() . "\n");
  140. Minz_Log::record('Invalid API user ' . $email, Minz_Log::WARNING);
  141. unauthorized();
  142. }
  143. if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) {
  144. header('Content-Type: text/plain; charset=UTF-8');
  145. $auth = $email . '/' . sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash);
  146. echo 'SID=', $auth, "\n",
  147. 'Auth=', $auth, "\n";
  148. exit();
  149. } else {
  150. Minz_Log::record('Password API mismatch for user ' . $email, Minz_Log::WARNING);
  151. unauthorized();
  152. }
  153. } else {
  154. badRequest();
  155. }
  156. die();
  157. }
  158. function token($conf) {
  159. //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
  160. logMe('token('. $conf->user . ")\n"); //TODO: Implement real token that expires
  161. $token = str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters
  162. echo $token, "\n";
  163. exit();
  164. }
  165. function checkToken($conf, $token) {
  166. //http://code.google.com/p/google-reader-api/wiki/ActionToken
  167. logMe('checkToken(' . $token . ")\n");
  168. if ($token === str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z')) {
  169. return true;
  170. }
  171. unauthorized();
  172. }
  173. function tagList() {
  174. logMe("tagList()\n");
  175. header('Content-Type: application/json; charset=UTF-8');
  176. $pdo = new MyPDO();
  177. $stm = $pdo->prepare('SELECT c.name FROM `%_category` c');
  178. $stm->execute();
  179. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  180. $tags = array(
  181. array('id' => 'user/-/state/com.google/starred'),
  182. //array('id' => 'user/-/state/com.google/broadcast', 'sortid' => '2'),
  183. );
  184. foreach ($res as $cName) {
  185. $tags[] = array(
  186. 'id' => 'user/-/label/' . $cName,
  187. //'sortid' => $cName,
  188. );
  189. }
  190. echo json_encode(array('tags' => $tags)), "\n";
  191. exit();
  192. }
  193. function subscriptionList() {
  194. logMe("subscriptionList()\n");
  195. header('Content-Type: application/json; charset=UTF-8');
  196. $pdo = new MyPDO();
  197. $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
  198. INNER JOIN `%_category` c ON c.id = f.category');
  199. $stm->execute();
  200. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  201. $subscriptions = array();
  202. foreach ($res as $line) {
  203. $subscriptions[] = array(
  204. 'id' => 'feed/' . $line['id'],
  205. 'title' => $line['name'],
  206. 'categories' => array(
  207. array(
  208. 'id' => 'user/-/label/' . $line['c_name'],
  209. 'label' => $line['c_name'],
  210. ),
  211. ),
  212. //'sortid' => $line['name'],
  213. //'firstitemmsec' => 0,
  214. 'url' => $line['url'],
  215. 'htmlUrl' => $line['website'],
  216. //'iconUrl' => '',
  217. );
  218. }
  219. echo json_encode(array('subscriptions' => $subscriptions)), "\n";
  220. exit();
  221. }
  222. function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
  223. logMe("unreadCount()\n");
  224. header('Content-Type: application/json; charset=UTF-8');
  225. $totalUnreads = 0;
  226. $totalLastUpdate = 0;
  227. $categoryDAO = new FreshRSS_CategoryDAO();
  228. foreach ($categoryDAO->listCategories(true, true) as $cat) {
  229. $catLastUpdate = 0;
  230. foreach ($cat->feeds() as $feed) {
  231. $lastUpdate = $feed->lastUpdate();
  232. $unreadcounts[] = array(
  233. 'id' => 'feed/' . $feed->id(),
  234. 'count' => $feed->nbNotRead(),
  235. 'newestItemTimestampUsec' => $lastUpdate . '000000',
  236. );
  237. if ($catLastUpdate < $lastUpdate) {
  238. $catLastUpdate = $lastUpdate;
  239. }
  240. }
  241. $unreadcounts[] = array(
  242. 'id' => 'user/-/label/' . $cat->name(),
  243. 'count' => $cat->nbNotRead(),
  244. 'newestItemTimestampUsec' => $catLastUpdate . '000000',
  245. );
  246. $totalUnreads += $cat->nbNotRead();
  247. if ($totalLastUpdate < $catLastUpdate) {
  248. $totalLastUpdate = $catLastUpdate;
  249. }
  250. }
  251. $unreadcounts[] = array(
  252. 'id' => 'user/-/state/com.google/reading-list',
  253. 'count' => $totalUnreads,
  254. 'newestItemTimestampUsec' => $totalLastUpdate . '000000',
  255. );
  256. echo json_encode(array(
  257. 'max' => $totalUnreads,
  258. 'unreadcounts' => $unreadcounts,
  259. )), "\n";
  260. exit();
  261. }
  262. 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
  263. logMe('streamContents(' . $include_target . ")\n");
  264. header('Content-Type: application/json; charset=UTF-8');
  265. $feedDAO = new FreshRSS_FeedDAO();
  266. $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
  267. switch ($path) {
  268. case 'reading-list':
  269. $type = 'A';
  270. break;
  271. case 'starred':
  272. $type = 's';
  273. break;
  274. case 'feed':
  275. $type = 'f';
  276. break;
  277. case 'label':
  278. $type = 'c';
  279. $categoryDAO = new FreshRSS_CategoryDAO();
  280. $cat = $categoryDAO->searchByName($include_target);
  281. $include_target = $cat == null ? -1 : $cat->id();
  282. break;
  283. default:
  284. $type = 'A';
  285. break;
  286. }
  287. switch ($exclude_target) {
  288. case 'user/-/state/com.google/read':
  289. $state = 'not_read';
  290. break;
  291. default:
  292. $state = 'all';
  293. break;
  294. }
  295. if (!empty($continuation)) {
  296. $count++; //Shift by one element
  297. }
  298. $entryDAO = new FreshRSS_EntryDAO();
  299. $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, '', $start_time);
  300. $items = array();
  301. foreach ($entries as $entry) {
  302. $f_id = $entry->feed();
  303. if (isset($arrayFeedCategoryNames[$f_id])) {
  304. $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
  305. $f_name = $arrayFeedCategoryNames[$f_id]['name'];
  306. } else {
  307. $c_name = '_';
  308. $f_name = '_';
  309. }
  310. $item = array(
  311. 'id' => /*'tag:google.com,2005:reader/item/' .*/ dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  312. 'crawlTimeMsec' => substr($entry->id(), 0, -3),
  313. 'timestampUsec' => $entry->id(), //EasyRSS
  314. 'published' => $entry->date(true),
  315. 'title' => $entry->title(),
  316. 'summary' => array('content' => $entry->content()),
  317. 'alternate' => array(
  318. array('href' => $entry->link()),
  319. ),
  320. 'categories' => array(
  321. 'user/-/state/com.google/reading-list',
  322. 'user/-/label/' . $c_name,
  323. ),
  324. 'origin' => array(
  325. 'streamId' => 'feed/' . $f_id,
  326. 'title' => $f_name, //EasyRSS
  327. //'htmlUrl' => $line['f_website'],
  328. ),
  329. );
  330. if ($entry->author() != '') {
  331. $item['author'] = $entry->author();
  332. }
  333. if ($entry->isRead()) {
  334. $item['categories'][] = 'user/-/state/com.google/read';
  335. }
  336. if ($entry->isFavorite()) {
  337. $item['categories'][] = 'user/-/state/com.google/starred';
  338. }
  339. $items[] = $item;
  340. }
  341. if (!empty($continuation)) {
  342. array_shift($items); //Discard first element that was already sent in the previous response
  343. }
  344. $response = array(
  345. 'id' => 'user/-/state/com.google/reading-list',
  346. 'updated' => time(),
  347. 'items' => $items,
  348. );
  349. if ((count($entries) >= $count) && (!empty($entry))) {
  350. $response['continuation'] = $entry->id();
  351. }
  352. echo json_encode($response), "\n";
  353. exit();
  354. }
  355. 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
  356. logMe('streamContentsItemsIds(' . $streamId . ")\n");
  357. $type = 'A';
  358. $id = '';
  359. if ($streamId === 'user/-/state/com.google/reading-list') {
  360. $type = 'A';
  361. } elseif ('user/-/state/com.google/starred') {
  362. $type = 's';
  363. } elseif (strpos($streamId, 'feed/') === 0) {
  364. $type = 'f';
  365. $id = basename($streamId);
  366. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  367. $type = 'c';
  368. $c_name = basename($streamId);
  369. $categoryDAO = new FreshRSS_CategoryDAO();
  370. $cat = $categoryDAO->searchByName($c_name);
  371. $id = $cat == null ? -1 : $cat->id();
  372. }
  373. switch ($exclude_target) {
  374. case 'user/-/state/com.google/read':
  375. $state = 'not_read';
  376. break;
  377. default:
  378. $state = 'all';
  379. break;
  380. }
  381. $entryDAO = new FreshRSS_EntryDAO();
  382. $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time);
  383. $itemRefs = array();
  384. foreach ($ids as $id) {
  385. $itemRefs[] = array(
  386. 'id' => $id, //64-bit decimal
  387. );
  388. }
  389. echo json_encode(array(
  390. 'itemRefs' => $itemRefs,
  391. )), "\n";
  392. exit();
  393. }
  394. function editTag($e_ids, $a, $r) {
  395. logMe("editTag()\n");
  396. foreach ($e_ids as $i => $e_id) {
  397. $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  398. }
  399. $entryDAO = new FreshRSS_EntryDAO();
  400. switch ($a) {
  401. case 'user/-/state/com.google/read':
  402. $entryDAO->markRead($e_ids, true);
  403. break;
  404. case 'user/-/state/com.google/starred':
  405. $entryDAO->markFavorite($e_ids, true);
  406. break;
  407. /*case 'user/-/state/com.google/tracking-kept-unread':
  408. break;
  409. case 'user/-/state/com.google/like':
  410. break;
  411. case 'user/-/state/com.google/broadcast':
  412. break;*/
  413. }
  414. switch ($r) {
  415. case 'user/-/state/com.google/read':
  416. $entryDAO->markRead($e_ids, false);
  417. break;
  418. case 'user/-/state/com.google/starred':
  419. $entryDAO->markFavorite($e_ids, false);
  420. break;
  421. }
  422. echo 'OK';
  423. exit();
  424. }
  425. function markAllAsRead($streamId, $olderThanId) {
  426. logMe('markAllAsRead(' . $streamId . ")\n");
  427. $entryDAO = new FreshRSS_EntryDAO();
  428. if (strpos($streamId, 'feed/') === 0) {
  429. $f_id = basename($streamId);
  430. $entryDAO->markReadFeed($f_id, $olderThanId);
  431. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  432. $c_name = basename($streamId);
  433. $entryDAO->markReadCatName($c_name, $olderThanId);
  434. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  435. $entryDAO->markReadEntries($olderThanId, false, -1);
  436. }
  437. echo 'OK';
  438. exit();
  439. }
  440. logMe('----------------------------------------------------------------'."\n");
  441. logMe(print_r($debugInfo, true));
  442. $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
  443. $pathInfos = explode('/', $pathInfo);
  444. logMe('pathInfos => ' . print_r($pathInfos, true));
  445. Minz_Configuration::init();
  446. if (!Minz_Configuration::apiEnabled()) {
  447. serviceUnavailable();
  448. }
  449. Minz_Session::init('FreshRSS');
  450. $conf = authorizationToUserConf();
  451. $user = $conf == null ? '' : $conf->user;
  452. logMe('User => ' . $user . "\n");
  453. Minz_Session::_param('currentUser', $user);
  454. if (count($pathInfos) < 3) {
  455. badRequest();
  456. }
  457. elseif ($pathInfos[1] === 'accounts') {
  458. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  459. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  460. }
  461. }
  462. elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  463. if ($user == '') {
  464. unauthorized();
  465. }
  466. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  467. switch ($pathInfos[4]) {
  468. case 'stream':
  469. $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).
  470. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  471. $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.
  472. $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.
  473. $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
  474. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  475. if (isset($pathInfos[7])) {
  476. if ($pathInfos[6] === 'feed') {
  477. $include_target = $pathInfos[7];
  478. StreamContents($pathInfos[6], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  479. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  480. if ($pathInfos[8] === 'state') {
  481. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  482. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  483. $include_target = '';
  484. streamContents($pathInfos[10], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  485. }
  486. }
  487. } elseif ($pathInfos[8] === 'label') {
  488. $include_target = $pathInfos[9];
  489. streamContents($pathInfos[8], $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  490. }
  491. }
  492. } else { //EasyRSS
  493. $include_target = '';
  494. streamContents('reading-list', $include_target, $start_time, $count, $order, $exclude_target, $continuation);
  495. }
  496. } elseif ($pathInfos[5] === 'items') {
  497. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  498. $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).
  499. streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target);
  500. }
  501. }
  502. break;
  503. case 'tag':
  504. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  505. $output = isset($_GET['output']) ? $_GET['output'] : '';
  506. if ($output !== 'json') notImplemented();
  507. tagList($_GET['output']);
  508. }
  509. break;
  510. case 'subscription':
  511. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  512. $output = isset($_GET['output']) ? $_GET['output'] : '';
  513. if ($output !== 'json') notImplemented();
  514. subscriptionList($_GET['output']);
  515. }
  516. break;
  517. case 'unread-count':
  518. $output = isset($_GET['output']) ? $_GET['output'] : '';
  519. if ($output !== 'json') notImplemented();
  520. $all = isset($_GET['all']) ? $_GET['all'] : '';
  521. unreadCount($all);
  522. break;
  523. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  524. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  525. checkToken($conf, $token);
  526. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  527. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  528. $e_ids = multiplePosts('i'); //item IDs
  529. editTag($e_ids, $a, $r);
  530. break;
  531. case 'mark-all-as-read':
  532. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  533. checkToken($conf, $token);
  534. $streamId = $_POST['s']; //StreamId
  535. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  536. if (!ctype_digit($ts)) {
  537. $ts = '0';
  538. }
  539. markAllAsRead($streamId, $ts);
  540. break;
  541. case 'token':
  542. Token($conf);
  543. break;
  544. }
  545. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  546. checkCompatibility();
  547. }
  548. badRequest();