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