]> git.wh0rd.org - tt-rss.git/blame - classes/rpc.php
rpc: switch to PDO
[tt-rss.git] / classes / rpc.php
CommitLineData
d5112468 1<?php
369dbc19 2class RPC extends Handler_Protected {
d5112468 3
8484ce22 4 function csrf_ignore($method) {
fbe7cb0a 5 $csrf_ignored = array("sanitycheck", "completelabels", "saveprofile");
8484ce22
AD
6
7 return array_search($method, $csrf_ignored) !== false;
8 }
9
d5112468 10 function setprofile() {
fbe7cb0a 11 $_SESSION["profile"] = $_REQUEST["id"];
d5112468
AD
12 }
13
14 function remprofiles() {
fbe7cb0a 15 $ids = explode(",", trim($_REQUEST["ids"]));
d5112468
AD
16
17 foreach ($ids as $id) {
18 if ($_SESSION["profile"] != $id) {
fbe7cb0a
AD
19 $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND
20 owner_uid = ?");
21 $sth->execute([$id, $_SESSION['uid']]);
d5112468
AD
22 }
23 }
24 }
25
26 // Silent
27 function addprofile() {
fbe7cb0a
AD
28 $title = trim($_REQUEST["title"]);
29
d5112468 30 if ($title) {
fbe7cb0a 31 $this->pdo->beginTransaction();
d5112468 32
fbe7cb0a
AD
33 $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
34 WHERE title = ? AND owner_uid = ?");
35 $sth->execute([$title, $_SESSION['uid']]);
d5112468 36
fbe7cb0a 37 if (!$sth->fetch()) {
d5112468 38
fbe7cb0a
AD
39 $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid)
40 VALUES (?, ?)");
d5112468 41
fbe7cb0a 42 $sth->execute([$title, $_SESSION['uid']]);
d5112468 43
fbe7cb0a
AD
44 $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE
45 title = ? AND owner_uid = ?");
46 $sth->execute([$title, $_SESSION['uid']]);
47
48 if ($row = $sth->fetch()) {
49 $profile_id = $row['id'];
d5112468
AD
50
51 if ($profile_id) {
a42c55f0 52 initialize_user_prefs($_SESSION["uid"], $profile_id);
d5112468
AD
53 }
54 }
55 }
56
fbe7cb0a 57 $this->pdo->commit();
d5112468
AD
58 }
59 }
60
d5112468 61 function saveprofile() {
fbe7cb0a
AD
62 $id = $_REQUEST["id"];
63 $title = trim($_REQUEST["value"]);
d5112468
AD
64
65 if ($id == 0) {
66 print __("Default profile");
67 return;
68 }
69
70 if ($title) {
fbe7cb0a
AD
71 $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles
72 SET title = ? WHERE id = ? AND
73 owner_uid = ?");
d5112468 74
fbe7cb0a
AD
75 $sth->execute([$title, $id, $_SESSION['uid']]);
76 print $title;
d5112468
AD
77 }
78 }
79
80 // Silent
81 function remarchive() {
fbe7cb0a 82 $ids = explode(",", $_REQUEST["ids"]);
d5112468 83
fbe7cb0a
AD
84 $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE
85 (SELECT COUNT(*) FROM ttrss_user_entries
86 WHERE orig_feed_id = :id) = 0 AND
87 id = :id AND owner_uid = :uid");
d5112468 88
fbe7cb0a
AD
89 foreach ($ids as $id) {
90 $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]);
d5112468
AD
91 }
92 }
93
94 function addfeed() {
fbe7cb0a
AD
95 $feed = $_REQUEST['feed'];
96 $cat = $_REQUEST['cat'];
97 $login = $_REQUEST['login'];
98 $pass = trim($_REQUEST['pass']);
d5112468 99
86a8351c 100 $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
d5112468
AD
101
102 print json_encode(array("result" => $rc));
103 }
104
d5112468 105 function togglepref() {
fbe7cb0a 106 $key = $_REQUEST["key"];
a42c55f0
AD
107 set_pref($key, !get_pref($key));
108 $value = get_pref($key);
d5112468
AD
109
110 print json_encode(array("param" =>$key, "value" => $value));
111 }
112
113 function setpref() {
0380cfa9 114 // set_pref escapes input, so no need to double escape it here
74eef4fc
AD
115 $key = $_REQUEST['key'];
116 $value = str_replace("\n", "<br/>", $_REQUEST['value']);
d5112468 117
86d07d36 118 set_pref($key, $value, false, $key != 'USER_STYLESHEET');
d5112468
AD
119
120 print json_encode(array("param" =>$key, "value" => $value));
121 }
122
123 function mark() {
124 $mark = $_REQUEST["mark"];
fbe7cb0a 125 $id = $_REQUEST["id"];
d5112468 126
fbe7cb0a 127 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?,
7873d588 128 last_marked = NOW()
fbe7cb0a
AD
129 WHERE ref_id = ? AND owner_uid = ?");
130
131 $sth->execute([$mark, $id, $_SESSION['uid']]);
d5112468
AD
132
133 print json_encode(array("message" => "UPDATE_COUNTERS"));
134 }
135
136 function delete() {
fbe7cb0a
AD
137 $ids = explode(",", $_REQUEST["ids"]);
138 $ids_qmarks = arr_qmarks($ids);
d5112468 139
fbe7cb0a
AD
140 $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries
141 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
142 $sth->execute(array_merge($ids, [$_SESSION['uid']]));
d5112468 143
a230bf88 144 Article::purge_orphans();
f0d3c94a 145
d5112468
AD
146 print json_encode(array("message" => "UPDATE_COUNTERS"));
147 }
148
149 function unarchive() {
b029f916
AD
150 $ids = explode(",", $_REQUEST["ids"]);
151
152 foreach ($ids as $id) {
fbe7cb0a 153 $this->pdo->beginTransaction();
b029f916 154
fbe7cb0a
AD
155 $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds
156 WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = :id
157 AND owner_uid = :uid) AND owner_uid = :uid");
158 $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]);
b029f916 159
fbe7cb0a
AD
160 if ($row = $sth->fetch()) {
161 $feed_url = $row['feed_url'];
162 $site_url = $row['site_url'];
163 $title = $row['title'];
b029f916 164
fbe7cb0a
AD
165 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
166 AND owner_uid = ?");
167 $sth->execute([$feed_url, $_SESSION['uid']]);
b029f916 168
fbe7cb0a
AD
169 if ($row = $sth->fetch()) {
170 $feed_id = $row["id"];
171 } else {
b029f916
AD
172 if (!$title) $title = '[Unknown]';
173
fbe7cb0a 174 $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
b029f916 175 (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method)
fbe7cb0a
AD
176 VALUES (?, ?, ?, ?, NULL, '', '', 0)");
177 $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]);
b029f916 178
fbe7cb0a
AD
179 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
180 AND owner_uid = ?");
181 $sth->execute([$feed_url, $_SESSION['uid']]);
182
183 if ($row = $sth->fetch()) {
184 $feed_id = $row['id'];
185 }
b029f916
AD
186 }
187
188 if ($feed_id) {
fbe7cb0a
AD
189 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries
190 SET feed_id = ?, orig_feed_id = NULL
191 WHERE ref_id = ? AND owner_uid = ?");
192 $sth->execute([$feed_id, $id, $_SESSION['uid']]);
b029f916
AD
193 }
194 }
195
fbe7cb0a 196 $this->pdo->commit();
b029f916 197 }
d5112468
AD
198
199 print json_encode(array("message" => "UPDATE_COUNTERS"));
200 }
201
202 function archive() {
fbe7cb0a 203 $ids = explode(",", $_REQUEST["ids"]);
d5112468
AD
204
205 foreach ($ids as $id) {
a42c55f0 206 $this->archive_article($id, $_SESSION["uid"]);
d5112468
AD
207 }
208
209 print json_encode(array("message" => "UPDATE_COUNTERS"));
210 }
211
a42c55f0 212 private function archive_article($id, $owner_uid) {
fbe7cb0a
AD
213 $this->pdo->beginTransaction();
214
215 if (!$owner_uid) $owner_uid = $_SESSION['uid'];
87d7e850 216
fbe7cb0a
AD
217 $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries
218 WHERE ref_id = ? AND owner_uid = ?");
219 $sth->execute([$id, $owner_uid]);
87d7e850 220
fbe7cb0a 221 if ($row = $sth->fetch()) {
87d7e850
AD
222
223 /* prepare the archived table */
224
fbe7cb0a 225 $feed_id = (int) $row['feed_id'];
87d7e850
AD
226
227 if ($feed_id) {
fbe7cb0a
AD
228 $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds
229 WHERE id = ? AND owner_uid = ?");
230 $sth->execute([$feed_id, $owner_uid]);
87d7e850 231
fbe7cb0a
AD
232 if ($row = $sth->fetch()) {
233 $new_feed_id = $row['id'];
234 } else {
235 $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch();
236 $new_feed_id = (int)$row['id'] + 1;
71b75bb7 237
fbe7cb0a 238 $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds
87d7e850 239 (id, owner_uid, title, feed_url, site_url)
fbe7cb0a
AD
240 SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds
241 WHERE id = ?");
242
243 $sth->execute([$new_feed_id, $feed_id]);
87d7e850
AD
244 }
245
fbe7cb0a
AD
246 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries
247 SET orig_feed_id = ?, feed_id = NULL
248 WHERE ref_id = ? AND owner_uid = ?");
249 $sth->execute([$new_feed_id, $id, $owner_uid]);
87d7e850
AD
250 }
251 }
252
fbe7cb0a 253 $this->pdo->commit();
87d7e850
AD
254 }
255
d5112468
AD
256 function publ() {
257 $pub = $_REQUEST["pub"];
fbe7cb0a 258 $id = $_REQUEST["id"];
d5112468 259
fbe7cb0a
AD
260 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
261 published = ?, last_published = NOW()
262 WHERE ref_id = ? AND owner_uid = ?");
d5112468 263
fbe7cb0a 264 $sth->execute([$pub, $id, $_SESSION['uid']]);
d5112468 265
5b6ea1ef 266 print json_encode(array("message" => "UPDATE_COUNTERS"));
d5112468
AD
267 }
268
269 function getAllCounters() {
270 $last_article_id = (int) $_REQUEST["last_article_id"];
271
272 $reply = array();
273
6f7798b6 274 if (!empty($_REQUEST['seq'])) $reply['seq'] = (int) $_REQUEST['seq'];
d5112468 275
aeb1abed 276 if ($last_article_id != Article::getLastArticleId()) {
65af3b2c 277 $reply['counters'] = Counters::getAllCounters();
5b55e9e2 278 }
d5112468 279
6322ac79 280 $reply['runtime-info'] = make_runtime_info();
d5112468 281
5b55e9e2 282 print json_encode($reply);
d5112468
AD
283 }
284
285 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
286 function catchupSelected() {
fbe7cb0a 287 $ids = explode(",", $_REQUEST["ids"]);
d5112468
AD
288 $cmode = sprintf("%d", $_REQUEST["cmode"]);
289
aeb1abed 290 Article::catchupArticlesById($ids, $cmode);
d5112468 291
ae31704b 292 print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
d5112468
AD
293 }
294
295 function markSelected() {
fbe7cb0a
AD
296 $ids = explode(",", $_REQUEST["ids"]);
297 $cmode = (int)$_REQUEST["cmode"];
d5112468 298
a42c55f0 299 $this->markArticlesById($ids, $cmode);
d5112468
AD
300
301 print json_encode(array("message" => "UPDATE_COUNTERS"));
302 }
303
304 function publishSelected() {
fbe7cb0a
AD
305 $ids = explode(",", $_REQUEST["ids"]);
306 $cmode = (int)$_REQUEST["cmode"];
d5112468 307
a42c55f0 308 $this->publishArticlesById($ids, $cmode);
d5112468
AD
309
310 print json_encode(array("message" => "UPDATE_COUNTERS"));
311 }
312
313 function sanityCheck() {
314 $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
4f7d69e1 315 $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
40fe2d73 316 $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
6bfc97da 317 $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
d5112468
AD
318
319 $reply = array();
320
6322ac79 321 $reply['error'] = sanity_check();
d5112468
AD
322
323 if ($reply['error']['code'] == 0) {
6322ac79 324 $reply['init-params'] = make_init_params();
79c891a8 325 $reply['runtime-info'] = make_runtime_info(true);
d5112468
AD
326 }
327
328 print json_encode($reply);
329 }
330
1b4d1a6b 331 function completeLabels() {
fbe7cb0a 332 $search = $_REQUEST["search"];
1b4d1a6b 333
fbe7cb0a 334 $sth = $this->pdo->query("SELECT DISTINCT caption FROM
1b4d1a6b 335 ttrss_labels2
fbe7cb0a
AD
336 WHERE owner_uid = ? AND
337 LOWER(caption) LIKE LOWER(?) ORDER BY caption
1b4d1a6b 338 LIMIT 5");
fbe7cb0a 339 $sth->execute([$_SESSION['uid'], "%$search%"]);
1b4d1a6b
AD
340
341 print "<ul>";
fbe7cb0a 342 while ($line = $sth->fetch()) {
1b4d1a6b
AD
343 print "<li>" . $line["caption"] . "</li>";
344 }
345 print "</ul>";
346 }
347
d5112468 348 function purge() {
fbe7cb0a
AD
349 $ids = explode(",", $_REQUEST["ids"]);
350 $days = (int) $_REQUEST["days"];
d5112468 351
fbe7cb0a
AD
352 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
353 id = ? AND owner_uid = ?");
d5112468 354
fbe7cb0a
AD
355 foreach ($ids as $id) {
356 $sth->execute([$id, $_SESSION['uid']]);
d5112468 357
fbe7cb0a 358 if ($sth->fetch()) {
a42c55f0 359 purge_feed($id, $days);
d5112468
AD
360 }
361 }
362 }
363
d5112468 364 function updateFeedBrowser() {
0e653f75
AK
365 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
366
fbe7cb0a
AD
367 $search = $_REQUEST["search"];
368 $limit = $_REQUEST["limit"];
369 $mode = (int) $_REQUEST["mode"];
d5112468 370
55c7f092
AD
371 require_once "feedbrowser.php";
372
d5112468 373 print json_encode(array("content" =>
a42c55f0 374 make_feed_browser($search, $limit, $mode),
d5112468
AD
375 "mode" => $mode));
376 }
377
378 // Silent
379 function massSubscribe() {
380
381 $payload = json_decode($_REQUEST["payload"], false);
382 $mode = $_REQUEST["mode"];
383
384 if (!$payload || !is_array($payload)) return;
385
386 if ($mode == 1) {
387 foreach ($payload as $feed) {
388
fbe7cb0a
AD
389 $title = $feed[0];
390 $feed_url = $feed[1];
d5112468 391
fbe7cb0a
AD
392 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
393 feed_url = ? AND owner_uid = ?");
394 $sth->execute([$feed_url, $_SESSION['uid']]);
d5112468 395
fbe7cb0a
AD
396 if (!$sth->fetch()) {
397 $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
d5112468 398 (owner_uid,feed_url,title,cat_id,site_url)
fbe7cb0a
AD
399 VALUES (?, ?, ?, NULL, '')");
400
401 $sth->execute([$_SESSION['uid'], $feed_url, $title]);
d5112468
AD
402 }
403 }
404 } else if ($mode == 2) {
405 // feed archive
406 foreach ($payload as $id) {
fbe7cb0a
AD
407 $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds
408 WHERE id = ? AND owner_uid = ?");
409 $sth->execute([$id, $_SESSION['uid']]);
410
411 if ($row = $sth->fetch()) {
412 $site_url = $row['site_url'];
413 $feed_url = $row['feed_url'];
414 $title = $row['title'];
415
416 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
417 feed_url = ? AND owner_uid = ?");
418 $sth->execute([$feed_url, $_SESSION['uid']]);
419
420 if (!$sth->fetch()) {
421 $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
422 (owner_uid,feed_url,title,cat_id,site_url)
423 VALUES (?, ?, ?, NULL, ?)");
424
425 $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]);
d5112468
AD
426 }
427 }
428 }
429 }
430 }
431
d5112468 432 function catchupFeed() {
fbe7cb0a
AD
433 $feed_id = $_REQUEST['feed_id'];
434 $is_cat = $_REQUEST['is_cat'] == "true";
435 $mode = $_REQUEST['mode'];
436 $search_query = $_REQUEST['search_query'];
437 $search_lang = $_REQUEST['search_lang'];
d5112468 438
86a8351c 439 Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
d5112468
AD
440
441 print json_encode(array("message" => "UPDATE_COUNTERS"));
442 }
443
7d8f5657
AD
444 function setpanelmode() {
445 $wide = (int) $_REQUEST["wide"];
446
f03701fe 447 setcookie("ttrss_widescreen", $wide,
e57a1507 448 time() + COOKIE_LIFETIME_LONG);
7d8f5657
AD
449
450 print json_encode(array("wide" => $wide));
451 }
452
fbe7cb0a 453 static function updaterandomfeed_real() {
113c3dec 454
8b83bf5f
AD
455 // Test if the feed need a update (update interval exceded).
456 if (DB_TYPE == "pgsql") {
457 $update_limit_qpart = "AND ((
458 ttrss_feeds.update_interval = 0
459 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
460 ) OR (
461 ttrss_feeds.update_interval > 0
462 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
463 ) OR ttrss_feeds.last_updated IS NULL
464 OR last_updated = '1970-01-01 00:00:00')";
465 } else {
466 $update_limit_qpart = "AND ((
467 ttrss_feeds.update_interval = 0
468 AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
469 ) OR (
470 ttrss_feeds.update_interval > 0
471 AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
472 ) OR ttrss_feeds.last_updated IS NULL
473 OR last_updated = '1970-01-01 00:00:00')";
474 }
475
476 // Test if feed is currently being updated by another process.
477 if (DB_TYPE == "pgsql") {
478 $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
479 } else {
480 $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
481 }
482
483 $random_qpart = sql_random_function();
484
fbe7cb0a
AD
485 $pdo = Db::pdo();
486
e1f1857d
AD
487 // we could be invoked from public.php with no active session
488 if ($_SESSION["uid"]) {
fbe7cb0a 489 $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]);
e1f1857d
AD
490 } else {
491 $owner_check_qpart = "";
492 }
493
8b83bf5f 494 // We search for feed needing update.
fbe7cb0a 495 $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
8b83bf5f
AD
496 FROM
497 ttrss_feeds, ttrss_users, ttrss_user_prefs
498 WHERE
499 ttrss_feeds.owner_uid = ttrss_users.id
500 AND ttrss_users.id = ttrss_user_prefs.owner_uid
501 AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
e1f1857d
AD
502 $owner_check_qpart
503 $update_limit_qpart
504 $updstart_thresh_qpart
8b83bf5f
AD
505 ORDER BY $random_qpart LIMIT 30");
506
8b83bf5f
AD
507 $num_updated = 0;
508
509 $tstart = time();
510
fbe7cb0a 511 while ($line = $res->fetch()) {
8b83bf5f
AD
512 $feed_id = $line["id"];
513
6b1a4ecd 514 if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
e6c886bf 515 RSSUtils::update_rss_feed($feed_id, true);
8b83bf5f
AD
516 ++$num_updated;
517 } else {
518 break;
519 }
520 }
521
cda55d67 522 // Purge orphans and cleanup tags
a230bf88 523 Article::purge_orphans();
9b736a20 524 //cleanup_tags(14, 50000);
cda55d67 525
8b83bf5f
AD
526 if ($num_updated > 0) {
527 print json_encode(array("message" => "UPDATE_COUNTERS",
528 "num_updated" => $num_updated));
529 } else {
530 print json_encode(array("message" => "NOTHING_TO_UPDATE"));
531 }
532
533 }
534
113c3dec 535 function updaterandomfeed() {
fbe7cb0a 536 RPC::updaterandomfeed_real();
113c3dec
AD
537 }
538
a42c55f0 539 private function markArticlesById($ids, $cmode) {
87d7e850 540
fbe7cb0a 541 $ids_qmarks = arr_qmarks($ids);
87d7e850
AD
542
543 if ($cmode == 0) {
fbe7cb0a
AD
544 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
545 marked = false, last_marked = NOW()
546 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 547 } else if ($cmode == 1) {
fbe7cb0a
AD
548 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
549 marked = true, last_marked = NOW()
550 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 551 } else {
fbe7cb0a
AD
552 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
553 marked = NOT marked,last_marked = NOW()
554 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 555 }
fbe7cb0a
AD
556
557 $sth->execute(array_merge($ids, [$_SESSION['uid']]));
87d7e850
AD
558 }
559
a42c55f0 560 private function publishArticlesById($ids, $cmode) {
87d7e850 561
fbe7cb0a 562 $ids_qmarks = arr_qmarks($ids);
87d7e850
AD
563
564 if ($cmode == 0) {
fbe7cb0a
AD
565 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
566 published = false, last_published = NOW()
567 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 568 } else if ($cmode == 1) {
fbe7cb0a
AD
569 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
570 published = true, last_published = NOW()
571 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 572 } else {
fbe7cb0a
AD
573 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
574 published = NOT published,last_published = NOW()
575 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
87d7e850 576 }
fbe7cb0a
AD
577
578 $sth->execute(array_merge($ids, [$_SESSION['uid']]));
87d7e850
AD
579 }
580
5defc29f 581 function getlinktitlebyid() {
fbe7cb0a 582 $id = $_REQUEST['id'];
7fc2e87e 583
fbe7cb0a
AD
584 $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
585 WHERE ref_id = ? AND ref_id = id AND owner_uid = ?");
586 $sth->execute([$id, $_SESSION['uid']]);
7fc2e87e 587
fbe7cb0a
AD
588 if ($row = $sth->fetch()) {
589 $link = $row['link'];
590 $title = $row['title'];
7fc2e87e 591
5defc29f 592 echo json_encode(array("link" => $link, "title" => $title));
7fc2e87e
AD
593 } else {
594 echo json_encode(array("error" => "ARTICLE_NOT_FOUND"));
595 }
596 }
597
f66492d3 598 function log() {
fbe7cb0a
AD
599 $msg = $_REQUEST['msg'];
600 $file = basename($_REQUEST['file']);
270c0a00 601 $line = (int) $_REQUEST['line'];
fbe7cb0a 602 $context = $_REQUEST['context'];
f66492d3 603
270c0a00 604 if ($msg) {
f66492d3 605 Logger::get()->log_error(E_USER_WARNING,
270c0a00 606 $msg, 'client-js:' . $file, $line, $context);
f66492d3 607
270c0a00
AD
608 echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
609 } else {
610 echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
611 }
f66492d3
AD
612
613 }
ea79a0e0 614}