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