]>
git.wh0rd.org - tt-rss.git/blob - classes/api.php
6f95db0bed0479db683e68e69bc4000141c78d16
3 class API
extends Handler
{
12 function before ( $method ) {
13 if ( parent
:: before ( $method )) {
14 header ( "Content-Type: text/json" );
16 if (! $_SESSION [ "uid" ] && $method != "login" && $method != "isloggedin" ) {
17 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'NOT_LOGGED_IN' ));
21 if ( $_SESSION [ "uid" ] && $method != "logout" && ! get_pref ( $this -> link
, 'ENABLE_API_ACCESS' )) {
22 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'API_DISABLED' ));
26 $this -> seq
= ( int ) $_REQUEST [ 'seq' ];
33 function wrap ( $status , $reply ) {
34 print json_encode ( array ( "seq" => $this -> seq
,
36 "content" => $reply ));
39 function getVersion () {
40 $rv = array ( "version" => VERSION
);
41 print $this -> wrap ( self
:: STATUS_OK
, $rv );
44 function getApiLevel () {
45 $rv = array ( "level" => self
:: API_LEVEL
);
46 print $this -> wrap ( self
:: STATUS_OK
, $rv );
53 $login = db_escape_string ( $this -> link
, $_REQUEST [ "user" ]);
54 $password = $_REQUEST [ "password" ];
55 $password_base64 = base64_decode ( $_REQUEST [ "password" ]);
57 if ( SINGLE_USER_MODE
) $login = "admin" ;
59 $result = db_query ( $this -> link
, "SELECT id FROM ttrss_users WHERE login = ' $login '" );
61 if ( db_num_rows ( $result ) != 0 ) {
62 $uid = db_fetch_result ( $result , 0 , "id" );
68 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => "LOGIN_ERROR" ));
72 if ( get_pref ( $this -> link
, "ENABLE_API_ACCESS" , $uid )) {
73 if ( authenticate_user ( $this -> link
, $login , $password )) { // try login with normal password
74 print $this -> wrap ( self
:: STATUS_OK
, array ( "session_id" => session_id (),
75 "api_level" => self
:: API_LEVEL
));
76 } else if ( authenticate_user ( $this -> link
, $login , $password_base64 )) { // else try with base64_decoded password
77 print $this -> wrap ( self
:: STATUS_OK
, array ( "session_id" => session_id (),
78 "api_level" => self
:: API_LEVEL
));
79 } else { // else we are not logged in
80 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => "LOGIN_ERROR" ));
83 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => "API_DISABLED" ));
90 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ));
93 function isLoggedIn () {
94 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => $_SESSION [ "uid" ] != '' ));
97 function getUnread () {
98 $feed_id = db_escape_string ( $this -> link
, $_REQUEST [ "feed_id" ]);
99 $is_cat = db_escape_string ( $this -> link
, $_REQUEST [ "is_cat" ]);
102 print $this -> wrap ( self
:: STATUS_OK
, array ( "unread" => getFeedUnread ( $this -> link
, $feed_id , $is_cat )));
104 print $this -> wrap ( self
:: STATUS_OK
, array ( "unread" => getGlobalUnread ( $this -> link
)));
108 /* Method added for ttrss-reader for Android */
109 function getCounters () {
110 print $this -> wrap ( self
:: STATUS_OK
, getAllCounters ( $this -> link
));
113 function getFeedStats () {
114 $feeds = $this -> api_get_feed_stats ( $this -> link
);
115 print $this -> wrap ( self
:: STATUS_OK
, $feeds );
118 function getFeeds () {
119 $cat_id = db_escape_string ( $this -> link
, $_REQUEST [ "cat_id" ]);
120 $unread_only = sql_bool_to_bool ( $_REQUEST [ "unread_only" ]);
121 $limit = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "limit" ]);
122 $offset = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "offset" ]);
123 $include_nested = sql_bool_to_bool ( $_REQUEST [ "include_nested" ]);
125 $feeds = $this -> api_get_feeds ( $this -> link
, $cat_id , $unread_only , $limit , $offset , $include_nested );
127 print $this -> wrap ( self
:: STATUS_OK
, $feeds );
130 function getCategories () {
131 $unread_only = sql_bool_to_bool ( $_REQUEST [ "unread_only" ]);
132 $enable_nested = sql_bool_to_bool ( $_REQUEST [ "enable_nested" ]);
133 $include_empty = sql_bool_to_bool ( $_REQUEST [ 'include_empty' ]);
135 // TODO do not return empty categories, return Uncategorized and standard virtual cats
138 $nested_qpart = "parent_cat IS NULL" ;
140 $nested_qpart = "true" ;
142 $result = db_query ( $this -> link
, "SELECT
143 id, title, order_id, (SELECT COUNT(id) FROM
145 ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds,
146 (SELECT COUNT(id) FROM
147 ttrss_feed_categories AS c2 WHERE
148 c2.parent_cat = ttrss_feed_categories.id) AS num_cats
149 FROM ttrss_feed_categories
150 WHERE $nested_qpart AND owner_uid = " .
155 while ( $line = db_fetch_assoc ( $result )) {
156 if ( $include_empty ||
$line [ "num_feeds" ] > 0 ||
$line [ "num_cats" ] > 0 ) {
157 $unread = getFeedUnread ( $this -> link
, $line [ "id" ], true );
160 $unread +
= getCategoryChildrenUnread ( $this -> link
, $line [ "id" ]);
162 if ( $unread ||
! $unread_only ) {
163 array_push ( $cats , array ( "id" => $line [ "id" ],
164 "title" => $line [ "title" ],
166 "order_id" => ( int ) $line [ "order_id" ],
172 foreach ( array (- 2 ,- 1 , 0 ) as $cat_id ) {
173 if ( $include_empty ||
! $this -> isCategoryEmpty ( $cat_id )) {
174 $unread = getFeedUnread ( $this -> link
, $cat_id , true );
176 if ( $unread ||
! $unread_only ) {
177 array_push ( $cats , array ( "id" => $cat_id ,
178 "title" => getCategoryTitle ( $this -> link
, $cat_id ),
179 "unread" => $unread ));
184 print $this -> wrap ( self
:: STATUS_OK
, $cats );
187 function getHeadlines () {
188 $feed_id = db_escape_string ( $this -> link
, $_REQUEST [ "feed_id" ]);
189 if ( $feed_id != "" ) {
191 $limit = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "limit" ]);
193 if (! $limit ||
$limit >= 60 ) $limit = 60 ;
195 $offset = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "skip" ]);
196 $filter = db_escape_string ( $this -> link
, $_REQUEST [ "filter" ]);
197 $is_cat = sql_bool_to_bool ( $_REQUEST [ "is_cat" ]);
198 $show_excerpt = sql_bool_to_bool ( $_REQUEST [ "show_excerpt" ]);
199 $show_content = sql_bool_to_bool ( $_REQUEST [ "show_content" ]);
200 /* all_articles, unread, adaptive, marked, updated */
201 $view_mode = db_escape_string ( $this -> link
, $_REQUEST [ "view_mode" ]);
202 $include_attachments = sql_bool_to_bool ( $_REQUEST [ "include_attachments" ]);
203 $since_id = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "since_id" ]);
204 $include_nested = sql_bool_to_bool ( $_REQUEST [ "include_nested" ]);
205 $sanitize_content = true ;
207 $override_order = false ;
208 switch ( $_REQUEST [ "order_by" ]) {
210 $override_order = "date_entered, updated" ;
213 $override_order = "updated DESC" ;
217 /* do not rely on params below */
219 $search = db_escape_string ( $this -> link
, $_REQUEST [ "search" ]);
220 $search_mode = db_escape_string ( $this -> link
, $_REQUEST [ "search_mode" ]);
222 $headlines = $this -> api_get_headlines ( $this -> link
, $feed_id , $limit , $offset ,
223 $filter , $is_cat , $show_excerpt , $show_content , $view_mode , $override_order ,
224 $include_attachments , $since_id , $search , $search_mode ,
225 $include_nested , $sanitize_content );
227 print $this -> wrap ( self
:: STATUS_OK
, $headlines );
229 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'INCORRECT_USAGE' ));
233 function updateArticle () {
234 $article_ids = array_filter ( explode ( "," , db_escape_string ( $this -> link
, $_REQUEST [ "article_ids" ])), is_numeric
);
235 $mode = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "mode" ]);
236 $data = db_escape_string ( $this -> link
, $_REQUEST [ "data" ]);
237 $field_raw = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "field" ]);
242 switch ( $field_raw ) {
245 $additional_fields = ",last_marked = NOW()" ;
248 $field = "published" ;
249 $additional_fields = ",last_published = NOW()" ;
253 $additional_fields = ",last_read = NOW()" ;
267 $set_to = "NOT $field " ;
271 if ( $field == "note" ) $set_to = "' $data '" ;
273 if ( $field && $set_to && count ( $article_ids ) > 0 ) {
275 $article_ids = join ( ", " , $article_ids );
277 $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" ]);
279 $num_updated = db_affected_rows ( $this -> link
, $result );
281 if ( $num_updated > 0 && $field == "unread" ) {
282 $result = db_query ( $this -> link
, "SELECT DISTINCT feed_id FROM ttrss_user_entries
283 WHERE ref_id IN ( $article_ids )" );
285 while ( $line = db_fetch_assoc ( $result )) {
286 ccache_update ( $this -> link
, $line [ "feed_id" ], $_SESSION [ "uid" ]);
290 if ( $num_updated > 0 && $field == "published" ) {
291 if ( PUBSUBHUBBUB_HUB
) {
292 $rss_link = get_self_url_prefix () .
293 "/public.php?op=rss&id=-2&key=" .
294 get_feed_access_key ( $this -> link
, - 2 , false );
296 $p = new Publisher ( PUBSUBHUBBUB_HUB
);
297 $pubsub_result = $p -> publish_update ( $rss_link );
301 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ,
302 "updated" => $num_updated ));
305 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'INCORRECT_USAGE' ));
310 function getArticle () {
312 $article_id = join ( "," , array_filter ( explode ( "," , db_escape_string ( $this -> link
, $_REQUEST [ "article_id" ])), is_numeric
));
314 $query = "SELECT id,title,link,content,cached_content,feed_id,comments,int_id,
315 marked,unread,published,
316 " . SUBSTRING_FOR_DATE
. "(updated,1,16) as updated,
318 FROM ttrss_entries,ttrss_user_entries
319 WHERE id IN ( $article_id ) AND ref_id = id AND owner_uid = " .
322 $result = db_query ( $this -> link
, $query );
326 if ( db_num_rows ( $result ) != 0 ) {
328 while ( $line = db_fetch_assoc ( $result )) {
330 $attachments = get_article_enclosures ( $this -> link
, $line [ 'id' ]);
334 "title" => $line [ "title" ],
335 "link" => $line [ "link" ],
336 "labels" => get_article_labels ( $this -> link
, $line [ 'id' ]),
337 "unread" => sql_bool_to_bool ( $line [ "unread" ]),
338 "marked" => sql_bool_to_bool ( $line [ "marked" ]),
339 "published" => sql_bool_to_bool ( $line [ "published" ]),
340 "comments" => $line [ "comments" ],
341 "author" => $line [ "author" ],
342 "updated" => ( int ) strtotime ( $line [ "updated" ]),
343 "content" => $line [ "cached_content" ] != "" ?
$line [ "cached_content" ] : $line [ "content" ],
344 "feed_id" => $line [ "feed_id" ],
345 "attachments" => $attachments
349 foreach ( $pluginhost -> get_hooks ( $pluginhost :: HOOK_RENDER_ARTICLE_API
) as $p ) {
350 $article = $p -> hook_render_article_api ( array ( "article" => $article ));
354 array_push ( $articles , $article );
359 print $this -> wrap ( self
:: STATUS_OK
, $articles );
363 function getConfig () {
365 "icons_dir" => ICONS_DIR
,
366 "icons_url" => ICONS_URL
);
368 $config [ "daemon_is_running" ] = file_is_locked ( "update_daemon.lock" );
370 $result = db_query ( $this -> link
, "SELECT COUNT(*) AS cf FROM
371 ttrss_feeds WHERE owner_uid = " . $_SESSION [ "uid" ]);
373 $num_feeds = db_fetch_result ( $result , 0 , "cf" );
375 $config [ "num_feeds" ] = ( int ) $num_feeds ;
377 print $this -> wrap ( self
:: STATUS_OK
, $config );
380 function updateFeed () {
381 require_once "include/rssfuncs.php" ;
383 $feed_id = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "feed_id" ]);
385 update_rss_feed ( $this -> link
, $feed_id , true );
387 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ));
390 function catchupFeed () {
391 $feed_id = db_escape_string ( $this -> link
, $_REQUEST [ "feed_id" ]);
392 $is_cat = db_escape_string ( $this -> link
, $_REQUEST [ "is_cat" ]);
394 catchup_feed ( $this -> link
, $feed_id , $is_cat );
396 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ));
400 $pref_name = db_escape_string ( $this -> link
, $_REQUEST [ "pref_name" ]);
402 print $this -> wrap ( self
:: STATUS_OK
, array ( "value" => get_pref ( $this -> link
, $pref_name )));
405 function getLabels () {
406 //$article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric);
408 $article_id = ( int ) $_REQUEST [ 'article_id' ];
412 $result = db_query ( $this -> link
, "SELECT id, caption, fg_color, bg_color
414 WHERE owner_uid = '" . $_SESSION [ 'uid' ]. "' ORDER BY caption" );
417 $article_labels = get_article_labels ( $this -> link
, $article_id );
419 $article_labels = array ();
421 while ( $line = db_fetch_assoc ( $result )) {
424 foreach ( $article_labels as $al ) {
425 if ( $al [ 0 ] == $line [ 'id' ]) {
431 array_push ( $rv , array (
432 "id" => ( int ) $line [ 'id' ],
433 "caption" => $line [ 'caption' ],
434 "fg_color" => $line [ 'fg_color' ],
435 "bg_color" => $line [ 'bg_color' ],
436 "checked" => $checked ));
439 print $this -> wrap ( self
:: STATUS_OK
, $rv );
442 function setArticleLabel () {
444 $article_ids = array_filter ( explode ( "," , db_escape_string ( $this -> link
, $_REQUEST [ "article_ids" ])), is_numeric
);
445 $label_id = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ 'label_id' ]);
446 $assign = ( bool ) db_escape_string ( $this -> link
, $_REQUEST [ 'assign' ]) == "true" ;
448 $label = db_escape_string ( $this -> link
, label_find_caption ( $this -> link
,
449 $label_id , $_SESSION [ "uid" ]));
455 foreach ( $article_ids as $id ) {
458 label_add_article ( $this -> link
, $id , $label , $_SESSION [ "uid" ]);
460 label_remove_article ( $this -> link
, $id , $label , $_SESSION [ "uid" ]);
467 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ,
468 "updated" => $num_updated ));
473 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'UNKNOWN_METHOD' ));
476 function shareToPublished () {
477 $title = db_escape_string ( $this -> link
, strip_tags ( $_REQUEST [ "title" ]));
478 $url = db_escape_string ( $this -> link
, strip_tags ( $_REQUEST [ "url" ]));
479 $content = db_escape_string ( $this -> link
, strip_tags ( $_REQUEST [ "content" ]));
481 if ( Article
:: create_published_article ( $this -> link
, $title , $url , $content , "" , $_SESSION [ "uid" ])) {
482 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => 'OK' ));
484 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'Publishing failed' ));
488 static function api_get_feed_stats ( $link ) {
492 $result = db_query ( $link , "SELECT ttrss_feeds.id, ttrss_feeds.title," .
493 " MIN(ttrss_entries.id) AS first, MAX(ttrss_entries.id) AS last," .
494 " COUNT(ttrss_entries.id) AS total" .
495 " FROM ttrss_entries, ttrss_user_entries, ttrss_feeds" .
496 " WHERE ttrss_user_entries.feed_id = ttrss_feeds.id" .
497 " AND ttrss_user_entries.ref_id = ttrss_entries.id" .
498 " AND ttrss_user_entries.owner_uid = " . $_SESSION [ "uid" ].
499 " GROUP BY ttrss_feeds.title" );
501 while ( $line = db_fetch_assoc ( $result )) {
503 $unread = getFeedUnread ( $link , $line [ "id" ]);
506 "id" => ( int ) $line [ "id" ],
507 "title" => $line [ "title" ],
508 "first" => ( int ) $line [ "first" ],
509 "last" => ( int ) $line [ "last" ],
510 "total" => ( int ) $line [ "total" ],
511 "unread" => ( int ) $unread
514 array_push ( $feeds , $row );
520 static function api_get_feeds ( $link , $cat_id , $unread_only , $limit , $offset , $include_nested = false ) {
526 if ( $cat_id == - 4 ||
$cat_id == - 2 ) {
527 $counters = getLabelCounters ( $link , true );
529 foreach ( array_values ( $counters ) as $cv ) {
531 $unread = $cv [ "counter" ];
533 if ( $unread ||
! $unread_only ) {
537 "title" => $cv [ "description" ],
538 "unread" => $cv [ "counter" ],
542 array_push ( $feeds , $row );
549 if ( $cat_id == - 4 ||
$cat_id == - 1 ) {
550 foreach ( array (- 1 , - 2 , - 3 , - 4 , - 6 , 0 ) as $i ) {
551 $unread = getFeedUnread ( $link , $i );
553 if ( $unread ||
! $unread_only ) {
554 $title = getFeedTitle ( $link , $i );
562 array_push ( $feeds , $row );
570 if ( $include_nested && $cat_id ) {
571 $result = db_query ( $link , "SELECT
572 id, title FROM ttrss_feed_categories
573 WHERE parent_cat = ' $cat_id ' AND owner_uid = " . $_SESSION [ "uid" ] .
574 " ORDER BY id, title" );
576 while ( $line = db_fetch_assoc ( $result )) {
577 $unread = getFeedUnread ( $link , $line [ "id" ], true ) +
578 getCategoryChildrenUnread ( $link , $line [ "id" ]);
580 if ( $unread ||
! $unread_only ) {
583 "title" => $line [ "title" ],
587 array_push ( $feeds , $row );
595 $limit_qpart = "LIMIT $limit OFFSET $offset " ;
600 if ( $cat_id == - 4 ||
$cat_id == - 3 ) {
601 $result = db_query ( $link , "SELECT
602 id, feed_url, cat_id, title, order_id, " .
603 SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
604 FROM ttrss_feeds WHERE owner_uid = " . $_SESSION [ "uid" ] .
605 " ORDER BY cat_id, title " . $limit_qpart );
609 $cat_qpart = "cat_id = ' $cat_id '" ;
611 $cat_qpart = "cat_id IS NULL" ;
613 $result = db_query ( $link , "SELECT
614 id, feed_url, cat_id, title, order_id, " .
615 SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
616 FROM ttrss_feeds WHERE
617 $cat_qpart AND owner_uid = " . $_SESSION [ "uid" ] .
618 " ORDER BY cat_id, title " . $limit_qpart );
621 while ( $line = db_fetch_assoc ( $result )) {
623 $unread = getFeedUnread ( $link , $line [ "id" ]);
625 $has_icon = feed_has_icon ( $line [ 'id' ]);
627 if ( $unread ||
! $unread_only ) {
630 "feed_url" => $line [ "feed_url" ],
631 "title" => $line [ "title" ],
632 "id" => ( int ) $line [ "id" ],
633 "unread" => ( int ) $unread ,
634 "has_icon" => $has_icon ,
635 "cat_id" => ( int ) $line [ "cat_id" ],
636 "last_updated" => ( int ) strtotime ( $line [ "last_updated" ]),
637 "order_id" => ( int ) $line [ "order_id" ],
640 array_push ( $feeds , $row );
647 static function api_get_headlines ( $link , $feed_id , $limit , $offset ,
648 $filter , $is_cat , $show_excerpt , $show_content , $view_mode , $order ,
649 $include_attachments , $since_id ,
650 $search = "" , $search_mode = "" ,
651 $include_nested = false , $sanitize_content = true ) {
653 $qfh_ret = queryFeedHeadlines ( $link , $feed_id , $limit ,
654 $view_mode , $is_cat , $search , $search_mode ,
655 $order , $offset , 0 , false , $since_id , $include_nested );
657 $result = $qfh_ret [ 0 ];
658 $feed_title = $qfh_ret [ 1 ];
660 $headlines = array ();
662 while ( $line = db_fetch_assoc ( $result )) {
663 $is_updated = ( $line [ "last_read" ] == "" &&
664 ( $line [ "unread" ] != "t" && $line [ "unread" ] != "1" ));
666 $tags = explode ( "," , $line [ "tag_cache" ]);
667 $labels = json_decode ( $line [ "label_cache" ], true );
669 //if (!$tags) $tags = get_article_tags($link, $line["id"]);
670 //if (!$labels) $labels = get_article_labels($link, $line["id"]);
672 $headline_row = array (
673 "id" => ( int ) $line [ "id" ],
674 "unread" => sql_bool_to_bool ( $line [ "unread" ]),
675 "marked" => sql_bool_to_bool ( $line [ "marked" ]),
676 "published" => sql_bool_to_bool ( $line [ "published" ]),
677 "updated" => ( int ) strtotime ( $line [ "updated" ]),
678 "is_updated" => $is_updated ,
679 "title" => $line [ "title" ],
680 "link" => $line [ "link" ],
681 "feed_id" => $line [ "feed_id" ],
685 if ( $include_attachments )
686 $headline_row [ 'attachments' ] = get_article_enclosures ( $link ,
690 $excerpt = truncate_string ( strip_tags ( $line [ "content_preview" ]), 100 );
691 $headline_row [ "excerpt" ] = $excerpt ;
696 if ( $line [ "cached_content" ] != "" ) {
697 $line [ "content_preview" ] =& $line [ "cached_content" ];
700 if ( $sanitize_content ) {
701 $headline_row [ "content" ] = sanitize ( $link ,
702 $line [ "content_preview" ],
703 sql_bool_to_bool ( $line [ 'hide_images' ]),
704 false , $line [ "site_url" ]);
706 $headline_row [ "content" ] = $line [ "content_preview" ];
710 // unify label output to ease parsing
711 if ( $labels [ "no-labels" ] == 1 ) $labels = array ();
713 $headline_row [ "labels" ] = $labels ;
715 $headline_row [ "feed_title" ] = $line [ "feed_title" ];
717 $headline_row [ "comments_count" ] = ( int ) $line [ "num_comments" ];
718 $headline_row [ "comments_link" ] = $line [ "comments" ];
720 $headline_row [ "always_display_attachments" ] = sql_bool_to_bool ( $line [ "always_display_enclosures" ]);
722 $headline_row [ "author" ] = $line [ "author" ];
725 foreach ( $pluginhost -> get_hooks ( $pluginhost :: HOOK_RENDER_ARTICLE_API
) as $p ) {
726 $headline_row = $p -> hook_render_article_api ( array ( "headline" => $headline_row ));
729 array_push ( $headlines , $headline_row );
735 function unsubscribeFeed () {
736 $feed_id = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "feed_id" ]);
738 $result = db_query ( $this -> link
, "SELECT id FROM ttrss_feeds WHERE
739 id = ' $feed_id ' AND owner_uid = " . $_SESSION [ "uid" ]);
741 if ( db_num_rows ( $result ) != 0 ) {
742 Pref_Feeds
:: remove_feed ( $this -> link
, $feed_id , $_SESSION [ "uid" ]);
743 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => "OK" ));
745 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => "FEED_NOT_FOUND" ));
749 function subscribeToFeed () {
750 $feed_url = db_escape_string ( $this -> link
, $_REQUEST [ "feed_url" ]);
751 $category_id = ( int ) db_escape_string ( $this -> link
, $_REQUEST [ "category_id" ]);
752 $login = db_escape_string ( $this -> link
, $_REQUEST [ "login" ]);
753 $password = db_escape_string ( $this -> link
, $_REQUEST [ "password" ]);
756 $rc = subscribe_to_feed ( $this -> link
, $feed_url , $category_id ,
757 $login , $password , false );
759 print $this -> wrap ( self
:: STATUS_OK
, array ( "status" => $rc ));
761 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" => 'INCORRECT_USAGE' ));
765 function getFeedTree () {
766 $include_empty = sql_bool_to_bool ( $_REQUEST [ 'include_empty' ]);
768 $pf = new Pref_Feeds ( $this -> link
, $_REQUEST );
770 $_REQUEST [ 'mode' ] = 2 ;
771 $_REQUEST [ 'force_show_empty' ] = $include_empty ;
774 $data = $pf -> makefeedtree ();
775 print $this -> wrap ( self
:: STATUS_OK
, array ( "categories" => $data ));
777 print $this -> wrap ( self
:: STATUS_ERR
, array ( "error" =>
778 'UNABLE_TO_INSTANTIATE_OBJECT' ));
783 // only works for labels or uncategorized for the time being
784 private function isCategoryEmpty ( $id ) {
787 $result = db_query ( $this -> link
, "SELECT COUNT(*) AS count FROM ttrss_labels2
788 WHERE owner_uid = " . $_SESSION [ "uid" ]);
790 return db_fetch_result ( $result , 0 , "count" ) == 0 ;
792 } else if ( $id == 0 ) {
793 $result = db_query ( $this -> link
, "SELECT COUNT(*) AS count FROM ttrss_feeds
794 WHERE cat_id IS NULL AND owner_uid = " . $_SESSION [ "uid" ]);
796 return db_fetch_result ( $result , 0 , "count" ) == 0 ;