From a5819bb35d94e318d3d221dd7bbc4bea36c24ef0 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@bah.org.ru>
Date: Wed, 13 Jan 2010 12:48:49 +0300
Subject: [PATCH] code cleanup; remove unnecessary callbacks; rework
 subscribtion dialog

---
 functions.js             | 159 +++++++++++++++------------------------
 functions.php            |  42 +++++++----
 modules/backend-rpc.php  |  17 +++++
 modules/popup-dialog.php |  14 ++--
 modules/pref-feeds.php   | 128 +++++++++++++++----------------
 prefs.js                 |  80 ++++----------------
 tt-rss.css               |   4 -
 tt-rss.js                |  27 +------
 viewfeed.js              | 149 +++++++++++++++---------------------
 9 files changed, 251 insertions(+), 369 deletions(-)

diff --git a/functions.js b/functions.js
index a5d803c9f..ea3fcb7be 100644
--- a/functions.js
+++ b/functions.js
@@ -84,44 +84,6 @@ function enableHotkeys() {
 	hotkeys_enabled = true;
 }
 
-function open_article_callback(transport) {
-	try {
-
-		if (transport.responseXML) {
-			
-			var link = transport.responseXML.getElementsByTagName("link")[0];
-			var id = transport.responseXML.getElementsByTagName("id")[0];
-
-			debug("open_article_callback, received link: " + link);
-
-			if (link && id) {
-
-				var wname = "ttrss_article_" + id.firstChild.nodeValue;
-
-				debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
-
-				var w = window.open(link.firstChild.nodeValue, wname);
-
-				if (!w) { notify_error("Failed to load article in new window"); }
-
-				if (id) {
-					id = id.firstChild.nodeValue;
-					if (!$("headlinesList")) {
-						window.setTimeout("toggleUnread(" + id + ", 0)", 100);
-					}
-				}
-			} else {
-				notify_error("Can't open article: received invalid article link");
-			}
-		} else {
-			notify_error("Can't open article: received invalid XML");
-		}
-
-	} catch (e) {
-		exception_error("open_article_callback", e);
-	}
-}
-
 function param_escape(arg) {
 	if (typeof encodeURIComponent != 'undefined')
 		return encodeURIComponent(arg);	
@@ -1406,20 +1368,14 @@ function createFilter() {
 	}
 }
 
