]>
Commit | Line | Data |
---|---|---|
378a548c | 1 | <?php |
378a548c AD |
2 | error_reporting(E_ERROR | E_PARSE); |
3 | ||
4 | require_once "../config.php"; | |
5 | ||
6 | require_once "../db.php"; | |
7 | require_once "../db-prefs.php"; | |
8 | require_once "../functions.php"; | |
9 | ||
3acc0da6 AD |
10 | define('API_STATUS_OK', 0); |
11 | define('API_STATUS_ERR', 1); | |
12 | ||
70543b6a AD |
13 | if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT) { |
14 | ob_start("ob_gzhandler"); | |
15 | } | |
16 | ||
378a548c AD |
17 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
18 | ||
19 | $session_expire = SESSION_EXPIRE_TIME; //seconds | |
20 | $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api"; | |
21 | ||
3bb7e191 AD |
22 | session_name($session_name); |
23 | ||
24 | if ($_REQUEST["sid"]) { | |
25 | session_id($_REQUEST["sid"]); | |
26 | } | |
27 | ||
378a548c AD |
28 | session_start(); |
29 | ||
30 | if (!$link) { | |
31 | if (DB_TYPE == "mysql") { | |
32 | print mysql_error(); | |
33 | } | |
34 | // PG seems to display its own errors just fine by default. | |
35 | return; | |
36 | } | |
37 | ||
38 | init_connection($link); | |
39 | ||
40 | $op = db_escape_string($_REQUEST["op"]); | |
3acc0da6 | 41 | $seq = (int) $_REQUEST["seq"]; |
378a548c AD |
42 | |
43 | // header("Content-Type: application/json"); | |
44 | ||
3acc0da6 AD |
45 | function api_wrap_reply($status, $seq, $reply) { |
46 | print json_encode(array("seq" => $seq, | |
47 | "status" => $status, | |
48 | "content" => $reply)); | |
49 | } | |
50 | ||
378a548c | 51 | if (!$_SESSION["uid"] && $op != "login" && $op != "isLoggedIn") { |
3acc0da6 | 52 | print api_wrap_reply(API_STATUS_ERR, $seq, array("error" => 'NOT_LOGGED_IN')); |
378a548c AD |
53 | return; |
54 | } | |
55 | ||
3a216db4 | 56 | if ($_SESSION["uid"] && $op != "logout" && !get_pref($link, 'ENABLE_API_ACCESS')) { |
3acc0da6 | 57 | print api_wrap_reply(API_STATUS_ERR, $seq, array("error" => 'API_DISABLED')); |
378a548c | 58 | return; |
3a216db4 | 59 | } |
378a548c AD |
60 | |
61 | switch ($op) { | |
70543b6a | 62 | |
378a548c AD |
63 | case "getVersion": |
64 | $rv = array("version" => VERSION); | |
3acc0da6 | 65 | print api_wrap_reply(API_STATUS_OK, $seq, $rv); |
70543b6a AD |
66 | break; |
67 | ||
378a548c AD |
68 | case "login": |
69 | $login = db_escape_string($_REQUEST["user"]); | |
70 | $password = db_escape_string($_REQUEST["password"]); | |
70543b6a | 71 | $password_base64 = db_escape_string(base64_decode($_REQUEST["password"])); |
378a548c | 72 | |
2bebdd34 AD |
73 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); |
74 | ||
75 | if (db_num_rows($result) != 0) { | |
76 | $uid = db_fetch_result($result, 0, "id"); | |
77 | } else { | |
78 | $uid = 0; | |
79 | } | |
80 | ||
a7a99686 | 81 | if ($uid && get_pref($link, "ENABLE_API_ACCESS", $uid)) { |
70543b6a | 82 | if (authenticate_user($link, $login, $password)) { // try login with normal password |
3acc0da6 AD |
83 | print api_wrap_reply(API_STATUS_OK, $seq, |
84 | array("session_id" => session_id())); | |
70543b6a | 85 | } else if (authenticate_user($link, $login, $password_base64)) { // else try with base64_decoded password |
3acc0da6 AD |
86 | print api_wrap_reply(API_STATUS_OK, $seq, |
87 | array("session_id" => session_id())); | |
70543b6a | 88 | } else { // else we are not logged in |
3acc0da6 AD |
89 | print api_wrap_reply(API_STATUS_ERR, $seq, |
90 | array("error" => "LOGIN_ERROR")); | |
4cdd0d7c | 91 | } |
378a548c | 92 | } else { |
3acc0da6 AD |
93 | print api_wrap_reply(API_STATUS_ERR, $seq, |
94 | array("error" => "API_DISABLED")); | |
378a548c AD |
95 | } |
96 | ||
97 | break; | |
70543b6a | 98 | |
378a548c AD |
99 | case "logout": |
100 | logout_user(); | |
3acc0da6 | 101 | print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK")); |
378a548c | 102 | break; |
70543b6a | 103 | |
378a548c | 104 | case "isLoggedIn": |
3acc0da6 AD |
105 | print api_wrap_reply(API_STATUS_OK, $seq, |
106 | array("status" => $_SESSION["uid"] != '')); | |
378a548c | 107 | break; |
70543b6a | 108 | |
03e5f9eb AD |
109 | case "getUnread": |
110 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
111 | $is_cat = db_escape_string($_REQUEST["is_cat"]); | |
112 | ||
113 | if ($feed_id) { | |
3acc0da6 AD |
114 | print api_wrap_reply(API_STATUS_OK, $seq, |
115 | array("unread" => getFeedUnread($link, $feed_id, $is_cat))); | |
03e5f9eb | 116 | } else { |
3acc0da6 AD |
117 | print api_wrap_reply(API_STATUS_OK, $seq, |
118 | array("unread" => getGlobalUnread($link))); | |
03e5f9eb | 119 | } |
285f7597 | 120 | break; |
70543b6a AD |
121 | |
122 | /* Method added for ttrss-reader for Android */ | |
285f7597 | 123 | case "getCounters": |
70543b6a | 124 | |
9798b2b4 AD |
125 | /* flct (flc is the default) FIXME: document */ |
126 | $output_mode = db_escape_string($_REQUEST["output_mode"]); | |
70543b6a | 127 | |
3acc0da6 AD |
128 | print api_wrap_reply(API_STATUS_OK, $seq, |
129 | getAllCounters($link, $output_mode)); | |
03e5f9eb | 130 | break; |
70543b6a | 131 | |
378a548c AD |
132 | case "getFeeds": |
133 | $cat_id = db_escape_string($_REQUEST["cat_id"]); | |
134 | $unread_only = (bool)db_escape_string($_REQUEST["unread_only"]); | |
37882ef3 AD |
135 | $limit = (int) db_escape_string($_REQUEST["limit"]); |
136 | $offset = (int) db_escape_string($_REQUEST["offset"]); | |
137 | ||
911d4c08 | 138 | $feeds = api_get_feeds($link, $cat_id, $unread_only, $limit, $offset); |
53aff642 | 139 | |
3acc0da6 | 140 | print api_wrap_reply(API_STATUS_OK, $seq, $feeds); |
378a548c AD |
141 | |
142 | break; | |
70543b6a | 143 | |
378a548c | 144 | case "getCategories": |
730c97c7 AD |
145 | $unread_only = (bool)db_escape_string($_REQUEST["unread_only"]); |
146 | ||
378a548c AD |
147 | $result = db_query($link, "SELECT |
148 | id, title FROM ttrss_feed_categories | |
149 | WHERE owner_uid = " . | |
150 | $_SESSION["uid"]); | |
151 | ||
152 | $cats = array(); | |
153 | ||
154 | while ($line = db_fetch_assoc($result)) { | |
155 | $unread = getFeedUnread($link, $line["id"], true); | |
730c97c7 AD |
156 | |
157 | if ($unread || !$unread_only) { | |
f1c2b672 AD |
158 | array_push($cats, array("id" => $line["id"], |
159 | "title" => $line["title"], | |
160 | "unread" => $unread)); | |
730c97c7 | 161 | } |
378a548c AD |
162 | } |
163 | ||
3acc0da6 | 164 | print api_wrap_reply(API_STATUS_OK, $seq, $cats); |
378a548c | 165 | break; |
70543b6a | 166 | |
378a548c AD |
167 | case "getHeadlines": |
168 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
169 | $limit = (int)db_escape_string($_REQUEST["limit"]); | |
285f7597 | 170 | $offset = (int)db_escape_string($_REQUEST["skip"]); |
378a548c AD |
171 | $filter = db_escape_string($_REQUEST["filter"]); |
172 | $is_cat = (bool)db_escape_string($_REQUEST["is_cat"]); | |
d5e71621 AD |
173 | $show_excerpt = (bool)db_escape_string($_REQUEST["show_excerpt"]); |
174 | $show_content = (bool)db_escape_string($_REQUEST["show_content"]); | |
ef6c9ba4 AD |
175 | /* all_articles, unread, adaptive, marked, updated */ |
176 | $view_mode = db_escape_string($_REQUEST["view_mode"]); | |
378a548c | 177 | |
911d4c08 AD |
178 | $headlines = api_get_headlines($link, $feed_id, $limit, $offset, |
179 | $filter, $is_cat, $show_excerpt, $show_content, $view_mode, false); | |
378a548c | 180 | |
3acc0da6 | 181 | print api_wrap_reply(API_STATUS_OK, $seq, $headlines); |
378a548c | 182 | |
730c97c7 | 183 | break; |
70543b6a | 184 | |
1c3fffbb | 185 | case "updateArticle": |
ef6c9ba4 | 186 | $article_ids = split(",", db_escape_string($_REQUEST["article_ids"])); |
1c3fffbb AD |
187 | $mode = (int) db_escape_string($_REQUEST["mode"]); |
188 | $field_raw = (int)db_escape_string($_REQUEST["field"]); | |
189 | ||
190 | $field = ""; | |
191 | $set_to = ""; | |
192 | ||
193 | switch ($field_raw) { | |
194 | case 0: | |
195 | $field = "marked"; | |
196 | break; | |
197 | case 1: | |
198 | $field = "published"; | |
199 | break; | |
200 | case 2: | |
201 | $field = "unread"; | |
202 | break; | |
203 | }; | |
204 | ||
205 | switch ($mode) { | |
206 | case 1: | |
207 | $set_to = "true"; | |
208 | break; | |
209 | case 0: | |
210 | $set_to = "false"; | |
211 | break; | |
212 | case 2: | |
213 | $set_to = "NOT $field"; | |
214 | break; | |
215 | } | |
216 | ||
ef6c9ba4 AD |
217 | if ($field && $set_to && count($article_ids) > 0) { |
218 | ||
219 | $article_ids = join(", ", $article_ids); | |
220 | ||
1c3fffbb AD |
221 | if ($field == "unread") { |
222 | $result = db_query($link, "UPDATE ttrss_user_entries SET $field = $set_to, | |
223 | last_read = NOW() | |
ef6c9ba4 | 224 | WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]); |
1c3fffbb AD |
225 | } else { |
226 | $result = db_query($link, "UPDATE ttrss_user_entries SET $field = $set_to | |
ef6c9ba4 | 227 | WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]); |
1c3fffbb | 228 | } |
48317f5a | 229 | |
b4fdbcf4 AD |
230 | $num_updated = db_affected_rows($link, $result); |
231 | ||
232 | if ($num_updated > 0 && $field == "unread") { | |
233 | $result = db_query($link, "SELECT DISTINCT feed_id FROM ttrss_user_entries | |
234 | WHERE ref_id IN ($article_ids)"); | |
235 | ||
236 | while ($line = db_fetch_assoc($result)) { | |
237 | ccache_update($link, $line["feed_id"], $_SESSION["uid"]); | |
238 | } | |
239 | } | |
240 | ||
3acc0da6 | 241 | print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK", |
b4fdbcf4 AD |
242 | "updated" => $num_updated)); |
243 | ||
244 | } else { | |
3acc0da6 AD |
245 | print api_wrap_reply(API_STATUS_ERR, $seq, |
246 | array("error" => 'INCORRECT_USAGE')); | |
1c3fffbb AD |
247 | } |
248 | ||
249 | break; | |
250 | ||
730c97c7 AD |
251 | case "getArticle": |
252 | ||
f95ac275 | 253 | $article_id = db_escape_string($_REQUEST["article_id"]); |
730c97c7 | 254 | |
f95ac275 | 255 | $query = "SELECT id,title,link,content,feed_id,comments,int_id, |
1c3fffbb | 256 | marked,unread,published, |
730c97c7 AD |
257 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
258 | author | |
259 | FROM ttrss_entries,ttrss_user_entries | |
f95ac275 | 260 | WHERE id IN ($article_id) AND ref_id = id AND owner_uid = " . |
730c97c7 AD |
261 | $_SESSION["uid"] ; |
262 | ||
263 | $result = db_query($link, $query); | |
3acc0da6 AD |
264 | |
265 | $articles = array(); | |
266 | ||
730c97c7 | 267 | if (db_num_rows($result) != 0) { |
730c97c7 | 268 | |
f95ac275 AD |
269 | while ($line = db_fetch_assoc($result)) { |
270 | ||
271 | $attachments = get_article_enclosures($link, $line['id']); | |
272 | ||
273 | $article = array( | |
274 | "id" => $line["id"], | |
275 | "title" => $line["title"], | |
276 | "link" => $line["link"], | |
277 | "labels" => get_article_labels($link, $line['id']), | |
278 | "unread" => sql_bool_to_bool($line["unread"]), | |
279 | "marked" => sql_bool_to_bool($line["marked"]), | |
280 | "published" => sql_bool_to_bool($line["published"]), | |
281 | "comments" => $line["comments"], | |
282 | "author" => $line["author"], | |
283 | "updated" => strtotime($line["updated"]), | |
284 | "content" => $line["content"], | |
285 | "feed_id" => $line["feed_id"], | |
286 | "attachments" => $attachments | |
287 | ); | |
288 | ||
3acc0da6 AD |
289 | array_push($articles, $article); |
290 | ||
f95ac275 AD |
291 | } |
292 | } | |
730c97c7 | 293 | |
3acc0da6 AD |
294 | print api_wrap_reply(API_STATUS_OK, $seq, $articles); |
295 | ||
7c6d05cd | 296 | break; |
70543b6a | 297 | |
7c6d05cd AD |
298 | case "getConfig": |
299 | $config = array( | |
300 | "icons_dir" => ICONS_DIR, | |
301 | "icons_url" => ICONS_URL); | |
302 | ||
303 | if (ENABLE_UPDATE_DAEMON) { | |
304 | $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); | |
305 | } | |
306 | ||
307 | $result = db_query($link, "SELECT COUNT(*) AS cf FROM | |
308 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
309 | ||
310 | $num_feeds = db_fetch_result($result, 0, "cf"); | |
311 | ||
312 | $config["num_feeds"] = (int)$num_feeds; | |
313 | ||
3acc0da6 | 314 | print api_wrap_reply(API_STATUS_OK, $seq, $config); |
7c6d05cd | 315 | |
4d557a13 | 316 | break; |
7c6d05cd | 317 | |
cc374435 AD |
318 | case "updateFeed": |
319 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
320 | ||
c633e370 | 321 | update_rss_feed($link, $feed_id, true); |
cc374435 | 322 | |
3acc0da6 | 323 | print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK")); |
c45ffc0c | 324 | |
cc374435 AD |
325 | break; |
326 | ||
ca75c2e2 AD |
327 | case "catchupFeed": |
328 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
ee273da6 | 329 | $is_cat = db_escape_string($_REQUEST["is_cat"]); |
ca75c2e2 | 330 | |
423e6e55 | 331 | catchup_feed($link, $feed_id, $is_cat); |
ca75c2e2 | 332 | |
3acc0da6 | 333 | print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK")); |
ca75c2e2 AD |
334 | |
335 | break; | |
336 | ||
4d557a13 AD |
337 | case "getPref": |
338 | $pref_name = db_escape_string($_REQUEST["pref_name"]); | |
3acc0da6 AD |
339 | |
340 | print api_wrap_reply(API_STATUS_OK, $seq, | |
341 | array("value" => get_pref($link, $pref_name))); | |
378a548c | 342 | break; |
70543b6a AD |
343 | |
344 | /* Method added for ttrss-reader for Android */ | |
345 | case "getArticles": | |
ee273da6 | 346 | $isCategory = (int)db_escape_string($_REQUEST["is_cat"]); |
70543b6a AD |
347 | $id = (int)db_escape_string($_REQUEST["id"]); |
348 | $displayUnread = (int)db_escape_string($_REQUEST["unread"]); | |
349 | $limit = (int)db_escape_string($_REQUEST["limit"]); | |
350 | $feeds = array(); | |
351 | ||
352 | if ($isCategory > 0) { | |
353 | // Get Feeds of the category | |
354 | ||
355 | if ($id == 0) { | |
356 | $category_part = "cat_id is NULL"; | |
357 | } else { | |
358 | $category_part = "cat_id = '$id'"; | |
359 | } | |
360 | ||
361 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE ". | |
362 | $category_part." AND owner_uid = '".$_SESSION["uid"]."'"); | |
363 | ||
364 | while ($line = db_fetch_assoc($result)) { | |
365 | array_push($feeds, $line["id"]); | |
366 | } | |
367 | ||
368 | // Virtual feeds | |
369 | $match_part = ""; | |
370 | if ($id == -1) { | |
371 | $match_part = "marked = true"; | |
372 | array_push($feeds, -1); | |
373 | } else if ($id == -2) { | |
374 | $match_part = "published = true"; | |
375 | array_push($feeds, -2); | |
376 | } else if ($id == -3) { | |
377 | $match_part = "unread = true"; | |
378 | array_push($feeds, -3); | |
379 | ||
380 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); | |
381 | ||
382 | if (DB_TYPE == "pgsql") { | |
383 | $match_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; | |
384 | } else { | |
385 | $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; | |
386 | } | |
387 | } else if ($id == -4) { | |
388 | $match_part = "true"; | |
389 | array_push($feeds, -4); | |
390 | } | |
391 | } else { | |
392 | // Only add one feed | |
393 | array_push($feeds, $id); | |
394 | } | |
395 | ||
396 | $ret = array(); | |
397 | ||
398 | if (DB_TYPE == "mysql") { | |
399 | $limit_part = " LIMIT 0,".$limit; | |
400 | } else if (DB_TYPE == "pgsql") { | |
401 | $limit_part = " LIMIT ".$limit; | |
402 | } else { | |
403 | $limit_part = ""; | |
404 | } | |
405 | ||
406 | // Fetch articles for the feeds | |
407 | foreach ($feeds as $feed) { | |
408 | ||
409 | if ($match_part) { | |
410 | $from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries"; | |
411 | $feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; | |
412 | ||
413 | $query = "SELECT ttrss_entries.id,ttrss_entries.title,link,content,feed_id,comments,int_id, | |
414 | marked,unread,published,".SUBSTRING_FOR_DATE."(updated,1,16) as updated,author | |
415 | FROM $from_qpart WHERE | |
416 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
417 | $feeds_qpart ($match_part) AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]." ORDER BY updated DESC".$limit_part; | |
418 | ||
419 | $result = db_query($link, $query); | |
420 | } else { | |
421 | $query = "SELECT ttrss_entries.id,ttrss_entries.title,link,content,feed_id,comments,int_id, | |
422 | marked,unread,published,".SUBSTRING_FOR_DATE."(updated,1,16) as updated,author | |
423 | FROM ttrss_entries,ttrss_user_entries | |
424 | WHERE feed_id = '".$feed."' AND ref_id = id AND owner_uid = ". | |
425 | $_SESSION["uid"]." AND unread >= '".$displayUnread."' ORDER BY updated DESC".$limit_part; | |
426 | ||
427 | $result = db_query($link, $query); | |
428 | } | |
429 | ||
430 | $articles = array(); | |
431 | $i=0; | |
432 | while ($i < mysql_numrows($result)) { | |
433 | ||
434 | $article_id = db_fetch_result($result, $i, "id"); | |
435 | ||
436 | $attachments = get_article_enclosures($link, $article_id); | |
437 | ||
438 | $article = array( | |
439 | "id" => db_fetch_result($result, $i, "ttrss_entries.id"), | |
440 | "title" => db_fetch_result($result, $i, "ttrss_entries.title"), | |
441 | "link" => db_fetch_result($result, $i, "link"), | |
442 | "labels" => get_article_labels($link, $article_id), | |
443 | "unread" => sql_bool_to_bool(db_fetch_result($result, $i, "unread")), | |
444 | "marked" => sql_bool_to_bool(db_fetch_result($result, $i, "marked")), | |
445 | "published" => sql_bool_to_bool(db_fetch_result($result, $i, "published")), | |
446 | "comments" => db_fetch_result($result, $i, "comments"), | |
447 | "author" => db_fetch_result($result, $i, "author"), | |
448 | "updated" => strtotime(db_fetch_result($result, $i, "updated")), | |
449 | "content" => db_fetch_result($result, $i, "content"), | |
450 | "feed_id" => db_fetch_result($result, $i, "feed_id"), | |
451 | "attachments" => $attachments | |
452 | ); | |
453 | ||
454 | array_push($ret, $article); | |
455 | ||
456 | $i++; | |
457 | } | |
458 | } | |
459 | ||
3acc0da6 | 460 | print api_wrap_reply(API_STATUS_OK, $seq, $ret); |
70543b6a AD |
461 | break; |
462 | ||
463 | /* Method added for ttrss-reader for Android */ | |
464 | case "getNewArticles": | |
465 | $time = (int) db_escape_string($_REQUEST["time"]); | |
466 | // unread=1 zeigt alle an, unread=0 nur ungelesene | |
467 | $displayUnread = (int) db_escape_string($_REQUEST["unread"]); | |
468 | ||
469 | if (DB_TYPE == "mysql") { | |
470 | $db_time_function = " AND last_updated > FROM_UNIXTIME(".$time.")"; | |
471 | } else if (DB_TYPE == "pgsql") { | |
472 | $db_time_function = " AND last_updated > to_timestamp(".$time.")"; | |
473 | } else { | |
474 | $db_time_function = ""; | |
475 | } | |
476 | ||
477 | if (DB_TYPE == "mysql") { | |
478 | $db_time_function2 = " AND updated > FROM_UNIXTIME(".$time.")"; | |
479 | } else if (DB_TYPE == "pgsql") { | |
480 | $db_time_function2 = " AND updated > to_timestamp(".$time.")"; | |
481 | } else { | |
482 | $db_time_function2 = ""; | |
483 | } | |
484 | ||
485 | $cats = array(); | |
486 | ||
487 | ||
488 | // Add uncategorized feeds | |
489 | $unread = getFeedUnread($link, 0, true); | |
490 | if ($unread || $displayUnread > 0) { | |
491 | $feeds = array(); | |
492 | $result_0 = db_query($link, "SELECT id, feed_url, cat_id, title, ". | |
493 | SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated ". | |
494 | "FROM ttrss_feeds WHERE cat_id IS null AND owner_uid = '".$_SESSION["uid"]."'" . $db_time_function); | |
495 | ||
496 | while ($line_feeds = db_fetch_assoc($result_0)) { | |
497 | $unread_feed = getFeedUnread($link, $line_feeds["id"], false); | |
498 | if ($unread || $displayUnread > 0) { | |
499 | ||
500 | $result_1 = db_query($link, "SELECT id,title,link,content,feed_id,comments,int_id, | |
501 | marked,unread,published,". | |
502 | SUBSTRING_FOR_DATE."(updated,1,16) as updated,author | |
503 | FROM ttrss_entries,ttrss_user_entries | |
504 | WHERE feed_id = '".$line_feeds["id"]."' AND ref_id = id AND owner_uid = " . | |
505 | $_SESSION["uid"]." AND unread >= '".$displayUnread."'" . $db_time_function2); | |
506 | ||
507 | $articles = array(); | |
508 | while ($line_articles = db_fetch_assoc($result_1)) { | |
509 | $article_id = db_fetch_result($result, $i, "id"); | |
510 | $attachments = get_article_enclosures($link, $article_id); | |
511 | array_push($articles, $article = array( | |
512 | "id" => $line_articles["id"], | |
513 | "title" => $line_articles["title"], | |
514 | "link" => $line_articles["link"], | |
515 | "labels" => $article_id, | |
516 | "unread" => $line_articles["unread"], | |
517 | "marked" => $line_articles["marked"], | |
518 | "published" => $line_articles["published"], | |
519 | "comments" => $line_articles["comments"], | |
520 | "author" => $line_articles["author"], | |
521 | "updated" => strtotime($line_articles["updated"]), | |
522 | "content" => $line_articles["content"], | |
523 | "feed_id" => $line_articles["feed_id"], | |
524 | "attachments" => $attachments)); | |
525 | } | |
526 | ||
527 | array_push($feeds, array( | |
528 | "feed_url" => $line_feeds["feed_url"], | |
529 | "title" => $line_feeds["title"], | |
530 | "id" => (int)$line_feeds["id"], | |
531 | "unread" => (int)$unread_feed, | |
532 | "has_icon" => $has_icon, | |
533 | "cat_id" => (int)$line_feeds["cat_id"], | |
534 | "last_updated" => strtotime($line_feeds["last_updated"]), | |
535 | "articles" => $articles | |
536 | )); | |
537 | } | |
538 | } | |
539 | ||
540 | array_push($cats, | |
541 | array( | |
542 | "id" => 0, | |
543 | "title" => "Uncategorized Feeds", | |
544 | "unread" => $unread, | |
545 | "feeds" => $feeds)); | |
546 | } | |
b792cd70 | 547 | |
70543b6a AD |
548 | |
549 | $result = db_query($link, "SELECT id, title FROM ttrss_feed_categories WHERE owner_uid = " . $_SESSION["uid"]); | |
550 | while ($line = db_fetch_assoc($result)) { | |
551 | $unread = getFeedUnread($link, $line["id"], true); | |
552 | ||
553 | if ($unread || $displayUnread > 0) { | |
554 | $feeds = array(); | |
555 | $result_0 = db_query($link, "SELECT id, feed_url, cat_id, title, ". | |
556 | SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated ". | |
557 | "FROM ttrss_feeds WHERE cat_id = '". | |
558 | $line["id"]."' AND owner_uid = '".$_SESSION["uid"]."'" . $db_time_function); | |
559 | ||
560 | while ($line_feeds = db_fetch_assoc($result_0)) { | |
561 | $unread_feed = getFeedUnread($link, $line_feeds["id"], false); | |
562 | if ($unread_feed || $displayUnread > 0) { | |
563 | ||
564 | $result_1 = db_query($link, "SELECT id,title,link,content,feed_id,comments,int_id, | |
565 | marked,unread,published,". | |
566 | SUBSTRING_FOR_DATE."(updated,1,16) as updated,author | |
567 | FROM ttrss_entries,ttrss_user_entries | |
568 | WHERE feed_id = '".$line_feeds["id"]."' AND ref_id = id AND owner_uid = " . | |
569 | $_SESSION["uid"]." AND unread >= '".$displayUnread."'" . $db_time_function2); | |
570 | ||
571 | $articles = array(); | |
572 | while ($line_articles = db_fetch_assoc($result_1)) { | |
573 | $article_id = db_fetch_result($result, $i, "id"); | |
574 | $attachments = get_article_enclosures($link, $article_id); | |
575 | array_push($articles, $article = array( | |
576 | "id" => $line_articles["id"], | |
577 | "title" => $line_articles["title"], | |
578 | "link" => $line_articles["link"], | |
579 | "labels" => $article_id, | |
580 | "unread" => $line_articles["unread"], | |
581 | "marked" => $line_articles["marked"], | |
582 | "published" => $line_articles["published"], | |
583 | "comments" => $line_articles["comments"], | |
584 | "author" => $line_articles["author"], | |
585 | "updated" => strtotime($line_articles["updated"]), | |
586 | "content" => $line_articles["content"], | |
587 | "feed_id" => $line_articles["feed_id"], | |
588 | "attachments" => $attachments)); | |
589 | } | |
590 | ||
591 | array_push($feeds, array( | |
592 | "feed_url" => $line_feeds["feed_url"], | |
593 | "title" => $line_feeds["title"], | |
594 | "id" => (int)$line_feeds["id"], | |
595 | "unread" => (int)$unread_feed, | |
596 | "cat_id" => (int)$line_feeds["cat_id"], | |
597 | "last_updated" => strtotime($line_feeds["last_updated"]), | |
598 | "articles" => $articles | |
599 | )); | |
600 | ||
601 | } | |
602 | } | |
603 | ||
604 | array_push($cats, | |
605 | array( | |
606 | "id" => $line["id"], | |
607 | "title" => $line["title"], | |
608 | "unread" => $unread, | |
609 | "feeds" => $feeds)); | |
610 | } | |
611 | } | |
3acc0da6 | 612 | print api_wrap_reply(API_STATUS_OK, $seq, $cats); |
70543b6a AD |
613 | break; |
614 | ||
b792cd70 | 615 | default: |
3acc0da6 AD |
616 | print api_wrap_reply(API_STATUS_ERR, $seq, |
617 | array("error" => 'UNKNOWN_METHOD')); | |
b792cd70 AD |
618 | break; |
619 | ||
378a548c AD |
620 | } |
621 | ||
622 | db_close($link); | |
623 | ||
624 | ?> |