]> git.wh0rd.org - tt-rss.git/blame - classes/rpc.php
enable manual filters to work on complete html content
[tt-rss.git] / classes / rpc.php
CommitLineData
d5112468 1<?php
369dbc19 2class RPC extends Handler_Protected {
d5112468 3
8484ce22 4 function csrf_ignore($method) {
8361e724 5 $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "sharepopup");
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
429 function completeTags() {
430 $search = db_escape_string($_REQUEST["search"]);
431
432 $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags
433 WHERE owner_uid = '".$_SESSION["uid"]."' AND
434 tag_name LIKE '$search%' ORDER BY tag_name
435 LIMIT 10");
436
437 print "<ul>";
438 while ($line = db_fetch_assoc($result)) {
439 print "<li>" . $line["tag_name"] . "</li>";
440 }
441 print "</ul>";
442 }
443
444 function purge() {
445 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
446 $days = sprintf("%d", $_REQUEST["days"]);
447
448 foreach ($ids as $id) {
449
450 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
451 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
452
453 if (db_num_rows($result) == 1) {
454 purge_feed($this->link, $id, $days);
455 }
456 }
457 }
458
459 function getArticles() {
460 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
461 $articles = array();
462
463 foreach ($ids as $id) {
464 if ($id) {
465 array_push($articles, format_article($this->link, $id, 0, false));
466 }
467 }
468
469 print json_encode($articles);
470 }
471
472 function checkDate() {
473 $date = db_escape_string($_REQUEST["date"]);
474 $date_parsed = strtotime($date);
475
476 print json_encode(array("result" => (bool)$date_parsed,
477 "date" => date("c", $date_parsed)));
478 }
479
480 function assigntolabel() {
4fdb8759 481 return $this->labelops(true);
d5112468 482 }
46da73c2 483
d5112468 484 function removefromlabel() {
4fdb8759 485 return $this->labelops(false);
d5112468 486 }
46da73c2 487
d5112468
AD
488 function labelops($assign) {
489 $reply = array();
490
491 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
492 $label_id = db_escape_string($_REQUEST["lid"]);
493
494 $label = db_escape_string(label_find_caption($this->link, $label_id,
495 $_SESSION["uid"]));
496
497 $reply["info-for-headlines"] = array();
498
499 if ($label) {
500
501 foreach ($ids as $id) {
502
503 if ($assign)
504 label_add_article($this->link, $id, $label, $_SESSION["uid"]);
505 else
506 label_remove_article($this->link, $id, $label, $_SESSION["uid"]);
507
508 $labels = get_article_labels($this->link, $id, $_SESSION["uid"]);
509
510 array_push($reply["info-for-headlines"],
511 array("id" => $id, "labels" => format_article_labels($labels, $id)));
512
513 }
514 }
515
516 $reply["message"] = "UPDATE_COUNTERS";
517
518 print json_encode($reply);
519 }
520
521 function updateFeedBrowser() {
522 $search = db_escape_string($_REQUEST["search"]);
523 $limit = db_escape_string($_REQUEST["limit"]);
524 $mode = (int) db_escape_string($_REQUEST["mode"]);
525
526 print json_encode(array("content" =>
527 make_feed_browser($this->link, $search, $limit, $mode),
528 "mode" => $mode));
529 }
530
531 // Silent
532 function massSubscribe() {
533
534 $payload = json_decode($_REQUEST["payload"], false);
535 $mode = $_REQUEST["mode"];
536
537 if (!$payload || !is_array($payload)) return;
538
539 if ($mode == 1) {
540 foreach ($payload as $feed) {
541
542 $title = db_escape_string($feed[0]);
543 $feed_url = db_escape_string($feed[1]);
544
545 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
546 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
547
548 if (db_num_rows($result) == 0) {
549 $result = db_query($this->link, "INSERT INTO ttrss_feeds
550 (owner_uid,feed_url,title,cat_id,site_url)
551 VALUES ('".$_SESSION["uid"]."',
552 '$feed_url', '$title', NULL, '')");
553 }
554 }
555 } else if ($mode == 2) {
556 // feed archive
557 foreach ($payload as $id) {
558 $result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
559 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
560
561 if (db_num_rows($result) != 0) {
562 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
563 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
564 $title = db_escape_string(db_fetch_result($result, 0, "title"));
565
566 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
567 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
568
569 if (db_num_rows($result) == 0) {
570 $result = db_query($this->link, "INSERT INTO ttrss_feeds
571 (owner_uid,feed_url,title,cat_id,site_url)
572 VALUES ('$id','".$_SESSION["uid"]."',
573 '$feed_url', '$title', NULL, '$site_url')");
574 }
575 }
576 }
577 }
578 }
579
580 function digestgetcontents() {
581 $article_id = db_escape_string($_REQUEST['article_id']);
582
583 $result = db_query($this->link, "SELECT content,title,link,marked,published
584 FROM ttrss_entries, ttrss_user_entries
585 WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
586
b3682750 587 $content = sanitize($this->link, db_fetch_result($result, 0, "content"));
d5112468
AD
588 $title = strip_tags(db_fetch_result($result, 0, "title"));
589 $article_url = htmlspecialchars(db_fetch_result($result, 0, "link"));
590 $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked"));
591 $published = sql_bool_to_bool(db_fetch_result($result, 0, "published"));
592
593 print json_encode(array("article" =>
594 array("id" => $article_id, "url" => $article_url,
595 "tags" => get_article_tags($this->link, $article_id),
596 "marked" => $marked, "published" => $published,
597 "title" => $title, "content" => $content)));
598 }
599
600 function digestupdate() {
601 $feed_id = db_escape_string($_REQUEST['feed_id']);
602 $offset = db_escape_string($_REQUEST['offset']);
603 $seq = db_escape_string($_REQUEST['seq']);
604
605 if (!$feed_id) $feed_id = -4;
606 if (!$offset) $offset = 0;
607
608 $reply = array();
609
610 $reply['seq'] = $seq;
611
612 $headlines = api_get_headlines($this->link, $feed_id, 30, $offset,
613 '', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0);
614
615 $reply['headlines'] = array();
616 $reply['headlines']['title'] = getFeedTitle($this->link, $feed_id);
617 $reply['headlines']['content'] = $headlines;
618
619 print json_encode($reply);
620 }
621
622 function digestinit() {
623 $tmp_feeds = api_get_feeds($this->link, -4, true, false, 0);
624
625 $feeds = array();
626
627 foreach ($tmp_feeds as $f) {
628 if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
629 }
630
631 print json_encode(array("feeds" => $feeds));
632 }
633
634 function catchupFeed() {
635 $feed_id = db_escape_string($_REQUEST['feed_id']);
636 $is_cat = db_escape_string($_REQUEST['is_cat']) == "true";
184f5195 637 $max_id = (int) db_escape_string($_REQUEST['max_id']);
d5112468 638
184f5195 639 catchup_feed($this->link, $feed_id, $is_cat, false, $max_id);
d5112468
AD
640
641 print json_encode(array("message" => "UPDATE_COUNTERS"));
642 }
643
d5112468
AD
644 function quickAddCat() {
645 $cat = db_escape_string($_REQUEST["cat"]);
646
647 add_feed_category($this->link, $cat);
648
649 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
650 title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
651
652 if (db_num_rows($result) == 1) {
653 $id = db_fetch_result($result, 0, "id");
654 } else {
655 $id = 0;
656 }
657
658 print_feed_cat_select($this->link, "cat_id", $id);
659 }
660
661 function regenFeedKey() {
662 $feed_id = db_escape_string($_REQUEST['id']);
663 $is_cat = db_escape_string($_REQUEST['is_cat']) == "true";
664
665 $new_key = update_feed_access_key($this->link, $feed_id, $is_cat);
666
667 print json_encode(array("link" => $new_key));
668 }
669
670 // Silent
671 function clearKeys() {
672 db_query($this->link, "DELETE FROM ttrss_access_keys WHERE
673 owner_uid = " . $_SESSION["uid"]);
674 }
675
676 // Silent
677 function clearArticleKeys() {
678 db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE
679 owner_uid = " . $_SESSION["uid"]);
680
681 return;
682 }
683
d5112468
AD
684 function verifyRegexp() {
685 $reg_exp = $_REQUEST["reg_exp"];
686
687 $status = @preg_match("/$reg_exp/i", "TEST") !== false;
688
689 print json_encode(array("status" => $status));
690 }
691
f9ac31d6 692 function buttonPlugin() {
369dbc19 693 $pclass = "button_" . basename($_REQUEST['plugin']);
f9ac31d6
AD
694 $method = $_REQUEST['plugin_method'];
695
696 if (class_exists($pclass)) {
697 $plugin = new $pclass($this->link);
698 if (method_exists($plugin, $method)) {
699 return $plugin->$method();
700 }
d5112468 701 }
d5112468
AD
702 }
703
d5112468
AD
704 function genHash() {
705 $hash = sha1(uniqid(rand(), true));
706
707 print json_encode(array("hash" => $hash));
708 }
33f0fdd0
AD
709
710 function batchAddFeeds() {
711 $cat_id = db_escape_string($_REQUEST['cat']);
712 $feeds = explode("\n", db_escape_string($_REQUEST['feeds']));
713 $login = db_escape_string($_REQUEST['login']);
714 $pass = db_escape_string($_REQUEST['pass']);
715 $need_auth = db_escape_string($_REQUEST['need_auth']) != "";
716
33f0fdd0
AD
717 foreach ($feeds as $feed) {
718 $feed = trim($feed);
719
720 if (validate_feed_url($feed)) {
721
722 db_query($this->link, "BEGIN");
723
304aadb9 724 $update_method = 0;
33f0fdd0
AD
725
726 if ($cat_id == "0" || !$cat_id) {
727 $cat_qpart = "NULL";
728 } else {
729 $cat_qpart = "'$cat_id'";
730 }
731
732 $result = db_query($this->link,
733 "SELECT id FROM ttrss_feeds
734 WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
735
736 if (db_num_rows($result) == 0) {
737 $result = db_query($this->link,
738 "INSERT INTO ttrss_feeds
739 (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method)
740 VALUES ('".$_SESSION["uid"]."', '$feed',
741 '[Unknown]', $cat_qpart, '$login', '$pass', '$update_method')");
742 }
743
744 db_query($this->link, "COMMIT");
745 }
746 }
747 }
748
d5112468
AD
749}
750?>