move some more stuff out of common.js

rework client-side cookie functions a bit
limit dojo cachebust based on server scripts modification time
remove param_escape()
master
Andrew Dolgov 6 years ago
parent ad1b6f0a86
commit d9c5c93cef

@ -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>";
}

@ -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>";

@ -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;
}

@ -91,7 +91,7 @@
<script>
dojoConfig = {
async: true,
cacheBust: new Date(),
cacheBust: "<?php echo get_scripts_timestamp(); ?>",
packages: [
{ name: "fox", location: "../../js" },
]

@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) {
return false;
},
editTags: function(id) {
const query = "backend.php?op=article&method=editArticleTags&param=" + param_escape(id);
const query = "backend.php?op=article&method=editArticleTags&param=" + encodeURIComponent(id);
if (dijit.byId("editTagsDlg"))
dijit.byId("editTagsDlg").destroyRecursive();

@ -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";

@ -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",

@ -608,7 +608,7 @@ define(["dojo/_base/declare"], function (declare) {
},
search: function() {
const query = "backend.php?op=feeds&method=search&param=" +
param_escape(Feeds.getActive() + ":" + Feeds.activeIsCat());
encodeURIComponent(Feeds.getActive() + ":" + Feeds.activeIsCat());
if (dijit.byId("searchDlg"))
dijit.byId("searchDlg").destroyRecursive();

@ -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();

@ -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();

@ -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();

@ -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();

@ -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) {

@ -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 {

@ -1,7 +1,7 @@
function showTrgmRelated(id) {
try {
const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated&param=" + param_escape(id);
const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated&param=" + encodeURIComponent(id);
if (dijit.byId("trgmRelatedDlg"))
dijit.byId("trgmRelatedDlg").destroyRecursive();

@ -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&param=" + param_escape(id);
var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle&param=" + encodeURIComponent(id);
dialog = new dijit.Dialog({
id: "emailArticleDlg",

@ -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&param=" + param_escape(id);
const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle&param=" + encodeURIComponent(id);
dialog = new dijit.Dialog({
id: "emailArticleDlg",

@ -1,7 +1,7 @@
function editArticleNote(id) {
try {
var query = "backend.php?op=pluginhandler&plugin=note&method=edit&param=" + param_escape(id);
var query = "backend.php?op=pluginhandler&plugin=note&method=edit&param=" + encodeURIComponent(id);
if (dijit.byId("editNoteDlg"))
dijit.byId("editNoteDlg").destroyRecursive();

@ -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&param=" + param_escape(id);
var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + 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" },

Loading…
Cancel
Save