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