]>
git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
2b3fe8726d128b027b16b835cf7941bef2a1fb7d
2 function handle_rpc_request($link) {
4 $subop = $_GET["subop"];
6 if ($subop == "setpref") {
13 $key = db_escape_string($_GET["key"]);
14 $value = db_escape_string($_GET["value"]);
16 set_pref($link, $key, $value);
18 print "<param-set key=\"$key\" value=\"$value\"/>";
25 if ($subop == "getLabelCounters") {
29 getLabelCounters($link);
31 getFeedCounter($link, $aid);
39 if ($subop == "getFeedCounters") {
42 getFeedCounters($link);
49 if ($subop == "getAllCounters") {
53 $omode = $_GET["omode"];
55 getAllCounters($link, $omode);
57 print_runtime_info($link);
63 if ($subop == "mark") {
64 $mark = $_GET["mark"];
65 $id = db_escape_string($_GET["id"]);
73 // FIXME this needs collision testing
75 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
76 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
78 print "<rpc-reply><counters>";
79 getGlobalCounters($link);
80 getLabelCounters($link);
81 if (get_pref($link, 'ENABLE_FEED_CATS')) {
82 getCategoryCounters($link);
84 print "</counters></rpc-reply>";
89 if ($subop == "publ") {
91 $id = db_escape_string($_GET["id"]);
99 // FIXME this needs collision testing
101 $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub
102 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
104 print "<rpc-reply><counters>";
105 getGlobalCounters($link);
106 getLabelCounters($link);
107 if (get_pref($link, 'ENABLE_FEED_CATS')) {
108 getCategoryCounters($link);
110 print "</counters></rpc-reply>";
115 if ($subop == "updateFeed") {
116 $feed_id = db_escape_string($_GET["feed"]);
118 $result = db_query($link,
119 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
120 AND owner_uid = " . $_SESSION["uid"]);
122 if (db_num_rows($result) > 0) {
123 $feed_url = db_fetch_result($result, 0, "feed_url");
124 update_rss_feed($link, $feed_url, $feed_id);
129 getFeedCounter($link, $feed_id);
131 print "</rpc-reply>";
136 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
138 if (ENABLE_UPDATE_DAEMON
) {
140 if ($subop == "forceUpdateAllFeeds") {
142 $result = db_query($link, "SELECT count(id) AS cid FROM
143 ttrss_scheduled_updates WHERE feed_id IS NULL AND
144 owner_uid = " . $_SESSION["uid"]);
146 $cid = db_fetch_result($result, 0, "cid");
150 db_query($link, "INSERT INTO ttrss_scheduled_updates
151 (owner_uid, feed_id, entered) VALUES
152 (".$_SESSION["uid"].", NULL, NOW())");
158 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
161 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
162 $global_unread = getGlobalUnread($link);
168 $omode = $_GET["omode"];
170 if (!$omode) $omode = "tflc";
172 if (strchr($omode, "l")) getLabelCounters($link);
174 if (strchr($omode, "c")) {
175 if (get_pref($link, 'ENABLE_FEED_CATS')) {
176 getCategoryCounters($link);
180 if ($global_unread_caller != $global_unread) {
182 if (strchr($omode, "f")) getFeedCounters($link);
183 if (strchr($omode, "t")) getTagCounters($link);
186 getGlobalCounters($link, $global_unread);
190 print_runtime_info($link);
192 print "</rpc-reply>";
197 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
198 if ($subop == "catchupSelected") {
200 $ids = split(",", db_escape_string($_GET["ids"]));
201 $cmode = sprintf("%d", $_GET["cmode"]);
203 catchupArticlesById($link, $ids, $cmode);
207 getAllCounters($link, $_GET["omode"]);
209 print_runtime_info($link);
210 print "</rpc-reply>";
215 if ($subop == "markSelected") {
217 $ids = split(",", db_escape_string($_GET["ids"]));
218 $cmode = sprintf("%d", $_GET["cmode"]);
220 markArticlesById($link, $ids, $cmode);
224 getAllCounters($link, $_GET["omode"]);
226 print_runtime_info($link);
227 print "</rpc-reply>";
232 if ($subop == "publishSelected") {
234 $ids = split(",", db_escape_string($_GET["ids"]));
235 $cmode = sprintf("%d", $_GET["cmode"]);
237 publishArticlesById($link, $ids, $cmode);
241 getAllCounters($link, $_GET["omode"]);
243 print_runtime_info($link);
244 print "</rpc-reply>";
249 if ($subop == "sanityCheck") {
251 if (sanity_check($link)) {
252 print "<error error-code=\"0\"/>";
253 print_init_params($link);
254 print_runtime_info($link);
256 # assign client-passed params to session
257 $_SESSION["client.userAgent"] = $_GET["ua"];
260 print "</rpc-reply>";
265 if ($subop == "globalPurge") {
268 global_purge_old_posts($link, true);
269 print "</rpc-reply>";
274 if ($subop == "getArticleLink") {
276 $id = db_escape_string($_GET["id"]);
278 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
279 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
281 if (db_num_rows($result) == 1) {
282 $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link")));
283 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
285 print "<rpc-reply><error>Article not found</error></rpc-reply>";
291 if ($subop == "setArticleTags") {
293 $id = db_escape_string($_GET["id"]);
295 $tags_str = db_escape_string($_GET["tags_str"]);
297 $tags = array_unique(trim_array(split(",", $tags_str)));
299 db_query($link, "BEGIN");
301 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
302 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
304 if (db_num_rows($result) == 1) {
306 $int_id = db_fetch_result($result, 0, "int_id");
308 db_query($link, "DELETE FROM ttrss_tags WHERE
309 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
311 foreach ($tags as $tag) {
312 $tag = sanitize_tag($tag);
314 if (!tag_is_valid($tag)) {
318 if (preg_match("/^[0-9]*$/", $tag)) {
322 print "<!-- $id : $int_id : $tag -->";
325 db_query($link, "INSERT INTO ttrss_tags
326 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
331 db_query($link, "COMMIT");
334 <message>$id</message>
340 if ($subop == "regenPubKey") {
344 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
346 $new_link = article_publish_url($link);
348 print "<link><![CDATA[$new_link]]></link>";
350 print "</rpc-reply>";
355 if ($subop == "logout") {
361 if ($subop == "completeTags") {
363 $search = db_escape_string($_REQUEST["search"]);
365 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
366 WHERE owner_uid = '".$_SESSION["uid"]."' AND
367 tag_name LIKE '$search%' ORDER BY tag_name
371 while ($line = db_fetch_assoc($result)) {
372 print "<li>" . $line["tag_name"] . "</li>";
379 if ($subop == "purge") {
380 $ids = split(",", db_escape_string($_GET["ids"]));
381 $days = sprintf("%d", $_GET["days"]);
385 print "<message><![CDATA[";
387 foreach ($ids as $id) {
389 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
390 id = '$id' AND owner_uid = ".$_SESSION["uid"]);
392 if (db_num_rows($result) == 1) {
393 purge_feed($link, $id, $days, true);
397 print "]]></message>";
399 print "</rpc-reply>";
404 if ($subop == "setScore") {
405 $id = db_escape_string($_REQUEST["id"]);
406 $score = sprintf("%d", $_REQUEST["score"]);
408 $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score'
409 WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
411 print "<rpc-reply><message>Acknowledged.</message></rpc-reply>";
417 if ($subop == "getArticles") {
418 $ids = split(",", db_escape_string($_REQUEST["ids"]));
422 foreach ($ids as $id) {
424 outputArticleXML($link, $id, 0, false);
427 print "</rpc-reply>";
432 print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";