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