if ($subop == "download") {
$stage = (int) $_REQUEST["stage"];
+ $amount = (int) $_REQUEST["amount"];
+ $unread_only = db_escape_string($_REQUEST["unread_only"]);
+
+ if (!$amount) $amount = 50;
print "<rpc-reply>";
}
+ if ($stage > 0) {
+
+ print "<articles>";
+
+ $limit = 50;
+ $skip = $limit*($stage-1);
+
+ if ($amount > 0) $amount -= $skip;
+
+ if ($amount > 0) {
+
+ $limit = min($limit, $amount);
+
+ if ($unread_only) {
+ $unread_qpart = "unread = true AND ";
+ }
+
+ $result = db_query($link,
+ "SELECT DISTINCT id,title,guid,link,
+ feed_id,content,updated,unread,marked FROM
+ ttrss_user_entries,ttrss_entries
+ WHERE $unread_qpart
+ ref_id = id AND owner_uid = ".$_SESSION["uid"]."
+ ORDER BY updated DESC LIMIT $limit OFFSET $skip");
+
+ while ($line = db_fetch_assoc($result)) {
+ print "<article><![CDATA[";
+ print json_encode($line);
+ print "]]></article>";
+ }
+
+ }
+
+ print "</articles>";
+
+ }
+
print "</rpc-reply>";
return;
db.execute("CREATE TABLE if not exists offline_feeds (id integer, title text)");
- db.execute("CREATE TABLE if not exists offline_data (id integer, feed_id integer, title text, updated text, content text, tags text)");
+ db.execute("CREATE TABLE if not exists offline_data (id integer, feed_id integer, title text, link text, guid text, updated text, content text, tags text)");
var qmcDownload = document.getElementById("qmcDownload");
if (qmcDownload) Element.show(qmcDownload);
}
window.setTimeout("initiate_offline_download("+(stage+1)+")", 50);
- }
+ } else {
- notify_info("All done.");
+ var articles = transport.responseXML.getElementsByTagName("article");
- }
- } catch (e) {
- exception_error("offline_download_parse", e);
- }
-}
+ var articles_found = 0;
-function download_set_progress(p) {
- try {
- var o = document.getElementById("d_progress_i");
+ for (var i = 0; i < articles.length; i++) {
+ var a = eval("("+articles[i].firstChild.nodeValue+")");
+ articles_found++;
+ if (a) {
+ db.execute("DELETE FROM offline_data WHERE id = ?", [a.id]);
+ db.execute("INSERT INTO offline_data "+
+ "(id, feed_id, title, link, guid, updated, content) "+
+ "VALUES (?, ?, ?, ?, ?, ?, ?)",
+ [a.id, a.feed_id, a.title, a.link, a.guid, a.updated, a.content]);
- if (!o) return;
+ }
+ }
- Element.show(o);
+ if (articles_found > 0) {
+ window.setTimeout("initiate_offline_download("+(stage+1)+")", 50);
+ }
+ }
- new Effect.Scale(o, p, {
- scaleY : false,
- scaleFrom : download_progress_last,
- scaleMode: { originalWidth : 100 },
- queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
+ notify_info("All done.");
- download_progress_last = p;
+ }
} catch (e) {
- exception_error("download_progress", e);
+ exception_error("offline_download_parse", e);
}
}
if (!stage) stage = 0;
- notify_progress("Loading, please wait... S" + stage, true);
- download_set_progress(20);
+ notify_progress("Loading, please wait... (" + stage +")", true);
var query = "backend.php?op=rpc&subop=download&stage=" + stage;