]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
2 | function handle_rpc_request($link) { |
3 | ||
4 | $subop = $_GET["subop"]; | |
5 | ||
6 | if ($subop == "setpref") { | |
7 | if (WEB_DEMO_MODE) { | |
8 | return; | |
9 | } | |
10 | ||
11 | print "<rpc-reply>"; | |
12 | ||
13 | $key = db_escape_string($_GET["key"]); | |
14 | $value = db_escape_string($_GET["value"]); | |
15 | ||
16 | set_pref($link, $key, $value); | |
17 | ||
18 | print "<param-set key=\"$key\" value=\"$value\"/>"; | |
19 | ||
20 | print "</rpc-reply>"; | |
21 | ||
22 | } | |
23 | ||
24 | if ($subop == "getLabelCounters") { | |
25 | $aid = $_GET["aid"]; | |
26 | print "<rpc-reply>"; | |
f54f515f | 27 | print "<counters>"; |
01b3e191 AD |
28 | getLabelCounters($link); |
29 | if ($aid) { | |
30 | getFeedCounter($link, $aid); | |
31 | } | |
f54f515f | 32 | print "</counters>"; |
01b3e191 AD |
33 | print "</rpc-reply>"; |
34 | } | |
35 | ||
36 | if ($subop == "getFeedCounters") { | |
37 | print "<rpc-reply>"; | |
f54f515f | 38 | print "<counters>"; |
01b3e191 | 39 | getFeedCounters($link); |
f54f515f | 40 | print "</counters>"; |
01b3e191 AD |
41 | print "</rpc-reply>"; |
42 | } | |
43 | ||
44 | if ($subop == "getAllCounters") { | |
45 | print "<rpc-reply>"; | |
f54f515f | 46 | print "<counters>"; |
01b3e191 | 47 | getAllCounters($link); |
f54f515f AD |
48 | print "</counters>"; |
49 | print_runtime_info($link); | |
01b3e191 AD |
50 | print "</rpc-reply>"; |
51 | } | |
52 | ||
53 | if ($subop == "mark") { | |
54 | $mark = $_GET["mark"]; | |
55 | $id = db_escape_string($_GET["id"]); | |
56 | ||
57 | if ($mark == "1") { | |
58 | $mark = "true"; | |
59 | } else { | |
60 | $mark = "false"; | |
61 | } | |
62 | ||
63 | // FIXME this needs collision testing | |
64 | ||
65 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
66 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
67 | } | |
68 | ||
69 | if ($subop == "updateFeed") { | |
70 | $feed_id = db_escape_string($_GET["feed"]); | |
71 | ||
72 | $result = db_query($link, | |
73 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
74 | AND owner_uid = " . $_SESSION["uid"]); | |
75 | ||
76 | if (db_num_rows($result) > 0) { | |
77 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
78 | update_rss_feed($link, $feed_url, $feed_id); | |
79 | } | |
80 | ||
f54f515f AD |
81 | print "<rpc-reply>"; |
82 | print "<counters>"; | |
01b3e191 | 83 | getFeedCounter($link, $feed_id); |
f54f515f | 84 | print "</counters>"; |
01b3e191 AD |
85 | print "</rpc-reply>"; |
86 | ||
87 | return; | |
88 | } | |
89 | ||
90 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
91 | ||
92 | if (ENABLE_UPDATE_DAEMON) { | |
93 | ||
94 | if ($subop == "forceUpdateAllFeeds") { | |
95 | ||
96 | $result = db_query($link, "SELECT count(id) AS cid FROM | |
97 | ttrss_scheduled_updates WHERE feed_id IS NULL AND | |
98 | owner_uid = " . $_SESSION["uid"]); | |
99 | ||
100 | $cid = db_fetch_result($result, 0, "cid"); | |
101 | ||
102 | if ($cid == 0) { | |
103 | ||
104 | db_query($link, "INSERT INTO ttrss_scheduled_updates | |
105 | (owner_uid, feed_id, entered) VALUES | |
106 | (".$_SESSION["uid"].", NULL, NOW())"); | |
107 | ||
108 | } | |
109 | } | |
110 | ||
111 | } else { | |
112 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); | |
113 | } | |
114 | ||
115 | $global_unread_caller = sprintf("%d", $_GET["uctr"]); | |
116 | $global_unread = getGlobalUnread($link); | |
117 | ||
118 | print "<rpc-reply>"; | |
119 | ||
f54f515f AD |
120 | print "<counters>"; |
121 | ||
01b3e191 AD |
122 | if ($global_unread_caller != $global_unread) { |
123 | ||
124 | $omode = $_GET["omode"]; | |
125 | ||
126 | if (!$omode) $omode = "tflc"; | |
127 | ||
128 | if (strchr($omode, "l")) getLabelCounters($link); | |
129 | if (strchr($omode, "f")) getFeedCounters($link); | |
130 | if (strchr($omode, "t")) getTagCounters($link); | |
131 | if (strchr($omode, "c")) { | |
132 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
133 | getCategoryCounters($link); | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | getGlobalCounters($link, $global_unread); | |
139 | ||
f54f515f AD |
140 | print "</counters>"; |
141 | ||
142 | print_runtime_info($link); | |
143 | ||
01b3e191 AD |
144 | print "</rpc-reply>"; |
145 | ||
146 | } | |
147 | ||
148 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
149 | if ($subop == "catchupSelected") { | |
150 | ||
151 | $ids = split(",", db_escape_string($_GET["ids"])); | |
152 | ||
153 | $cmode = sprintf("%d", $_GET["cmode"]); | |
154 | ||
155 | foreach ($ids as $id) { | |
156 | ||
157 | if ($cmode == 0) { | |
158 | db_query($link, "UPDATE ttrss_user_entries SET | |
159 | unread = false,last_read = NOW() | |
160 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
161 | } else if ($cmode == 1) { | |
162 | db_query($link, "UPDATE ttrss_user_entries SET | |
163 | unread = true | |
164 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
165 | } else { | |
166 | db_query($link, "UPDATE ttrss_user_entries SET | |
167 | unread = NOT unread,last_read = NOW() | |
168 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
169 | } | |
170 | } | |
171 | print "<rpc-reply>"; | |
f54f515f | 172 | print "<counters>"; |
01b3e191 | 173 | getAllCounters($link); |
f54f515f AD |
174 | print "</counters>"; |
175 | print_runtime_info($link); | |
01b3e191 AD |
176 | print "</rpc-reply>"; |
177 | } | |
178 | ||
179 | if ($subop == "markSelected") { | |
180 | ||
181 | $ids = split(",", db_escape_string($_GET["ids"])); | |
182 | ||
183 | $cmode = sprintf("%d", $_GET["cmode"]); | |
184 | ||
185 | foreach ($ids as $id) { | |
186 | ||
187 | if ($cmode == 0) { | |
188 | db_query($link, "UPDATE ttrss_user_entries SET | |
189 | marked = false | |
190 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
191 | } else if ($cmode == 1) { | |
192 | db_query($link, "UPDATE ttrss_user_entries SET | |
193 | marked = true | |
194 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
195 | } else { | |
196 | db_query($link, "UPDATE ttrss_user_entries SET | |
197 | marked = NOT marked | |
198 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
199 | } | |
200 | } | |
201 | print "<rpc-reply>"; | |
f54f515f | 202 | print "<counters>"; |
01b3e191 | 203 | getAllCounters($link); |
f54f515f AD |
204 | print "</counters>"; |
205 | print_runtime_info($link); | |
01b3e191 AD |
206 | print "</rpc-reply>"; |
207 | } | |
208 | ||
209 | if ($subop == "sanityCheck") { | |
3ac2b520 | 210 | print "<rpc-reply>"; |
01b3e191 AD |
211 | if (sanity_check($link)) { |
212 | print "<error error-code=\"0\"/>"; | |
3ac2b520 | 213 | print_init_params($link); |
f54f515f | 214 | print_runtime_info($link); |
01b3e191 | 215 | } |
3ac2b520 AD |
216 | print "</rpc-reply>"; |
217 | } | |
01b3e191 AD |
218 | |
219 | if ($subop == "globalPurge") { | |
220 | ||
221 | print "<rpc-reply>"; | |
222 | global_purge_old_posts($link, true); | |
223 | print "</rpc-reply>"; | |
224 | ||
225 | } | |
3ac2b520 AD |
226 | |
227 | if ($subop == "storeParam") { | |
228 | $key = $_GET["key"]; | |
229 | $value = $_GET["value"]; | |
230 | $_SESSION["stored-params"][$key] = $value; | |
0b7cb301 AD |
231 | print "<rpc-reply> |
232 | <message>$key : $value</message> | |
233 | </rpc-reply>"; | |
3ac2b520 | 234 | } |
01b3e191 AD |
235 | } |
236 | ?> |