functions.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975
  1. var loading_progress = 0;
  2. var sanity_check_done = false;
  3. var init_params = {};
  4. var _label_base_index = -1024;
  5. var notify_hide_timerid = false;
  6. Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
  7. function (callOriginal, options) {
  8. if (getInitParam("csrf_token") != undefined) {
  9. Object.extend(options, options || { });
  10. if (Object.isString(options.parameters))
  11. options.parameters = options.parameters.toQueryParams();
  12. else if (Object.isHash(options.parameters))
  13. options.parameters = options.parameters.toObject();
  14. options.parameters["csrf_token"] = getInitParam("csrf_token");
  15. }
  16. return callOriginal(options);
  17. }
  18. );
  19. /* add method to remove element from array */
  20. Array.prototype.remove = function(s) {
  21. for (var i=0; i < this.length; i++) {
  22. if (s == this[i]) this.splice(i, 1);
  23. }
  24. };
  25. /* create console.log if it doesn't exist */
  26. if (!window.console) console = {};
  27. console.log = console.log || function(msg) { };
  28. console.warn = console.warn || function(msg) { };
  29. console.error = console.error || function(msg) { };
  30. function exception_error(location, e, ext_info) {
  31. var msg = format_exception_error(location, e);
  32. if (!ext_info) ext_info = false;
  33. try {
  34. if (ext_info) {
  35. if (ext_info.responseText) {
  36. ext_info = ext_info.responseText;
  37. }
  38. }
  39. try {
  40. new Ajax.Request("backend.php", {
  41. parameters: {op: "rpc", method: "log", logmsg: msg},
  42. onComplete: function (transport) {
  43. console.log(transport.responseText);
  44. } });
  45. } catch (eii) {
  46. console.log("Exception while trying to log the error.");
  47. console.log(eii);
  48. }
  49. msg += "<p>"+ __("The error will be reported to the configured log destination.") +
  50. "</p>";
  51. var content = "<div class=\"fatalError\">" +
  52. "<pre>" + msg + "</pre>";
  53. content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+
  54. "action=\"http://tt-rss.org/report.php\" method=\"POST\">";
  55. content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>";
  56. content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>";
  57. if (ext_info) {
  58. content += "<div><b>Additional information:</b></div>" +
  59. "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>";
  60. }
  61. content += "<div><b>Stack trace:</b></div>" +
  62. "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
  63. content += "</form>";
  64. content += "</div>";
  65. content += "<div class='dlgButtons'>";
  66. content += "<button dojoType=\"dijit.form.Button\""+
  67. "onclick=\"dijit.byId('exceptionDlg').report()\">" +
  68. __('Report to tt-rss.org') + "</button> ";
  69. content += "<button dojoType=\"dijit.form.Button\" "+
  70. "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
  71. __('Close') + "</button>";
  72. content += "</div>";
  73. if (dijit.byId("exceptionDlg"))
  74. dijit.byId("exceptionDlg").destroyRecursive();
  75. var dialog = new dijit.Dialog({
  76. id: "exceptionDlg",
  77. title: "Unhandled exception",
  78. style: "width: 600px",
  79. report: function() {
  80. 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."))) {
  81. document.forms['exceptionForm'].params.value = $H({
  82. browserName: navigator.appName,
  83. browserVersion: navigator.appVersion,
  84. browserPlatform: navigator.platform,
  85. browserCookies: navigator.cookieEnabled,
  86. }).toQueryString();
  87. document.forms['exceptionForm'].submit();
  88. }
  89. },
  90. content: content});
  91. dialog.show();
  92. } catch (ei) {
  93. console.log("Exception while trying to report an exception. Oh boy.");
  94. console.log(ei);
  95. console.log("Original exception:");
  96. console.log(e);
  97. msg += "\n\nAdditional exception caught while trying to show the error dialog.\n\n" + format_exception_error('exception_error', ei);
  98. try {
  99. new Ajax.Request("backend.php", {
  100. parameters: {op: "rpc", method: "log", logmsg: msg},
  101. onComplete: function (transport) {
  102. console.log(transport.responseText);
  103. } });
  104. } catch (eii) {
  105. console.log("Third exception while trying to log the error! Seriously?");
  106. console.log(eii);
  107. }
  108. msg += "\n\nThe error will be reported to the configured log destination.";
  109. alert(msg);
  110. }
  111. }
  112. function format_exception_error(location, e) {
  113. var msg;
  114. if (e.fileName) {
  115. var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
  116. msg = "Exception: " + e.name + ", " + e.message +
  117. "\nFunction: " + location + "()" +
  118. "\nLocation: " + base_fname + ":" + e.lineNumber;
  119. } else if (e.description) {
  120. msg = "Exception: " + e.description + "\nFunction: " + location + "()";
  121. } else {
  122. msg = "Exception: " + e + "\nFunction: " + location + "()";
  123. }
  124. console.error("EXCEPTION: " + msg);
  125. return msg;
  126. }
  127. function param_escape(arg) {
  128. if (typeof encodeURIComponent != 'undefined')
  129. return encodeURIComponent(arg);
  130. else
  131. return escape(arg);
  132. }
  133. function param_unescape(arg) {
  134. if (typeof decodeURIComponent != 'undefined')
  135. return decodeURIComponent(arg);
  136. else
  137. return unescape(arg);
  138. }
  139. function hide_notify() {
  140. Element.hide('notify');
  141. }
  142. function notify_real(msg, no_hide, n_type) {
  143. var n = $("notify");
  144. if (!n) return;
  145. if (notify_hide_timerid) {
  146. window.clearTimeout(notify_hide_timerid);
  147. }
  148. if (msg == "") {
  149. if (Element.visible(n)) {
  150. notify_hide_timerid = window.setTimeout("hide_notify()", 0);
  151. }
  152. return;
  153. } else {
  154. Element.show(n);
  155. }
  156. /* types:
  157. 1 - generic
  158. 2 - progress
  159. 3 - error
  160. 4 - info
  161. */
  162. msg = "<span class=\"msg\"> " + __(msg) + "</span>";
  163. if (n_type == 1) {
  164. n.className = "notify";
  165. } else if (n_type == 2) {
  166. n.className = "notify progress";
  167. msg = "<span><img src='images/indicator_white.gif'></span>" + msg;
  168. no_hide = true;
  169. } else if (n_type == 3) {
  170. n.className = "notify error";
  171. msg = "<span><img src='images/alert.png'></span>" + msg;
  172. } else if (n_type == 4) {
  173. n.className = "notify info";
  174. msg = "<span><img src='images/information.png'></span>" + msg;
  175. }
  176. msg += " <span><img src=\"images/cross.png\" class=\"close\" title=\"" +
  177. __("Click to close") + "\" onclick=\"notify('')\"></span>";
  178. // msg = "<img src='images/live_com_loading.gif'> " + msg;
  179. n.innerHTML = msg;
  180. if (!no_hide) {
  181. notify_hide_timerid = window.setTimeout("hide_notify()", 5*1000);
  182. }
  183. }
  184. function notify(msg, no_hide) {
  185. notify_real(msg, no_hide, 1);
  186. }
  187. function notify_progress(msg, no_hide) {
  188. notify_real(msg, no_hide, 2);
  189. }
  190. function notify_error(msg, no_hide) {
  191. notify_real(msg, no_hide, 3);
  192. }
  193. function notify_info(msg, no_hide) {
  194. notify_real(msg, no_hide, 4);
  195. }
  196. function setCookie(name, value, lifetime, path, domain, secure) {
  197. var d = false;
  198. if (lifetime) {
  199. d = new Date();
  200. d.setTime(d.getTime() + (lifetime * 1000));
  201. }
  202. console.log("setCookie: " + name + " => " + value + ": " + d);
  203. int_setCookie(name, value, d, path, domain, secure);
  204. }
  205. function int_setCookie(name, value, expires, path, domain, secure) {
  206. document.cookie= name + "=" + escape(value) +
  207. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  208. ((path) ? "; path=" + path : "") +
  209. ((domain) ? "; domain=" + domain : "") +
  210. ((secure) ? "; secure" : "");
  211. }
  212. function delCookie(name, path, domain) {
  213. if (getCookie(name)) {
  214. document.cookie = name + "=" +
  215. ((path) ? ";path=" + path : "") +
  216. ((domain) ? ";domain=" + domain : "" ) +
  217. ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  218. }
  219. }
  220. function getCookie(name) {
  221. var dc = document.cookie;
  222. var prefix = name + "=";
  223. var begin = dc.indexOf("; " + prefix);
  224. if (begin == -1) {
  225. begin = dc.indexOf(prefix);
  226. if (begin != 0) return null;
  227. }
  228. else {
  229. begin += 2;
  230. }
  231. var end = document.cookie.indexOf(";", begin);
  232. if (end == -1) {
  233. end = dc.length;
  234. }
  235. return unescape(dc.substring(begin + prefix.length, end));
  236. }
  237. function gotoPreferences() {
  238. document.location.href = "prefs.php";
  239. }
  240. function gotoLogout() {
  241. document.location.href = "backend.php?op=logout";
  242. }
  243. function gotoMain() {
  244. document.location.href = "index.php";
  245. }
  246. /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
  247. * * @author Sundar Dorai-Raj
  248. * * Email: sdoraira@vt.edu
  249. * * This program is free software; you can redistribute it and/or
  250. * * modify it under the terms of the GNU General Public License
  251. * * as published by the Free Software Foundation; either version 2
  252. * * of the License, or (at your option) any later version,
  253. * * provided that any use properly credits the author.
  254. * * This program is distributed in the hope that it will be useful,
  255. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  256. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  257. * * GNU General Public License for more details at http://www.gnu.org * * */
  258. var numbers=".0123456789";
  259. function isNumeric(x) {
  260. // is x a String or a character?
  261. if(x.length>1) {
  262. // remove negative sign
  263. x=Math.abs(x)+"";
  264. for(var j=0;j<x.length;j++) {
  265. // call isNumeric recursively for each character
  266. number=isNumeric(x.substring(j,j+1));
  267. if(!number) return number;
  268. }
  269. return number;
  270. }
  271. else {
  272. // if x is number return true
  273. if(numbers.indexOf(x)>=0) return true;
  274. return false;
  275. }
  276. }
  277. function toggleSelectRowById(sender, id) {
  278. var row = $(id);
  279. return toggleSelectRow(sender, row);
  280. }
  281. function toggleSelectListRow(sender) {
  282. var row = sender.parentNode;
  283. return toggleSelectRow(sender, row);
  284. }
  285. /* this is for dijit Checkbox */
  286. function toggleSelectListRow2(sender) {
  287. var row = sender.domNode.parentNode;
  288. return toggleSelectRow(sender, row);
  289. }
  290. /* this is for dijit Checkbox */
  291. function toggleSelectRow2(sender, row, is_cdm) {
  292. if (!row)
  293. if (!is_cdm)
  294. row = sender.domNode.parentNode.parentNode;
  295. else
  296. row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
  297. if (sender.checked && !row.hasClassName('Selected'))
  298. row.addClassName('Selected');
  299. else
  300. row.removeClassName('Selected');
  301. if (typeof updateSelectedPrompt != undefined)
  302. updateSelectedPrompt();
  303. }
  304. function toggleSelectRow(sender, row) {
  305. if (!row) row = sender.parentNode.parentNode;
  306. if (sender.checked && !row.hasClassName('Selected'))
  307. row.addClassName('Selected');
  308. else
  309. row.removeClassName('Selected');
  310. if (typeof updateSelectedPrompt != undefined)
  311. updateSelectedPrompt();
  312. }
  313. function checkboxToggleElement(elem, id) {
  314. if (elem.checked) {
  315. Effect.Appear(id, {duration : 0.5});
  316. } else {
  317. Effect.Fade(id, {duration : 0.5});
  318. }
  319. }
  320. function dropboxSelect(e, v) {
  321. for (var i = 0; i < e.length; i++) {
  322. if (e[i].value == v) {
  323. e.selectedIndex = i;
  324. break;
  325. }
  326. }
  327. }
  328. function getURLParam(param){
  329. return String(window.location.href).parseQuery()[param];
  330. }
  331. function closeInfoBox(cleanup) {
  332. try {
  333. dialog = dijit.byId("infoBox");
  334. if (dialog) dialog.hide();
  335. } catch (e) {
  336. //exception_error("closeInfoBox", e);
  337. }
  338. return false;
  339. }
  340. function displayDlg(title, id, param, callback) {
  341. notify_progress("Loading, please wait...", true);
  342. var query = "?op=dlg&method=" +
  343. param_escape(id) + "&param=" + param_escape(param);
  344. new Ajax.Request("backend.php", {
  345. parameters: query,
  346. onComplete: function (transport) {
  347. infobox_callback2(transport, title);
  348. if (callback) callback(transport);
  349. } });
  350. return false;
  351. }
  352. function infobox_callback2(transport, title) {
  353. try {
  354. var dialog = false;
  355. if (dijit.byId("infoBox")) {
  356. dialog = dijit.byId("infoBox");
  357. }
  358. //console.log("infobox_callback2");
  359. notify('');
  360. var content = transport.responseText;
  361. if (!dialog) {
  362. dialog = new dijit.Dialog({
  363. title: title,
  364. id: 'infoBox',
  365. style: "width: 600px",
  366. onCancel: function() {
  367. return true;
  368. },
  369. onExecute: function() {
  370. return true;
  371. },
  372. onClose: function() {
  373. return true;
  374. },
  375. content: content});
  376. } else {
  377. dialog.attr('title', title);
  378. dialog.attr('content', content);
  379. }
  380. dialog.show();
  381. notify("");
  382. } catch (e) {
  383. exception_error("infobox_callback2", e);
  384. }
  385. }
  386. function filterCR(e, f)
  387. {
  388. var key;
  389. if(window.event)
  390. key = window.event.keyCode; //IE
  391. else
  392. key = e.which; //firefox
  393. if (key == 13) {
  394. if (typeof f != 'undefined') {
  395. f();
  396. return false;
  397. } else {
  398. return false;
  399. }
  400. } else {
  401. return true;
  402. }
  403. }
  404. function getInitParam(key) {
  405. return init_params[key];
  406. }
  407. function setInitParam(key, value) {
  408. init_params[key] = value;
  409. }
  410. function fatalError(code, msg, ext_info) {
  411. try {
  412. if (code == 6) {
  413. window.location.href = "index.php";
  414. } else if (code == 5) {
  415. window.location.href = "public.php?op=dbupdate";
  416. } else {
  417. if (msg == "") msg = "Unknown error";
  418. if (ext_info) {
  419. if (ext_info.responseText) {
  420. ext_info = ext_info.responseText;
  421. }
  422. }
  423. if (ERRORS && ERRORS[code] && !msg) {
  424. msg = ERRORS[code];
  425. }
  426. var content = "<div><b>Error code:</b> " + code + "</div>" +
  427. "<p>" + msg + "</p>";
  428. if (ext_info) {
  429. content = content + "<div><b>Additional information:</b></div>" +
  430. "<textarea style='width: 100%' readonly=\"1\">" +
  431. ext_info + "</textarea>";
  432. }
  433. var dialog = new dijit.Dialog({
  434. title: "Fatal error",
  435. style: "width: 600px",
  436. content: content});
  437. dialog.show();
  438. }
  439. return false;
  440. } catch (e) {
  441. exception_error("fatalError", e);
  442. }
  443. }
  444. function filterDlgCheckAction(sender) {
  445. try {
  446. var action = sender.value;
  447. var action_param = $("filterDlg_paramBox");
  448. if (!action_param) {
  449. console.log("filterDlgCheckAction: can't find action param box!");
  450. return;
  451. }
  452. // if selected action supports parameters, enable params field
  453. if (action == 4 || action == 6 || action == 7) {
  454. new Effect.Appear(action_param, {duration : 0.5});
  455. if (action != 7) {
  456. Element.show(dijit.byId("filterDlg_actionParam").domNode);
  457. Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
  458. } else {
  459. Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
  460. Element.hide(dijit.byId("filterDlg_actionParam").domNode);
  461. }
  462. } else {
  463. Element.hide(action_param);
  464. }
  465. } catch (e) {
  466. exception_error("filterDlgCheckAction", e);
  467. }
  468. }
  469. function explainError(code) {
  470. return displayDlg(__("Error explained"), "explainError", code);
  471. }
  472. function loading_set_progress(p) {
  473. try {
  474. loading_progress += p;
  475. if (dijit.byId("loading_bar"))
  476. dijit.byId("loading_bar").update({progress: loading_progress});
  477. if (loading_progress >= 90)
  478. remove_splash();
  479. } catch (e) {
  480. exception_error("loading_set_progress", e);
  481. }
  482. }
  483. function remove_splash() {
  484. if (Element.visible("overlay")) {
  485. console.log("about to remove splash, OMG!");
  486. Element.hide("overlay");
  487. console.log("removed splash!");
  488. }
  489. }
  490. function transport_error_check(transport) {
  491. try {
  492. if (transport.responseXML) {
  493. var error = transport.responseXML.getElementsByTagName("error")[0];
  494. if (error) {
  495. var code = error.getAttribute("error-code");
  496. var msg = error.getAttribute("error-msg");
  497. if (code != 0) {
  498. fatalError(code, msg);
  499. return false;
  500. }
  501. }
  502. }
  503. } catch (e) {
  504. exception_error("check_for_error_xml", e);
  505. }
  506. return true;
  507. }
  508. function strip_tags(s) {
  509. return s.replace(/<\/?[^>]+(>|$)/g, "");
  510. }
  511. function truncate_string(s, length) {
  512. if (!length) length = 30;
  513. var tmp = s.substring(0, length);
  514. if (s.length > length) tmp += "&hellip;";
  515. return tmp;
  516. }
  517. function hotkey_prefix_timeout() {
  518. try {
  519. var date = new Date();
  520. var ts = Math.round(date.getTime() / 1000);
  521. if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
  522. console.log("hotkey_prefix seems to be stuck, aborting");
  523. hotkey_prefix_pressed = false;
  524. hotkey_prefix = false;
  525. Element.hide('cmdline');
  526. }
  527. setTimeout("hotkey_prefix_timeout()", 1000);
  528. } catch (e) {
  529. exception_error("hotkey_prefix_timeout", e);
  530. }
  531. }
  532. function uploadIconHandler(rc) {
  533. try {
  534. switch (rc) {
  535. case 0:
  536. notify_info("Upload complete.");
  537. if (inPreferences()) {
  538. updateFeedList();
  539. } else {
  540. setTimeout('updateFeedList(false, false)', 50);
  541. }
  542. break;
  543. case 1:
  544. notify_error("Upload failed: icon is too big.");
  545. break;
  546. case 2:
  547. notify_error("Upload failed.");
  548. break;
  549. }
  550. } catch (e) {
  551. exception_error("uploadIconHandler", e);
  552. }
  553. }
  554. function removeFeedIcon(id) {
  555. try {
  556. if (confirm(__("Remove stored feed icon?"))) {
  557. var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id);
  558. console.log(query);
  559. notify_progress("Removing feed icon...", true);
  560. new Ajax.Request("backend.php", {
  561. parameters: query,
  562. onComplete: function(transport) {
  563. notify_info("Feed icon removed.");
  564. if (inPreferences()) {
  565. updateFeedList();
  566. } else {
  567. setTimeout('updateFeedList(false, false)', 50);
  568. }
  569. } });
  570. }
  571. return false;
  572. } catch (e) {
  573. exception_error("removeFeedIcon", e);
  574. }
  575. }
  576. function uploadFeedIcon() {
  577. try {
  578. var file = $("icon_file");
  579. if (file.value.length == 0) {
  580. alert(__("Please select an image file to upload."));
  581. } else {
  582. if (confirm(__("Upload new icon for this feed?"))) {
  583. notify_progress("Uploading, please wait...", true);
  584. return true;
  585. }
  586. }
  587. return false;
  588. } catch (e) {
  589. exception_error("uploadFeedIcon", e);
  590. }
  591. }
  592. function addLabel(select, callback) {
  593. try {
  594. var caption = prompt(__("Please enter label caption:"), "");
  595. if (caption != undefined) {
  596. if (caption == "") {
  597. alert(__("Can't create label: missing caption."));
  598. return false;
  599. }
  600. var query = "?op=pref-labels&method=add&caption=" +
  601. param_escape(caption);
  602. if (select)
  603. query += "&output=select";
  604. notify_progress("Loading, please wait...", true);
  605. if (inPreferences() && !select) active_tab = "labelConfig";
  606. new Ajax.Request("backend.php", {
  607. parameters: query,
  608. onComplete: function(transport) {
  609. if (callback) {
  610. callback(transport);
  611. } else if (inPreferences()) {
  612. updateLabelList();
  613. } else {
  614. updateFeedList();
  615. }
  616. } });
  617. }
  618. } catch (e) {
  619. exception_error("addLabel", e);
  620. }
  621. }
  622. function quickAddFeed() {
  623. try {
  624. var query = "backend.php?op=feeds&method=quickAddFeed";
  625. // overlapping widgets
  626. if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
  627. if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
  628. var dialog = new dijit.Dialog({
  629. id: "feedAddDlg",
  630. title: __("Subscribe to Feed"),
  631. style: "width: 600px",
  632. execute: function() {
  633. if (this.validate()) {
  634. console.log(dojo.objectToQuery(this.attr('value')));
  635. var feed_url = this.attr('value').feed;
  636. Element.show("feed_add_spinner");
  637. new Ajax.Request("backend.php", {
  638. parameters: dojo.objectToQuery(this.attr('value')),
  639. onComplete: function(transport) {
  640. try {
  641. var reply = JSON.parse(transport.responseText);
  642. var rc = reply['result'];
  643. notify('');
  644. Element.hide("feed_add_spinner");
  645. console.log(rc);
  646. switch (parseInt(rc['code'])) {
  647. case 1:
  648. dialog.hide();
  649. notify_info(__("Subscribed to %s").replace("%s", feed_url));
  650. updateFeedList();
  651. break;
  652. case 2:
  653. alert(__("Specified URL seems to be invalid."));
  654. break;
  655. case 3:
  656. alert(__("Specified URL doesn't seem to contain any feeds."));
  657. break;
  658. case 4:
  659. feeds = rc['feeds'];
  660. Element.show("fadd_multiple_notify");
  661. var select = dijit.byId("feedDlg_feedContainerSelect");
  662. while (select.getOptions().length > 0)
  663. select.removeOption(0);
  664. select.addOption({value: '', label: __("Expand to select feed")});
  665. var count = 0;
  666. for (var feedUrl in feeds) {
  667. select.addOption({value: feedUrl, label: feeds[feedUrl]});
  668. count++;
  669. }
  670. Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
  671. break;
  672. case 5:
  673. alert(__("Couldn't download the specified URL: %s").
  674. replace("%s", rc['message']));
  675. break;
  676. case 6:
  677. alert(__("XML validation failed: %s").
  678. replace("%s", rc['message']));
  679. break;
  680. break;
  681. case 0:
  682. alert(__("You are already subscribed to this feed."));
  683. break;
  684. }
  685. } catch (e) {
  686. exception_error("subscribeToFeed", e, transport);
  687. }
  688. } });
  689. }
  690. },
  691. href: query});
  692. dialog.show();
  693. } catch (e) {
  694. exception_error("quickAddFeed", e);
  695. }
  696. }
  697. function createNewRuleElement(parentNode, replaceNode) {
  698. try {
  699. var form = document.forms["filter_new_rule_form"];
  700. form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
  701. var query = "backend.php?op=pref-filters&method=printrulename&rule="+
  702. param_escape(dojo.formToJson(form));
  703. console.log(query);
  704. new Ajax.Request("backend.php", {
  705. parameters: query,
  706. onComplete: function (transport) {
  707. try {
  708. var li = dojo.create("li");
  709. var cb = dojo.create("input", { type: "checkbox" }, li);
  710. new dijit.form.CheckBox({
  711. onChange: function() {
  712. toggleSelectListRow2(this) },
  713. }, cb);
  714. dojo.create("input", { type: "hidden",
  715. name: "rule[]",
  716. value: dojo.formToJson(form) }, li);
  717. dojo.create("span", {
  718. onclick: function() {
  719. dijit.byId('filterEditDlg').editRule(this);
  720. },
  721. innerHTML: transport.responseText }, li);
  722. if (replaceNode) {
  723. parentNode.replaceChild(li, replaceNode);
  724. } else {
  725. parentNode.appendChild(li);
  726. }
  727. } catch (e) {
  728. exception_error("createNewRuleElement", e);
  729. }
  730. } });
  731. } catch (e) {
  732. exception_error("createNewRuleElement", e);
  733. }
  734. }
  735. function createNewActionElement(parentNode, replaceNode) {
  736. try {
  737. var form = document.forms["filter_new_action_form"];
  738. if (form.action_id.value == 7) {
  739. form.action_param.value = form.action_param_label.value;
  740. }
  741. var query = "backend.php?op=pref-filters&method=printactionname&action="+
  742. param_escape(dojo.formToJson(form));
  743. console.log(query);
  744. new Ajax.Request("backend.php", {
  745. parameters: query,
  746. onComplete: function (transport) {
  747. try {
  748. var li = dojo.create("li");
  749. var cb = dojo.create("input", { type: "checkbox" }, li);
  750. new dijit.form.CheckBox({
  751. onChange: function() {
  752. toggleSelectListRow2(this) },
  753. }, cb);
  754. dojo.create("input", { type: "hidden",
  755. name: "action[]",
  756. value: dojo.formToJson(form) }, li);
  757. dojo.create("span", {
  758. onclick: function() {
  759. dijit.byId('filterEditDlg').editAction(this);
  760. },
  761. innerHTML: transport.responseText }, li);
  762. if (replaceNode) {
  763. parentNode.replaceChild(li, replaceNode);
  764. } else {
  765. parentNode.appendChild(li);
  766. }
  767. } catch (e) {
  768. exception_error("createNewActionElement", e);
  769. }
  770. } });
  771. } catch (e) {
  772. exception_error("createNewActionElement", e);
  773. }
  774. }
  775. function addFilterRule(replaceNode, ruleStr) {
  776. try {
  777. if (dijit.byId("filterNewRuleDlg"))
  778. dijit.byId("filterNewRuleDlg").destroyRecursive();
  779. var query = "backend.php?op=pref-filters&method=newrule&rule=" +
  780. param_escape(ruleStr);
  781. var rule_dlg = new dijit.Dialog({
  782. id: "filterNewRuleDlg",
  783. title: ruleStr ? __("Edit rule") : __("Add rule"),
  784. style: "width: 600px",
  785. execute: function() {
  786. if (this.validate()) {
  787. createNewRuleElement($("filterDlg_Matches"), replaceNode);
  788. this.hide();
  789. }
  790. },
  791. href: query});
  792. rule_dlg.show();
  793. } catch (e) {
  794. exception_error("addFilterRule", e);
  795. }
  796. }
  797. function addFilterAction(replaceNode, actionStr) {
  798. try {
  799. if (dijit.byId("filterNewActionDlg"))
  800. dijit.byId("filterNewActionDlg").destroyRecursive();
  801. var query = "backend.php?op=pref-filters&method=newaction&action=" +
  802. param_escape(actionStr);
  803. var rule_dlg = new dijit.Dialog({
  804. id: "filterNewActionDlg",
  805. title: actionStr ? __("Edit action") : __("Add action"),
  806. style: "width: 600px",
  807. execute: function() {
  808. if (this.validate()) {
  809. createNewActionElement($("filterDlg_Actions"), replaceNode);
  810. this.hide();
  811. }
  812. },
  813. href: query});
  814. rule_dlg.show();
  815. } catch (e) {
  816. exception_error("addFilterAction", e);
  817. }
  818. }
  819. function quickAddFilter() {
  820. try {
  821. var query = "";
  822. if (!inPreferences()) {
  823. query = "backend.php?op=pref-filters&method=newfilter&feed=" +
  824. param_escape(getActiveFeedId()) + "&is_cat=" +
  825. param_escape(activeFeedIsCat());
  826. } else {
  827. query = "backend.php?op=pref-filters&method=newfilter";
  828. }
  829. console.log(query);
  830. if (dijit.byId("feedEditDlg"))
  831. dijit.byId("feedEditDlg").destroyRecursive();
  832. if (dijit.byId("filterEditDlg"))
  833. dijit.byId("filterEditDlg").destroyRecursive();
  834. dialog = new dijit.Dialog({
  835. id: "filterEditDlg",
  836. title: __("Create Filter"),
  837. style: "width: 600px",
  838. test: function() {
  839. var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
  840. if (dijit.byId("filterTestDlg"))
  841. dijit.byId("filterTestDlg").destroyRecursive();
  842. var test_dlg = new dijit.Dialog({
  843. id: "filterTestDlg",
  844. title: "Test Filter",
  845. style: "width: 600px",
  846. href: query});
  847. test_dlg.show();
  848. },
  849. selectRules: function(select) {
  850. $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
  851. e.checked = select;
  852. if (select)
  853. e.parentNode.addClassName("Selected");
  854. else
  855. e.parentNode.removeClassName("Selected");
  856. });
  857. },
  858. selectActions: function(select) {
  859. $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
  860. e.checked = select;
  861. if (select)
  862. e.parentNode.addClassName("Selected");
  863. else
  864. e.parentNode.removeClassName("Selected");
  865. });
  866. },
  867. editRule: function(e) {
  868. var li = e.parentNode;
  869. var rule = li.getElementsByTagName("INPUT")[1].value;
  870. addFilterRule(li, rule);
  871. },
  872. editAction: function(e) {
  873. var li = e.parentNode;
  874. var action = li.getElementsByTagName("INPUT")[1].value;
  875. addFilterAction(li, action);
  876. },
  877. addAction: function() { addFilterAction(); },
  878. addRule: function() { addFilterRule(); },
  879. deleteAction: function() {
  880. $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
  881. },
  882. deleteRule: function() {
  883. $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
  884. },
  885. execute: function() {
  886. if (this.validate()) {
  887. var query = dojo.formToQuery("filter_new_form");
  888. console.log(query);
  889. new Ajax.Request("backend.php", {
  890. parameters: query,
  891. onComplete: function (transport) {
  892. if (inPreferences()) {
  893. updateFilterList();
  894. }
  895. dialog.hide();
  896. } });
  897. }
  898. },
  899. href: query});
  900. if (!inPreferences()) {
  901. var selectedText = getSelectionText();
  902. var lh = dojo.connect(dialog, "onLoad", function(){
  903. dojo.disconnect(lh);
  904. if (selectedText != "") {
  905. var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
  906. getActiveFeedId();
  907. var rule = { reg_exp: selectedText, feed_id: feed_id, filter_type: 1 };
  908. addFilterRule(null, dojo.toJson(rule));
  909. } else {
  910. var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
  911. new Ajax.Request("backend.php", {
  912. parameters: query,
  913. onComplete: function(transport) {
  914. var reply = JSON.parse(transport.responseText);
  915. var title = false;
  916. if (reply && reply) title = reply.title;
  917. if (title || getActiveFeedId() || activeFeedIsCat()) {
  918. console.log(title + " " + getActiveFeedId());
  919. var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
  920. getActiveFeedId();
  921. var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
  922. addFilterRule(null, dojo.toJson(rule));
  923. }
  924. } });
  925. }
  926. });
  927. }
  928. dialog.show();
  929. } catch (e) {
  930. exception_error("quickAddFilter", e);
  931. }
  932. }
  933. function resetPubSub(feed_id, title) {
  934. var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title);
  935. if (title == undefined || confirm(msg)) {
  936. notify_progress("Loading, please wait...");
  937. var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id;
  938. new Ajax.Request("backend.php", {
  939. parameters: query,
  940. onComplete: function(transport) {
  941. dijit.byId("pubsubReset_Btn").attr('disabled', true);
  942. notify_info("Subscription reset.");
  943. } });
  944. }
  945. return false;
  946. }
  947. function unsubscribeFeed(feed_id, title) {
  948. var msg = __("Unsubscribe from %s?").replace("%s", title);
  949. if (title == undefined || confirm(msg)) {
  950. notify_progress("Removing feed...");
  951. var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id;
  952. new Ajax.Request("backend.php", {
  953. parameters: query,
  954. onComplete: function(transport) {
  955. if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
  956. if (inPreferences()) {
  957. updateFeedList();
  958. } else {
  959. if (feed_id == getActiveFeedId())
  960. setTimeout("viewfeed(-5)", 100);
  961. if (feed_id < 0) updateFeedList();
  962. }
  963. } });
  964. }
  965. return false;
  966. }
  967. function backend_sanity_check_callback(transport) {
  968. try {
  969. if (sanity_check_done) {
  970. fatalError(11, "Sanity check request received twice. This can indicate "+
  971. "presence of Firebug or some other disrupting extension. "+
  972. "Please disable it and try again.");
  973. return;
  974. }
  975. var reply = JSON.parse(transport.responseText);
  976. if (!reply) {
  977. fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
  978. return;
  979. }
  980. var error_code = reply['error']['code'];
  981. if (error_code && error_code != 0) {
  982. return fatalError(error_code, reply['error']['message']);
  983. }
  984. console.log("sanity check ok");
  985. var params = reply['init-params'];
  986. if (params) {
  987. console.log('reading init-params...');
  988. for (k in params) {
  989. var v = params[k];
  990. console.log("IP: " + k + " => " + v);
  991. if (k == "label_base_index") _label_base_index = parseInt(v);
  992. }
  993. init_params = params;
  994. // PluginHost might not be available on non-index pages
  995. window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
  996. }
  997. sanity_check_done = true;
  998. init_second_stage();
  999. } catch (e) {
  1000. exception_error("backend_sanity_check_callback", e, transport);
  1001. }
  1002. }
  1003. /*function has_local_storage() {
  1004. try {
  1005. return 'sessionStorage' in window && window['sessionStorage'] != null;
  1006. } catch (e) {
  1007. return false;
  1008. }
  1009. } */
  1010. function catSelectOnChange(elem) {
  1011. try {
  1012. /* var value = elem[elem.selectedIndex].value;
  1013. var def = elem.getAttribute('default');
  1014. if (value == "ADD_CAT") {
  1015. if (def)
  1016. dropboxSelect(elem, def);
  1017. else
  1018. elem.selectedIndex = 0;
  1019. quickAddCat(elem);
  1020. } */
  1021. } catch (e) {
  1022. exception_error("catSelectOnChange", e);
  1023. }
  1024. }
  1025. function quickAddCat(elem) {
  1026. try {
  1027. var cat = prompt(__("Please enter category title:"));
  1028. if (cat) {
  1029. var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat);
  1030. notify_progress("Loading, please wait...", true);
  1031. new Ajax.Request("backend.php", {
  1032. parameters: query,
  1033. onComplete: function (transport) {
  1034. var response = transport.responseXML;
  1035. var select = response.getElementsByTagName("select")[0];
  1036. var options = select.getElementsByTagName("option");
  1037. dropbox_replace_options(elem, options);
  1038. notify('');
  1039. } });
  1040. }
  1041. } catch (e) {
  1042. exception_error("quickAddCat", e);
  1043. }
  1044. }
  1045. function genUrlChangeKey(feed, is_cat) {
  1046. try {
  1047. var ok = confirm(__("Generate new syndication address for this feed?"));
  1048. if (ok) {
  1049. notify_progress("Trying to change address...", true);
  1050. var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) +
  1051. "&is_cat=" + param_escape(is_cat);
  1052. new Ajax.Request("backend.php", {
  1053. parameters: query,
  1054. onComplete: function(transport) {
  1055. var reply = JSON.parse(transport.responseText);
  1056. var new_link = reply.link;
  1057. var e = $('gen_feed_url');
  1058. if (new_link) {
  1059. e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
  1060. "&amp;key=" + new_link);
  1061. e.href = e.href.replace(/\&key=.*$/,
  1062. "&key=" + new_link);
  1063. new Effect.Highlight(e);
  1064. notify('');
  1065. } else {
  1066. notify_error("Could not change feed URL.");
  1067. }
  1068. } });
  1069. }
  1070. } catch (e) {
  1071. exception_error("genUrlChangeKey", e);
  1072. }
  1073. return false;
  1074. }
  1075. function labelSelectOnChange(elem) {
  1076. try {
  1077. /* var value = elem[elem.selectedIndex].value;
  1078. var def = elem.getAttribute('default');
  1079. if (value == "ADD_LABEL") {
  1080. if (def)
  1081. dropboxSelect(elem, def);
  1082. else
  1083. elem.selectedIndex = 0;
  1084. addLabel(elem, function(transport) {
  1085. try {
  1086. var response = transport.responseXML;
  1087. var select = response.getElementsByTagName("select")[0];
  1088. var options = select.getElementsByTagName("option");
  1089. dropbox_replace_options(elem, options);
  1090. notify('');
  1091. } catch (e) {
  1092. exception_error("addLabel", e);
  1093. }
  1094. });
  1095. } */
  1096. } catch (e) {
  1097. exception_error("labelSelectOnChange", e);
  1098. }
  1099. }
  1100. function dropbox_replace_options(elem, options) {
  1101. try {
  1102. while (elem.hasChildNodes())
  1103. elem.removeChild(elem.firstChild);
  1104. var sel_idx = -1;
  1105. for (var i = 0; i < options.length; i++) {
  1106. var text = options[i].firstChild.nodeValue;
  1107. var value = options[i].getAttribute("value");
  1108. if (value == undefined) value = text;
  1109. var issel = options[i].getAttribute("selected") == "1";
  1110. var option = new Option(text, value, issel);
  1111. if (options[i].getAttribute("disabled"))
  1112. option.setAttribute("disabled", true);
  1113. elem.insert(option);
  1114. if (issel) sel_idx = i;
  1115. }
  1116. // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
  1117. if (sel_idx >= 0) elem.selectedIndex = sel_idx;
  1118. } catch (e) {
  1119. exception_error("dropbox_replace_options", e);
  1120. }
  1121. }
  1122. // mode = all, none, invert
  1123. function selectTableRows(id, mode) {
  1124. try {
  1125. var rows = $(id).rows;
  1126. for (var i = 0; i < rows.length; i++) {
  1127. var row = rows[i];
  1128. var cb = false;
  1129. var dcb = false;
  1130. if (row.id && row.className) {
  1131. var bare_id = row.id.replace(/^[A-Z]*?-/, "");
  1132. var inputs = rows[i].getElementsByTagName("input");
  1133. for (var j = 0; j < inputs.length; j++) {
  1134. var input = inputs[j];
  1135. if (input.getAttribute("type") == "checkbox" &&
  1136. input.id.match(bare_id)) {
  1137. cb = input;
  1138. dcb = dijit.getEnclosingWidget(cb);
  1139. break;
  1140. }
  1141. }
  1142. if (cb || dcb) {
  1143. var issel = row.hasClassName("Selected");
  1144. if (mode == "all" && !issel) {
  1145. row.addClassName("Selected");
  1146. cb.checked = true;
  1147. if (dcb) dcb.set("checked", true);
  1148. } else if (mode == "none" && issel) {
  1149. row.removeClassName("Selected");
  1150. cb.checked = false;
  1151. if (dcb) dcb.set("checked", false);
  1152. } else if (mode == "invert") {
  1153. if (issel) {
  1154. row.removeClassName("Selected");
  1155. cb.checked = false;
  1156. if (dcb) dcb.set("checked", false);
  1157. } else {
  1158. row.addClassName("Selected");
  1159. cb.checked = true;
  1160. if (dcb) dcb.set("checked", true);
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. } catch (e) {
  1167. exception_error("selectTableRows", e);
  1168. }
  1169. }
  1170. function getSelectedTableRowIds(id) {
  1171. var rows = [];
  1172. try {
  1173. var elem_rows = $(id).rows;
  1174. for (var i = 0; i < elem_rows.length; i++) {
  1175. if (elem_rows[i].hasClassName("Selected")) {
  1176. var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
  1177. rows.push(bare_id);
  1178. }
  1179. }
  1180. } catch (e) {
  1181. exception_error("getSelectedTableRowIds", e);
  1182. }
  1183. return rows;
  1184. }
  1185. function editFeed(feed, event) {
  1186. try {
  1187. if (feed <= 0)
  1188. return alert(__("You can't edit this kind of feed."));
  1189. var query = "backend.php?op=pref-feeds&method=editfeed&id=" +
  1190. param_escape(feed);
  1191. console.log(query);
  1192. if (dijit.byId("filterEditDlg"))
  1193. dijit.byId("filterEditDlg").destroyRecursive();
  1194. if (dijit.byId("feedEditDlg"))
  1195. dijit.byId("feedEditDlg").destroyRecursive();
  1196. dialog = new dijit.Dialog({
  1197. id: "feedEditDlg",
  1198. title: __("Edit Feed"),
  1199. style: "width: 600px",
  1200. execute: function() {
  1201. if (this.validate()) {
  1202. // console.log(dojo.objectToQuery(this.attr('value')));
  1203. notify_progress("Saving data...", true);
  1204. new Ajax.Request("backend.php", {
  1205. parameters: dojo.objectToQuery(dialog.attr('value')),
  1206. onComplete: function(transport) {
  1207. dialog.hide();
  1208. notify('');
  1209. updateFeedList();
  1210. }});
  1211. }
  1212. },
  1213. href: query});
  1214. dialog.show();
  1215. } catch (e) {
  1216. exception_error("editFeed", e);
  1217. }
  1218. }
  1219. function feedBrowser() {
  1220. try {
  1221. var query = "backend.php?op=feeds&method=feedBrowser";
  1222. if (dijit.byId("feedAddDlg"))
  1223. dijit.byId("feedAddDlg").hide();
  1224. if (dijit.byId("feedBrowserDlg"))
  1225. dijit.byId("feedBrowserDlg").destroyRecursive();
  1226. var dialog = new dijit.Dialog({
  1227. id: "feedBrowserDlg",
  1228. title: __("More Feeds"),
  1229. style: "width: 600px",
  1230. getSelectedFeedIds: function() {
  1231. var list = $$("#browseFeedList li[id*=FBROW]");
  1232. var selected = new Array();
  1233. list.each(function(child) {
  1234. var id = child.id.replace("FBROW-", "");
  1235. if (child.hasClassName('Selected')) {
  1236. selected.push(id);
  1237. }
  1238. });
  1239. return selected;
  1240. },
  1241. getSelectedFeeds: function() {
  1242. var list = $$("#browseFeedList li.Selected");
  1243. var selected = new Array();
  1244. list.each(function(child) {
  1245. var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
  1246. var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
  1247. selected.push([title,url]);
  1248. });
  1249. return selected;
  1250. },
  1251. subscribe: function() {
  1252. var mode = this.attr('value').mode;
  1253. var selected = [];
  1254. if (mode == "1")
  1255. selected = this.getSelectedFeeds();
  1256. else
  1257. selected = this.getSelectedFeedIds();
  1258. if (selected.length > 0) {
  1259. dijit.byId("feedBrowserDlg").hide();
  1260. notify_progress("Loading, please wait...", true);
  1261. // we use dojo.toJson instead of JSON.stringify because
  1262. // it somehow escapes everything TWICE, at least in Chrome 9
  1263. var query = "?op=rpc&method=massSubscribe&payload="+
  1264. param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
  1265. console.log(query);
  1266. new Ajax.Request("backend.php", {
  1267. parameters: query,
  1268. onComplete: function(transport) {
  1269. notify('');
  1270. updateFeedList();
  1271. } });
  1272. } else {
  1273. alert(__("No feeds are selected."));
  1274. }
  1275. },
  1276. update: function() {
  1277. var query = dojo.objectToQuery(dialog.attr('value'));
  1278. Element.show('feed_browser_spinner');
  1279. new Ajax.Request("backend.php", {
  1280. parameters: query,
  1281. onComplete: function(transport) {
  1282. notify('');
  1283. Element.hide('feed_browser_spinner');
  1284. var c = $("browseFeedList");
  1285. var reply = JSON.parse(transport.responseText);
  1286. var r = reply['content'];
  1287. var mode = reply['mode'];
  1288. if (c && r) {
  1289. c.innerHTML = r;
  1290. }
  1291. dojo.parser.parse("browseFeedList");
  1292. if (mode == 2) {
  1293. Element.show(dijit.byId('feed_archive_remove').domNode);
  1294. } else {
  1295. Element.hide(dijit.byId('feed_archive_remove').domNode);
  1296. }
  1297. } });
  1298. },
  1299. removeFromArchive: function() {
  1300. var selected = this.getSelectedFeedIds();
  1301. if (selected.length > 0) {
  1302. var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
  1303. if (confirm(pr)) {
  1304. Element.show('feed_browser_spinner');
  1305. var query = "?op=rpc&method=remarchive&ids=" +
  1306. param_escape(selected.toString());;
  1307. new Ajax.Request("backend.php", {
  1308. parameters: query,
  1309. onComplete: function(transport) {
  1310. dialog.update();
  1311. } });
  1312. }
  1313. }
  1314. },
  1315. execute: function() {
  1316. if (this.validate()) {
  1317. this.subscribe();
  1318. }
  1319. },
  1320. href: query});
  1321. dialog.show();
  1322. } catch (e) {
  1323. exception_error("editFeed", e);
  1324. }
  1325. }
  1326. function showFeedsWithErrors() {
  1327. try {
  1328. var query = "backend.php?op=pref-feeds&method=feedsWithErrors";
  1329. if (dijit.byId("errorFeedsDlg"))
  1330. dijit.byId("errorFeedsDlg").destroyRecursive();
  1331. dialog = new dijit.Dialog({
  1332. id: "errorFeedsDlg",
  1333. title: __("Feeds with update errors"),
  1334. style: "width: 600px",
  1335. getSelectedFeeds: function() {
  1336. return getSelectedTableRowIds("prefErrorFeedList");
  1337. },
  1338. removeSelected: function() {
  1339. var sel_rows = this.getSelectedFeeds();
  1340. console.log(sel_rows);
  1341. if (sel_rows.length > 0) {
  1342. var ok = confirm(__("Remove selected feeds?"));
  1343. if (ok) {
  1344. notify_progress("Removing selected feeds...", true);
  1345. var query = "?op=pref-feeds&method=remove&ids="+
  1346. param_escape(sel_rows.toString());
  1347. new Ajax.Request("backend.php", {
  1348. parameters: query,
  1349. onComplete: function(transport) {
  1350. notify('');
  1351. dialog.hide();
  1352. updateFeedList();
  1353. } });
  1354. }
  1355. } else {
  1356. alert(__("No feeds are selected."));
  1357. }
  1358. },
  1359. execute: function() {
  1360. if (this.validate()) {
  1361. }
  1362. },
  1363. href: query});
  1364. dialog.show();
  1365. } catch (e) {
  1366. exception_error("showFeedsWithErrors", e);
  1367. }
  1368. }
  1369. /* new support functions for SelectByTag */
  1370. function get_all_tags(selObj){
  1371. try {
  1372. if( !selObj ) return "";
  1373. var result = "";
  1374. var len = selObj.options.length;
  1375. for (var i=0; i < len; i++){
  1376. if (selObj.options[i].selected) {
  1377. result += selObj[i].value + "%2C"; // is really a comma
  1378. }
  1379. }
  1380. if (result.length > 0){
  1381. result = result.substr(0, result.length-3); // remove trailing %2C
  1382. }
  1383. return(result);
  1384. } catch (e) {
  1385. exception_error("get_all_tags", e);
  1386. }
  1387. }
  1388. function get_radio_checked(radioObj) {
  1389. try {
  1390. if (!radioObj) return "";
  1391. var len = radioObj.length;
  1392. if (len == undefined){
  1393. if(radioObj.checked){
  1394. return(radioObj.value);
  1395. } else {
  1396. return("");
  1397. }
  1398. }
  1399. for( var i=0; i < len; i++ ){
  1400. if( radioObj[i].checked ){
  1401. return( radioObj[i].value);
  1402. }
  1403. }
  1404. } catch (e) {
  1405. exception_error("get_radio_checked", e);
  1406. }
  1407. return("");
  1408. }
  1409. function get_timestamp() {
  1410. var date = new Date();
  1411. return Math.round(date.getTime() / 1000);
  1412. }
  1413. function helpDialog(topic) {
  1414. try {
  1415. var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
  1416. if (dijit.byId("helpDlg"))
  1417. dijit.byId("helpDlg").destroyRecursive();
  1418. dialog = new dijit.Dialog({
  1419. id: "helpDlg",
  1420. title: __("Help"),
  1421. style: "width: 600px",
  1422. href: query,
  1423. });
  1424. dialog.show();
  1425. } catch (e) {
  1426. exception_error("helpDialog", e);
  1427. }
  1428. }
  1429. function htmlspecialchars_decode (string, quote_style) {
  1430. // http://kevin.vanzonneveld.net
  1431. // + original by: Mirek Slugen
  1432. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1433. // + bugfixed by: Mateusz "loonquawl" Zalega
  1434. // + input by: ReverseSyntax
  1435. // + input by: Slawomir Kaniecki
  1436. // + input by: Scott Cariss
  1437. // + input by: Francois
  1438. // + bugfixed by: Onno Marsman
  1439. // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  1440. // + bugfixed by: Brett Zamir (http://brett-zamir.me)
  1441. // + input by: Ratheous
  1442. // + input by: Mailfaker (http://www.weedem.fr/)
  1443. // + reimplemented by: Brett Zamir (http://brett-zamir.me)
  1444. // + bugfixed by: Brett Zamir (http://brett-zamir.me)
  1445. // * example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
  1446. // * returns 1: '<p>this -> &quot;</p>'
  1447. // * example 2: htmlspecialchars_decode("&amp;quot;");
  1448. // * returns 2: '&quot;'
  1449. var optTemp = 0,
  1450. i = 0,
  1451. noquotes = false;
  1452. if (typeof quote_style === 'undefined') {
  1453. quote_style = 2;
  1454. }
  1455. string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  1456. var OPTS = {
  1457. 'ENT_NOQUOTES': 0,
  1458. 'ENT_HTML_QUOTE_SINGLE': 1,
  1459. 'ENT_HTML_QUOTE_DOUBLE': 2,
  1460. 'ENT_COMPAT': 2,
  1461. 'ENT_QUOTES': 3,
  1462. 'ENT_IGNORE': 4
  1463. };
  1464. if (quote_style === 0) {
  1465. noquotes = true;
  1466. }
  1467. if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
  1468. quote_style = [].concat(quote_style);
  1469. for (i = 0; i < quote_style.length; i++) {
  1470. // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
  1471. if (OPTS[quote_style[i]] === 0) {
  1472. noquotes = true;
  1473. } else if (OPTS[quote_style[i]]) {
  1474. optTemp = optTemp | OPTS[quote_style[i]];
  1475. }
  1476. }
  1477. quote_style = optTemp;
  1478. }
  1479. if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
  1480. string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
  1481. // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
  1482. }
  1483. if (!noquotes) {
  1484. string = string.replace(/&quot;/g, '"');
  1485. }
  1486. // Put this in last place to avoid escape being double-decoded
  1487. string = string.replace(/&amp;/g, '&');
  1488. return string;
  1489. }
  1490. function label_to_feed_id(label) {
  1491. return _label_base_index - 1 - Math.abs(label);
  1492. }
  1493. function feed_to_label_id(feed) {
  1494. return _label_base_index - 1 + Math.abs(feed);
  1495. }
  1496. // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
  1497. function getSelectionText() {
  1498. var text = "";
  1499. if (typeof window.getSelection != "undefined") {
  1500. var sel = window.getSelection();
  1501. if (sel.rangeCount) {
  1502. var container = document.createElement("div");
  1503. for (var i = 0, len = sel.rangeCount; i < len; ++i) {
  1504. container.appendChild(sel.getRangeAt(i).cloneContents());
  1505. }
  1506. text = container.innerHTML;
  1507. }
  1508. } else if (typeof document.selection != "undefined") {
  1509. if (document.selection.type == "Text") {
  1510. text = document.selection.createRange().textText;
  1511. }
  1512. }
  1513. return text.stripTags();
  1514. }