automagically updating labels with cute XML RPC
This commit is contained in:
parent
a82065a18b
commit
090e250b69
114
backend.php
114
backend.php
|
@ -1,5 +1,9 @@
|
||||||
<?
|
<?
|
||||||
// header("Content-Type: application/xml");
|
$op = $_GET["op"];
|
||||||
|
|
||||||
|
if ($op == "rpc") {
|
||||||
|
header("Content-Type: application/xml");
|
||||||
|
}
|
||||||
|
|
||||||
require_once "config.php";
|
require_once "config.php";
|
||||||
require_once "db.php";
|
require_once "db.php";
|
||||||
|
@ -12,9 +16,54 @@
|
||||||
pg_query("set client_encoding = 'utf-8'");
|
pg_query("set client_encoding = 'utf-8'");
|
||||||
}
|
}
|
||||||
|
|
||||||
$op = $_GET["op"];
|
|
||||||
$fetch = $_GET["fetch"];
|
$fetch = $_GET["fetch"];
|
||||||
|
|
||||||
|
function getLabelCounters($link) {
|
||||||
|
|
||||||
|
$result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
|
||||||
|
WHERE marked = true");
|
||||||
|
|
||||||
|
$count = pg_fetch_result($result, 0, "count");
|
||||||
|
|
||||||
|
print "<label id=\"-1\" counter=\"$count\"/>";
|
||||||
|
|
||||||
|
$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 "<feed id=\"$id\" counter=\"$count\"/>";
|
||||||
|
|
||||||
|
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 "<feed id=\"$id\" counter=\"$count\"/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function outputFeedList($link) {
|
function outputFeedList($link) {
|
||||||
|
|
||||||
print "<html><head>
|
print "<html><head>
|
||||||
|
@ -37,7 +86,7 @@
|
||||||
|
|
||||||
if (ENABLE_LABELS) {
|
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");
|
ttrss_labels ORDER by description");
|
||||||
|
|
||||||
if (db_num_rows($result) > 0) {
|
if (db_num_rows($result) > 0) {
|
||||||
|
@ -46,8 +95,17 @@
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
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,
|
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"];
|
$subop = $_GET["subop"];
|
||||||
|
|
||||||
|
if ($subop == "getLabelCounters") {
|
||||||
|
print "<rpc-reply>";
|
||||||
|
getLabelCounters($link);
|
||||||
|
print "</rpc-reply>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subop == "getFeedCounters") {
|
||||||
|
print "<rpc-reply>";
|
||||||
|
getFeedCounters($link);
|
||||||
|
print "</rpc-reply>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subop == "getAllCounters") {
|
||||||
|
print "<rpc-reply>";
|
||||||
|
getLabelCounters($link);
|
||||||
|
getFeedCounters($link);
|
||||||
|
print "</rpc-reply>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if ($subop == "mark") {
|
if ($subop == "mark") {
|
||||||
$mark = $_GET["mark"];
|
$mark = $_GET["mark"];
|
||||||
$id = db_escape_string($_GET["id"]);
|
$id = db_escape_string($_GET["id"]);
|
||||||
|
@ -137,12 +215,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subop == "forceUpdateAllFeeds") {
|
if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
|
||||||
update_all_feeds($link, true);
|
update_all_feeds($link, true);
|
||||||
}
|
|
||||||
|
|
||||||
if ($subop == "updateAllFeeds") {
|
print "<rpc-reply>";
|
||||||
update_all_feeds($link, false);
|
getLabelCounters($link);
|
||||||
|
getFeedCounters($link);
|
||||||
|
print "</rpc-reply>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subop == "catchupPage") {
|
if ($subop == "catchupPage") {
|
||||||
|
@ -158,7 +237,6 @@
|
||||||
|
|
||||||
print "Marked active page as read.";
|
print "Marked active page as read.";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($op == "feeds") {
|
if ($op == "feeds") {
|
||||||
|
@ -230,6 +308,9 @@
|
||||||
|
|
||||||
print "</div>";
|
print "</div>";
|
||||||
|
|
||||||
|
print "<script type=\"text/javascript\">
|
||||||
|
update_label_counters();
|
||||||
|
</script>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addheader) {
|
if ($addheader) {
|
||||||
|
@ -463,9 +544,18 @@
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// print "[viewfeed] feed type not implemented<br>";
|
// print "[viewfeed] feed type not implemented<br>";
|
||||||
$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
|
// update unread/total counters and status for active feed in the feedlist
|
||||||
// kludge, because iframe doesn't seem to support onload()
|
// kludge, because iframe doesn't seem to support onload()
|
||||||
|
|
||||||
|
@ -483,7 +573,7 @@
|
||||||
|
|
||||||
var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
|
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\";
|
feedr.className = feedr.className + \"Unread\";
|
||||||
feedctr.className = '';
|
feedctr.className = '';
|
||||||
} else if ($unread <= 0) {
|
} else if ($unread <= 0) {
|
||||||
|
@ -491,6 +581,8 @@
|
||||||
feedctr.className = 'invisible';
|
feedctr.className = 'invisible';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_label_counters();
|
||||||
|
|
||||||
// p_notify(\"\");
|
// p_notify(\"\");
|
||||||
|
|
||||||
</script>";
|
</script>";
|
||||||
|
|
54
functions.js
54
functions.js
|
@ -278,3 +278,57 @@ function getActiveFeedId() {
|
||||||
function setActiveFeedId(id) {
|
function setActiveFeedId(id) {
|
||||||
return setCookie("ttrss_vf_actfeed", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
tt-rss.js
26
tt-rss.js
|
@ -49,18 +49,38 @@ function feedlist_callback() {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function refetch_callback() {
|
function refetch_callback() {
|
||||||
|
|
||||||
if (xmlhttp.readyState == 4) {
|
if (xmlhttp.readyState == 4) {
|
||||||
|
|
||||||
document.title = "Tiny Tiny RSS";
|
document.title = "Tiny Tiny RSS";
|
||||||
notify("All feeds updated.");
|
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) {
|
function updateFeed(feed_id) {
|
||||||
|
|
||||||
var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
|
var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
31
viewfeed.js
31
viewfeed.js
|
@ -8,7 +8,7 @@ var xmlhttp_rpc = false;
|
||||||
// JScript gives us Conditional compilation, we can cope with old IE versions.
|
// JScript gives us Conditional compilation, we can cope with old IE versions.
|
||||||
// and security blocked creation of the objects.
|
// and security blocked creation of the objects.
|
||||||
try {
|
try {
|
||||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
|
xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
|
@ -26,23 +26,25 @@ function view(id, feed_id) {
|
||||||
|
|
||||||
// p_notify("Loading article...");
|
// p_notify("Loading article...");
|
||||||
|
|
||||||
|
var f_document = parent.frames["feeds-frame"].document;
|
||||||
|
var h_document = document;
|
||||||
|
var m_document = parent.document;
|
||||||
|
|
||||||
enableHotkeys();
|
enableHotkeys();
|
||||||
|
|
||||||
var crow = document.getElementById("RROW-" + id);
|
var crow = h_document.getElementById("RROW-" + id);
|
||||||
|
|
||||||
var f_doc = parent.frames["feeds-frame"].document;
|
|
||||||
|
|
||||||
if (crow.className.match("Unread")) {
|
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;
|
umark.innerHTML = umark.innerHTML - 1;
|
||||||
crow.className = crow.className.replace("Unread", "");
|
crow.className = crow.className.replace("Unread", "");
|
||||||
|
|
||||||
if (umark.innerHTML == "0") {
|
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", "");
|
feedr.className = feedr.className.replace("Unread", "");
|
||||||
|
|
||||||
var feedctr = f_doc.getElementById("FEEDCTR-" + feed_id);
|
var feedctr = f_document.getElementById("FEEDCTR-" + feed_id);
|
||||||
|
|
||||||
if (feedctr) {
|
if (feedctr) {
|
||||||
feedctr.className = "invisible";
|
feedctr.className = "invisible";
|
||||||
|
@ -55,7 +57,7 @@ function view(id, feed_id) {
|
||||||
|
|
||||||
cleanSelected("headlinesList");
|
cleanSelected("headlinesList");
|
||||||
|
|
||||||
var upd_img_pic = document.getElementById("FUPDPIC-" + id);
|
var upd_img_pic = h_document.getElementById("FUPDPIC-" + id);
|
||||||
|
|
||||||
if (upd_img_pic) {
|
if (upd_img_pic) {
|
||||||
upd_img_pic.src = "images/blank_icon.gif";
|
upd_img_pic.src = "images/blank_icon.gif";
|
||||||
|
@ -64,7 +66,7 @@ function view(id, feed_id) {
|
||||||
var unread_rows = getVisibleUnreadHeadlines();
|
var unread_rows = getVisibleUnreadHeadlines();
|
||||||
|
|
||||||
if (unread_rows.length == 0) {
|
if (unread_rows.length == 0) {
|
||||||
var button = document.getElementById("btnCatchupPage");
|
var button = h_document.getElementById("btnCatchupPage");
|
||||||
if (button) {
|
if (button) {
|
||||||
button.className = "disabledButton";
|
button.className = "disabledButton";
|
||||||
button.href = "";
|
button.href = "";
|
||||||
|
@ -74,17 +76,20 @@ function view(id, feed_id) {
|
||||||
active_post_id = id;
|
active_post_id = id;
|
||||||
setActiveFeedId(feed_id);
|
setActiveFeedId(feed_id);
|
||||||
|
|
||||||
var content = parent.document.getElementById("content-frame");
|
var content = m_document.getElementById("content-frame");
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id);
|
content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id);
|
||||||
markHeadline(active_post_id);
|
markHeadline(active_post_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toggleMark(id, toggle) {
|
function toggleMark(id, toggle) {
|
||||||
|
|
||||||
|
var f_document = parent.frames["feeds-frame"].document;
|
||||||
|
|
||||||
if (!xmlhttp_ready(xmlhttp_rpc)) {
|
if (!xmlhttp_ready(xmlhttp_rpc)) {
|
||||||
printLockingError();
|
printLockingError();
|
||||||
return;
|
return;
|
||||||
|
@ -94,9 +99,9 @@ function toggleMark(id, toggle) {
|
||||||
|
|
||||||
var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
|
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) {
|
if (toggle == true) {
|
||||||
mark_img.src = "images/mark_set.png";
|
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 && vfeedctr) {
|
||||||
if ((+vfeedu.innerHTML) > 0) {
|
if ((+vfeedu.innerHTML) > 0) {
|
||||||
|
|
Loading…
Reference in New Issue