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);
}
}
-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;
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;
}
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);
}
-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");
}
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 ($parts['scheme'] == 'feed') $parts['scheme'] = 'http';
- if ($feed_link == "") return;
+ $url = make_url_from_parts($parts);
if ($cat_id == "0" || !$cat_id) {
$cat_qpart = "NULL";
$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;
}
}
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');
+
+ }
?>
$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;
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\">";
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>";
<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>";
}
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"]);
-
- /* only read authentication information from POST */
-
- $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>";
- }
+ $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
+ $cat_id = db_escape_string($_REQUEST["cat_id"]);
+ $p_from = db_escape_string($_REQUEST["from"]);
- 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));
- }
+ /* only read authentication information from POST */
- 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"]);
+ $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>";
+ }
- $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
+ $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;
+ }
- $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
- feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+ 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"]);
- $feed_id = db_fetch_result($result, 0, "id");
- print "<p>";
+ $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
- 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>";
- }
+ $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+ feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
- print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
- <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
- </form></p>";
+ $feed_id = db_fetch_result($result, 0, "id");
- print "</body></html>";
- return;
+ 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 "<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>";
return $feedctr;
}
+
?>
}
}
-/* stub for subscription dialog */
-
-function dlg_frefresh_callback(transport) {
- return feedlist_callback2(transport);
-}
-
function filterlist_callback2(transport) {
var container = $('prefContent');
container.innerHTML=transport.responseText;
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 {
}
}
-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?"));
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
- prefs_reset_callback2(transport);
+ notify_info(transport.responseText);
+ selectTab();
} });
}
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();
} });
}
}
+function inPreferences() {
+ return true;
+}
clear : both;
}
-div#label_test_result {
- clear : both;
-}
-
pre, code {
font-size : 12px;
font-family : monospace;
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 {
new Ajax.Request("backend.php", {
parameters: query_str,
onComplete: function(transport) {
- refetch_callback2(transport);
+ parse_counters_reply(transport, true);
} });
}
}
}
-
+function inPreferences() {
+ return 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);
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);
}
}
});
}
-
-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...");
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() {
}
}
-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;
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) {