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;
exit;
}
- if (!$op) {
- print_error_xml(7); exit;
- }
-
$purge_intervals = array(
0 => "Use default",
-1 => "Never purge",
}
}
+ 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);
?>
+<?php if ($op != "getUnread") { ?>
<!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
-
+<?php } ?>
/* 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;
}