]>
Commit | Line | Data |
---|---|---|
d5112468 | 1 | <?php |
46da73c2 | 2 | class RPC extends Protected_Handler { |
d5112468 | 3 | |
8484ce22 | 4 | function csrf_ignore($method) { |
566faa14 | 5 | $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget"); |
8484ce22 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
d5112468 AD |
10 | function setprofile() { |
11 | $id = db_escape_string($_REQUEST["id"]); | |
46da73c2 | 12 | |
d5112468 AD |
13 | $_SESSION["profile"] = $id; |
14 | $_SESSION["prefs_cache"] = array(); | |
15 | } | |
16 | ||
566faa14 AD |
17 | function exportget() { |
18 | $exportname = CACHE_DIR . "/export/" . | |
19 | sha1($_SESSION['uid'] . $_SESSION['login']) . ".xml"; | |
20 | ||
21 | if (file_exists($exportname)) { | |
22 | header("Content-type: text/xml"); | |
23 | header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml"); | |
24 | ||
25 | echo file_get_contents($exportname); | |
26 | } else { | |
27 | echo "File not found."; | |
28 | } | |
29 | } | |
30 | ||
31 | function exportrun() { | |
32 | $offset = (int) db_escape_string($_REQUEST['offset']); | |
33 | $exported = 0; | |
34 | $limit = 250; | |
35 | ||
36 | if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) { | |
37 | $result = db_query($this->link, "SELECT | |
38 | ttrss_entries.guid, | |
39 | ttrss_entries.title, | |
40 | content, | |
41 | marked, | |
42 | published, | |
43 | score, | |
44 | note, | |
45 | tag_cache, | |
46 | label_cache, | |
47 | ttrss_feeds.title AS feed_title, | |
48 | ttrss_feeds.feed_url AS feed_url, | |
49 | ttrss_entries.updated | |
50 | FROM | |
51 | ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id), | |
52 | ttrss_entries | |
53 | WHERE | |
54 | (marked = true OR feed_id IS NULL) AND | |
55 | ref_id = ttrss_entries.id AND | |
56 | ttrss_user_entries.owner_uid = " . $_SESSION['uid'] . " | |
57 | ORDER BY ttrss_entries.id LIMIT $limit OFFSET $offset"); | |
58 | ||
59 | $exportname = sha1($_SESSION['uid'] . $_SESSION['login']); | |
60 | ||
61 | if ($offset == 0) { | |
62 | $fp = fopen(CACHE_DIR . "/export/$exportname.xml", "w"); | |
63 | fputs($fp, "<articles schema-version=\"".SCHEMA_VERSION."\">"); | |
64 | } else { | |
65 | $fp = fopen(CACHE_DIR . "/export/$exportname.xml", "a"); | |
66 | } | |
67 | ||
68 | if ($fp) { | |
69 | ||
70 | while ($line = db_fetch_assoc($result)) { | |
71 | fputs($fp, "<article>"); | |
72 | ||
73 | foreach ($line as $k => $v) { | |
74 | fputs($fp, "<$k><![CDATA[$v]]></$k>"); | |
75 | } | |
76 | ||
77 | fputs($fp, "</article>"); | |
78 | } | |
79 | ||
80 | $exported = db_num_rows($result); | |
81 | ||
82 | if ($exported < $limit && $exported > 0) { | |
83 | fputs($fp, "</articles>"); | |
84 | } | |
85 | ||
86 | fclose($fp); | |
87 | } | |
88 | ||
89 | } | |
90 | ||
91 | print json_encode(array("exported" => $exported)); | |
92 | } | |
93 | ||
d5112468 AD |
94 | function remprofiles() { |
95 | $ids = explode(",", db_escape_string(trim($_REQUEST["ids"]))); | |
96 | ||
97 | foreach ($ids as $id) { | |
98 | if ($_SESSION["profile"] != $id) { | |
99 | db_query($this->link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
100 | owner_uid = " . $_SESSION["uid"]); | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | // Silent | |
106 | function addprofile() { | |
107 | $title = db_escape_string(trim($_REQUEST["title"])); | |
108 | if ($title) { | |
109 | db_query($this->link, "BEGIN"); | |
110 | ||
111 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
112 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
113 | ||
114 | if (db_num_rows($result) == 0) { | |
115 | ||
116 | db_query($this->link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
117 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
118 | ||
119 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles WHERE | |
120 | title = '$title'"); | |
121 | ||
122 | if (db_num_rows($result) != 0) { | |
123 | $profile_id = db_fetch_result($result, 0, "id"); | |
124 | ||
125 | if ($profile_id) { | |
126 | initialize_user_prefs($this->link, $_SESSION["uid"], $profile_id); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | db_query($this->link, "COMMIT"); | |
132 | } | |
133 | } | |
134 | ||
135 | // Silent | |
136 | function saveprofile() { | |
137 | $id = db_escape_string($_REQUEST["id"]); | |
138 | $title = db_escape_string(trim($_REQUEST["value"])); | |
139 | ||
140 | if ($id == 0) { | |
141 | print __("Default profile"); | |
142 | return; | |
143 | } | |
144 | ||
145 | if ($title) { | |
146 | db_query($this->link, "BEGIN"); | |
147 | ||
148 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
149 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
150 | ||
151 | if (db_num_rows($result) == 0) { | |
152 | db_query($this->link, "UPDATE ttrss_settings_profiles | |
153 | SET title = '$title' WHERE id = '$id' AND | |
154 | owner_uid = " . $_SESSION["uid"]); | |
155 | print $title; | |
156 | } else { | |
157 | $result = db_query($this->link, "SELECT title FROM ttrss_settings_profiles | |
158 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
159 | print db_fetch_result($result, 0, "title"); | |
160 | } | |
161 | ||
162 | db_query($this->link, "COMMIT"); | |
163 | } | |
164 | } | |
165 | ||
166 | // Silent | |
167 | function remarchive() { | |
168 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
169 | ||
170 | foreach ($ids as $id) { | |
171 | $result = db_query($this->link, "DELETE FROM ttrss_archived_feeds WHERE | |
172 | (SELECT COUNT(*) FROM ttrss_user_entries | |
173 | WHERE orig_feed_id = '$id') = 0 AND | |
174 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
175 | ||
176 | $rc = db_affected_rows($this->link, $result); | |
177 | } | |
178 | } | |
179 | ||
180 | function addfeed() { | |
181 | $feed = db_escape_string($_REQUEST['feed']); | |
182 | $cat = db_escape_string($_REQUEST['cat']); | |
183 | $login = db_escape_string($_REQUEST['login']); | |
184 | $pass = db_escape_string($_REQUEST['pass']); | |
185 | ||
186 | $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass); | |
187 | ||
188 | print json_encode(array("result" => $rc)); | |
189 | } | |
190 | ||
191 | function extractfeedurls() { | |
192 | $urls = get_feeds_from_html($_REQUEST['url']); | |
193 | ||
194 | print json_encode(array("urls" => $urls)); | |
195 | } | |
196 | ||
197 | function togglepref() { | |
198 | $key = db_escape_string($_REQUEST["key"]); | |
199 | set_pref($this->link, $key, !get_pref($this->link, $key)); | |
200 | $value = get_pref($this->link, $key); | |
201 | ||
202 | print json_encode(array("param" =>$key, "value" => $value)); | |
203 | } | |
204 | ||
205 | function setpref() { | |
206 | $value = str_replace("\n", "<br/>", $_REQUEST['value']); | |
207 | ||
208 | $key = db_escape_string($_REQUEST["key"]); | |
209 | $value = db_escape_string($value); | |
210 | ||
211 | set_pref($this->link, $key, $value); | |
212 | ||
213 | print json_encode(array("param" =>$key, "value" => $value)); | |
214 | } | |
215 | ||
216 | function mark() { | |
217 | $mark = $_REQUEST["mark"]; | |
218 | $id = db_escape_string($_REQUEST["id"]); | |
219 | ||
220 | if ($mark == "1") { | |
221 | $mark = "true"; | |
222 | } else { | |
223 | $mark = "false"; | |
224 | } | |
225 | ||
226 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark | |
227 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
228 | ||
229 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
230 | } | |
231 | ||
232 | function delete() { | |
233 | $ids = db_escape_string($_REQUEST["ids"]); | |
234 | ||
235 | $result = db_query($this->link, "DELETE FROM ttrss_user_entries | |
236 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
237 | ||
238 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
239 | } | |
240 | ||
241 | function unarchive() { | |
242 | $ids = db_escape_string($_REQUEST["ids"]); | |
243 | ||
244 | $result = db_query($this->link, "UPDATE ttrss_user_entries | |
245 | SET feed_id = orig_feed_id, orig_feed_id = NULL | |
246 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
247 | ||
248 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
249 | } | |
250 | ||
251 | function archive() { | |
252 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
253 | ||
254 | foreach ($ids as $id) { | |
255 | archive_article($this->link, $id, $_SESSION["uid"]); | |
256 | } | |
257 | ||
258 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
259 | } | |
260 | ||
261 | function publ() { | |
262 | $pub = $_REQUEST["pub"]; | |
263 | $id = db_escape_string($_REQUEST["id"]); | |
264 | $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); | |
265 | ||
266 | if ($pub == "1") { | |
267 | $pub = "true"; | |
268 | } else { | |
269 | $pub = "false"; | |
270 | } | |
271 | ||
272 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET | |
273 | published = $pub | |
274 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
275 | ||
276 | $pubsub_result = false; | |
277 | ||
278 | if (PUBSUBHUBBUB_HUB) { | |
279 | $rss_link = get_self_url_prefix() . | |
280 | "/public.php?op=rss&id=-2&key=" . | |
281 | get_feed_access_key($this->link, -2, false); | |
282 | ||
283 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
284 | ||
285 | $pubsub_result = $p->publish_update($rss_link); | |
286 | } | |
287 | ||
288 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
289 | "pubsub_result" => $pubsub_result)); | |
290 | } | |
291 | ||
292 | function getAllCounters() { | |
293 | $last_article_id = (int) $_REQUEST["last_article_id"]; | |
294 | ||
295 | $reply = array(); | |
296 | ||
297 | if ($seq) $reply['seq'] = $seq; | |
298 | ||
299 | if ($last_article_id != getLastArticleId($this->link)) { | |
300 | $omode = $_REQUEST["omode"]; | |
46da73c2 | 301 | |
d5112468 AD |
302 | if ($omode != "T") |
303 | $reply['counters'] = getAllCounters($this->link, $omode); | |
304 | else | |
305 | $reply['counters'] = getGlobalCounters($this->link); | |
306 | } | |
307 | ||
308 | $reply['runtime-info'] = make_runtime_info($this->link); | |
309 | ||
310 | print json_encode($reply); | |
311 | } | |
312 | ||
313 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
314 | function catchupSelected() { | |
315 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
316 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
317 | ||
318 | catchupArticlesById($this->link, $ids, $cmode); | |
319 | ||
320 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
321 | } | |
322 | ||
323 | function markSelected() { | |
324 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
325 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
326 | ||
327 | markArticlesById($this->link, $ids, $cmode); | |
328 | ||
329 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
330 | } | |
331 | ||
332 | function publishSelected() { | |
333 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
334 | $cmode = sprintf("%d", $_REQUEST["cmode"]); | |
335 | ||
336 | publishArticlesById($this->link, $ids, $cmode); | |
337 | ||
338 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
339 | } | |
340 | ||
341 | function sanityCheck() { | |
342 | $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; | |
343 | ||
344 | $reply = array(); | |
345 | ||
346 | $reply['error'] = sanity_check($this->link); | |
347 | ||
348 | if ($reply['error']['code'] == 0) { | |
349 | $reply['init-params'] = make_init_params($this->link); | |
350 | $reply['runtime-info'] = make_runtime_info($this->link); | |
351 | } | |
352 | ||
353 | print json_encode($reply); | |
354 | } | |
355 | ||
356 | function setArticleTags() { | |
357 | global $memcache; | |
358 | ||
359 | $id = db_escape_string($_REQUEST["id"]); | |
360 | ||
361 | $tags_str = db_escape_string($_REQUEST["tags_str"]); | |
362 | $tags = array_unique(trim_array(explode(",", $tags_str))); | |
363 | ||
364 | db_query($this->link, "BEGIN"); | |
365 | ||
366 | $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE | |
367 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
368 | ||
369 | if (db_num_rows($result) == 1) { | |
370 | ||
371 | $tags_to_cache = array(); | |
372 | ||
373 | $int_id = db_fetch_result($result, 0, "int_id"); | |
374 | ||
375 | db_query($this->link, "DELETE FROM ttrss_tags WHERE | |
376 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
377 | ||
378 | foreach ($tags as $tag) { | |
379 | $tag = sanitize_tag($tag); | |
380 | ||
381 | if (!tag_is_valid($tag)) { | |
382 | continue; | |
383 | } | |
384 | ||
385 | if (preg_match("/^[0-9]*$/", $tag)) { | |
386 | continue; | |
387 | } | |
388 | ||
389 | // print "<!-- $id : $int_id : $tag -->"; | |
390 | ||
391 | if ($tag != '') { | |
392 | db_query($this->link, "INSERT INTO ttrss_tags | |
393 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
394 | } | |
395 | ||
396 | array_push($tags_to_cache, $tag); | |
397 | } | |
398 | ||
399 | /* update tag cache */ | |
400 | ||
401 | sort($tags_to_cache); | |
402 | $tags_str = join(",", $tags_to_cache); | |
403 | ||
404 | db_query($this->link, "UPDATE ttrss_user_entries | |
405 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' | |
406 | AND owner_uid = " . $_SESSION["uid"]); | |
407 | } | |
408 | ||
409 | db_query($this->link, "COMMIT"); | |
410 | ||
411 | if ($memcache) { | |
412 | $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); | |
413 | $memcache->delete($obj_id); | |
414 | } | |
415 | ||
416 | $tags = get_article_tags($this->link, $id); | |
417 | $tags_str = format_tags_string($tags, $id); | |
418 | $tags_str_full = join(", ", $tags); | |
419 | ||
420 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
421 | ||
422 | print json_encode(array("tags_str" => array("id" => $id, | |
423 | "content" => $tags_str, "content_full" => $tags_str_full))); | |
424 | } | |
425 | ||
426 | function regenOPMLKey() { | |
427 | update_feed_access_key($this->link, 'OPML:Publish', | |
428 | false, $_SESSION["uid"]); | |
429 | ||
430 | $new_link = opml_publish_url($this->link); | |
431 | ||
432 | print json_encode(array("link" => $new_link)); | |
433 | } | |
434 | ||
435 | function completeTags() { | |
436 | $search = db_escape_string($_REQUEST["search"]); | |
437 | ||
438 | $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
439 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
440 | tag_name LIKE '$search%' ORDER BY tag_name | |
441 | LIMIT 10"); | |
442 | ||
443 | print "<ul>"; | |
444 | while ($line = db_fetch_assoc($result)) { | |
445 | print "<li>" . $line["tag_name"] . "</li>"; | |
446 | } | |
447 | print "</ul>"; | |
448 | } | |
449 | ||
450 | function purge() { | |
451 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
452 | $days = sprintf("%d", $_REQUEST["days"]); | |
453 | ||
454 | foreach ($ids as $id) { | |
455 | ||
456 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
457 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
458 | ||
459 | if (db_num_rows($result) == 1) { | |
460 | purge_feed($this->link, $id, $days); | |
461 | } | |
462 | } | |
463 | } | |
464 | ||
465 | function getArticles() { | |
466 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
467 | $articles = array(); | |
468 | ||
469 | foreach ($ids as $id) { | |
470 | if ($id) { | |
471 | array_push($articles, format_article($this->link, $id, 0, false)); | |
472 | } | |
473 | } | |
474 | ||
475 | print json_encode($articles); | |
476 | } | |
477 | ||
478 | function checkDate() { | |
479 | $date = db_escape_string($_REQUEST["date"]); | |
480 | $date_parsed = strtotime($date); | |
481 | ||
482 | print json_encode(array("result" => (bool)$date_parsed, | |
483 | "date" => date("c", $date_parsed))); | |
484 | } | |
485 | ||
486 | function assigntolabel() { | |
4fdb8759 | 487 | return $this->labelops(true); |
d5112468 | 488 | } |
46da73c2 | 489 | |
d5112468 | 490 | function removefromlabel() { |
4fdb8759 | 491 | return $this->labelops(false); |
d5112468 | 492 | } |
46da73c2 | 493 | |
d5112468 AD |
494 | function labelops($assign) { |
495 | $reply = array(); | |
496 | ||
497 | $ids = explode(",", db_escape_string($_REQUEST["ids"])); | |
498 | $label_id = db_escape_string($_REQUEST["lid"]); | |
499 | ||
500 | $label = db_escape_string(label_find_caption($this->link, $label_id, | |
501 | $_SESSION["uid"])); | |
502 | ||
503 | $reply["info-for-headlines"] = array(); | |
504 | ||
505 | if ($label) { | |
506 | ||
507 | foreach ($ids as $id) { | |
508 | ||
509 | if ($assign) | |
510 | label_add_article($this->link, $id, $label, $_SESSION["uid"]); | |
511 | else | |
512 | label_remove_article($this->link, $id, $label, $_SESSION["uid"]); | |
513 | ||
514 | $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); | |
515 | ||
516 | array_push($reply["info-for-headlines"], | |
517 | array("id" => $id, "labels" => format_article_labels($labels, $id))); | |
518 | ||
519 | } | |
520 | } | |
521 | ||
522 | $reply["message"] = "UPDATE_COUNTERS"; | |
523 | ||
524 | print json_encode($reply); | |
525 | } | |
526 | ||
527 | function updateFeedBrowser() { | |
528 | $search = db_escape_string($_REQUEST["search"]); | |
529 | $limit = db_escape_string($_REQUEST["limit"]); | |
530 | $mode = (int) db_escape_string($_REQUEST["mode"]); | |
531 | ||
532 | print json_encode(array("content" => | |
533 | make_feed_browser($this->link, $search, $limit, $mode), | |
534 | "mode" => $mode)); | |
535 | } | |
536 | ||
537 | // Silent | |
538 | function massSubscribe() { | |
539 | ||
540 | $payload = json_decode($_REQUEST["payload"], false); | |
541 | $mode = $_REQUEST["mode"]; | |
542 | ||
543 | if (!$payload || !is_array($payload)) return; | |
544 | ||
545 | if ($mode == 1) { | |
546 | foreach ($payload as $feed) { | |
547 | ||
548 | $title = db_escape_string($feed[0]); | |
549 | $feed_url = db_escape_string($feed[1]); | |
550 | ||
551 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
552 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
553 | ||
554 | if (db_num_rows($result) == 0) { | |
555 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
556 | (owner_uid,feed_url,title,cat_id,site_url) | |
557 | VALUES ('".$_SESSION["uid"]."', | |
558 | '$feed_url', '$title', NULL, '')"); | |
559 | } | |
560 | } | |
561 | } else if ($mode == 2) { | |
562 | // feed archive | |
563 | foreach ($payload as $id) { | |
564 | $result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds | |
565 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
566 | ||
567 | if (db_num_rows($result) != 0) { | |
568 | $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); | |
569 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
570 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
571 | ||
572 | $result = db_query($this->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 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
577 | (owner_uid,feed_url,title,cat_id,site_url) | |
578 | VALUES ('$id','".$_SESSION["uid"]."', | |
579 | '$feed_url', '$title', NULL, '$site_url')"); | |
580 | } | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
586 | function digestgetcontents() { | |
587 | $article_id = db_escape_string($_REQUEST['article_id']); | |
588 | ||
589 | $result = db_query($this->link, "SELECT content,title,link,marked,published | |
590 | FROM ttrss_entries, ttrss_user_entries | |
591 | WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); | |
592 | ||
183ff16c | 593 | $content = sanitize($this->link, db_fetch_result($result, 0, "content")); |
d5112468 AD |
594 | $title = strip_tags(db_fetch_result($result, 0, "title")); |
595 | $article_url = htmlspecialchars(db_fetch_result($result, 0, "link")); | |
596 | $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked")); | |
597 | $published = sql_bool_to_bool(db_fetch_result($result, 0, "published")); | |
598 | ||
599 | print json_encode(array("article" => | |
600 | array("id" => $article_id, "url" => $article_url, | |
601 | "tags" => get_article_tags($this->link, $article_id), | |
602 | "marked" => $marked, "published" => $published, | |
603 | "title" => $title, "content" => $content))); | |
604 | } | |
605 | ||
606 | function digestupdate() { | |
607 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
608 | $offset = db_escape_string($_REQUEST['offset']); | |
609 | $seq = db_escape_string($_REQUEST['seq']); | |
610 | ||
611 | if (!$feed_id) $feed_id = -4; | |
612 | if (!$offset) $offset = 0; | |
613 | ||
614 | $reply = array(); | |
615 | ||
616 | $reply['seq'] = $seq; | |
617 | ||
618 | $headlines = api_get_headlines($this->link, $feed_id, 30, $offset, | |
619 | '', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0); | |
620 | ||
621 | $reply['headlines'] = array(); | |
622 | $reply['headlines']['title'] = getFeedTitle($this->link, $feed_id); | |
623 | $reply['headlines']['content'] = $headlines; | |
624 | ||
625 | print json_encode($reply); | |
626 | } | |
627 | ||
628 | function digestinit() { | |
629 | $tmp_feeds = api_get_feeds($this->link, -4, true, false, 0); | |
630 | ||
631 | $feeds = array(); | |
632 | ||
633 | foreach ($tmp_feeds as $f) { | |
634 | if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); | |
635 | } | |
636 | ||
637 | print json_encode(array("feeds" => $feeds)); | |
638 | } | |
639 | ||
640 | function catchupFeed() { | |
641 | $feed_id = db_escape_string($_REQUEST['feed_id']); | |
642 | $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; | |
643 | ||
644 | catchup_feed($this->link, $feed_id, $is_cat); | |
645 | ||
646 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
647 | } | |
648 | ||
d5112468 AD |
649 | function quickAddCat() { |
650 | $cat = db_escape_string($_REQUEST["cat"]); | |
651 | ||
652 | add_feed_category($this->link, $cat); | |
653 | ||
654 | $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE | |
655 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); | |
656 | ||
657 | if (db_num_rows($result) == 1) { | |
658 | $id = db_fetch_result($result, 0, "id"); | |
659 | } else { | |
660 | $id = 0; | |
661 | } | |
662 | ||
663 | print_feed_cat_select($this->link, "cat_id", $id); | |
664 | } | |
665 | ||
666 | function regenFeedKey() { | |
667 | $feed_id = db_escape_string($_REQUEST['id']); | |
668 | $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; | |
669 | ||
670 | $new_key = update_feed_access_key($this->link, $feed_id, $is_cat); | |
671 | ||
672 | print json_encode(array("link" => $new_key)); | |
673 | } | |
674 | ||
675 | // Silent | |
676 | function clearKeys() { | |
677 | db_query($this->link, "DELETE FROM ttrss_access_keys WHERE | |
678 | owner_uid = " . $_SESSION["uid"]); | |
679 | } | |
680 | ||
681 | // Silent | |
682 | function clearArticleKeys() { | |
683 | db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE | |
684 | owner_uid = " . $_SESSION["uid"]); | |
685 | ||
686 | return; | |
687 | } | |
688 | ||
689 | ||
690 | function verifyRegexp() { | |
691 | $reg_exp = $_REQUEST["reg_exp"]; | |
692 | ||
693 | $status = @preg_match("/$reg_exp/i", "TEST") !== false; | |
694 | ||
695 | print json_encode(array("status" => $status)); | |
696 | } | |
697 | ||
698 | // TODO: unify with digest-get-contents? | |
699 | function cdmGetArticle() { | |
700 | $ids = array(db_escape_string($_REQUEST["id"])); | |
701 | $cids = explode(",", $_REQUEST["cids"]); | |
702 | ||
703 | $ids = array_merge($ids, $cids); | |
704 | ||
705 | $rv = array(); | |
706 | ||
707 | foreach ($ids as $id) { | |
708 | $id = (int)$id; | |
709 | ||
710 | $result = db_query($this->link, "SELECT content, | |
711 | ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds, | |
712 | ttrss_entries | |
713 | WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND | |
714 | ttrss_entries.id = ref_id AND | |
715 | ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); | |
716 | ||
717 | if (db_num_rows($result) != 0) { | |
718 | $line = db_fetch_assoc($result); | |
719 | ||
183ff16c | 720 | $article_content = sanitize($this->link, $line["content"], |
d5112468 AD |
721 | false, false, $line['site_url']); |
722 | ||
723 | array_push($rv, | |
724 | array("id" => $id, "content" => $article_content)); | |
725 | } | |
726 | } | |
727 | ||
728 | print json_encode($rv); | |
729 | } | |
730 | ||
731 | function scheduleFeedUpdate() { | |
732 | $feed_id = db_escape_string($_REQUEST["id"]); | |
733 | $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; | |
734 | ||
735 | $message = __("Your request could not be completed."); | |
736 | ||
737 | if ($feed_id >= 0) { | |
738 | if (!$is_cat) { | |
739 | $message = __("Feed update has been scheduled."); | |
740 | ||
741 | db_query($this->link, "UPDATE ttrss_feeds SET | |
742 | last_update_started = '1970-01-01', | |
743 | last_updated = '1970-01-01' WHERE id = '$feed_id' AND | |
744 | owner_uid = ".$_SESSION["uid"]); | |
745 | ||
746 | } else { | |
747 | $message = __("Category update has been scheduled."); | |
748 | ||
749 | if ($feed_id) | |
750 | $cat_query = "cat_id = '$feed_id'"; | |
751 | else | |
752 | $cat_query = "cat_id IS NULL"; | |
753 | ||
754 | db_query($this->link, "UPDATE ttrss_feeds SET | |
755 | last_update_started = '1970-01-01', | |
756 | last_updated = '1970-01-01' WHERE $cat_query AND | |
757 | owner_uid = ".$_SESSION["uid"]); | |
758 | } | |
759 | } else { | |
760 | $message = __("Can't update this kind of feed."); | |
761 | } | |
762 | ||
763 | print json_encode(array("message" => $message)); | |
764 | return; | |
765 | } | |
766 | ||
f9ac31d6 AD |
767 | function buttonPlugin() { |
768 | $pclass = basename($_REQUEST['plugin']) . "_button"; | |
769 | $method = $_REQUEST['plugin_method']; | |
770 | ||
771 | if (class_exists($pclass)) { | |
772 | $plugin = new $pclass($this->link); | |
773 | if (method_exists($plugin, $method)) { | |
774 | return $plugin->$method(); | |
775 | } | |
d5112468 | 776 | } |
d5112468 AD |
777 | } |
778 | ||
d5112468 AD |
779 | function genHash() { |
780 | $hash = sha1(uniqid(rand(), true)); | |
781 | ||
782 | print json_encode(array("hash" => $hash)); | |
783 | } | |
784 | } | |
785 | ?> |