-function toggleSubmitNotEmpty(e, submit_id) {
-	try {
-		$(submit_id).disabled = (e.value == "")
-	} catch (e) {
-		exception_error("toggleSubmitNotEmpty", e);
-	}
-}
-
 function isValidURL(s) {
 	return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
 }
 
 function subscribeToFeed() {
 
+	try {
+
 	var form = document.forms['feed_add_form'];
 	var feed_url = form.feed_url.value;
 
@@ -1430,22 +1386,49 @@ function subscribeToFeed() {
 
 	notify_progress(__("Subscribing to feed..."), true);
 
-	closeInfoBox();
-
-	var feeds_doc = document;
-
-//	feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
-	
 	var query = Form.serialize("feed_add_form");
 	
 	debug("subscribe q: " + query);
 
+	Form.disable("feed_add_form");
+
 	new Ajax.Request("backend.php", {
 		parameters: query,
 		onComplete: function(transport) { 
-			dlg_frefresh_callback(transport); 
+			//dlg_frefresh_callback(transport); 
+
+			notify('');
+
+			var result = transport.responseXML.getElementsByTagName('result')[0];
+			var rc = parseInt(result.getAttribute('code'));
+
+			Form.enable("feed_add_form");
+
+			switch (rc) {
+			case 1:
+				closeInfoBox();
+				notify_info(__("Subscribed to %s").replace("%s", feed_url));
+
+				if (inPreferences()) {
+					updateFeedList();
+				} else {
+					setTimeout('updateFeedList(false, false)', 50);
+				}
+				break;
+			case 2:
+				alert(__("Can't subscribe to the specified URL."));
+				break;
+			case 0:
+				alert(__("You are already subscribed to this feed."));
+				break;
+			}
+
 		} });
 
+	} catch (e) {
+		exception_error("subscribeToFeed", e);
+	}
+
 	return false;
 }
 
@@ -1739,9 +1722,32 @@ function openArticleInNewWindow(id) {
 		new Ajax.Request("backend.php", {
 			parameters: query,
 			onComplete: function(transport) { 
-				open_article_callback(transport); 
-			} });
 
+					var link = transport.responseXML.getElementsByTagName("link")[0];
+					var id = transport.responseXML.getElementsByTagName("id")[0];
+		
+					debug("open_article received link: " + link);
+		
+					if (link && id) {
+		
+						var wname = "ttrss_article_" + id.firstChild.nodeValue;
+		
+						debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
+		
+						var w = window.open(link.firstChild.nodeValue, wname);
+		
+						if (!w) { notify_error("Failed to load article in new window"); }
+		
+						if (id) {
+							id = id.firstChild.nodeValue;
+							if (!$("headlinesList")) {
+								window.setTimeout("toggleUnread(" + id + ", 0)", 100);
+							}
+						}
+					} else {
+						notify_error("Can't open article: received invalid article link");
+					}
+				} });
 
 	} catch (e) {
 		exception_error("openArticleInNewWindow", e);
@@ -1778,49 +1784,6 @@ Position.Center = function(element, parent) {
 }
 
 
-function labeltest_callback(transport) {
-	try {
-		var container = $('label_test_result');
-	
-		container.innerHTML = transport.responseText;
-		if (!Element.visible(container)) {
-			Effect.SlideDown(container, { duration : 0.5 });
-		}
-
-		notify("");
-	} catch (e) {
-		exception_error("labeltest_callback", e);
-	}
-}
-
-function labelTest() {
-
-	try {
-		var container = $('label_test_result');
-	
-		var form = document.forms['label_edit_form'];
-	
-		var sql_exp = form.sql_exp.value;
-		var description = form.description.value;
-	
-		notify_progress("Loading, please wait...");
-	
-		var query = "?op=pref-labels&subop=test&expr=" +
-			param_escape(sql_exp) + "&descr=" + param_escape(description);
-	
-		new Ajax.Request("backend.php", {
-			parameters: query,
-			onComplete: function (transport) {
-				labeltest_callback(transport);
-			} });
-	
-		return false;
-
-	} catch (e) {
-		exception_error("labelTest", e);
-	}
-}
-
 function isCdmMode() {
 	return !$("headlinesList");
 }
diff --git a/functions.php b/functions.php
index 54385a4a7..a0ec1c3fb 100644
--- a/functions.php
+++ b/functions.php
@@ -2836,18 +2836,16 @@
 		print "</rpc-reply>";
 	}
 
