greader.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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() {
  223. logMe("unreadCount()\n");
  224. header('Content-Type: application/json; charset=UTF-8');
  225. $pdo = new MyPDO();
  226. $stm = $pdo->prepare('SELECT f.id, f.lastUpdate, f.cache_nbUnreads FROM `%_feed` f');
  227. $stm->execute();
  228. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  229. $unreadcounts = array();
  230. $totalUnreads = 0;
  231. $totalLastUpdate = 0;
  232. foreach ($res as $line) {
  233. $nbUnreads = $line['cache_nbUnreads'];
  234. $totalUnreads += $nbUnreads;
  235. $lastUpdate = $line['lastUpdate'];
  236. if ($totalLastUpdate < $lastUpdate) {
  237. $totalLastUpdate = $lastUpdate;
  238. }
  239. $unreadcounts[] = array(
  240. 'id' => 'feed/' . $line['id'],
  241. 'count' => $nbUnreads,
  242. 'newestItemTimestampUsec' => $lastUpdate . '000000',
  243. );
  244. }
  245. $unreadcounts[] = array(
  246. 'id' => 'user/-/state/com.google/reading-list',
  247. 'count' => $totalUnreads,
  248. 'newestItemTimestampUsec' => $totalLastUpdate . '000000',
  249. );
  250. echo json_encode(array(
  251. 'max' => $totalUnreads,
  252. 'unreadcounts' => $unreadcounts,
  253. )), "\n";
  254. exit();
  255. }
  256. function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target)
  257. {//http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  258. logMe('streamContents(' . $include_target . ")\n");
  259. header('Content-Type: application/json; charset=UTF-8');
  260. $feedDAO = new FreshRSS_FeedDAO();
  261. $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
  262. switch ($path) {
  263. case 'reading-list':
  264. $type = 'A';
  265. break;
  266. case 'starred':
  267. $type = 's';
  268. break;
  269. case 'feed':
  270. $type = 'f';
  271. break;
  272. case 'label':
  273. $type = 'c';
  274. $categoryDAO = new FreshRSS_CategoryDAO();
  275. $cat = $categoryDAO->searchByName($include_target);
  276. $include_target = $cat == null ? -1 : $cat->id();
  277. break;
  278. default:
  279. $type = 'A';
  280. break;
  281. }
  282. switch ($exclude_target) {
  283. case 'user/-/state/com.google/read':
  284. $state = 'not_read';
  285. break;
  286. default:
  287. $state = 'all';
  288. break;
  289. }
  290. $entryDAO = new FreshRSS_EntryDAO();
  291. $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time);
  292. $items = array();
  293. foreach ($entries as $entry) {
  294. $f_id = $entry->feed();
  295. if (isset($arrayFeedCategoryNames[$f_id])) {
  296. $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
  297. $f_name = $arrayFeedCategoryNames[$f_id]['name'];
  298. } else {
  299. $c_name = '_';
  300. $f_name = '_';
  301. }
  302. $item = array(
  303. 'id' => /*'tag:google.com,2005:reader/item/' .*/ dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  304. 'crawlTimeMsec' => substr($entry->id(), 0, -3),
  305. 'timestampUsec' => $entry->id(), //EasyRSS
  306. 'published' => $entry->date(true),
  307. 'title' => $entry->title(),
  308. 'summary' => array('content' => $entry->content()),
  309. 'alternate' => array(
  310. array('href' => $entry->link()),
  311. ),
  312. 'categories' => array(
  313. 'user/-/state/com.google/reading-list',
  314. 'user/-/label/' . $c_name,
  315. ),
  316. 'origin' => array(
  317. 'streamId' => 'feed/' . $f_id,
  318. 'title' => $f_name, //EasyRSS
  319. //'htmlUrl' => $line['f_website'],
  320. ),
  321. );
  322. if ($entry->author() != '') {
  323. $item['author'] = $entry->author();
  324. }
  325. if ($entry->isRead()) {
  326. $item['categories'][] = 'user/-/state/com.google/read';
  327. }
  328. if ($entry->isFavorite()) {
  329. $item['categories'][] = 'user/-/state/com.google/starred';
  330. }
  331. $items[] = $item;
  332. }
  333. echo json_encode(array(
  334. 'id' => 'user/-/state/com.google/reading-list',
  335. 'updated' => time(),
  336. 'items' => $items,
  337. )), "\n";
  338. exit();
  339. }
  340. function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)
  341. {//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
  342. logMe('streamContentsItemsIds(' . $streamId . ")\n");
  343. $type = 'A';
  344. $id = '';
  345. if ($streamId === 'user/-/state/com.google/reading-list') {
  346. $type = 'A';
  347. } elseif ('user/-/state/com.google/starred') {
  348. $type = 's';
  349. } elseif (strpos($streamId, 'feed/') === 0) {
  350. $type = 'f';
  351. $id = basename($streamId);
  352. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  353. $type = 'c';
  354. $c_name = basename($streamId);
  355. $categoryDAO = new FreshRSS_CategoryDAO();
  356. $cat = $categoryDAO->searchByName($c_name);
  357. $id = $cat == null ? -1 : $cat->id();
  358. }
  359. switch ($exclude_target) {
  360. case 'user/-/state/com.google/read':
  361. $state = 'not_read';
  362. break;
  363. default:
  364. $state = 'all';
  365. break;
  366. }
  367. $entryDAO = new FreshRSS_EntryDAO();
  368. $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time);
  369. $itemRefs = array();
  370. foreach ($ids as $id) {
  371. $itemRefs[] = array(
  372. 'id' => $id, //64-bit decimal
  373. );
  374. }
  375. echo json_encode(array(
  376. 'itemRefs' => $itemRefs,
  377. )), "\n";
  378. exit();
  379. }
  380. function editTag($e_ids, $a, $r) {
  381. logMe("editTag()\n");
  382. foreach ($e_ids as $i => $e_id) {
  383. $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  384. }
  385. $entryDAO = new FreshRSS_EntryDAO();
  386. switch ($a) {
  387. case 'user/-/state/com.google/read':
  388. $entryDAO->markRead($e_ids, true);
  389. break;
  390. case 'user/-/state/com.google/starred':
  391. $entryDAO->markFavorite($e_ids, true);
  392. break;
  393. /*case 'user/-/state/com.google/tracking-kept-unread':
  394. break;
  395. case 'user/-/state/com.google/like':
  396. break;
  397. case 'user/-/state/com.google/broadcast':
  398. break;*/
  399. }
  400. switch ($r) {
  401. case 'user/-/state/com.google/read':
  402. $entryDAO->markRead($e_ids, false);
  403. break;
  404. case 'user/-/state/com.google/starred':
  405. $entryDAO->markFavorite($e_ids, false);
  406. break;
  407. }
  408. echo 'OK';
  409. exit();
  410. }
  411. function markAllAsRead($streamId, $olderThanId) {
  412. logMe('markAllAsRead(' . $streamId . ")\n");
  413. $entryDAO = new FreshRSS_EntryDAO();
  414. if (strpos($streamId, 'feed/') === 0) {
  415. $f_id = basename($streamId);
  416. $entryDAO->markReadFeed($f_id, $olderThanId);
  417. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  418. $c_name = basename($streamId);
  419. $entryDAO->markReadCatName($c_name, $olderThanId);
  420. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  421. $entryDAO->markReadEntries($olderThanId, false, -1);
  422. }
  423. echo 'OK';
  424. exit();
  425. }
  426. logMe('----------------------------------------------------------------'."\n");
  427. logMe(print_r($debugInfo, true));
  428. $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
  429. $pathInfos = explode('/', $pathInfo);
  430. logMe('pathInfos => ' . print_r($pathInfos, true));
  431. Minz_Configuration::init();
  432. if (!Minz_Configuration::apiEnabled()) {
  433. serviceUnavailable();
  434. }
  435. Minz_Session::init('FreshRSS');
  436. $conf = authorizationToUserConf();
  437. $user = $conf == null ? '' : $conf->user;
  438. logMe('User => ' . $user . "\n");
  439. Minz_Session::_param('currentUser', $user);
  440. if (count($pathInfos) < 3) {
  441. badRequest();
  442. }
  443. elseif ($pathInfos[1] === 'accounts') {
  444. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  445. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  446. }
  447. }
  448. elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  449. if ($user == '') {
  450. unauthorized();
  451. }
  452. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  453. switch ($pathInfos[4]) {
  454. case 'stream':
  455. $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).
  456. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  457. $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.
  458. $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.
  459. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  460. if (isset($pathInfos[7])) {
  461. if ($pathInfos[6] === 'feed') {
  462. $include_target = $pathInfos[7];
  463. StreamContents($pathInfos[6], $include_target, $start_time, $count, $order, $exclude_target);
  464. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  465. if ($pathInfos[8] === 'state') {
  466. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  467. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  468. $include_target = '';
  469. streamContents($pathInfos[10], $include_target, $start_time, $count, $order, $exclude_target);
  470. }
  471. }
  472. } elseif ($pathInfos[8] === 'label') {
  473. $include_target = $pathInfos[9];
  474. streamContents($pathInfos[8], $include_target, $start_time, $count, $order, $exclude_target);
  475. }
  476. }
  477. } else { //EasyRSS
  478. $include_target = '';
  479. streamContents('reading-list', $include_target, $start_time, $count, $order, $exclude_target);
  480. }
  481. } elseif ($pathInfos[5] === 'items') {
  482. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  483. $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).
  484. streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target);
  485. }
  486. }
  487. break;
  488. case 'tag':
  489. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  490. $output = isset($_GET['output']) ? $_GET['output'] : '';
  491. if ($output !== 'json') notImplemented();
  492. tagList($_GET['output']);
  493. }
  494. break;
  495. case 'subscription':
  496. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  497. $output = isset($_GET['output']) ? $_GET['output'] : '';
  498. if ($output !== 'json') notImplemented();
  499. subscriptionList($_GET['output']);
  500. }
  501. break;
  502. case 'unread-count':
  503. $output = isset($_GET['output']) ? $_GET['output'] : '';
  504. if ($output !== 'json') notImplemented();
  505. $all = isset($_GET['all']) ? $_GET['all'] : '';
  506. unreadCount($all);
  507. break;
  508. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  509. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  510. checkToken($conf, $token);
  511. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  512. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  513. $e_ids = multiplePosts('i'); //item IDs
  514. editTag($e_ids, $a, $r);
  515. break;
  516. case 'mark-all-as-read':
  517. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  518. checkToken($conf, $token);
  519. $streamId = $_POST['s']; //StreamId
  520. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  521. if (!ctype_digit($ts)) {
  522. $ts = '0';
  523. }
  524. markAllAsRead($streamId, $ts);
  525. break;
  526. case 'token':
  527. Token($conf);
  528. break;
  529. }
  530. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  531. checkCompatibility();
  532. }
  533. badRequest();