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