From 75c510323be9682951412510d82f97d838dcb3bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Nov 2010 21:50:13 +0300 Subject: remove google gears --- digest.js | 3 - feedlist.js | 21 - functions.js | 15 - gears_init.js | 87 --- manifest.json.php | 70 -- modules/backend-rpc.php | 214 ------ modules/pref-prefs.php | 3 +- offline.js | 1770 ----------------------------------------------- prefs.js | 3 - tt-rss.js | 15 - tt-rss.php | 34 - viewfeed.js | 292 ++------ 12 files changed, 77 insertions(+), 2450 deletions(-) delete mode 100644 gears_init.js delete mode 100644 manifest.json.php delete mode 100644 offline.js diff --git a/digest.js b/digest.js index 22835adf8..d282f4ee2 100644 --- a/digest.js +++ b/digest.js @@ -1,9 +1,6 @@ var last_feeds = []; var init_params = {}; -var db = false; -var store = false; - var _active_feed_id = false; var _active_feed_offset = false; var _update_timeout = false; diff --git a/feedlist.js b/feedlist.js index 3df1bd80d..7dfaef952 100644 --- a/feedlist.js +++ b/feedlist.js @@ -67,8 +67,6 @@ function viewfeed(feed, subop, is_cat, offset) { try { if (is_cat == undefined) is_cat = false; - if (offline_mode) return viewfeed_offline(feed, subop, is_cat, offset); - // if (!offset) page_offset = 0; last_requested_article = 0; @@ -147,8 +145,6 @@ function viewfeed(feed, subop, is_cat, offset) { if (subop == "MarkAllRead") { - catchup_local_feed(feed, is_cat); - var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { @@ -367,8 +363,6 @@ function toggleCollapseCat(cat) { { parameters: "backend.php?op=feeds&subop=collapse&cid=" + param_escape(cat) } ); - local_collapse_cat(cat); - } catch (e) { exception_error("toggleCollapseCat", e); } @@ -418,8 +412,6 @@ function feedlist_init() { document.onmousedown = mouse_down_handler; document.onmouseup = mouse_up_handler; - if (!offline_mode) setTimeout("timeout()", 1); - setTimeout("hotkey_prefix_timeout()", 5*1000); if (getActiveFeedId()) { @@ -579,10 +571,6 @@ function mouse_up_handler(e) { document.onselectstart = null; var e = $("headlineActionsBody"); if (e) Element.hide(e); - - var e = $("offlineModeDrop"); - if (e) Element.hide(e); - } } catch (e) { @@ -591,11 +579,7 @@ function mouse_up_handler(e) { } function request_counters_real() { - try { - - if (offline_mode) return; - console.log("requesting counters..."); var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq(); @@ -683,11 +667,6 @@ function parse_counters(reply, scheduled_call) { var xmsg = elems[l].xmsg; if (id == "global-unread") { - - if (ctr > global_unread) { - offlineDownloadStart(1); - } - global_unread = ctr; updateTitle(); continue; diff --git a/functions.js b/functions.js index 8428af39e..56fafad9f 100644 --- a/functions.js +++ b/functions.js @@ -1227,16 +1227,9 @@ function backend_sanity_check_callback(transport) { fatalError(3, "Sanity check: Received reply is not XML", transport.responseText); return; - } else { - init_offline(); - return; } } - if (getURLParam("offline")) { - return init_offline(); - } - var reply = transport.responseXML.getElementsByTagName("error")[0]; if (!reply) { @@ -1261,16 +1254,8 @@ function backend_sanity_check_callback(transport) { if (params) { for (k in params) { - var v = params[k]; - console.log("IP: " + k + " => " + v); - - if (db) { - db.execute("DELETE FROM init_params WHERE key = ?", [k]); - db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)", - [k, v]); - } } } diff --git a/gears_init.js b/gears_init.js deleted file mode 100644 index 3462d73e8..000000000 --- a/gears_init.js +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2007, Google Inc. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// 3. Neither the name of Google Inc. nor the names of its contributors may be -// used to endorse or promote products derived from this software without -// specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Sets up google.gears.*, which is *the only* supported way to access Gears. -// -// Circumvent this file at your own risk! -// -// In the future, Gears may automatically define google.gears.* without this -// file. Gears may use these objects to transparently fix bugs and compatibility -// issues. Applications that use the code below will continue to work seamlessly -// when that happens. - -(function() { - // We are already defined. Hooray! - if (window.google && google.gears) { - return; - } - - var factory = null; - - // Firefox - if (typeof GearsFactory != 'undefined') { - factory = new GearsFactory(); - } else { - // IE - try { - factory = new ActiveXObject('Gears.Factory'); - // privateSetGlobalObject is only required and supported on IE Mobile on - // WinCE. - if (factory.getBuildInfo().indexOf('ie_mobile') != -1) { - factory.privateSetGlobalObject(this); - } - } catch (e) { - // Safari - if ((typeof navigator.mimeTypes != 'undefined') - && navigator.mimeTypes["application/x-googlegears"]) { - factory = document.createElement("object"); - factory.style.display = "none"; - factory.width = 0; - factory.height = 0; - factory.type = "application/x-googlegears"; - document.documentElement.appendChild(factory); - } - } - } - - // *Do not* define any objects if Gears is not installed. This mimics the - // behavior of Gears defining the objects in the future. - if (!factory) { - return; - } - - // Now set up the objects, being careful not to overwrite anything. - // - // Note: In Internet Explorer for Windows Mobile, you can't add properties to - // the window object. However, global objects are automatically added as - // properties of the window object in all browsers. - if (!window.google) { - google = {}; - } - - if (!google.gears) { - google.gears = {factory: factory}; - } -})(); diff --git a/manifest.json.php b/manifest.json.php deleted file mode 100644 index b322df262..000000000 --- a/manifest.json.php +++ /dev/null @@ -1,70 +0,0 @@ - $mtime_max) { - $mtime_max = $tmp; - } - - array_push($manifest_formatted, "{ \"url\": \"$f\" }"); - } -?> - -{ - "betaManifestVersion": 1, - "version": "", - "entries": [ - - ] -} diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 23706ea3d..286831804 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -713,220 +713,6 @@ return; } - if ($subop == "download") { - $stage = (int) $_REQUEST["stage"]; - $cidt = (int)db_escape_string($_REQUEST["cidt"]); - $cidb = (int)db_escape_string($_REQUEST["cidb"]); - $sync = db_escape_string($_REQUEST["sync"]); - //$amount = (int) $_REQUEST["amount"]; - //$unread_only = db_escape_string($_REQUEST["unread_only"]); - //if (!$amount) $amount = 50; - - /* Amount is not used by the frontend offline.js anymore, it goes by - * date_qpart below + cidb/cidt IDs */ - - $amount = 2000; - $unread_only = true; - - print ""; - - $sync = split(";", $sync); - - print ""; - - if (count($sync) > 0) { - if (strtotime($sync[0])) { - $last_online = db_escape_string($sync[0]); - - print ""; - - for ($i = 1; $i < count($sync); $i++) { - $e = split(",", $sync[$i]); - - if (count($e) == 3) { - - $id = (int) $e[0]; - $unread = bool_to_sql_bool((bool) $e[1]); - $marked = (bool)$e[2]; - - if ($marked) { - $marked = bool_to_sql_bool($marked); - $marked_qpart = "marked = $marked,"; - } - - $query = "UPDATE ttrss_user_entries SET - $marked_qpart - unread = $unread, - last_read = '$last_online' - WHERE ref_id = '$id' AND - (last_read IS NULL OR last_read < '$last_online') AND - owner_uid = ".$_SESSION["uid"]; - - $result = db_query($link, $query); - - print ""; - - } - } - - /* Maybe we need to further update local DB for this client */ - - $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries - WHERE last_read >= '$last_online' AND - owner_uid = ".$_SESSION["uid"] . " LIMIT 1000"; - - $result = db_query($link, $query); - - while ($line = db_fetch_assoc($result)) { - $unread = (int) sql_bool_to_bool($line["unread"]); - $marked = (int) sql_bool_to_bool($line["marked"]); - - print ""; - } - - } - } - - print ""; - - if ($stage == 0) { - print ""; - - $result = db_query($link, "SELECT id, title, cat_id FROM - ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); - - while ($line = db_fetch_assoc($result)) { - - $has_icon = (int) feed_has_icon($line["id"]); - - print ""; - } - - print ""; - - print ""; - - $result = db_query($link, "SELECT id, title, collapsed FROM - ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]); - - print ""; - - print ""; - - print ""; - - while ($line = db_fetch_assoc($result)) { - print ""; - } - - print ""; - - print ""; - - $result = db_query($link, "SELECT * FROM - ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]); - - while ($line = db_fetch_assoc($result)) { - print ""; - } - - - print ""; - - } - - if ($stage > 0) { - print ""; - - $limit = 10; - $skip = $limit*($stage-1); - - print ""; - - if ($amount > 0) $amount -= $skip; - - if ($amount > 0) { - - $limit = min($limit, $amount); - - if ($unread_only) { - $unread_qpart = "(unread = true OR marked = true) AND "; - } - - if ($cidt && $cidb) { - $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND "; - } - - if (DB_TYPE == "pgsql") { - $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND"; - } else { - $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND"; - } - - $result = db_query($link, - "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title, - guid,link,comments, - feed_id,content,updated,unread,marked FROM - ttrss_user_entries,ttrss_entries,ttrss_feeds - WHERE $unread_qpart $cid_qpart $date_qpart - ttrss_feeds.id = feed_id AND - ref_id = ttrss_entries.id AND - ttrss_user_entries.owner_uid = ".$_SESSION["uid"]." - ORDER BY updated DESC LIMIT $limit OFFSET $skip"); - - if (function_exists('json_encode')) { - - while ($line = db_fetch_assoc($result)) { - print "
"; - } - } - - } - - print "
"; - - } - - print "
"; - - return; - } - if ($subop == "digest-get-contents") { $article_id = db_escape_string($_REQUEST['article_id']); diff --git a/modules/pref-prefs.php b/modules/pref-prefs.php index e291e5c11..004227939 100644 --- a/modules/pref-prefs.php +++ b/modules/pref-prefs.php @@ -14,7 +14,8 @@ $subop = $_REQUEST["subop"]; $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS", - "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS"); + "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS", "ENABLE_FEED_ICONS", + "ENABLE_OFFLINE_READING"); $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", diff --git a/offline.js b/offline.js deleted file mode 100644 index 4fb374aab..000000000 --- a/offline.js +++ /dev/null @@ -1,1770 +0,0 @@ -var SCHEMA_VERSION = 10; - -var offline_mode = false; -var store = false; -var localServer = false; -var db = false; -var articles_synced = 0; -var sync_in_progress = false; -var sync_timer = false; - -function view_offline(id) { - try { - - enableHotkeys(); - showArticleInHeadlines(id); - - 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 = "
"; - - tmp += "
"; - - tmp += "
"+rs.fieldByName("updated")+"
"; - - if (rs.fieldByName("link") != "") { - tmp += "
" + - rs.fieldByName("title") + "
"; - } else { - tmp += "
" + rs.fieldByName("title") + "
"; - } - -/* tmp += "
"+ - "Tags"; - tmp += rs.fieldByName("tags"); - tmp += "
"; */ - -/* tmp += "
"+ - "" + - __("comments") + "
"; */ - - tmp += "
"; - - tmp += "
" - tmp += rs.fieldByName("content"); - tmp += "
"; - - tmp += "
"; - - render_article(tmp); - update_local_feedlist_counters(); - } - - rs.close(); - - return false; - - } catch (e) { - exception_error("view_offline", e); - } -} - -function viewfeed_offline(feed_id, subop, is_cat, offset) { - try { - notify(''); - - if (!offset) offset = 0; - - 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; - } - - loading_set_progress(100); - - clean_feed_selections(); - - setActiveFeedId(feed_id, is_cat); - - if (!is_cat) { - var feedr = $("FEEDR-" + feed_id); - if (feedr && !feedr.className.match("Selected")) { - feedr.className = feedr.className + "Selected"; - } - } else { - var feedr = $("FCAT-" + feed_id); - if (feedr && !feedr.className.match("Selected")) { - feedr.className = feedr.className + "Selected"; - } - } - - if (subop == "MarkAllRead") { - catchup_local_feed(feed_id, is_cat); - } - - Form.enable("main_toolbar_form"); - - var f = $("headlines-frame"); - try { - if (reply.offset == 0) { - console.log("resetting headlines scrollTop"); - f.scrollTop = 0; - } - } catch (e) { }; - - - var tmp = ""; - var feed_title = ""; - - if (is_cat) { - feed_title = get_local_category_title(feed_id); - } else { - feed_title = get_local_feed_title(feed_id); - } - - if (feed_title) { - - if (offset == 0) { - tmp += "
"; - - tmp += "
"; - tmp += "
"; - tmp += feed_title; - tmp += "
"; - - var catchup_feed_link = "javascript:catchupCurrentFeed()"; - var catchup_sel_link = "javascript:catchupSelection()"; - - var sel_all_link = "javascript:selectArticles('all')"; - var sel_unread_link = "javascript:selectArticles('unread')"; - var sel_none_link = "javascript:selectArticles('none')"; - var sel_inv_link = "javascript:invertHeadlineSelection()"; - - var tog_unread_link = "javascript:selectionToggleUnread()"; - var tog_marked_link = "javascript:selectionToggleMarked()"; - - tmp += __('Select:')+ - " "+__('All')+", "+ - ""+__('Unread')+", "+ - ""+__('Invert')+", "+ - ""+__('None')+""; - - tmp += "  "; - - tmp += "" + - __("Actions...") + "  " + - ""; - - tmp += "
    "; - - tmp += "
  • "+__('Selection toggle:')+"
  • "+ - "
  •   "+__('Unread')+"
  • "+ - "
  •   "+__('Starred')+"
  • "+ - "
  • "+__('Mark as read:')+"
  • "+ - "
  •   "+__('Selection')+"
  • "; - - tmp += "
  •   "+__('Entire feed')+ - "
  • "; - - tmp += "
