]>
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"]);
72 if ($subop == "publ") {
74 $id = db_escape_string($_GET["id"]);
82 // FIXME this needs collision testing
84 $result = db_query($link, "UPDATE ttrss_user_entries SET published = $pub
85 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
88 if ($subop == "updateFeed") {
89 $feed_id = db_escape_string($_GET["feed"]);
91 $result = db_query($link,
92 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
93 AND owner_uid = " . $_SESSION["uid"]);
95 if (db_num_rows($result) > 0) {
96 $feed_url = db_fetch_result($result, 0, "feed_url");
97 update_rss_feed($link, $feed_url, $feed_id);
102 getFeedCounter($link, $feed_id);
104 print "</rpc-reply>";
109 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
111 if (ENABLE_UPDATE_DAEMON
) {
113 if ($subop == "forceUpdateAllFeeds") {
115 $result = db_query($link, "SELECT count(id) AS cid FROM
116 ttrss_scheduled_updates WHERE feed_id IS NULL AND
117 owner_uid = " . $_SESSION["uid"]);
119 $cid = db_fetch_result($result, 0, "cid");
123 db_query($link, "INSERT INTO ttrss_scheduled_updates
124 (owner_uid, feed_id, entered) VALUES
125 (".$_SESSION["uid"].", NULL, NOW())");
131 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
134 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
135 $global_unread = getGlobalUnread($link);
141 if ($global_unread_caller != $global_unread) {
143 $omode = $_GET["omode"];
145 if (!$omode) $omode = "tflc";
147 if (strchr($omode, "l")) getLabelCounters($link);
148 if (strchr($omode, "f")) getFeedCounters($link);
149 if (strchr($omode, "t")) getTagCounters($link);
150 if (strchr($omode, "c")) {
151 if (get_pref($link, 'ENABLE_FEED_CATS')) {
152 getCategoryCounters($link);
157 getGlobalCounters($link, $global_unread);
161 print_runtime_info($link);
163 print "</rpc-reply>";
167 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
168 if ($subop == "catchupSelected") {
170 $ids = split(",", db_escape_string($_GET["ids"]));
171 $cmode = sprintf("%d", $_GET["cmode"]);
173 catchupArticlesById($link, $ids, $cmode);
177 getAllCounters($link);
179 print_runtime_info($link);
180 print "</rpc-reply>";
183 if ($subop == "markSelected") {
185 $ids = split(",", db_escape_string($_GET["ids"]));
186 $cmode = sprintf("%d", $_GET["cmode"]);
188 markArticlesById($link, $ids, $cmode);
192 getAllCounters($link);
194 print_runtime_info($link);
195 print "</rpc-reply>";
198 if ($subop == "publishSelected") {
200 $ids = split(",", db_escape_string($_GET["ids"]));
201 $cmode = sprintf("%d", $_GET["cmode"]);
203 publishArticlesById($link, $ids, $cmode);
207 getAllCounters($link);
209 print_runtime_info($link);
210 print "</rpc-reply>";
213 if ($subop == "sanityCheck") {
215 if (sanity_check($link)) {
216 print "<error error-code=\"0\"/>";
217 print_init_params($link);
218 print_runtime_info($link);
220 # assign client-passed params to session
221 $_SESSION["client.userAgent"] = $_GET["ua"];
224 print "</rpc-reply>";
227 if ($subop == "globalPurge") {
230 global_purge_old_posts($link, true);
231 print "</rpc-reply>";
235 if ($subop == "getArticleLink") {
237 $id = db_escape_string($_GET["id"]);
239 $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
240 WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
242 if (db_num_rows($result) == 1) {
243 $link = strip_tags(db_fetch_result($result, 0, "link"));
244 print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
246 print "<rpc-reply><error>Article not found</error></rpc-reply>";
250 if ($subop == "setArticleTags") {
252 $id = db_escape_string($_GET["id"]);
254 $tags_str = db_escape_string($_GET["tags_str"]);
256 $tags = array_unique(trim_array(split(",", $tags_str)));
258 db_query($link, "BEGIN");
260 $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
261 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
263 if (db_num_rows($result) == 1) {
265 $int_id = db_fetch_result($result, 0, "int_id");
267 db_query($link, "DELETE FROM ttrss_tags WHERE
268 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
270 foreach ($tags as $tag) {
271 $tag = sanitize_tag($tag);
273 if (!tag_is_valid($tag)) {
277 if (preg_match("/^[0-9]*$/", $tag)) {
281 // print "<!-- $tag -->";
284 db_query($link, "INSERT INTO ttrss_tags
285 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
290 db_query($link, "COMMIT");
293 <message>$id</message>
298 if ($subop == "regenPubKey") {
302 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
304 $url_path = 'http://' . $_SERVER["HTTP_HOST"] . \
305 parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH
);
307 $new_link = $url_path . "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");
309 print "<link><![CDATA[$new_link]]></link>";
311 print "</rpc-reply>";
315 if ($subop == "logout") {