]> git.wh0rd.org - tt-rss.git/blame - classes/api.php
login: add session_destroy() first
[tt-rss.git] / classes / api.php
CommitLineData
de8260cb
AD
1<?php
2
3class API extends Handler {
4
efc6553d 5 const API_LEVEL = 5;
de8260cb
AD
6
7 const STATUS_OK = 0;
8 const STATUS_ERR = 1;
9
10 private $seq;
11
12 function before($method) {
13 if (parent::before($method)) {
12f31782 14 header("Content-Type: text/json");
de8260cb
AD
15
16 if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
17 print $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN'));
18 return false;
19 }
20
21 if ($_SESSION["uid"] && $method != "logout" && !get_pref($this->link, 'ENABLE_API_ACCESS')) {
22 print $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED'));
23 return false;
24 }
25
26 $this->seq = (int) $_REQUEST['seq'];
27
de8260cb
AD
28 return true;
29 }
30 return false;
31 }
32
33 function wrap($status, $reply) {
34 print json_encode(array("seq" => $this->seq,
35 "status" => $status,
36 "content" => $reply));
37 }
38
39 function getVersion() {
40 $rv = array("version" => VERSION);
41 print $this->wrap(self::STATUS_OK, $rv);
42 }
43
44 function getApiLevel() {
a3b5394a 45 $rv = array("level" => self::API_LEVEL);
de8260cb
AD
46 print $this->wrap(self::STATUS_OK, $rv);
47 }
48
49 function login() {
5160620c
AD
50 @session_start();
51
3972bf59 52 $login = db_escape_string($this->link, $_REQUEST["user"]);
de8260cb
AD
53 $password = $_REQUEST["password"];
54 $password_base64 = base64_decode($_REQUEST["password"]);
55
56 if (SINGLE_USER_MODE) $login = "admin";
57
58 $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'");
59
60 if (db_num_rows($result) != 0) {
61 $uid = db_fetch_result($result, 0, "id");
62 } else {
63 $uid = 0;
64 }
65
66 if (!$uid) {
67 print $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
68 return;
69 }
70
71 if (get_pref($this->link, "ENABLE_API_ACCESS", $uid)) {
72 if (authenticate_user($this->link, $login, $password)) { // try login with normal password
5ba4ebc6
AD
73 print $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
74 "api_level" => self::API_LEVEL));
de8260cb 75 } else if (authenticate_user($this->link, $login, $password_base64)) { // else try with base64_decoded password
5ba4ebc6
AD
76 print $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
77 "api_level" => self::API_LEVEL));
de8260cb
AD
78 } else { // else we are not logged in
79 print $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
80 }
81 } else {
82 print $this->wrap(self::STATUS_ERR, array("error" => "API_DISABLED"));
83 }
84
85 }
86
87 function logout() {
88 logout_user();
89 print $this->wrap(self::STATUS_OK, array("status" => "OK"));
90 }
91
92 function isLoggedIn() {
93 print $this->wrap(self::STATUS_OK, array("status" => $_SESSION["uid"] != ''));
94 }
95
96 function getUnread() {
3972bf59
AD
97 $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
98 $is_cat = db_escape_string($this->link, $_REQUEST["is_cat"]);
de8260cb
AD
99
100 if ($feed_id) {
101 print $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($this->link, $feed_id, $is_cat)));
102 } else {
103 print $this->wrap(self::STATUS_OK, array("unread" => getGlobalUnread($this->link)));
104 }
105 }
106
107 /* Method added for ttrss-reader for Android */
108 function getCounters() {
5b55e9e2 109 print $this->wrap(self::STATUS_OK, getAllCounters($this->link));
de8260cb
AD
110 }
111
112 function getFeeds() {
3972bf59 113 $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
9955a134 114 $unread_only = sql_bool_to_bool($_REQUEST["unread_only"]);
3972bf59
AD
115 $limit = (int) db_escape_string($this->link, $_REQUEST["limit"]);
116 $offset = (int) db_escape_string($this->link, $_REQUEST["offset"]);
9955a134 117 $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]);
de8260cb 118
04f60eb7 119 $feeds = $this->api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset, $include_nested);
de8260cb
AD
120
121 print $this->wrap(self::STATUS_OK, $feeds);
122 }
123
124 function getCategories() {
9955a134
AD
125 $unread_only = sql_bool_to_bool($_REQUEST["unread_only"]);
126 $enable_nested = sql_bool_to_bool($_REQUEST["enable_nested"]);
de8260cb
AD
127
128 // TODO do not return empty categories, return Uncategorized and standard virtual cats
129
48646336
AD
130 if ($enable_nested)
131 $nested_qpart = "parent_cat IS NULL";
132 else
133 $nested_qpart = "true";
134
de8260cb 135 $result = db_query($this->link, "SELECT
d49dfa38
AD
136 id, title, order_id, (SELECT COUNT(id) FROM
137 ttrss_feeds WHERE
7be3fcd5
AD
138 ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds,
139 (SELECT COUNT(id) FROM
140 ttrss_feed_categories AS c2 WHERE
141 c2.parent_cat = ttrss_feed_categories.id) AS num_cats
d49dfa38 142 FROM ttrss_feed_categories
48646336 143 WHERE $nested_qpart AND owner_uid = " .
de8260cb
AD
144 $_SESSION["uid"]);
145
146 $cats = array();
147
148 while ($line = db_fetch_assoc($result)) {
7be3fcd5 149 if ($line["num_feeds"] > 0 || $line["num_cats"] > 0) {
d49dfa38
AD
150 $unread = getFeedUnread($this->link, $line["id"], true);
151
152 if ($enable_nested)
153 $unread += getCategoryChildrenUnread($this->link, $line["id"]);
154
155 if ($unread || !$unread_only) {
156 array_push($cats, array("id" => $line["id"],
157 "title" => $line["title"],
158 "unread" => $unread,
159 "order_id" => (int) $line["order_id"],
160 ));
161 }
de8260cb
AD
162 }
163 }
164
165 foreach (array(-2,-1,0) as $cat_id) {
166 $unread = getFeedUnread($this->link, $cat_id, true);
167
168 if ($unread || !$unread_only) {
169 array_push($cats, array("id" => $cat_id,
170 "title" => getCategoryTitle($this->link, $cat_id),
171 "unread" => $unread));
172 }
173 }
174
175 print $this->wrap(self::STATUS_OK, $cats);
176 }
177
178 function getHeadlines() {
3972bf59 179 $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
8aa3becc 180 if ($feed_id != "") {
de8260cb 181
3972bf59 182 $limit = (int)db_escape_string($this->link, $_REQUEST["limit"]);
1a740cf6
AD
183
184 if (!$limit || $limit >= 60) $limit = 60;
185
3972bf59
AD
186 $offset = (int)db_escape_string($this->link, $_REQUEST["skip"]);
187 $filter = db_escape_string($this->link, $_REQUEST["filter"]);
9955a134
AD
188 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
189 $show_excerpt = sql_bool_to_bool($_REQUEST["show_excerpt"]);
190 $show_content = sql_bool_to_bool($_REQUEST["show_content"]);
de8260cb 191 /* all_articles, unread, adaptive, marked, updated */
3972bf59 192 $view_mode = db_escape_string($this->link, $_REQUEST["view_mode"]);
9955a134 193 $include_attachments = sql_bool_to_bool($_REQUEST["include_attachments"]);
3972bf59 194 $since_id = (int)db_escape_string($this->link, $_REQUEST["since_id"]);
9955a134 195 $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]);
db9e00e3 196 $sanitize_content = true;
de8260cb 197
3e4af5b0
AD
198 /* do not rely on params below */
199
3972bf59
AD
200 $search = db_escape_string($this->link, $_REQUEST["search"]);
201 $search_mode = db_escape_string($this->link, $_REQUEST["search_mode"]);
3e4af5b0 202
04f60eb7 203 $headlines = $this->api_get_headlines($this->link, $feed_id, $limit, $offset,
de8260cb 204 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, false,
ca5d9be4 205 $include_attachments, $since_id, $search, $search_mode,
db9e00e3 206 $include_nested, $sanitize_content);
de8260cb
AD
207
208 print $this->wrap(self::STATUS_OK, $headlines);
209 } else {
210 print $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
211 }
212 }
213
214 function updateArticle() {
3972bf59
AD
215 $article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric);
216 $mode = (int) db_escape_string($this->link, $_REQUEST["mode"]);
217 $data = db_escape_string($this->link, $_REQUEST["data"]);
218 $field_raw = (int)db_escape_string($this->link, $_REQUEST["field"]);
de8260cb
AD
219
220 $field = "";
221 $set_to = "";
222
223 switch ($field_raw) {
224 case 0:
225 $field = "marked";
7873d588 226 $additional_fields = ",last_marked = NOW()";
de8260cb
AD
227 break;
228 case 1:
229 $field = "published";
7873d588 230 $additional_fields = ",last_published = NOW()";
de8260cb
AD
231 break;
232 case 2:
233 $field = "unread";
7873d588 234 $additional_fields = ",last_read = NOW()";
de8260cb
AD
235 break;
236 case 3:
237 $field = "note";
238 };
239
240 switch ($mode) {
241 case 1:
242 $set_to = "true";
243 break;
244 case 0:
245 $set_to = "false";
246 break;
247 case 2:
248 $set_to = "NOT $field";
249 break;
250 }
251
252 if ($field == "note") $set_to = "'$data'";
253
254 if ($field && $set_to && count($article_ids) > 0) {
255
256 $article_ids = join(", ", $article_ids);
257
7873d588 258 $result = db_query($this->link, "UPDATE ttrss_user_entries SET $field = $set_to $additional_fields WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]);
de8260cb
AD
259
260 $num_updated = db_affected_rows($this->link, $result);
261
262 if ($num_updated > 0 && $field == "unread") {
263 $result = db_query($this->link, "SELECT DISTINCT feed_id FROM ttrss_user_entries
264 WHERE ref_id IN ($article_ids)");
265
266 while ($line = db_fetch_assoc($result)) {
267 ccache_update($this->link, $line["feed_id"], $_SESSION["uid"]);
268 }
269 }
270
7873d588
AD
271 if ($num_updated > 0 && $field == "published") {
272 if (PUBSUBHUBBUB_HUB) {
273 $rss_link = get_self_url_prefix() .
274 "/public.php?op=rss&id=-2&key=" .
275 get_feed_access_key($this->link, -2, false);
276
277 $p = new Publisher(PUBSUBHUBBUB_HUB);
278 $pubsub_result = $p->publish_update($rss_link);
279 }
280 }
281
de8260cb
AD
282 print $this->wrap(self::STATUS_OK, array("status" => "OK",
283 "updated" => $num_updated));
284
285 } else {
286 print $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
287 }
288
289 }
290
291 function getArticle() {
292
3972bf59 293 $article_id = join(",", array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_id"])), is_numeric));
de8260cb 294
87764a50 295 $query = "SELECT id,title,link,content,cached_content,feed_id,comments,int_id,
de8260cb
AD
296 marked,unread,published,
297 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
298 author
299 FROM ttrss_entries,ttrss_user_entries
300 WHERE id IN ($article_id) AND ref_id = id AND owner_uid = " .
301 $_SESSION["uid"] ;
302
303 $result = db_query($this->link, $query);
304
305 $articles = array();
306
307 if (db_num_rows($result) != 0) {
308
309 while ($line = db_fetch_assoc($result)) {
310
311 $attachments = get_article_enclosures($this->link, $line['id']);
312
313 $article = array(
314 "id" => $line["id"],
315 "title" => $line["title"],
316 "link" => $line["link"],
317 "labels" => get_article_labels($this->link, $line['id']),
318 "unread" => sql_bool_to_bool($line["unread"]),
319 "marked" => sql_bool_to_bool($line["marked"]),
320 "published" => sql_bool_to_bool($line["published"]),
321 "comments" => $line["comments"],
322 "author" => $line["author"],
ef3da31c 323 "updated" => (int) strtotime($line["updated"]),
87764a50 324 "content" => $line["cached_content"] != "" ? $line["cached_content"] : $line["content"],
de8260cb
AD
325 "feed_id" => $line["feed_id"],
326 "attachments" => $attachments
327 );
328
329 array_push($articles, $article);
330
331 }
332 }
333
334 print $this->wrap(self::STATUS_OK, $articles);
335
336 }
337
338 function getConfig() {
339 $config = array(
340 "icons_dir" => ICONS_DIR,
341 "icons_url" => ICONS_URL);
342
343 $config["daemon_is_running"] = file_is_locked("update_daemon.lock");
344
345 $result = db_query($this->link, "SELECT COUNT(*) AS cf FROM
346 ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
347
348 $num_feeds = db_fetch_result($result, 0, "cf");
349
350 $config["num_feeds"] = (int)$num_feeds;
351
352 print $this->wrap(self::STATUS_OK, $config);
353 }
354
355 function updateFeed() {
c1f6e5f8
AD
356 require_once "include/rssfuncs.php";
357
358 $feed_id = (int) db_escape_string($this->link, $_REQUEST["feed_id"]);
de8260cb
AD
359
360 update_rss_feed($this->link, $feed_id, true);
361
362 print $this->wrap(self::STATUS_OK, array("status" => "OK"));
363 }
364
365 function catchupFeed() {
3972bf59
AD
366 $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
367 $is_cat = db_escape_string($this->link, $_REQUEST["is_cat"]);
de8260cb
AD
368
369 catchup_feed($this->link, $feed_id, $is_cat);
370
371 print $this->wrap(self::STATUS_OK, array("status" => "OK"));
372 }
373
374 function getPref() {
3972bf59 375 $pref_name = db_escape_string($this->link, $_REQUEST["pref_name"]);
de8260cb
AD
376
377 print $this->wrap(self::STATUS_OK, array("value" => get_pref($this->link, $pref_name)));
378 }
379
ea1c2903 380 function getLabels() {
3972bf59 381 //$article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric);
ea1c2903
AD
382
383 $article_id = (int)$_REQUEST['article_id'];
384
385 $rv = array();
386
387 $result = db_query($this->link, "SELECT id, caption, fg_color, bg_color
388 FROM ttrss_labels2
389 WHERE owner_uid = '".$_SESSION['uid']."' ORDER BY caption");
390
391 if ($article_id)
392 $article_labels = get_article_labels($this->link, $article_id);
393 else
394 $article_labels = array();
395
396 while ($line = db_fetch_assoc($result)) {
397
398 $checked = false;
399 foreach ($article_labels as $al) {
400 if ($al[0] == $line['id']) {
401 $checked = true;
402 break;
403 }
404 }
405
406 array_push($rv, array(
407 "id" => (int)$line['id'],
408 "caption" => $line['caption'],
409 "fg_color" => $line['fg_color'],
410 "bg_color" => $line['bg_color'],
411 "checked" => $checked));
412 }
413
414 print $this->wrap(self::STATUS_OK, $rv);
415 }
416
396bfdf9
AD
417 function setArticleLabel() {
418
3972bf59
AD
419 $article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric);
420 $label_id = (int) db_escape_string($this->link, $_REQUEST['label_id']);
421 $assign = (bool) db_escape_string($this->link, $_REQUEST['assign']) == "true";
396bfdf9 422
3972bf59 423 $label = db_escape_string($this->link, label_find_caption($this->link,
396bfdf9
AD
424 $label_id, $_SESSION["uid"]));
425
426 $num_updated = 0;
427
428 if ($label) {
429
430 foreach ($article_ids as $id) {
431
432 if ($assign)
433 label_add_article($this->link, $id, $label, $_SESSION["uid"]);
434 else
435 label_remove_article($this->link, $id, $label, $_SESSION["uid"]);
436
437 ++$num_updated;
438
439 }
440 }
441
442 print $this->wrap(self::STATUS_OK, array("status" => "OK",
443 "updated" => $num_updated));
444
445 }
446
de8260cb
AD
447 function index() {
448 print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD'));
449 }
450
8361e724 451 function shareToPublished() {
3972bf59
AD
452 $title = db_escape_string($this->link, strip_tags($_REQUEST["title"]));
453 $url = db_escape_string($this->link, strip_tags($_REQUEST["url"]));
454 $content = db_escape_string($this->link, strip_tags($_REQUEST["content"]));
8361e724 455
50832719 456 if (Article::create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) {
8361e724
AD
457 print $this->wrap(self::STATUS_OK, array("status" => 'OK'));
458 } else {
459 print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));
460 }
461 }
04f60eb7
AD
462
463 static function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) {
464
465 $feeds = array();
466
467 /* Labels */
468
469 if ($cat_id == -4 || $cat_id == -2) {
470 $counters = getLabelCounters($link, true);
471
472 foreach (array_values($counters) as $cv) {
473
474 $unread = $cv["counter"];
475
476 if ($unread || !$unread_only) {
477
478 $row = array(
479 "id" => $cv["id"],
480 "title" => $cv["description"],
481 "unread" => $cv["counter"],
482 "cat_id" => -2,
483 );
484
485 array_push($feeds, $row);
486 }
487 }
488 }
489
490 /* Virtual feeds */
491
492 if ($cat_id == -4 || $cat_id == -1) {
493 foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
494 $unread = getFeedUnread($link, $i);
495
496 if ($unread || !$unread_only) {
497 $title = getFeedTitle($link, $i);
498
499 $row = array(
500 "id" => $i,
501 "title" => $title,
502 "unread" => $unread,
503 "cat_id" => -1,
504 );
505 array_push($feeds, $row);
506 }
507
508 }
509 }
510
511 /* Child cats */
512
513 if ($include_nested && $cat_id) {
514 $result = db_query($link, "SELECT
515 id, title FROM ttrss_feed_categories
516 WHERE parent_cat = '$cat_id' AND owner_uid = " . $_SESSION["uid"] .
517 " ORDER BY id, title");
518
519 while ($line = db_fetch_assoc($result)) {
520 $unread = getFeedUnread($link, $line["id"], true) +
521 getCategoryChildrenUnread($link, $line["id"]);
522
523 if ($unread || !$unread_only) {
524 $row = array(
525 "id" => $line["id"],
526 "title" => $line["title"],
527 "unread" => $unread,
528 "is_cat" => true,
529 );
530 array_push($feeds, $row);
531 }
532 }
533 }
534
535 /* Real feeds */
536
537 if ($limit) {
538 $limit_qpart = "LIMIT $limit OFFSET $offset";
539 } else {
540 $limit_qpart = "";
541 }
542
543 if ($cat_id == -4 || $cat_id == -3) {
544 $result = db_query($link, "SELECT
545 id, feed_url, cat_id, title, order_id, ".
546 SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
547 FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] .
548 " ORDER BY cat_id, title " . $limit_qpart);
549 } else {
550
551 if ($cat_id)
552 $cat_qpart = "cat_id = '$cat_id'";
553 else
554 $cat_qpart = "cat_id IS NULL";
555
556 $result = db_query($link, "SELECT
557 id, feed_url, cat_id, title, order_id, ".
558 SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
559 FROM ttrss_feeds WHERE
560 $cat_qpart AND owner_uid = " . $_SESSION["uid"] .
561 " ORDER BY cat_id, title " . $limit_qpart);
562 }
563
564 while ($line = db_fetch_assoc($result)) {
565
566 $unread = getFeedUnread($link, $line["id"]);
567
568 $has_icon = feed_has_icon($line['id']);
569
570 if ($unread || !$unread_only) {
571
572 $row = array(
573 "feed_url" => $line["feed_url"],
574 "title" => $line["title"],
575 "id" => (int)$line["id"],
576 "unread" => (int)$unread,
577 "has_icon" => $has_icon,
578 "cat_id" => (int)$line["cat_id"],
ef3da31c 579 "last_updated" => (int) strtotime($line["last_updated"]),
04f60eb7
AD
580 "order_id" => (int) $line["order_id"],
581 );
582
583 array_push($feeds, $row);
584 }
585 }
586
587 return $feeds;
588 }
589
590 static function api_get_headlines($link, $feed_id, $limit, $offset,
591 $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
592 $include_attachments, $since_id,
ca5d9be4 593 $search = "", $search_mode = "",
04f60eb7
AD
594 $include_nested = false, $sanitize_content = true) {
595
596 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
ca5d9be4 597 $view_mode, $is_cat, $search, $search_mode,
04f60eb7
AD
598 $order, $offset, 0, false, $since_id, $include_nested);
599
600 $result = $qfh_ret[0];
601 $feed_title = $qfh_ret[1];
602
603 $headlines = array();
604
605 while ($line = db_fetch_assoc($result)) {
606 $is_updated = ($line["last_read"] == "" &&
607 ($line["unread"] != "t" && $line["unread"] != "1"));
608
609 $tags = explode(",", $line["tag_cache"]);
610 $labels = json_decode($line["label_cache"], true);
611
612 //if (!$tags) $tags = get_article_tags($link, $line["id"]);
613 //if (!$labels) $labels = get_article_labels($link, $line["id"]);
614
615 $headline_row = array(
616 "id" => (int)$line["id"],
617 "unread" => sql_bool_to_bool($line["unread"]),
618 "marked" => sql_bool_to_bool($line["marked"]),
619 "published" => sql_bool_to_bool($line["published"]),
ef3da31c 620 "updated" => (int) strtotime($line["updated"]),
04f60eb7
AD
621 "is_updated" => $is_updated,
622 "title" => $line["title"],
623 "link" => $line["link"],
624 "feed_id" => $line["feed_id"],
625 "tags" => $tags,
626 );
627
628 if ($include_attachments)
629 $headline_row['attachments'] = get_article_enclosures($link,
630 $line['id']);
631
632 if ($show_excerpt) {
633 $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
634 $headline_row["excerpt"] = $excerpt;
635 }
636
637 if ($show_content) {
638
639 if ($line["cached_content"] != "") {
640 $line["content_preview"] =& $line["cached_content"];
641 }
642
643 if ($sanitize_content) {
644 $headline_row["content"] = sanitize($link,
bfd61d3f
AD
645 $line["content_preview"],
646 sql_bool_to_bool($line['hide_images']),
647 false, $line["site_url"]);
04f60eb7
AD
648 } else {
649 $headline_row["content"] = $line["content_preview"];
650 }
651 }
652
653 // unify label output to ease parsing
654 if ($labels["no-labels"] == 1) $labels = array();
655
656 $headline_row["labels"] = $labels;
657
658 $headline_row["feed_title"] = $line["feed_title"];
659
660 $headline_row["comments_count"] = (int)$line["num_comments"];
661 $headline_row["comments_link"] = $line["comments"];
662
663 $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
664
b6604c96
AD
665 global $pluginhost;
666 foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_API) as $p) {
667 $headline_row = $p->hook_render_article_api($headline_row);
668 }
669
04f60eb7
AD
670 array_push($headlines, $headline_row);
671 }
672
673 return $headlines;
674 }
675
efc6553d
AD
676 function unsubscribeFeed() {
677 $feed_id = (int) db_escape_string($this->link, $_REQUEST["feed_id"]);
678
679 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
680 id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
681
682 if (db_num_rows($result) != 0) {
683 Pref_Feeds::remove_feed($this->link, $feed_id, $_SESSION["uid"]);
684 print $this->wrap(self::STATUS_OK, array("status" => "OK"));
685 } else {
686 print $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND"));
687 }
688 }
689
690 function subscribeToFeed() {
691 $feed_url = db_escape_string($this->link, $_REQUEST["feed_url"]);
692 $category_id = (int) db_escape_string($this->link, $_REQUEST["category_id"]);
693 $login = db_escape_string($this->link, $_REQUEST["login"]);
694 $password = db_escape_string($this->link, $_REQUEST["password"]);
695
696 if ($feed_url) {
697 $rc = subscribe_to_feed($this->link, $feed_url, $category_id,
698 $login, $password, false);
699
700 print $this->wrap(self::STATUS_OK, array("status" => $rc));
701 } else {
702 print $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
703 }
704 }
705
de8260cb
AD
706}
707
708?>