}
if ($subop == "togglepref") {
- print "<rpc-reply>";
+ header("Content-Type: text/plain");
$key = db_escape_string($_REQUEST["key"]);
-
set_pref($link, $key, !get_pref($link, $key));
-
$value = get_pref($link, $key);
- print "<param-set key=\"$key\" value=\"$value\"/>";
-
- print "</rpc-reply>";
-
+ print json_encode(array("param" =>$key, "value" => $value));
return;
}
}
if ($subop == "mark") {
+ header("Content-Type: text/plain");
+
$mark = $_REQUEST["mark"];
$id = db_escape_string($_REQUEST["id"]);
$result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "delete") {
+ header("Content-Type: text/plain");
+
$ids = db_escape_string($_REQUEST["ids"]);
$result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "unarchive") {
+ header("Content-Type: text/plain");
+
$ids = db_escape_string($_REQUEST["ids"]);
$result = db_query($link, "UPDATE ttrss_user_entries
SET feed_id = orig_feed_id, orig_feed_id = NULL
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "archive") {
+ header("Content-Type: text/plain");
+
$ids = split(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
archive_article($link, $id, $_SESSION["uid"]);
}
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
return;
}
- if ($subop == "updateFeed") {
+/* if ($subop == "updateFeed") {
$feed_id = db_escape_string($_REQUEST["feed"]);
update_rss_feed($link, $feed_id);
print "</rpc-reply>";
return;
- }
+ } */
if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
if ($subop == "catchupSelected") {
+ header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
catchupArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "markSelected") {
+ header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
markArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "publishSelected") {
+ header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
publishArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<message>UPDATE_COUNTERS</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
}
if ($subop == "completeTags") {
+ header("Content-Type: text/plain");
$search = db_escape_string($_REQUEST["search"]);
$ids = split(",", db_escape_string($_REQUEST["ids"]));
$days = sprintf("%d", $_REQUEST["days"]);
- print "<rpc-reply>";
-
- print "<message><![CDATA[";
-
foreach ($ids as $id) {
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
id = '$id' AND owner_uid = ".$_SESSION["uid"]);
if (db_num_rows($result) == 1) {
- purge_feed($link, $id, $days, true);
+ purge_feed($link, $id, $days);
}
}
- print "]]></message>";
-
- print "</rpc-reply>";
-
return;
}
}
if ($subop == "cdmGetArticle") {
+ header("Content-Type: text/plain");
+
$id = db_escape_string($_REQUEST["id"]);
$result = db_query($link, "SELECT content,
$article_content = '';
}
- print "<rpc-reply><article id=\"$id\"><![CDATA[";
- print "$article_content";
- print "]]></article></rpc-reply>";
+ print json_encode(array("article" =>
+ array("id" => $id, "content" => $article_content)));
return;
}
if ($subop == "scheduleFeedUpdate") {
+ header("Content-Type: text/plain");
+
$feed_id = db_escape_string($_REQUEST["id"]);
$is_cat = db_escape_string($_REQUEST['is_cat']) == 'true';
$message = __("Can't update this kind of feed.");
}
- print "<rpc-reply>";
- print "<message>$message</message>";
- print "</rpc-reply>";
-
+ print json_encode(array("message" => $message));
return;
}
var cache_added = [];
-function catchup_callback2(transport, callback) {
- try {
- console.log("catchup_callback2 " + transport + ", " + callback);
- notify("");
- handle_rpc_reply(transport);
- if (callback) {
- setTimeout(callback, 10);
- }
- } catch (e) {
- exception_error("catchup_callback2", e, transport);
- }
-}
-
function headlines_callback2(transport, feed_cur_page) {
try {
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- handle_rpc_reply(transport);
+ handle_rpc_json(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- handle_rpc_reply(transport);
+ handle_rpc_json(transport);
} });
}
}
}
-function selectionToggleUnread(set_state, callback_func, no_error) {
+function selectionToggleUnread(set_state, callback, no_error) {
try {
var rows = getSelectedArticleIds2();
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- catchup_callback2(transport, callback_func);
+ handle_rpc_json(transport);
+ if (callback) callback(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- handle_rpc_reply(transport);
+ handle_rpc_json(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- handle_rpc_reply(transport);
+ handle_rpc_json(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
+ handle_rpc_json(transport);
viewCurrentFeed();
} });
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
+ handle_rpc_json(transport);
viewCurrentFeed();
} });
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- handle_rpc_reply(transport);
+ handle_rpc_json(transport);
} });
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- catchup_callback2(transport);
+ handle_rpc_json(transport);
} });
}
onComplete: function(transport) {
$("FUPDPIC-" + id).src = 'images/blank_icon.gif';
- if (transport.responseXML) {
- var article = transport.responseXML.getElementsByTagName("article")[0];
- var recv_id = article.getAttribute("id");
+ handle_rpc_json(transport);
+
+ var reply = JSON.parse(transport.responseText);
+
+ if (reply) {
+ var article = reply['article']['content'];
+ var recv_id = reply['article']['id'];
if (recv_id == id)
- $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue;
+ $("CWRAP-" + id).innerHTML = article;
} else {
$("CWRAP-" + id).innerHTML = __("Unable to load article.");