rpc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. print json_encode(array("message" => "UPDATE_COUNTERS"));
  208. }
  209. function getAllCounters() {
  210. $last_article_id = (int) $_REQUEST["last_article_id"];
  211. $reply = array();
  212. if (!empty($_REQUEST['seq'])) $reply['seq'] = (int) $_REQUEST['seq'];
  213. if ($last_article_id != Article::getLastArticleId()) {
  214. $reply['counters'] = Counters::getAllCounters();
  215. }
  216. $reply['runtime-info'] = make_runtime_info();
  217. print json_encode($reply);
  218. }
  219. /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
  220. function catchupSelected() {
  221. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  222. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  223. Article::catchupArticlesById($ids, $cmode);
  224. print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
  225. }
  226. function markSelected() {
  227. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  228. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  229. $this->markArticlesById($ids, $cmode);
  230. print json_encode(array("message" => "UPDATE_COUNTERS"));
  231. }
  232. function publishSelected() {
  233. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  234. $cmode = sprintf("%d", $_REQUEST["cmode"]);
  235. $this->publishArticlesById($ids, $cmode);
  236. print json_encode(array("message" => "UPDATE_COUNTERS"));
  237. }
  238. function sanityCheck() {
  239. $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
  240. $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
  241. $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
  242. $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
  243. $reply = array();
  244. $reply['error'] = sanity_check();
  245. if ($reply['error']['code'] == 0) {
  246. $reply['init-params'] = make_init_params();
  247. $reply['runtime-info'] = make_runtime_info(true);
  248. }
  249. print json_encode($reply);
  250. }
  251. function completeLabels() {
  252. $search = $this->dbh->escape_string($_REQUEST["search"]);
  253. $result = $this->dbh->query("SELECT DISTINCT caption FROM
  254. ttrss_labels2
  255. WHERE owner_uid = '".$_SESSION["uid"]."' AND
  256. LOWER(caption) LIKE LOWER('$search%') ORDER BY caption
  257. LIMIT 5");
  258. print "<ul>";
  259. while ($line = $this->dbh->fetch_assoc($result)) {
  260. print "<li>" . $line["caption"] . "</li>";
  261. }
  262. print "</ul>";
  263. }
  264. function purge() {
  265. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  266. $days = sprintf("%d", $_REQUEST["days"]);
  267. foreach ($ids as $id) {
  268. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  269. id = '$id' AND owner_uid = ".$_SESSION["uid"]);
  270. if ($this->dbh->num_rows($result) == 1) {
  271. purge_feed($id, $days);
  272. }
  273. }
  274. }
  275. function updateFeedBrowser() {
  276. if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
  277. $search = $this->dbh->escape_string($_REQUEST["search"]);
  278. $limit = $this->dbh->escape_string($_REQUEST["limit"]);
  279. $mode = (int) $this->dbh->escape_string($_REQUEST["mode"]);
  280. require_once "feedbrowser.php";
  281. print json_encode(array("content" =>
  282. make_feed_browser($search, $limit, $mode),
  283. "mode" => $mode));
  284. }
  285. // Silent
  286. function massSubscribe() {
  287. $payload = json_decode($_REQUEST["payload"], false);
  288. $mode = $_REQUEST["mode"];
  289. if (!$payload || !is_array($payload)) return;
  290. if ($mode == 1) {
  291. foreach ($payload as $feed) {
  292. $title = $this->dbh->escape_string($feed[0]);
  293. $feed_url = $this->dbh->escape_string($feed[1]);
  294. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  295. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  296. if ($this->dbh->num_rows($result) == 0) {
  297. $result = $this->dbh->query("INSERT INTO ttrss_feeds
  298. (owner_uid,feed_url,title,cat_id,site_url)
  299. VALUES ('".$_SESSION["uid"]."',
  300. '$feed_url', '$title', NULL, '')");
  301. }
  302. }
  303. } else if ($mode == 2) {
  304. // feed archive
  305. foreach ($payload as $id) {
  306. $result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds
  307. WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  308. if ($this->dbh->num_rows($result) != 0) {
  309. $site_url = $this->dbh->escape_string(db_fetch_result($result, 0, "site_url"));
  310. $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url"));
  311. $title = $this->dbh->escape_string(db_fetch_result($result, 0, "title"));
  312. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  313. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  314. if ($this->dbh->num_rows($result) == 0) {
  315. $result = $this->dbh->query("INSERT INTO ttrss_feeds
  316. (owner_uid,feed_url,title,cat_id,site_url)
  317. VALUES ('".$_SESSION["uid"]."',
  318. '$feed_url', '$title', NULL, '$site_url')");
  319. }
  320. }
  321. }
  322. }
  323. }
  324. function catchupFeed() {
  325. $feed_id = $this->dbh->escape_string($_REQUEST['feed_id']);
  326. $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true";
  327. $mode = $this->dbh->escape_string($_REQUEST['mode']);
  328. $search_query = $this->dbh->escape_string($_REQUEST['search_query']);
  329. $search_lang = $this->dbh->escape_string($_REQUEST['search_lang']);
  330. Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
  331. print json_encode(array("message" => "UPDATE_COUNTERS"));
  332. }
  333. function quickAddCat() {
  334. $cat = $this->dbh->escape_string($_REQUEST["cat"]);
  335. add_feed_category($cat);
  336. $result = $this->dbh->query("SELECT id FROM ttrss_feed_categories WHERE
  337. title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
  338. if ($this->dbh->num_rows($result) == 1) {
  339. $id = $this->dbh->fetch_result($result, 0, "id");
  340. } else {
  341. $id = 0;
  342. }
  343. print_feed_cat_select("cat_id", $id, '');
  344. }
  345. function setpanelmode() {
  346. $wide = (int) $_REQUEST["wide"];
  347. setcookie("ttrss_widescreen", $wide,
  348. time() + COOKIE_LIFETIME_LONG);
  349. print json_encode(array("wide" => $wide));
  350. }
  351. static function updaterandomfeed_real($dbh) {
  352. // Test if the feed need a update (update interval exceded).
  353. if (DB_TYPE == "pgsql") {
  354. $update_limit_qpart = "AND ((
  355. ttrss_feeds.update_interval = 0
  356. AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
  357. ) OR (
  358. ttrss_feeds.update_interval > 0
  359. AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
  360. ) OR ttrss_feeds.last_updated IS NULL
  361. OR last_updated = '1970-01-01 00:00:00')";
  362. } else {
  363. $update_limit_qpart = "AND ((
  364. ttrss_feeds.update_interval = 0
  365. AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
  366. ) OR (
  367. ttrss_feeds.update_interval > 0
  368. AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
  369. ) OR ttrss_feeds.last_updated IS NULL
  370. OR last_updated = '1970-01-01 00:00:00')";
  371. }
  372. // Test if feed is currently being updated by another process.
  373. if (DB_TYPE == "pgsql") {
  374. $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
  375. } else {
  376. $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
  377. }
  378. $random_qpart = sql_random_function();
  379. // we could be invoked from public.php with no active session
  380. if ($_SESSION["uid"]) {
  381. $owner_check_qpart = "AND ttrss_feeds.owner_uid = '".$_SESSION["uid"]."'";
  382. } else {
  383. $owner_check_qpart = "";
  384. }
  385. // We search for feed needing update.
  386. $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
  387. FROM
  388. ttrss_feeds, ttrss_users, ttrss_user_prefs
  389. WHERE
  390. ttrss_feeds.owner_uid = ttrss_users.id
  391. AND ttrss_users.id = ttrss_user_prefs.owner_uid
  392. AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
  393. $owner_check_qpart
  394. $update_limit_qpart
  395. $updstart_thresh_qpart
  396. ORDER BY $random_qpart LIMIT 30");
  397. $feed_id = -1;
  398. $num_updated = 0;
  399. $tstart = time();
  400. while ($line = $dbh->fetch_assoc($result)) {
  401. $feed_id = $line["id"];
  402. if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
  403. RSSUtils::update_rss_feed($feed_id, true);
  404. ++$num_updated;
  405. } else {
  406. break;
  407. }
  408. }
  409. // Purge orphans and cleanup tags
  410. Article::purge_orphans();
  411. //cleanup_tags(14, 50000);
  412. if ($num_updated > 0) {
  413. print json_encode(array("message" => "UPDATE_COUNTERS",
  414. "num_updated" => $num_updated));
  415. } else {
  416. print json_encode(array("message" => "NOTHING_TO_UPDATE"));
  417. }
  418. }
  419. function updaterandomfeed() {
  420. RPC::updaterandomfeed_real($this->dbh);
  421. }
  422. private function markArticlesById($ids, $cmode) {
  423. $tmp_ids = array();
  424. foreach ($ids as $id) {
  425. array_push($tmp_ids, "ref_id = '$id'");
  426. }
  427. $ids_qpart = join(" OR ", $tmp_ids);
  428. if ($cmode == 0) {
  429. $this->dbh->query("UPDATE ttrss_user_entries SET
  430. marked = false, last_marked = NOW()
  431. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  432. } else if ($cmode == 1) {
  433. $this->dbh->query("UPDATE ttrss_user_entries SET
  434. marked = true, last_marked = NOW()
  435. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  436. } else {
  437. $this->dbh->query("UPDATE ttrss_user_entries SET
  438. marked = NOT marked,last_marked = NOW()
  439. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  440. }
  441. }
  442. private function publishArticlesById($ids, $cmode) {
  443. $tmp_ids = array();
  444. foreach ($ids as $id) {
  445. array_push($tmp_ids, "ref_id = '$id'");
  446. }
  447. $ids_qpart = join(" OR ", $tmp_ids);
  448. if ($cmode == 0) {
  449. $this->dbh->query("UPDATE ttrss_user_entries SET
  450. published = false,last_published = NOW()
  451. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  452. } else if ($cmode == 1) {
  453. $this->dbh->query("UPDATE ttrss_user_entries SET
  454. published = true,last_published = NOW()
  455. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  456. } else {
  457. $this->dbh->query("UPDATE ttrss_user_entries SET
  458. published = NOT published,last_published = NOW()
  459. WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
  460. }
  461. }
  462. function getlinktitlebyid() {
  463. $id = $this->dbh->escape_string($_REQUEST['id']);
  464. $result = $this->dbh->query("SELECT link, title FROM ttrss_entries, ttrss_user_entries
  465. WHERE ref_id = '$id' AND ref_id = id AND owner_uid = ". $_SESSION["uid"]);
  466. if ($this->dbh->num_rows($result) != 0) {
  467. $link = $this->dbh->fetch_result($result, 0, "link");
  468. $title = $this->dbh->fetch_result($result, 0, "title");
  469. echo json_encode(array("link" => $link, "title" => $title));
  470. } else {
  471. echo json_encode(array("error" => "ARTICLE_NOT_FOUND"));
  472. }
  473. }
  474. function log() {
  475. $msg = $this->dbh->escape_string($_REQUEST['msg']);
  476. $file = $this->dbh->escape_string(basename($_REQUEST['file']));
  477. $line = (int) $_REQUEST['line'];
  478. $context = $this->dbh->escape_string($_REQUEST['context']);
  479. if ($msg) {
  480. Logger::get()->log_error(E_USER_WARNING,
  481. $msg, 'client-js:' . $file, $line, $context);
  482. echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
  483. } else {
  484. echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
  485. }
  486. }
  487. }