greader.php 36 KB

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