]>
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\"/>";
24 if ($subop == "getLabelCounters") {
28 getLabelCounters($link);
30 getFeedCounter($link, $aid);
36 if ($subop == "getFeedCounters") {
39 getFeedCounters($link);
44 if ($subop == "getAllCounters") {
48 $omode = $_GET["omode"];
50 getAllCounters($link, $omode);
52 print_runtime_info($link);
56 if ($subop == "mark") {
57 $mark = $_GET["mark"];
58 $id = db_escape_string($_GET["id"]);
66 // FIXME this needs collision testing
68 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
69 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
71 print "<rpc-reply><mark>$id</mark></rpc-reply>";
75 if ($subop == "publ") {
77 $id = db_escape_string($_GET["id"]);
85 // FIXME this needs collision testing
87 $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub
88 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
90 print "<rpc-reply><pub>$id</pub></rpc-reply>";
94 if ($subop == "updateFeed") {
95 $feed_id = db_escape_string($_GET["feed"]);
97 $result = db_query($link,
98 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
99 AND owner_uid = " . $_SESSION["uid"]);
101 if (db_num_rows($result) > 0) {
102 $feed_url = db_fetch_result($result, 0, "feed_url");
103 update_rss_feed($link, $feed_url, $feed_id);
108 getFeedCounter($link, $feed_id);
110 print "</rpc-reply>";
115 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
117 if (ENABLE_UPDATE_DAEMON
) {
119 if ($subop == "forceUpdateAllFeeds") {
121 $result = db_query($link, "SELECT count(id) AS cid FROM
122 ttrss_scheduled_updates WHERE feed_id IS NULL AND
123 owner_uid = " . $_SESSION["uid"]);
125 $cid = db_fetch_result($result, 0, "cid");
129 db_query($link, "INSERT INTO ttrss_scheduled_updates
130 (owner_uid, feed_id, entered) VALUES
131 (".$_SESSION["uid"].", NULL, NOW())");
137 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
140 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
141 $global_unread = getGlobalUnread($link);
147 if ($global_unread_caller != $global_unread) {
149 $omode = $_GET["omode"];
151 if (!$omode) $omode = "tflc";
153 if (strchr($omode, "l")) getLabelCounters($link);
154 if (strchr($omode, "f")) getFeedCounters($link);
155 if (strchr($omode, "t")) getTagCounters($link);
156 if (strchr($omode, "c")) {
157 if (get_pref($link, 'ENABLE_FEED_CATS')) {
158 getCategoryCounters($link);
163 getGlobalCounters($link, $global_unread);
167 print_runtime_info($link);
169 print "</rpc-reply>";
173 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
174 if ($subop == "catchupSelected") {
176 $ids = split(",", db_escape_string($_GET["ids"]));
177 $cmode = sprintf("%d", $_GET["cmode"]);
179 catchupArticlesById($link, $ids, $cmode);
183 getAllCounters($link, $_GET["omode"]);
185 print_runtime_info($link);
186 print "</rpc-reply>";
189 if ($subop == "markSelected") {
191 $ids = split(",", db_escape_string($_GET["ids"]));
192 $cmode = sprintf("%d", $_GET["cmode"]);
194 markArticlesById($link, $ids, $cmode);
198 getAllCounters($link, $_GET["omode"]);
200 print_runtime_info($link);
201 print "</rpc-reply>";
204 if ($subop == "publishSelected") {
206 $ids = split(",", db_escape_string($_GET["ids"]));
207 $cmode = sprintf("%d", $_GET["cmode"]);
209 publishArticlesById($link, $ids, $cmode);
213 getAllCounters($link, $_GET["omode"]);
215 print_runtime_info($link);
216 print "</rpc-reply>";
219 if ($subop == "sanityCheck") {
221 if (sanity_check($link)) {
222 print "<error error-code=\"0\"/>";
223 print_init_params($link);
224 print_runtime_info($link);
226 # assign client-passed params to session
227 $_SESSION["client.userAgent"] = $_GET["ua"];
230 print "</rpc-reply>";
233 if ($subop == "globalPurge") {
236 global_purge_old_posts($link, true);
237 print "</rpc-reply>";
241 if ($subop == "getArticleLink") {
243 $id = db_escape_string($_GET["id"]);
245 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
246 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
248 if (db_num_rows($result) == 1) {
249 $link = strip_tags(db_fetch_result($result, 0, "link"));
250 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
252 print "<rpc-reply><error>Article not found</error></rpc-reply>";
256 if ($subop == "setArticleTags") {
258 $id = db_escape_string($_GET["id"]);
260 $tags_str = db_escape_string($_GET["tags_str"]);
262 $tags = array_unique(trim_array(split(",", $tags_str)));
264 db_query($link, "BEGIN");
266 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
267 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
269 if (db_num_rows($result) == 1) {
271 $int_id = db_fetch_result($result, 0, "int_id");
273 db_query($link, "DELETE FROM ttrss_tags WHERE
274 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
276 foreach ($tags as $tag) {
277 $tag = sanitize_tag($tag);
279 if (!tag_is_valid($tag)) {
283 if (preg_match("/^[0-9]*$/", $tag)) {
287 print "<!-- $id : $int_id : $tag -->";
290 db_query($link, "INSERT INTO ttrss_tags
291 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
296 db_query($link, "COMMIT");
299 <message>$id</message>
304 if ($subop == "regenPubKey") {
308 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
310 $new_link = article_publish_url($link);
312 print "<link><![CDATA[$new_link]]></link>";
314 print "</rpc-reply>";
318 if ($subop == "logout") {
323 if ($subop == "completeTags") {
325 $search = db_escape_string($_REQUEST["search"]);
327 $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
328 WHERE owner_uid = '".$_SESSION["uid"]."' AND
329 tag_name LIKE '$search%' ORDER BY tag_name
333 while ($line = db_fetch_assoc($result)) {
334 print "<li>" . $line["tag_name"] . "</li>";