-	function subscribe_to_feed($link, $feed_link, $cat_id = 0, 
+	function subscribe_to_feed($link, $url, $cat_id = 0, 
 			$auth_login = '', $auth_pass = '') {
 
-		# check for feed:http://url
-		$feed_link = trim(preg_replace("/^feed:/", "", $feed_link));
+		$parts = parse_url($url);
 
-		# check for feed://URL
-		if (strpos($feed_link, "//") === 0) {
-			$feed_link = "http:$feed_link";
-		}
+		if (!validate_feed_url($url)) return 2;
 
-		if ($feed_link == "") return;
+		if ($parts['scheme'] == 'feed') $parts['scheme'] = 'http';
+
+		$url = make_url_from_parts($parts);
 
 		if ($cat_id == "0" || !$cat_id) {
 			$cat_qpart = "NULL";
@@ -2857,29 +2855,29 @@
 	
 		$result = db_query($link,
 			"SELECT id FROM ttrss_feeds 
-			WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
+			WHERE feed_url = '$url' AND owner_uid = ".$_SESSION["uid"]);
 	
 		if (db_num_rows($result) == 0) {
 			
 			$result = db_query($link,
 				"INSERT INTO ttrss_feeds 
 					(owner_uid,feed_url,title,cat_id, auth_login,auth_pass) 
-				VALUES ('".$_SESSION["uid"]."', '$feed_link', 
+				VALUES ('".$_SESSION["uid"]."', '$url', 
 				'[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')");
 	
 			$result = db_query($link,
-				"SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' 
+				"SELECT id FROM ttrss_feeds WHERE feed_url = '$url' 
 					AND owner_uid = " . $_SESSION["uid"]);
 	
 			$feed_id = db_fetch_result($result, 0, "id");
 	
 			if ($feed_id) {
-				update_rss_feed($link, $feed_link, $feed_id, true);
+				update_rss_feed($link, $url, $feed_id, true);
 			}
 
-			return true;
+			return 1;
 		} else {
-			return false;
+			return 0;
 		}
 	}
 
@@ -6401,4 +6399,20 @@
 			return 0;
 		}
 	}
+
+	function make_url_from_parts($parts) {
+		$url = $parts['scheme'] . '://' . $parts['host'];
+
+		if ($parts['path']) $url .= $parts['path'];
+		if ($parts['query']) $url .= '?' . $parts['query'];
+
+		return $url;
+	}
+
+	function validate_feed_url($url) {
+		$parts = parse_url($url);
+
+		return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https');
+
+	}
 ?>
diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php
index 4bf633d2f..e10a20de3 100644
--- a/modules/backend-rpc.php
+++ b/modules/backend-rpc.php
@@ -3,6 +3,23 @@
 
 		$subop = $_REQUEST["subop"];
 
+		if ($subop == "addfeed") {
+
+			$feed = db_escape_string($_REQUEST['feed']);
+			$cat = db_escape_string($_REQUEST['cat']);
+			$login = db_escape_string($_REQUEST['login']);
+			$pass = db_escape_string($_REQUEST['pass']);
+
+			$rc = subscribe_to_feed($link, $feed, $cat, $login, $pass);
+
+			print "<rpc-reply>";
+			print "<result code='$rc'/>";
+			print "</rpc-reply>";
+
+			return;
+
+		}
+
 		if ($subop == "setpref") {
 			if (WEB_DEMO_MODE) {
 				return;
diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php
index a035cfe91..b5aae1846 100644
--- a/modules/popup-dialog.php
+++ b/modules/popup-dialog.php
@@ -90,9 +90,9 @@
 
 			print "<form id='feed_add_form' onsubmit='return false'>";
 
-			print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
-			print "<input type=\"hidden\" name=\"subop\" value=\"add\">"; 
-			print "<input type=\"hidden\" name=\"from\" value=\"tt-rss\">"; 
+			print "<input type=\"hidden\" name=\"op\" value=\"rpc\">";
+			print "<input type=\"hidden\" name=\"subop\" value=\"addfeed\">"; 
+			//print "<input type=\"hidden\" name=\"from\" value=\"tt-rss\">"; 
 
 			print "<div class=\"dlgSec\">".__("Feed")."</div>";
 			print "<div class=\"dlgSecCont\">";
@@ -101,13 +101,13 @@
 
 			print "<input size=\"40\"
 					onkeypress=\"return filterCR(event, subscribeToFeed)\"
-					name=\"feed_url\" id=\"feed_url\"></td></tr>";
+					name=\"feed\" id=\"feed_url\"></td></tr>";
 
 			print "<br/>";
 
 			if (get_pref($link, 'ENABLE_FEED_CATS')) {
 				print __('Place in category:') . " ";
-				print_feed_cat_select($link, "cat_id");			
+				print_feed_cat_select($link, "cat");			
 			}
 
 			print "</div>";
@@ -117,10 +117,10 @@
 					<div class=\"dlgSec\">".__("Authentication")."</div>
 					<div class=\"dlgSecCont\">".
 
-					__('Login:') . " <input name='auth_login' size=\"20\" 
+					__('Login:') . " <input name='login' size=\"20\" 
 							onkeypress=\"return filterCR(event, subscribeToFeed)\"> ".
 					__('Password:') . "<input type='password'
-							name='auth_pass' size=\"20\" 
+							name='pass' size=\"20\" 
 							onkeypress=\"return filterCR(event, subscribeToFeed)\">
 				</div></div>";
 
diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php
index c1190b549..9d33461af 100644
--- a/modules/pref-feeds.php
+++ b/modules/pref-feeds.php
@@ -819,67 +819,71 @@
 		}
 
 		if ($subop == "add") {
-		
-			if (!WEB_DEMO_MODE) {
 
-				$feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
-				$cat_id = db_escape_string($_REQUEST["cat_id"]);
-				$p_from = db_escape_string($_REQUEST["from"]);
+			$feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
+			$cat_id = db_escape_string($_REQUEST["cat_id"]);
+			$p_from = db_escape_string($_REQUEST["from"]);
 
-				/* only read authentication information from POST */
+			/* only read authentication information from POST */
 
-				$auth_login = db_escape_string(trim($_POST["auth_login"]));
-				$auth_pass = db_escape_string(trim($_POST["auth_pass"]));
+			$auth_login = db_escape_string(trim($_POST["auth_login"]));
+			$auth_pass = db_escape_string(trim($_POST["auth_pass"]));
 
-				if ($p_from != 'tt-rss') {
-					print "<html>
-						<head>
-							<title>Tiny Tiny RSS</title>
-							<link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
-						</head>
-						<body>
-						<img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
-					  		alt=\"Tiny Tiny RSS\"/>	
-						<h1>Subscribe to feed...</h1>";
+			if ($p_from != 'tt-rss') {
+				print "<html>
+					<head>
+						<title>Tiny Tiny RSS</title>
+						<link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
+					</head>
+					<body>
+					<img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
+				  		alt=\"Tiny Tiny RSS\"/>	
+					<h1>Subscribe to feed...</h1>";
+			}
+
+			$rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
+
+			switch ($rc) {
+			case 1: 
+				print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
+				break;
+			case 2:
+				print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
+				break;
+			case 0:
+				print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
+				break;
+			}
+
+			if ($p_from != 'tt-rss') {
+				$tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
+
+
+				$tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
+
+				$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+					feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+
+				$feed_id = db_fetch_result($result, 0, "id");
+
+				print "<p>";
+
+				if ($feed_id) {
+					print "<form method=\"GET\" style='display: inline' 
+						action=\"$tp_uri\">
+						<input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
+						<input type=\"hidden\" name=\"subop\" value=\"editFeed\">
+						<input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
+						<input type=\"submit\" value=\"".__("Edit subscription options")."\">
+						</form>";
 				}
 
-				if (subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass)) {
-					print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
-				} else {
-					print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
-				}
-
-				if ($p_from != 'tt-rss') {
-					$tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
-
-
-					$tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
-
-					$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
-						feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
-
-					$feed_id = db_fetch_result($result, 0, "id");
-
-					print "<p>";
-
-					if ($feed_id) {
-						print "<form method=\"GET\" style='display: inline' 
-							action=\"$tp_uri\">
-							<input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
-							<input type=\"hidden\" name=\"subop\" value=\"editFeed\">
-							<input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
-							<input type=\"submit\" value=\"".__("Edit subscription options")."\">
-							</form>";
-					}
-
-					print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
-						<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
-						</form></p>";
-
-					print "</body></html>";
-					return;
-				}
+				print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
+					<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+					</form></p>";
 
+				print "</body></html>";
+				return;
 			}
 		}
 
@@ -1358,21 +1362,6 @@
 
 			print "<p>";
 
-/*			print "<div id=\"feedOpToolbar\">";
-
-			if (get_pref($link, 'ENABLE_FEED_CATS')) {
-
-				print __('Selection:') . " ";
-
-				print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
-
-				print " <input type=\"submit\" class=\"button\" disabled=\"true\"
-					onclick=\"javascript:categorizeSelectedFeeds()\" value=\"".
-					__('Recategorize')."\">";
-			}
-				
-			print "</div>"; */
-
 		} else {
 
 			print "<p>";
@@ -1538,4 +1527,5 @@
 		return $feedctr;
 
 	}
+
 ?>
diff --git a/prefs.js b/prefs.js
index 1a48571cd..bf2574445 100644
--- a/prefs.js
+++ b/prefs.js
@@ -39,12 +39,6 @@ function feedlist_callback2(transport) {
 	}
 }
 
-/* stub for subscription dialog */
-
-function dlg_frefresh_callback(transport) {
-	return feedlist_callback2(transport);
-}
-
 function filterlist_callback2(transport) {
 	var container = $('prefContent');
 	container.innerHTML=transport.responseText;
@@ -127,34 +121,6 @@ function notify_callback2(transport) {
 	notify_info(transport.responseText);	 
 }
 
-function prefs_reset_callback2(transport) {
-	try {
-		notify_info(transport.responseText);
-		selectTab();
-	} catch (e) {
-		exception_error("prefs_reset_callback2", e);
-	}
-}
-
-
-function changepass_callback2(transport) {
-	try {
-	
-			if (transport.responseText.indexOf("ERROR: ") == 0) {
-				notify_error(transport.responseText.replace("ERROR: ", ""));
-			} else {
-				notify_info(transport.responseText);
-				var warn = $("default_pass_warning");
-				if (warn) warn.style.display = "none";
-			}
-	
-			document.forms['change_pass_form'].reset();
-
-	} catch (e) {
-		exception_error("changepass_callback2", e);
-	}
-}
-
 function init_cat_inline_editor() {
 	try {
 
@@ -1221,34 +1187,6 @@ function init() {
 	}
 }
 
-function categorizeSelectedFeeds() {
-
-	var sel_rows = getSelectedFeeds();
-
-	var cat_sel = $("sfeed_set_fcat");
-	var cat_id = cat_sel[cat_sel.selectedIndex].value;
-
-	if (sel_rows.length > 0) {
-
-		notify_progress("Changing category of selected feeds...");
-
-		var query = "?op=pref-feeds&subop=categorize&ids="+
-			param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id);
-
-		new Ajax.Request("backend.php", {
-			parameters: query,
-			onComplete: function(transport) { 
-				feedlist_callback2(transport); 
-			} });
-
-	} else {
-
-		alert(__("No feeds are selected."));
-
-	}
-
-}
-
 function validatePrefsReset() {
 	try {
 		var ok = confirm(__("Reset to defaults?"));
@@ -1262,7 +1200,8 @@ function validatePrefsReset() {
 			new Ajax.Request("backend.php", {
 				parameters: query,
 				onComplete: function(transport) { 
-					prefs_reset_callback2(transport);
+					notify_info(transport.responseText);
+					selectTab();
 				} });
 
 		}
@@ -1644,12 +1583,20 @@ function changeUserPassword() {
 
 		var query = Form.serialize("change_pass_form");
 	
-		notify_progress("Trying to change password...");
+		notify_progress("Changing password...");
 
 		new Ajax.Request("backend.php", {
 			parameters: query,
 			onComplete: function(transport) { 
-				changepass_callback2(transport); 
+				if (transport.responseText.indexOf("ERROR: ") == 0) {
+					notify_error(transport.responseText.replace("ERROR: ", ""));
+				} else {
+					notify_info(transport.responseText);
+					var warn = $("default_pass_warning");
+					if (warn) warn.style.display = "none";
+				}
+		
+				document.forms['change_pass_form'].reset();
 			} });
 
 
@@ -2154,3 +2101,6 @@ function mouse_up_handler(e) {
 	}
 }
 
+function inPreferences() {
+	return true;
+}
diff --git a/tt-rss.css b/tt-rss.css
index fc42bb0ad..f8204924f 100644
--- a/tt-rss.css
+++ b/tt-rss.css
@@ -1893,10 +1893,6 @@ div.dlgButtons {
 	clear : both;
 }
 
-div#label_test_result {
-	clear : both;
-}
-
 pre, code {
 	font-size : 12px;
 	font-family : monospace;
diff --git a/tt-rss.js b/tt-rss.js
index fefbf963a..eef469c4f 100644
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -98,27 +98,6 @@ function dlg_frefresh_callback(transport, deleted_feed) {
 	closeInfoBox();
 }
 
-function refetch_callback2(transport) {
-	try {
-
-		var date = new Date();
-
-		parse_counters_reply(transport, true);
-
-		debug("refetch_callback2: done");
-
-/*		if (!daemon_enabled && !daemon_refresh_only) {
-			notify_info("All feeds updated.");
-			updateTitle("");
-		} else {
-			//notify("");
-		} */
-	} catch (e) {
-		exception_error("refetch_callback", e);
-		updateTitle("");
-	}
-}
-
 function backend_sanity_check_callback(transport) {
 
 	try {
@@ -232,7 +211,7 @@ function scheduleFeedUpdate(force) {
 	new Ajax.Request("backend.php", {
 		parameters: query_str,
 		onComplete: function(transport) { 
-				refetch_callback2(transport); 
+				parse_counters_reply(transport, true);
 			} });
 }
 
@@ -1524,4 +1503,6 @@ function feedBrowserSubscribe() {
 	}
 }
 
-
+function inPreferences() {
+	return false;
+}
diff --git a/viewfeed.js b/viewfeed.js
index d2425d99c..028ad68f1 100644
--- a/viewfeed.js
+++ b/viewfeed.js
@@ -15,39 +15,6 @@ var post_under_pointer = false;
 
 var last_requested_article = false;
 
-function toggle_published_callback(transport) {
-	try {
-		if (transport.responseXML) {
-
-			all_counters_callback2(transport);
-
-			var note = transport.responseXML.getElementsByTagName("note")[0];
-
-			if (note) {
-				var note_id = note.getAttribute("id");
-				var note_size = note.getAttribute("size");
-				var note_content = note.firstChild.nodeValue;
-
-				var container = $('POSTNOTE-' + note_id);
-
-				cache_invalidate(note_id);
-
-				if (container) {
-					if (note_size == "0") {
-						Element.hide(container);
-					} else {
-						container.innerHTML = note_content;
-						Element.show(container);
-					}
-				}
-			}	
-		}
-
-	} catch (e) {
-		exception_error("toggle_published_callback", e, transport);
-	}
-}
-
 function catchup_callback2(transport, callback) {
 	try {
 		debug("catchup_callback2 " + transport + ", " + callback);
@@ -720,12 +687,33 @@ function togglePub(id, client_only, no_effects, note) {
 			new Ajax.Request("backend.php", {
 				parameters: query,
 				onComplete: function(transport) { 
-					toggle_published_callback(transport); 
+					all_counters_callback2(transport);
+		
+					var note = transport.responseXML.getElementsByTagName("note")[0];
+		
+					if (note) {
+						var note_id = note.getAttribute("id");
+						var note_size = note.getAttribute("size");
+						var note_content = note.firstChild.nodeValue;
+		
+						var container = $('POSTNOTE-' + note_id);
+		
+						cache_invalidate(note_id);
+		
+						if (container) {
+							if (note_size == "0") {
+								Element.hide(container);
+							} else {
+								container.innerHTML = note_content;
+								Element.show(container);
+							}
+						}
+					}	
+
 				} });
 		}
 
 	} catch (e) {
-
 		exception_error("togglePub", e);
 	}
 }
@@ -1476,39 +1464,6 @@ function editArticleTags(id, feed_id, cdm_enabled) {
 			   });
 }
 
-
-function tag_saved_callback(transport) {
-	try {
-		debug("in tag_saved_callback");
-
-		closeInfoBox();
-		notify("");
-
-		if (tagsAreDisplayed()) {
-			_reload_feedlist_after_view = true;
-		}
-
-
-		if (transport.responseXML) {
-			var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
-			
-			if (tags_str) {
-				var id = tags_str.getAttribute("id");
-
-				if (id) {
-					var tags = $("ATSTR-" + id);
-					if (tags) {
-						tags.innerHTML = tags_str.firstChild.nodeValue;
-					}
-				}
-			}
-		}
-
-	} catch (e) {
-		exception_error("tag_saved_callback", e);
-	}
-}
-
 function editTagsSave() {
 
 	notify_progress("Saving article tags...");
@@ -1524,9 +1479,35 @@ function editTagsSave() {
 	new Ajax.Request("backend.php",	{
 		parameters: query,
 		onComplete: function(transport) {
-				tag_saved_callback(transport);
+				try {
+					debug("tags saved...");
+			
+					closeInfoBox();
+					notify("");
+			
+					if (tagsAreDisplayed()) {
+						_reload_feedlist_after_view = true;
+					}			
+			
+					if (transport.responseXML) {
+						var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
+						
+						if (tags_str) {
+							var id = tags_str.getAttribute("id");
+			
+							if (id) {
+								var tags = $("ATSTR-" + id);
+								if (tags) {
+									tags.innerHTML = tags_str.firstChild.nodeValue;
+								}
+							}
+						}
+					}
+			
+				} catch (e) {
+					exception_error("editTagsSave", e);
+				}
 			} });
-
 }
 
 function editTagsInsert() {
@@ -1934,24 +1915,6 @@ function cdmClicked(id) {
 	} 
 }
 
-function preload_article_callback(transport) {
-	try {
-		if (transport.responseXML) {
-			var articles = transport.responseXML.getElementsByTagName("article");
-
-			for (var i = 0; i < articles.length; i++) {
-				var id = articles[i].getAttribute("id");
-				if (!cache_check(id)) {
-					cache_inject(id, articles[i].firstChild.nodeValue);				
-					debug("preloaded article: " + id);
-				}
-			}
-		}
-	} catch (e) {
-		exception_error("preload_article_callback", e);
-	}
-}
-
 function preloadArticleUnderPointer(id) {
 	try {
 		if (getInitParam("bw_limit") == "1") return;
@@ -1981,7 +1944,15 @@ function preloadArticleUnderPointer(id) {
 			new Ajax.Request("backend.php", {
 				parameters: query,
 				onComplete: function(transport) { 
-					preload_article_callback(transport);
+					var articles = transport.responseXML.getElementsByTagName("article");
+
+					for (var i = 0; i < articles.length; i++) {
+						var id = articles[i].getAttribute("id");
+						if (!cache_check(id)) {
+							cache_inject(id, articles[i].firstChild.nodeValue);				
+							debug("preloaded article: " + id);
+						}
+					}
 			} });
 		}
 	} catch (e) {