1 var loading_progress = 0;
2 var sanity_check_done = false;
4 var _label_base_index = -1024;
5 var notify_hide_timerid = false;
7 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
8 function (callOriginal, options) {
10 if (getInitParam("csrf_token") != undefined) {
11 Object.extend(options, options || { });
13 if (Object.isString(options.parameters))
14 options.parameters = options.parameters.toQueryParams();
15 else if (Object.isHash(options.parameters))
16 options.parameters = options.parameters.toObject();
18 options.parameters["csrf_token"] = getInitParam("csrf_token");
21 return callOriginal(options);
25 /* add method to remove element from array */
27 Array.prototype.remove = function(s) {
28 for (var i=0; i < this.length; i++) {
29 if (s == this[i]) this.splice(i, 1);
33 /* create console.log if it doesn't exist */
35 if (!window.console) console = {};
36 console.log = console.log || function(msg) { };
37 console.warn = console.warn || function(msg) { };
38 console.error = console.error || function(msg) { };
40 function exception_error(location, e, ext_info) {
41 var msg = format_exception_error(location, e);
43 if (!ext_info) ext_info = false;
48 if (ext_info.responseText) {
49 ext_info = ext_info.responseText;
54 new Ajax.Request("backend.php", {
55 parameters: {op: "rpc", method: "log", logmsg: msg},
56 onComplete: function (transport) {
57 console.log(transport.responseText);
61 console.log("Exception while trying to log the error.");
65 msg += "<p>"+ __("The error will be reported to the configured log destination.") +
68 var content = "<div class=\"fatalError\">" +
69 "<pre>" + msg + "</pre>";
71 content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+
72 "action=\"http://tt-rss.org/report.php\" method=\"POST\">";
74 content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>";
75 content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>";
78 content += "<div><b>Additional information:</b></div>" +
79 "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>";
82 content += "<div><b>Stack trace:</b></div>" +
83 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
89 content += "<div class='dlgButtons'>";
91 content += "<button dojoType=\"dijit.form.Button\""+
92 "onclick=\"dijit.byId('exceptionDlg').report()\">" +
93 __('Report to tt-rss.org') + "</button> ";
94 content += "<button dojoType=\"dijit.form.Button\" "+
95 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
96 __('Close') + "</button>";
99 if (dijit.byId("exceptionDlg"))
100 dijit.byId("exceptionDlg").destroyRecursive();
102 var dialog = new dijit.Dialog({
104 title: "Unhandled exception",
105 style: "width: 600px",
107 if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) {
109 document.forms['exceptionForm'].params.value = $H({
110 browserName: navigator.appName,
111 browserVersion: navigator.appVersion,
112 browserPlatform: navigator.platform,
113 browserCookies: navigator.cookieEnabled,
116 document.forms['exceptionForm'].submit();
125 console.log("Exception while trying to report an exception. Oh boy.");
127 console.log("Original exception:");
130 msg += "\n\nAdditional exception caught while trying to show the error dialog.\n\n" + format_exception_error('exception_error', ei);
133 new Ajax.Request("backend.php", {
134 parameters: {op: "rpc", method: "log", logmsg: msg},
135 onComplete: function (transport) {
136 console.log(transport.responseText);
140 console.log("Third exception while trying to log the error! Seriously?");
144 msg += "\n\nThe error will be reported to the configured log destination.";
151 function format_exception_error(location, e) {
155 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
157 msg = "Exception: " + e.name + ", " + e.message +
158 "\nFunction: " + location + "()" +
159 "\nLocation: " + base_fname + ":" + e.lineNumber;
161 } else if (e.description) {
162 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
164 msg = "Exception: " + e + "\nFunction: " + location + "()";
167 console.error("EXCEPTION: " + msg);
172 function param_escape(arg) {
173 if (typeof encodeURIComponent != 'undefined')
174 return encodeURIComponent(arg);
179 function param_unescape(arg) {
180 if (typeof decodeURIComponent != 'undefined')
181 return decodeURIComponent(arg);
183 return unescape(arg);
187 function hide_notify() {
188 Element.hide('notify');
191 function notify_real(msg, no_hide, n_type) {
197 if (notify_hide_timerid) {
198 window.clearTimeout(notify_hide_timerid);
202 if (Element.visible(n)) {
203 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
219 msg = "<span class=\"msg\"> " + __(msg) + "</span>";
222 n.className = "notify";
223 } else if (n_type == 2) {
224 n.className = "notify progress";
225 msg = "<span><img src='images/indicator_white.gif'></span>" + msg;
227 } else if (n_type == 3) {
228 n.className = "notify error";
229 msg = "<span><img src='images/alert.png'></span>" + msg;
230 } else if (n_type == 4) {
231 n.className = "notify info";
232 msg = "<span><img src='images/information.png'></span>" + msg;
235 msg += " <span><img src=\"images/cross.png\" class=\"close\" title=\"" +
236 __("Click to close") + "\" onclick=\"notify('')\"></span>";
238 // msg = "<img src='images/live_com_loading.gif'> " + msg;
243 notify_hide_timerid = window.setTimeout("hide_notify()", 5*1000);
247 function notify(msg, no_hide) {
248 notify_real(msg, no_hide, 1);
251 function notify_progress(msg, no_hide) {
252 notify_real(msg, no_hide, 2);
255 function notify_error(msg, no_hide) {
256 notify_real(msg, no_hide, 3);
260 function notify_info(msg, no_hide) {
261 notify_real(msg, no_hide, 4);
264 function setCookie(name, value, lifetime, path, domain, secure) {
270 d.setTime(d.getTime() + (lifetime * 1000));
273 console.log("setCookie: " + name + " => " + value + ": " + d);
275 int_setCookie(name, value, d, path, domain, secure);
279 function int_setCookie(name, value, expires, path, domain, secure) {
280 document.cookie= name + "=" + escape(value) +
281 ((expires) ? "; expires=" + expires.toGMTString() : "") +
282 ((path) ? "; path=" + path : "") +
283 ((domain) ? "; domain=" + domain : "") +
284 ((secure) ? "; secure" : "");
287 function delCookie(name, path, domain) {
288 if (getCookie(name)) {
289 document.cookie = name + "=" +
290 ((path) ? ";path=" + path : "") +
291 ((domain) ? ";domain=" + domain : "" ) +
292 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
297 function getCookie(name) {
299 var dc = document.cookie;
300 var prefix = name + "=";
301 var begin = dc.indexOf("; " + prefix);
303 begin = dc.indexOf(prefix);
304 if (begin != 0) return null;
309 var end = document.cookie.indexOf(";", begin);
313 return unescape(dc.substring(begin + prefix.length, end));
316 function gotoPreferences() {
317 document.location.href = "prefs.php";
320 function gotoLogout() {
321 document.location.href = "backend.php?op=logout";
324 function gotoMain() {
325 document.location.href = "index.php";
328 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
329 * * @author Sundar Dorai-Raj
330 * * Email: sdoraira@vt.edu
331 * * This program is free software; you can redistribute it and/or
332 * * modify it under the terms of the GNU General Public License
333 * * as published by the Free Software Foundation; either version 2
334 * * of the License, or (at your option) any later version,
335 * * provided that any use properly credits the author.
336 * * This program is distributed in the hope that it will be useful,
337 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
338 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
339 * * GNU General Public License for more details at http://www.gnu.org * * */
341 var numbers=".0123456789";
342 function isNumeric(x) {
343 // is x a String or a character?
345 // remove negative sign
347 for(var j=0;j<x.length;j++) {
348 // call isNumeric recursively for each character
349 number=isNumeric(x.substring(j,j+1));
350 if(!number) return number;
355 // if x is number return true
356 if(numbers.indexOf(x)>=0) return true;
362 function toggleSelectRowById(sender, id) {
364 return toggleSelectRow(sender, row);
367 function toggleSelectListRow(sender) {
368 var row = sender.parentNode;
369 return toggleSelectRow(sender, row);
372 /* this is for dijit Checkbox */
373 function toggleSelectListRow2(sender) {
374 var row = sender.domNode.parentNode;
375 return toggleSelectRow(sender, row);
378 /* this is for dijit Checkbox */
379 function toggleSelectRow2(sender, row, is_cdm) {
383 row = sender.domNode.parentNode.parentNode;
385 row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
387 if (sender.checked && !row.hasClassName('Selected'))
388 row.addClassName('Selected');
390 row.removeClassName('Selected');
392 if (typeof updateSelectedPrompt != undefined)
393 updateSelectedPrompt();
397 function toggleSelectRow(sender, row) {
399 if (!row) row = sender.parentNode.parentNode;
401 if (sender.checked && !row.hasClassName('Selected'))
402 row.addClassName('Selected');
404 row.removeClassName('Selected');
406 if (typeof updateSelectedPrompt != undefined)
407 updateSelectedPrompt();
410 function checkboxToggleElement(elem, id) {
412 Effect.Appear(id, {duration : 0.5});
414 Effect.Fade(id, {duration : 0.5});
418 function dropboxSelect(e, v) {
419 for (var i = 0; i < e.length; i++) {
420 if (e[i].value == v) {
427 function getURLParam(param){
428 return String(window.location.href).parseQuery()[param];
431 function closeInfoBox(cleanup) {
433 dialog = dijit.byId("infoBox");
435 if (dialog) dialog.hide();
438 //exception_error("closeInfoBox", e);
444 function displayDlg(title, id, param, callback) {
446 notify_progress("Loading, please wait...", true);
448 var query = "?op=dlg&method=" +
449 param_escape(id) + "¶m=" + param_escape(param);
451 new Ajax.Request("backend.php", {
453 onComplete: function (transport) {
454 infobox_callback2(transport, title);
455 if (callback) callback(transport);
461 function infobox_callback2(transport, title) {
465 if (dijit.byId("infoBox")) {
466 dialog = dijit.byId("infoBox");
469 //console.log("infobox_callback2");
472 var content = transport.responseText;
475 dialog = new dijit.Dialog({
478 style: "width: 600px",
479 onCancel: function() {
482 onExecute: function() {
485 onClose: function() {
490 dialog.attr('title', title);
491 dialog.attr('content', content);
498 exception_error("infobox_callback2", e);
502 function filterCR(e, f)
507 key = window.event.keyCode; //IE
509 key = e.which; //firefox
512 if (typeof f != 'undefined') {
523 function getInitParam(key) {
524 return init_params[key];
527 function setInitParam(key, value) {
528 init_params[key] = value;
531 function fatalError(code, msg, ext_info) {
535 window.location.href = "index.php";
536 } else if (code == 5) {
537 window.location.href = "public.php?op=dbupdate";
540 if (msg == "") msg = "Unknown error";
543 if (ext_info.responseText) {
544 ext_info = ext_info.responseText;
548 if (ERRORS && ERRORS[code] && !msg) {
552 var content = "<div><b>Error code:</b> " + code + "</div>" +
553 "<p>" + msg + "</p>";
556 content = content + "<div><b>Additional information:</b></div>" +
557 "<textarea style='width: 100%' readonly=\"1\">" +
558 ext_info + "</textarea>";
561 var dialog = new dijit.Dialog({
562 title: "Fatal error",
563 style: "width: 600px",
573 exception_error("fatalError", e);
577 function filterDlgCheckAction(sender) {
581 var action = sender.value;
583 var action_param = $("filterDlg_paramBox");
586 console.log("filterDlgCheckAction: can't find action param box!");
590 // if selected action supports parameters, enable params field
591 if (action == 4 || action == 6 || action == 7) {
592 new Effect.Appear(action_param, {duration : 0.5});
594 Element.show(dijit.byId("filterDlg_actionParam").domNode);
595 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
597 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
598 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
601 Element.hide(action_param);
605 exception_error("filterDlgCheckAction", e);
611 function explainError(code) {
612 return displayDlg(__("Error explained"), "explainError", code);
615 function loading_set_progress(p) {
617 loading_progress += p;
619 if (dijit.byId("loading_bar"))
620 dijit.byId("loading_bar").update({progress: loading_progress});
622 if (loading_progress >= 90)
626 exception_error("loading_set_progress", e);
630 function remove_splash() {
632 if (Element.visible("overlay")) {
633 console.log("about to remove splash, OMG!");
634 Element.hide("overlay");
635 console.log("removed splash!");
639 function transport_error_check(transport) {
641 if (transport.responseXML) {
642 var error = transport.responseXML.getElementsByTagName("error")[0];
645 var code = error.getAttribute("error-code");
646 var msg = error.getAttribute("error-msg");
648 fatalError(code, msg);
654 exception_error("check_for_error_xml", e);
659 function strip_tags(s) {
660 return s.replace(/<\/?[^>]+(>|$)/g, "");
663 function truncate_string(s, length) {
664 if (!length) length = 30;
665 var tmp = s.substring(0, length);
666 if (s.length > length) tmp += "…";
670 function hotkey_prefix_timeout() {
673 var date = new Date();
674 var ts = Math.round(date.getTime() / 1000);
676 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
677 console.log("hotkey_prefix seems to be stuck, aborting");
678 hotkey_prefix_pressed = false;
679 hotkey_prefix = false;
680 Element.hide('cmdline');
683 setTimeout("hotkey_prefix_timeout()", 1000);
686 exception_error("hotkey_prefix_timeout", e);
690 function uploadIconHandler(rc) {
694 notify_info("Upload complete.");
695 if (inPreferences()) {
698 setTimeout('updateFeedList(false, false)', 50);
702 notify_error("Upload failed: icon is too big.");
705 notify_error("Upload failed.");
710 exception_error("uploadIconHandler", e);
714 function removeFeedIcon(id) {
718 if (confirm(__("Remove stored feed icon?"))) {
719 var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id);
723 notify_progress("Removing feed icon...", true);
725 new Ajax.Request("backend.php", {
727 onComplete: function(transport) {
728 notify_info("Feed icon removed.");
729 if (inPreferences()) {
732 setTimeout('updateFeedList(false, false)', 50);
739 exception_error("removeFeedIcon", e);
743 function uploadFeedIcon() {
747 var file = $("icon_file");
749 if (file.value.length == 0) {
750 alert(__("Please select an image file to upload."));
752 if (confirm(__("Upload new icon for this feed?"))) {
753 notify_progress("Uploading, please wait...", true);
761 exception_error("uploadFeedIcon", e);
765 function addLabel(select, callback) {
769 var caption = prompt(__("Please enter label caption:"), "");
771 if (caption != undefined) {
774 alert(__("Can't create label: missing caption."));
778 var query = "?op=pref-labels&method=add&caption=" +
779 param_escape(caption);
782 query += "&output=select";
784 notify_progress("Loading, please wait...", true);
786 if (inPreferences() && !select) active_tab = "labelConfig";
788 new Ajax.Request("backend.php", {
790 onComplete: function(transport) {
793 } else if (inPreferences()) {
803 exception_error("addLabel", e);
807 function quickAddFeed() {
809 var query = "backend.php?op=feeds&method=quickAddFeed";
811 // overlapping widgets
812 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
813 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
815 var dialog = new dijit.Dialog({
817 title: __("Subscribe to Feed"),
818 style: "width: 600px",
819 execute: function() {
820 if (this.validate()) {
821 console.log(dojo.objectToQuery(this.attr('value')));
823 var feed_url = this.attr('value').feed;
825 Element.show("feed_add_spinner");
827 new Ajax.Request("backend.php", {
828 parameters: dojo.objectToQuery(this.attr('value')),
829 onComplete: function(transport) {
832 var reply = JSON.parse(transport.responseText);
834 var rc = reply['result'];
837 Element.hide("feed_add_spinner");
841 switch (parseInt(rc['code'])) {
844 notify_info(__("Subscribed to %s").replace("%s", feed_url));
849 alert(__("Specified URL seems to be invalid."));
852 alert(__("Specified URL doesn't seem to contain any feeds."));
857 var select = dijit.byId("feedDlg_feedContainerSelect");
859 while (select.getOptions().length > 0)
860 select.removeOption(0);
862 select.addOption({value: '', label: __("Expand to select feed")});
865 for (var feedUrl in feeds) {
866 select.addOption({value: feedUrl, label: feeds[feedUrl]});
870 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
874 alert(__("Couldn't download the specified URL: %s").
875 replace("%s", rc['message']));
878 alert(__("XML validation failed: %s").
879 replace("%s", rc['message']));
883 alert(__("You are already subscribed to this feed."));
888 exception_error("subscribeToFeed", e, transport);
899 exception_error("quickAddFeed", e);
903 function createNewRuleElement(parentNode, replaceNode) {
905 var form = document.forms["filter_new_rule_form"];
907 form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
909 var query = "backend.php?op=pref-filters&method=printrulename&rule="+
910 param_escape(dojo.formToJson(form));
914 new Ajax.Request("backend.php", {
916 onComplete: function (transport) {
918 var li = dojo.create("li");
920 var cb = dojo.create("input", { type: "checkbox" }, li);
922 new dijit.form.CheckBox({
923 onChange: function() {
924 toggleSelectListRow2(this) },
927 dojo.create("input", { type: "hidden",
929 value: dojo.formToJson(form) }, li);
931 dojo.create("span", {
932 onclick: function() {
933 dijit.byId('filterEditDlg').editRule(this);
935 innerHTML: transport.responseText }, li);
938 parentNode.replaceChild(li, replaceNode);
940 parentNode.appendChild(li);
943 exception_error("createNewRuleElement", e);
947 exception_error("createNewRuleElement", e);
951 function createNewActionElement(parentNode, replaceNode) {
953 var form = document.forms["filter_new_action_form"];
955 if (form.action_id.value == 7) {
956 form.action_param.value = form.action_param_label.value;
959 var query = "backend.php?op=pref-filters&method=printactionname&action="+
960 param_escape(dojo.formToJson(form));
964 new Ajax.Request("backend.php", {
966 onComplete: function (transport) {
968 var li = dojo.create("li");
970 var cb = dojo.create("input", { type: "checkbox" }, li);
972 new dijit.form.CheckBox({
973 onChange: function() {
974 toggleSelectListRow2(this) },
977 dojo.create("input", { type: "hidden",
979 value: dojo.formToJson(form) }, li);
981 dojo.create("span", {
982 onclick: function() {
983 dijit.byId('filterEditDlg').editAction(this);
985 innerHTML: transport.responseText }, li);
988 parentNode.replaceChild(li, replaceNode);
990 parentNode.appendChild(li);
994 exception_error("createNewActionElement", e);
998 exception_error("createNewActionElement", e);
1003 function addFilterRule(replaceNode, ruleStr) {
1005 if (dijit.byId("filterNewRuleDlg"))
1006 dijit.byId("filterNewRuleDlg").destroyRecursive();
1008 var query = "backend.php?op=pref-filters&method=newrule&rule=" +
1009 param_escape(ruleStr);
1011 var rule_dlg = new dijit.Dialog({
1012 id: "filterNewRuleDlg",
1013 title: ruleStr ? __("Edit rule") : __("Add rule"),
1014 style: "width: 600px",
1015 execute: function() {
1016 if (this.validate()) {
1017 createNewRuleElement($("filterDlg_Matches"), replaceNode);
1025 exception_error("addFilterRule", e);
1029 function addFilterAction(replaceNode, actionStr) {
1031 if (dijit.byId("filterNewActionDlg"))
1032 dijit.byId("filterNewActionDlg").destroyRecursive();
1034 var query = "backend.php?op=pref-filters&method=newaction&action=" +
1035 param_escape(actionStr);
1037 var rule_dlg = new dijit.Dialog({
1038 id: "filterNewActionDlg",
1039 title: actionStr ? __("Edit action") : __("Add action"),
1040 style: "width: 600px",
1041 execute: function() {
1042 if (this.validate()) {
1043 createNewActionElement($("filterDlg_Actions"), replaceNode);
1051 exception_error("addFilterAction", e);
1055 function quickAddFilter() {
1058 if (!inPreferences()) {
1059 query = "backend.php?op=pref-filters&method=newfilter&feed=" +
1060 param_escape(getActiveFeedId()) + "&is_cat=" +
1061 param_escape(activeFeedIsCat());
1063 query = "backend.php?op=pref-filters&method=newfilter";
1068 if (dijit.byId("feedEditDlg"))
1069 dijit.byId("feedEditDlg").destroyRecursive();
1071 if (dijit.byId("filterEditDlg"))
1072 dijit.byId("filterEditDlg").destroyRecursive();
1074 dialog = new dijit.Dialog({
1075 id: "filterEditDlg",
1076 title: __("Create Filter"),
1077 style: "width: 600px",
1079 var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
1081 if (dijit.byId("filterTestDlg"))
1082 dijit.byId("filterTestDlg").destroyRecursive();
1084 var test_dlg = new dijit.Dialog({
1085 id: "filterTestDlg",
1086 title: "Test Filter",
1087 style: "width: 600px",
1092 selectRules: function(select) {
1093 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
1096 e.parentNode.addClassName("Selected");
1098 e.parentNode.removeClassName("Selected");
1101 selectActions: function(select) {
1102 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
1106 e.parentNode.addClassName("Selected");
1108 e.parentNode.removeClassName("Selected");
1112 editRule: function(e) {
1113 var li = e.parentNode;
1114 var rule = li.getElementsByTagName("INPUT")[1].value;
1115 addFilterRule(li, rule);
1117 editAction: function(e) {
1118 var li = e.parentNode;
1119 var action = li.getElementsByTagName("INPUT")[1].value;
1120 addFilterAction(li, action);
1122 addAction: function() { addFilterAction(); },
1123 addRule: function() { addFilterRule(); },
1124 deleteAction: function() {
1125 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1127 deleteRule: function() {
1128 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1130 execute: function() {
1131 if (this.validate()) {
1133 var query = dojo.formToQuery("filter_new_form");
1137 new Ajax.Request("backend.php", {
1139 onComplete: function (transport) {
1140 if (inPreferences()) {
1150 if (!inPreferences()) {
1151 var lh = dojo.connect(dialog, "onLoad", function(){
1152 dojo.disconnect(lh);
1154 var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1156 new Ajax.Request("backend.php", {
1158 onComplete: function(transport) {
1159 var reply = JSON.parse(transport.responseText);
1163 if (reply && reply) title = reply.title;
1165 if (title || getActiveFeedId() || activeFeedIsCat()) {
1167 console.log(title + " " + getActiveFeedId());
1169 var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1172 var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
1174 addFilterRule(null, dojo.toJson(rule));
1185 exception_error("quickAddFilter", e);
1189 function resetPubSub(feed_id, title) {
1191 var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title);
1193 if (title == undefined || confirm(msg)) {
1194 notify_progress("Loading, please wait...");
1196 var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id;
1198 new Ajax.Request("backend.php", {
1200 onComplete: function(transport) {
1201 dijit.byId("pubsubReset_Btn").attr('disabled', true);
1202 notify_info("Subscription reset.");
1210 function unsubscribeFeed(feed_id, title) {
1212 var msg = __("Unsubscribe from %s?").replace("%s", title);
1214 if (title == undefined || confirm(msg)) {
1215 notify_progress("Removing feed...");
1217 var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id;
1219 new Ajax.Request("backend.php", {
1221 onComplete: function(transport) {
1223 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1225 if (inPreferences()) {
1228 if (feed_id == getActiveFeedId())
1229 setTimeout("viewfeed(-5)", 100);
1231 if (feed_id < 0) updateFeedList();
1241 function backend_sanity_check_callback(transport) {
1245 if (sanity_check_done) {
1246 fatalError(11, "Sanity check request received twice. This can indicate "+
1247 "presence of Firebug or some other disrupting extension. "+
1248 "Please disable it and try again.");
1252 var reply = JSON.parse(transport.responseText);
1255 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1259 var error_code = reply['error']['code'];
1261 if (error_code && error_code != 0) {
1262 return fatalError(error_code, reply['error']['message']);
1265 console.log("sanity check ok");
1267 var params = reply['init-params'];
1270 console.log('reading init-params...');
1274 console.log("IP: " + k + " => " + v);
1276 if (k == "label_base_index") _label_base_index = parseInt(v);
1279 init_params = params;
1281 // PluginHost might not be available on non-index pages
1282 window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
1285 sanity_check_done = true;
1287 init_second_stage();
1290 exception_error("backend_sanity_check_callback", e, transport);
1294 /*function has_local_storage() {
1296 return 'sessionStorage' in window && window['sessionStorage'] != null;
1302 function catSelectOnChange(elem) {
1304 /* var value = elem[elem.selectedIndex].value;
1305 var def = elem.getAttribute('default');
1307 if (value == "ADD_CAT") {
1310 dropboxSelect(elem, def);
1312 elem.selectedIndex = 0;
1318 exception_error("catSelectOnChange", e);
1322 function quickAddCat(elem) {
1324 var cat = prompt(__("Please enter category title:"));
1328 var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat);
1330 notify_progress("Loading, please wait...", true);
1332 new Ajax.Request("backend.php", {
1334 onComplete: function (transport) {
1335 var response = transport.responseXML;
1336 var select = response.getElementsByTagName("select")[0];
1337 var options = select.getElementsByTagName("option");
1339 dropbox_replace_options(elem, options);
1348 exception_error("quickAddCat", e);
1352 function genUrlChangeKey(feed, is_cat) {
1355 var ok = confirm(__("Generate new syndication address for this feed?"));
1359 notify_progress("Trying to change address...", true);
1361 var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) +
1362 "&is_cat=" + param_escape(is_cat);
1364 new Ajax.Request("backend.php", {
1366 onComplete: function(transport) {
1367 var reply = JSON.parse(transport.responseText);
1368 var new_link = reply.link;
1370 var e = $('gen_feed_url');
1374 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
1375 "&key=" + new_link);
1377 e.href = e.href.replace(/\&key=.*$/,
1378 "&key=" + new_link);
1380 new Effect.Highlight(e);
1385 notify_error("Could not change feed URL.");
1390 exception_error("genUrlChangeKey", e);
1395 function labelSelectOnChange(elem) {
1397 /* var value = elem[elem.selectedIndex].value;
1398 var def = elem.getAttribute('default');
1400 if (value == "ADD_LABEL") {
1403 dropboxSelect(elem, def);
1405 elem.selectedIndex = 0;
1407 addLabel(elem, function(transport) {
1411 var response = transport.responseXML;
1412 var select = response.getElementsByTagName("select")[0];
1413 var options = select.getElementsByTagName("option");
1415 dropbox_replace_options(elem, options);
1419 exception_error("addLabel", e);
1425 exception_error("labelSelectOnChange", e);
1429 function dropbox_replace_options(elem, options) {
1432 while (elem.hasChildNodes())
1433 elem.removeChild(elem.firstChild);
1437 for (var i = 0; i < options.length; i++) {
1438 var text = options[i].firstChild.nodeValue;
1439 var value = options[i].getAttribute("value");
1441 if (value == undefined) value = text;
1443 var issel = options[i].getAttribute("selected") == "1";
1445 var option = new Option(text, value, issel);
1447 if (options[i].getAttribute("disabled"))
1448 option.setAttribute("disabled", true);
1450 elem.insert(option);
1452 if (issel) sel_idx = i;
1455 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1456 if (sel_idx >= 0) elem.selectedIndex = sel_idx;
1459 exception_error("dropbox_replace_options", e);
1463 // mode = all, none, invert
1464 function selectTableRows(id, mode) {
1466 var rows = $(id).rows;
1468 for (var i = 0; i < rows.length; i++) {
1473 if (row.id && row.className) {
1474 var bare_id = row.id.replace(/^[A-Z]*?-/, "");
1475 var inputs = rows[i].getElementsByTagName("input");
1477 for (var j = 0; j < inputs.length; j++) {
1478 var input = inputs[j];
1480 if (input.getAttribute("type") == "checkbox" &&
1481 input.id.match(bare_id)) {
1484 dcb = dijit.getEnclosingWidget(cb);
1490 var issel = row.hasClassName("Selected");
1492 if (mode == "all" && !issel) {
1493 row.addClassName("Selected");
1495 if (dcb) dcb.set("checked", true);
1496 } else if (mode == "none" && issel) {
1497 row.removeClassName("Selected");
1499 if (dcb) dcb.set("checked", false);
1501 } else if (mode == "invert") {
1504 row.removeClassName("Selected");
1506 if (dcb) dcb.set("checked", false);
1508 row.addClassName("Selected");
1510 if (dcb) dcb.set("checked", true);
1518 exception_error("selectTableRows", e);
1523 function getSelectedTableRowIds(id) {
1527 var elem_rows = $(id).rows;
1529 for (var i = 0; i < elem_rows.length; i++) {
1530 if (elem_rows[i].hasClassName("Selected")) {
1531 var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1537 exception_error("getSelectedTableRowIds", e);
1543 function editFeed(feed, event) {
1546 return alert(__("You can't edit this kind of feed."));
1548 var query = "backend.php?op=pref-feeds&method=editfeed&id=" +
1553 if (dijit.byId("filterEditDlg"))
1554 dijit.byId("filterEditDlg").destroyRecursive();
1556 if (dijit.byId("feedEditDlg"))
1557 dijit.byId("feedEditDlg").destroyRecursive();
1559 dialog = new dijit.Dialog({
1561 title: __("Edit Feed"),
1562 style: "width: 600px",
1563 execute: function() {
1564 if (this.validate()) {
1565 // console.log(dojo.objectToQuery(this.attr('value')));
1567 notify_progress("Saving data...", true);
1569 new Ajax.Request("backend.php", {
1570 parameters: dojo.objectToQuery(dialog.attr('value')),
1571 onComplete: function(transport) {
1583 exception_error("editFeed", e);
1587 function feedBrowser() {
1589 var query = "backend.php?op=feeds&method=feedBrowser";
1591 if (dijit.byId("feedAddDlg"))
1592 dijit.byId("feedAddDlg").hide();
1594 if (dijit.byId("feedBrowserDlg"))
1595 dijit.byId("feedBrowserDlg").destroyRecursive();
1597 var dialog = new dijit.Dialog({
1598 id: "feedBrowserDlg",
1599 title: __("More Feeds"),
1600 style: "width: 600px",
1601 getSelectedFeedIds: function() {
1602 var list = $$("#browseFeedList li[id*=FBROW]");
1603 var selected = new Array();
1605 list.each(function(child) {
1606 var id = child.id.replace("FBROW-", "");
1608 if (child.hasClassName('Selected')) {
1615 getSelectedFeeds: function() {
1616 var list = $$("#browseFeedList li.Selected");
1617 var selected = new Array();
1619 list.each(function(child) {
1620 var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1621 var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1623 selected.push([title,url]);
1630 subscribe: function() {
1631 var mode = this.attr('value').mode;
1635 selected = this.getSelectedFeeds();
1637 selected = this.getSelectedFeedIds();
1639 if (selected.length > 0) {
1640 dijit.byId("feedBrowserDlg").hide();
1642 notify_progress("Loading, please wait...", true);
1644 // we use dojo.toJson instead of JSON.stringify because
1645 // it somehow escapes everything TWICE, at least in Chrome 9
1647 var query = "?op=rpc&method=massSubscribe&payload="+
1648 param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
1652 new Ajax.Request("backend.php", {
1654 onComplete: function(transport) {
1660 alert(__("No feeds are selected."));
1664 update: function() {
1665 var query = dojo.objectToQuery(dialog.attr('value'));
1667 Element.show('feed_browser_spinner');
1669 new Ajax.Request("backend.php", {
1671 onComplete: function(transport) {
1674 Element.hide('feed_browser_spinner');
1676 var c = $("browseFeedList");
1678 var reply = JSON.parse(transport.responseText);
1680 var r = reply['content'];
1681 var mode = reply['mode'];
1687 dojo.parser.parse("browseFeedList");
1690 Element.show(dijit.byId('feed_archive_remove').domNode);
1692 Element.hide(dijit.byId('feed_archive_remove').domNode);
1697 removeFromArchive: function() {
1698 var selected = this.getSelectedFeedIds();
1700 if (selected.length > 0) {
1702 var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1705 Element.show('feed_browser_spinner');
1707 var query = "?op=rpc&method=remarchive&ids=" +
1708 param_escape(selected.toString());;
1710 new Ajax.Request("backend.php", {
1712 onComplete: function(transport) {
1718 execute: function() {
1719 if (this.validate()) {
1728 exception_error("editFeed", e);
1732 function showFeedsWithErrors() {
1734 var query = "backend.php?op=pref-feeds&method=feedsWithErrors";
1736 if (dijit.byId("errorFeedsDlg"))
1737 dijit.byId("errorFeedsDlg").destroyRecursive();
1739 dialog = new dijit.Dialog({
1740 id: "errorFeedsDlg",
1741 title: __("Feeds with update errors"),
1742 style: "width: 600px",
1743 getSelectedFeeds: function() {
1744 return getSelectedTableRowIds("prefErrorFeedList");
1746 removeSelected: function() {
1747 var sel_rows = this.getSelectedFeeds();
1749 console.log(sel_rows);
1751 if (sel_rows.length > 0) {
1752 var ok = confirm(__("Remove selected feeds?"));
1755 notify_progress("Removing selected feeds...", true);
1757 var query = "?op=pref-feeds&method=remove&ids="+
1758 param_escape(sel_rows.toString());
1760 new Ajax.Request("backend.php", {
1762 onComplete: function(transport) {
1770 alert(__("No feeds are selected."));
1773 execute: function() {
1774 if (this.validate()) {
1782 exception_error("showFeedsWithErrors", e);
1787 /* new support functions for SelectByTag */
1789 function get_all_tags(selObj){
1791 if( !selObj ) return "";
1794 var len = selObj.options.length;
1796 for (var i=0; i < len; i++){
1797 if (selObj.options[i].selected) {
1798 result += selObj[i].value + "%2C"; // is really a comma
1802 if (result.length > 0){
1803 result = result.substr(0, result.length-3); // remove trailing %2C
1809 exception_error("get_all_tags", e);
1813 function get_radio_checked(radioObj) {
1815 if (!radioObj) return "";
1817 var len = radioObj.length;
1819 if (len == undefined){
1820 if(radioObj.checked){
1821 return(radioObj.value);
1827 for( var i=0; i < len; i++ ){
1828 if( radioObj[i].checked ){
1829 return( radioObj[i].value);
1834 exception_error("get_radio_checked", e);
1839 function get_timestamp() {
1840 var date = new Date();
1841 return Math.round(date.getTime() / 1000);
1844 function helpDialog(topic) {
1846 var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
1848 if (dijit.byId("helpDlg"))
1849 dijit.byId("helpDlg").destroyRecursive();
1851 dialog = new dijit.Dialog({
1854 style: "width: 600px",
1861 exception_error("helpDialog", e);
1865 function htmlspecialchars_decode (string, quote_style) {
1866 // http://kevin.vanzonneveld.net
1867 // + original by: Mirek Slugen
1868 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1869 // + bugfixed by: Mateusz "loonquawl" Zalega
1870 // + input by: ReverseSyntax
1871 // + input by: Slawomir Kaniecki
1872 // + input by: Scott Cariss
1873 // + input by: Francois
1874 // + bugfixed by: Onno Marsman
1875 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1876 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1877 // + input by: Ratheous
1878 // + input by: Mailfaker (http://www.weedem.fr/)
1879 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1880 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1881 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1882 // * returns 1: '<p>this -> "</p>'
1883 // * example 2: htmlspecialchars_decode("&quot;");
1884 // * returns 2: '"'
1888 if (typeof quote_style === 'undefined') {
1891 string = string.toString().replace(/</g, '<').replace(/>/g, '>');
1894 'ENT_HTML_QUOTE_SINGLE': 1,
1895 'ENT_HTML_QUOTE_DOUBLE': 2,
1900 if (quote_style === 0) {
1903 if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
1904 quote_style = [].concat(quote_style);
1905 for (i = 0; i < quote_style.length; i++) {
1906 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1907 if (OPTS[quote_style[i]] === 0) {
1909 } else if (OPTS[quote_style[i]]) {
1910 optTemp = optTemp | OPTS[quote_style[i]];
1913 quote_style = optTemp;
1915 if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
1916 string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1917 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1920 string = string.replace(/"/g, '"');
1922 // Put this in last place to avoid escape being double-decoded
1923 string = string.replace(/&/g, '&');
1929 function label_to_feed_id(label) {
1930 return _label_base_index - 1 - Math.abs(label);
1933 function feed_to_label_id(feed) {
1934 return _label_base_index - 1 + Math.abs(feed);