greader.php 18 KB

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