From 090e250b6905ecbc078cdc2f485f343a1d3a7bfc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 8 Sep 2005 13:10:07 +0100 Subject: automagically updating labels with cute XML RPC --- backend.php | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 12 deletions(-) (limited to 'backend.php') diff --git a/backend.php b/backend.php index 7903dcf55..71b7d4574 100644 --- a/backend.php +++ b/backend.php @@ -1,5 +1,9 @@ "; + + $result = db_query($link, "SELECT id,sql_exp,description FROM + ttrss_labels ORDER by description"); + + while ($line = db_fetch_assoc($result)) { + + $id = -$line["id"] - 11; + + error_reporting (0); + + $tmp_result = pg_query("SELECT count(id) as count FROM ttrss_entries + WHERE " . $line["sql_exp"]); + + $count = pg_fetch_result($tmp_result, 0, "count"); + + print ""; + + error_reporting (E_ERROR | E_WARNING | E_PARSE); + + } + } + + function getFeedCounters($link) { + + $result = db_query($link, "SELECT id, + (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id + AND unread = true) as count + FROM ttrss_feeds"); + + while ($line = db_fetch_assoc($result)) { + + $id = $line["id"]; + $count = $line["count"]; + + print ""; + } + } + function outputFeedList($link) { print " @@ -37,7 +86,7 @@ if (ENABLE_LABELS) { - $result = db_query($link, "SELECT id,description FROM + $result = db_query($link, "SELECT id,sql_exp,description FROM ttrss_labels ORDER by description"); if (db_num_rows($result) > 0) { @@ -45,9 +94,18 @@ } while ($line = db_fetch_assoc($result)) { + + error_reporting (0); + $tmp_result = pg_query("SELECT count(id) as count FROM ttrss_entries + WHERE " . $line["sql_exp"]); + + $count = pg_fetch_result($tmp_result, 0, "count"); + + error_reporting (E_ERROR | E_WARNING | E_PARSE); + printFeedEntry(-$line["id"]-11, - "odd", $line["description"], 0, "images/label.png"); + "odd", $line["description"], $count, "images/label.png"); } } @@ -107,6 +165,26 @@ $subop = $_GET["subop"]; + if ($subop == "getLabelCounters") { + print ""; + getLabelCounters($link); + print ""; + } + + if ($subop == "getFeedCounters") { + print ""; + getFeedCounters($link); + print ""; + } + + if ($subop == "getAllCounters") { + print ""; + getLabelCounters($link); + getFeedCounters($link); + print ""; + + } + if ($subop == "mark") { $mark = $_GET["mark"]; $id = db_escape_string($_GET["id"]); @@ -137,12 +215,13 @@ return; } - if ($subop == "forceUpdateAllFeeds") { + if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { update_all_feeds($link, true); - } - if ($subop == "updateAllFeeds") { - update_all_feeds($link, false); + print ""; + getLabelCounters($link); + getFeedCounters($link); + print ""; } if ($subop == "catchupPage") { @@ -158,7 +237,6 @@ print "Marked active page as read."; } - } if ($op == "feeds") { @@ -230,6 +308,9 @@ print ""; + print ""; } if ($addheader) { @@ -463,9 +544,18 @@ } else { // print "[viewfeed] feed type not implemented
"; - $unread = 0; + + error_reporting(0); + $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries + WHERE $query_strategy_part"); + + $unread = db_fetch_result($result, 0, "unread"); + + error_reporting (E_ERROR | E_WARNING | E_PARSE); } + if (!$unread) $unread = 0; + // update unread/total counters and status for active feed in the feedlist // kludge, because iframe doesn't seem to support onload() @@ -483,7 +573,7 @@ var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed); - if ($unread > 0 && $feed != -1 && !feedr.className.match(\"Unread\")) { + if ($unread > 0 && $feed >= 0 && !feedr.className.match(\"Unread\")) { feedr.className = feedr.className + \"Unread\"; feedctr.className = ''; } else if ($unread <= 0) { @@ -491,6 +581,8 @@ feedctr.className = 'invisible'; } + update_label_counters(); + // p_notify(\"\"); "; -- cgit v1.2.3-54-g00ecf