]>
git.wh0rd.org - tt-rss.git/blob - modules/backend-rpc.php
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 if ($global_unread_caller != $global_unread) {
170 $omode = $_GET["omode"];
172 if (!$omode) $omode = "tflc";
174 if (strchr($omode, "l")) getLabelCounters($link);
175 if (strchr($omode, "f")) getFeedCounters($link);
176 if (strchr($omode, "t")) getTagCounters($link);
177 if (strchr($omode, "c")) {
178 if (get_pref($link, 'ENABLE_FEED_CATS')) {
179 getCategoryCounters($link);
184 getGlobalCounters($link, $global_unread);
188 print_runtime_info($link);
190 print "</rpc-reply>";
195 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
196 if ($subop == "catchupSelected") {
198 $ids = split(",", db_escape_string($_GET["ids"]));
199 $cmode = sprintf("%d", $_GET["cmode"]);
201 catchupArticlesById($link, $ids, $cmode);
205 getAllCounters($link, $_GET["omode"]);
207 print_runtime_info($link);
208 print "</rpc-reply>";
213 if ($subop == "markSelected") {
215 $ids = split(",", db_escape_string($_GET["ids"]));
216 $cmode = sprintf("%d", $_GET["cmode"]);
218 markArticlesById($link, $ids, $cmode);
222 getAllCounters($link, $_GET["omode"]);
224 print_runtime_info($link);
225 print "</rpc-reply>";
230 if ($subop == "publishSelected") {
232 $ids = split(",", db_escape_string($_GET["ids"]));
233 $cmode = sprintf("%d", $_GET["cmode"]);
235 publishArticlesById($link, $ids, $cmode);
239 getAllCounters($link, $_GET["omode"]);
241 print_runtime_info($link);
242 print "</rpc-reply>";
247 if ($subop == "sanityCheck") {
249 if (sanity_check($link)) {
250 print "<error error-code=\"0\"/>";
251 print_init_params($link);
252 print_runtime_info($link);
254 # assign client-passed params to session
255 $_SESSION["client.userAgent"] = $_GET["ua"];
258 print "</rpc-reply>";
263 if ($subop == "globalPurge") {
266 global_purge_old_posts($link, true);
267 print "</rpc-reply>";
272 if ($subop == "getArticleLink") {
274 $id = db_escape_string($_GET["id"]);
276 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
277 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
279 if (db_num_rows($result) == 1) {
280 $link = strip_tags(db_fetch_result($result, 0, "link"));
281 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
283 print "<rpc-reply><error>Article not found</error></rpc-reply>";
289 if ($subop == "setArticleTags") {
291 $id = db_escape_string($_GET["id"]);
293 $tags_str = db_escape_string($_GET["tags_str"]);
295 $tags = array_unique(trim_array(split(",", $tags_str)));
297 db_query($link, "BEGIN");
299 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
300 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
302 if (db_num_rows($result) == 1) {
304 $int_id = db_fetch_result($result, 0, "int_id");
306 db_query($link, "DELETE FROM ttrss_tags WHERE
307 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
309 foreach ($tags as $tag) {
310 $tag = sanitize_tag($tag);
312 if (!tag_is_valid($tag)) {
316 if (preg_match("/^[0-9]*$/", $tag)) {
320 print "<!-- $id : $int_id : $tag -->";
323 db_query($link, "INSERT INTO ttrss_tags
324 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
329 db_query($link, "COMMIT");
332 <message>$id</message>
338 if ($subop == "regenPubKey") {
342 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
344 $new_link = article_publish_url($link);
346 print "<link><![CDATA[$new_link]]></link>";
348 print "</rpc-reply>";
353 if ($subop == "logout") {
359 if ($subop == "completeTags") {
361 $search = db_escape_string($_REQUEST["search"]);
363 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
364 WHERE owner_uid = '".$_SESSION["uid"]."' AND
365 tag_name LIKE '$search%' ORDER BY tag_name
369 while ($line = db_fetch_assoc($result)) {
370 print "<li>" . $line["tag_name"] . "</li>";
377 print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";