diff --git a/backend.php b/backend.php index 7903dcf5..71b7d457 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(\"\"); "; diff --git a/functions.js b/functions.js index 4e758a7d..0db4ea30 100644 --- a/functions.js +++ b/functions.js @@ -278,3 +278,57 @@ function getActiveFeedId() { function setActiveFeedId(id) { return setCookie("ttrss_vf_actfeed", id); } + +var xmlhttp_rpc = false; + +/*@cc_on @*/ +/*@if (@_jscript_version >= 5) +// JScript gives us Conditional compilation, we can cope with old IE versions. +// and security blocked creation of the objects. +try { + xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); +} catch (e) { + try { + xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (E) { + xmlhttp_rpc = false; + } +} +@end @*/ + +if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') { + xmlhttp_rpc = new XMLHttpRequest(); +} + +function label_counters_callback() { + if (xmlhttp_rpc.readyState == 4) { + var reply = xmlhttp_rpc.responseXML.firstChild; + + var f_document = parent.frames["feeds-frame"].document; + + for (var l = 0; l < reply.childNodes.length; l++) { + var id = reply.childNodes[l].getAttribute("id"); + var ctr = reply.childNodes[l].getAttribute("counter"); + + var feedctr = f_document.getElementById("FEEDCTR-" + id); + var feedu = f_document.getElementById("FEEDU-" + id); + + feedu.innerHTML = ctr; + + if (ctr > 0) { + feedctr.className = "odd"; + } else { + feedctr.className = "invisible"; + } + } + } +} + +function update_label_counters() { + if (xmlhttp_ready(xmlhttp_rpc)) { + var query = "backend.php?op=rpc&subop=getLabelCounters"; + xmlhttp_rpc.open("GET", query, true); + xmlhttp_rpc.onreadystatechange=label_counters_callback; + xmlhttp_rpc.send(null); + } +} diff --git a/tt-rss.js b/tt-rss.js index 4f532d60..d1bcad69 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -49,17 +49,37 @@ function feedlist_callback() { */ function refetch_callback() { - if (xmlhttp.readyState == 4) { document.title = "Tiny Tiny RSS"; notify("All feeds updated."); - updateFeedList(); - - } -} + var reply = xmlhttp.responseXML.firstChild; + var f_document = window.frames["feeds-frame"].document; + + for (var l = 0; l < reply.childNodes.length; l++) { + var id = reply.childNodes[l].getAttribute("id"); + var ctr = reply.childNodes[l].getAttribute("counter"); + + var feedctr = f_document.getElementById("FEEDCTR-" + id); + var feedu = f_document.getElementById("FEEDU-" + id); + var feedr = f_document.getElementById("FEEDR-" + id); + + feedu.innerHTML = ctr; + + if (ctr > 0) { + feedctr.className = "odd"; + if (id > 0 && !feedr.className.match("Unread")) { + feedr.className = feedr.className + "Unread"; + } + } else { + feedctr.className = "invisible"; + feedr.className = feedr.className.replace("Unread", ""); + } + } + } +} function updateFeed(feed_id) { diff --git a/view.js b/view.js new file mode 100644 index 00000000..6450a0b7 --- /dev/null +++ b/view.js @@ -0,0 +1,53 @@ +var xmlhttp_rpc = false; + +/*@cc_on @*/ +/*@if (@_jscript_version >= 5) +// JScript gives us Conditional compilation, we can cope with old IE versions. +// and security blocked creation of the objects. +try { + xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); +} catch (e) { + try { + xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (E) { + xmlhttp_rpc = false; + } +} +@end @*/ + +if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') { + xmlhttp_rpc = new XMLHttpRequest(); +} + +function label_counters_callback() { + if (xmlhttp_rpc.readyState == 4) { + var reply = xmlhttp_rpc.responseXML.firstChild; + + var f_document = parent.frames["feeds-frame"].document; + + for (var l = 0; l < reply.childNodes.length; l++) { + var id = reply.childNodes[l].getAttribute("id"); + var ctr = reply.childNodes[l].getAttribute("counter"); + + var feedctr = f_document.getElementById("FEEDCTR-" + id); + var feedu = f_document.getElementById("FEEDU-" + id); + + feedu.innerHTML = ctr; + + if (ctr > 0) { + feedctr.className = "odd"; + } else { + feedctr.className = "invisible"; + } + } + } +} + +function update_label_counters() { + if (xmlhttp_ready(xmlhttp_rpc)) { + var query = "backend.php?op=rpc&subop=getLabelCounters"; + xmlhttp_rpc.open("GET", query, true); + xmlhttp_rpc.onreadystatechange=label_counters_callback; + xmlhttp_rpc.send(null); + } +} diff --git a/viewfeed.js b/viewfeed.js index 5bcb3812..4bded276 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -8,7 +8,7 @@ var xmlhttp_rpc = false; // JScript gives us Conditional compilation, we can cope with old IE versions. // and security blocked creation of the objects. try { - xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); + xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); @@ -26,23 +26,25 @@ function view(id, feed_id) { // p_notify("Loading article..."); + var f_document = parent.frames["feeds-frame"].document; + var h_document = document; + var m_document = parent.document; + enableHotkeys(); - var crow = document.getElementById("RROW-" + id); - - var f_doc = parent.frames["feeds-frame"].document; + var crow = h_document.getElementById("RROW-" + id); if (crow.className.match("Unread")) { - var umark = f_doc.getElementById("FEEDU-" + feed_id); + var umark = f_document.getElementById("FEEDU-" + feed_id); umark.innerHTML = umark.innerHTML - 1; crow.className = crow.className.replace("Unread", ""); if (umark.innerHTML == "0") { - var feedr = f_doc.getElementById("FEEDR-" + feed_id); + var feedr = f_document.getElementById("FEEDR-" + feed_id); feedr.className = feedr.className.replace("Unread", ""); - var feedctr = f_doc.getElementById("FEEDCTR-" + feed_id); + var feedctr = f_document.getElementById("FEEDCTR-" + feed_id); if (feedctr) { feedctr.className = "invisible"; @@ -55,7 +57,7 @@ function view(id, feed_id) { cleanSelected("headlinesList"); - var upd_img_pic = document.getElementById("FUPDPIC-" + id); + var upd_img_pic = h_document.getElementById("FUPDPIC-" + id); if (upd_img_pic) { upd_img_pic.src = "images/blank_icon.gif"; @@ -64,7 +66,7 @@ function view(id, feed_id) { var unread_rows = getVisibleUnreadHeadlines(); if (unread_rows.length == 0) { - var button = document.getElementById("btnCatchupPage"); + var button = h_document.getElementById("btnCatchupPage"); if (button) { button.className = "disabledButton"; button.href = ""; @@ -74,17 +76,20 @@ function view(id, feed_id) { active_post_id = id; setActiveFeedId(feed_id); - var content = parent.document.getElementById("content-frame"); + var content = m_document.getElementById("content-frame"); if (content) { content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id); markHeadline(active_post_id); } + } function toggleMark(id, toggle) { + var f_document = parent.frames["feeds-frame"].document; + if (!xmlhttp_ready(xmlhttp_rpc)) { printLockingError(); return; @@ -94,9 +99,9 @@ function toggleMark(id, toggle) { var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; - var f_doc = parent.frames["feeds-frame"].document; + var vfeedu = f_document.getElementById("FEEDU--1"); - var vfeedu = f_doc.getElementById("FEEDU--1"); +// alert(vfeedu); if (toggle == true) { mark_img.src = "images/mark_set.png"; @@ -116,7 +121,7 @@ function toggleMark(id, toggle) { } - var vfeedctr = f_doc.getElementById("FEEDCTR--1"); + var vfeedctr = f_document.getElementById("FEEDCTR--1"); if (vfeedu && vfeedctr) { if ((+vfeedu.innerHTML) > 0) {