greader.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. <?php
  2. /**
  3. == Description ==
  4. Server-side API compatible with Google Reader API layer 2
  5. for the FreshRSS project https://freshrss.org
  6. == Credits ==
  7. * 2014-03: Released by Alexandre Alapetite https://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. * https://www.inoreader.com/developers/
  20. * https://feedhq.readthedocs.io/en/latest/api/index.html
  21. */
  22. require(__DIR__ . '/../../constants.php');
  23. require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
  24. $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576);
  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. define('JSON_OPTIONS', JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
  41. function headerVariable($headerName, $varName) {
  42. $header = '';
  43. $upName = 'HTTP_' . strtoupper($headerName);
  44. if (isset($_SERVER[$upName])) {
  45. $header = $_SERVER[$upName];
  46. } elseif (isset($_SERVER['REDIRECT_' . $upName])) {
  47. $header = $_SERVER['REDIRECT_' . $upName];
  48. } elseif (function_exists('getallheaders')) {
  49. $ALL_HEADERS = getallheaders();
  50. if (isset($ALL_HEADERS[$headerName])) {
  51. $header = $ALL_HEADERS[$headerName];
  52. }
  53. }
  54. parse_str($header, $pairs);
  55. return isset($pairs[$varName]) ? $pairs[$varName] : null;
  56. }
  57. function multiplePosts($name) { //https://bugs.php.net/bug.php?id=51633
  58. global $ORIGINAL_INPUT;
  59. $inputs = explode('&', $ORIGINAL_INPUT);
  60. $result = array();
  61. $prefix = $name . '=';
  62. $prefixLength = strlen($prefix);
  63. foreach ($inputs as $input) {
  64. if (strpos($input, $prefix) === 0) {
  65. $result[] = urldecode(substr($input, $prefixLength));
  66. }
  67. }
  68. return $result;
  69. }
  70. class MyPDO extends Minz_ModelPdo {
  71. function prepare($sql) {
  72. return $this->bd->prepare(str_replace('%_', $this->prefix, $sql));
  73. }
  74. }
  75. function debugInfo() {
  76. if (function_exists('getallheaders')) {
  77. $ALL_HEADERS = getallheaders();
  78. } else { //nginx http://php.net/getallheaders#84262
  79. $ALL_HEADERS = array();
  80. foreach ($_SERVER as $name => $value) {
  81. if (substr($name, 0, 5) === 'HTTP_') {
  82. $ALL_HEADERS[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
  83. }
  84. }
  85. }
  86. global $ORIGINAL_INPUT;
  87. return print_r(
  88. array(
  89. 'date' => date('c'),
  90. 'headers' => $ALL_HEADERS,
  91. '_SERVER' => $_SERVER,
  92. '_GET' => $_GET,
  93. '_POST' => $_POST,
  94. '_COOKIE' => $_COOKIE,
  95. 'INPUT' => $ORIGINAL_INPUT
  96. ), true);
  97. }
  98. function badRequest() {
  99. Minz_Log::warning('badRequest() ' . debugInfo(), API_LOG);
  100. header('HTTP/1.1 400 Bad Request');
  101. header('Content-Type: text/plain; charset=UTF-8');
  102. die('Bad Request!');
  103. }
  104. function unauthorized() {
  105. Minz_Log::warning('unauthorized() ' . debugInfo(), API_LOG);
  106. header('HTTP/1.1 401 Unauthorized');
  107. header('Content-Type: text/plain; charset=UTF-8');
  108. header('Google-Bad-Token: true');
  109. die('Unauthorized!');
  110. }
  111. function notImplemented() {
  112. Minz_Log::warning('notImplemented() ' . debugInfo(), API_LOG);
  113. header('HTTP/1.1 501 Not Implemented');
  114. header('Content-Type: text/plain; charset=UTF-8');
  115. die('Not Implemented!');
  116. }
  117. function serviceUnavailable() {
  118. Minz_Log::warning('serviceUnavailable() ' . debugInfo(), API_LOG);
  119. header('HTTP/1.1 503 Service Unavailable');
  120. header('Content-Type: text/plain; charset=UTF-8');
  121. die('Service Unavailable!');
  122. }
  123. function checkCompatibility() {
  124. Minz_Log::warning('checkCompatibility() ' . debugInfo(), API_LOG);
  125. header('Content-Type: text/plain; charset=UTF-8');
  126. if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) {
  127. die('FAIL 64-bit or GMP extension! Wrong PHP configuration.');
  128. }
  129. $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth');
  130. if ($headerAuth == '') {
  131. die('FAIL get HTTP Authorization header! Wrong Web server configuration.');
  132. }
  133. echo 'PASS';
  134. exit();
  135. }
  136. function authorizationToUser() {
  137. $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth'); //Input is 'GoogleLogin auth', but PHP replaces spaces by '_' http://php.net/language.variables.external
  138. if ($headerAuth != '') {
  139. $headerAuthX = explode('/', $headerAuth, 2);
  140. if (count($headerAuthX) === 2) {
  141. $user = $headerAuthX[0];
  142. if (FreshRSS_user_Controller::checkUsername($user)) {
  143. FreshRSS_Context::$user_conf = get_user_configuration($user);
  144. if (FreshRSS_Context::$user_conf == null) {
  145. Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.');
  146. unauthorized();
  147. }
  148. if ($headerAuthX[1] === sha1(FreshRSS_Context::$system_conf->salt . $user . FreshRSS_Context::$user_conf->apiPasswordHash)) {
  149. return $user;
  150. } else {
  151. Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], API_LOG);
  152. Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]);
  153. unauthorized();
  154. }
  155. } else {
  156. badRequest();
  157. }
  158. }
  159. }
  160. return '';
  161. }
  162. function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html
  163. if (FreshRSS_user_Controller::checkUsername($email)) {
  164. FreshRSS_Context::$user_conf = get_user_configuration($email);
  165. if (FreshRSS_Context::$user_conf == null) {
  166. Minz_Log::warning('Invalid API user ' . $email . ': configuration cannot be found.');
  167. unauthorized();
  168. }
  169. if (FreshRSS_Context::$user_conf->apiPasswordHash != '' && password_verify($pass, FreshRSS_Context::$user_conf->apiPasswordHash)) {
  170. header('Content-Type: text/plain; charset=UTF-8');
  171. $auth = $email . '/' . sha1(FreshRSS_Context::$system_conf->salt . $email . FreshRSS_Context::$user_conf->apiPasswordHash);
  172. echo 'SID=', $auth, "\n",
  173. 'LSID=null', "\n", //Vienna RSS
  174. 'Auth=', $auth, "\n";
  175. exit();
  176. } else {
  177. Minz_Log::warning('Password API mismatch for user ' . $email);
  178. unauthorized();
  179. }
  180. } else {
  181. badRequest();
  182. }
  183. die();
  184. }
  185. function token($conf) {
  186. //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/
  187. //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php
  188. $user = Minz_Session::param('currentUser', '_');
  189. //Minz_Log::debug('token('. $user . ')', API_LOG); //TODO: Implement real token that expires
  190. $token = str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters
  191. echo $token, "\n";
  192. exit();
  193. }
  194. function checkToken($conf, $token) {
  195. //http://code.google.com/p/google-reader-api/wiki/ActionToken
  196. $user = Minz_Session::param('currentUser', '_');
  197. if ($user !== '_' && ( //TODO: Check security consequences
  198. $token == '' || //FeedMe
  199. $token === 'x')) { //Reeder
  200. return true;
  201. }
  202. if ($token === str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) {
  203. return true;
  204. }
  205. Minz_Log::warning('Invalid POST token: ' . $token, API_LOG);
  206. unauthorized();
  207. }
  208. function userInfo() { //https://github.com/theoldreader/api#user-info
  209. $user = Minz_Session::param('currentUser', '_');
  210. exit(json_encode(array(
  211. 'userId' => $user,
  212. 'userName' => $user,
  213. 'userProfileId' => $user,
  214. 'userEmail' => FreshRSS_Context::$user_conf->mail_login,
  215. ), JSON_OPTIONS));
  216. }
  217. function tagList() {
  218. header('Content-Type: application/json; charset=UTF-8');
  219. $pdo = new MyPDO();
  220. $stm = $pdo->prepare('SELECT c.name FROM `%_category` c');
  221. $stm->execute();
  222. $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
  223. $tags = array(
  224. array('id' => 'user/-/state/com.google/starred'),
  225. //array('id' => 'user/-/state/com.google/broadcast', 'sortid' => '2'),
  226. );
  227. foreach ($res as $cName) {
  228. $tags[] = array(
  229. 'id' => 'user/-/label/' . htmlspecialchars_decode($cName, ENT_QUOTES),
  230. //'sortid' => $cName,
  231. 'type' => 'folder', //Inoreader
  232. );
  233. }
  234. unset($res);
  235. $tagDAO = FreshRSS_Factory::createTagDao();
  236. $labels = $tagDAO->listTags(true);
  237. foreach ($labels as $label) {
  238. $tags[] = array(
  239. 'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
  240. //'sortid' => $cName,
  241. 'type' => 'tag', //Inoreader
  242. 'unread_count' => $label->nbUnread(), //Inoreader
  243. );
  244. }
  245. echo json_encode(array('tags' => $tags), JSON_OPTIONS), "\n";
  246. exit();
  247. }
  248. function subscriptionList() {
  249. header('Content-Type: application/json; charset=UTF-8');
  250. $pdo = new MyPDO();
  251. $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
  252. INNER JOIN `%_category` c ON c.id = f.category AND f.priority >= :priority_normal');
  253. $stm->execute(array(':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL));
  254. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  255. $salt = FreshRSS_Context::$system_conf->salt;
  256. $faviconsUrl = Minz_Url::display('/f.php?', '', true);
  257. $faviconsUrl = str_replace('/api/greader.php/reader/api/0/subscription', '', $faviconsUrl); //Security if base_url is not set properly
  258. $subscriptions = array();
  259. foreach ($res as $line) {
  260. $subscriptions[] = array(
  261. 'id' => 'feed/' . $line['id'],
  262. 'title' => escapeToUnicodeAlternative($line['name'], true),
  263. 'categories' => array(
  264. array(
  265. 'id' => 'user/-/label/' . htmlspecialchars_decode($line['c_name'], ENT_QUOTES),
  266. 'label' => htmlspecialchars_decode($line['c_name'], ENT_QUOTES),
  267. ),
  268. ),
  269. //'sortid' => $line['name'],
  270. //'firstitemmsec' => 0,
  271. 'url' => htmlspecialchars_decode($line['url'], ENT_QUOTES),
  272. 'htmlUrl' => htmlspecialchars_decode($line['website'], ENT_QUOTES),
  273. 'iconUrl' => $faviconsUrl . hash('crc32b', $salt . $line['url']),
  274. );
  275. }
  276. echo json_encode(array('subscriptions' => $subscriptions), JSON_OPTIONS), "\n";
  277. exit();
  278. }
  279. function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') {
  280. //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki
  281. switch ($action) {
  282. case 'subscribe':
  283. case 'unsubscribe':
  284. case 'edit':
  285. break;
  286. default:
  287. badRequest();
  288. }
  289. $addCatId = 0;
  290. $categoryDAO = null;
  291. if ($add != '' || $remove != '') {
  292. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  293. }
  294. $c_name = '';
  295. if ($add != '' && strpos($add, 'user/') === 0) { //user/-/label/Example ; user/username/label/Example
  296. if (strpos($add, 'user/-/label/') === 0) {
  297. $c_name = substr($add, 13);
  298. } else {
  299. $user = Minz_Session::param('currentUser', '_');
  300. $prefix = 'user/' . $user . '/label/';
  301. if (strpos($add, $prefix) === 0) {
  302. $c_name = substr($add, strlen($prefix));
  303. } else {
  304. $c_name = '';
  305. }
  306. }
  307. $c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8');
  308. $cat = $categoryDAO->searchByName($c_name);
  309. $addCatId = $cat == null ? 0 : $cat->id();
  310. } elseif ($remove != '' && strpos($remove, 'user/-/label/') === 0) {
  311. $addCatId = 1; //Default category
  312. }
  313. $feedDAO = FreshRSS_Factory::createFeedDao();
  314. if (!is_array($streamNames) || count($streamNames) < 1) {
  315. badRequest();
  316. }
  317. for ($i = count($streamNames) - 1; $i >= 0; $i--) {
  318. $streamUrl = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338
  319. if (strpos($streamUrl, 'feed/') === 0) {
  320. $streamUrl = substr($streamUrl, 5);
  321. $feedId = 0;
  322. if (ctype_digit($streamUrl)) {
  323. if ($action === 'subscribe') {
  324. continue;
  325. }
  326. $feedId = $streamUrl;
  327. } else {
  328. $streamUrl = htmlspecialchars($streamUrl, ENT_COMPAT, 'UTF-8');
  329. $feed = $feedDAO->searchByUrl($streamUrl);
  330. $feedId = $feed == null ? -1 : $feed->id();
  331. }
  332. $title = isset($titles[$i]) ? $titles[$i] : '';
  333. $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
  334. switch ($action) {
  335. case 'subscribe':
  336. if ($feedId <= 0) {
  337. $http_auth = '';
  338. try {
  339. $feed = FreshRSS_feed_Controller::addFeed($streamUrl, $title, $addCatId, $c_name, $http_auth);
  340. continue 2;
  341. } catch (Exception $e) {
  342. Minz_Log::error('subscriptionEdit error subscribe: ' . $e->getMessage(), API_LOG);
  343. }
  344. }
  345. badRequest();
  346. break;
  347. case 'unsubscribe':
  348. if (!($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId))) {
  349. badRequest();
  350. }
  351. break;
  352. case 'edit':
  353. if ($feedId > 0) {
  354. if ($addCatId > 0 || $c_name != '') {
  355. FreshRSS_feed_Controller::moveFeed($feedId, $addCatId, $c_name);
  356. }
  357. if ($title != '') {
  358. FreshRSS_feed_Controller::renameFeed($feedId, $title);
  359. }
  360. } else {
  361. badRequest();
  362. }
  363. break;
  364. }
  365. }
  366. }
  367. exit('OK');
  368. }
  369. function quickadd($url) {
  370. try {
  371. $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
  372. $feed = FreshRSS_feed_Controller::addFeed($url);
  373. exit(json_encode(array(
  374. 'numResults' => 1,
  375. 'streamId' => $feed->id(),
  376. ), JSON_OPTIONS));
  377. } catch (Exception $e) {
  378. Minz_Log::error('quickadd error: ' . $e->getMessage(), API_LOG);
  379. die(json_encode(array(
  380. 'numResults' => 0,
  381. 'error' => $e->getMessage(),
  382. ), JSON_OPTIONS));
  383. }
  384. }
  385. function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
  386. header('Content-Type: application/json; charset=UTF-8');
  387. $totalUnreads = 0;
  388. $totalLastUpdate = 0;
  389. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  390. foreach ($categoryDAO->listCategories(true, true) as $cat) {
  391. $catLastUpdate = 0;
  392. foreach ($cat->feeds() as $feed) {
  393. $lastUpdate = $feed->lastUpdate();
  394. $unreadcounts[] = array(
  395. 'id' => 'feed/' . $feed->id(),
  396. 'count' => $feed->nbNotRead(),
  397. 'newestItemTimestampUsec' => $lastUpdate . '000000',
  398. );
  399. if ($catLastUpdate < $lastUpdate) {
  400. $catLastUpdate = $lastUpdate;
  401. }
  402. }
  403. $unreadcounts[] = array(
  404. 'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  405. 'count' => $cat->nbNotRead(),
  406. 'newestItemTimestampUsec' => $catLastUpdate . '000000',
  407. );
  408. $totalUnreads += $cat->nbNotRead();
  409. if ($totalLastUpdate < $catLastUpdate) {
  410. $totalLastUpdate = $catLastUpdate;
  411. }
  412. }
  413. $tagDAO = FreshRSS_Factory::createTagDao();
  414. foreach ($tagDAO->listTags(true) as $label) {
  415. $unreadcounts[] = array(
  416. 'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
  417. 'count' => $label->nbUnread(),
  418. );
  419. }
  420. $unreadcounts[] = array(
  421. 'id' => 'user/-/state/com.google/reading-list',
  422. 'count' => $totalUnreads,
  423. 'newestItemTimestampUsec' => $totalLastUpdate . '000000',
  424. );
  425. echo json_encode(array(
  426. 'max' => $totalUnreads,
  427. 'unreadcounts' => $unreadcounts,
  428. ), JSON_OPTIONS), "\n";
  429. exit();
  430. }
  431. function entriesToArray($entries) {
  432. if (empty($entries)) {
  433. return array();
  434. }
  435. $feedDAO = FreshRSS_Factory::createFeedDao();
  436. $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
  437. $tagDAO = FreshRSS_Factory::createTagDao();
  438. $entryIdsTagNames = $tagDAO->getEntryIdsTagNames($entries);
  439. if ($entryIdsTagNames == false) {
  440. $entryIdsTagNames = array();
  441. }
  442. $items = array();
  443. foreach ($entries as $entry) {
  444. $f_id = $entry->feed();
  445. if (isset($arrayFeedCategoryNames[$f_id])) {
  446. $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
  447. $f_name = $arrayFeedCategoryNames[$f_id]['name'];
  448. } else {
  449. $c_name = '_';
  450. $f_name = '_';
  451. }
  452. $item = array(
  453. 'id' => 'tag:google.com,2005:reader/item/' . dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  454. 'crawlTimeMsec' => substr($entry->id(), 0, -3),
  455. 'timestampUsec' => '' . $entry->id(), //EasyRSS
  456. 'published' => $entry->date(true),
  457. 'title' => escapeToUnicodeAlternative($entry->title(), false),
  458. 'summary' => array('content' => $entry->content()),
  459. 'alternate' => array(
  460. array('href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES)),
  461. ),
  462. 'categories' => array(
  463. 'user/-/state/com.google/reading-list',
  464. 'user/-/label/' . htmlspecialchars_decode($c_name, ENT_QUOTES),
  465. ),
  466. 'origin' => array(
  467. 'streamId' => 'feed/' . $f_id,
  468. 'title' => escapeToUnicodeAlternative($f_name, true), //EasyRSS
  469. //'htmlUrl' => $line['f_website'],
  470. ),
  471. );
  472. $author = $entry->authors(true);
  473. $author = trim($author, '; ');
  474. if ($author != '') {
  475. $item['author'] = escapeToUnicodeAlternative($author, false);
  476. }
  477. if ($entry->isRead()) {
  478. $item['categories'][] = 'user/-/state/com.google/read';
  479. }
  480. if ($entry->isFavorite()) {
  481. $item['categories'][] = 'user/-/state/com.google/starred';
  482. }
  483. $tagNames = isset($entryIdsTagNames['e_' . $entry->id()]) ? $entryIdsTagNames['e_' . $entry->id()] : array();
  484. foreach ($tagNames as $tagName) {
  485. $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($tagName, ENT_QUOTES);
  486. }
  487. $items[] = $item;
  488. }
  489. return $items;
  490. }
  491. function streamContentsFilters($type, $streamId, $filter_target, $exclude_target, $start_time, $stop_time) {
  492. switch ($type) {
  493. case 'f': //feed
  494. if ($streamId != '' && !ctype_digit($streamId)) {
  495. $feedDAO = FreshRSS_Factory::createFeedDao();
  496. $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8');
  497. $feed = $feedDAO->searchByUrl($streamId);
  498. $streamId = $feed == null ? -1 : $feed->id();
  499. }
  500. break;
  501. case 'c': //category or label
  502. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  503. $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8');
  504. $cat = $categoryDAO->searchByName($streamId);
  505. if ($cat != null) {
  506. $type = 'c';
  507. $streamId = $cat->id();
  508. } else {
  509. $tagDAO = FreshRSS_Factory::createTagDao();
  510. $tag = $tagDAO->searchByName($streamId);
  511. if ($tag != null) {
  512. $type = 't';
  513. $streamId = $tag->id();
  514. } else {
  515. $type = 'A';
  516. $streamId = -1;
  517. }
  518. }
  519. break;
  520. }
  521. switch ($filter_target) {
  522. case 'user/-/state/com.google/read':
  523. $state = FreshRSS_Entry::STATE_READ;
  524. break;
  525. case 'user/-/state/com.google/unread':
  526. $state = FreshRSS_Entry::STATE_NOT_READ;
  527. break;
  528. case 'user/-/state/com.google/starred':
  529. $state = FreshRSS_Entry::STATE_FAVORITE;
  530. break;
  531. default:
  532. $state = FreshRSS_Entry::STATE_ALL;
  533. break;
  534. }
  535. switch ($exclude_target) {
  536. case 'user/-/state/com.google/read':
  537. $state &= FreshRSS_Entry::STATE_NOT_READ;
  538. break;
  539. case 'user/-/state/com.google/unread':
  540. $state &= FreshRSS_Entry::STATE_READ;
  541. break;
  542. case 'user/-/state/com.google/starred':
  543. $state &= FreshRSS_Entry::STATE_NOT_FAVORITE;
  544. break;
  545. }
  546. $searches = new FreshRSS_BooleanSearch('');
  547. if ($start_time != '') {
  548. $search = new FreshRSS_Search('');
  549. $search->setMinDate($start_time);
  550. $searches->add($search);
  551. }
  552. if ($stop_time != '') {
  553. $search = new FreshRSS_Search('');
  554. $search->setMaxDate($stop_time);
  555. $searches->add($search);
  556. }
  557. return array($type, $streamId, $state, $searches);
  558. }
  559. function streamContents($path, $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation) {
  560. //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  561. //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  562. header('Content-Type: application/json; charset=UTF-8');
  563. switch ($path) {
  564. case 'reading-list':
  565. $type = 'A';
  566. break;
  567. case 'starred':
  568. $type = 's';
  569. break;
  570. case 'feed':
  571. $type = 'f';
  572. break;
  573. case 'label':
  574. $type = 'c';
  575. break;
  576. default:
  577. $type = 'A';
  578. break;
  579. }
  580. list($type, $include_target, $state, $searches) = streamContentsFilters($type, $include_target, $filter_target, $exclude_target, $start_time, $stop_time);
  581. if ($continuation != '') {
  582. $count++; //Shift by one element
  583. }
  584. $entryDAO = FreshRSS_Factory::createEntryDao();
  585. $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, $searches);
  586. $items = entriesToArray($entries);
  587. if ($continuation != '') {
  588. array_shift($items); //Discard first element that was already sent in the previous response
  589. $count--;
  590. }
  591. $response = array(
  592. 'id' => 'user/-/state/com.google/reading-list',
  593. 'updated' => time(),
  594. 'items' => $items,
  595. );
  596. if (count($entries) >= $count) {
  597. $entry = end($entries);
  598. if ($entry != false) {
  599. $response['continuation'] = $entry->id();
  600. }
  601. }
  602. echo json_encode($response, JSON_OPTIONS), "\n";
  603. exit();
  604. }
  605. function streamContentsItemsIds($streamId, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation) {
  606. //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds
  607. //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  608. //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  609. $type = 'A';
  610. $id = '';
  611. if ($streamId === 'user/-/state/com.google/reading-list') {
  612. $type = 'A';
  613. } elseif ($streamId === 'user/-/state/com.google/starred') {
  614. $type = 's';
  615. } elseif (strpos($streamId, 'feed/') === 0) {
  616. $type = 'f';
  617. $streamId = substr($streamId, 5);
  618. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  619. $type = 'c';
  620. $streamId = substr($streamId, 13);
  621. }
  622. list($type, $id, $state, $searches) = streamContentsFilters($type, $streamId, $filter_target, $exclude_target, $start_time, $stop_time);
  623. if ($continuation != '') {
  624. $count++; //Shift by one element
  625. }
  626. $entryDAO = FreshRSS_Factory::createEntryDao();
  627. $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, $searches);
  628. if ($continuation != '') {
  629. array_shift($ids); //Discard first element that was already sent in the previous response
  630. $count--;
  631. }
  632. if (empty($ids) && isset($_GET['client']) && $_GET['client'] === 'newsplus') {
  633. $ids[] = 0; //For News+ bug https://github.com/noinnion/newsplus/issues/84#issuecomment-57834632
  634. }
  635. $itemRefs = array();
  636. foreach ($ids as $id) {
  637. $itemRefs[] = array(
  638. 'id' => $id, //64-bit decimal
  639. );
  640. }
  641. $response = array(
  642. 'itemRefs' => $itemRefs,
  643. );
  644. if (count($ids) >= $count) {
  645. $id = end($ids);
  646. if ($id != false) {
  647. $response['continuation'] = $id;
  648. }
  649. }
  650. echo json_encode($response, JSON_OPTIONS), "\n";
  651. exit();
  652. }
  653. function streamContentsItems($e_ids, $order) {
  654. header('Content-Type: application/json; charset=UTF-8');
  655. foreach ($e_ids as $i => $e_id) {
  656. if (strpos($e_id, '/') !== null) {
  657. $e_id = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  658. }
  659. $e_ids[$i] = $e_id;
  660. }
  661. $entryDAO = FreshRSS_Factory::createEntryDao();
  662. $entries = $entryDAO->listByIds($e_ids, $order === 'o' ? 'ASC' : 'DESC');
  663. $items = entriesToArray($entries);
  664. $response = array(
  665. 'id' => 'user/-/state/com.google/reading-list',
  666. 'updated' => time(),
  667. 'items' => $items,
  668. );
  669. echo json_encode($response, JSON_OPTIONS), "\n";
  670. exit();
  671. }
  672. function editTag($e_ids, $a, $r) {
  673. foreach ($e_ids as $i => $e_id) {
  674. if (strpos($e_id, '/') !== null) {
  675. $e_id = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  676. }
  677. $e_ids[$i] = $e_id;
  678. }
  679. $entryDAO = FreshRSS_Factory::createEntryDao();
  680. $tagDAO = FreshRSS_Factory::createTagDao();
  681. switch ($a) {
  682. case 'user/-/state/com.google/read':
  683. $entryDAO->markRead($e_ids, true);
  684. break;
  685. case 'user/-/state/com.google/starred':
  686. $entryDAO->markFavorite($e_ids, true);
  687. break;
  688. /*case 'user/-/state/com.google/tracking-kept-unread':
  689. break;
  690. case 'user/-/state/com.google/like':
  691. break;
  692. case 'user/-/state/com.google/broadcast':
  693. break;*/
  694. default:
  695. $tagName = '';
  696. if (strpos($a, 'user/-/label/') === 0) {
  697. $tagName = substr($a, 13);
  698. } else {
  699. $user = Minz_Session::param('currentUser', '_');
  700. $prefix = 'user/' . $user . '/label/';
  701. if (strpos($a, $prefix) === 0) {
  702. $tagName = substr($a, strlen($prefix));
  703. }
  704. }
  705. if ($tagName != '') {
  706. $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
  707. $tag = $tagDAO->searchByName($tagName);
  708. if ($tag == null) {
  709. $tagDAO->addTag(array('name' => $tagName));
  710. $tag = $tagDAO->searchByName($tagName);
  711. }
  712. if ($tag != null) {
  713. foreach ($e_ids as $e_id) {
  714. $tagDAO->tagEntry($tag->id(), $e_id, true);
  715. }
  716. }
  717. }
  718. break;
  719. }
  720. switch ($r) {
  721. case 'user/-/state/com.google/read':
  722. $entryDAO->markRead($e_ids, false);
  723. break;
  724. case 'user/-/state/com.google/starred':
  725. $entryDAO->markFavorite($e_ids, false);
  726. break;
  727. default:
  728. if (strpos($r, 'user/-/label/') === 0) {
  729. $tagName = substr($r, 13);
  730. $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
  731. $tag = $tagDAO->searchByName($tagName);
  732. if ($tag != null) {
  733. foreach ($e_ids as $e_id) {
  734. $tagDAO->tagEntry($tag->id(), $e_id, false);
  735. }
  736. }
  737. }
  738. break;
  739. }
  740. exit('OK');
  741. }
  742. function renameTag($s, $dest) {
  743. if ($s != '' && strpos($s, 'user/-/label/') === 0 &&
  744. $dest != '' && strpos($dest, 'user/-/label/') === 0) {
  745. $s = substr($s, 13);
  746. $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
  747. $dest = substr($dest, 13);
  748. $dest = htmlspecialchars($dest, ENT_COMPAT, 'UTF-8');
  749. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  750. $cat = $categoryDAO->searchByName($s);
  751. if ($cat != null) {
  752. $categoryDAO->updateCategory($cat->id(), array('name' => $dest));
  753. exit('OK');
  754. } else {
  755. $tagDAO = FreshRSS_Factory::createTagDao();
  756. $tag = $tagDAO->searchByName($s);
  757. if ($tag != null) {
  758. $tagDAO->updateTag($tag->id(), array('name' => $dest));
  759. exit('OK');
  760. }
  761. }
  762. }
  763. badRequest();
  764. }
  765. function disableTag($s) {
  766. if ($s != '' && strpos($s, 'user/-/label/') === 0) {
  767. $s = substr($s, 13);
  768. $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
  769. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  770. $cat = $categoryDAO->searchByName($s);
  771. if ($cat != null) {
  772. $feedDAO = FreshRSS_Factory::createFeedDao();
  773. $feedDAO->changeCategory($cat->id(), 0);
  774. if ($cat->id() > 1) {
  775. $categoryDAO->deleteCategory($cat->id());
  776. }
  777. exit('OK');
  778. } else {
  779. $tagDAO = FreshRSS_Factory::createTagDao();
  780. $tag = $tagDAO->searchByName($s);
  781. if ($tag != null) {
  782. $tagDAO->deleteTag($tag->id());
  783. exit('OK');
  784. }
  785. }
  786. }
  787. badRequest();
  788. }
  789. function markAllAsRead($streamId, $olderThanId) {
  790. $entryDAO = FreshRSS_Factory::createEntryDao();
  791. if (strpos($streamId, 'feed/') === 0) {
  792. $f_id = basename($streamId);
  793. $entryDAO->markReadFeed($f_id, $olderThanId);
  794. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  795. $c_name = substr($streamId, 13);
  796. $c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8');
  797. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  798. $cat = $categoryDAO->searchByName($c_name);
  799. if ($cat != null) {
  800. $entryDAO->markReadCat($cat->id(), $olderThanId);
  801. } else {
  802. $tagDAO = FreshRSS_Factory::createTagDao();
  803. $tag = $tagDAO->searchByName($c_name);
  804. if ($tag != null) {
  805. $entryDAO->markReadTag($tag->id(), $olderThanId);
  806. }
  807. }
  808. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  809. $entryDAO->markReadEntries($olderThanId, false, -1);
  810. }
  811. exit('OK');
  812. }
  813. $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
  814. $pathInfos = explode('/', $pathInfo);
  815. Minz_Configuration::register('system',
  816. DATA_PATH . '/config.php',
  817. FRESHRSS_PATH . '/config.default.php');
  818. FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
  819. //Minz_Log::debug('----------------------------------------------------------------', API_LOG);
  820. //Minz_Log::debug(debugInfo(), API_LOG);
  821. if (!FreshRSS_Context::$system_conf->api_enabled) {
  822. serviceUnavailable();
  823. } elseif (count($pathInfos) < 3) {
  824. badRequest();
  825. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  826. checkCompatibility();
  827. }
  828. ini_set('session.use_cookies', '0');
  829. register_shutdown_function('session_destroy');
  830. Minz_Session::init('FreshRSS');
  831. $user = authorizationToUser();
  832. FreshRSS_Context::$user_conf = null;
  833. if ($user !== '') {
  834. FreshRSS_Context::$user_conf = get_user_configuration($user);
  835. }
  836. Minz_Session::_param('currentUser', $user);
  837. if ($pathInfos[1] === 'accounts') {
  838. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  839. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  840. }
  841. } elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  842. if ($user == '') {
  843. unauthorized();
  844. }
  845. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  846. switch ($pathInfos[4]) {
  847. case 'stream':
  848. /* xt=[exclude target] : Used to exclude certain items from the feed.
  849. * For example, using xt=user/-/state/com.google/read will exclude items
  850. * that the current user has marked as read, or xt=feed/[feedurl] will
  851. * exclude items from a particular feed (obviously not useful in this
  852. * request, but xt appears in other listing requests). */
  853. $exclude_target = isset($_GET['xt']) ? $_GET['xt'] : '';
  854. $filter_target = isset($_GET['it']) ? $_GET['it'] : '';
  855. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  856. $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.
  857. /* ot=[unix timestamp] : The time from which you want to retrieve
  858. * items. Only items that have been crawled by Google Reader after
  859. * this time will be returned. */
  860. $start_time = isset($_GET['ot']) ? intval($_GET['ot']) : 0;
  861. $stop_time = isset($_GET['nt']) ? intval($_GET['nt']) : 0;
  862. /* Continuation token. If a StreamContents response does not represent
  863. * all items in a timestamp range, it will have a continuation attribute.
  864. * The same request can be re-issued with the value of that attribute put
  865. * in this parameter to get more items */
  866. $continuation = isset($_GET['c']) ? trim($_GET['c']) : '';
  867. if (!ctype_digit($continuation)) {
  868. $continuation = '';
  869. }
  870. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  871. if (isset($pathInfos[7])) {
  872. if ($pathInfos[6] === 'feed') {
  873. $include_target = $pathInfos[7];
  874. if ($include_target != '' && !ctype_digit($include_target)) {
  875. $include_target = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  876. if (preg_match('#/reader/api/0/stream/contents/feed/([A-Za-z0-9\'!*()%$_.~+-]+)#', $include_target, $matches) && isset($matches[1])) {
  877. $include_target = urldecode($matches[1]);
  878. } else {
  879. $include_target = '';
  880. }
  881. }
  882. streamContents($pathInfos[6], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  883. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  884. if ($pathInfos[8] === 'state') {
  885. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  886. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  887. $include_target = '';
  888. streamContents($pathInfos[10], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  889. }
  890. }
  891. } elseif ($pathInfos[8] === 'label') {
  892. $include_target = $pathInfos[9];
  893. streamContents($pathInfos[8], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  894. }
  895. }
  896. } else { //EasyRSS
  897. $include_target = '';
  898. streamContents('reading-list', $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  899. }
  900. } elseif ($pathInfos[5] === 'items') {
  901. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  902. /* StreamId for which to fetch the item IDs. The parameter may
  903. * be repeated to fetch the item IDs from multiple streams at once
  904. * (more efficient from a backend perspective than multiple requests). */
  905. $streamId = $_GET['s'];
  906. streamContentsItemsIds($streamId, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  907. } elseif ($pathInfos[6] === 'contents' && isset($_POST['i'])) { //FeedMe
  908. $e_ids = multiplePosts('i'); //item IDs
  909. streamContentsItems($e_ids, $order);
  910. }
  911. }
  912. break;
  913. case 'tag':
  914. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  915. $output = isset($_GET['output']) ? $_GET['output'] : '';
  916. if ($output !== 'json') notImplemented();
  917. tagList($output);
  918. }
  919. break;
  920. case 'subscription':
  921. if (isset($pathInfos[5])) {
  922. switch ($pathInfos[5]) {
  923. case 'list':
  924. $output = isset($_GET['output']) ? $_GET['output'] : '';
  925. if ($output !== 'json') notImplemented();
  926. subscriptionList($_GET['output']);
  927. break;
  928. case 'edit':
  929. if (isset($_REQUEST['s']) && isset($_REQUEST['ac'])) {
  930. //StreamId to operate on. The parameter may be repeated to edit multiple subscriptions at once
  931. $streamNames = empty($_POST['s']) && isset($_GET['s']) ? array($_GET['s']) : multiplePosts('s');
  932. /* Title to use for the subscription. For the `subscribe` action,
  933. * if not specified then the feed's current title will be used. Can
  934. * be used with the `edit` action to rename a subscription */
  935. $titles = empty($_POST['t']) && isset($_GET['t']) ? array($_GET['t']) : multiplePosts('t');
  936. $action = $_REQUEST['ac']; //Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit`
  937. $add = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; //StreamId to add the subscription to (generally a user label)
  938. $remove = isset($_REQUEST['r']) ? $_REQUEST['r'] : ''; //StreamId to remove the subscription from (generally a user label)
  939. subscriptionEdit($streamNames, $titles, $action, $add, $remove);
  940. }
  941. break;
  942. case 'quickadd': //https://github.com/theoldreader/api
  943. if (isset($_GET['quickadd'])) {
  944. quickadd($_GET['quickadd']);
  945. }
  946. break;
  947. }
  948. }
  949. break;
  950. case 'unread-count':
  951. $output = isset($_GET['output']) ? $_GET['output'] : '';
  952. if ($output !== 'json') notImplemented();
  953. $all = isset($_GET['all']) ? $_GET['all'] : '';
  954. unreadCount($all);
  955. break;
  956. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  957. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  958. checkToken(FreshRSS_Context::$user_conf, $token);
  959. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  960. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  961. $e_ids = multiplePosts('i'); //item IDs
  962. editTag($e_ids, $a, $r);
  963. break;
  964. case 'rename-tag': //https://github.com/theoldreader/api
  965. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  966. checkToken(FreshRSS_Context::$user_conf, $token);
  967. $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder
  968. $dest = isset($_POST['dest']) ? $_POST['dest'] : ''; //user/-/label/NewFolder
  969. renameTag($s, $dest);
  970. break;
  971. case 'disable-tag': //https://github.com/theoldreader/api
  972. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  973. checkToken(FreshRSS_Context::$user_conf, $token);
  974. $s_s = multiplePosts('s');
  975. foreach ($s_s as $s) {
  976. disableTag($s); //user/-/label/Folder
  977. }
  978. break;
  979. case 'mark-all-as-read':
  980. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  981. checkToken(FreshRSS_Context::$user_conf, $token);
  982. $streamId = $_POST['s']; //StreamId
  983. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  984. if (!ctype_digit($ts)) {
  985. $ts = '0';
  986. }
  987. markAllAsRead($streamId, $ts);
  988. break;
  989. case 'token':
  990. token(FreshRSS_Context::$user_conf);
  991. break;
  992. case 'user-info':
  993. userInfo();
  994. break;
  995. }
  996. }
  997. badRequest();