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