From: Andrew Dolgov Date: Sat, 17 Dec 2011 07:06:55 +0000 (+0400) Subject: api: add getLabels X-Git-Tag: 1.5.8~3 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ea1c2903ee5a5bca9b79d13c5199e7a34147caa8;p=tt-rss.git api: add getLabels --- diff --git a/classes/api.php b/classes/api.php index e046fc57..9dd8fa7e 100644 --- a/classes/api.php +++ b/classes/api.php @@ -337,6 +337,43 @@ class API extends Handler { print $this->wrap(self::STATUS_OK, array("value" => get_pref($this->link, $pref_name))); } + function getLabels() { + //$article_ids = array_filter(explode(",", db_escape_string($_REQUEST["article_ids"])), is_numeric); + + $article_id = (int)$_REQUEST['article_id']; + + $rv = array(); + + $result = db_query($this->link, "SELECT id, caption, fg_color, bg_color + FROM ttrss_labels2 + WHERE owner_uid = '".$_SESSION['uid']."' ORDER BY caption"); + + if ($article_id) + $article_labels = get_article_labels($this->link, $article_id); + else + $article_labels = array(); + + while ($line = db_fetch_assoc($result)) { + + $checked = false; + foreach ($article_labels as $al) { + if ($al[0] == $line['id']) { + $checked = true; + break; + } + } + + array_push($rv, array( + "id" => (int)$line['id'], + "caption" => $line['caption'], + "fg_color" => $line['fg_color'], + "bg_color" => $line['bg_color'], + "checked" => $checked)); + } + + print $this->wrap(self::STATUS_OK, $rv); + } + function index() { print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD')); }