greader.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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']) ? '' : urldecode($_SERVER['PATH_INFO']);
  810. if ($pathInfo == '') {
  811. exit('OK');
  812. }
  813. $pathInfos = explode('/', $pathInfo);
  814. if (count($pathInfos) < 3) {
  815. badRequest();
  816. }
  817. Minz_Configuration::register('system',
  818. DATA_PATH . '/config.php',
  819. FRESHRSS_PATH . '/config.default.php');
  820. FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
  821. //Minz_Log::debug('----------------------------------------------------------------', API_LOG);
  822. //Minz_Log::debug(debugInfo(), API_LOG);
  823. if (!FreshRSS_Context::$system_conf->api_enabled) {
  824. serviceUnavailable();
  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. Minz_ExtensionManager::init();
  836. Minz_Translate::init(FreshRSS_Context::$user_conf->language);
  837. if (FreshRSS_Context::$user_conf != null) {
  838. Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled);
  839. }
  840. } else {
  841. Minz_Translate::init();
  842. }
  843. Minz_Session::_param('currentUser', $user);
  844. if ($pathInfos[1] === 'accounts') {
  845. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  846. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  847. }
  848. } elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  849. if ($user == '') {
  850. unauthorized();
  851. }
  852. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  853. switch ($pathInfos[4]) {
  854. case 'stream':
  855. /* xt=[exclude target] : Used to exclude certain items from the feed.
  856. * For example, using xt=user/-/state/com.google/read will exclude items
  857. * that the current user has marked as read, or xt=feed/[feedurl] will
  858. * exclude items from a particular feed (obviously not useful in this
  859. * request, but xt appears in other listing requests). */
  860. $exclude_target = isset($_GET['xt']) ? $_GET['xt'] : '';
  861. $filter_target = isset($_GET['it']) ? $_GET['it'] : '';
  862. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  863. $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.
  864. /* ot=[unix timestamp] : The time from which you want to retrieve
  865. * items. Only items that have been crawled by Google Reader after
  866. * this time will be returned. */
  867. $start_time = isset($_GET['ot']) ? intval($_GET['ot']) : 0;
  868. $stop_time = isset($_GET['nt']) ? intval($_GET['nt']) : 0;
  869. /* Continuation token. If a StreamContents response does not represent
  870. * all items in a timestamp range, it will have a continuation attribute.
  871. * The same request can be re-issued with the value of that attribute put
  872. * in this parameter to get more items */
  873. $continuation = isset($_GET['c']) ? trim($_GET['c']) : '';
  874. if (!ctype_digit($continuation)) {
  875. $continuation = '';
  876. }
  877. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  878. if (isset($pathInfos[7])) {
  879. if ($pathInfos[6] === 'feed') {
  880. $include_target = $pathInfos[7];
  881. if ($include_target != '' && !ctype_digit($include_target)) {
  882. $include_target = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  883. if (preg_match('#/reader/api/0/stream/contents/feed/([A-Za-z0-9\'!*()%$_.~+-]+)#', $include_target, $matches) && isset($matches[1])) {
  884. $include_target = urldecode($matches[1]);
  885. } else {
  886. $include_target = '';
  887. }
  888. }
  889. streamContents($pathInfos[6], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  890. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  891. if ($pathInfos[8] === 'state') {
  892. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  893. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  894. $include_target = '';
  895. streamContents($pathInfos[10], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  896. }
  897. }
  898. } elseif ($pathInfos[8] === 'label') {
  899. $include_target = $pathInfos[9];
  900. streamContents($pathInfos[8], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  901. }
  902. }
  903. } else { //EasyRSS
  904. $include_target = '';
  905. streamContents('reading-list', $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  906. }
  907. } elseif ($pathInfos[5] === 'items') {
  908. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  909. /* StreamId for which to fetch the item IDs. The parameter may
  910. * be repeated to fetch the item IDs from multiple streams at once
  911. * (more efficient from a backend perspective than multiple requests). */
  912. $streamId = $_GET['s'];
  913. streamContentsItemsIds($streamId, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  914. } elseif ($pathInfos[6] === 'contents' && isset($_POST['i'])) { //FeedMe
  915. $e_ids = multiplePosts('i'); //item IDs
  916. streamContentsItems($e_ids, $order);
  917. }
  918. }
  919. break;
  920. case 'tag':
  921. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  922. $output = isset($_GET['output']) ? $_GET['output'] : '';
  923. if ($output !== 'json') notImplemented();
  924. tagList();
  925. }
  926. break;
  927. case 'subscription':
  928. if (isset($pathInfos[5])) {
  929. switch ($pathInfos[5]) {
  930. case 'list':
  931. $output = isset($_GET['output']) ? $_GET['output'] : '';
  932. if ($output !== 'json') notImplemented();
  933. subscriptionList();
  934. break;
  935. case 'edit':
  936. if (isset($_REQUEST['s']) && isset($_REQUEST['ac'])) {
  937. //StreamId to operate on. The parameter may be repeated to edit multiple subscriptions at once
  938. $streamNames = empty($_POST['s']) && isset($_GET['s']) ? array($_GET['s']) : multiplePosts('s');
  939. /* Title to use for the subscription. For the `subscribe` action,
  940. * if not specified then the feed's current title will be used. Can
  941. * be used with the `edit` action to rename a subscription */
  942. $titles = empty($_POST['t']) && isset($_GET['t']) ? array($_GET['t']) : multiplePosts('t');
  943. $action = $_REQUEST['ac']; //Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit`
  944. $add = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; //StreamId to add the subscription to (generally a user label)
  945. $remove = isset($_REQUEST['r']) ? $_REQUEST['r'] : ''; //StreamId to remove the subscription from (generally a user label)
  946. subscriptionEdit($streamNames, $titles, $action, $add, $remove);
  947. }
  948. break;
  949. case 'quickadd': //https://github.com/theoldreader/api
  950. if (isset($_GET['quickadd'])) {
  951. quickadd($_GET['quickadd']);
  952. }
  953. break;
  954. }
  955. }
  956. break;
  957. case 'unread-count':
  958. $output = isset($_GET['output']) ? $_GET['output'] : '';
  959. if ($output !== 'json') notImplemented();
  960. $all = isset($_GET['all']) ? $_GET['all'] : '';
  961. unreadCount($all);
  962. break;
  963. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  964. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  965. checkToken(FreshRSS_Context::$user_conf, $token);
  966. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  967. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  968. $e_ids = multiplePosts('i'); //item IDs
  969. editTag($e_ids, $a, $r);
  970. break;
  971. case 'rename-tag': //https://github.com/theoldreader/api
  972. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  973. checkToken(FreshRSS_Context::$user_conf, $token);
  974. $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder
  975. $dest = isset($_POST['dest']) ? $_POST['dest'] : ''; //user/-/label/NewFolder
  976. renameTag($s, $dest);
  977. break;
  978. case 'disable-tag': //https://github.com/theoldreader/api
  979. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  980. checkToken(FreshRSS_Context::$user_conf, $token);
  981. $s_s = multiplePosts('s');
  982. foreach ($s_s as $s) {
  983. disableTag($s); //user/-/label/Folder
  984. }
  985. break;
  986. case 'mark-all-as-read':
  987. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  988. checkToken(FreshRSS_Context::$user_conf, $token);
  989. $streamId = $_POST['s']; //StreamId
  990. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  991. if (!ctype_digit($ts)) {
  992. $ts = '0';
  993. }
  994. markAllAsRead($streamId, $ts);
  995. break;
  996. case 'token':
  997. token(FreshRSS_Context::$user_conf);
  998. break;
  999. case 'user-info':
  1000. userInfo();
  1001. break;
  1002. }
  1003. }
  1004. badRequest();