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