]>
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() { |
d9c85e0f | 11 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
46da73c2 | 12 | |
d5112468 | 13 | $_SESSION["profile"] = $id; |
d5112468 AD |
14 | } |
15 | ||
16 | function remprofiles() { | |
d9c85e0f | 17 | $ids = explode(",", $this->dbh->escape_string(trim($_REQUEST["ids"]))); |
d5112468 AD |
18 | |
19 | foreach ($ids as $id) { | |
20 | if ($_SESSION["profile"] != $id) { | |
d9c85e0f | 21 | $this->dbh->query("DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND |
d5112468 AD |
22 | owner_uid = " . $_SESSION["uid"]); |
23 | } | |
24 | } | |
25 | } | |
26 | ||
27 | // Silent | |
28 | function addprofile() { | |
d9c85e0f | 29 | $title = $this->dbh->escape_string(trim($_REQUEST["title"])); |
d5112468 | 30 | if ($title) { |
d9c85e0f | 31 | $this->dbh->query("BEGIN"); |
d5112468 | 32 | |
d9c85e0f | 33 | $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles |
d5112468 AD |
34 | WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); |
35 | ||
d9c85e0f | 36 | if ($this->dbh->num_rows($result) == 0) { |
d5112468 | 37 | |
d9c85e0f | 38 | $this->dbh->query("INSERT INTO ttrss_settings_profiles (title, owner_uid) |
d5112468 AD |
39 | VALUES ('$title', ".$_SESSION["uid"] .")"); |
40 | ||
d9c85e0f | 41 | $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles WHERE |
d5112468 AD |
42 | title = '$title'"); |
43 | ||
d9c85e0f AD |
44 | if ($this->dbh->num_rows($result) != 0) { |
45 | $profile_id = $this->dbh->fetch_result($result, 0, "id"); | |
d5112468 AD |
46 | |
47 | if ($profile_id) { | |
a42c55f0 | 48 | initialize_user_prefs($_SESSION["uid"], $profile_id); |
d5112468 AD |
49 | } |
50 | } | |
51 | } | |
52 | ||
d9c85e0f | 53 | $this->dbh->query("COMMIT"); |
d5112468 AD |
54 | } |
55 | } | |
56 | ||
57 | // Silent | |
58 | function saveprofile() { | |
d9c85e0f AD |
59 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
60 | $title = $this->dbh->escape_string(trim($_REQUEST["value"])); | |
d5112468 AD |
61 | |
62 | if ($id == 0) { | |
63 | print __("Default profile"); | |
64 | return; | |
65 | } | |
66 | ||
67 | if ($title) { | |
d9c85e0f | 68 | $this->dbh->query("BEGIN"); |
d5112468 | 69 | |
d9c85e0f | 70 | $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles |
d5112468 AD |
71 | WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); |
72 | ||
d9c85e0f AD |
73 | if ($this->dbh->num_rows($result) == 0) { |
74 | $this->dbh->query("UPDATE ttrss_settings_profiles | |
d5112468 AD |
75 | SET title = '$title' WHERE id = '$id' AND |
76 | owner_uid = " . $_SESSION["uid"]); | |
77 | print $title; | |
78 | } else { | |
d9c85e0f | 79 | $result = $this->dbh->query("SELECT title FROM ttrss_settings_profiles |
d5112468 | 80 | WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); |
d9c85e0f | 81 | print $this->dbh->fetch_result($result, 0, "title"); |
d5112468 AD |
82 | } |
83 | ||
d9c85e0f | 84 | $this->dbh->query("COMMIT"); |
d5112468 AD |
85 | } |
86 | } | |
87 | ||
88 | // Silent | |
89 | function remarchive() { | |
d9c85e0f | 90 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
91 | |
92 | foreach ($ids as $id) { | |
d9c85e0f | 93 | $result = $this->dbh->query("DELETE FROM ttrss_archived_feeds WHERE |
d5112468 AD |
94 | (SELECT COUNT(*) FROM ttrss_user_entries |
95 | WHERE orig_feed_id = '$id') = 0 AND | |
96 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
97 | ||
4a80c57c | 98 | $this->dbh->affected_rows($result); |
d5112468 AD |
99 | } |
100 | } | |
101 | ||
102 | function addfeed() { | |
d9c85e0f AD |
103 | $feed = $this->dbh->escape_string($_REQUEST['feed']); |
104 | $cat = $this->dbh->escape_string($_REQUEST['cat']); | |
105 | $login = $this->dbh->escape_string($_REQUEST['login']); | |
41694a95 | 106 | $pass = trim($_REQUEST['pass']); // escaped later |
d5112468 | 107 | |
a42c55f0 | 108 | $rc = subscribe_to_feed($feed, $cat, $login, $pass); |
d5112468 AD |
109 | |
110 | print json_encode(array("result" => $rc)); | |
111 | } | |
112 | ||
d5112468 | 113 | function togglepref() { |
d9c85e0f | 114 | $key = $this->dbh->escape_string($_REQUEST["key"]); |
a42c55f0 AD |
115 | set_pref($key, !get_pref($key)); |
116 | $value = get_pref($key); | |
d5112468 AD |
117 | |
118 | print json_encode(array("param" =>$key, "value" => $value)); | |
119 | } | |
120 | ||
121 | function setpref() { | |
0380cfa9 | 122 | // set_pref escapes input, so no need to double escape it here |
74eef4fc AD |
123 | $key = $_REQUEST['key']; |
124 | $value = str_replace("\n", "<br/>", $_REQUEST['value']); | |
d5112468 | 125 | |
86d07d36 | 126 | set_pref($key, $value, false, $key != 'USER_STYLESHEET'); |
d5112468 AD |
127 | |
128 | print json_encode(array("param" =>$key, "value" => $value)); | |
129 | } | |
130 | ||
131 | function mark() { | |
132 | $mark = $_REQUEST["mark"]; | |
d9c85e0f | 133 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
d5112468 AD |
134 | |
135 | if ($mark == "1") { | |
136 | $mark = "true"; | |
137 | } else { | |
138 | $mark = "false"; | |
139 | } | |
140 | ||
4a80c57c | 141 | $this->dbh->query("UPDATE ttrss_user_entries SET marked = $mark, |
7873d588 | 142 | last_marked = NOW() |
d5112468 AD |
143 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
144 | ||
145 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
146 | } | |
147 | ||
148 | function delete() { | |
d9c85e0f | 149 | $ids = $this->dbh->escape_string($_REQUEST["ids"]); |
d5112468 | 150 | |
4a80c57c AD |
151 | $this->dbh->query("DELETE FROM ttrss_user_entries |
152 | WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); | |
d5112468 | 153 | |
6322ac79 | 154 | purge_orphans(); |
f0d3c94a | 155 | |
d5112468 AD |
156 | print json_encode(array("message" => "UPDATE_COUNTERS")); |
157 | } | |
158 | ||
159 | function unarchive() { | |
b029f916 AD |
160 | $ids = explode(",", $_REQUEST["ids"]); |
161 | ||
162 | foreach ($ids as $id) { | |
d9c85e0f AD |
163 | $id = $this->dbh->escape_string(trim($id)); |
164 | $this->dbh->query("BEGIN"); | |
b029f916 | 165 | |
d9c85e0f | 166 | $result = $this->dbh->query("SELECT feed_url,site_url,title FROM ttrss_archived_feeds |
b029f916 | 167 | WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = $id |
71b75bb7 | 168 | AND owner_uid = ".$_SESSION["uid"].") AND owner_uid = " . $_SESSION["uid"]); |
b029f916 | 169 | |
d9c85e0f AD |
170 | if ($this->dbh->num_rows($result) != 0) { |
171 | $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url")); | |
172 | $site_url = $this->dbh->escape_string(db_fetch_result($result, 0, "site_url")); | |
173 | $title = $this->dbh->escape_string(db_fetch_result($result, 0, "title")); | |
b029f916 | 174 | |
d9c85e0f | 175 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' |
b029f916 AD |
176 | AND owner_uid = " .$_SESSION["uid"]); |
177 | ||
d9c85e0f | 178 | if ($this->dbh->num_rows($result) == 0) { |
b029f916 AD |
179 | |
180 | if (!$title) $title = '[Unknown]'; | |
181 | ||
d9c85e0f | 182 | $result = $this->dbh->query( |
b029f916 AD |
183 | "INSERT INTO ttrss_feeds |
184 | (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method) | |
185 | VALUES (".$_SESSION["uid"].", | |
186 | '$feed_url', | |
187 | '$site_url', | |
188 | '$title', | |
189 | NULL, '', '', 0)"); | |
d5112468 | 190 | |
d9c85e0f | 191 | $result = $this->dbh->query( |
b029f916 AD |
192 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' |
193 | AND owner_uid = ".$_SESSION["uid"]); | |
194 | ||
d9c85e0f AD |
195 | if ($this->dbh->num_rows($result) != 0) { |
196 | $feed_id = $this->dbh->fetch_result($result, 0, "id"); | |
b029f916 AD |
197 | } |
198 | ||
199 | } else { | |
d9c85e0f | 200 | $feed_id = $this->dbh->fetch_result($result, 0, "id"); |
b029f916 AD |
201 | } |
202 | ||
203 | if ($feed_id) { | |
d9c85e0f | 204 | $result = $this->dbh->query("UPDATE ttrss_user_entries |
b029f916 AD |
205 | SET feed_id = '$feed_id', orig_feed_id = NULL |
206 | WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]); | |
207 | } | |
208 | } | |
209 | ||
d9c85e0f | 210 | $this->dbh->query("COMMIT"); |
b029f916 | 211 | } |
d5112468 AD |
212 | |
213 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
214 | } | |
215 | ||
216 | function archive() { | |
d9c85e0f | 217 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
218 | |
219 | foreach ($ids as $id) { | |
a42c55f0 | 220 | $this->archive_article($id, $_SESSION["uid"]); |
d5112468 AD |
221 | } |
222 | ||
223 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
224 | } | |
225 | ||
a42c55f0 | 226 | private function archive_article($id, $owner_uid) { |
d9c85e0f | 227 | $this->dbh->query("BEGIN"); |
87d7e850 | 228 | |
d9c85e0f | 229 | $result = $this->dbh->query("SELECT feed_id FROM ttrss_user_entries |
87d7e850 AD |
230 | WHERE ref_id = '$id' AND owner_uid = $owner_uid"); |
231 | ||
d9c85e0f | 232 | if ($this->dbh->num_rows($result) != 0) { |
87d7e850 AD |
233 | |
234 | /* prepare the archived table */ | |
235 | ||
d9c85e0f | 236 | $feed_id = (int) $this->dbh->fetch_result($result, 0, "feed_id"); |
87d7e850 AD |
237 | |
238 | if ($feed_id) { | |
d9c85e0f | 239 | $result = $this->dbh->query("SELECT id FROM ttrss_archived_feeds |
71b75bb7 | 240 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
87d7e850 | 241 | |
d9c85e0f | 242 | if ($this->dbh->num_rows($result) == 0) { |
71b75bb7 AD |
243 | $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
244 | $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1; | |
245 | ||
d9c85e0f | 246 | $this->dbh->query("INSERT INTO ttrss_archived_feeds |
87d7e850 | 247 | (id, owner_uid, title, feed_url, site_url) |
71b75bb7 | 248 | SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds |
87d7e850 | 249 | WHERE id = '$feed_id'"); |
71b75bb7 AD |
250 | } else { |
251 | $new_feed_id = $this->dbh->fetch_result($result, 0, "id"); | |
87d7e850 AD |
252 | } |
253 | ||
d9c85e0f | 254 | $this->dbh->query("UPDATE ttrss_user_entries |
71b75bb7 | 255 | SET orig_feed_id = $new_feed_id, feed_id = NULL |
87d7e850 AD |
256 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
257 | } | |
258 | } | |
259 | ||
d9c85e0f | 260 | $this->dbh->query("COMMIT"); |
87d7e850 AD |
261 | } |
262 | ||
d5112468 AD |
263 | function publ() { |
264 | $pub = $_REQUEST["pub"]; | |
d9c85e0f | 265 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
d5112468 AD |
266 | |
267 | if ($pub == "1") { | |
268 | $pub = "true"; | |
269 | } else { | |
270 | $pub = "false"; | |
271 | } | |
272 | ||
4a80c57c | 273 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 274 | published = $pub, last_published = NOW() |
d5112468 AD |
275 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
276 | ||
277 | $pubsub_result = false; | |
278 | ||
279 | if (PUBSUBHUBBUB_HUB) { | |
280 | $rss_link = get_self_url_prefix() . | |
281 | "/public.php?op=rss&id=-2&key=" . | |
a42c55f0 | 282 | get_feed_access_key(-2, false); |
d5112468 AD |
283 | |
284 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
285 | ||
286 | $pubsub_result = $p->publish_update($rss_link); | |
287 | } | |
288 | ||
289 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
290 | "pubsub_result" => $pubsub_result)); | |
291 | } | |
292 | ||
293 | function getAllCounters() { | |
294 | $last_article_id = (int) $_REQUEST["last_article_id"]; | |
295 | ||
296 | $reply = array(); | |
297 | ||
6f7798b6 | 298 | if (!empty($_REQUEST['seq'])) $reply['seq'] = (int) $_REQUEST['seq']; |
d5112468 | 299 | |
6322ac79 AD |
300 | if ($last_article_id != getLastArticleId()) { |
301 | $reply['counters'] = getAllCounters(); | |
5b55e9e2 | 302 | } |
d5112468 | 303 | |
6322ac79 | 304 | $reply['runtime-info'] = make_runtime_info(); |
d5112468 | 305 | |
5b55e9e2 | 306 | print json_encode($reply); |
d5112468 AD |
307 | } |
308 | ||
309 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
310 | function catchupSelected() { | |
d9c85e0f | 311 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
312 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
313 | ||
a42c55f0 | 314 | catchupArticlesById($ids, $cmode); |
d5112468 | 315 | |
ae31704b | 316 | print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids)); |
d5112468 AD |
317 | } |
318 | ||
319 | function markSelected() { | |
d9c85e0f | 320 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
321 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
322 | ||
a42c55f0 | 323 | $this->markArticlesById($ids, $cmode); |
d5112468 AD |
324 | |
325 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
326 | } | |
327 | ||
328 | function publishSelected() { | |
d9c85e0f | 329 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
330 | $cmode = sprintf("%d", $_REQUEST["cmode"]); |
331 | ||
a42c55f0 | 332 | $this->publishArticlesById($ids, $cmode); |
d5112468 AD |
333 | |
334 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
335 | } | |
336 | ||
337 | function sanityCheck() { | |
338 | $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; | |
4f7d69e1 | 339 | $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true"; |
40fe2d73 | 340 | $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true"; |
6bfc97da | 341 | $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"]; |
d5112468 AD |
342 | |
343 | $reply = array(); | |
344 | ||
6322ac79 | 345 | $reply['error'] = sanity_check(); |
d5112468 AD |
346 | |
347 | if ($reply['error']['code'] == 0) { | |
6322ac79 | 348 | $reply['init-params'] = make_init_params(); |
79c891a8 | 349 | $reply['runtime-info'] = make_runtime_info(true); |
d5112468 AD |
350 | } |
351 | ||
352 | print json_encode($reply); | |
353 | } | |
354 | ||
1b4d1a6b | 355 | function completeLabels() { |
d9c85e0f | 356 | $search = $this->dbh->escape_string($_REQUEST["search"]); |
1b4d1a6b | 357 | |
d9c85e0f | 358 | $result = $this->dbh->query("SELECT DISTINCT caption FROM |
1b4d1a6b AD |
359 | ttrss_labels2 |
360 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
361 | LOWER(caption) LIKE LOWER('$search%') ORDER BY caption | |
362 | LIMIT 5"); | |
363 | ||
364 | print "<ul>"; | |
d9c85e0f | 365 | while ($line = $this->dbh->fetch_assoc($result)) { |
1b4d1a6b AD |
366 | print "<li>" . $line["caption"] . "</li>"; |
367 | } | |
368 | print "</ul>"; | |
369 | } | |
370 | ||
d5112468 | 371 | function purge() { |
d9c85e0f | 372 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
d5112468 AD |
373 | $days = sprintf("%d", $_REQUEST["days"]); |
374 | ||
375 | foreach ($ids as $id) { | |
376 | ||
d9c85e0f | 377 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
d5112468 AD |
378 | id = '$id' AND owner_uid = ".$_SESSION["uid"]); |
379 | ||
d9c85e0f | 380 | if ($this->dbh->num_rows($result) == 1) { |
a42c55f0 | 381 | purge_feed($id, $days); |
d5112468 AD |
382 | } |
383 | } | |
384 | } | |
385 | ||
d5112468 | 386 | function updateFeedBrowser() { |
0e653f75 AK |
387 | if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return; |
388 | ||
d9c85e0f AD |
389 | $search = $this->dbh->escape_string($_REQUEST["search"]); |
390 | $limit = $this->dbh->escape_string($_REQUEST["limit"]); | |
391 | $mode = (int) $this->dbh->escape_string($_REQUEST["mode"]); | |
d5112468 | 392 | |
55c7f092 AD |
393 | require_once "feedbrowser.php"; |
394 | ||
d5112468 | 395 | print json_encode(array("content" => |
a42c55f0 | 396 | make_feed_browser($search, $limit, $mode), |
d5112468 AD |
397 | "mode" => $mode)); |
398 | } | |
399 | ||
400 | // Silent | |
401 | function massSubscribe() { | |
402 | ||
403 | $payload = json_decode($_REQUEST["payload"], false); | |
404 | $mode = $_REQUEST["mode"]; | |
405 | ||
406 | if (!$payload || !is_array($payload)) return; | |
407 | ||
408 | if ($mode == 1) { | |
409 | foreach ($payload as $feed) { | |
410 | ||
d9c85e0f AD |
411 | $title = $this->dbh->escape_string($feed[0]); |
412 | $feed_url = $this->dbh->escape_string($feed[1]); | |
d5112468 | 413 | |
d9c85e0f | 414 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
d5112468 AD |
415 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); |
416 | ||
d9c85e0f AD |
417 | if ($this->dbh->num_rows($result) == 0) { |
418 | $result = $this->dbh->query("INSERT INTO ttrss_feeds | |
d5112468 AD |
419 | (owner_uid,feed_url,title,cat_id,site_url) |
420 | VALUES ('".$_SESSION["uid"]."', | |
421 | '$feed_url', '$title', NULL, '')"); | |
422 | } | |
423 | } | |
424 | } else if ($mode == 2) { | |
425 | // feed archive | |
426 | foreach ($payload as $id) { | |
d9c85e0f | 427 | $result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds |
d5112468 AD |
428 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
429 | ||
d9c85e0f AD |
430 | if ($this->dbh->num_rows($result) != 0) { |
431 | $site_url = $this->dbh->escape_string(db_fetch_result($result, 0, "site_url")); | |
432 | $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url")); | |
433 | $title = $this->dbh->escape_string(db_fetch_result($result, 0, "title")); | |
d5112468 | 434 | |
d9c85e0f | 435 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
d5112468 AD |
436 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); |
437 | ||
d9c85e0f AD |
438 | if ($this->dbh->num_rows($result) == 0) { |
439 | $result = $this->dbh->query("INSERT INTO ttrss_feeds | |
d5112468 AD |
440 | (owner_uid,feed_url,title,cat_id,site_url) |
441 | VALUES ('$id','".$_SESSION["uid"]."', | |
442 | '$feed_url', '$title', NULL, '$site_url')"); | |
443 | } | |
444 | } | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
d5112468 | 449 | function catchupFeed() { |
d9c85e0f AD |
450 | $feed_id = $this->dbh->escape_string($_REQUEST['feed_id']); |
451 | $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; | |
452 | $mode = $this->dbh->escape_string($_REQUEST['mode']); | |
d5112468 | 453 | |
a42c55f0 | 454 | catchup_feed($feed_id, $is_cat, false, false, $mode); |
d5112468 AD |
455 | |
456 | print json_encode(array("message" => "UPDATE_COUNTERS")); | |
457 | } | |
458 | ||
d5112468 | 459 | function quickAddCat() { |
d9c85e0f | 460 | $cat = $this->dbh->escape_string($_REQUEST["cat"]); |
d5112468 | 461 | |
a42c55f0 | 462 | add_feed_category($cat); |
d5112468 | 463 | |
d9c85e0f | 464 | $result = $this->dbh->query("SELECT id FROM ttrss_feed_categories WHERE |
d5112468 AD |
465 | title = '$cat' AND owner_uid = " . $_SESSION["uid"]); |
466 | ||
d9c85e0f AD |
467 | if ($this->dbh->num_rows($result) == 1) { |
468 | $id = $this->dbh->fetch_result($result, 0, "id"); | |
d5112468 AD |
469 | } else { |
470 | $id = 0; | |
471 | } | |
472 | ||
6f7798b6 | 473 | print_feed_cat_select("cat_id", $id, ''); |
d5112468 AD |
474 | } |
475 | ||
7d8f5657 AD |
476 | function setpanelmode() { |
477 | $wide = (int) $_REQUEST["wide"]; | |
478 | ||
f03701fe | 479 | setcookie("ttrss_widescreen", $wide, |
e57a1507 | 480 | time() + COOKIE_LIFETIME_LONG); |
7d8f5657 AD |
481 | |
482 | print json_encode(array("wide" => $wide)); | |
483 | } | |
484 | ||
113c3dec AD |
485 | static function updaterandomfeed_real($dbh) { |
486 | ||
8b83bf5f AD |
487 | // Test if the feed need a update (update interval exceded). |
488 | if (DB_TYPE == "pgsql") { | |
489 | $update_limit_qpart = "AND (( | |
490 | ttrss_feeds.update_interval = 0 | |
491 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) | |
492 | ) OR ( | |
493 | ttrss_feeds.update_interval > 0 | |
494 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) | |
495 | ) OR ttrss_feeds.last_updated IS NULL | |
496 | OR last_updated = '1970-01-01 00:00:00')"; | |
497 | } else { | |
498 | $update_limit_qpart = "AND (( | |
499 | ttrss_feeds.update_interval = 0 | |
500 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) | |
501 | ) OR ( | |
502 | ttrss_feeds.update_interval > 0 | |
503 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) | |
504 | ) OR ttrss_feeds.last_updated IS NULL | |
505 | OR last_updated = '1970-01-01 00:00:00')"; | |
506 | } | |
507 | ||
508 | // Test if feed is currently being updated by another process. | |
509 | if (DB_TYPE == "pgsql") { | |
510 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; | |
511 | } else { | |
512 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; | |
513 | } | |
514 | ||
515 | $random_qpart = sql_random_function(); | |
516 | ||
e1f1857d AD |
517 | // we could be invoked from public.php with no active session |
518 | if ($_SESSION["uid"]) { | |
519 | $owner_check_qpart = "AND ttrss_feeds.owner_uid = '".$_SESSION["uid"]."'"; | |
520 | } else { | |
521 | $owner_check_qpart = ""; | |
522 | } | |
523 | ||
8b83bf5f | 524 | // We search for feed needing update. |
113c3dec | 525 | $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id |
8b83bf5f AD |
526 | FROM |
527 | ttrss_feeds, ttrss_users, ttrss_user_prefs | |
528 | WHERE | |
529 | ttrss_feeds.owner_uid = ttrss_users.id | |
530 | AND ttrss_users.id = ttrss_user_prefs.owner_uid | |
531 | AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' | |
e1f1857d AD |
532 | $owner_check_qpart |
533 | $update_limit_qpart | |
534 | $updstart_thresh_qpart | |
8b83bf5f AD |
535 | ORDER BY $random_qpart LIMIT 30"); |
536 | ||
537 | $feed_id = -1; | |
538 | ||
539 | require_once "rssfuncs.php"; | |
540 | ||
541 | $num_updated = 0; | |
542 | ||
543 | $tstart = time(); | |
544 | ||
113c3dec | 545 | while ($line = $dbh->fetch_assoc($result)) { |
8b83bf5f AD |
546 | $feed_id = $line["id"]; |
547 | ||
6b1a4ecd | 548 | if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
a42c55f0 | 549 | update_rss_feed($feed_id, true); |
8b83bf5f AD |
550 | ++$num_updated; |
551 | } else { | |
552 | break; | |
553 | } | |
554 | } | |
555 | ||
cda55d67 | 556 | // Purge orphans and cleanup tags |
6322ac79 | 557 | purge_orphans(); |
9b736a20 | 558 | //cleanup_tags(14, 50000); |
cda55d67 | 559 | |
8b83bf5f AD |
560 | if ($num_updated > 0) { |
561 | print json_encode(array("message" => "UPDATE_COUNTERS", | |
562 | "num_updated" => $num_updated)); | |
563 | } else { | |
564 | print json_encode(array("message" => "NOTHING_TO_UPDATE")); | |
565 | } | |
566 | ||
567 | } | |
568 | ||
113c3dec AD |
569 | function updaterandomfeed() { |
570 | RPC::updaterandomfeed_real($this->dbh); | |
571 | } | |
572 | ||
a42c55f0 | 573 | private function markArticlesById($ids, $cmode) { |
87d7e850 AD |
574 | |
575 | $tmp_ids = array(); | |
576 | ||
577 | foreach ($ids as $id) { | |
578 | array_push($tmp_ids, "ref_id = '$id'"); | |
579 | } | |
580 | ||
581 | $ids_qpart = join(" OR ", $tmp_ids); | |
582 | ||
583 | if ($cmode == 0) { | |
d9c85e0f | 584 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 585 | marked = false, last_marked = NOW() |
87d7e850 AD |
586 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
587 | } else if ($cmode == 1) { | |
d9c85e0f | 588 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 589 | marked = true, last_marked = NOW() |
87d7e850 AD |
590 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
591 | } else { | |
d9c85e0f | 592 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 593 | marked = NOT marked,last_marked = NOW() |
87d7e850 AD |
594 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
595 | } | |
596 | } | |
597 | ||
a42c55f0 | 598 | private function publishArticlesById($ids, $cmode) { |
87d7e850 AD |
599 | |
600 | $tmp_ids = array(); | |
601 | ||
602 | foreach ($ids as $id) { | |
603 | array_push($tmp_ids, "ref_id = '$id'"); | |
604 | } | |
605 | ||
606 | $ids_qpart = join(" OR ", $tmp_ids); | |
607 | ||
608 | if ($cmode == 0) { | |
d9c85e0f | 609 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 610 | published = false,last_published = NOW() |
87d7e850 AD |
611 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
612 | } else if ($cmode == 1) { | |
d9c85e0f | 613 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 614 | published = true,last_published = NOW() |
87d7e850 AD |
615 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
616 | } else { | |
d9c85e0f | 617 | $this->dbh->query("UPDATE ttrss_user_entries SET |
7873d588 | 618 | published = NOT published,last_published = NOW() |
87d7e850 AD |
619 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); |
620 | } | |
621 | ||
622 | if (PUBSUBHUBBUB_HUB) { | |
623 | $rss_link = get_self_url_prefix() . | |
624 | "/public.php?op=rss&id=-2&key=" . | |
a42c55f0 | 625 | get_feed_access_key(-2, false); |
87d7e850 AD |
626 | |
627 | $p = new Publisher(PUBSUBHUBBUB_HUB); | |
628 | ||
4a80c57c | 629 | /* $pubsub_result = */ $p->publish_update($rss_link); |
87d7e850 AD |
630 | } |
631 | } | |
632 | ||
5defc29f | 633 | function getlinktitlebyid() { |
d9c85e0f | 634 | $id = $this->dbh->escape_string($_REQUEST['id']); |
7fc2e87e | 635 | |
d9c85e0f | 636 | $result = $this->dbh->query("SELECT link, title FROM ttrss_entries, ttrss_user_entries |
7fc2e87e AD |
637 | WHERE ref_id = '$id' AND ref_id = id AND owner_uid = ". $_SESSION["uid"]); |
638 | ||
d9c85e0f AD |
639 | if ($this->dbh->num_rows($result) != 0) { |
640 | $link = $this->dbh->fetch_result($result, 0, "link"); | |
641 | $title = $this->dbh->fetch_result($result, 0, "title"); | |
7fc2e87e | 642 | |
5defc29f | 643 | echo json_encode(array("link" => $link, "title" => $title)); |
7fc2e87e AD |
644 | } else { |
645 | echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); | |
646 | } | |
647 | } | |
648 | ||
f66492d3 AD |
649 | function log() { |
650 | $logmsg = $this->dbh->escape_string($_REQUEST['logmsg']); | |
651 | ||
652 | if ($logmsg) { | |
653 | Logger::get()->log_error(E_USER_WARNING, | |
654 | $logmsg, '[client-js]', 0, false); | |
655 | } | |
656 | ||
657 | echo json_encode(array("message" => "HOST_ERROR_LOGGED")); | |
658 | ||
659 | } | |
d5112468 AD |
660 | } |
661 | ?> |