4
0

greader.php 20 KB

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