"; - - tmp += "
"; - - tmp += "
"; - if ($("content-frame")) { - tmp += ""; - } - - } - - 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 = ""; - var offset_qpart = ""; - - if (limit != 0) { - limit_qpart = "LIMIT " + limit; - } - - if (view_mode == "all_articles") { - mode_qpart = "1"; - } else if (view_mode == "adaptive") { - if (is_cat && get_local_category_unread(feed_id) || - 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"; - } - - var ext_tables_qpart = ""; - - if (is_cat) { - if (feed_id >= 0) { - strategy_qpart = "cat_id = " + feed_id; - } else if (feed_id == -2) { - strategy_qpart = "article_labels.id = articles.id"; - ext_tables_qpart = ",article_labels"; - } - } else 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"; - } else if (feed_id < -10) { - var label_id = -11 - feed_id; - strategy_qpart = "article_labels.id = articles.id AND label_id = " + label_id; - ext_tables_qpart = ",article_labels"; - } - - if (offset > 0) { - offset_qpart = "OFFSET " + (offset*30); - } else { - offset_qpart = ""; - } - - var query = "SELECT *,feeds.title AS feed_title "+ - "FROM articles,feeds,categories"+ext_tables_qpart+" "+ - "WHERE " + - "cat_id = categories.id AND " + - "feed_id = feeds.id AND " + - strategy_qpart + - " AND " + mode_qpart + - " ORDER BY updated DESC "+ - limit_qpart + " " + - offset_qpart; - - var rs = db.execute(query); - - var line_num = offset*30; - - var real_feed_id = feed_id; - - while (rs.isValidRow()) { - - var id = rs.fieldByName("id"); - var feed_id = rs.fieldByName("feed_id"); - - var entry_feed_title = false; - - if (real_feed_id < 0 || is_cat) { - entry_feed_title = rs.fieldByName("feed_title"); - } - - var marked_pic; - - var row_class = (line_num % 2) ? "even" : "odd"; - - if (rs.fieldByName("unread") == "1") { - row_class += "Unread"; - } - - var labels = get_local_article_labels(id); - - var labels_str = ""; - labels_str += format_article_labels(labels, id); - labels_str += ""; - - if (rs.fieldByName("marked") == "1") { - marked_pic = ""; - } else { - marked_pic = ""; - } - - var mouseover_attrs = "onmouseover='postMouseIn($id)' "+ - "onmouseout='postMouseOut($id)'"; - - var content_preview = truncate_string(strip_tags(rs.fieldByName("content")), - 100); - - if ($("content-frame")) { - - tmp += ""; - - tmp += ""; - - tmp += ""; - - tmp += ""; - - tmp += ""; - - tmp += ""; - - tmp += ""; - } else { - - var add_class = ""; - - if (rs.fieldByName("unread") == "1") { - add_class = "Unread"; - } - - tmp += "
"; - - feed_icon_img = "\"\""; - cdm_feed_icon = ""+feed_icon_img+""; - - tmp += "
"; - tmp += "
"+ - rs.fieldByName("updated").substring(0,16)+ - " "+cdm_feed_icon+"
"; - - tmp += ""+ - ""+rs.fieldByName("title")+""; - - tmp += labels_str; - - if (entry_feed_title) { - tmp += " ("+entry_feed_title+")"; - } - - tmp += "
"; - - tmp += "
"; - tmp += rs.fieldByName("content"); - tmp += "
" - tmp += "
"; - - tmp += "
"; - tmp += __("Select:")+ - " "; - - tmp += ""+marked_pic+" "; - -/* tmp += ""+ - "Tags"+ - ""+rs.fieldByName("tags")+""+ - ""; */ - - tmp += "Toggle: "+ - "Unread"; - tmp += "
"; - - tmp += "
"; - } - - rs.next(); - line_num++; - } - - if (line_num - offset*30 < 30) { - _infscroll_disable = 1; - } - - rs.close(); - - if (offset == 0) { - tmp += "
"+ - ""+marked_pic+""; - - tmp += ""+ - rs.fieldByName("title"); - - tmp += " - "+content_preview+""; - - tmp += ""; - - tmp += labels_str; - - if (entry_feed_title) { - tmp += " "+ - "("+entry_feed_title+")"; - } - - tmp += ""+ - ""+rs.fieldByName("updated").substring(0,16)+ - "
"; - - if (line_num - offset*30 == 0) { - tmp += "
" + - __("No articles found to display.") + - "
"; - } - tmp += "
"; - } - - if (offset == 0) { - var container = $("headlines-frame"); - container.innerHTML = tmp; - } else { - var ids = getSelectedArticleIds2(); - - var container = $("headlinesList"); - container.innerHTML = container.innerHTML + tmp; - - for (var i = 0; i < ids.length; i++) { - markHeadline(ids[i]); - } - } - } - - remove_splash(); - - _infscroll_request_sent = 0; - - } catch (e) { - exception_error("viewfeed_offline", e); - } -} - -function render_offline_feedlist() { - try { - var cats_enabled = getInitParam("enable_feed_cats") == "1"; - - var tmp = ""; - } else { - tmp += "

  • "; - } - - if (cats_enabled) { - tmp += printCategoryHeader(-2, is_local_cat_collapsed(-2), false); - } - - var rs = db.execute("SELECT id,caption "+ - "FROM labels "+ - "ORDER BY caption"); - - while (rs.isValidRow()) { - var id = -11 - parseInt(rs.field(0)); - var caption = rs.field(1); - var unread = get_local_feed_unread(id); - - tmp += printFeedEntry(id, caption, "feed", unread, - "images/label.png"); - - rs.next(); - } - - rs.close(); - - if (cats_enabled) { - tmp += ""; - } else { - tmp += "

  • "; - } - -/* var rs = db.execute("SELECT feeds.id,feeds.title,has_icon,COUNT(articles.id) "+ - "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ - "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ - "ORDER BY feeds.title"); */ - - var order_by = "feeds.title"; - - if (cats_enabled) order_by = "categories.title," + order_by; - - var rs = db.execute("SELECT "+ - "feeds.id,feeds.title,has_icon,cat_id,collapsed "+ - "FROM feeds,categories WHERE cat_id = categories.id "+ - "ORDER BY "+order_by); - - var tmp_cat_id = -1; - - while (rs.isValidRow()) { - - var id = rs.field(0); - var title = rs.field(1); - var has_icon = rs.field(2); - var unread = get_local_feed_unread(id); - var cat_id = rs.field(3); - var cat_hidden = rs.field(4); - - if (cat_id != tmp_cat_id && cats_enabled) { - if (tmp_cat_id != -1) { - tmp += ""; - } - tmp += printCategoryHeader(cat_id, cat_hidden, true); - tmp_cat_id = cat_id; - } - - var icon = ""; - - if (has_icon) { - icon = getInitParam("icons_url") + "/" + 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(); - } - - rs.close(); - - if (cats_enabled) { - tmp += ""; - } - - tmp += ""; - - render_feedlist(tmp); - } catch (e) { - exception_error("render_offline_feedlist", e); - } -} - -function init_offline() { - try { - offline_mode = true; - store.enabled = true; - - Element.hide("dispSwitchPrompt"); - - Element.hide("topLinksOnline"); - Element.show("topLinksOffline"); - - var tb_form = $("main_toolbar_form"); - Element.hide(tb_form.update); - - var chooser = $("quickMenuChooser"); - chooser.disabled = true; - - 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(); - - 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.")); - } - - render_offline_feedlist(); - init_second_stage(); - window.setTimeout("viewfeed(-4)", 50); - - } catch (e) { - exception_error("init_offline", e); - } -} - -function offline_download_parse(stage, transport) { - try { - if (transport.responseXML) { - - if (!sync_in_progress) return; - - var sync_ok = transport.responseXML.getElementsByTagName("sync-ok"); - - if (sync_ok.length > 0) { - for (var i = 0; i < sync_ok.length; i++) { - var id = sync_ok[i].getAttribute("id"); - var unread = sync_ok[i].getAttribute("unread"); - var marked = sync_ok[i].getAttribute("marked"); - - if (id) { - console.log("synced offline info for id " + id); - - if (unread != undefined && marked != undefined) { - db.execute("UPDATE articles SET "+ - "unread = ?, marked = ? WHERE id = ?", [unread, marked, id]); - - } - db.execute("UPDATE articles SET modified = '' WHERE id = ?", [id]); - } - } - } - - if (stage == 0) { - - $("offlineModeSyncMsg").innerHTML = __("Synchronizing feeds..."); - - 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; - var cat_id = feeds[i].getAttribute("cat_id"); - - db.execute("INSERT INTO feeds (id,title,has_icon,cat_id)"+ - "VALUES (?,?,?,?)", - [id, title, has_icon, cat_id]); - } - - $("offlineModeSyncMsg").innerHTML = __("Synchronizing categories..."); - - var cats = transport.responseXML.getElementsByTagName("category"); - - if (feeds.length > 0) { - db.execute("DELETE FROM categories"); - } - - for (var i = 0; i < cats.length; i++) { - var id = cats[i].getAttribute("id"); - var collapsed = cats[i].getAttribute("collapsed"); - var title = cats[i].firstChild.nodeValue; - - db.execute("INSERT INTO categories (id,title,collapsed)"+ - "VALUES (?,?,?)", - [id, title, collapsed]); - } - - $("offlineModeSyncMsg").innerHTML = __("Synchronizing labels..."); - - var labels = transport.responseXML.getElementsByTagName("label"); - - if (labels.length > 0) { - db.execute("DELETE FROM labels"); - } - - for (var i = 0; i < labels.length; i++) { - var id = labels[i].getAttribute("id"); - var fg_color = labels[i].getAttribute("fg_color"); - var bg_color = labels[i].getAttribute("bg_color"); - var caption = labels[i].firstChild.nodeValue; - - db.execute("INSERT INTO labels (id,caption,fg_color,bg_color)"+ - "VALUES (?,?,?,?)", - [id, caption, fg_color, bg_color]); - } - - $("offlineModeSyncMsg").innerHTML = __("Synchronizing articles..."); - - sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 2*1000); - } else { - - var articles = transport.responseXML.getElementsByTagName("article"); - - var limit = transport.responseXML.getElementsByTagName("limit")[0]; - - if (limit) { - limit = limit.getAttribute("value"); - } else { - limit = 0; - } - - var articles_found = 0; - - for (var i = 0; i < articles.length; i++) { - var a = eval("("+articles[i].firstChild.nodeValue+")"); - articles_found++; - if (a) { - - db.execute("DELETE FROM articles WHERE id = ?", [a.id]); - - db.execute("INSERT INTO articles "+ - "(id, feed_id, title, link, guid, updated, content, "+ - "unread, marked, tags, comments) "+ - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - [a.id, a.feed_id, a.title, a.link, a.guid, a.updated, - a.content, a.unread, a.marked, a.tags, - a.comments]); - - if (a.labels.length > 0) { - for (var j = 0; j < a.labels.length; j++) { - label_local_add_article(a.id, a.labels[j][0]); - } - } - - } - } - - console.log("downloaded articles: " + articles_found + " limit: " + limit); - - articles_synced += articles_found; - - var msg =__("Synchronizing articles (%d)...").replace("%d", articles_synced); - - $("offlineModeSyncMsg").innerHTML = msg; - - var has_sync_data = has_local_sync_data(); - - if (articles_found >= limit || has_sync_data) { - sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", - 3*1000); - console.log("update_offline_data: done " + stage + " HSD: " + - has_sync_data + ""); - } else { - window.setTimeout("offlineDownloadStart()", 180*1000); - console.log("update_offline_data: finished"); - - var pic = $("offlineModePic"); - - if (pic) { - pic.src = "images/offline.png"; - - var rs = db.execute("SELECT value FROM syncdata WHERE key = 'last_online'"); - var last_sync = ""; - - if (rs.isValidRow()) { - last_sync = rs.field(0).substring(0,16); - } - rs.close(); - - var msg = __("Last sync: %s").replace("%s", last_sync); - - articles_synced = 0; - - $("offlineModeSyncMsg").innerHTML = msg; - } - - offlineSyncShowHideElems(false); - - sync_in_progress = false; - - db.execute("DELETE FROM articles WHERE "+ - "updated < DATETIME('NOW', 'localtime', '-31 days')"); - - } - } - - update_local_sync_data(); - - -// notify(''); - - } else { - sync_in_progress = false; - - var pic = $("offlineModePic"); - - if (pic) { - pic.src = "images/offline.png"; - var msg = __("Last sync: Error receiving data."); - articles_synced = 0; - $("offlineModeSyncMsg").innerHTML = msg; - } - - offlineSyncShowHideElems(false); - } - - } catch (e) { - exception_error("offline_download_parse", e); - } -} - -function update_offline_data(stage) { - try { - - if (!stage) stage = 0; - - if (!db || offline_mode || getInitParam("offline_enabled") != "1") return; - - var query = "?op=rpc&subop=download"; - - var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles"); - - 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; - - if (stage > 0) stage = 1; - } - - rs.close(); - - console.log("update_offline_data: stage " + stage); - - query = query + "&stage=" + stage; - - var to_sync = prepare_local_sync_data(); - - if (to_sync != "") { - to_sync = "&sync=" + param_escape(to_sync); - } - - query = query + to_sync; - - var pic = $("offlineModePic"); - - if (pic) { - pic.src = "images/offline-sync.gif"; - if (articles_synced == 0) { - $("offlineModeSyncMsg").innerHTML = __("Synchronizing..."); - } - } - - offlineSyncShowHideElems(true); - offlineUpdateStore(); - - sync_in_progress = true; - - console.log(query); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - offline_download_parse(stage, transport); - } }); - - } catch (e) { - exception_error("initiate_offline_download", e); - } -} - -function set_feedlist_counter(id, ctr, is_cat) { - try { - - var feedctr = $("FEEDCTR-" + id); - var feedu = $("FEEDU-" + id); - var feedr = $("FEEDR-" + id); - - if (is_cat) { - var catctr = $("FCATCTR-" + id); - if (catctr) { - catctr.innerHTML = "(" + ctr + ")"; - if (ctr > 0) { - catctr.className = "catCtrHasUnread"; - } else { - catctr.className = "catCtrNoUnread"; - } - } - } else 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 { - if (!offline_mode || !db) return; - -/* var rs = db.execute("SELECT feeds.id,COUNT(articles.id) "+ - "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ - "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ - "ORDER BY feeds.title"); */ - - var rs = db.execute("SELECT id FROM feeds "+ - "ORDER BY title"); - - while (rs.isValidRow()) { - var id = rs.field(0); - var ctr = get_local_feed_unread(id); - set_feedlist_counter(id, ctr, false); - rs.next(); - } - - rs.close(); - - var rs = db.execute("SELECT cat_id,SUM(unread) "+ - "FROM articles, feeds WHERE feeds.id = feed_id GROUP BY cat_id"); - - while (rs.isValidRow()) { - var id = rs.field(0); - var ctr = rs.field(1); - set_feedlist_counter(id, ctr, true); - rs.next(); - } - - rs.close(); - - set_feedlist_counter(-2, get_local_category_unread(-2), true); - - set_feedlist_counter(-4, get_local_feed_unread(-4)); - set_feedlist_counter(-1, get_local_feed_unread(-1)); - - var rs = db.execute("SELECT id FROM labels"); - - while (rs.isValidRow()) { - var id = -11 - rs.field(0); - var ctr = get_local_feed_unread(id); - set_feedlist_counter(id, ctr, false); - rs.next(); - } - - rs.close(); - - hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); - - global_unread = get_local_feed_unread(-4); - updateTitle(); - - } catch (e) { - exception_error("update_local_feedlist_counters", e); - } -} - -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 if (id > 0) { - rs = db.execute("SELECT SUM(unread) FROM articles WHERE feed_id = ?", [id]); - } else if (id < -10) { - var label_id = -11 - id; - rs = db.execute("SELECT SUM(unread) FROM articles,article_labels "+ - "WHERE article_labels.id = articles.id AND label_id = ?", [label_id]); - } - - var a = false; - - if (rs.isValidRow()) { - a = rs.field(0); - } else { - a = 0; - } - - rs.close(); - - return a; - - } catch (e) { - exception_error("get_local_feed_unread", e); - } -} - -function enable_offline_reading() { - try { - - if (db && getInitParam("offline_enabled") == "1") { - init_local_sync_data(); - Element.show("offlineModePic"); - offlineDownloadStart(); - } - - } catch (e) { - exception_error("enable_offline_reading", e); - } -} - -function init_gears() { - try { - - if (window.google && google.gears) { - - try { - localServer = google.gears.factory.create("beta.localserver"); - } catch (e) { - return; - } - - store = localServer.createManagedStore("tt-rss"); - store.manifestUrl = "manifest.json.php"; - store.enabled = false; - - 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); - } - - rs.close(); - - if (version != SCHEMA_VERSION) { - db.execute("DROP TABLE IF EXISTS init_params"); - db.execute("DROP TABLE IF EXISTS cache"); - db.execute("DROP TABLE IF EXISTS feeds"); - db.execute("DROP TABLE IF EXISTS categories"); - db.execute("DROP TABLE IF EXISTS labels"); - db.execute("DROP TABLE IF EXISTS article_labels"); - db.execute("DROP TABLE IF EXISTS articles"); - db.execute("DROP INDEX IF EXISTS article_labels_label_id_idx"); - db.execute("DROP INDEX IF EXISTS articles_unread_idx"); - db.execute("DROP INDEX IF EXISTS articles_feed_id_idx"); - db.execute("DROP INDEX IF EXISTS articles_id_idx"); - db.execute("DROP INDEX IF EXISTS article_labels_id_idx"); - db.execute("DROP TABLE IF EXISTS version"); - db.execute("DROP TRIGGER IF EXISTS articles_update_unread"); - db.execute("DROP TRIGGER IF EXISTS articles_update_marked"); - db.execute("DROP TRIGGER IF EXISTS articles_remove_labelrefs"); - db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); - db.execute("DROP TABLE IF EXISTS syncdata"); - db.execute("INSERT INTO version (schema_version) VALUES (?)", - [SCHEMA_VERSION]); - } - - db.execute("CREATE TABLE IF NOT EXISTS init_params (key text, value text)"); - - db.execute("CREATE TABLE IF NOT EXISTS cache (id integer, article text, param text, added text)"); - db.execute("CREATE TABLE IF NOT EXISTS feeds (id integer, title text, has_icon integer, cat_id integer)"); - db.execute("CREATE TABLE IF NOT EXISTS categories (id integer, title text, collapsed integer)"); - db.execute("CREATE TABLE IF NOT EXISTS labels (id integer, caption text, fg_color text, bg_color text)"); - db.execute("CREATE TABLE IF NOT EXISTS article_labels (id integer, label_id integer)"); - db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated timestamp, content text, tags text, unread integer, marked integer, added text, modified timestamp, comments text)"); - - db.execute("CREATE INDEX IF NOT EXISTS articles_unread_idx ON articles(unread)"); - db.execute("CREATE INDEX IF NOT EXISTS article_labels_label_id_idx ON article_labels(label_id)"); - db.execute("CREATE INDEX IF NOT EXISTS articles_feed_id_idx ON articles(feed_id)"); - db.execute("CREATE INDEX IF NOT EXISTS articles_id_idx ON articles(id)"); - db.execute("CREATE INDEX IF NOT EXISTS article_labels_id_idx ON article_labels(id)"); - - db.execute("CREATE TABLE IF NOT EXISTS syncdata (key integer, value text)"); - - db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'"); - - db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_unread "+ - "UPDATE OF unread ON articles "+ - "BEGIN "+ - "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ - "WHERE id = OLD.id AND "+ - "OLD.unread != NEW.unread;"+ - "END;"); - - db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_marked "+ - "UPDATE OF marked ON articles "+ - "BEGIN "+ - "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ - "WHERE id = OLD.id;"+ - "END;"); - - db.execute("CREATE TRIGGER IF NOT EXISTS articles_remove_labelrefs "+ - "DELETE ON articles "+ - "BEGIN "+ - "DELETE FROM article_labels WHERE id = OLD.id; "+ - "END; "); - - } - - cache_expire(); - - } catch (e) { - exception_error("init_gears", e); - } -} - -function offlineArticlesStored() { - - var rs = db.execute("SELECT COUNT(*) FROM articles"); - var count = 0; - if (rs.isValidRow()) { - count = rs.field(0); - } - - rs.close(); - - return count; -} - -function gotoOffline() { - -// console.log("[Local store] currentVersion = " + store.currentVersion); - - - if (offlineArticlesStored() == 0) { - notify_error("You have to synchronize some articles before going into offline mode."); - return; - } - - if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) { - - store.enabled = true; - store.checkForUpdate(); - - notify_progress("Preparing offline mode...", true); - - var timerId = window.setInterval(function() { - if (store.currentVersion) { - window.clearInterval(timerId); - console.log("[Local store] sync complete: " + store.currentVersion); - - //window.location.href = "tt-rss.php"; - - offlineDownloadStop(); - init_offline(); - - notify_info("Tiny Tiny RSS is in offline mode."); - - } else if (store.updateStatus == 3) { - console.log("[Local store] sync error: " + store.lastErrorMessage); - notify_error(store.lastErrorMessage, true); - } }, 500); - } -} - -function gotoOnline() { -// if (confirm(__("You won't be able to access offline version of Tiny Tiny RSS until you switch it into offline mode again. Go online?"))) { - if (confirm(__("Tiny Tiny RSS will reload. Go online?"))) { - //localServer.removeManagedStore("tt-rss"); - window.location.href = "tt-rss.php?online=1"; - } -} - -function local_collapse_cat(id) { - try { - if (db) { - db.execute("UPDATE categories SET collapsed = NOT collapsed WHERE id = ?", - [id]); - } - } catch (e) { - exception_error("local_collapse_cat", e); - } -} - -function get_local_category_title(id) { - try { - - var rs = db.execute("SELECT title FROM categories WHERE id = ?", [id]); - var tmp = ""; - - if (rs.isValidRow()) { - tmp = rs.field(0); - } - - rs.close(); - - return tmp; - - } catch (e) { - exception_error("get_local_category_title", e); - } -} - -function get_local_category_unread(id) { - try { - var rs = false; - - if (id >= 0) { - rs = db.execute("SELECT SUM(unread) FROM articles, feeds "+ - "WHERE feeds.id = feed_id AND cat_id = ?", [id]); - } else if (id == -2) { - rs = db.execute("SELECT SUM(unread) FROM article_labels, articles "+ - "where article_labels.id = articles.id"); - } else { - return 0; - } - - var tmp = 0; - - if (rs.isValidRow()) { - tmp = rs.field(0); - } - - rs.close(); - - return tmp; - - } catch (e) { - exception_error("get_local_category_unread", e); - } -} - -function printCategoryHeader(cat_id, hidden, can_browse) { - try { - if (hidden == undefined) hidden = false; - if (can_browse == undefined) can_browse = false; - - var tmp_category = get_local_category_title(cat_id); - var tmp = ""; - - var cat_unread = get_local_category_unread(cat_id); - - var holder_style = ""; - var ellipsis = ""; - - if (hidden) { - holder_style = "display:none;"; - ellipsis = "…"; - } - - var catctr_class = (cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; - - var browse_cat_link = ""; - var inner_title_class = "catTitleNL"; - - if (can_browse) { - browse_cat_link = "onclick=\"javascript:viewCategory("+cat_id+")\""; - inner_title_class = "catTitle"; - } - - var cat_class = "feedCat"; - - tmp += "
  • "+ - ""+tmp_category+""; - - tmp += ""; - - tmp += " ("+cat_unread+") "+ellipsis; - - tmp += ""; - - tmp += "