aboutsummaryrefslogtreecommitdiff
path: root/p/api/greader.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-03-03 22:10:46 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-03-03 22:10:46 +0100
commit75ce6a55bdecb2b669267c7e674b89e63c20d6ad (patch)
tree3ffc1b2c6152da8887fc436ef0d80f6965cb3185 /p/api/greader.php
parentff8fd9565413d8b690e0027bd6a091d8e74165b1 (diff)
API: better unread-count
https://github.com/marienfressinaud/FreshRSS/issues/443 For e.g. EasyRSS
Diffstat (limited to 'p/api/greader.php')
-rw-r--r--p/api/greader.php44
1 files changed, 24 insertions, 20 deletions
diff --git a/p/api/greader.php b/p/api/greader.php
index b1ed34d27..ab2a210a2 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -249,30 +249,36 @@ function subscriptionList() {
exit();
}
-function unreadCount() {
+function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count
logMe("unreadCount()\n");
header('Content-Type: application/json; charset=UTF-8');
- $pdo = new MyPDO();
- $stm = $pdo->prepare('SELECT f.id, f.lastUpdate, f.cache_nbUnreads FROM `%_feed` f');
- $stm->execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
-
- $unreadcounts = array();
$totalUnreads = 0;
$totalLastUpdate = 0;
- foreach ($res as $line) {
- $nbUnreads = $line['cache_nbUnreads'];
- $totalUnreads += $nbUnreads;
- $lastUpdate = $line['lastUpdate'];
- if ($totalLastUpdate < $lastUpdate) {
- $totalLastUpdate = $lastUpdate;
+
+ $categoryDAO = new FreshRSS_CategoryDAO();
+ foreach ($categoryDAO->listCategories(true, true) as $cat) {
+ $catLastUpdate = 0;
+ foreach ($cat->feeds() as $feed) {
+ $lastUpdate = $feed->lastUpdate();
+ $unreadcounts[] = array(
+ 'id' => 'feed/' . $feed->id(),
+ 'count' => $feed->nbNotRead(),
+ 'newestItemTimestampUsec' => $lastUpdate . '000000',
+ );
+ if ($catLastUpdate < $lastUpdate) {
+ $catLastUpdate = $lastUpdate;
+ }
}
$unreadcounts[] = array(
- 'id' => 'feed/' . $line['id'],
- 'count' => $nbUnreads,
- 'newestItemTimestampUsec' => $lastUpdate . '000000',
+ 'id' => 'user/-/label/' . $cat->name(),
+ 'count' => $cat->nbNotRead(),
+ 'newestItemTimestampUsec' => $catLastUpdate . '000000',
);
+ $totalUnreads += $cat->nbNotRead();
+ if ($totalLastUpdate < $catLastUpdate) {
+ $totalLastUpdate = $catLastUpdate;
+ }
}
$unreadcounts[] = array(
@@ -288,8 +294,7 @@ function unreadCount() {
exit();
}
-function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)
-{//http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
+function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
logMe('streamContents(' . $include_target . ")\n");
header('Content-Type: application/json; charset=UTF-8');
@@ -392,8 +397,7 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex
exit();
}
-function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)
-{//http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
+function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target) { //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
logMe('streamContentsItemsIds(' . $streamId . ")\n");
$type = 'A';