]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
01b3e191 AD |
2 | function handle_rpc_request($link) { |
3 | ||
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
6237ea05 | 5 | $seq = (int) $_REQUEST["seq"]; |
01b3e191 | 6 | |
d9084cf2 AD |
7 | if ($subop == "setprofile") { |
8 | $id = db_escape_string($_REQUEST["id"]); | |
9 | ||
10 | $_SESSION["profile"] = $id; | |
11 | $_SESSION["prefs_cache"] = array(); | |
12 | return; | |
13 | } | |
14 | ||
15 | if ($subop == "remprofiles") { | |
16 | $ids = split(",", db_escape_string(trim($_REQUEST["ids"]))); | |
17 | ||
18 | foreach ($ids as $id) { | |
19 | if ($_SESSION["profile"] != $id) { | |
20 | db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
21 | owner_uid = " . $_SESSION["uid"]); | |
22 | } | |
23 | } | |
24 | return; | |
25 | } | |
26 | ||
27 | if ($subop == "addprofile") { | |
28 | $title = db_escape_string(trim($_REQUEST["title"])); | |
29 | if ($title) { | |
30 | db_query($link, "BEGIN"); | |
31 | ||
32 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
33 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
34 | ||
35 | if (db_num_rows($result) == 0) { | |
36 | ||
37 | db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
38 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
39 | ||
40 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE | |
41 | title = '$title'"); | |
42 | ||
43 | if (db_num_rows($result) != 0) { | |
44 | $profile_id = db_fetch_result($result, 0, "id"); | |
45 | ||
46 | if ($profile_id) { | |
47 | initialize_user_prefs($link, $_SESSION["uid"], $profile_id); | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | db_query($link, "COMMIT"); | |
53 | } | |
54 | return; | |
55 | } | |
56 | ||
57 | if ($subop == "saveprofile") { | |
58 | $id = db_escape_string($_REQUEST["id"]); | |
59 | $title = db_escape_string(trim($_REQUEST["value"])); | |
60 | ||
61 | if ($id == 0) { | |
62 | print __("Default profile"); | |
63 | return; | |
64 | } | |
65 | ||
66 | if ($title) { | |
67 | db_query($link, "BEGIN"); | |
68 | ||
69 | $result = db_query($link, "SELECT id FROM ttrss_settings_profiles | |
70 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
71 | ||
72 | if (db_num_rows($result) == 0) { | |
73 | db_query($link, "UPDATE ttrss_settings_profiles | |
74 | SET title = '$title' WHERE id = '$id' AND | |
75 | owner_uid = " . $_SESSION["uid"]); | |
76 | print $title; | |
77 | } else { | |
78 | $result = db_query($link, "SELECT title FROM ttrss_settings_profiles | |
79 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
80 | print db_fetch_result($result, 0, "title"); | |
81 | } | |
82 | ||
83 | db_query($link, "COMMIT"); | |
84 | } | |
85 | return; | |
86 | } | |
87 | ||
ef88b1cc AD |
88 | if ($subop == "remarchive") { |
89 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
90 | ||
91 | print "<rpc-reply>"; | |
92 | ||
93 | foreach ($ids as $id) { | |
94 | $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE | |
95 | (SELECT COUNT(*) FROM ttrss_user_entries | |
96 | WHERE orig_feed_id = '$id') = 0 AND | |
97 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
98 | ||
99 | $rc = db_affected_rows($link, $result); | |
100 | ||
101 | print "<feed id='$id' rc='$rc'/>"; | |
102 | ||
103 | } | |
104 | ||
105 | print "</rpc-reply>"; | |
106 | ||
107 | return; | |
108 | } | |
109 | ||
a5819bb3 AD |
110 | if ($subop == "addfeed") { |
111 | ||
112 | $feed = db_escape_string($_REQUEST['feed']); | |
113 | $cat = db_escape_string($_REQUEST['cat']); | |
114 | $login = db_escape_string($_REQUEST['login']); | |
115 | $pass = db_escape_string($_REQUEST['pass']); | |
116 | ||
117 | $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass); | |
118 | ||
119 | print "<rpc-reply>"; | |
120 | print "<result code='$rc'/>"; | |
121 | print "</rpc-reply>"; | |
122 | ||
123 | return; | |
124 | ||
125 | } | |
126 | ||
f0266f51 CW |
127 | if ($subop == "extractfeedurls") { |
128 | print "<rpc-reply>"; | |
129 | ||
130 | $urls = get_feeds_from_html($_REQUEST['url']); | |
131 | print "<urls><![CDATA[" . json_encode($urls) . "]]></urls>"; | |
132 | ||
133 | print "</rpc-reply>"; | |
134 | return; | |
135 | } | |
136 | ||
8a3e0b1a | 137 | if ($subop == "togglepref") { |
74d12bab | 138 | header("Content-Type: text/plain"); |
8a3e0b1a AD |
139 | |
140 | $key = db_escape_string($_REQUEST["key"]); | |
8a3e0b1a | 141 | set_pref($link, $key, !get_pref($link, $key)); |
8a3e0b1a | 142 | $value = get_pref($link, $key); |
01b3e191 | 143 | |
74d12bab | 144 | print json_encode(array("param" =>$key, "value" => $value)); |
8a3e0b1a AD |
145 | return; |
146 | } | |
147 | ||
148 | if ($subop == "setpref") { | |
01b3e191 AD |
149 | print "<rpc-reply>"; |
150 | ||
b4e75b2a AD |
151 | $key = db_escape_string($_REQUEST["key"]); |
152 | $value = db_escape_string($_REQUEST["value"]); | |
01b3e191 AD |
153 | |
154 | set_pref($link, $key, $value); | |
155 | ||
156 | print "<param-set key=\"$key\" value=\"$value\"/>"; | |
157 | ||
158 | print "</rpc-reply>"; | |
159 | ||
85bd574b | 160 | return; |
01b3e191 AD |
161 | } |
162 | ||
01b3e191 | 163 | if ($subop == "mark") { |
74d12bab AD |
164 | header("Content-Type: text/plain"); |
165 | ||
b4e75b2a AD |
166 | $mark = $_REQUEST["mark"]; |
167 | $id = db_escape_string($_REQUEST["id"]); | |
01b3e191 AD |
168 | |
169 | if ($mark == "1") { | |
170 | $mark = "true"; | |
171 | } else { | |
172 | $mark = "false"; | |
173 | } | |
174 | ||
175 | // FIXME this needs collision testing | |
176 | ||
177 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
178 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
49aa6de9 | 179 | |
74d12bab | 180 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
85bd574b | 181 | return; |
01b3e191 AD |
182 | } |
183 | ||
e04c18a2 | 184 | if ($subop == "delete") { |
74d12bab AD |
185 | header("Content-Type: text/plain"); |
186 | ||
b4e75b2a | 187 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
188 | |
189 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
190 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
191 | ||
74d12bab | 192 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
e04c18a2 AD |
193 | return; |
194 | } | |
195 | ||
196 | if ($subop == "unarchive") { | |
74d12bab AD |
197 | header("Content-Type: text/plain"); |
198 | ||
b4e75b2a | 199 | $ids = db_escape_string($_REQUEST["ids"]); |
e04c18a2 AD |
200 | |
201 | $result = db_query($link, "UPDATE ttrss_user_entries | |
ef83538d | 202 | SET feed_id = orig_feed_id, orig_feed_id = NULL |
e04c18a2 AD |
203 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
204 | ||
74d12bab | 205 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
e04c18a2 AD |
206 | return; |
207 | } | |
208 | ||
209 | if ($subop == "archive") { | |
74d12bab AD |
210 | header("Content-Type: text/plain"); |
211 | ||
b4e75b2a | 212 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
e04c18a2 | 213 | |
16fdac16 AD |
214 | foreach ($ids as $id) { |
215 | archive_article($link, $id, $_SESSION["uid"]); | |
216 | } | |
e04c18a2 | 217 | |
74d12bab | 218 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
e04c18a2 AD |
219 | return; |
220 | } | |
221 | ||
222 | ||
e4f4b46f | 223 | if ($subop == "publ") { |
c7e51de1 AD |
224 | $pub = $_REQUEST["pub"]; |
225 | $id = db_escape_string($_REQUEST["id"]); | |
226 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
e4f4b46f AD |
227 | |
228 | if ($pub == "1") { | |
0a8011eb | 229 | $pub = "true"; |
e4f4b46f AD |
230 | } else { |
231 | $pub = "false"; | |
232 | } | |
233 | ||
c7e51de1 AD |
234 | if ($note != 'undefined') { |
235 | $note_qpart = "note = '$note',"; | |
236 | } | |
237 | ||
e4f4b46f AD |
238 | // FIXME this needs collision testing |
239 | ||
c7e51de1 AD |
240 | $result = db_query($link, "UPDATE ttrss_user_entries SET |
241 | $note_qpart | |
242 | published = $pub | |
e4f4b46f | 243 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
49aa6de9 | 244 | |
c7e51de1 AD |
245 | |
246 | print "<rpc-reply>"; | |
247 | ||
c7e51de1 AD |
248 | if ($note != 'undefined') { |
249 | $note_size = strlen($note); | |
250 | print "<note id=\"$id\" size=\"$note_size\">"; | |
251 | print "<![CDATA[" . format_article_note($id, $note) . "]]>"; | |
252 | print "</note>"; | |
253 | } | |
254 | ||
f8fb4498 AD |
255 | print "<message>UPDATE_COUNTERS</message>"; |
256 | ||
c7e51de1 | 257 | print "</rpc-reply>"; |
49aa6de9 | 258 | |
85bd574b | 259 | return; |
e4f4b46f AD |
260 | } |
261 | ||
74d12bab | 262 | /* if ($subop == "updateFeed") { |
b4e75b2a | 263 | $feed_id = db_escape_string($_REQUEST["feed"]); |
01b3e191 | 264 | |
c633e370 | 265 | update_rss_feed($link, $feed_id); |
01b3e191 | 266 | |
f8fb4498 AD |
267 | print "<rpc-reply>"; |
268 | print "<message>UPDATE_COUNTERS</message>"; | |
01b3e191 | 269 | print "</rpc-reply>"; |
f8fb4498 | 270 | |
01b3e191 | 271 | return; |
74d12bab | 272 | } */ |
01b3e191 | 273 | |
773adf8b | 274 | if ($subop == "updateAllFeeds" || $subop == "getAllCounters") { |
f8fb4498 | 275 | |
563b9c78 AD |
276 | header("Content-Type: text/plain"); |
277 | ||
f8fb4498 | 278 | $last_article_id = (int) $_REQUEST["last_article_id"]; |
01b3e191 | 279 | |
563b9c78 | 280 | $reply = array(); |
01b3e191 | 281 | |
563b9c78 | 282 | if ($seq) $reply['seq'] = $seq; |
6237ea05 | 283 | |
f8fb4498 | 284 | if ($last_article_id != getLastArticleId($link)) { |
6a7817c1 | 285 | $omode = $_REQUEST["omode"]; |
f8fb4498 AD |
286 | |
287 | if ($omode != "T") | |
563b9c78 | 288 | $reply['counters'] = getAllCounters($link, $omode); |
f8fb4498 | 289 | else |
563b9c78 | 290 | $reply['counters'] = getGlobalCounters($link); |
a06d0e5a AD |
291 | } |
292 | ||
563b9c78 | 293 | $reply['runtime-info'] = make_runtime_info($link); |
f54f515f | 294 | |
01b3e191 | 295 | |
563b9c78 | 296 | print json_encode($reply); |
85bd574b | 297 | return; |
01b3e191 | 298 | } |
472782e8 | 299 | |
01b3e191 AD |
300 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
301 | if ($subop == "catchupSelected") { | |
74d12bab | 302 | header("Content-Type: text/plain"); |
01b3e191 | 303 | |
2855ee88 AD |
304 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
305 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 306 | |
472782e8 | 307 | catchupArticlesById($link, $ids, $cmode); |
01b3e191 | 308 | |
74d12bab | 309 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
85bd574b | 310 | return; |
01b3e191 AD |
311 | } |
312 | ||
313 | if ($subop == "markSelected") { | |
74d12bab | 314 | header("Content-Type: text/plain"); |
01b3e191 | 315 | |
b4e75b2a AD |
316 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
317 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
01b3e191 | 318 | |
18eddb2c AD |
319 | markArticlesById($link, $ids, $cmode); |
320 | ||
74d12bab | 321 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
85bd574b | 322 | return; |
01b3e191 AD |
323 | } |
324 | ||
e4f4b46f | 325 | if ($subop == "publishSelected") { |
74d12bab | 326 | header("Content-Type: text/plain"); |
e4f4b46f | 327 | |
b4e75b2a AD |
328 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
329 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
e4f4b46f AD |
330 | |
331 | publishArticlesById($link, $ids, $cmode); | |
332 | ||
74d12bab | 333 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
85bd574b | 334 | return; |
e4f4b46f AD |
335 | } |
336 | ||
01b3e191 | 337 | if ($subop == "sanityCheck") { |
3ac2b520 | 338 | print "<rpc-reply>"; |
01b3e191 AD |
339 | if (sanity_check($link)) { |
340 | print "<error error-code=\"0\"/>"; | |
d8221301 AD |
341 | |
342 | print "<init-params><![CDATA["; | |
343 | print json_encode(make_init_params($link)); | |
344 | print "]]></init-params>"; | |
345 | ||
f54f515f | 346 | print_runtime_info($link); |
4220d6b0 AD |
347 | |
348 | # assign client-passed params to session | |
b4e75b2a | 349 | $_SESSION["client.userAgent"] = $_REQUEST["ua"]; |
4220d6b0 | 350 | |
01b3e191 | 351 | } |
3ac2b520 | 352 | print "</rpc-reply>"; |
85bd574b AD |
353 | |
354 | return; | |
3ac2b520 | 355 | } |
01b3e191 AD |
356 | |
357 | if ($subop == "globalPurge") { | |
358 | ||
359 | print "<rpc-reply>"; | |
360 | global_purge_old_posts($link, true); | |
361 | print "</rpc-reply>"; | |
362 | ||
85bd574b | 363 | return; |
01b3e191 | 364 | } |
3ac2b520 | 365 | |
0b126ac2 | 366 | if ($subop == "setArticleTags") { |
14b6c54b | 367 | |
bd3f2ade AD |
368 | global $memcache; |
369 | ||
b4e75b2a | 370 | $id = db_escape_string($_REQUEST["id"]); |
14b6c54b | 371 | |
b4e75b2a | 372 | $tags_str = db_escape_string($_REQUEST["tags_str"]); |
d62a3b63 | 373 | $tags = array_unique(trim_array(split(",", $tags_str))); |
0b126ac2 AD |
374 | |
375 | db_query($link, "BEGIN"); | |
376 | ||
377 | $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE | |
378 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
379 | ||
380 | if (db_num_rows($result) == 1) { | |
381 | ||
779560b7 AD |
382 | $tags_to_cache = array(); |
383 | ||
0b126ac2 AD |
384 | $int_id = db_fetch_result($result, 0, "int_id"); |
385 | ||
386 | db_query($link, "DELETE FROM ttrss_tags WHERE | |
387 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
388 | ||
389 | foreach ($tags as $tag) { | |
14b6c54b | 390 | $tag = sanitize_tag($tag); |
0b126ac2 | 391 | |
ef063748 AD |
392 | if (!tag_is_valid($tag)) { |
393 | continue; | |
394 | } | |
395 | ||
0b126ac2 AD |
396 | if (preg_match("/^[0-9]*$/", $tag)) { |
397 | continue; | |
398 | } | |
14b6c54b | 399 | |
307d187c | 400 | // print "<!-- $id : $int_id : $tag -->"; |
0b126ac2 AD |
401 | |
402 | if ($tag != '') { | |
403 | db_query($link, "INSERT INTO ttrss_tags | |
404 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
405 | } | |
779560b7 AD |
406 | |
407 | array_push($tags_to_cache, $tag); | |
0b126ac2 | 408 | } |
0b126ac2 | 409 | |
779560b7 AD |
410 | /* update tag cache */ |
411 | ||
412 | $tags_str = join(",", $tags_to_cache); | |
413 | ||
414 | db_query($link, "UPDATE ttrss_user_entries | |
415 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' | |
416 | AND owner_uid = " . $_SESSION["uid"]); | |
417 | } | |
490c366d | 418 | |
0b126ac2 AD |
419 | db_query($link, "COMMIT"); |
420 | ||
bd3f2ade AD |
421 | if ($memcache) { |
422 | $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); | |
423 | $memcache->delete($obj_id); | |
424 | } | |
425 | ||
307d187c AD |
426 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
427 | ||
0b126ac2 | 428 | print "<rpc-reply> |
307d187c | 429 | <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str> |
0b126ac2 AD |
430 | </rpc-reply>"; |
431 | ||
85bd574b | 432 | return; |
0b126ac2 | 433 | } |
01a87dff | 434 | |
ef7b7bbd MK |
435 | if ($subop == "regenOPMLKey") { |
436 | ||
437 | print "<rpc-reply>"; | |
2e7f046f AD |
438 | |
439 | update_feed_access_key($link, 'OPML:Publish', | |
440 | false, $_SESSION["uid"]); | |
441 | ||
ef7b7bbd MK |
442 | $new_link = opml_publish_url($link); |
443 | print "<link><![CDATA[$new_link]]></link>"; | |
444 | print "</rpc-reply>"; | |
445 | return; | |
446 | } | |
447 | ||
01a87dff AD |
448 | if ($subop == "logout") { |
449 | logout_user(); | |
450 | print_error_xml(6); | |
85bd574b | 451 | return; |
01a87dff AD |
452 | } |
453 | ||
05fcdf52 | 454 | if ($subop == "completeTags") { |
74d12bab | 455 | header("Content-Type: text/plain"); |
05fcdf52 AD |
456 | |
457 | $search = db_escape_string($_REQUEST["search"]); | |
458 | ||
459 | $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
460 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
461 | tag_name LIKE '$search%' ORDER BY tag_name | |
462 | LIMIT 10"); | |
463 | ||
464 | print "<ul>"; | |
465 | while ($line = db_fetch_assoc($result)) { | |
466 | print "<li>" . $line["tag_name"] . "</li>"; | |
467 | } | |
468 | print "</ul>"; | |
469 | ||
85bd574b | 470 | return; |
05fcdf52 AD |
471 | } |
472 | ||
81cd6cac | 473 | if ($subop == "purge") { |
b4e75b2a AD |
474 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
475 | $days = sprintf("%d", $_REQUEST["days"]); | |
81cd6cac | 476 | |
81cd6cac AD |
477 | foreach ($ids as $id) { |
478 | ||
479 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
480 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
481 | ||
482 | if (db_num_rows($result) == 1) { | |
74d12bab | 483 | purge_feed($link, $id, $days); |
81cd6cac AD |
484 | } |
485 | } | |
486 | ||
81cd6cac AD |
487 | return; |
488 | } | |
489 | ||
9bf3f101 | 490 | /* if ($subop == "setScore") { |
546499a9 AD |
491 | $id = db_escape_string($_REQUEST["id"]); |
492 | $score = sprintf("%d", $_REQUEST["score"]); | |
493 | ||
494 | $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score' | |
495 | WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
496 | ||
497 | print "<rpc-reply><message>Acknowledged.</message></rpc-reply>"; | |
498 | ||
499 | return; | |
500 | ||
9bf3f101 | 501 | } */ |
546499a9 | 502 | |
aa0fa9df AD |
503 | if ($subop == "getArticles") { |
504 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
505 | ||
506 | print "<rpc-reply>"; | |
507 | ||
508 | foreach ($ids as $id) { | |
509 | if ($id) { | |
510 | outputArticleXML($link, $id, 0, false); | |
511 | } | |
512 | } | |
513 | print "</rpc-reply>"; | |
514 | ||
515 | return; | |
516 | } | |
517 | ||
d0da85c2 AD |
518 | if ($subop == "checkDate") { |
519 | ||
520 | $date = db_escape_string($_REQUEST["date"]); | |
521 | $date_parsed = strtotime($date); | |
522 | ||
523 | print "<rpc-reply>"; | |
524 | ||
525 | if ($date_parsed) { | |
526 | print "<result>1</result>"; | |
527 | } else { | |
528 | print "<result>0</result>"; | |
529 | } | |
530 | ||
531 | print "</rpc-reply>"; | |
532 | ||
533 | return; | |
534 | } | |
535 | ||
933ba4ee AD |
536 | if ($subop == "removeFromLabel") { |
537 | ||
905ff52a | 538 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); |
933ba4ee AD |
539 | $label_id = db_escape_string($_REQUEST["lid"]); |
540 | ||
7a13338b AD |
541 | $label = db_escape_string(label_find_caption($link, $label_id, |
542 | $_SESSION["uid"])); | |
933ba4ee | 543 | |
1c9c6025 AD |
544 | print "<rpc-reply>"; |
545 | print "<info-for-headlines>"; | |
546 | ||
933ba4ee AD |
547 | if ($label) { |
548 | ||
549 | foreach ($ids as $id) { | |
550 | label_remove_article($link, $id, $label, $_SESSION["uid"]); | |
1c9c6025 AD |
551 | |
552 | print "<entry id=\"$id\"><![CDATA["; | |
553 | ||
554 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 555 | print format_article_labels($labels, $id); |
1c9c6025 AD |
556 | |
557 | print "]]></entry>"; | |
558 | ||
933ba4ee AD |
559 | } |
560 | } | |
561 | ||
1c9c6025 AD |
562 | print "</info-for-headlines>"; |
563 | ||
f8fb4498 | 564 | print "<message>UPDATE_COUNTERS</message>"; |
1c9c6025 | 565 | print "</rpc-reply>"; |
933ba4ee AD |
566 | |
567 | return; | |
568 | } | |
569 | ||
b8a637f3 AD |
570 | if ($subop == "assignToLabel") { |
571 | ||
572 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
573 | $label_id = db_escape_string($_REQUEST["lid"]); | |
574 | ||
7a13338b AD |
575 | $label = db_escape_string(label_find_caption($link, $label_id, |
576 | $_SESSION["uid"])); | |
b8a637f3 | 577 | |
f9247195 AD |
578 | print "<rpc-reply>"; |
579 | ||
580 | print "<info-for-headlines>"; | |
581 | ||
b8a637f3 AD |
582 | if ($label) { |
583 | ||
584 | foreach ($ids as $id) { | |
585 | label_add_article($link, $id, $label, $_SESSION["uid"]); | |
f9247195 AD |
586 | |
587 | print "<entry id=\"$id\"><![CDATA["; | |
588 | ||
589 | $labels = get_article_labels($link, $id, $_SESSION["uid"]); | |
2eb9c95c | 590 | print format_article_labels($labels, $id); |
f9247195 AD |
591 | |
592 | print "]]></entry>"; | |
593 | ||
b8a637f3 AD |
594 | } |
595 | } | |
596 | ||
f9247195 AD |
597 | print "</info-for-headlines>"; |
598 | ||
f8fb4498 | 599 | print "<message>UPDATE_COUNTERS</message>"; |
f9247195 | 600 | print "</rpc-reply>"; |
b8a637f3 AD |
601 | |
602 | return; | |
603 | } | |
604 | ||
ef88b1cc | 605 | if ($subop == "updateFeedBrowser") { |
c2913898 AD |
606 | |
607 | $search = db_escape_string($_REQUEST["search"]); | |
608 | $limit = db_escape_string($_REQUEST["limit"]); | |
082ae95b | 609 | $mode = db_escape_string($_REQUEST["mode"]); |
c2913898 AD |
610 | |
611 | print "<rpc-reply>"; | |
612 | print "<content>"; | |
613 | print "<![CDATA["; | |
082ae95b | 614 | $ctr = print_feed_browser($link, $search, $limit, $mode); |
c2913898 AD |
615 | print "]]>"; |
616 | print "</content>"; | |
617 | print "<num-results value=\"$ctr\"/>"; | |
ef88b1cc | 618 | print "<mode value=\"$mode\"/>"; |
c2913898 AD |
619 | print "</rpc-reply>"; |
620 | ||
621 | return; | |
622 | } | |
623 | ||
ef88b1cc AD |
624 | |
625 | if ($subop == "massSubscribe") { | |
626 | ||
627 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
628 | $mode = $_REQUEST["mode"]; | |
629 | ||
630 | $subscribed = array(); | |
631 | ||
632 | foreach ($ids as $id) { | |
633 | ||
634 | if ($mode == 1) { | |
635 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
636 | WHERE id = '$id'"); | |
637 | } else if ($mode == 2) { | |
638 | $result = db_query($link, "SELECT * FROM ttrss_archived_feeds | |
639 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
640 | $orig_id = db_escape_string(db_fetch_result($result, 0, "id")); | |
641 | $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); | |
642 | } | |
643 | ||
644 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
645 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
646 | ||
647 | $title_orig = db_fetch_result($result, 0, "title"); | |
648 | ||
649 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
650 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
651 | ||
652 | if (db_num_rows($result) == 0) { | |
653 | if ($mode == 1) { | |
654 | $result = db_query($link, | |
655 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
656 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
657 | } else if ($mode == 2) { | |
658 | $result = db_query($link, | |
659 | "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) | |
660 | VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')"); | |
661 | } | |
662 | array_push($subscribed, $title_orig); | |
663 | } | |
664 | } | |
665 | ||
666 | $num_feeds = count($subscribed); | |
667 | ||
668 | print "<rpc-reply>"; | |
669 | print "<num-feeds value='$num_feeds'/>"; | |
670 | print "</rpc-reply>"; | |
671 | ||
672 | return; | |
673 | } | |
674 | ||
d8ea9902 AD |
675 | if ($subop == "digest-get-contents") { |
676 | $article_id = db_escape_string($_REQUEST['article_id']); | |
677 | ||
678 | $result = db_query($link, "SELECT content | |
679 | FROM ttrss_entries, ttrss_user_entries | |
680 | WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); | |
681 | ||
682 | print "<rpc-reply>"; | |
683 | ||
684 | print "<article id=\"$article_id\"><![CDATA["; | |
685 | ||
686 | $content = sanitize_rss($link, db_fetch_result($result, 0, "content")); | |
687 | ||
688 | print $content; | |
689 | ||
690 | print "]]></article>"; | |
691 | ||
692 | print "</rpc-reply>"; | |
693 | ||
694 | return; | |
695 | } | |
696 | ||
1ca8997b | 697 | if ($subop == "digest-update") { |
126cb765 AD |
698 | header("Content-Type: text/plain"); |
699 | ||
b41c2549 | 700 | $feed_id = db_escape_string($_REQUEST['feed_id']); |
1ca8997b | 701 | $offset = db_escape_string($_REQUEST['offset']); |
e4c530dc | 702 | $seq = db_escape_string($_REQUEST['seq']); |
1ca8997b | 703 | |
b41c2549 | 704 | if (!$feed_id) $feed_id = -4; |
1ca8997b | 705 | if (!$offset) $offset = 0; |
1ca8997b | 706 | |
126cb765 AD |
707 | $reply = array(); |
708 | ||
709 | $reply['seq'] = $seq; | |
e4c530dc | 710 | |
1ca8997b | 711 | $headlines = api_get_headlines($link, $feed_id, 10, $offset, |
d8ea9902 | 712 | '', ($feed_id == -4), true, false, "unread", "updated DESC"); |
1ca8997b AD |
713 | |
714 | //function api_get_headlines($link, $feed_id, $limit, $offset, | |
715 | // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) { | |
716 | ||
126cb765 AD |
717 | $reply['headlines'] = array(); |
718 | $reply['headlines']['title'] = getFeedTitle($link, $feed_id); | |
719 | $reply['headlines']['content'] = $headlines; | |
1ca8997b | 720 | |
126cb765 | 721 | print json_encode($reply); |
1ca8997b AD |
722 | return; |
723 | } | |
724 | ||
725 | if ($subop == "digest-init") { | |
126cb765 AD |
726 | header("Content-Type: text/plain"); |
727 | ||
a17d7219 | 728 | $tmp_feeds = api_get_feeds($link, -3, true, false, 0); |
911d4c08 | 729 | |
911d4c08 AD |
730 | $feeds = array(); |
731 | ||
732 | foreach ($tmp_feeds as $f) { | |
b41c2549 | 733 | if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); |
911d4c08 AD |
734 | } |
735 | ||
126cb765 | 736 | print json_encode(array("feeds" => $feeds)); |
911d4c08 | 737 | |
911d4c08 AD |
738 | return; |
739 | } | |
740 | ||
c1b5cd23 AD |
741 | if ($subop == "catchupFeed") { |
742 | ||
743 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
744 | $is_cat = db_escape_string($_REQUEST['is_cat']); | |
745 | ||
746 | print "<rpc-reply>"; | |
747 | ||
748 | catchup_feed($link, $feed_id, $is_cat); | |
749 | ||
750 | print "</rpc-reply>"; | |
751 | ||
752 | return; | |
753 | } | |
754 | ||
31a53903 AD |
755 | if ($subop == "sendEmail") { |
756 | $secretkey = $_REQUEST['secretkey']; | |
757 | ||
758 | print "<rpc-reply>"; | |
759 | ||
760 | if (DIGEST_ENABLE && $_SESSION['email_secretkey'] && | |
761 | $secretkey == $_SESSION['email_secretkey']) { | |
762 | ||
763 | $_SESSION['email_secretkey'] = ''; | |
764 | ||
765 | $destination = $_REQUEST['destination']; | |
766 | $subject = $_REQUEST['subject']; | |
767 | $content = $_REQUEST['content']; | |
768 | ||
769 | $replyto = strip_tags($_SESSION['email_replyto']); | |
770 | $fromname = strip_tags($_SESSION['email_fromname']); | |
771 | ||
772 | $mail = new PHPMailer(); | |
773 | ||
774 | $mail->PluginDir = "lib/phpmailer/"; | |
775 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
776 | ||
777 | $mail->CharSet = "UTF-8"; | |
778 | ||
779 | $mail->From = $replyto; | |
780 | $mail->FromName = $fromname; | |
781 | $mail->AddAddress($destination); | |
782 | ||
783 | if (DIGEST_SMTP_HOST) { | |
784 | $mail->Host = DIGEST_SMTP_HOST; | |
785 | $mail->Mailer = "smtp"; | |
786 | $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; | |
787 | $mail->Username = DIGEST_SMTP_LOGIN; | |
788 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
789 | } | |
790 | ||
791 | $mail->IsHTML(false); | |
792 | $mail->Subject = $subject; | |
793 | $mail->Body = $content; | |
794 | ||
795 | $rc = $mail->Send(); | |
796 | ||
797 | if (!$rc) { | |
798 | print "<error><![CDATA[" . $mail->ErrorInfo . "]]></error>"; | |
799 | } else { | |
800 | save_email_address($link, db_escape_string($destination)); | |
f8fb4498 | 801 | print "<message>UPDATE_COUNTERS</message>"; |
31a53903 AD |
802 | } |
803 | ||
804 | } else { | |
805 | print "<error>Not authorized.</error>"; | |
806 | } | |
807 | ||
808 | print "</rpc-reply>"; | |
809 | ||
810 | return; | |
811 | } | |
812 | ||
813 | if ($subop == "completeEmails") { | |
814 | ||
815 | $search = db_escape_string($_REQUEST["search"]); | |
816 | ||
817 | print "<ul>"; | |
818 | ||
819 | foreach ($_SESSION['stored_emails'] as $email) { | |
820 | if (strpos($email, $search) !== false) { | |
821 | print "<li>$email</li>"; | |
822 | } | |
823 | } | |
824 | ||
825 | print "</ul>"; | |
826 | ||
827 | return; | |
828 | } | |
829 | ||
5c7c7da9 AD |
830 | if ($subop == "quickAddCat") { |
831 | print "<rpc-reply>"; | |
832 | ||
833 | $cat = db_escape_string($_REQUEST["cat"]); | |
834 | ||
835 | add_feed_category($link, $cat); | |
836 | ||
837 | $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE | |
838 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); | |
839 | ||
840 | if (db_num_rows($result) == 1) { | |
841 | $id = db_fetch_result($result, 0, "id"); | |
842 | } else { | |
843 | $id = 0; | |
844 | } | |
845 | ||
5c7c7da9 | 846 | print_feed_cat_select($link, "cat_id", $id); |
5c7c7da9 AD |
847 | |
848 | print "</rpc-reply>"; | |
849 | ||
850 | return; | |
851 | } | |
852 | ||
8801fb01 AD |
853 | if ($subop == "regenFeedKey") { |
854 | $feed_id = db_escape_string($_REQUEST['id']); | |
855 | $is_cat = (bool) db_escape_string($_REQUEST['is_cat']); | |
856 | ||
857 | print "<rpc-reply>"; | |
858 | ||
859 | $new_key = update_feed_access_key($link, $feed_id, $is_cat); | |
860 | ||
861 | print "<link><![CDATA[$new_key]]></link>"; | |
862 | ||
863 | print "</rpc-reply>"; | |
864 | ||
865 | return; | |
866 | } | |
867 | ||
8d86f15f AD |
868 | if ($subop == "clearKeys") { |
869 | ||
870 | db_query($link, "DELETE FROM ttrss_access_keys WHERE | |
871 | owner_uid = " . $_SESSION["uid"]); | |
872 | ||
f8fb4498 AD |
873 | print "<rpc-reply>"; |
874 | print "<message>UPDATE_COUNTERS</message>"; | |
875 | print "</rpc-reply>"; | |
8d86f15f AD |
876 | |
877 | return; | |
878 | } | |
879 | ||
f705f206 AD |
880 | if ($subop == "verifyRegexp") { |
881 | $reg_exp = $_REQUEST["reg_exp"]; | |
882 | ||
883 | print "<rpc-reply><status>"; | |
884 | ||
885 | if (@preg_match("/$reg_exp/i", "TEST") === false) { | |
886 | print "INVALID"; | |
887 | } else { | |
888 | print "OK"; | |
889 | } | |
890 | ||
891 | print "</status></rpc-reply>"; | |
892 | ||
893 | return; | |
894 | } | |
895 | ||
dd1c0680 | 896 | if ($subop == "cdmGetArticle") { |
74d12bab AD |
897 | header("Content-Type: text/plain"); |
898 | ||
dd1c0680 AD |
899 | $id = db_escape_string($_REQUEST["id"]); |
900 | ||
901 | $result = db_query($link, "SELECT content, | |
902 | ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds, | |
903 | ttrss_entries | |
904 | WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND | |
905 | ttrss_entries.id = ref_id AND | |
906 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); | |
907 | ||
908 | if (db_num_rows($result) != 0) { | |
909 | $line = db_fetch_assoc($result); | |
910 | ||
911 | $article_content = sanitize_rss($link, $line["content"], | |
912 | false, false, $line['site_url']); | |
913 | ||
914 | } else { | |
915 | $article_content = ''; | |
916 | } | |
917 | ||
74d12bab AD |
918 | print json_encode(array("article" => |
919 | array("id" => $id, "content" => $article_content))); | |
dd1c0680 AD |
920 | |
921 | return; | |
922 | } | |
923 | ||
428b704d | 924 | if ($subop == "scheduleFeedUpdate") { |
74d12bab AD |
925 | header("Content-Type: text/plain"); |
926 | ||
428b704d | 927 | $feed_id = db_escape_string($_REQUEST["id"]); |
997429c2 | 928 | $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; |
428b704d AD |
929 | |
930 | $message = __("Your request could not be completed."); | |
931 | ||
932 | if ($feed_id >= 0) { | |
933 | if (!$is_cat) { | |
934 | $message = __("Feed update has been scheduled."); | |
935 | ||
936 | db_query($link, "UPDATE ttrss_feeds SET | |
937 | last_update_started = '1970-01-01', | |
938 | last_updated = '1970-01-01' WHERE id = '$feed_id' AND | |
939 | owner_uid = ".$_SESSION["uid"]); | |
940 | ||
941 | } else { | |
942 | $message = __("Category update has been scheduled."); | |
943 | ||
944 | if ($feed_id) | |
945 | $cat_query = "cat_id = '$feed_id'"; | |
946 | else | |
947 | $cat_query = "cat_id IS NULL"; | |
948 | ||
949 | db_query($link, "UPDATE ttrss_feeds SET | |
950 | last_update_started = '1970-01-01', | |
951 | last_updated = '1970-01-01' WHERE $cat_query AND | |
952 | owner_uid = ".$_SESSION["uid"]); | |
953 | } | |
954 | } else { | |
955 | $message = __("Can't update this kind of feed."); | |
956 | } | |
957 | ||
74d12bab | 958 | print json_encode(array("message" => $message)); |
428b704d AD |
959 | return; |
960 | } | |
961 | ||
ba7e88e5 | 962 | if ($subop == "getTweetInfo") { |
563b9c78 | 963 | header("Content-Type: text/plain"); |
ba7e88e5 AD |
964 | $id = db_escape_string($_REQUEST['id']); |
965 | ||
966 | $result = db_query($link, "SELECT title, link | |
967 | FROM ttrss_entries, ttrss_user_entries | |
968 | WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']); | |
969 | ||
970 | if (db_num_rows($result) != 0) { | |
971 | $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), | |
972 | 100, '...'); | |
973 | $article_link = db_fetch_result($result, 0, 'link'); | |
974 | } | |
975 | ||
976 | print json_encode(array("title" => $title, "link" => $article_link, | |
977 | "id" => $id)); | |
978 | ||
979 | return; | |
980 | } | |
981 | ||
85bd574b | 982 | print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>"; |
01b3e191 AD |
983 | } |
984 | ?> |