summaryrefslogtreecommitdiff
path: root/classes/api.php
diff options
context:
space:
mode:
authorPedro Silva <[email protected]>2013-04-11 16:25:37 +0100
committerPedro Silva <[email protected]>2013-04-11 16:25:37 +0100
commit0192ffe5a5f8254d723cf46e4bda839220191c2c (patch)
tree339b55be1c0d4703f5ab15160dce145a35a59887 /classes/api.php
parent063ac6135304223d6667401936e3a3931522b07c (diff)
Add new API method: `getFeedStats'
`getFeedStats' calls the new static function `api_get_feed_stats' to return an array of real feeds of the following form: [{ "first" : 1127, "unread" : 873, "last" : 15460, "title" : "Some feed", "id" : 31, "total" : 1513 }] where "first", "last", "total" are the first, last and total number of articles in the feed. This adds the ability to nntp-oriented clients to efficiently retrieve an "active file" without having to resort to `getHeadlines(limit=-1)'
Diffstat (limited to 'classes/api.php')
-rw-r--r--classes/api.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/classes/api.php b/classes/api.php
index 4427834eb..6f95db0be 100644
--- a/classes/api.php
+++ b/classes/api.php
@@ -110,6 +110,11 @@ class API extends Handler {
print $this->wrap(self::STATUS_OK, getAllCounters($this->link));
}
+ function getFeedStats() {
+ $feeds = $this->api_get_feed_stats($this->link);
+ print $this->wrap(self::STATUS_OK, $feeds);
+ }
+
function getFeeds() {
$cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
$unread_only = sql_bool_to_bool($_REQUEST["unread_only"]);
@@ -480,6 +485,38 @@ class API extends Handler {
}
}
+ static function api_get_feed_stats($link) {
+
+ $feeds = array();
+
+ $result = db_query($link, "SELECT ttrss_feeds.id, ttrss_feeds.title,".
+ " MIN(ttrss_entries.id) AS first, MAX(ttrss_entries.id) AS last,".
+ " COUNT(ttrss_entries.id) AS total".
+ " FROM ttrss_entries, ttrss_user_entries, ttrss_feeds".
+ " WHERE ttrss_user_entries.feed_id = ttrss_feeds.id".
+ " AND ttrss_user_entries.ref_id = ttrss_entries.id".
+ " AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"].
+ " GROUP BY ttrss_feeds.title");
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $unread = getFeedUnread($link, $line["id"]);
+
+ $row = array(
+ "id" => (int)$line["id"],
+ "title" => $line["title"],
+ "first" => (int)$line["first"],
+ "last" => (int)$line["last"],
+ "total" => (int)$line["total"],
+ "unread" => (int)$unread
+ );
+
+ array_push($feeds, $row);
+ }
+
+ return $feeds;
+}
+
static function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) {
$feeds = array();