From 0ee2d12f1fc5135abeb5363b372c9b77e81c78a7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 12 Dec 2005 05:58:38 +0100 Subject: [PATCH] adaptive view mode --- backend.php | 47 +++++++++++++++++++++++++++++++++++++++++++++-- tt-rss.php | 5 ++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/backend.php b/backend.php index 790a016cb..b87c6cf31 100644 --- a/backend.php +++ b/backend.php @@ -62,6 +62,40 @@ getGlobalCounters($link); } + function getFeedUnread($link, $feed) { + $n_feed = sprintf("%d", $feed); + + if ($n_feed == -1) { + $match_part = "marked = true"; + } else if ($feed > 0) { + $match_part = "feed_id = '$n_feed'"; + } else if ($feed < -10) { + $label_id = -$feed - 11; + + $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE + id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); + + $match_part = db_fetch_result($result, 0, "sql_exp"); + } + + if ($match_part) { + + $result = db_query($link, "SELECT count(int_id) AS unread + FROM ttrss_user_entries + WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); + + } else { + + $result = db_query($link, "SELECT COUNT(post_int_id) AS unread + FROM ttrss_tags,ttrss_user_entries + WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND + ttrss_tags.owner_uid = " . $_SESSION["uid"]); + } + + $unread = db_fetch_result($result, 0, "unread"); + return $unread; + } + /* FIXME this needs reworking */ function getGlobalCounters($link) { @@ -911,6 +945,15 @@ $view_query_part = ""; + if ($view_mode == "Adaptive") { + if ($feed != -1) { + $unread = getFeedUnread($link, $feed); + if ($unread > 0) { + $view_query_part = " unread = true AND "; + } + } + } + if ($view_mode == "Starred") { $view_query_part = " marked = true AND "; } @@ -919,13 +962,13 @@ $view_query_part = " unread = true AND "; } - if ($view_mode == "Unread or Starred") { +/* if ($view_mode == "Unread or Starred") { $view_query_part = " (unread = true OR marked = true) AND "; } if ($view_mode == "Unread or Updated") { $view_query_part = " (unread = true OR last_read is NULL) AND "; - } + } */ /* $result = db_query($link, "SELECT count(id) AS total_entries FROM ttrss_entries WHERE diff --git a/tt-rss.php b/tt-rss.php index 5c15a507b..f76614c2e 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -136,11 +136,10 @@  View:  Limit: