From f3acc32e569294b36e73831fa9ed550d6021f4a6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 20 Aug 2006 04:35:47 +0100 Subject: [PATCH] add simple op=getUnread call to return global unread counter --- backend.php | 29 +++++++++++++++++++++++------ functions.php | 9 +++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/backend.php b/backend.php index 1b530ac5..36fe3253 100644 --- a/backend.php +++ b/backend.php @@ -37,7 +37,12 @@ header("Content-Type: application/xml"); } - if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss") { + if (!$op) { + header("Content-Type: application/xml"); + print_error_xml(7); exit; + } + + if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") { if ($op == "rpc") { print_error_xml(6); die; @@ -58,10 +63,6 @@ exit; } - if (!$op) { - print_error_xml(7); exit; - } - $purge_intervals = array( 0 => "Use default", -1 => "Never purge", @@ -3872,8 +3873,24 @@ } } + if ($op == "getUnread") { + $login = db_escape_string($_GET["login"]); + + header("Content-Type: text/plain"); + + $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); + + if (db_num_rows($result) == 1) { + $uid = db_fetch_result($result, 0, "id"); + print getGlobalUnread($link, $uid); + } else { + print "Error: user not found"; + } + } + db_close($link); ?> + - + diff --git a/functions.php b/functions.php index 2b6e53b3..5feba77f 100644 --- a/functions.php +++ b/functions.php @@ -1555,13 +1555,18 @@ /* FIXME this needs reworking */ - function getGlobalUnread($link) { + function getGlobalUnread($link, $user_id = false) { + + if (!$user_id) { + $user_id = $_SESSION["uid"]; + } + $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds WHERE unread = true AND ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND hidden = false AND - ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); + ttrss_user_entries.owner_uid = '$user_id'"); $c_id = db_fetch_result($result, 0, "c_id"); return $c_id; } -- 2.39.5