greader.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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->arrayCategoryNames();
  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. $c_name = isset($arrayFeedCategoryNames[$f_id]) ? $arrayFeedCategoryNames[$f_id] : '_';
  296. $item = array(
  297. 'id' => /*'tag:google.com,2005:reader/item/' .*/ dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  298. 'crawlTimeMsec' => substr($entry->id(), 0, -3),
  299. 'published' => $entry->date(true),
  300. 'title' => $entry->title(),
  301. 'summary' => array('content' => $entry->content()),
  302. 'alternate' => array(
  303. array('href' => $entry->link()),
  304. ),
  305. 'categories' => array(
  306. 'user/-/state/com.google/reading-list',
  307. 'user/-/label/' . $c_name,
  308. ),
  309. 'origin' => array(
  310. 'streamId' => 'feed/' . $f_id,
  311. //'title' => $line['f_name'],
  312. //'htmlUrl' => $line['f_website'],
  313. ),
  314. );
  315. if ($entry->author() != '') {
  316. $item['author'] = $entry->author();
  317. }
  318. if ($entry->isRead()) {
  319. $item['categories'][] = 'user/-/state/com.google/read';
  320. }
  321. if ($entry->isFavorite()) {
  322. $item['categories'][] = 'user/-/state/com.google/starred';
  323. }
  324. $items[] = $item;
  325. }
  326. echo json_encode(array(
  327. 'id' => 'user/-/state/com.google/reading-list',
  328. 'updated' => time(),
  329. 'items' => $items,
  330. )), "\n";
  331. exit();
  332. }
  333. function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)
  334. {//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
  335. logMe('streamContentsItemsIds(' . $streamId . ")\n");
  336. $type = 'A';
  337. $id = '';
  338. if ($streamId === 'user/-/state/com.google/reading-list') {
  339. $type = 'A';
  340. } elseif ('user/-/state/com.google/starred') {
  341. $type = 's';
  342. } elseif (strpos($streamId, 'feed/') === 0) {
  343. $type = 'f';
  344. $id = basename($streamId);
  345. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  346. $type = 'c';
  347. $c_name = basename($streamId);
  348. $categoryDAO = new FreshRSS_CategoryDAO();
  349. $cat = $categoryDAO->searchByName($c_name);
  350. $id = $cat == null ? -1 : $cat->id();
  351. }
  352. switch ($exclude_target) {
  353. case 'user/-/state/com.google/read':
  354. $state = 'not_read';
  355. break;
  356. default:
  357. $state = 'all';
  358. break;
  359. }
  360. $entryDAO = new FreshRSS_EntryDAO();
  361. $entries = $entryDAO->listWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time);
  362. $itemRefs = array();
  363. foreach ($entries as $entry) {
  364. $f_id = $entry->feed();
  365. $itemRefs[] = array(
  366. 'id' => $entry->id(), //64-bit decimal
  367. //'timestampUsec' => $entry->dateAdded(true),
  368. /*'directStreamIds' => array(
  369. 'feed/' . $entry->feed()
  370. ),*/
  371. );
  372. }
  373. echo json_encode(array(
  374. 'itemRefs' => $itemRefs,
  375. )), "\n";
  376. exit();
  377. }
  378. function editTag($e_ids, $a, $r) {
  379. logMe("editTag()\n");
  380. $entryDAO = new FreshRSS_EntryDAO();
  381. foreach ($e_ids as $e_id) { //TODO: User WHERE...IN
  382. $e_id = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  383. switch ($a) {
  384. case 'user/-/state/com.google/read':
  385. $entryDAO->markRead($e_id, true);
  386. break;
  387. case 'user/-/state/com.google/starred':
  388. $entryDAO->markFavorite($e_id, true);
  389. break;
  390. /*case 'user/-/state/com.google/tracking-kept-unread':
  391. break;
  392. case 'user/-/state/com.google/like':
  393. break;
  394. case 'user/-/state/com.google/broadcast':
  395. break;*/
  396. }
  397. switch ($r) {
  398. case 'user/-/state/com.google/read':
  399. $entryDAO->markRead($e_id, false);
  400. break;
  401. case 'user/-/state/com.google/starred':
  402. $entryDAO->markFavorite($e_id, false);
  403. break;
  404. }
  405. }
  406. echo 'OK';
  407. exit();
  408. }
  409. function markAllAsRead($streamId, $olderThanId) {
  410. logMe('markAllAsRead(' . $streamId . ")\n");
  411. $entryDAO = new FreshRSS_EntryDAO();
  412. if (strpos($streamId, 'feed/') === 0) {
  413. $f_id = basename($streamId);
  414. $entryDAO->markReadFeed($f_id, $olderThanId);
  415. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  416. $c_name = basename($streamId);
  417. $entryDAO->markReadCatName($c_name, $olderThanId);
  418. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  419. $entryDAO->markReadEntries($olderThanId, false, -1);
  420. }
  421. echo 'OK';
  422. exit();
  423. }
  424. logMe('----------------------------------------------------------------'."\n");
  425. logMe(print_r($debugInfo, true));
  426. $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
  427. $pathInfos = explode('/', $pathInfo);
  428. logMe('pathInfos => ' . print_r($pathInfos, true));
  429. Minz_Configuration::init();
  430. if (!Minz_Configuration::apiEnabled()) {
  431. serviceUnavailable();
  432. }
  433. Minz_Session::init('FreshRSS');
  434. $conf = authorizationToUserConf();
  435. $user = $conf == null ? '' : $conf->user;
  436. logMe('User => ' . $user . "\n");
  437. Minz_Session::_param('currentUser', $user);
  438. if (count($pathInfos) < 3) {
  439. badRequest();
  440. }
  441. elseif ($pathInfos[1] === 'accounts') {
  442. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  443. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  444. }
  445. }
  446. elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  447. if ($user == '') {
  448. unauthorized();
  449. }
  450. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  451. switch ($pathInfos[4]) {
  452. case 'stream':
  453. $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).
  454. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  455. $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.
  456. $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.
  457. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6]) && isset($pathInfos[7])) {
  458. if ($pathInfos[6] === 'feed') {
  459. $include_target = $pathInfos[7];
  460. StreamContents($pathInfos[6], $include_target, $start_time, $count, $order, $exclude_target);
  461. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  462. if ($pathInfos[8] === 'state') {
  463. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  464. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  465. $include_target = '';
  466. streamContents($pathInfos[10], $include_target, $start_time, $count, $order, $exclude_target);
  467. }
  468. }
  469. } elseif ($pathInfos[8] === 'label') {
  470. $include_target = $pathInfos[9];
  471. streamContents($pathInfos[8], $include_target, $start_time, $count, $order, $exclude_target);
  472. }
  473. }
  474. } elseif ($pathInfos[5] === 'items') {
  475. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  476. $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).
  477. streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target);
  478. }
  479. }
  480. break;
  481. case 'tag':
  482. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  483. $output = isset($_GET['output']) ? $_GET['output'] : '';
  484. if ($output !== 'json') notImplemented();
  485. tagList($_GET['output']);
  486. }
  487. break;
  488. case 'subscription':
  489. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  490. $output = isset($_GET['output']) ? $_GET['output'] : '';
  491. if ($output !== 'json') notImplemented();
  492. subscriptionList($_GET['output']);
  493. }
  494. break;
  495. case 'unread-count':
  496. $output = isset($_GET['output']) ? $_GET['output'] : '';
  497. if ($output !== 'json') notImplemented();
  498. $all = isset($_GET['all']) ? $_GET['all'] : '';
  499. unreadCount($all);
  500. break;
  501. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  502. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  503. checkToken($conf, $token);
  504. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  505. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  506. $e_ids = multiplePosts('i'); //item IDs
  507. editTag($e_ids, $a, $r);
  508. break;
  509. case 'mark-all-as-read':
  510. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  511. checkToken($conf, $token);
  512. $streamId = $_POST['s']; //StreamId
  513. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  514. if (!ctype_digit($ts)) {
  515. $ts = '0';
  516. }
  517. markAllAsRead($streamId, $ts);
  518. break;
  519. case 'token':
  520. Token($conf);
  521. break;
  522. }
  523. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  524. checkCompatibility();
  525. }
  526. badRequest();