greader.php 20 KB

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