2021-02-12 12:22:10 +00:00
|
|
|
/* global Plugins, xhrJson, Notify, fox, xhrPost, __ */
|
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
Plugins.Share = {
|
|
|
|
shareArticle: function(id) {
|
|
|
|
const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id);
|
2011-12-21 04:46:39 +00:00
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2011-12-21 04:46:39 +00:00
|
|
|
id: "shareArticleDlg",
|
|
|
|
title: __("Share article by URL"),
|
2018-12-03 07:51:14 +00:00
|
|
|
newurl: function () {
|
2018-11-30 10:05:59 +00:00
|
|
|
if (confirm(__("Generate new share URL for this article?"))) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Trying to change URL...", true);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id};
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
xhrJson("backend.php", query, (reply) => {
|
|
|
|
if (reply) {
|
|
|
|
const new_link = reply.link;
|
|
|
|
const e = $('gen_article_url');
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
if (new_link) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
e.href = e.href.replace(/\&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
new Effect.Highlight(e);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
const img = $("SHARE-IMG-" + id);
|
2018-12-05 19:19:46 +00:00
|
|
|
img.addClassName("shared");
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
} else {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.error("Could not change URL.");
|
2018-11-30 12:23:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-07-11 10:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2018-12-03 07:51:14 +00:00
|
|
|
unshare: function () {
|
2018-11-30 10:05:59 +00:00
|
|
|
if (confirm(__("Remove sharing for this article?"))) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-09 08:48:29 +00:00
|
|
|
try {
|
|
|
|
const img = $("SHARE-IMG-" + id);
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2018-12-09 08:48:29 +00:00
|
|
|
if (img) {
|
|
|
|
img.removeClassName("shared");
|
|
|
|
img.up("div[id*=RROW]").removeClassName("shared");
|
|
|
|
}
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2018-12-09 08:48:29 +00:00
|
|
|
dialog.hide();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-11-30 12:23:48 +00:00
|
|
|
});
|
2013-07-11 10:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2018-12-03 07:51:14 +00:00
|
|
|
href: query
|
|
|
|
});
|
2011-12-21 04:46:39 +00:00
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
const img = $("SHARE-IMG-" + id);
|
2018-12-05 19:19:46 +00:00
|
|
|
img.addClassName("shared");
|
2011-12-21 04:46:39 +00:00
|
|
|
}
|
2021-02-12 12:22:10 +00:00
|
|
|
}
|