diff --git a/backend.php b/backend.php index 52b4f346..6fdd3c8e 100644 --- a/backend.php +++ b/backend.php @@ -53,6 +53,12 @@ pg_query("set client_encoding = 'utf-8'"); } + if (get_pref($link, "HIDE_READ_FEEDS") == "true") { + setcookie("ttrss_vf_hreadf", 1); + } else { + setcookie("ttrss_vf_hreadf", 0); + } + $fetch = $_GET["fetch"]; setcookie("ttrss_icons_url", ICONS_URL); @@ -616,6 +622,24 @@ $subop = $_GET["subop"]; + if ($subop == "setpref") { + if (WEB_DEMO_MODE) { + return; + } + + print ""; + + $key = db_escape_string($_GET["key"]); + $value = db_escape_string($_GET["value"]); + + set_pref($link, $key, $value); + + print ""; + + print ""; + + } + if ($subop == "getLabelCounters") { $aid = $_GET["aid"]; print ""; diff --git a/db-prefs.php b/db-prefs.php index 293af7be..1b6262d9 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -57,4 +57,18 @@ return $value; } } + + // doesn't peform any type checking, be vigilant + + function set_pref($link, $key, $value) { + $key = db_escape_string($key); + $value = db_escape_string($value); + + db_query($link, "UPDATE ttrss_user_prefs SET + value = '$value' WHERE pref_name = '$key' + AND owner_uid = " . $_SESSION["uid"]); + + $_SESSION["prefs_cache"] = array(); + + } ?> diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index c80d1844..8b62cd83 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -235,6 +235,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_SEARCH_TOOLBAR', 1, 'false', 'Enable search toolbar',2); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('HIDE_READ_FEEDS', 1, 'false', 'Hide feeds with no unread messages',2); + create table ttrss_user_prefs ( owner_uid integer not null, pref_name varchar(250), diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 2deae606..a0d570d3 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -213,6 +213,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_SEARCH_TOOLBAR', 1, 'false', 'Enable search toolbar',2); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('HIDE_READ_FEEDS', 1, 'false', 'Hide feeds with no unread messages',2); + create table ttrss_user_prefs ( owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE, diff --git a/schema/upgrade-1.1.1-1.1.2-mysql.sql b/schema/upgrade-1.1.1-1.1.2-mysql.sql index d6c8a522..6dfc5f82 100644 --- a/schema/upgrade-1.1.1-1.1.2-mysql.sql +++ b/schema/upgrade-1.1.1-1.1.2-mysql.sql @@ -10,6 +10,8 @@ update ttrss_feeds set private = false; alter table ttrss_feeds change private private bool not null; alter table ttrss_feeds alter column private set default 0; +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('HIDE_READ_FEEDS', 1, 'false', 'Hide feeds with no unread messages',2); + update ttrss_version set schema_version = 4; commit; diff --git a/schema/upgrade-1.1.1-1.1.2-pgsql.sql b/schema/upgrade-1.1.1-1.1.2-pgsql.sql index 960ed8b6..1f926eae 100644 --- a/schema/upgrade-1.1.1-1.1.2-pgsql.sql +++ b/schema/upgrade-1.1.1-1.1.2-pgsql.sql @@ -10,6 +10,8 @@ update ttrss_feeds set private = false; alter table ttrss_feeds alter column private set not null; alter table ttrss_feeds alter column private set default false; +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('HIDE_READ_FEEDS', 1, 'false', 'Hide feeds with no unread messages',2); + update ttrss_version set schema_version = 4; commit; diff --git a/tt-rss.js b/tt-rss.js index 85c4564d..36aec2ba 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -72,6 +72,31 @@ function dlg_display_callback() { } } +function hide_unread_callback() { + if (xmlhttp.readyState == 4) { + + try { + + var reply = xmlhttp.responseXML.firstChild.firstChild; + var value = reply.getAttribute("value"); + var hide_read_feeds = (value != "false") + var feeds_doc = window.frames["feeds-frame"].document; + + hideOrShowFeeds(feeds_doc, hide_read_feeds); + + if (hide_read_feeds) { + setCookie("ttrss_vf_hreadf", 1); + } else { + setCookie("ttrss_vf_hreadf", 0); + } + + } catch (e) { + exception_error("hide_unread_callback", e); + } + + } +} + function refetch_callback() { if (xmlhttp.readyState == 4) { try { @@ -504,6 +529,11 @@ function qaddFilter() { function displayDlg(id, param) { + if (!xmlhttp_ready(xmlhttp)) { + printLockingError(); + return + } + notify(""); xmlhttp.open("GET", "backend.php?op=dlg&id=" + @@ -524,6 +554,11 @@ function qfdDelete(feed_id) { notify("Removing feed..."); + if (!xmlhttp_ready(xmlhttp)) { + printLockingError(); + return + } + // var feeds_doc = window.frames["feeds-frame"].document; // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; @@ -563,19 +598,26 @@ function updateFeedTitle(t) { } function toggleDispRead() { - var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1); + try { - hide_read_feeds = !hide_read_feeds; + if (!xmlhttp_ready(xmlhttp)) { + printLockingError(); + return + } - var feeds_doc = window.frames["feeds-frame"].document; + var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1); - hideOrShowFeeds(feeds_doc, hide_read_feeds); + hide_read_feeds = !hide_read_feeds; + + var query = "backend.php?op=rpc&subop=setpref" + + "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds); - if (hide_read_feeds) { - setCookie("ttrss_vf_hreadf", 1); - } else { - setCookie("ttrss_vf_hreadf", 0); + xmlhttp.open("GET", query); + xmlhttp.onreadystatechange=hide_unread_callback; + xmlhttp.send(null); + + } catch (e) { + exception_error("toggleDispRead", e); } - }