]>
Commit | Line | Data |
---|---|---|
d5112468 | 1 | <?php |
369dbc19 | 2 | class RPC extends Handler_Protected { |
d5112468 | 3 | |
8484ce22 | 4 | function csrf_ignore($method) { |
6c2637d9 | 5 | $csrf_ignored = array("sanitycheck", "completelabels"); |
8484ce22 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
d5112468 | 10 | function setprofile() { |
3972bf59 | 11 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
46da73c2 | 12 | |
d5112468 AD |
13 | $_SESSION["profile"] = $id; |
14 | $_SESSION["prefs_cache"] = array(); | |
15 | } | |
16 | ||
17 | function remprofiles() { | |
3972bf59 | 18 | $ids = explode(",", db_escape_string($this->link, trim($_REQUEST["ids"]))); |
d5112468 AD |
19 | |
20 | foreach ($ids as $id) { | |
21 | if ($_SESSION["profile"] != $id) { | |
22 | db_query($this->link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND | |
23 | owner_uid = " . $_SESSION["uid"]); | |
24 | } | |
25 | } | |
26 | } | |
27 | ||
28 | // Silent | |
29 | function addprofile() { | |
3972bf59 | 30 | $title = db_escape_string($this->link, trim($_REQUEST["title"])); |
d5112468 AD |
31 | if ($title) { |
32 | db_query($this->link, "BEGIN"); | |
33 | ||
34 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
35 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); | |
36 | ||
37 | if (db_num_rows($result) == 0) { | |
38 | ||
39 | db_query($this->link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) | |
40 | VALUES ('$title', ".$_SESSION["uid"] .")"); | |
41 | ||
42 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles WHERE | |
43 | title = '$title'"); | |
44 | ||
45 | if (db_num_rows($result) != 0) { | |
46 | $profile_id = db_fetch_result($result, 0, "id"); | |
47 | ||
48 | if ($profile_id) { | |
49 | initialize_user_prefs($this->link, $_SESSION["uid"], $profile_id); | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | db_query($this->link, "COMMIT"); | |
55 | } | |
56 | } | |
57 | ||
58 | // Silent | |
59 | function saveprofile() { | |
3972bf59 AD |
60 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
61 | $title = db_escape_string($this->link, trim($_REQUEST["value"])); | |
d5112468 AD |
62 | |
63 | if ($id == 0) { | |
64 | print __("Default profile"); | |
65 | return; | |
66 | } | |
67 | ||
68 | if ($title) { | |
69 | db_query($this->link, "BEGIN"); | |
70 | ||
71 | $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles | |
72 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); | |
73 | ||
74 | if (db_num_rows($result) == 0) { | |
75 | db_query($this->link, "UPDATE ttrss_settings_profiles | |
76 | SET title = '$title' WHERE id = '$id' AND | |
77 | owner_uid = " . $_SESSION["uid"]); | |
78 | print $title; | |
79 | } else { | |
80 | $result = db_query($this->link, "SELECT title FROM ttrss_settings_profiles | |
81 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); | |
82 | print db_fetch_result($result, 0, "title"); | |
83 | } | |
84 | ||
85 | db_query($this->link, "COMMIT"); | |
86 | } | |
87 | } | |
88 | ||
89 | // Silent | |
90 | function remarchive() { | |
3972bf59 | 91 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
92 | |
93 | foreach ($ids as $id) { | |
94 | $result = db_query($this->link, "DELETE FROM ttrss_archived_feeds WHERE | |
95 | (SELECT COUNT(*) FROM ttrss_user_entries | |
96 | WHERE orig_feed_id = '$id') = 0 AND | |
97 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
98 | ||
99 | $rc = db_affected_rows($this->link, $result); | |
100 | } | |
101 | } | |
102 | ||
103 | function addfeed() { | |
3972bf59 AD |
104 | $feed = db_escape_string($this->link, $_REQUEST['feed']); |
105 | $cat = db_escape_string($this->link, $_REQUEST['cat']); | |
106 | $login = db_escape_string($this->link, $_REQUEST['login']); | |
107 | $pass = db_escape_string($this->link, $_REQUEST['pass']); | |
d5112468 | 108 | |
efc6553d | 109 | $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass); |
d5112468 AD |
110 | |
111 | print json_encode(array("result" => $rc)); | |
112 | } | |
113 | ||
d5112468 | 114 | function togglepref() { |
3972bf59 | 115 | $key = db_escape_string($this->link, $_REQUEST["key"]); |
d5112468 AD |
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() { | |
0380cfa9 | 123 | // set_pref escapes input, so no need to double escape it here |
74eef4fc AD |
124 | $key = $_REQUEST['key']; |
125 | $value = str_replace("\n", "<br/>", $_REQUEST['value']); | |
d5112468 | 126 | |
7e431502 | 127 | set_pref($this->link, $key, $value, $_SESSION['uid'], $key != 'USER_STYLESHEET'); |
d5112468 AD |
128 | |
129 | print json_encode(array("param" =>$key, "value" => $value)); | |
130 | } | |
131 | ||
132 | function mark() { | |
133 | $mark = $_REQUEST["mark"]; | |
3972bf59 | 134 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
d5112468 AD |
135 | |
136 | if ($mark == "1") { | |
137 | $mark = "true"; | |
138 | } else { | |
139 | $mark = "false"; | |
140 | } | |
141 | ||
7873d588 AD |
142 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark, |
143 | last_marked = NOW() | |
d5112468 AD |
144 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
145 | ||
146 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
147 | } | |
148 | ||
149 | function delete() { | |
3972bf59 | 150 | $ids = db_escape_string($this->link, $_REQUEST["ids"]); |
d5112468 AD |
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() { | |
3972bf59 | 159 | $ids = db_escape_string($this->link, $_REQUEST["ids"]); |
d5112468 AD |
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() { | |
3972bf59 | 169 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
170 | |
171 | foreach ($ids as $id) { | |
87d7e850 | 172 | $this->archive_article($this->link, $id, $_SESSION["uid"]); |
d5112468 AD |
173 | } |
174 | ||
175 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
176 | } | |
177 | ||
87d7e850 AD |
178 | private function archive_article($link, $id, $owner_uid) { |
179 | db_query($link, "BEGIN"); | |
180 | ||
181 | $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries | |
182 | WHERE ref_id = '$id' AND owner_uid = $owner_uid"); | |
183 | ||
184 | if (db_num_rows($result) != 0) { | |
185 | ||
186 | /* prepare the archived table */ | |
187 | ||
188 | $feed_id = (int) db_fetch_result($result, 0, "feed_id"); | |
189 | ||
190 | if ($feed_id) { | |
191 | $result = db_query($link, "SELECT id FROM ttrss_archived_feeds | |
192 | WHERE id = '$feed_id'"); | |
193 | ||
194 | if (db_num_rows($result) == 0) { | |
195 | db_query($link, "INSERT INTO ttrss_archived_feeds | |
196 | (id, owner_uid, title, feed_url, site_url) | |
197 | SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds | |
198 | WHERE id = '$feed_id'"); | |
199 | } | |
200 | ||
201 | db_query($link, "UPDATE ttrss_user_entries | |
202 | SET orig_feed_id = feed_id, feed_id = NULL | |
203 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
204 | } | |
205 | } | |
206 | ||
207 | db_query($link, "COMMIT"); | |
208 | } | |
209 | ||
d5112468 AD |
210 | function publ() { |
211 | $pub = $_REQUEST["pub"]; | |
3972bf59 AD |
212 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
213 | $note = trim(strip_tags(db_escape_string($this->link, $_REQUEST["note"]))); | |
d5112468 AD |
214 | |
215 | if ($pub == "1") { | |
216 | $pub = "true"; | |
217 | } else { | |
218 | $pub = "false"; | |
219 | } | |
220 | ||
221 | $result = db_query($this->link, "UPDATE ttrss_user_entries SET | |
7873d588 | 222 | published = $pub, last_published = NOW() |
d5112468 AD |
223 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
224 | ||
225 | $pubsub_result = false; | |
226 | ||
227 | if (PUBSUBHUBBUB_HUB) { | |
228 | $rss_link = get_self_url_prefix() . | |
229 | "/public.php?op=rss&id=-2&key=" . | |
230 | get_feed_access_key($this->link, -2, false); | |
231 | ||
232 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
233 | ||
234 | $pubsub_result = $p->publish_update($rss_link); | |
235 | } | |
236 | ||
237 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
238 | "pubsub_result" => $pubsub_result)); | |
239 | } | |
240 | ||
241 | function getAllCounters() { | |
242 | $last_article_id = (int) $_REQUEST["last_article_id"]; | |
243 | ||
244 | $reply = array(); | |
245 | ||
5b55e9e2 | 246 | if ($seq) $reply['seq'] = $seq; |
d5112468 | 247 | |
5b55e9e2 AD |
248 | if ($last_article_id != getLastArticleId($this->link)) { |
249 | $reply['counters'] = getAllCounters($this->link); | |
250 | } | |
d5112468 | 251 | |
5b55e9e2 | 252 | $reply['runtime-info'] = make_runtime_info($this->link); |
d5112468 | 253 | |
5b55e9e2 | 254 | print json_encode($reply); |
d5112468 AD |
255 | } |
256 | ||
257 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
258 | function catchupSelected() { | |
3972bf59 | 259 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
260 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
261 | ||
262 | catchupArticlesById($this->link, $ids, $cmode); | |
263 | ||
264 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
265 | } | |
266 | ||
267 | function markSelected() { | |
3972bf59 | 268 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
269 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
270 | ||
87d7e850 | 271 | $this->markArticlesById($this->link, $ids, $cmode); |
d5112468 AD |
272 | |
273 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
274 | } | |
275 | ||
276 | function publishSelected() { | |
3972bf59 | 277 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
278 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
279 | ||
87d7e850 | 280 | $this->publishArticlesById($this->link, $ids, $cmode); |
d5112468 AD |
281 | |
282 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
283 | } | |
284 | ||
285 | function sanityCheck() { | |
286 | $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; | |
4f7d69e1 | 287 | $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true"; |
d5112468 AD |
288 | |
289 | $reply = array(); | |
290 | ||
291 | $reply['error'] = sanity_check($this->link); | |
292 | ||
293 | if ($reply['error']['code'] == 0) { | |
294 | $reply['init-params'] = make_init_params($this->link); | |
295 | $reply['runtime-info'] = make_runtime_info($this->link); | |
296 | } | |
297 | ||
298 | print json_encode($reply); | |
299 | } | |
300 | ||
301 | function setArticleTags() { | |
d5112468 | 302 | |
3972bf59 | 303 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
d5112468 | 304 | |
3972bf59 | 305 | $tags_str = db_escape_string($this->link, $_REQUEST["tags_str"]); |
d5112468 AD |
306 | $tags = array_unique(trim_array(explode(",", $tags_str))); |
307 | ||
308 | db_query($this->link, "BEGIN"); | |
309 | ||
310 | $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE | |
311 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); | |
312 | ||
313 | if (db_num_rows($result) == 1) { | |
314 | ||
315 | $tags_to_cache = array(); | |
316 | ||
317 | $int_id = db_fetch_result($result, 0, "int_id"); | |
318 | ||
319 | db_query($this->link, "DELETE FROM ttrss_tags WHERE | |
320 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); | |
321 | ||
322 | foreach ($tags as $tag) { | |
323 | $tag = sanitize_tag($tag); | |
324 | ||
325 | if (!tag_is_valid($tag)) { | |
326 | continue; | |
327 | } | |
328 | ||
329 | if (preg_match("/^[0-9]*$/", $tag)) { | |
330 | continue; | |
331 | } | |
332 | ||
333 | // print "<!-- $id : $int_id : $tag -->"; | |
334 | ||
335 | if ($tag != '') { | |
336 | db_query($this->link, "INSERT INTO ttrss_tags | |
337 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); | |
338 | } | |
339 | ||
340 | array_push($tags_to_cache, $tag); | |
341 | } | |
342 | ||
343 | /* update tag cache */ | |
344 | ||
345 | sort($tags_to_cache); | |
346 | $tags_str = join(",", $tags_to_cache); | |
347 | ||
348 | db_query($this->link, "UPDATE ttrss_user_entries | |
349 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' | |
350 | AND owner_uid = " . $_SESSION["uid"]); | |
351 | } | |
352 | ||
353 | db_query($this->link, "COMMIT"); | |
354 | ||
d5112468 AD |
355 | $tags = get_article_tags($this->link, $id); |
356 | $tags_str = format_tags_string($tags, $id); | |
357 | $tags_str_full = join(", ", $tags); | |
358 | ||
359 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
360 | ||
361 | print json_encode(array("tags_str" => array("id" => $id, | |
362 | "content" => $tags_str, "content_full" => $tags_str_full))); | |
363 | } | |
364 | ||
365 | function regenOPMLKey() { | |
87d7e850 | 366 | $this->update_feed_access_key($this->link, 'OPML:Publish', |
d5112468 AD |
367 | false, $_SESSION["uid"]); |
368 | ||
50832719 | 369 | $new_link = Opml::opml_publish_url($this->link); |
d5112468 AD |
370 | |
371 | print json_encode(array("link" => $new_link)); | |
372 | } | |
373 | ||
1b4d1a6b | 374 | function completeLabels() { |
3972bf59 | 375 | $search = db_escape_string($this->link, $_REQUEST["search"]); |
1b4d1a6b AD |
376 | |
377 | $result = db_query($this->link, "SELECT DISTINCT caption FROM | |
378 | ttrss_labels2 | |
379 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
380 | LOWER(caption) LIKE LOWER('$search%') ORDER BY caption | |
381 | LIMIT 5"); | |
382 | ||
383 | print "<ul>"; | |
384 | while ($line = db_fetch_assoc($result)) { | |
385 | print "<li>" . $line["caption"] . "</li>"; | |
386 | } | |
387 | print "</ul>"; | |
388 | } | |
389 | ||
390 | ||
d5112468 | 391 | function completeTags() { |
3972bf59 | 392 | $search = db_escape_string($this->link, $_REQUEST["search"]); |
d5112468 AD |
393 | |
394 | $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags | |
395 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
396 | tag_name LIKE '$search%' ORDER BY tag_name | |
397 | LIMIT 10"); | |
398 | ||
399 | print "<ul>"; | |
400 | while ($line = db_fetch_assoc($result)) { | |
401 | print "<li>" . $line["tag_name"] . "</li>"; | |
402 | } | |
403 | print "</ul>"; | |
404 | } | |
405 | ||
406 | function purge() { | |
3972bf59 | 407 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
408 | $days = sprintf("%d", $_REQUEST["days"]); |
409 | ||
410 | foreach ($ids as $id) { | |
411 | ||
412 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
413 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
414 | ||
415 | if (db_num_rows($result) == 1) { | |
416 | purge_feed($this->link, $id, $days); | |
417 | } | |
418 | } | |
419 | } | |
420 | ||
421 | function getArticles() { | |
3972bf59 | 422 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
d5112468 AD |
423 | $articles = array(); |
424 | ||
425 | foreach ($ids as $id) { | |
426 | if ($id) { | |
427 | array_push($articles, format_article($this->link, $id, 0, false)); | |
428 | } | |
429 | } | |
430 | ||
431 | print json_encode($articles); | |
432 | } | |
433 | ||
434 | function checkDate() { | |
3972bf59 | 435 | $date = db_escape_string($this->link, $_REQUEST["date"]); |
d5112468 AD |
436 | $date_parsed = strtotime($date); |
437 | ||
438 | print json_encode(array("result" => (bool)$date_parsed, | |
439 | "date" => date("c", $date_parsed))); | |
440 | } | |
441 | ||
442 | function assigntolabel() { | |
4fdb8759 | 443 | return $this->labelops(true); |
d5112468 | 444 | } |
46da73c2 | 445 | |
d5112468 | 446 | function removefromlabel() { |
4fdb8759 | 447 | return $this->labelops(false); |
d5112468 | 448 | } |
46da73c2 | 449 | |
d5112468 AD |
450 | function labelops($assign) { |
451 | $reply = array(); | |
452 | ||
3972bf59 AD |
453 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
454 | $label_id = db_escape_string($this->link, $_REQUEST["lid"]); | |
d5112468 | 455 | |
3972bf59 | 456 | $label = db_escape_string($this->link, label_find_caption($this->link, $label_id, |
d5112468 AD |
457 | $_SESSION["uid"])); |
458 | ||
459 | $reply["info-for-headlines"] = array(); | |
460 | ||
461 | if ($label) { | |
462 | ||
463 | foreach ($ids as $id) { | |
464 | ||
465 | if ($assign) | |
466 | label_add_article($this->link, $id, $label, $_SESSION["uid"]); | |
467 | else | |
468 | label_remove_article($this->link, $id, $label, $_SESSION["uid"]); | |
469 | ||
470 | $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); | |
471 | ||
472 | array_push($reply["info-for-headlines"], | |
473 | array("id" => $id, "labels" => format_article_labels($labels, $id))); | |
474 | ||
475 | } | |
476 | } | |
477 | ||
478 | $reply["message"] = "UPDATE_COUNTERS"; | |
479 | ||
480 | print json_encode($reply); | |
481 | } | |
482 | ||
483 | function updateFeedBrowser() { | |
3972bf59 AD |
484 | $search = db_escape_string($this->link, $_REQUEST["search"]); |
485 | $limit = db_escape_string($this->link, $_REQUEST["limit"]); | |
486 | $mode = (int) db_escape_string($this->link, $_REQUEST["mode"]); | |
d5112468 | 487 | |
55c7f092 AD |
488 | require_once "feedbrowser.php"; |
489 | ||
d5112468 AD |
490 | print json_encode(array("content" => |
491 | make_feed_browser($this->link, $search, $limit, $mode), | |
492 | "mode" => $mode)); | |
493 | } | |
494 | ||
495 | // Silent | |
496 | function massSubscribe() { | |
497 | ||
498 | $payload = json_decode($_REQUEST["payload"], false); | |
499 | $mode = $_REQUEST["mode"]; | |
500 | ||
501 | if (!$payload || !is_array($payload)) return; | |
502 | ||
503 | if ($mode == 1) { | |
504 | foreach ($payload as $feed) { | |
505 | ||
3972bf59 AD |
506 | $title = db_escape_string($this->link, $feed[0]); |
507 | $feed_url = db_escape_string($this->link, $feed[1]); | |
d5112468 AD |
508 | |
509 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
510 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
511 | ||
512 | if (db_num_rows($result) == 0) { | |
513 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
514 | (owner_uid,feed_url,title,cat_id,site_url) | |
515 | VALUES ('".$_SESSION["uid"]."', | |
516 | '$feed_url', '$title', NULL, '')"); | |
517 | } | |
518 | } | |
519 | } else if ($mode == 2) { | |
520 | // feed archive | |
521 | foreach ($payload as $id) { | |
522 | $result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds | |
523 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
524 | ||
525 | if (db_num_rows($result) != 0) { | |
3972bf59 AD |
526 | $site_url = db_escape_string($this->link, db_fetch_result($result, 0, "site_url")); |
527 | $feed_url = db_escape_string($this->link, db_fetch_result($result, 0, "feed_url")); | |
528 | $title = db_escape_string($this->link, db_fetch_result($result, 0, "title")); | |
d5112468 AD |
529 | |
530 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE | |
531 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
532 | ||
533 | if (db_num_rows($result) == 0) { | |
534 | $result = db_query($this->link, "INSERT INTO ttrss_feeds | |
535 | (owner_uid,feed_url,title,cat_id,site_url) | |
536 | VALUES ('$id','".$_SESSION["uid"]."', | |
537 | '$feed_url', '$title', NULL, '$site_url')"); | |
538 | } | |
539 | } | |
540 | } | |
541 | } | |
542 | } | |
543 | ||
d5112468 | 544 | function catchupFeed() { |
3972bf59 AD |
545 | $feed_id = db_escape_string($this->link, $_REQUEST['feed_id']); |
546 | $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true"; | |
547 | $max_id = (int) db_escape_string($this->link, $_REQUEST['max_id']); | |
d5112468 | 548 | |
184f5195 | 549 | catchup_feed($this->link, $feed_id, $is_cat, false, $max_id); |
d5112468 AD |
550 | |
551 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
552 | } | |
553 | ||
d5112468 | 554 | function quickAddCat() { |
3972bf59 | 555 | $cat = db_escape_string($this->link, $_REQUEST["cat"]); |
d5112468 AD |
556 | |
557 | add_feed_category($this->link, $cat); | |
558 | ||
559 | $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE | |
560 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); | |
561 | ||
562 | if (db_num_rows($result) == 1) { | |
563 | $id = db_fetch_result($result, 0, "id"); | |
564 | } else { | |
565 | $id = 0; | |
566 | } | |
567 | ||
568 | print_feed_cat_select($this->link, "cat_id", $id); | |
569 | } | |
570 | ||
571 | function regenFeedKey() { | |
3972bf59 AD |
572 | $feed_id = db_escape_string($this->link, $_REQUEST['id']); |
573 | $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true"; | |
d5112468 | 574 | |
87d7e850 | 575 | $new_key = $this->update_feed_access_key($this->link, $feed_id, $is_cat); |
d5112468 AD |
576 | |
577 | print json_encode(array("link" => $new_key)); | |
578 | } | |
579 | ||
580 | // Silent | |
581 | function clearKeys() { | |
582 | db_query($this->link, "DELETE FROM ttrss_access_keys WHERE | |
583 | owner_uid = " . $_SESSION["uid"]); | |
584 | } | |
585 | ||
586 | // Silent | |
587 | function clearArticleKeys() { | |
588 | db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE | |
589 | owner_uid = " . $_SESSION["uid"]); | |
590 | ||
591 | return; | |
592 | } | |
593 | ||
d5112468 AD |
594 | function verifyRegexp() { |
595 | $reg_exp = $_REQUEST["reg_exp"]; | |
596 | ||
597 | $status = @preg_match("/$reg_exp/i", "TEST") !== false; | |
598 | ||
599 | print json_encode(array("status" => $status)); | |
600 | } | |
601 | ||
19c73507 | 602 | /* function buttonPlugin() { |
369dbc19 | 603 | $pclass = "button_" . basename($_REQUEST['plugin']); |
f9ac31d6 AD |
604 | $method = $_REQUEST['plugin_method']; |
605 | ||
606 | if (class_exists($pclass)) { | |
607 | $plugin = new $pclass($this->link); | |
608 | if (method_exists($plugin, $method)) { | |
609 | return $plugin->$method(); | |
610 | } | |
d5112468 | 611 | } |
19c73507 | 612 | } */ |
d5112468 | 613 | |
d5112468 AD |
614 | function genHash() { |
615 | $hash = sha1(uniqid(rand(), true)); | |
616 | ||
617 | print json_encode(array("hash" => $hash)); | |
618 | } | |
33f0fdd0 AD |
619 | |
620 | function batchAddFeeds() { | |
3972bf59 AD |
621 | $cat_id = db_escape_string($this->link, $_REQUEST['cat']); |
622 | $feeds = explode("\n", db_escape_string($this->link, $_REQUEST['feeds'])); | |
623 | $login = db_escape_string($this->link, $_REQUEST['login']); | |
624 | $pass = db_escape_string($this->link, $_REQUEST['pass']); | |
33f0fdd0 | 625 | |
33f0fdd0 AD |
626 | foreach ($feeds as $feed) { |
627 | $feed = trim($feed); | |
628 | ||
629 | if (validate_feed_url($feed)) { | |
630 | ||
631 | db_query($this->link, "BEGIN"); | |
632 | ||
33f0fdd0 AD |
633 | if ($cat_id == "0" || !$cat_id) { |
634 | $cat_qpart = "NULL"; | |
635 | } else { | |
636 | $cat_qpart = "'$cat_id'"; | |
637 | } | |
638 | ||
639 | $result = db_query($this->link, | |
640 | "SELECT id FROM ttrss_feeds | |
641 | WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
642 | ||
643 | if (db_num_rows($result) == 0) { | |
644 | $result = db_query($this->link, | |
645 | "INSERT INTO ttrss_feeds | |
646 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method) | |
647 | VALUES ('".$_SESSION["uid"]."', '$feed', | |
19b3992b | 648 | '[Unknown]', $cat_qpart, '$login', '$pass', 0)"); |
33f0fdd0 AD |
649 | } |
650 | ||
651 | db_query($this->link, "COMMIT"); | |
652 | } | |
653 | } | |
654 | } | |
655 | ||
beb6ce27 | 656 | function setScore() { |
3972bf59 AD |
657 | $ids = db_escape_string($this->link, $_REQUEST['id']); |
658 | $score = (int)db_escape_string($this->link, $_REQUEST['score']); | |
beb6ce27 AD |
659 | |
660 | db_query($this->link, "UPDATE ttrss_user_entries SET | |
29064218 | 661 | score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
beb6ce27 AD |
662 | |
663 | print json_encode(array("id" => $id, | |
2a3b6de0 | 664 | "score_pic" => get_score_pic($score))); |
beb6ce27 AD |
665 | } |
666 | ||
7d8f5657 AD |
667 | function setpanelmode() { |
668 | $wide = (int) $_REQUEST["wide"]; | |
669 | ||
f03701fe AD |
670 | setcookie("ttrss_widescreen", $wide, |
671 | time() + SESSION_COOKIE_LIFETIME); | |
7d8f5657 AD |
672 | |
673 | print json_encode(array("wide" => $wide)); | |
674 | } | |
675 | ||
8b83bf5f AD |
676 | function updaterandomfeed() { |
677 | // Test if the feed need a update (update interval exceded). | |
678 | if (DB_TYPE == "pgsql") { | |
679 | $update_limit_qpart = "AND (( | |
680 | ttrss_feeds.update_interval = 0 | |
681 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) | |
682 | ) OR ( | |
683 | ttrss_feeds.update_interval > 0 | |
684 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) | |
685 | ) OR ttrss_feeds.last_updated IS NULL | |
686 | OR last_updated = '1970-01-01 00:00:00')"; | |
687 | } else { | |
688 | $update_limit_qpart = "AND (( | |
689 | ttrss_feeds.update_interval = 0 | |
690 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) | |
691 | ) OR ( | |
692 | ttrss_feeds.update_interval > 0 | |
693 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) | |
694 | ) OR ttrss_feeds.last_updated IS NULL | |
695 | OR last_updated = '1970-01-01 00:00:00')"; | |
696 | } | |
697 | ||
698 | // Test if feed is currently being updated by another process. | |
699 | if (DB_TYPE == "pgsql") { | |
700 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; | |
701 | } else { | |
702 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; | |
703 | } | |
704 | ||
705 | $random_qpart = sql_random_function(); | |
706 | ||
707 | // We search for feed needing update. | |
708 | $result = db_query($this->link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id | |
709 | FROM | |
710 | ttrss_feeds, ttrss_users, ttrss_user_prefs | |
711 | WHERE | |
712 | ttrss_feeds.owner_uid = ttrss_users.id | |
713 | AND ttrss_users.id = ttrss_user_prefs.owner_uid | |
714 | AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' | |
715 | AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." | |
716 | $update_limit_qpart $updstart_thresh_qpart | |
717 | ORDER BY $random_qpart LIMIT 30"); | |
718 | ||
719 | $feed_id = -1; | |
720 | ||
721 | require_once "rssfuncs.php"; | |
722 | ||
723 | $num_updated = 0; | |
724 | ||
725 | $tstart = time(); | |
726 | ||
727 | while ($line = db_fetch_assoc($result)) { | |
728 | $feed_id = $line["id"]; | |
729 | ||
6b1a4ecd | 730 | if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
8b83bf5f AD |
731 | update_rss_feed($this->link, $feed_id, true); |
732 | ++$num_updated; | |
733 | } else { | |
734 | break; | |
735 | } | |
736 | } | |
737 | ||
738 | if ($num_updated > 0) { | |
739 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
740 | "num_updated" => $num_updated)); | |
741 | } else { | |
742 | print json_encode(array("message" => "NOTHING_TO_UPDATE")); | |
743 | } | |
744 | ||
745 | } | |
746 | ||
87d7e850 AD |
747 | function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) { |
748 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
749 | ||
750 | $sql_is_cat = bool_to_sql_bool($is_cat); | |
751 | ||
752 | $result = db_query($link, "SELECT access_key FROM ttrss_access_keys | |
753 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat | |
754 | AND owner_uid = " . $owner_uid); | |
755 | ||
756 | if (db_num_rows($result) == 1) { | |
3972bf59 | 757 | $key = db_escape_string($this->link, sha1(uniqid(rand(), true))); |
87d7e850 AD |
758 | |
759 | db_query($link, "UPDATE ttrss_access_keys SET access_key = '$key' | |
760 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat | |
761 | AND owner_uid = " . $owner_uid); | |
762 | ||
763 | return $key; | |
764 | ||
765 | } else { | |
766 | return get_feed_access_key($link, $feed_id, $is_cat, $owner_uid); | |
767 | } | |
768 | } | |
769 | ||
770 | private function markArticlesById($link, $ids, $cmode) { | |
771 | ||
772 | $tmp_ids = array(); | |
773 | ||
774 | foreach ($ids as $id) { | |
775 | array_push($tmp_ids, "ref_id = '$id'"); | |
776 | } | |
777 | ||
778 | $ids_qpart = join(" OR ", $tmp_ids); | |
779 | ||
780 | if ($cmode == 0) { | |
781 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 782 | marked = false, last_marked = NOW() |
87d7e850 AD |
783 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
784 | } else if ($cmode == 1) { | |
785 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 786 | marked = true, last_marked = NOW() |
87d7e850 AD |
787 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
788 | } else { | |
789 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 790 | marked = NOT marked,last_marked = NOW() |
87d7e850 AD |
791 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
792 | } | |
793 | } | |
794 | ||
795 | private function publishArticlesById($link, $ids, $cmode) { | |
796 | ||
797 | $tmp_ids = array(); | |
798 | ||
799 | foreach ($ids as $id) { | |
800 | array_push($tmp_ids, "ref_id = '$id'"); | |
801 | } | |
802 | ||
803 | $ids_qpart = join(" OR ", $tmp_ids); | |
804 | ||
805 | if ($cmode == 0) { | |
806 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 807 | published = false,last_published = NOW() |
87d7e850 AD |
808 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
809 | } else if ($cmode == 1) { | |
810 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 811 | published = true,last_published = NOW() |
87d7e850 AD |
812 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
813 | } else { | |
814 | db_query($link, "UPDATE ttrss_user_entries SET | |
7873d588 | 815 | published = NOT published,last_published = NOW() |
87d7e850 AD |
816 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
817 | } | |
818 | ||
819 | if (PUBSUBHUBBUB_HUB) { | |
820 | $rss_link = get_self_url_prefix() . | |
821 | "/public.php?op=rss&id=-2&key=" . | |
822 | get_feed_access_key($link, -2, false); | |
823 | ||
824 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
825 | ||
826 | $pubsub_result = $p->publish_update($rss_link); | |
827 | } | |
828 | } | |
829 | ||
5defc29f | 830 | function getlinktitlebyid() { |
3972bf59 | 831 | $id = db_escape_string($this->link, $_REQUEST['id']); |
7fc2e87e | 832 | |
5defc29f | 833 | $result = db_query($this->link, "SELECT link, title FROM ttrss_entries, ttrss_user_entries |
7fc2e87e AD |
834 | WHERE ref_id = '$id' AND ref_id = id AND owner_uid = ". $_SESSION["uid"]); |
835 | ||
836 | if (db_num_rows($result) != 0) { | |
837 | $link = db_fetch_result($result, 0, "link"); | |
5defc29f | 838 | $title = db_fetch_result($result, 0, "title"); |
7fc2e87e | 839 | |
5defc29f | 840 | echo json_encode(array("link" => $link, "title" => $title)); |
7fc2e87e AD |
841 | } else { |
842 | echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); | |
843 | } | |
844 | } | |
845 | ||
d2f3467b AD |
846 | function cdmArticlePreview() { |
847 | $id = db_escape_string($this->link, $_REQUEST['id']); | |
848 | ||
849 | $result = db_query($this->link, "SELECT link, | |
850 | ttrss_entries.title, content, feed_url | |
851 | FROM | |
852 | ttrss_entries, ttrss_user_entries | |
853 | LEFT JOIN ttrss_feeds ON (ttrss_user_entries.feed_id = ttrss_feeds.id) | |
854 | WHERE ref_id = '$id' AND ref_id = ttrss_entries.id AND | |
855 | ttrss_user_entries.owner_uid = ". $_SESSION["uid"]); | |
856 | ||
857 | if (db_num_rows($result) != 0) { | |
858 | $link = db_fetch_result($result, 0, "link"); | |
859 | $title = db_fetch_result($result, 0, "title"); | |
860 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
861 | ||
862 | $content = sanitize($this->link, | |
863 | db_fetch_result($result, 0, "content"), false, false, $feed_url); | |
864 | ||
865 | print "<div class='content'>".$content."</content>"; | |
866 | ||
867 | } else { | |
868 | print "Article not found."; | |
869 | } | |
870 | ||
871 | } | |
872 | ||
d5112468 AD |
873 | } |
874 | ?> |