rpc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <?php
  2. class RPC extends Handler_Protected {
  3. function csrf_ignore($method) {
  4. $csrf_ignored = array("sanitycheck", "completelabels");
  5. return array_search($method, $csrf_ignored) !== false;
  6. }
  7. function setprofile() {
  8. $id = $this->dbh->escape_string($_REQUEST["id"]);
  9. $_SESSION["profile"] = $id;
  10. }
  11. function remprofiles() {
  12. $ids = explode(",", $this->dbh->escape_string(trim($_REQUEST["ids"])));
  13. foreach ($ids as $id) {
  14. if ($_SESSION["profile"] != $id) {
  15. $this->dbh->query("DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND
  16. owner_uid = " . $_SESSION["uid"]);
  17. }
  18. }
  19. }
  20. // Silent
  21. function addprofile() {
  22. $title = $this->dbh->escape_string(trim($_REQUEST["title"]));
  23. if ($title) {
  24. $this->dbh->query("BEGIN");
  25. $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
  26. WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]);
  27. if ($this->dbh->num_rows($result) == 0) {
  28. $this->dbh->query("INSERT INTO ttrss_settings_profiles (title, owner_uid)
  29. VALUES ('$title', ".$_SESSION["uid"] .")");
  30. $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles WHERE
  31. title = '$title'");
  32. if ($this->dbh->num_rows($result) != 0) {
  33. $profile_id = $this->dbh->fetch_result($result, 0, "id");
  34. if ($profile_id) {
  35. initialize_user_prefs($_SESSION["uid"], $profile_id);
  36. }
  37. }
  38. }
  39. $this->dbh->query("COMMIT");
  40. }
  41. }
  42. // Silent
  43. function saveprofile() {
  44. $id = $this->dbh->escape_string($_REQUEST["id"]);
  45. $title = $this->dbh->escape_string(trim($_REQUEST["value"]));
  46. if ($id == 0) {
  47. print __("Default profile");
  48. return;
  49. }
  50. if ($title) {
  51. $this->dbh->query("BEGIN");
  52. $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
  53. WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]);
  54. if ($this->dbh->num_rows($result) == 0) {
  55. $this->dbh->query("UPDATE ttrss_settings_profiles
  56. SET title = '$title' WHERE id = '$id' AND
  57. owner_uid = " . $_SESSION["uid"]);
  58. print $title;
  59. } else {
  60. $result = $this->dbh->query("SELECT title FROM ttrss_settings_profiles
  61. WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]);
  62. print $this->dbh->fetch_result($result, 0, "title");
  63. }
  64. $this->dbh->query("COMMIT");
  65. }
  66. }
  67. // Silent
  68. function remarchive() {
  69. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  70. foreach ($ids as $id) {
  71. $result = $this->dbh->query("DELETE FROM ttrss_archived_feeds WHERE
  72. (SELECT COUNT(*) FROM ttrss_user_entries
  73. WHERE orig_feed_id = '$id') = 0 AND
  74. id = '$id' AND owner_uid = ".$_SESSION["uid"]);
  75. $this->dbh->affected_rows($result);
  76. }
  77. }
  78. function addfeed() {
  79. $feed = $this->dbh->escape_string($_REQUEST['feed']);
  80. $cat = $this->dbh->escape_string($_REQUEST['cat']);
  81. $login = $this->dbh->escape_string($_REQUEST['login']);
  82. $pass = trim($_REQUEST['pass']); // escaped later
  83. $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
  84. print json_encode(array("result" => $rc));
  85. }
  86. function togglepref() {
  87. $key = $this->dbh->escape_string($_REQUEST["key"]);
  88. set_pref($key, !get_pref($key));
  89. $value = get_pref($key);
  90. print json_encode(array("param" =>$key, "value" => $value));
  91. }
  92. function setpref() {
  93. // set_pref escapes input, so no need to double escape it here
  94. $key = $_REQUEST['key'];
  95. $value = str_replace("\n", "<br/>", $_REQUEST['value']);
  96. set_pref($key, $value, false, $key != 'USER_STYLESHEET');
  97. print json_encode(array("param" =>$key, "value" => $value));
  98. }
  99. function mark() {
  100. $mark = $_REQUEST["mark"];
  101. $id = $this->dbh->escape_string($_REQUEST["id"]);
  102. if ($mark == "1") {
  103. $mark = "true";
  104. } else {
  105. $mark = "false";
  106. }
  107. $this->dbh->query("UPDATE ttrss_user_entries SET marked = $mark,
  108. last_marked = NOW()
  109. WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  110. print json_encode(array("message" => "UPDATE_COUNTERS"));
  111. }
  112. function delete() {
  113. $ids = $this->dbh->escape_string($_REQUEST["ids"]);
  114. $this->dbh->query("DELETE FROM ttrss_user_entries
  115. WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
  116. Article::purge_orphans();
  117. print json_encode(array("message" => "UPDATE_COUNTERS"));
  118. }
  119. function unarchive() {
  120. $ids = explode(",", $_REQUEST["ids"]);
  121. foreach ($ids as $id) {
  122. $id = $this->dbh->escape_string(trim($id));
  123. $this->dbh->query("BEGIN");
  124. $result = $this->dbh->query("SELECT feed_url,site_url,title FROM ttrss_archived_feeds
  125. WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = $id
  126. AND owner_uid = ".$_SESSION["uid"].") AND owner_uid = " . $_SESSION["uid"]);
  127. if ($this->dbh->num_rows($result) != 0) {
  128. $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url"));
  129. $site_url = $this->dbh->escape_string(db_fetch_result($result, 0, "site_url"));
  130. $title = $this->dbh->escape_string(db_fetch_result($result, 0, "title"));
  131. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url'
  132. AND owner_uid = " .$_SESSION["uid"]);
  133. if ($this->dbh->num_rows($result) == 0) {
  134. if (!$title) $title = '[Unknown]';
  135. $result = $this->dbh->query(
  136. "INSERT INTO ttrss_feeds
  137. (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method)
  138. VALUES (".$_SESSION["uid"].",
  139. '$feed_url',
  140. '$site_url',
  141. '$title',
  142. NULL, '', '', 0)");
  143. $result = $this->dbh->query(
  144. "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url'
  145. AND owner_uid = ".$_SESSION["uid"]);
  146. if ($this->dbh->num_rows($result) != 0) {
  147. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  148. }
  149. } else {
  150. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  151. }
  152. if ($feed_id) {
  153. $result = $this->dbh->query("UPDATE ttrss_user_entries
  154. SET feed_id = '$feed_id', orig_feed_id = NULL
  155. WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]);
  156. }
  157. }
  158. $this->dbh->query("COMMIT");
  159. }
  160. print json_encode(array("message" => "UPDATE_COUNTERS"));
  161. }
  162. function archive() {
  163. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  164. foreach ($ids as $id) {
  165. $this->archive_article($id, $_SESSION["uid"]);
  166. }
  167. print json_encode(array("message" => "UPDATE_COUNTERS"));
  168. }
  169. private function archive_article($id, $owner_uid) {
  170. $this->dbh->query("BEGIN");
  171. $result = $this->dbh->query("SELECT feed_id FROM ttrss_user_entries
  172. WHERE ref_id = '$id' AND owner_uid = $owner_uid");
  173. if ($this->dbh->num_rows($result) != 0) {
  174. /* prepare the archived table */
  175. $feed_id = (int) $this->dbh->fetch_result($result, 0, "feed_id");
  176. if ($feed_id) {
  177. $result = $this->dbh->query("SELECT id FROM ttrss_archived_feeds
  178. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  179. if ($this->dbh->num_rows($result) == 0) {
  180. $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
  181. $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
  182. $this->dbh->query("INSERT INTO ttrss_archived_feeds
  183. (id, owner_uid, title, feed_url, site_url)
  184. SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
  185. WHERE id = '$feed_id'");
  186. } else {
  187. $new_feed_id = $this->dbh->fetch_result($result, 0, "id");
  188. }
  189. $this->dbh->query("UPDATE ttrss_user_entries
  190. SET orig_feed_id = $new_feed_id, feed_id = NULL
  191. WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  192. }
  193. }
  194. $this->dbh->query("COMMIT");
  195. }
  196. function publ() {
  197. $pub = $_REQUEST["pub"];
  198. $id = $this->dbh->escape_string($_REQUEST["id"]);
  199. if ($pub == "1") {
  200. $pub = "true";
  201. } else {
  202. $pub = "false";
  203. }
  204. $this->dbh->query("UPDATE ttrss_user_entries SET
  205. published = $pub, last_published = NOW()
  206. WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  207. $pubsub_result = false;
  208. if (PUBSUBHUBBUB_HUB) {
  209. $rss_link = get_self_url_prefix() .
  210. "/public.php?op=rss&id=-2&key=" .
  211. get_feed_access_key(-2, false);
  212. $p = new pubsubhubbub\publisher\Publisher(PUBSUBHUBBUB_HUB);
  213. $pubsub_result = $p->publish_update($rss_link);
  214. }
  215. print json_encode(array("message" => "UPDATE_COUNTERS",
  216. "pubsub_result" => $pubsub_result));
  217. }
  218. function getAllCounters() {
  219. $last_article_id = (int) $_REQUEST["last_article_id"];
  220. $reply = array();
  221. if (!empty($_REQUEST['seq'])) $reply['seq'] = (int) $_REQUEST['seq'];
  222. if ($last_article_id != Article::getLastArticleId()) {
  223. $reply['counters'] = Counters::getAllCounters();
  224. }
  225. $reply['runtime-info'] = make_runtime_info();
  226. print json_encode($reply);
  227. }
  228. /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
  229. function catchupSelected() {
  230. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  231. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  232. Article::catchupArticlesById($ids, $cmode);
  233. print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
  234. }
  235. function markSelected() {
  236. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  237. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  238. $this->markArticlesById($ids, $cmode);
  239. print json_encode(array("message" => "UPDATE_COUNTERS"));
  240. }
  241. function publishSelected() {
  242. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  243. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  244. $this->publishArticlesById($ids, $cmode);
  245. print json_encode(array("message" => "UPDATE_COUNTERS"));
  246. }
  247. function sanityCheck() {
  248. $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
  249. $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
  250. $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
  251. $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
  252. $reply = array();
  253. $reply['error'] = sanity_check();
  254. if ($reply['error']['code'] == 0) {
  255. $reply['init-params'] = make_init_params();
  256. $reply['runtime-info'] = make_runtime_info(true);
  257. }
  258. print json_encode($reply);
  259. }
  260. function completeLabels() {
  261. $search = $this->dbh->escape_string($_REQUEST["search"]);
  262. $result = $this->dbh->query("SELECT DISTINCT caption FROM
  263. ttrss_labels2
  264. WHERE owner_uid = '".$_SESSION["uid"]."' AND
  265. LOWER(caption) LIKE LOWER('$search%') ORDER BY caption
  266. LIMIT 5");
  267. print "<ul>";
  268. while ($line = $this->dbh->fetch_assoc($result)) {
  269. print "<li>" . $line["caption"] . "</li>";
  270. }
  271. print "</ul>";
  272. }
  273. function purge() {
  274. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  275. $days = sprintf("%d", $_REQUEST["days"]);
  276. foreach ($ids as $id) {
  277. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  278. id = '$id' AND owner_uid = ".$_SESSION["uid"]);
  279. if ($this->dbh->num_rows($result) == 1) {
  280. purge_feed($id, $days);
  281. }
  282. }
  283. }
  284. function updateFeedBrowser() {
  285. if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
  286. $search = $this->dbh->escape_string($_REQUEST["search"]);
  287. $limit = $this->dbh->escape_string($_REQUEST["limit"]);
  288. $mode = (int) $this->dbh->escape_string($_REQUEST["mode"]);
  289. require_once "feedbrowser.php";
  290. print json_encode(array("content" =>
  291. make_feed_browser($search, $limit, $mode),
  292. "mode" => $mode));
  293. }
  294. // Silent
  295. function massSubscribe() {
  296. $payload = json_decode($_REQUEST["payload"], false);
  297. $mode = $_REQUEST["mode"];
  298. if (!$payload || !is_array($payload)) return;
  299. if ($mode == 1) {
  300. foreach ($payload as $feed) {
  301. $title = $this->dbh->escape_string($feed[0]);
  302. $feed_url = $this->dbh->escape_string($feed[1]);
  303. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  304. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  305. if ($this->dbh->num_rows($result) == 0) {
  306. $result = $this->dbh->query("INSERT INTO ttrss_feeds
  307. (owner_uid,feed_url,title,cat_id,site_url)
  308. VALUES ('".$_SESSION["uid"]."',
  309. '$feed_url', '$title', NULL, '')");
  310. }
  311. }
  312. } else if ($mode == 2) {
  313. // feed archive
  314. foreach ($payload as $id) {
  315. $result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds
  316. WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  317. if ($this->dbh->num_rows($result) != 0) {
  318. $site_url = $this->dbh->escape_string(db_fetch_result($result, 0, "site_url"));
  319. $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url"));
  320. $title = $this->dbh->escape_string(db_fetch_result($result, 0, "title"));
  321. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  322. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  323. if ($this->dbh->num_rows($result) == 0) {
  324. $result = $this->dbh->query("INSERT INTO ttrss_feeds
  325. (owner_uid,feed_url,title,cat_id,site_url)
  326. VALUES ('".$_SESSION["uid"]."',
  327. '$feed_url', '$title', NULL, '$site_url')");
  328. }
  329. }
  330. }
  331. }
  332. }
  333. function catchupFeed() {
  334. $feed_id = $this->dbh->escape_string($_REQUEST['feed_id']);
  335. $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true";
  336. $mode = $this->dbh->escape_string($_REQUEST['mode']);
  337. $search_query = $this->dbh->escape_string($_REQUEST['search_query']);
  338. $search_lang = $this->dbh->escape_string($_REQUEST['search_lang']);
  339. Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
  340. print json_encode(array("message" => "UPDATE_COUNTERS"));
  341. }
  342. function quickAddCat() {
  343. $cat = $this->dbh->escape_string($_REQUEST["cat"]);
  344. add_feed_category($cat);
  345. $result = $this->dbh->query("SELECT id FROM ttrss_feed_categories WHERE
  346. title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
  347. if ($this->dbh->num_rows($result) == 1) {
  348. $id = $this->dbh->fetch_result($result, 0, "id");
  349. } else {
  350. $id = 0;
  351. }
  352. print_feed_cat_select("cat_id", $id, '');
  353. }
  354. function setpanelmode() {
  355. $wide = (int) $_REQUEST["wide"];
  356. setcookie("ttrss_widescreen", $wide,
  357. time() + COOKIE_LIFETIME_LONG);
  358. print json_encode(array("wide" => $wide));
  359. }
  360. static function updaterandomfeed_real($dbh) {
  361. // Test if the feed need a update (update interval exceded).
  362. if (DB_TYPE == "pgsql") {
  363. $update_limit_qpart = "AND ((
  364. ttrss_feeds.update_interval = 0
  365. AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
  366. ) OR (
  367. ttrss_feeds.update_interval > 0
  368. AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
  369. ) OR ttrss_feeds.last_updated IS NULL
  370. OR last_updated = '1970-01-01 00:00:00')";
  371. } else {
  372. $update_limit_qpart = "AND ((
  373. ttrss_feeds.update_interval = 0
  374. AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
  375. ) OR (
  376. ttrss_feeds.update_interval > 0
  377. AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
  378. ) OR ttrss_feeds.last_updated IS NULL
  379. OR last_updated = '1970-01-01 00:00:00')";
  380. }
  381. // Test if feed is currently being updated by another process.
  382. if (DB_TYPE == "pgsql") {
  383. $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
  384. } else {
  385. $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
  386. }
  387. $random_qpart = sql_random_function();
  388. // we could be invoked from public.php with no active session
  389. if ($_SESSION["uid"]) {
  390. $owner_check_qpart = "AND ttrss_feeds.owner_uid = '".$_SESSION["uid"]."'";
  391. } else {
  392. $owner_check_qpart = "";
  393. }
  394. // We search for feed needing update.
  395. $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
  396. FROM
  397. ttrss_feeds, ttrss_users, ttrss_user_prefs
  398. WHERE
  399. ttrss_feeds.owner_uid = ttrss_users.id
  400. AND ttrss_users.id = ttrss_user_prefs.owner_uid
  401. AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
  402. $owner_check_qpart
  403. $update_limit_qpart
  404. $updstart_thresh_qpart
  405. ORDER BY $random_qpart LIMIT 30");
  406. $feed_id = -1;
  407. $num_updated = 0;
  408. $tstart = time();
  409. while ($line = $dbh->fetch_assoc($result)) {
  410. $feed_id = $line["id"];
  411. if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
  412. RSSUtils::update_rss_feed($feed_id, true);
  413. ++$num_updated;
  414. } else {
  415. break;
  416. }
  417. }
  418. // Purge orphans and cleanup tags
  419. Article::purge_orphans();
  420. //cleanup_tags(14, 50000);
  421. if ($num_updated > 0) {
  422. print json_encode(array("message" => "UPDATE_COUNTERS",
  423. "num_updated" => $num_updated));
  424. } else {
  425. print json_encode(array("message" => "NOTHING_TO_UPDATE"));
  426. }
  427. }
  428. function updaterandomfeed() {
  429. RPC::updaterandomfeed_real($this->dbh);
  430. }
  431. private function markArticlesById($ids, $cmode) {
  432. $tmp_ids = array();
  433. foreach ($ids as $id) {
  434. array_push($tmp_ids, "ref_id = '$id'");
  435. }
  436. $ids_qpart = join(" OR ", $tmp_ids);
  437. if ($cmode == 0) {
  438. $this->dbh->query("UPDATE ttrss_user_entries SET
  439. marked = false, last_marked = NOW()
  440. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  441. } else if ($cmode == 1) {
  442. $this->dbh->query("UPDATE ttrss_user_entries SET
  443. marked = true, last_marked = NOW()
  444. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  445. } else {
  446. $this->dbh->query("UPDATE ttrss_user_entries SET
  447. marked = NOT marked,last_marked = NOW()
  448. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  449. }
  450. }
  451. private function publishArticlesById($ids, $cmode) {
  452. $tmp_ids = array();
  453. foreach ($ids as $id) {
  454. array_push($tmp_ids, "ref_id = '$id'");
  455. }
  456. $ids_qpart = join(" OR ", $tmp_ids);
  457. if ($cmode == 0) {
  458. $this->dbh->query("UPDATE ttrss_user_entries SET
  459. published = false,last_published = NOW()
  460. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  461. } else if ($cmode == 1) {
  462. $this->dbh->query("UPDATE ttrss_user_entries SET
  463. published = true,last_published = NOW()
  464. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  465. } else {
  466. $this->dbh->query("UPDATE ttrss_user_entries SET
  467. published = NOT published,last_published = NOW()
  468. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  469. }
  470. if (PUBSUBHUBBUB_HUB) {
  471. $rss_link = get_self_url_prefix() .
  472. "/public.php?op=rss&id=-2&key=" .
  473. get_feed_access_key(-2, false);
  474. $p = new pubsubhubbub\publisher\Publisher(PUBSUBHUBBUB_HUB);
  475. /* $pubsub_result = */ $p->publish_update($rss_link);
  476. }
  477. }
  478. function getlinktitlebyid() {
  479. $id = $this->dbh->escape_string($_REQUEST['id']);
  480. $result = $this->dbh->query("SELECT link, title FROM ttrss_entries, ttrss_user_entries
  481. WHERE ref_id = '$id' AND ref_id = id AND owner_uid = ". $_SESSION["uid"]);
  482. if ($this->dbh->num_rows($result) != 0) {
  483. $link = $this->dbh->fetch_result($result, 0, "link");
  484. $title = $this->dbh->fetch_result($result, 0, "title");
  485. echo json_encode(array("link" => $link, "title" => $title));
  486. } else {
  487. echo json_encode(array("error" => "ARTICLE_NOT_FOUND"));
  488. }
  489. }
  490. function log() {
  491. $msg = $this->dbh->escape_string($_REQUEST['msg']);
  492. $file = $this->dbh->escape_string(basename($_REQUEST['file']));
  493. $line = (int) $_REQUEST['line'];
  494. $context = $this->dbh->escape_string($_REQUEST['context']);
  495. if ($msg) {
  496. Logger::get()->log_error(E_USER_WARNING,
  497. $msg, 'client-js:' . $file, $line, $context);
  498. echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
  499. } else {
  500. echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
  501. }
  502. }
  503. }