class API extends Handler {
- const API_LEVEL = 2;
+ const API_LEVEL = 4;
const STATUS_OK = 0;
const STATUS_ERR = 1;
function before($method) {
if (parent::before($method)) {
+ header("Content-Type: text/plain");
if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") {
print $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN'));
$this->seq = (int) $_REQUEST['seq'];
- header("Content-Type: text/plain");
return true;
}
return false;
if (get_pref($this->link, "ENABLE_API_ACCESS", $uid)) {
if (authenticate_user($this->link, $login, $password)) { // try login with normal password
- print $this->wrap(self::STATUS_OK, array("session_id" => session_id()));
+ print $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
+ "api_level" => self::API_LEVEL));
} else if (authenticate_user($this->link, $login, $password_base64)) { // else try with base64_decoded password
- print $this->wrap(self::STATUS_OK, array("session_id" => session_id()));
+ print $this->wrap(self::STATUS_OK, array("session_id" => session_id(),
+ "api_level" => self::API_LEVEL));
} else { // else we are not logged in
print $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR"));
}
$unread_only = (bool)db_escape_string($_REQUEST["unread_only"]);
$limit = (int) db_escape_string($_REQUEST["limit"]);
$offset = (int) db_escape_string($_REQUEST["offset"]);
+ $include_nested = (bool)db_escape_string($_REQUEST["include_nested"]);
- $feeds = api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset);
+ $feeds = api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset, $include_nested);
print $this->wrap(self::STATUS_OK, $feeds);
}
function getCategories() {
$unread_only = (bool)db_escape_string($_REQUEST["unread_only"]);
+ $enable_nested = (bool)db_escape_string($_REQUEST["enable_nested"]);
// TODO do not return empty categories, return Uncategorized and standard virtual cats
+ if ($enable_nested)
+ $nested_qpart = "parent_cat IS NULL";
+ else
+ $nested_qpart = "true";
+
$result = db_query($this->link, "SELECT
- id, title FROM ttrss_feed_categories
- WHERE owner_uid = " .
+ id, title, order_id FROM ttrss_feed_categories
+ WHERE $nested_qpart AND owner_uid = " .
$_SESSION["uid"]);
$cats = array();
while ($line = db_fetch_assoc($result)) {
$unread = getFeedUnread($this->link, $line["id"], true);
+ if ($enable_nested)
+ $unread += getCategoryChildrenUnread($this->link, $line["id"]);
+
if ($unread || !$unread_only) {
array_push($cats, array("id" => $line["id"],
"title" => $line["title"],
- "unread" => $unread));
+ "unread" => $unread,
+ "order_id" => (int) $line["order_id"],
+ ));
}
}
$view_mode = db_escape_string($_REQUEST["view_mode"]);
$include_attachments = (bool)db_escape_string($_REQUEST["include_attachments"]);
$since_id = (int)db_escape_string($_REQUEST["since_id"]);
+ $include_nested = (bool)db_escape_string($_REQUEST["include_nested"]);
+ $sanitize_content = true;
/* do not rely on params below */
$headlines = api_get_headlines($this->link, $feed_id, $limit, $offset,
$filter, $is_cat, $show_excerpt, $show_content, $view_mode, false,
- $include_attachments, $since_id, $search, $search_mode, $match_on);
+ $include_attachments, $since_id, $search, $search_mode, $match_on,
+ $include_nested, $sanitize_content);
print $this->wrap(self::STATUS_OK, $headlines);
} else {
$article_id = join(",", array_filter(explode(",", db_escape_string($_REQUEST["article_id"])), is_numeric));
- $query = "SELECT id,title,link,content,feed_id,comments,int_id,
+ $query = "SELECT id,title,link,content,cached_content,feed_id,comments,int_id,
marked,unread,published,
".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
author
"comments" => $line["comments"],
"author" => $line["author"],
"updated" => strtotime($line["updated"]),
- "content" => $line["content"],
+ "content" => $line["cached_content"] != "" ? $line["cached_content"] : $line["content"],
"feed_id" => $line["feed_id"],
"attachments" => $attachments
);
print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD'));
}
+ function shareToPublished() {
+ $title = db_escape_string(strip_tags($_REQUEST["title"]));
+ $url = db_escape_string(strip_tags($_REQUEST["url"]));
+ $content = db_escape_string(strip_tags($_REQUEST["content"]));
+
+ if (create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) {
+ print $this->wrap(self::STATUS_OK, array("status" => 'OK'));
+ } else {
+ print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));
+ }
+ }
}
?>