rpc.php 18 KB

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