greader.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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. $feedDAO = FreshRSS_Factory::createFeedDao();
  381. $feedsNewestItemUsec = $feedDAO->listFeedsNewestItemUsec();
  382. foreach ($categoryDAO->listCategories(true, true) as $cat) {
  383. $catLastUpdate = 0;
  384. foreach ($cat->feeds() as $feed) {
  385. $lastUpdate = isset($feedsNewestItemUsec['f_' . $feed->id()]) ? $feedsNewestItemUsec['f_' . $feed->id()] : 0;
  386. $unreadcounts[] = array(
  387. 'id' => 'feed/' . $feed->id(),
  388. 'count' => $feed->nbNotRead(),
  389. 'newestItemTimestampUsec' => $lastUpdate,
  390. );
  391. if ($catLastUpdate < $lastUpdate) {
  392. $catLastUpdate = $lastUpdate;
  393. }
  394. }
  395. $unreadcounts[] = array(
  396. 'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
  397. 'count' => $cat->nbNotRead(),
  398. 'newestItemTimestampUsec' => $catLastUpdate,
  399. );
  400. $totalUnreads += $cat->nbNotRead();
  401. if ($totalLastUpdate < $catLastUpdate) {
  402. $totalLastUpdate = $catLastUpdate;
  403. }
  404. }
  405. $tagDAO = FreshRSS_Factory::createTagDao();
  406. $tagsNewestItemUsec = $tagDAO->listTagsNewestItemUsec();
  407. foreach ($tagDAO->listTags(true) as $label) {
  408. $lastUpdate = isset($tagsNewestItemUsec['t_' . $label->id()]) ? $tagsNewestItemUsec['t_' . $label->id()] : 0;
  409. $unreadcounts[] = array(
  410. 'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
  411. 'count' => $label->nbUnread(),
  412. 'newestItemTimestampUsec' => $lastUpdate,
  413. );
  414. }
  415. $unreadcounts[] = array(
  416. 'id' => 'user/-/state/com.google/reading-list',
  417. 'count' => $totalUnreads,
  418. 'newestItemTimestampUsec' => $totalLastUpdate,
  419. );
  420. echo json_encode(array(
  421. 'max' => $totalUnreads,
  422. 'unreadcounts' => $unreadcounts,
  423. ), JSON_OPTIONS), "\n";
  424. exit();
  425. }
  426. function entriesToArray($entries) {
  427. if (empty($entries)) {
  428. return array();
  429. }
  430. $feedDAO = FreshRSS_Factory::createFeedDao();
  431. $arrayFeedCategoryNames = $feedDAO->arrayFeedCategoryNames();
  432. $tagDAO = FreshRSS_Factory::createTagDao();
  433. $entryIdsTagNames = $tagDAO->getEntryIdsTagNames($entries);
  434. if ($entryIdsTagNames == false) {
  435. $entryIdsTagNames = array();
  436. }
  437. $items = array();
  438. foreach ($entries as $item) {
  439. $entry = Minz_ExtensionManager::callHook('entry_before_display', $item);
  440. if ($entry == null) {
  441. continue;
  442. }
  443. $f_id = $entry->feed();
  444. if (isset($arrayFeedCategoryNames[$f_id])) {
  445. $c_name = $arrayFeedCategoryNames[$f_id]['c_name'];
  446. $f_name = $arrayFeedCategoryNames[$f_id]['name'];
  447. } else {
  448. $c_name = '_';
  449. $f_name = '_';
  450. }
  451. $item = array(
  452. 'id' => 'tag:google.com,2005:reader/item/' . dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  453. 'crawlTimeMsec' => substr($entry->dateAdded(true, true), 0, -3),
  454. 'timestampUsec' => '' . $entry->dateAdded(true, true), //EasyRSS & Reeder
  455. 'published' => $entry->date(true),
  456. 'title' => escapeToUnicodeAlternative($entry->title(), false),
  457. 'summary' => array('content' => $entry->content()),
  458. 'alternate' => array(
  459. array('href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES)),
  460. ),
  461. 'categories' => array(
  462. 'user/-/state/com.google/reading-list',
  463. 'user/-/label/' . htmlspecialchars_decode($c_name, ENT_QUOTES),
  464. ),
  465. 'origin' => array(
  466. 'streamId' => 'feed/' . $f_id,
  467. 'title' => escapeToUnicodeAlternative($f_name, true), //EasyRSS
  468. //'htmlUrl' => $line['f_website'],
  469. ),
  470. );
  471. $author = $entry->authors(true);
  472. $author = trim($author, '; ');
  473. if ($author != '') {
  474. $item['author'] = escapeToUnicodeAlternative($author, false);
  475. }
  476. if ($entry->isRead()) {
  477. $item['categories'][] = 'user/-/state/com.google/read';
  478. }
  479. if ($entry->isFavorite()) {
  480. $item['categories'][] = 'user/-/state/com.google/starred';
  481. }
  482. $tagNames = isset($entryIdsTagNames['e_' . $entry->id()]) ? $entryIdsTagNames['e_' . $entry->id()] : array();
  483. foreach ($tagNames as $tagName) {
  484. $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($tagName, ENT_QUOTES);
  485. }
  486. $items[] = $item;
  487. }
  488. return $items;
  489. }
  490. function streamContentsFilters($type, $streamId, $filter_target, $exclude_target, $start_time, $stop_time) {
  491. switch ($type) {
  492. case 'f': //feed
  493. if ($streamId != '' && !ctype_digit($streamId)) {
  494. $feedDAO = FreshRSS_Factory::createFeedDao();
  495. $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8');
  496. $feed = $feedDAO->searchByUrl($streamId);
  497. $streamId = $feed == null ? -1 : $feed->id();
  498. }
  499. break;
  500. case 'c': //category or label
  501. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  502. $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8');
  503. $cat = $categoryDAO->searchByName($streamId);
  504. if ($cat != null) {
  505. $type = 'c';
  506. $streamId = $cat->id();
  507. } else {
  508. $tagDAO = FreshRSS_Factory::createTagDao();
  509. $tag = $tagDAO->searchByName($streamId);
  510. if ($tag != null) {
  511. $type = 't';
  512. $streamId = $tag->id();
  513. } else {
  514. $type = 'A';
  515. $streamId = -1;
  516. }
  517. }
  518. break;
  519. }
  520. switch ($filter_target) {
  521. case 'user/-/state/com.google/read':
  522. $state = FreshRSS_Entry::STATE_READ;
  523. break;
  524. case 'user/-/state/com.google/unread':
  525. $state = FreshRSS_Entry::STATE_NOT_READ;
  526. break;
  527. case 'user/-/state/com.google/starred':
  528. $state = FreshRSS_Entry::STATE_FAVORITE;
  529. break;
  530. default:
  531. $state = FreshRSS_Entry::STATE_ALL;
  532. break;
  533. }
  534. switch ($exclude_target) {
  535. case 'user/-/state/com.google/read':
  536. $state &= FreshRSS_Entry::STATE_NOT_READ;
  537. break;
  538. case 'user/-/state/com.google/unread':
  539. $state &= FreshRSS_Entry::STATE_READ;
  540. break;
  541. case 'user/-/state/com.google/starred':
  542. $state &= FreshRSS_Entry::STATE_NOT_FAVORITE;
  543. break;
  544. }
  545. $searches = new FreshRSS_BooleanSearch('');
  546. if ($start_time != '') {
  547. $search = new FreshRSS_Search('');
  548. $search->setMinDate($start_time);
  549. $searches->add($search);
  550. }
  551. if ($stop_time != '') {
  552. $search = new FreshRSS_Search('');
  553. $search->setMaxDate($stop_time);
  554. $searches->add($search);
  555. }
  556. return array($type, $streamId, $state, $searches);
  557. }
  558. function streamContents($path, $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation) {
  559. //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  560. //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  561. header('Content-Type: application/json; charset=UTF-8');
  562. switch ($path) {
  563. case 'reading-list':
  564. $type = 'A';
  565. break;
  566. case 'starred':
  567. $type = 's';
  568. break;
  569. case 'feed':
  570. $type = 'f';
  571. break;
  572. case 'label':
  573. $type = 'c';
  574. break;
  575. default:
  576. $type = 'A';
  577. break;
  578. }
  579. list($type, $include_target, $state, $searches) = streamContentsFilters($type, $include_target, $filter_target, $exclude_target, $start_time, $stop_time);
  580. if ($continuation != '') {
  581. $count++; //Shift by one element
  582. }
  583. $entryDAO = FreshRSS_Factory::createEntryDao();
  584. $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, $searches);
  585. $entries = iterator_to_array($entries); //TODO: Improve
  586. $items = entriesToArray($entries);
  587. if ($continuation != '') {
  588. array_shift($items); //Discard first element that was already sent in the previous response
  589. $count--;
  590. }
  591. $response = array(
  592. 'id' => 'user/-/state/com.google/reading-list',
  593. 'updated' => time(),
  594. 'items' => $items,
  595. );
  596. if (count($entries) >= $count) {
  597. $entry = end($entries);
  598. if ($entry != false) {
  599. $response['continuation'] = $entry->id();
  600. }
  601. }
  602. echo json_encode($response, JSON_OPTIONS), "\n";
  603. exit();
  604. }
  605. function streamContentsItemsIds($streamId, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation) {
  606. //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds
  607. //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  608. //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
  609. $type = 'A';
  610. $id = '';
  611. if ($streamId === 'user/-/state/com.google/reading-list') {
  612. $type = 'A';
  613. } elseif ($streamId === 'user/-/state/com.google/starred') {
  614. $type = 's';
  615. } elseif (strpos($streamId, 'feed/') === 0) {
  616. $type = 'f';
  617. $streamId = substr($streamId, 5);
  618. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  619. $type = 'c';
  620. $streamId = substr($streamId, 13);
  621. }
  622. list($type, $id, $state, $searches) = streamContentsFilters($type, $streamId, $filter_target, $exclude_target, $start_time, $stop_time);
  623. if ($continuation != '') {
  624. $count++; //Shift by one element
  625. }
  626. $entryDAO = FreshRSS_Factory::createEntryDao();
  627. $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, $searches);
  628. if ($continuation != '') {
  629. array_shift($ids); //Discard first element that was already sent in the previous response
  630. $count--;
  631. }
  632. if (empty($ids) && isset($_GET['client']) && $_GET['client'] === 'newsplus') {
  633. $ids[] = 0; //For News+ bug https://github.com/noinnion/newsplus/issues/84#issuecomment-57834632
  634. }
  635. $itemRefs = array();
  636. foreach ($ids as $id) {
  637. $itemRefs[] = array(
  638. 'id' => '' . $id, //64-bit decimal
  639. );
  640. }
  641. $response = array(
  642. 'itemRefs' => $itemRefs,
  643. );
  644. if (count($ids) >= $count) {
  645. $id = end($ids);
  646. if ($id != false) {
  647. $response['continuation'] = $id;
  648. }
  649. }
  650. echo json_encode($response, JSON_OPTIONS), "\n";
  651. exit();
  652. }
  653. function streamContentsItems($e_ids, $order) {
  654. header('Content-Type: application/json; charset=UTF-8');
  655. foreach ($e_ids as $i => $e_id) {
  656. if (strpos($e_id, '/') !== null) {
  657. $e_id = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  658. }
  659. $e_ids[$i] = $e_id;
  660. }
  661. $entryDAO = FreshRSS_Factory::createEntryDao();
  662. $entries = $entryDAO->listByIds($e_ids, $order === 'o' ? 'ASC' : 'DESC');
  663. $entries = iterator_to_array($entries); //TODO: Improve
  664. $items = entriesToArray($entries);
  665. $response = array(
  666. 'id' => 'user/-/state/com.google/reading-list',
  667. 'updated' => time(),
  668. 'items' => $items,
  669. );
  670. echo json_encode($response, JSON_OPTIONS), "\n";
  671. exit();
  672. }
  673. function editTag($e_ids, $a, $r) {
  674. foreach ($e_ids as $i => $e_id) {
  675. if (strpos($e_id, '/') !== null) {
  676. $e_id = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
  677. }
  678. $e_ids[$i] = $e_id;
  679. }
  680. $entryDAO = FreshRSS_Factory::createEntryDao();
  681. $tagDAO = FreshRSS_Factory::createTagDao();
  682. switch ($a) {
  683. case 'user/-/state/com.google/read':
  684. $entryDAO->markRead($e_ids, true);
  685. break;
  686. case 'user/-/state/com.google/starred':
  687. $entryDAO->markFavorite($e_ids, true);
  688. break;
  689. /*case 'user/-/state/com.google/tracking-kept-unread':
  690. break;
  691. case 'user/-/state/com.google/like':
  692. break;
  693. case 'user/-/state/com.google/broadcast':
  694. break;*/
  695. default:
  696. $tagName = '';
  697. if (strpos($a, 'user/-/label/') === 0) {
  698. $tagName = substr($a, 13);
  699. } else {
  700. $user = Minz_Session::param('currentUser', '_');
  701. $prefix = 'user/' . $user . '/label/';
  702. if (strpos($a, $prefix) === 0) {
  703. $tagName = substr($a, strlen($prefix));
  704. }
  705. }
  706. if ($tagName != '') {
  707. $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
  708. $tag = $tagDAO->searchByName($tagName);
  709. if ($tag == null) {
  710. $tagDAO->addTag(array('name' => $tagName));
  711. $tag = $tagDAO->searchByName($tagName);
  712. }
  713. if ($tag != null) {
  714. foreach ($e_ids as $e_id) {
  715. $tagDAO->tagEntry($tag->id(), $e_id, true);
  716. }
  717. }
  718. }
  719. break;
  720. }
  721. switch ($r) {
  722. case 'user/-/state/com.google/read':
  723. $entryDAO->markRead($e_ids, false);
  724. break;
  725. case 'user/-/state/com.google/starred':
  726. $entryDAO->markFavorite($e_ids, false);
  727. break;
  728. default:
  729. if (strpos($r, 'user/-/label/') === 0) {
  730. $tagName = substr($r, 13);
  731. $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
  732. $tag = $tagDAO->searchByName($tagName);
  733. if ($tag != null) {
  734. foreach ($e_ids as $e_id) {
  735. $tagDAO->tagEntry($tag->id(), $e_id, false);
  736. }
  737. }
  738. }
  739. break;
  740. }
  741. exit('OK');
  742. }
  743. function renameTag($s, $dest) {
  744. if ($s != '' && strpos($s, 'user/-/label/') === 0 &&
  745. $dest != '' && strpos($dest, 'user/-/label/') === 0) {
  746. $s = substr($s, 13);
  747. $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
  748. $dest = substr($dest, 13);
  749. $dest = htmlspecialchars($dest, ENT_COMPAT, 'UTF-8');
  750. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  751. $cat = $categoryDAO->searchByName($s);
  752. if ($cat != null) {
  753. $categoryDAO->updateCategory($cat->id(), array('name' => $dest));
  754. exit('OK');
  755. } else {
  756. $tagDAO = FreshRSS_Factory::createTagDao();
  757. $tag = $tagDAO->searchByName($s);
  758. if ($tag != null) {
  759. $tagDAO->updateTag($tag->id(), array('name' => $dest));
  760. exit('OK');
  761. }
  762. }
  763. }
  764. badRequest();
  765. }
  766. function disableTag($s) {
  767. if ($s != '' && strpos($s, 'user/-/label/') === 0) {
  768. $s = substr($s, 13);
  769. $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
  770. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  771. $cat = $categoryDAO->searchByName($s);
  772. if ($cat != null) {
  773. $feedDAO = FreshRSS_Factory::createFeedDao();
  774. $feedDAO->changeCategory($cat->id(), 0);
  775. if ($cat->id() > 1) {
  776. $categoryDAO->deleteCategory($cat->id());
  777. }
  778. exit('OK');
  779. } else {
  780. $tagDAO = FreshRSS_Factory::createTagDao();
  781. $tag = $tagDAO->searchByName($s);
  782. if ($tag != null) {
  783. $tagDAO->deleteTag($tag->id());
  784. exit('OK');
  785. }
  786. }
  787. }
  788. badRequest();
  789. }
  790. function markAllAsRead($streamId, $olderThanId) {
  791. $entryDAO = FreshRSS_Factory::createEntryDao();
  792. if (strpos($streamId, 'feed/') === 0) {
  793. $f_id = basename($streamId);
  794. $entryDAO->markReadFeed($f_id, $olderThanId);
  795. } elseif (strpos($streamId, 'user/-/label/') === 0) {
  796. $c_name = substr($streamId, 13);
  797. $c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8');
  798. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  799. $cat = $categoryDAO->searchByName($c_name);
  800. if ($cat != null) {
  801. $entryDAO->markReadCat($cat->id(), $olderThanId);
  802. } else {
  803. $tagDAO = FreshRSS_Factory::createTagDao();
  804. $tag = $tagDAO->searchByName($c_name);
  805. if ($tag != null) {
  806. $entryDAO->markReadTag($tag->id(), $olderThanId);
  807. }
  808. }
  809. } elseif ($streamId === 'user/-/state/com.google/reading-list') {
  810. $entryDAO->markReadEntries($olderThanId, false, -1);
  811. }
  812. exit('OK');
  813. }
  814. $pathInfo = empty($_SERVER['PATH_INFO']) ? '' : urldecode($_SERVER['PATH_INFO']);
  815. if ($pathInfo == '') {
  816. exit('OK');
  817. }
  818. $pathInfos = explode('/', $pathInfo);
  819. if (count($pathInfos) < 3) {
  820. badRequest();
  821. }
  822. Minz_Configuration::register('system',
  823. DATA_PATH . '/config.php',
  824. FRESHRSS_PATH . '/config.default.php');
  825. FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
  826. //Minz_Log::debug('----------------------------------------------------------------', API_LOG);
  827. //Minz_Log::debug(debugInfo(), API_LOG);
  828. if (!FreshRSS_Context::$system_conf->api_enabled) {
  829. serviceUnavailable();
  830. } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') {
  831. checkCompatibility();
  832. }
  833. ini_set('session.use_cookies', '0');
  834. register_shutdown_function('session_destroy');
  835. Minz_Session::init('FreshRSS');
  836. $user = authorizationToUser();
  837. FreshRSS_Context::$user_conf = null;
  838. if ($user !== '') {
  839. FreshRSS_Context::$user_conf = get_user_configuration($user);
  840. Minz_ExtensionManager::init();
  841. Minz_Translate::init(FreshRSS_Context::$user_conf->language);
  842. if (FreshRSS_Context::$user_conf != null) {
  843. Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled);
  844. }
  845. } else {
  846. Minz_Translate::init();
  847. }
  848. Minz_Session::_param('currentUser', $user);
  849. if ($pathInfos[1] === 'accounts') {
  850. if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) {
  851. clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);
  852. }
  853. } elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) {
  854. if ($user == '') {
  855. unauthorized();
  856. }
  857. $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  858. switch ($pathInfos[4]) {
  859. case 'stream':
  860. /* xt=[exclude target] : Used to exclude certain items from the feed.
  861. * For example, using xt=user/-/state/com.google/read will exclude items
  862. * that the current user has marked as read, or xt=feed/[feedurl] will
  863. * exclude items from a particular feed (obviously not useful in this
  864. * request, but xt appears in other listing requests). */
  865. $exclude_target = isset($_GET['xt']) ? $_GET['xt'] : '';
  866. $filter_target = isset($_GET['it']) ? $_GET['it'] : '';
  867. $count = isset($_GET['n']) ? intval($_GET['n']) : 20; //n=[integer] : The maximum number of results to return.
  868. $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.
  869. /* ot=[unix timestamp] : The time from which you want to retrieve
  870. * items. Only items that have been crawled by Google Reader after
  871. * this time will be returned. */
  872. $start_time = isset($_GET['ot']) ? intval($_GET['ot']) : 0;
  873. $stop_time = isset($_GET['nt']) ? intval($_GET['nt']) : 0;
  874. /* Continuation token. If a StreamContents response does not represent
  875. * all items in a timestamp range, it will have a continuation attribute.
  876. * The same request can be re-issued with the value of that attribute put
  877. * in this parameter to get more items */
  878. $continuation = isset($_GET['c']) ? trim($_GET['c']) : '';
  879. if (!ctype_digit($continuation)) {
  880. $continuation = '';
  881. }
  882. if (isset($pathInfos[5]) && $pathInfos[5] === 'contents' && isset($pathInfos[6])) {
  883. if (isset($pathInfos[7])) {
  884. if ($pathInfos[6] === 'feed') {
  885. $include_target = $pathInfos[7];
  886. if ($include_target != '' && !ctype_digit($include_target)) {
  887. $include_target = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  888. if (preg_match('#/reader/api/0/stream/contents/feed/([A-Za-z0-9\'!*()%$_.~+-]+)#', $include_target, $matches) && isset($matches[1])) {
  889. $include_target = urldecode($matches[1]);
  890. } else {
  891. $include_target = '';
  892. }
  893. }
  894. streamContents($pathInfos[6], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  895. } elseif ($pathInfos[6] === 'user' && isset($pathInfos[8]) && isset($pathInfos[9])) {
  896. if ($pathInfos[8] === 'state') {
  897. if ($pathInfos[9] === 'com.google' && isset($pathInfos[10])) {
  898. if ($pathInfos[10] === 'reading-list' || $pathInfos[10] === 'starred') {
  899. $include_target = '';
  900. streamContents($pathInfos[10], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  901. }
  902. }
  903. } elseif ($pathInfos[8] === 'label') {
  904. $include_target = $pathInfos[9];
  905. streamContents($pathInfos[8], $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  906. }
  907. }
  908. } else { //EasyRSS
  909. $include_target = '';
  910. streamContents('reading-list', $include_target, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  911. }
  912. } elseif ($pathInfos[5] === 'items') {
  913. if ($pathInfos[6] === 'ids' && isset($_GET['s'])) {
  914. /* StreamId for which to fetch the item IDs. The parameter may
  915. * be repeated to fetch the item IDs from multiple streams at once
  916. * (more efficient from a backend perspective than multiple requests). */
  917. $streamId = $_GET['s'];
  918. streamContentsItemsIds($streamId, $start_time, $stop_time, $count, $order, $filter_target, $exclude_target, $continuation);
  919. } elseif ($pathInfos[6] === 'contents' && isset($_POST['i'])) { //FeedMe
  920. $e_ids = multiplePosts('i'); //item IDs
  921. streamContentsItems($e_ids, $order);
  922. }
  923. }
  924. break;
  925. case 'tag':
  926. if (isset($pathInfos[5]) && $pathInfos[5] === 'list') {
  927. $output = isset($_GET['output']) ? $_GET['output'] : '';
  928. if ($output !== 'json') notImplemented();
  929. tagList();
  930. }
  931. break;
  932. case 'subscription':
  933. if (isset($pathInfos[5])) {
  934. switch ($pathInfos[5]) {
  935. case 'list':
  936. $output = isset($_GET['output']) ? $_GET['output'] : '';
  937. if ($output !== 'json') notImplemented();
  938. subscriptionList();
  939. break;
  940. case 'edit':
  941. if (isset($_REQUEST['s']) && isset($_REQUEST['ac'])) {
  942. //StreamId to operate on. The parameter may be repeated to edit multiple subscriptions at once
  943. $streamNames = empty($_POST['s']) && isset($_GET['s']) ? array($_GET['s']) : multiplePosts('s');
  944. /* Title to use for the subscription. For the `subscribe` action,
  945. * if not specified then the feed's current title will be used. Can
  946. * be used with the `edit` action to rename a subscription */
  947. $titles = empty($_POST['t']) && isset($_GET['t']) ? array($_GET['t']) : multiplePosts('t');
  948. $action = $_REQUEST['ac']; //Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit`
  949. $add = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; //StreamId to add the subscription to (generally a user label)
  950. $remove = isset($_REQUEST['r']) ? $_REQUEST['r'] : ''; //StreamId to remove the subscription from (generally a user label)
  951. subscriptionEdit($streamNames, $titles, $action, $add, $remove);
  952. }
  953. break;
  954. case 'quickadd': //https://github.com/theoldreader/api
  955. if (isset($_GET['quickadd'])) {
  956. quickadd($_GET['quickadd']);
  957. }
  958. break;
  959. }
  960. }
  961. break;
  962. case 'unread-count':
  963. $output = isset($_GET['output']) ? $_GET['output'] : '';
  964. if ($output !== 'json') notImplemented();
  965. $all = isset($_GET['all']) ? $_GET['all'] : '';
  966. unreadCount($all);
  967. break;
  968. case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
  969. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  970. checkToken(FreshRSS_Context::$user_conf, $token);
  971. $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
  972. $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
  973. $e_ids = multiplePosts('i'); //item IDs
  974. editTag($e_ids, $a, $r);
  975. break;
  976. case 'rename-tag': //https://github.com/theoldreader/api
  977. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  978. checkToken(FreshRSS_Context::$user_conf, $token);
  979. $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder
  980. $dest = isset($_POST['dest']) ? $_POST['dest'] : ''; //user/-/label/NewFolder
  981. renameTag($s, $dest);
  982. break;
  983. case 'disable-tag': //https://github.com/theoldreader/api
  984. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  985. checkToken(FreshRSS_Context::$user_conf, $token);
  986. $s_s = multiplePosts('s');
  987. foreach ($s_s as $s) {
  988. disableTag($s); //user/-/label/Folder
  989. }
  990. break;
  991. case 'mark-all-as-read':
  992. $token = isset($_POST['T']) ? trim($_POST['T']) : '';
  993. checkToken(FreshRSS_Context::$user_conf, $token);
  994. $streamId = $_POST['s']; //StreamId
  995. $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds
  996. if (!ctype_digit($ts)) {
  997. $ts = '0';
  998. }
  999. markAllAsRead($streamId, $ts);
  1000. break;
  1001. case 'token':
  1002. token(FreshRSS_Context::$user_conf);
  1003. break;
  1004. case 'user-info':
  1005. userInfo();
  1006. break;
  1007. }
  1008. }
  1009. badRequest();