4
0

greader.php 35 KB

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