greader.php 36 KB

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