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