move runtime-info to JSON, simplify init-params format

This commit is contained in:
Andrew Dolgov 2010-11-10 14:23:26 +03:00
parent bd40aca6c0
commit c4f7ba8018
3 changed files with 46 additions and 78 deletions

View File

@ -2151,14 +2151,12 @@ function backend_sanity_check_callback(transport) {
params = JSON.parse(params.firstChild.nodeValue); params = JSON.parse(params.firstChild.nodeValue);
if (params) { if (params) {
for (var i = 0; i < params.length; i++) { for (k in params) {
var k = params[i].param; var v = params[k];
var v = params[i].value;
if (getURLParam('debug')) console.log(k + " => " + v);
init_params[k] = v;
console.log("IP: " + k + " => " + v);
if (db) { if (db) {
db.execute("DELETE FROM init_params WHERE key = ?", [k]); db.execute("DELETE FROM init_params WHERE key = ?", [k]);
db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)", db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
@ -2166,6 +2164,8 @@ function backend_sanity_check_callback(transport) {
} }
} }
} }
init_params = params;
} }
sanity_check_done = true; sanity_check_done = true;

View File

@ -3128,85 +3128,64 @@
function make_init_params($link) { function make_init_params($link) {
$params = array(); $params = array();
array_push($params, make_init_param("theme", get_user_theme($link))); $params["theme"] = get_user_theme($link);
array_push($params, make_init_param("theme_options", get_user_theme_options($link))); $params["theme_options"] = get_user_theme_options($link);
array_push($params, make_init_param("daemon_enabled", ENABLE_UPDATE_DAEMON)); $params["daemon_enabled"] = ENABLE_UPDATE_DAEMON;
array_push($params, make_init_param("feeds_frame_refresh", FEEDS_FRAME_REFRESH)); $params["feeds_frame_refresh"] = FEEDS_FRAME_REFRESH;
array_push($params, make_init_param("sign_progress", $params["sign_progress"] = theme_image($link, "images/indicator_white.gif");
theme_image($link, "images/indicator_white.gif"))); $params["sign_progress_tiny"] = theme_image($link, "images/indicator_tiny.gif");
$params["sign_excl"] = theme_image($link, "images/sign_excl.png");
array_push($params, make_init_param("sign_progress_tiny", $params["sign_info"] = theme_image($link, "images/sign_info.png");
theme_image($link, "images/indicator_tiny.gif")));
array_push($params, make_init_param("sign_excl",
theme_image($link, "images/sign_excl.png")));
array_push($params, make_init_param("sign_info",
theme_image($link, "images/sign_info.png")));
foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS", foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS",
"ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP", "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP",
"CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE", "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE",
"HIDE_READ_SHOWS_SPECIAL", "HIDE_FEEDLIST") as $param) { "HIDE_READ_SHOWS_SPECIAL", "HIDE_FEEDLIST") as $param) {
array_push($params, make_init_param(strtolower($param), $params[strtolower($param)] = (int) get_pref($link, $param);
(int) get_pref($link, $param)));
} }
array_push($params, make_init_param("icons_url", ICONS_URL)); $params["icons_url"] = ICONS_URL;
$params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
array_push($params, make_init_param("cookie_lifetime", SESSION_COOKIE_LIFETIME)); $params["default_view_mode"] = get_pref($link, "_DEFAULT_VIEW_MODE");
$params["default_view_limit"] = (int) get_pref($link, "_DEFAULT_VIEW_LIMIT");
array_push($params, make_init_param("default_view_mode", $params["default_view_order_by"] = get_pref($link, "_DEFAULT_VIEW_ORDER_BY");
get_pref($link, "_DEFAULT_VIEW_MODE"))); $params["prefs_active_tab"] = get_pref($link, "_PREFS_ACTIVE_TAB");
$params["infobox_disable_overlay"] = get_pref($link, "_INFOBOX_DISABLE_OVERLAY");
array_push($params, make_init_param("default_view_limit", $params["bw_limit"] = (int) $_SESSION["bw_limit"];
(int) get_pref($link, "_DEFAULT_VIEW_LIMIT"))); $params["offline_enabled"] = (int) get_pref($link, "ENABLE_OFFLINE_READING");
array_push($params, make_init_param("default_view_order_by",
get_pref($link, "_DEFAULT_VIEW_ORDER_BY")));
array_push($params, make_init_param("prefs_active_tab",
get_pref($link, "_PREFS_ACTIVE_TAB")));
array_push($params, make_init_param("infobox_disable_overlay",
get_pref($link, "_INFOBOX_DISABLE_OVERLAY")));
array_push($params, make_init_param("bw_limit",
(int) $_SESSION["bw_limit"]));
array_push($params, make_init_param("offline_enabled",
(int) get_pref($link, "ENABLE_OFFLINE_READING")));
$result = db_query($link, "SELECT COUNT(*) AS cf FROM $result = db_query($link, "SELECT COUNT(*) AS cf FROM
ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
$num_feeds = db_fetch_result($result, 0, "cf"); $num_feeds = db_fetch_result($result, 0, "cf");
array_push($params, make_init_param("num_feeds", $params["num_feeds"] = (int) $num_feeds;
(int) $num_feeds)); $params["collapsed_feedlist"] = (int) get_pref($link, "_COLLAPSED_FEEDLIST");
array_push($params, make_init_param("collapsed_feedlist",
(int) get_pref($link, "_COLLAPSED_FEEDLIST")));
return $params; return $params;
} }
function print_runtime_info($link) { function print_runtime_info($link) {
print "<runtime-info>"; print "<runtime-info><![CDATA[";
print json_encode(make_runtime_info($link));
print "]]></runtime-info>";
}
function make_runtime_info($link) {
$result = db_query($link, "SELECT COUNT(*) AS cf FROM $result = db_query($link, "SELECT COUNT(*) AS cf FROM
ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
$num_feeds = db_fetch_result($result, 0, "cf"); $num_feeds = db_fetch_result($result, 0, "cf");
print "<param key=\"num_feeds\" value=\"". $data = array();
(int)$num_feeds. "\"/>";
$data['num_feeds'] = (int) $num_feeds;
if (ENABLE_UPDATE_DAEMON) { if (ENABLE_UPDATE_DAEMON) {
print "<param key=\"daemon_is_running\" value=\"".
(int) file_is_locked("update_daemon.lock") . "\"/>"; $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
if (time() - $_SESSION["daemon_stamp_check"] > 30) { if (time() - $_SESSION["daemon_stamp_check"] > 30) {
@ -3222,11 +3201,11 @@
$_SESSION["daemon_stamp_check"] = time(); $_SESSION["daemon_stamp_check"] = time();
} }
print "<param key=\"daemon_stamp_ok\" value=\"$stamp_check\"/>"; $data['daemon_stamp_ok'] = $stamp_check;
$stamp_fmt = date("Y.m.d, G:i", $stamp); $stamp_fmt = date("Y.m.d, G:i", $stamp);
print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>"; $data['daemon_stamp'] = $stamp_fmt;
} }
} }
} }
@ -3245,7 +3224,7 @@
// print "<param key=\"new_version_available\" value=\"1\"/>"; // print "<param key=\"new_version_available\" value=\"1\"/>";
print "</runtime-info>"; return $data;
} }
function getSearchSql($search, $match_on) { function getSearchSql($search, $match_on) {

View File

@ -579,18 +579,17 @@ function toggleDispRead() {
} }
function parse_runtime_info(elem) { function parse_runtime_info(elem) {
if (!elem) {
console.log("parse_runtime_info: elem is null, aborting"); if (!elem || !elem.firstChild) {
return; return;
} }
var param = elem.firstChild; var data = JSON.parse(elem.firstChild.nodeValue);
console.log("parse_runtime_info: " + param); console.log("parsing runtime info...");
while (param) { for (k in data) {
var k = param.getAttribute("key"); var v = data[k];
var v = param.getAttribute("value");
console.log("RI: " + k + " => " + v); console.log("RI: " + k + " => " + v);
@ -623,18 +622,8 @@ function parse_runtime_info(elem) {
if (!error_flag) { if (!error_flag) {
notify(''); notify('');
} }
/* var w = $("noDaemonWarning");
if (w) {
if (k == "daemon_is_running" && v != 1) {
w.style.display = "block";
} else {
w.style.display = "none";
}
} */
param = param.nextSibling;
} }
} }