diff options
-rw-r--r-- | classes/dlg.php | 10 | ||||
-rwxr-xr-x | classes/pref/feeds.php | 4 | ||||
-rwxr-xr-x | include/functions.php | 12 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | js/Article.js | 2 | ||||
-rw-r--r-- | js/CommonDialogs.js | 34 | ||||
-rw-r--r-- | js/CommonFilters.js | 4 | ||||
-rw-r--r-- | js/Feeds.js | 2 | ||||
-rw-r--r-- | js/PrefFilterTree.js | 2 | ||||
-rw-r--r-- | js/PrefLabelTree.js | 2 | ||||
-rw-r--r-- | js/PrefUsers.js | 2 | ||||
-rw-r--r-- | js/Utils.js | 2 | ||||
-rwxr-xr-x | js/common.js | 126 | ||||
-rw-r--r-- | js/tt-rss.js | 32 | ||||
-rw-r--r-- | plugins/af_psql_trgm/init.js | 2 | ||||
-rw-r--r-- | plugins/mail/mail.js | 2 | ||||
-rw-r--r-- | plugins/mailto/init.js | 2 | ||||
-rw-r--r-- | plugins/note/note.js | 2 | ||||
-rw-r--r-- | plugins/share/share.js | 2 | ||||
-rw-r--r-- | prefs.php | 2 |
20 files changed, 111 insertions, 137 deletions
diff --git a/classes/dlg.php b/classes/dlg.php index 7e66c4b5e..32c41ee34 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -52,7 +52,7 @@ class Dlg extends Handler_Protected { print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">". __('Generate new URL')."</button> "; - print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">". + print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.closeInfoBox()\">". __('Close this window')."</button>"; print "</div>"; @@ -85,7 +85,7 @@ class Dlg extends Handler_Protected { print "<div align='center'>"; - print "<button onclick=\"return closeInfoBox()\">". + print "<button onclick=\"return CommonDialogs.closeInfoBox()\">". __('Close this window')."</button>"; print "</div>"; @@ -150,7 +150,7 @@ class Dlg extends Handler_Protected { print "<div align='center'>"; print "<button dojoType=\"dijit.form.Button\" - onclick=\"return closeInfoBox()\">". + onclick=\"return CommonDialogs.closeInfoBox()\">". __('Close this window')."</button>"; print "</div>"; @@ -179,7 +179,7 @@ class Dlg extends Handler_Protected { print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">". __('Generate new URL')."</button> "; - print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">". + print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.closeInfoBox()\">". __('Close this window')."</button>"; print "</div>"; @@ -195,7 +195,7 @@ class Dlg extends Handler_Protected { print "<button dojoType=\"dijit.form.Button\" onclick=\"document.location.href = 'prefs.php'\">". __('Open Preferences')."</button> "; print "<button dojoType=\"dijit.form.Button\" - onclick=\"return closeInfoBox()\">". + onclick=\"return CommonDialogs.closeInfoBox()\">". __('Close this window')."</button>"; print "</div>"; } diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 3b949073c..7ae7a04c1 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -745,9 +745,9 @@ class Pref_Feeds extends Handler_Protected { <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> <input type=\"hidden\" name=\"method\" value=\"uploadicon\"> - <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" + <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.uploadFeedIcon();\" type=\"submit\">".__('Replace')."</button> - <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" + <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.removeFeedIcon($feed_id);\" type=\"submit\">".__('Remove')."</button> </form>"; diff --git a/include/functions.php b/include/functions.php index baed6fb20..dcb2e7518 100755 --- a/include/functions.php +++ b/include/functions.php @@ -2566,3 +2566,15 @@ function arr_qmarks($arr) { return str_repeat('?,', count($arr) - 1) . '?'; } + + function get_scripts_timestamp() { + $files = glob("js/*.js"); + $ts = 0; + + foreach ($files as $file) { + $file_ts = filemtime($file); + if ($file_ts > $ts) $ts = $file_ts; + } + + return $ts; + }
\ No newline at end of file @@ -91,7 +91,7 @@ <script> dojoConfig = { async: true, - cacheBust: new Date(), + cacheBust: "<?php echo get_scripts_timestamp(); ?>", packages: [ { name: "fox", location: "../../js" }, ] diff --git a/js/Article.js b/js/Article.js index 0e1318948..7e5241fa5 100644 --- a/js/Article.js +++ b/js/Article.js @@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) { return false; }, editTags: function(id) { - const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); + const query = "backend.php?op=article&method=editArticleTags¶m=" + encodeURIComponent(id); if (dijit.byId("editTagsDlg")) dijit.byId("editTagsDlg").destroyRecursive(); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index d8733e1c2..efdc4e503 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -2,6 +2,40 @@ /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { return declare("fox.CommonDialogs", null, { + closeInfoBox: function() { + const dialog = dijit.byId("infoBox"); + if (dialog) dialog.hide(); + }, + removeFeedIcon: function(id) { + if (confirm(__("Remove stored feed icon?"))) { + notify_progress("Removing feed icon...", true); + + const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; + + xhrPost("backend.php", query, () => { + notify_info("Feed icon removed."); + if (App.isPrefs()) { + Feeds.reload(); + } else { + setTimeout('Feeds.reload(false, false)', 50); + } + }); + } + + return false; + }, + uploadFeedIcon: function() { + const file = $("icon_file"); + + if (file.value.length == 0) { + alert(__("Please select an image file to upload.")); + } else if (confirm(__("Upload new icon for this feed?"))) { + notify_progress("Uploading, please wait...", true); + return true; + } + + return false; + }, quickAddFeed: function() { const query = "backend.php?op=feeds&method=quickAddFeed"; diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 3f508ef71..ef087b50c 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -126,7 +126,7 @@ define(["dojo/_base/declare"], function (declare) { dijit.byId("filterNewRuleDlg").destroyRecursive(); const query = "backend.php?op=pref-filters&method=newrule&rule=" + - param_escape(ruleStr); + encodeURIComponent(ruleStr); const rule_dlg = new dijit.Dialog({ id: "filterNewRuleDlg", @@ -148,7 +148,7 @@ define(["dojo/_base/declare"], function (declare) { dijit.byId("filterNewActionDlg").destroyRecursive(); const query = "backend.php?op=pref-filters&method=newaction&action=" + - param_escape(actionStr); + encodeURIComponent(actionStr); const rule_dlg = new dijit.Dialog({ id: "filterNewActionDlg", diff --git a/js/Feeds.js b/js/Feeds.js index c7db1aee5..ec90caba7 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -608,7 +608,7 @@ define(["dojo/_base/declare"], function (declare) { }, search: function() { const query = "backend.php?op=feeds&method=search¶m=" + - param_escape(Feeds.getActive() + ":" + Feeds.activeIsCat()); + encodeURIComponent(Feeds.getActive() + ":" + Feeds.activeIsCat()); if (dijit.byId("searchDlg")) dijit.byId("searchDlg").destroyRecursive(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 9a2dd6c1c..6823fa8ad 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -138,7 +138,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }, editFilter: function(id) { - const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); + const query = "backend.php?op=pref-filters&method=edit&id=" + encodeURIComponent(id); if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").destroyRecursive(); diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 914df9a19..abe79a114 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -56,7 +56,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }, editLabel: function(id) { const query = "backend.php?op=pref-labels&method=edit&id=" + - param_escape(id); + encodeURIComponent(id); if (dijit.byId("labelEditDlg")) dijit.byId("labelEditDlg").destroyRecursive(); diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 891af8ddb..eed64e76b 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -27,7 +27,7 @@ define(["dojo/_base/declare"], function (declare) { }, edit: function(id) { const query = "backend.php?op=pref-users&method=edit&id=" + - param_escape(id); + encodeURIComponent(id); if (dijit.byId("userEditDlg")) dijit.byId("userEditDlg").destroyRecursive(); diff --git a/js/Utils.js b/js/Utils.js index 8778143f2..f01ecbc48 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -95,7 +95,7 @@ define(["dojo/_base/declare"], function (declare) { }); }, helpDialog: function(topic) { - const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); + const query = "backend.php?op=backend&method=help&topic=" + encodeURIComponent(topic); if (dijit.byId("helpDlg")) dijit.byId("helpDlg").destroyRecursive(); diff --git a/js/common.js b/js/common.js index b63257099..9a3c1715d 100755 --- a/js/common.js +++ b/js/common.js @@ -54,6 +54,8 @@ Array.prototype.remove = function(s) { } }; +/* common helpers not worthy of separate Dojo modules */ + const Lists = { onRowChecked: function(elem) { const checked = elem.domNode ? elem.attr("checked") : elem.checked; @@ -113,6 +115,31 @@ const Tables = { } }; +const Cookie = { + set: function (name, value, lifetime) { + const d = new Date(); + d.setTime(d.getTime() + lifetime * 1000); + const expires = "expires=" + d.toUTCString(); + document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires; + }, + get: function (name) { + name = name + "="; + const ca = document.cookie.split(';'); + for (let i=0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length)); + } + return ""; + }, + delete: function(name) { + const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT"; + document.cookie = name + "=" + "" + "; " + expires; + } +}; + +/* error reporting */ + function report_error(message, filename, lineno, colno, error) { exception_error(error, null, filename, lineno); } @@ -177,10 +204,6 @@ function exception_error(e, e_compat, filename, lineno, colno) { } -function param_escape(arg) { - return encodeURIComponent(arg); -} - function notify_real(msg, no_hide, n_type) { const n = $("notify"); @@ -263,58 +286,6 @@ function notify_info(msg, no_hide) { notify_real(msg, no_hide, 4); } -function setCookie(name, value, lifetime, path, domain, secure) { - - let d = false; - - if (lifetime) { - d = new Date(); - d.setTime(d.getTime() + (lifetime * 1000)); - } - - console.log("setCookie: " + name + " => " + value + ": " + d); - - int_setCookie(name, value, d, path, domain, secure); - -} - -function int_setCookie(name, value, expires, path, domain, secure) { - document.cookie= name + "=" + escape(value) + - ((expires) ? "; expires=" + expires.toGMTString() : "") + - ((path) ? "; path=" + path : "") + - ((domain) ? "; domain=" + domain : "") + - ((secure) ? "; secure" : ""); -} - -function delCookie(name, path, domain) { - if (getCookie(name)) { - document.cookie = name + "=" + - ((path) ? ";path=" + path : "") + - ((domain) ? ";domain=" + domain : "" ) + - ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; - } -} - - -function getCookie(name) { - - const dc = document.cookie; - const prefix = name + "="; - let begin = dc.indexOf("; " + prefix); - if (begin == -1) { - begin = dc.indexOf(prefix); - if (begin != 0) return null; - } - else { - begin += 2; - } - let end = document.cookie.indexOf(";", begin); - if (end == -1) { - end = dc.length; - } - return unescape(dc.substring(begin + prefix.length, end)); -} - // noinspection JSUnusedGlobalSymbols function displayIfChecked(checkbox, elemId) { if (checkbox.checked) { @@ -324,15 +295,6 @@ function displayIfChecked(checkbox, elemId) { } } -// noinspection JSUnusedGlobalSymbols -function closeInfoBox() { - const dialog = dijit.byId("infoBox"); - - if (dialog) dialog.hide(); - - return false; -} - function getInitParam(key) { return init_params[key]; } @@ -407,40 +369,6 @@ function uploadIconHandler(rc) { } } -// noinspection JSUnusedGlobalSymbols -function removeFeedIcon(id) { - if (confirm(__("Remove stored feed icon?"))) { - - notify_progress("Removing feed icon...", true); - - const query = { op: "pref-feeds", method: "removeicon", feed_id: id }; - - xhrPost("backend.php", query, () => { - notify_info("Feed icon removed."); - if (App.isPrefs()) { - Feeds.reload(); - } else { - setTimeout('Feeds.reload(false, false)', 50); - } - }); - } - - return false; -} - -// noinspection JSUnusedGlobalSymbols -function uploadFeedIcon() { - const file = $("icon_file"); - - if (file.value.length == 0) { - alert(__("Please select an image file to upload.")); - } else if (confirm(__("Upload new icon for this feed?"))) { - notify_progress("Uploading, please wait...", true); - return true; - } - - return false; -} // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { diff --git a/js/tt-rss.js b/js/tt-rss.js index 74b8403f8..4eeeed131 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -116,9 +116,9 @@ const App = { Feeds.reload(); Article.close(); - if (parseInt(getCookie("ttrss_fh_width")) > 0) { + if (parseInt(Cookie.get("ttrss_fh_width")) > 0) { dijit.byId("feeds-holder").domNode.setStyle( - {width: getCookie("ttrss_fh_width") + "px"}); + {width: Cookie.get("ttrss_fh_width") + "px"}); } dijit.byId("main").resize(); @@ -126,19 +126,19 @@ const App = { dojo.connect(dijit.byId('feeds-holder'), 'resize', function (args) { if (args && args.w >= 0) { - setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); } }); dojo.connect(dijit.byId('content-insert'), 'resize', function (args) { if (args && args.w >= 0 && args.h >= 0) { - setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); - setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); } }); - delCookie("ttrss_test"); + Cookie.delete("ttrss_test"); const toolbar = document.forms["main_toolbar_form"]; @@ -172,9 +172,9 @@ const App = { console.log("second stage ok"); }, genericSanityCheck: function() { - setCookie("ttrss_test", "TEST"); + Cookie.set("ttrss_test", "TEST"); - if (getCookie("ttrss_test") != "TEST") { + if (Cookie.get("ttrss_test") != "TEST") { return fatalError(2); } @@ -224,9 +224,9 @@ const App = { height: 'auto', borderTopWidth: '0px' }); - if (parseInt(getCookie("ttrss_ci_width")) > 0) { + if (parseInt(Cookie.get("ttrss_ci_width")) > 0) { dijit.byId("content-insert").domNode.setStyle( - {width: getCookie("ttrss_ci_width") + "px" }); + {width: Cookie.get("ttrss_ci_width") + "px" }); } $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); @@ -240,9 +240,9 @@ const App = { height: '50%', borderTopWidth: '0px'}); - if (parseInt(getCookie("ttrss_ci_height")) > 0) { + if (parseInt(Cookie.get("ttrss_ci_height")) > 0) { dijit.byId("content-insert").domNode.setStyle( - {height: getCookie("ttrss_ci_height") + "px" }); + {height: Cookie.get("ttrss_ci_height") + "px" }); } $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); @@ -466,8 +466,8 @@ const App = { App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); App.switchPanelMode(App._widescreen_mode); } else { @@ -557,8 +557,8 @@ const App = { App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); App.switchPanelMode(App._widescreen_mode); } else { diff --git a/plugins/af_psql_trgm/init.js b/plugins/af_psql_trgm/init.js index f84bb4877..af2facfc1 100644 --- a/plugins/af_psql_trgm/init.js +++ b/plugins/af_psql_trgm/init.js @@ -1,7 +1,7 @@ function showTrgmRelated(id) { try { - const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated¶m=" + param_escape(id); + const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated¶m=" + encodeURIComponent(id); if (dijit.byId("trgmRelatedDlg")) dijit.byId("trgmRelatedDlg").destroyRecursive(); diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index d6c28048b..af0cf3552 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -14,7 +14,7 @@ function emailArticle(id) { if (dijit.byId("emailArticleDlg")) dijit.byId("emailArticleDlg").destroyRecursive(); - var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + param_escape(id); + var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); dialog = new dijit.Dialog({ id: "emailArticleDlg", diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 47321923a..dacff725e 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -14,7 +14,7 @@ function mailtoArticle(id) { if (dijit.byId("emailArticleDlg")) dijit.byId("emailArticleDlg").destroyRecursive(); - const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + param_escape(id); + const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); dialog = new dijit.Dialog({ id: "emailArticleDlg", diff --git a/plugins/note/note.js b/plugins/note/note.js index ea0094078..c1f317b52 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,7 +1,7 @@ function editArticleNote(id) { try { - var query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + param_escape(id); + var query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); if (dijit.byId("editNoteDlg")) dijit.byId("editNoteDlg").destroyRecursive(); diff --git a/plugins/share/share.js b/plugins/share/share.js index 11748d8fe..4a6a65ce6 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -3,7 +3,7 @@ function shareArticle(id) { if (dijit.byId("shareArticleDlg")) dijit.byId("shareArticleDlg").destroyRecursive(); - var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + param_escape(id); + var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id); dialog = new dijit.Dialog({ id: "shareArticleDlg", @@ -57,7 +57,7 @@ <script> dojoConfig = { async: true, - cacheBust: new Date(), + cacheBust: "<?php echo get_scripts_timestamp(); ?>", packages: [ { name: "lib", location: "../" }, { name: "fox", location: "../../js" }, |