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