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