]>
Commit | Line | Data |
---|---|---|
d5112468 | 1 | <?php |
369dbc19 | 2 | class RPC extends Handler_Protected { |
d5112468 | 3 | |
8484ce22 | 4 | function csrf_ignore($method) { |
6c2637d9 | 5 | $csrf_ignored = array("sanitycheck", "completelabels"); |
8484ce22 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
d5112468 AD |
10 | function setprofile() { |
11 | $id = db_escape_string($_REQUEST["id"]); | |
46da73c2 | 12 | |
d5112468 AD |
13 | $_SESSION["profile"] = $id; |
14 | $_SESSION["prefs_cache"] = array(); | |
15 | } | |
16 | ||
17 | function remprofiles() { | |
18 | $ids = explode(",", db_escape_string(trim($_REQUEST["ids"]))); | |
19 | ||
20 | foreach ($ids as $id) { | |
21 | if ($_SESSION["profile"] != $id) { | |
22 | db_query($this->link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
23 | owner_uid = " . $_SESSION["uid"]); | |
24 | } | |
25 | } | |
26 | } | |
27 | ||
28 | // Silent | |
29 | function addprofile() { | |
30 | $title = db_escape_string(trim($_REQUEST["title"])); | |
31 | if ($title) { | |
32 | db_query($this->link, "BEGIN"); | |
33 | ||
34 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
35 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
36 | ||
37 | if (db_num_rows($result) == 0) { | |
38 | ||
39 | db_query($this->link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
40 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
41 | ||
42 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles WHERE | |
43 | title = '$title'"); | |
44 | ||
45 | if (db_num_rows($result) != 0) { | |
46 | $profile_id = db_fetch_result($result, 0, "id"); | |
47 | ||
48 | if ($profile_id) { | |
49 | initialize_user_prefs($this->link, $_SESSION["uid"], $profile_id); | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | db_query($this->link, "COMMIT"); | |
55 | } | |
56 | } | |
57 | ||
58 | // Silent | |
59 | function saveprofile() { | |
60 | $id = db_escape_string($_REQUEST["id"]); | |
61 | $title = db_escape_string(trim($_REQUEST["value"])); | |
62 | ||
63 | if ($id == 0) { | |
64 | print __("Default profile"); | |
65 | return; | |
66 | } | |
67 | ||
68 | if ($title) { | |
69 | db_query($this->link, "BEGIN"); | |
70 | ||
71 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
72 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
73 | ||
74 | if (db_num_rows($result) == 0) { | |
75 | db_query($this->link, "UPDATE ttrss_settings_profiles | |
76 | SET title = '$title' WHERE id = '$id' AND | |
77 | owner_uid = " . $_SESSION["uid"]); | |
78 | print $title; | |
79 | } else { | |
80 | $result = db_query($this->link, "SELECT title FROM ttrss_settings_profiles | |
81 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
82 | print db_fetch_result($result, 0, "title"); | |
83 | } | |
84 | ||
85 | db_query($this->link, "COMMIT"); | |
86 | } | |
87 | } | |
88 | ||
89 | // Silent | |
90 | function remarchive() { | |
91 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
92 | ||
93 | foreach ($ids as $id) { | |
94 | $result = db_query($this->link, "DELETE FROM ttrss_archived_feeds WHERE | |
95 | (SELECT COUNT(*) FROM ttrss_user_entries | |
96 | WHERE orig_feed_id = '$id') = 0 AND | |
97 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
98 | ||
99 | $rc = db_affected_rows($this->link, $result); | |
100 | } | |
101 | } | |
102 | ||
103 | function addfeed() { | |
104 | $feed = db_escape_string($_REQUEST['feed']); | |
105 | $cat = db_escape_string($_REQUEST['cat']); | |
106 | $login = db_escape_string($_REQUEST['login']); | |
107 | $pass = db_escape_string($_REQUEST['pass']); | |
aa60999b | 108 | $need_auth = db_escape_string($_REQUEST['need_auth']) != ""; |
d5112468 | 109 | |
aa60999b | 110 | $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass, $need_auth); |
d5112468 AD |
111 | |
112 | print json_encode(array("result" => $rc)); | |
113 | } | |
114 | ||
d5112468 AD |
115 | function togglepref() { |
116 | $key = db_escape_string($_REQUEST["key"]); | |
117 | set_pref($this->link, $key, !get_pref($this->link, $key)); | |
118 | $value = get_pref($this->link, $key); | |
119 | ||
120 | print json_encode(array("param" =>$key, "value" => $value)); | |
121 | } | |
122 | ||
123 | function setpref() { | |
0380cfa9 | 124 | // set_pref escapes input, so no need to double escape it here |
74eef4fc AD |
125 | $key = $_REQUEST['key']; |
126 | $value = str_replace("\n", "<br/>", $_REQUEST['value']); | |
d5112468 | 127 | |
7e431502 | 128 | set_pref($this->link, $key, $value, $_SESSION['uid'], $key != 'USER_STYLESHEET'); |
d5112468 AD |
129 | |
130 | print json_encode(array("param" =>$key, "value" => $value)); | |
131 | } | |
132 | ||
133 | function mark() { | |
134 | $mark = $_REQUEST["mark"]; | |
135 | $id = db_escape_string($_REQUEST["id"]); | |
136 | ||
137 | if ($mark == "1") { | |
138 | $mark = "true"; | |
139 | } else { | |
140 | $mark = "false"; | |
141 | } | |
142 | ||
143 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark | |
144 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
145 | ||
146 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
147 | } | |
148 | ||
149 | function delete() { | |
150 | $ids = db_escape_string($_REQUEST["ids"]); | |
151 | ||
152 | $result = db_query($this->link, "DELETE FROM ttrss_user_entries | |
153 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
154 | ||
155 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
156 | } | |
157 | ||
158 | function unarchive() { | |
159 | $ids = db_escape_string($_REQUEST["ids"]); | |
160 | ||
161 | $result = db_query($this->link, "UPDATE ttrss_user_entries | |
162 | SET feed_id = orig_feed_id, orig_feed_id = NULL | |
163 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
164 | ||
165 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
166 | } | |
167 | ||
168 | function archive() { | |
169 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
170 | ||
171 | foreach ($ids as $id) { | |
172 | archive_article($this->link, $id, $_SESSION["uid"]); | |
173 | } | |
174 | ||
175 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
176 | } | |
177 | ||
178 | function publ() { | |
179 | $pub = $_REQUEST["pub"]; | |
180 | $id = db_escape_string($_REQUEST["id"]); | |
181 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
182 | ||
183 | if ($pub == "1") { | |
184 | $pub = "true"; | |
185 | } else { | |
186 | $pub = "false"; | |
187 | } | |
188 | ||
189 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET | |
46b78149 | 190 | published = $pub, last_read = NOW() |
d5112468 AD |
191 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
192 | ||
193 | $pubsub_result = false; | |
194 | ||
195 | if (PUBSUBHUBBUB_HUB) { | |
196 | $rss_link = get_self_url_prefix() . | |
197 | "/public.php?op=rss&id=-2&key=" . | |
198 | get_feed_access_key($this->link, -2, false); | |
199 | ||
200 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
201 | ||
202 | $pubsub_result = $p->publish_update($rss_link); | |
203 | } | |
204 | ||
205 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
206 | "pubsub_result" => $pubsub_result)); | |
207 | } | |
208 | ||
209 | function getAllCounters() { | |
210 | $last_article_id = (int) $_REQUEST["last_article_id"]; | |
211 | ||
212 | $reply = array(); | |
213 | ||
214 | if ($seq) $reply['seq'] = $seq; | |
215 | ||
216 | if ($last_article_id != getLastArticleId($this->link)) { | |
217 | $omode = $_REQUEST["omode"]; | |
46da73c2 | 218 | |
d5112468 AD |
219 | if ($omode != "T") |
220 | $reply['counters'] = getAllCounters($this->link, $omode); | |
221 | else | |
222 | $reply['counters'] = getGlobalCounters($this->link); | |
223 | } | |
224 | ||
225 | $reply['runtime-info'] = make_runtime_info($this->link); | |
226 | ||
227 | print json_encode($reply); | |
228 | } | |
229 | ||
230 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
231 | function catchupSelected() { | |
232 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
233 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
234 | ||
235 | catchupArticlesById($this->link, $ids, $cmode); | |
236 | ||
237 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
238 | } | |
239 | ||
240 | function markSelected() { | |
241 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
242 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
243 | ||
244 | markArticlesById($this->link, $ids, $cmode); | |
245 | ||
246 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
247 | } | |
248 | ||
249 | function publishSelected() { | |
250 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
251 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
252 | ||
253 | publishArticlesById($this->link, $ids, $cmode); | |
254 | ||
255 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
256 | } | |
257 | ||
258 | function sanityCheck() { | |
259 | $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; | |
260 | ||
261 | $reply = array(); | |
262 | ||
263 | $reply['error'] = sanity_check($this->link); | |
264 | ||
265 | if ($reply['error']['code'] == 0) { | |
266 | $reply['init-params'] = make_init_params($this->link); | |
267 | $reply['runtime-info'] = make_runtime_info($this->link); | |
268 | } | |
269 | ||
270 | print json_encode($reply); | |
271 | } | |
272 | ||
273 | function setArticleTags() { | |
d5112468 AD |
274 | |
275 | $id = db_escape_string($_REQUEST["id"]); | |
276 | ||
277 | $tags_str = db_escape_string($_REQUEST["tags_str"]); | |
278 | $tags = array_unique(trim_array(explode(",", $tags_str))); | |
279 | ||
280 | db_query($this->link, "BEGIN"); | |
281 | ||
282 | $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE | |
283 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
284 | ||
285 | if (db_num_rows($result) == 1) { | |
286 | ||
287 | $tags_to_cache = array(); | |
288 | ||
289 | $int_id = db_fetch_result($result, 0, "int_id"); | |
290 | ||
291 | db_query($this->link, "DELETE FROM ttrss_tags WHERE | |
292 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
293 | ||
294 | foreach ($tags as $tag) { | |
295 | $tag = sanitize_tag($tag); | |
296 | ||
297 | if (!tag_is_valid($tag)) { | |
298 | continue; | |
299 | } | |
300 | ||
301 | if (preg_match("/^[0-9]*$/", $tag)) { | |
302 | continue; | |
303 | } | |
304 | ||
305 | // print "<!-- $id : $int_id : $tag -->"; | |
306 | ||
307 | if ($tag != '') { | |
308 | db_query($this->link, "INSERT INTO ttrss_tags | |
309 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
310 | } | |
311 | ||
312 | array_push($tags_to_cache, $tag); | |
313 | } | |
314 | ||
315 | /* update tag cache */ | |
316 | ||
317 | sort($tags_to_cache); | |
318 | $tags_str = join(",", $tags_to_cache); | |
319 | ||
320 | db_query($this->link, "UPDATE ttrss_user_entries | |
321 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' | |
322 | AND owner_uid = " . $_SESSION["uid"]); | |
323 | } | |
324 | ||
325 | db_query($this->link, "COMMIT"); | |
326 | ||
d5112468 AD |
327 | $tags = get_article_tags($this->link, $id); |
328 | $tags_str = format_tags_string($tags, $id); | |
329 | $tags_str_full = join(", ", $tags); | |
330 | ||
331 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
332 | ||
333 | print json_encode(array("tags_str" => array("id" => $id, | |
334 | "content" => $tags_str, "content_full" => $tags_str_full))); | |
335 | } | |
336 | ||
337 | function regenOPMLKey() { | |
338 | update_feed_access_key($this->link, 'OPML:Publish', | |
339 | false, $_SESSION["uid"]); | |
340 | ||
341 | $new_link = opml_publish_url($this->link); | |
342 | ||
343 | print json_encode(array("link" => $new_link)); | |
344 | } | |
345 | ||
1b4d1a6b AD |
346 | function completeLabels() { |
347 | $search = db_escape_string($_REQUEST["search"]); | |
348 | ||
349 | $result = db_query($this->link, "SELECT DISTINCT caption FROM | |
350 | ttrss_labels2 | |
351 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
352 | LOWER(caption) LIKE LOWER('$search%') ORDER BY caption | |
353 | LIMIT 5"); | |
354 | ||
355 | print "<ul>"; | |
356 | while ($line = db_fetch_assoc($result)) { | |
357 | print "<li>" . $line["caption"] . "</li>"; | |
358 | } | |
359 | print "</ul>"; | |
360 | } | |
361 | ||
362 | ||
d5112468 AD |
363 | function completeTags() { |
364 | $search = db_escape_string($_REQUEST["search"]); | |
365 | ||
366 | $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
367 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
368 | tag_name LIKE '$search%' ORDER BY tag_name | |
369 | LIMIT 10"); | |
370 | ||
371 | print "<ul>"; | |
372 | while ($line = db_fetch_assoc($result)) { | |
373 | print "<li>" . $line["tag_name"] . "</li>"; | |
374 | } | |
375 | print "</ul>"; | |
376 | } | |
377 | ||
378 | function purge() { | |
379 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
380 | $days = sprintf("%d", $_REQUEST["days"]); | |
381 | ||
382 | foreach ($ids as $id) { | |
383 | ||
384 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
385 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
386 | ||
387 | if (db_num_rows($result) == 1) { | |
388 | purge_feed($this->link, $id, $days); | |
389 | } | |
390 | } | |
391 | } | |
392 | ||
393 | function getArticles() { | |
394 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
395 | $articles = array(); | |
396 | ||
397 | foreach ($ids as $id) { | |
398 | if ($id) { | |
399 | array_push($articles, format_article($this->link, $id, 0, false)); | |
400 | } | |
401 | } | |
402 | ||
403 | print json_encode($articles); | |
404 | } | |
405 | ||
406 | function checkDate() { | |
407 | $date = db_escape_string($_REQUEST["date"]); | |
408 | $date_parsed = strtotime($date); | |
409 | ||
410 | print json_encode(array("result" => (bool)$date_parsed, | |
411 | "date" => date("c", $date_parsed))); | |
412 | } | |
413 | ||
414 | function assigntolabel() { | |
4fdb8759 | 415 | return $this->labelops(true); |
d5112468 | 416 | } |
46da73c2 | 417 | |
d5112468 | 418 | function removefromlabel() { |
4fdb8759 | 419 | return $this->labelops(false); |
d5112468 | 420 | } |
46da73c2 | 421 | |
d5112468 AD |
422 | function labelops($assign) { |
423 | $reply = array(); | |
424 | ||
425 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
426 | $label_id = db_escape_string($_REQUEST["lid"]); | |
427 | ||
428 | $label = db_escape_string(label_find_caption($this->link, $label_id, | |
429 | $_SESSION["uid"])); | |
430 | ||
431 | $reply["info-for-headlines"] = array(); | |
432 | ||
433 | if ($label) { | |
434 | ||
435 | foreach ($ids as $id) { | |
436 | ||
437 | if ($assign) | |
438 | label_add_article($this->link, $id, $label, $_SESSION["uid"]); | |
439 | else | |
440 | label_remove_article($this->link, $id, $label, $_SESSION["uid"]); | |
441 | ||
442 | $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); | |
443 | ||
444 | array_push($reply["info-for-headlines"], | |
445 | array("id" => $id, "labels" => format_article_labels($labels, $id))); | |
446 | ||
447 | } | |
448 | } | |
449 | ||
450 | $reply["message"] = "UPDATE_COUNTERS"; | |
451 | ||
452 | print json_encode($reply); | |
453 | } | |
454 | ||
455 | function updateFeedBrowser() { | |
456 | $search = db_escape_string($_REQUEST["search"]); | |
457 | $limit = db_escape_string($_REQUEST["limit"]); | |
458 | $mode = (int) db_escape_string($_REQUEST["mode"]); | |
459 | ||
55c7f092 AD |
460 | require_once "feedbrowser.php"; |
461 | ||
d5112468 AD |
462 | print json_encode(array("content" => |
463 | make_feed_browser($this->link, $search, $limit, $mode), | |
464 | "mode" => $mode)); | |
465 | } | |
466 | ||
467 | // Silent | |
468 | function massSubscribe() { | |
469 | ||
470 | $payload = json_decode($_REQUEST["payload"], false); | |
471 | $mode = $_REQUEST["mode"]; | |
472 | ||
473 | if (!$payload || !is_array($payload)) return; | |
474 | ||
475 | if ($mode == 1) { | |
476 | foreach ($payload as $feed) { | |
477 | ||
478 | $title = db_escape_string($feed[0]); | |
479 | $feed_url = db_escape_string($feed[1]); | |
480 | ||
481 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
482 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
483 | ||
484 | if (db_num_rows($result) == 0) { | |
485 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
486 | (owner_uid,feed_url,title,cat_id,site_url) | |
487 | VALUES ('".$_SESSION["uid"]."', | |
488 | '$feed_url', '$title', NULL, '')"); | |
489 | } | |
490 | } | |
491 | } else if ($mode == 2) { | |
492 | // feed archive | |
493 | foreach ($payload as $id) { | |
494 | $result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds | |
495 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
496 | ||
497 | if (db_num_rows($result) != 0) { | |
498 | $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); | |
499 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
500 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
501 | ||
502 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
503 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
504 | ||
505 | if (db_num_rows($result) == 0) { | |
506 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
507 | (owner_uid,feed_url,title,cat_id,site_url) | |
508 | VALUES ('$id','".$_SESSION["uid"]."', | |
509 | '$feed_url', '$title', NULL, '$site_url')"); | |
510 | } | |
511 | } | |
512 | } | |
513 | } | |
514 | } | |
515 | ||
d5112468 AD |
516 | function catchupFeed() { |
517 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
518 | $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; | |
184f5195 | 519 | $max_id = (int) db_escape_string($_REQUEST['max_id']); |
d5112468 | 520 | |
184f5195 | 521 | catchup_feed($this->link, $feed_id, $is_cat, false, $max_id); |
d5112468 AD |
522 | |
523 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
524 | } | |
525 | ||
d5112468 AD |
526 | function quickAddCat() { |
527 | $cat = db_escape_string($_REQUEST["cat"]); | |
528 | ||
529 | add_feed_category($this->link, $cat); | |
530 | ||
531 | $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE | |
532 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); | |
533 | ||
534 | if (db_num_rows($result) == 1) { | |
535 | $id = db_fetch_result($result, 0, "id"); | |
536 | } else { | |
537 | $id = 0; | |
538 | } | |
539 | ||
540 | print_feed_cat_select($this->link, "cat_id", $id); | |
541 | } | |
542 | ||
543 | function regenFeedKey() { | |
544 | $feed_id = db_escape_string($_REQUEST['id']); | |
545 | $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; | |
546 | ||
547 | $new_key = update_feed_access_key($this->link, $feed_id, $is_cat); | |
548 | ||
549 | print json_encode(array("link" => $new_key)); | |
550 | } | |
551 | ||
552 | // Silent | |
553 | function clearKeys() { | |
554 | db_query($this->link, "DELETE FROM ttrss_access_keys WHERE | |
555 | owner_uid = " . $_SESSION["uid"]); | |
556 | } | |
557 | ||
558 | // Silent | |
559 | function clearArticleKeys() { | |
560 | db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE | |
561 | owner_uid = " . $_SESSION["uid"]); | |
562 | ||
563 | return; | |
564 | } | |
565 | ||
d5112468 AD |
566 | function verifyRegexp() { |
567 | $reg_exp = $_REQUEST["reg_exp"]; | |
568 | ||
569 | $status = @preg_match("/$reg_exp/i", "TEST") !== false; | |
570 | ||
571 | print json_encode(array("status" => $status)); | |
572 | } | |
573 | ||
19c73507 | 574 | /* function buttonPlugin() { |
369dbc19 | 575 | $pclass = "button_" . basename($_REQUEST['plugin']); |
f9ac31d6 AD |
576 | $method = $_REQUEST['plugin_method']; |
577 | ||
578 | if (class_exists($pclass)) { | |
579 | $plugin = new $pclass($this->link); | |
580 | if (method_exists($plugin, $method)) { | |
581 | return $plugin->$method(); | |
582 | } | |
d5112468 | 583 | } |
19c73507 | 584 | } */ |
d5112468 | 585 | |
d5112468 AD |
586 | function genHash() { |
587 | $hash = sha1(uniqid(rand(), true)); | |
588 | ||
589 | print json_encode(array("hash" => $hash)); | |
590 | } | |
33f0fdd0 AD |
591 | |
592 | function batchAddFeeds() { | |
593 | $cat_id = db_escape_string($_REQUEST['cat']); | |
594 | $feeds = explode("\n", db_escape_string($_REQUEST['feeds'])); | |
595 | $login = db_escape_string($_REQUEST['login']); | |
596 | $pass = db_escape_string($_REQUEST['pass']); | |
597 | $need_auth = db_escape_string($_REQUEST['need_auth']) != ""; | |
598 | ||
33f0fdd0 AD |
599 | foreach ($feeds as $feed) { |
600 | $feed = trim($feed); | |
601 | ||
602 | if (validate_feed_url($feed)) { | |
603 | ||
604 | db_query($this->link, "BEGIN"); | |
605 | ||
33f0fdd0 AD |
606 | if ($cat_id == "0" || !$cat_id) { |
607 | $cat_qpart = "NULL"; | |
608 | } else { | |
609 | $cat_qpart = "'$cat_id'"; | |
610 | } | |
611 | ||
612 | $result = db_query($this->link, | |
613 | "SELECT id FROM ttrss_feeds | |
614 | WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
615 | ||
616 | if (db_num_rows($result) == 0) { | |
617 | $result = db_query($this->link, | |
618 | "INSERT INTO ttrss_feeds | |
619 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method) | |
620 | VALUES ('".$_SESSION["uid"]."', '$feed', | |
19b3992b | 621 | '[Unknown]', $cat_qpart, '$login', '$pass', 0)"); |
33f0fdd0 AD |
622 | } |
623 | ||
624 | db_query($this->link, "COMMIT"); | |
625 | } | |
626 | } | |
627 | } | |
628 | ||
beb6ce27 | 629 | function setScore() { |
29064218 | 630 | $ids = db_escape_string($_REQUEST['id']); |
beb6ce27 AD |
631 | $score = (int)db_escape_string($_REQUEST['score']); |
632 | ||
633 | db_query($this->link, "UPDATE ttrss_user_entries SET | |
29064218 | 634 | score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
beb6ce27 AD |
635 | |
636 | print json_encode(array("id" => $id, | |
637 | "score_pic" => theme_image($link, get_score_pic($score)))); | |
638 | } | |
639 | ||
7d8f5657 AD |
640 | function setpanelmode() { |
641 | $wide = (int) $_REQUEST["wide"]; | |
642 | ||
643 | $_SESSION["widescreen"] = $wide; | |
644 | ||
645 | print json_encode(array("wide" => $wide)); | |
646 | } | |
647 | ||
8b83bf5f AD |
648 | function updaterandomfeed() { |
649 | // Test if the feed need a update (update interval exceded). | |
650 | if (DB_TYPE == "pgsql") { | |
651 | $update_limit_qpart = "AND (( | |
652 | ttrss_feeds.update_interval = 0 | |
653 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) | |
654 | ) OR ( | |
655 | ttrss_feeds.update_interval > 0 | |
656 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) | |
657 | ) OR ttrss_feeds.last_updated IS NULL | |
658 | OR last_updated = '1970-01-01 00:00:00')"; | |
659 | } else { | |
660 | $update_limit_qpart = "AND (( | |
661 | ttrss_feeds.update_interval = 0 | |
662 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) | |
663 | ) OR ( | |
664 | ttrss_feeds.update_interval > 0 | |
665 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) | |
666 | ) OR ttrss_feeds.last_updated IS NULL | |
667 | OR last_updated = '1970-01-01 00:00:00')"; | |
668 | } | |
669 | ||
670 | // Test if feed is currently being updated by another process. | |
671 | if (DB_TYPE == "pgsql") { | |
672 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; | |
673 | } else { | |
674 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; | |
675 | } | |
676 | ||
677 | $random_qpart = sql_random_function(); | |
678 | ||
679 | // We search for feed needing update. | |
680 | $result = db_query($this->link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id | |
681 | FROM | |
682 | ttrss_feeds, ttrss_users, ttrss_user_prefs | |
683 | WHERE | |
684 | ttrss_feeds.owner_uid = ttrss_users.id | |
685 | AND ttrss_users.id = ttrss_user_prefs.owner_uid | |
686 | AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' | |
687 | AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." | |
688 | $update_limit_qpart $updstart_thresh_qpart | |
689 | ORDER BY $random_qpart LIMIT 30"); | |
690 | ||
691 | $feed_id = -1; | |
692 | ||
693 | require_once "rssfuncs.php"; | |
694 | ||
695 | $num_updated = 0; | |
696 | ||
697 | $tstart = time(); | |
698 | ||
699 | while ($line = db_fetch_assoc($result)) { | |
700 | $feed_id = $line["id"]; | |
701 | ||
6b1a4ecd | 702 | if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
8b83bf5f AD |
703 | update_rss_feed($this->link, $feed_id, true); |
704 | ++$num_updated; | |
705 | } else { | |
706 | break; | |
707 | } | |
708 | } | |
709 | ||
710 | if ($num_updated > 0) { | |
711 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
712 | "num_updated" => $num_updated)); | |
713 | } else { | |
714 | print json_encode(array("message" => "NOTHING_TO_UPDATE")); | |
715 | } | |
716 | ||
717 | } | |
718 | ||
d5112468 AD |
719 | } |
720 | ?> |