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