2009-02-04 12:15:58 +01:00
|
|
|
var SCHEMA_VERSION = 3;
|
2009-02-04 11:53:25 +01:00
|
|
|
|
2009-02-04 11:36:06 +01:00
|
|
|
var offline_mode = false;
|
|
|
|
var store = false;
|
|
|
|
var localServer = false;
|
|
|
|
var db = false;
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
function view_offline(id, feed_id) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
enableHotkeys();
|
|
|
|
showArticleInHeadlines(id);
|
|
|
|
|
2009-02-04 08:37:48 +01:00
|
|
|
db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
|
|
|
|
|
|
|
|
var rs = db.execute("SELECT * FROM articles WHERE id = ?", [id]);
|
|
|
|
|
|
|
|
if (rs.isValidRow()) {
|
|
|
|
|
|
|
|
var tmp = "<div class=\"postReply\">";
|
|
|
|
|
|
|
|
tmp += "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" "+
|
|
|
|
"onmouseout=\"enable_resize(false)\">";
|
|
|
|
|
|
|
|
tmp += "<div class=\"postDate\">"+rs.fieldByName("updated")+"</div>";
|
|
|
|
|
|
|
|
if (rs.fieldByName("link") != "") {
|
|
|
|
tmp += "<div clear='both'><a target=\"_blank\" "+
|
|
|
|
"href=\"" + rs.fieldByName("link") + "\">" +
|
|
|
|
rs.fieldByName("title") + "</a></div>";
|
|
|
|
} else {
|
|
|
|
tmp += "<div clear='both'>" + rs.fieldByName("title") + "</div>";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 08:37:48 +01:00
|
|
|
tmp += "<div style='float : right'> "+
|
|
|
|
"<img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>";
|
|
|
|
tmp += rs.fieldByName("tags");
|
|
|
|
tmp += "</div>";
|
|
|
|
|
2009-02-04 12:23:02 +01:00
|
|
|
tmp += "<div clear='both'>"+
|
|
|
|
"<a target=\"_blank\" "+
|
|
|
|
"href=\"" + rs.fieldByName("comments") + "\">" +
|
|
|
|
__("comments") + "</a></div>";
|
2009-02-04 08:37:48 +01:00
|
|
|
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
tmp += "<div class=\"postContent\">"
|
|
|
|
tmp += rs.fieldByName("content");
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
render_article(tmp);
|
|
|
|
update_local_feedlist_counters();
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("view_offline", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function viewfeed_offline(feed_id, subop, is_cat, subop_param, skip_history, offset) {
|
|
|
|
try {
|
|
|
|
notify('');
|
|
|
|
|
|
|
|
if (!offset) offset = 0;
|
|
|
|
|
2009-02-04 12:47:09 +01:00
|
|
|
if (offset > 0) {
|
|
|
|
_feed_cur_page = parseInt(offset);
|
|
|
|
if (_infscroll_request_sent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_feed_cur_page = 0;
|
|
|
|
_infscroll_disable = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getActiveFeedId() != feed_id) {
|
|
|
|
_feed_cur_page = 0;
|
|
|
|
active_post_id = 0;
|
|
|
|
_infscroll_disable = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
loading_set_progress(100);
|
|
|
|
|
|
|
|
clean_feed_selections();
|
|
|
|
|
|
|
|
setActiveFeedId(feed_id, is_cat);
|
|
|
|
|
|
|
|
if (!is_cat) {
|
|
|
|
var feedr = document.getElementById("FEEDR-" + feed_id);
|
|
|
|
if (feedr && !feedr.className.match("Selected")) {
|
|
|
|
feedr.className = feedr.className + "Selected";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var feedr = document.getElementById("FCAT-" + feed_id);
|
|
|
|
if (feedr && !feedr.className.match("Selected")) {
|
|
|
|
feedr.className = feedr.className + "Selected";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disableContainerChildren("headlinesToolbar", false);
|
|
|
|
Form.enable("main_toolbar_form");
|
|
|
|
|
|
|
|
var f = document.getElementById("headlines-frame");
|
|
|
|
try {
|
|
|
|
if (reply.offset == 0) {
|
|
|
|
debug("resetting headlines scrollTop");
|
|
|
|
f.scrollTop = 0;
|
|
|
|
}
|
|
|
|
} catch (e) { };
|
|
|
|
|
|
|
|
|
|
|
|
var tmp = "";
|
|
|
|
|
|
|
|
rs = db.execute("SELECT title FROM feeds WHERE id = ?", [feed_id]);
|
|
|
|
|
|
|
|
if (rs.isValidRow() || feed_id == -1 || feed_id == -4) {
|
|
|
|
|
|
|
|
feed_title = rs.field(0);
|
|
|
|
|
|
|
|
if (feed_id == -1) {
|
|
|
|
feed_title = __("Starred articles");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feed_id == -4) {
|
|
|
|
feed_title = __("All articles");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
tmp += "<div id=\"headlinesContainer\">";
|
|
|
|
|
|
|
|
tmp += "<div class=\"headlinesSubToolbar\">";
|
|
|
|
tmp += "<div id=\"subtoolbar_ftitle\">";
|
|
|
|
tmp += feed_title;
|
|
|
|
tmp += "</div>";
|
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
var sel_all_link;
|
|
|
|
var sel_unread_link;
|
|
|
|
var sel_none_link;
|
|
|
|
var sel_inv_link;
|
|
|
|
|
|
|
|
if (document.getElementById("content-frame")) {
|
|
|
|
sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
|
|
|
|
sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
|
|
|
|
sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
|
|
|
|
sel_inv_link = "javascript:invertHeadlineSelection()";
|
|
|
|
} else {
|
|
|
|
sel_all_link = "javascript:cdmSelectArticles('all')";
|
|
|
|
sel_unread_link = "javascript:cdmSelectArticles('unread')";
|
|
|
|
sel_none_link = "javascript:cdmSelectArticles('none')";
|
|
|
|
sel_inv_link = "javascript:invertHeadlineSelection()";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
tmp += __('Select:')+
|
|
|
|
" <a href=\""+sel_all_link+"\">"+__('All')+"</a>, "+
|
|
|
|
"<a href=\""+sel_unread_link+"\">"+__('Unread')+"</a>, "+
|
|
|
|
"<a href=\""+sel_inv_link+"\">"+__('Invert')+"</a>, "+
|
|
|
|
"<a href=\""+sel_none_link+"\">"+__('None')+"</a>";
|
|
|
|
|
|
|
|
tmp += " ";
|
|
|
|
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
tmp += "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
|
2009-02-04 13:42:59 +01:00
|
|
|
if (document.getElementById("content-frame")) {
|
|
|
|
tmp += "<table class=\"headlinesList\" id=\"headlinesList\" cellspacing=\"0\">";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var limit = 30;
|
|
|
|
|
|
|
|
var toolbar_form = document.forms["main_toolbar_form"];
|
|
|
|
|
|
|
|
var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex].value;
|
|
|
|
var view_mode = toolbar_form.view_mode[toolbar_form.view_mode.selectedIndex].value;
|
|
|
|
|
|
|
|
var limit_qpart = "";
|
|
|
|
var strategy_qpart = "";
|
|
|
|
var mode_qpart = "";
|
2009-02-04 12:33:43 +01:00
|
|
|
var offset_qpart = "";
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
if (limit != 0) {
|
|
|
|
limit_qpart = "LIMIT " + limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view_mode == "all_articles") {
|
|
|
|
mode_qpart = "1";
|
|
|
|
} else if (view_mode == "adaptive") {
|
|
|
|
if (get_local_feed_unread(feed_id) > 0) {
|
|
|
|
mode_qpart = "unread = 1";
|
|
|
|
} else {
|
|
|
|
mode_qpart = "1";
|
|
|
|
}
|
|
|
|
} else if (view_mode == "marked") {
|
|
|
|
mode_qpart = "marked = 1";
|
|
|
|
} else if (view_mode == "unread") {
|
|
|
|
mode_qpart = "unread = 1";
|
|
|
|
} else {
|
|
|
|
mode_qpart = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feed_id > 0) {
|
|
|
|
strategy_qpart = "feed_id = " + feed_id;
|
|
|
|
} else if (feed_id == -1) {
|
|
|
|
strategy_qpart = "marked = 1";
|
|
|
|
} else if (feed_id == -4) {
|
|
|
|
strategy_qpart = "1";
|
2009-02-04 12:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > 0) {
|
|
|
|
offset_qpart = "OFFSET " + (offset*30);
|
|
|
|
} else {
|
|
|
|
offset_qpart = "";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 21:13:21 +01:00
|
|
|
var query = "SELECT *,feeds.title AS feed_title "+
|
|
|
|
"FROM articles,feeds WHERE " +
|
|
|
|
"feed_id = feeds.id AND " +
|
2009-02-04 08:17:55 +01:00
|
|
|
strategy_qpart +
|
|
|
|
" AND " + mode_qpart +
|
|
|
|
" ORDER BY updated DESC "+
|
2009-02-04 12:33:43 +01:00
|
|
|
limit_qpart + " " +
|
|
|
|
offset_qpart;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
var rs = db.execute(query);
|
|
|
|
|
2009-02-04 12:33:43 +01:00
|
|
|
var line_num = offset*30;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 21:13:21 +01:00
|
|
|
var real_feed_id = feed_id;
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
while (rs.isValidRow()) {
|
|
|
|
|
|
|
|
var id = rs.fieldByName("id");
|
|
|
|
var feed_id = rs.fieldByName("feed_id");
|
|
|
|
|
2009-02-04 21:13:21 +01:00
|
|
|
var entry_feed_title = false;
|
|
|
|
|
|
|
|
if (real_feed_id < 0) {
|
|
|
|
entry_feed_title = rs.fieldByName("feed_title");
|
|
|
|
}
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
var marked_pic;
|
|
|
|
|
|
|
|
var row_class = (line_num % 2) ? "even" : "odd";
|
|
|
|
|
|
|
|
if (rs.fieldByName("unread") == "1") {
|
|
|
|
row_class += "Unread";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs.fieldByName("marked") == "1") {
|
|
|
|
marked_pic = "<img id=\"FMPIC-"+id+"\" "+
|
|
|
|
"src=\"images/mark_set.png\" class=\"markedPic\""+
|
|
|
|
"alt=\"Unstar article\" onclick='javascript:tMark("+id+")'>";
|
|
|
|
} else {
|
|
|
|
marked_pic = "<img id=\"FMPIC-"+id+"\" "+
|
|
|
|
"src=\"images/mark_unset.png\" class=\"markedPic\""+
|
|
|
|
"alt=\"Star article\" onclick='javascript:tMark("+id+")'>";
|
|
|
|
}
|
|
|
|
|
|
|
|
var mouseover_attrs = "onmouseover='postMouseIn($id)' "+
|
|
|
|
"onmouseout='postMouseOut($id)'";
|
2009-02-04 13:42:59 +01:00
|
|
|
|
|
|
|
var content_preview = truncate_string(strip_tags(rs.fieldByName("content")),
|
|
|
|
100);
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
if (document.getElementById("content-frame")) {
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "<tr class='"+row_class+"' id='RROW-"+id+"' "+mouseover_attrs+">";
|
|
|
|
|
|
|
|
tmp += "<td class='hlUpdPic'> </td>";
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "<td class='hlSelectRow'>"+
|
|
|
|
"<input type=\"checkbox\" onclick=\"tSR(this)\" id=\"RCHK-"+id+"\"></td>";
|
|
|
|
|
|
|
|
tmp += "<td class='hlMarkedPic'>"+marked_pic+"</td>";
|
|
|
|
|
|
|
|
tmp += "<td onclick='view("+id+","+feed_id+")' "+
|
|
|
|
"class='hlContent' valign='middle'>";
|
|
|
|
|
2009-02-04 21:13:21 +01:00
|
|
|
tmp += "<a target=\"_blank\" id=\"RTITLE-"+id+"\" href=\"" +
|
2009-02-04 13:42:59 +01:00
|
|
|
rs.fieldByName("link") + "\"" +
|
|
|
|
"onclick=\"return view("+id+","+feed_id+");\">"+
|
|
|
|
rs.fieldByName("title");
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "<span class=\"contentPreview\"> - "+content_preview+"</span>";
|
|
|
|
|
|
|
|
tmp += "</a>";
|
2009-02-04 21:13:21 +01:00
|
|
|
|
|
|
|
if (entry_feed_title) {
|
|
|
|
tmp += " <span class=\"hlFeed\">"+
|
|
|
|
"(<a href='javascript:viewfeed("+feed_id+
|
|
|
|
")'>"+entry_feed_title+"</a>)</span>";
|
|
|
|
}
|
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "</td>";
|
2009-02-04 15:27:29 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "<td class=\"hlUpdated\" onclick='view("+id+","+feed_id+")'>"+
|
2009-02-04 15:27:29 +01:00
|
|
|
"<nobr>"+rs.fieldByName("updated").substring(0,16)+
|
|
|
|
"</nobr></td>";
|
2009-02-04 13:42:59 +01:00
|
|
|
|
|
|
|
tmp += "</tr>";
|
|
|
|
} else {
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
var add_class = "";
|
|
|
|
|
|
|
|
if (rs.fieldByName("unread") == "1") {
|
|
|
|
add_class = "Unread";
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += "<div class=\"cdmArticle"+add_class+"\" id=\"RROW-"+id+"\" "+
|
|
|
|
mouseover_attrs+"'>";
|
|
|
|
|
2009-02-04 15:27:29 +01:00
|
|
|
feed_icon_img = "<img class=\"tinyFeedIcon\" src=\""+
|
|
|
|
getInitParam("icons_url")+"/"+feed_id+".ico\" alt=\"\">";
|
|
|
|
cdm_feed_icon = "<span style=\"cursor : pointer\" "+
|
|
|
|
"onclick=\"viewfeed("+feed_id+")\">"+feed_icon_img+"</span>";
|
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "<div class=\"cdmHeader\">";
|
|
|
|
tmp += "<div class=\"articleUpdated\">"+
|
2009-02-04 15:27:29 +01:00
|
|
|
rs.fieldByName("updated").substring(0,16)+
|
|
|
|
" "+cdm_feed_icon+"</div>";
|
2009-02-04 13:42:59 +01:00
|
|
|
|
|
|
|
tmp += "<span id=\"RTITLE-"+id+"\" class=\"titleWrap\">"+
|
|
|
|
"<a class=\"title\" onclick=\"javascript:toggleUnread("+id+", 0)\""+
|
|
|
|
"target=\"_blank\" href=\""+rs.fieldByName("link")+
|
|
|
|
"\">"+rs.fieldByName("title")+"</a>";
|
2009-02-04 21:13:21 +01:00
|
|
|
|
|
|
|
if (entry_feed_title) {
|
|
|
|
tmp += " (<a href='javascript:viewfeed("+feed_id+
|
|
|
|
")'>"+entry_feed_title+"</a>)";
|
|
|
|
}
|
|
|
|
|
2009-02-04 13:42:59 +01:00
|
|
|
tmp += "</span></div>";
|
|
|
|
|
|
|
|
tmp += "<div class=\"cdmContent\" onclick=\"cdmClicked("+id+")\""+
|
|
|
|
"id=\"CICD-"+id+"\">";
|
|
|
|
tmp += rs.fieldByName("content");
|
|
|
|
tmp += "<br clear='both'>"
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
tmp += "<div class=\"cdmFooter\"><span class='s0'>";
|
|
|
|
tmp += __("Select:")+
|
|
|
|
" <input type=\"checkbox\" "+
|
|
|
|
"onclick=\"toggleSelectRowById(this, 'RROW-"+id+"')\" "+
|
|
|
|
"class=\"feedCheckBox\" id=\"RCHK-"+id+"\">";
|
|
|
|
|
|
|
|
tmp += "</span><span class='s1'>"+marked_pic+"</span> ";
|
|
|
|
|
|
|
|
tmp += "<span class='s1'>"+
|
|
|
|
"<img class='tagsPic' src='images/tag.png' alt='Tags' title='Tags'>"+
|
|
|
|
"<span id=\"ATSTR-"+id+"\">"+rs.fieldByName("tags")+"</span>"+
|
|
|
|
"</span>";
|
|
|
|
|
|
|
|
tmp += "<span class='s2'>Toggle: <a class=\"cdmToggleLink\""+
|
|
|
|
"href=\"javascript:toggleUnread("+id+")\">"+
|
|
|
|
"Unread</a></span>";
|
|
|
|
tmp += "</div>";
|
|
|
|
|
|
|
|
tmp += "</div>";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
rs.next();
|
|
|
|
line_num++;
|
|
|
|
}
|
2009-02-04 12:20:25 +01:00
|
|
|
|
2009-02-04 12:47:09 +01:00
|
|
|
if (line_num - offset*30 < 30) {
|
|
|
|
_infscroll_disable = 1;
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
tmp += "</table>";
|
2009-02-04 21:23:12 +01:00
|
|
|
|
|
|
|
if (line_num - offset*30 == 0) {
|
|
|
|
tmp += "<div class='whiteBox'>" +
|
|
|
|
__("No articles found to display.") +
|
|
|
|
"</div>";
|
|
|
|
}
|
2009-02-04 08:17:55 +01:00
|
|
|
tmp += "</div></div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0) {
|
2009-02-04 12:33:43 +01:00
|
|
|
var container = document.getElementById("headlines-frame");
|
2009-02-04 08:17:55 +01:00
|
|
|
container.innerHTML = tmp;
|
|
|
|
} else {
|
|
|
|
var ids = getSelectedArticleIds2();
|
|
|
|
|
2009-02-04 12:33:43 +01:00
|
|
|
var container = document.getElementById("headlinesList");
|
|
|
|
container.innerHTML = container.innerHTML + tmp;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
for (var i = 0; i < ids.length; i++) {
|
|
|
|
markHeadline(ids[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_splash();
|
|
|
|
|
2009-02-04 12:47:09 +01:00
|
|
|
_infscroll_request_sent = 0;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("viewfeed_offline", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function render_offline_feedlist() {
|
|
|
|
try {
|
|
|
|
var tmp = "<ul class=\"feedList\" id=\"feedList\">";
|
|
|
|
|
|
|
|
var unread = get_local_feed_unread(-4);
|
|
|
|
|
|
|
|
global_unread = unread;
|
|
|
|
updateTitle();
|
|
|
|
|
|
|
|
tmp += printFeedEntry(-4, __("All articles"), "feed", unread,
|
|
|
|
"images/tag.png");
|
|
|
|
|
|
|
|
var unread = get_local_feed_unread(-1);
|
|
|
|
|
|
|
|
tmp += printFeedEntry(-1, __("Starred articles"), "feed", unread,
|
|
|
|
"images/mark_set.png");
|
|
|
|
|
|
|
|
tmp += "<li><hr/></li>";
|
|
|
|
|
2009-02-04 21:00:05 +01:00
|
|
|
/* var rs = db.execute("SELECT feeds.id,feeds.title,has_icon,COUNT(articles.id) "+
|
2009-02-04 08:17:55 +01:00
|
|
|
"FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+
|
|
|
|
"WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+
|
2009-02-04 21:00:05 +01:00
|
|
|
"ORDER BY feeds.title"); */
|
|
|
|
|
|
|
|
var rs = db.execute("SELECT id,title,has_icon FROM feeds "+
|
|
|
|
"ORDER BY title");
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
while (rs.isValidRow()) {
|
|
|
|
|
|
|
|
var id = rs.field(0);
|
|
|
|
var title = rs.field(1);
|
|
|
|
var has_icon = rs.field(2);
|
2009-02-04 21:00:05 +01:00
|
|
|
var unread = get_local_feed_unread(id);
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
var icon = "";
|
|
|
|
|
|
|
|
if (has_icon) {
|
|
|
|
icon = "icons/" + id + ".ico";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var feed_icon = "";
|
|
|
|
|
|
|
|
var row_class = "feed";
|
|
|
|
|
|
|
|
if (unread > 0) {
|
|
|
|
row_class += "Unread";
|
|
|
|
fctr_class = "feedCtrHasUnread";
|
|
|
|
} else {
|
|
|
|
fctr_class = "feedCtrNoUnread";
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += printFeedEntry(id, title, "feed", unread, icon);
|
|
|
|
|
|
|
|
rs.next();
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
tmp += "</ul>";
|
|
|
|
|
|
|
|
render_feedlist(tmp);
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("render_offline_feedlist", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init_offline() {
|
|
|
|
try {
|
|
|
|
offline_mode = true;
|
|
|
|
|
|
|
|
Element.hide("dispSwitchPrompt");
|
|
|
|
Element.hide("feedBrowserPrompt");
|
|
|
|
|
2009-02-04 20:47:26 +01:00
|
|
|
Element.hide("topLinksOnline");
|
|
|
|
Element.show("topLinksOffline");
|
|
|
|
|
2009-02-04 12:02:43 +01:00
|
|
|
var tb_form = document.getElementById("main_toolbar_form");
|
|
|
|
Element.hide(tb_form.update);
|
|
|
|
|
2009-02-04 13:49:34 +01:00
|
|
|
var chooser = document.getElementById("quickMenuChooser");
|
|
|
|
chooser.disabled = true;
|
|
|
|
|
2009-02-04 12:15:58 +01:00
|
|
|
var rs = db.execute("SELECT key, value FROM init_params");
|
|
|
|
|
|
|
|
while (rs.isValidRow()) {
|
|
|
|
init_params[rs.field(0)] = rs.field(1);
|
|
|
|
rs.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
rs.close();
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 21:17:50 +01:00
|
|
|
var rs = db.execute("SELECT COUNT(*) FROM feeds");
|
|
|
|
|
|
|
|
var num_feeds = 0;
|
|
|
|
|
|
|
|
if (rs.isValidRow()) {
|
|
|
|
num_feeds = rs.field(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rs.close();
|
|
|
|
|
|
|
|
if (num_feeds == 0) {
|
|
|
|
remove_splash();
|
|
|
|
return fatalError(0,
|
|
|
|
__("Data for offline browsing has not been downloaded yet."));
|
|
|
|
}
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
render_offline_feedlist();
|
2009-02-04 12:34:42 +01:00
|
|
|
init_second_stage();
|
2009-02-04 21:17:50 +01:00
|
|
|
window.setTimeout("viewfeed(-4)", 50);
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
} catch (e) {
|
|
|
|
exception_error("init_offline", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function offline_download_parse(stage, transport) {
|
|
|
|
try {
|
|
|
|
if (transport.responseXML) {
|
|
|
|
|
|
|
|
if (stage == 0) {
|
|
|
|
|
|
|
|
var feeds = transport.responseXML.getElementsByTagName("feed");
|
|
|
|
|
|
|
|
if (feeds.length > 0) {
|
|
|
|
db.execute("DELETE FROM feeds");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < feeds.length; i++) {
|
|
|
|
var id = feeds[i].getAttribute("id");
|
|
|
|
var has_icon = feeds[i].getAttribute("has_icon");
|
|
|
|
var title = feeds[i].firstChild.nodeValue;
|
|
|
|
|
|
|
|
db.execute("INSERT INTO feeds (id,title,has_icon)"+
|
|
|
|
"VALUES (?,?,?)",
|
|
|
|
[id, title, has_icon]);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var articles = transport.responseXML.getElementsByTagName("article");
|
|
|
|
|
|
|
|
var articles_found = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < articles.length; i++) {
|
|
|
|
var a = eval("("+articles[i].firstChild.nodeValue+")");
|
|
|
|
articles_found++;
|
|
|
|
if (a) {
|
|
|
|
|
|
|
|
var date = new Date();
|
|
|
|
var ts = Math.round(date.getTime() / 1000);
|
|
|
|
|
|
|
|
db.execute("DELETE FROM articles WHERE id = ?", [a.id]);
|
|
|
|
db.execute("INSERT INTO articles "+
|
|
|
|
"(id, feed_id, title, link, guid, updated, content, "+
|
2009-02-04 12:15:58 +01:00
|
|
|
"unread, marked, tags, added, comments) "+
|
|
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
2009-02-04 08:17:55 +01:00
|
|
|
[a.id, a.feed_id, a.title, a.link, a.guid, a.updated,
|
2009-02-04 12:15:58 +01:00
|
|
|
a.content, a.unread, a.marked, a.tags, ts,
|
|
|
|
a.comments]);
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (articles_found > 0) {
|
|
|
|
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
|
|
|
|
} else {
|
|
|
|
window.setTimeout("update_offline_data(0)", 1800*1000);
|
|
|
|
|
|
|
|
var date = new Date();
|
|
|
|
var ts = Math.round(date.getTime() / 1000);
|
|
|
|
|
|
|
|
db.execute("DELETE FROM articles WHERE added < ? - 2592000", [ts]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:47:19 +01:00
|
|
|
notify('');
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("offline_download_parse", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_offline_data(stage) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!stage) stage = 0;
|
2009-02-04 15:45:58 +01:00
|
|
|
if (offline_mode) return;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
debug("update_offline_data: stage " + stage);
|
|
|
|
|
2009-02-04 15:45:58 +01:00
|
|
|
notify_progress("Updating offline data... (" + stage +")", true);
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
var query = "backend.php?op=rpc&subop=download&stage=" + stage;
|
|
|
|
|
|
|
|
var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles");
|
2009-02-04 12:20:25 +01:00
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
if (rs.isValidRow() && rs.field(0)) {
|
|
|
|
var offline_dl_max_id = rs.field(0);
|
|
|
|
var offline_dl_min_id = rs.field(1);
|
|
|
|
|
|
|
|
query = query + "&cidt=" + offline_dl_max_id;
|
|
|
|
query = query + "&cidb=" + offline_dl_min_id;
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
new Ajax.Request(query, {
|
|
|
|
onComplete: function(transport) {
|
|
|
|
offline_download_parse(stage, transport);
|
|
|
|
debug("update_offline_data: done " + stage);
|
|
|
|
} });
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("initiate_offline_download", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_feedlist_counter(id, ctr) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
var feedctr = document.getElementById("FEEDCTR-" + id);
|
|
|
|
var feedu = document.getElementById("FEEDU-" + id);
|
|
|
|
var feedr = document.getElementById("FEEDR-" + id);
|
|
|
|
|
|
|
|
if (feedctr && feedu && feedr) {
|
|
|
|
|
|
|
|
var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
|
|
|
|
|
|
|
|
feedu.innerHTML = ctr;
|
|
|
|
|
|
|
|
if (ctr > 0) {
|
|
|
|
feedctr.className = "feedCtrHasUnread";
|
|
|
|
if (!feedr.className.match("Unread")) {
|
|
|
|
var is_selected = feedr.className.match("Selected");
|
|
|
|
|
|
|
|
feedr.className = feedr.className.replace("Selected", "");
|
|
|
|
feedr.className = feedr.className.replace("Unread", "");
|
|
|
|
|
|
|
|
feedr.className = feedr.className + "Unread";
|
|
|
|
|
|
|
|
if (is_selected) {
|
|
|
|
feedr.className = feedr.className + "Selected";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row_needs_hl) {
|
|
|
|
new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
|
|
|
|
queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
feedctr.className = "feedCtrNoUnread";
|
|
|
|
feedr.className = feedr.className.replace("Unread", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("set_feedlist_counter", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_local_feedlist_counters() {
|
|
|
|
try {
|
2009-02-04 21:00:05 +01:00
|
|
|
if (!offline_mode) return;
|
2009-02-04 08:17:55 +01:00
|
|
|
|
2009-02-04 21:00:05 +01:00
|
|
|
/* var rs = db.execute("SELECT feeds.id,COUNT(articles.id) "+
|
2009-02-04 08:17:55 +01:00
|
|
|
"FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+
|
|
|
|
"WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+
|
2009-02-04 21:00:05 +01:00
|
|
|
"ORDER BY feeds.title"); */
|
|
|
|
|
|
|
|
var rs = db.execute("SELECT id,title,has_icon FROM feeds "+
|
|
|
|
"ORDER BY title");
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
while (rs.isValidRow()) {
|
|
|
|
var id = rs.field(0);
|
2009-02-04 21:00:05 +01:00
|
|
|
var ctr = get_local_feed_unread(id);
|
2009-02-04 08:17:55 +01:00
|
|
|
|
|
|
|
set_feedlist_counter(id, ctr);
|
|
|
|
|
|
|
|
rs.next();
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
|
|
|
|
2009-02-04 08:17:55 +01:00
|
|
|
set_feedlist_counter(-4, get_local_feed_unread(-4));
|
|
|
|
set_feedlist_counter(-1, get_local_feed_unread(-1));
|
|
|
|
|
|
|
|
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
|
|
|
|
|
|
|
|
global_unread = get_local_feed_unread(-4);
|
|
|
|
updateTitle();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("update_local_feedlist_counters", e);
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 08:19:36 +01:00
|
|
|
|
|
|
|
function get_local_feed_unread(id) {
|
|
|
|
try {
|
|
|
|
var rs;
|
|
|
|
|
|
|
|
if (id == -4) {
|
|
|
|
rs = db.execute("SELECT SUM(unread) FROM articles");
|
|
|
|
} else if (id == -1) {
|
|
|
|
rs = db.execute("SELECT SUM(unread) FROM articles WHERE marked = 1");
|
|
|
|
} else {
|
|
|
|
rs = db.execute("SELECT SUM(unread) FROM articles WHERE feed_id = ?", [id]);
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
var a = false;
|
|
|
|
|
2009-02-04 08:19:36 +01:00
|
|
|
if (rs.isValidRow()) {
|
2009-02-04 12:20:25 +01:00
|
|
|
a = rs.field(0);
|
2009-02-04 08:19:36 +01:00
|
|
|
} else {
|
2009-02-04 12:20:25 +01:00
|
|
|
a = 0;
|
2009-02-04 08:19:36 +01:00
|
|
|
}
|
|
|
|
|
2009-02-04 12:20:25 +01:00
|
|
|
rs.close();
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
2009-02-04 08:19:36 +01:00
|
|
|
} catch (e) {
|
|
|
|
exception_error("get_local_feed_unread", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:36:06 +01:00
|
|
|
function init_gears() {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (window.google && google.gears) {
|
|
|
|
localServer = google.gears.factory.create("beta.localserver");
|
|
|
|
store = localServer.createManagedStore("tt-rss");
|
|
|
|
db = google.gears.factory.create('beta.database');
|
|
|
|
db.open('tt-rss');
|
|
|
|
|
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)");
|
|
|
|
|
|
|
|
var rs = db.execute("SELECT schema_version FROM version");
|
|
|
|
|
|
|
|
var version = "";
|
|
|
|
|
|
|
|
if (rs.isValidRow()) {
|
|
|
|
version = rs.field(0);
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:15:58 +01:00
|
|
|
rs.close();
|
|
|
|
|
2009-02-04 11:36:06 +01:00
|
|
|
if (version != SCHEMA_VERSION) {
|
2009-02-04 12:15:58 +01:00
|
|
|
db.execute("DROP TABLE IF EXISTS init_params");
|
2009-02-04 11:53:25 +01:00
|
|
|
db.execute("DROP TABLE IF EXISTS cache");
|
|
|
|
db.execute("DROP TABLE IF EXISTS feeds");
|
|
|
|
db.execute("DROP TABLE IF EXISTS articles");
|
2009-02-04 12:15:58 +01:00
|
|
|
db.execute("DROP TABLE IF EXISTS version");
|
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)");
|
2009-02-04 11:36:06 +01:00
|
|
|
db.execute("INSERT INTO version (schema_version) VALUES (?)",
|
|
|
|
[SCHEMA_VERSION]);
|
|
|
|
}
|
|
|
|
|
2009-02-04 12:15:58 +01:00
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS init_params (key text, value text)");
|
|
|
|
|
2009-02-04 11:36:06 +01:00
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS cache (id text, article text, param text, added text)");
|
2009-02-04 11:53:25 +01:00
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS feeds (id integer, title text, has_icon integer)");
|
|
|
|
db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated text, content text, tags text, unread text, marked text, added text, comments text)");
|
2009-02-04 13:42:59 +01:00
|
|
|
|
|
|
|
db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'");
|
2009-02-04 20:47:26 +01:00
|
|
|
|
|
|
|
Element.show("restartOfflinePic");
|
|
|
|
|
2009-02-04 11:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cache_expire();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
exception_error("init_gears", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 20:47:26 +01:00
|
|
|
function gotoOffline() {
|
|
|
|
window.location.href = "tt-rss.php?offline=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
function gotoOnline() {
|
|
|
|
window.location.href = "tt-rss.php";
|
|
|
|
}
|
2009-02-04 08:19:36 +01:00
|
|
|
|