share plugin: cleanup, fix icon not highlighting properly
This commit is contained in:
parent
0fc783e2b3
commit
7adcada324
|
@ -17,18 +17,17 @@ class Share extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_js() {
|
function get_js() {
|
||||||
return file_get_contents(dirname(__FILE__) . "/share.js");
|
return file_get_contents(__DIR__ . "/share.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_css() {
|
function get_css() {
|
||||||
return file_get_contents(dirname(__FILE__) . "/share.css");
|
return file_get_contents(__DIR__ . "/share.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_prefs_js() {
|
function get_prefs_js() {
|
||||||
return file_get_contents(dirname(__FILE__) . "/share_prefs.js");
|
return file_get_contents(__DIR__ . "/share_prefs.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function unshare() {
|
function unshare() {
|
||||||
$id = $_REQUEST['id'];
|
$id = $_REQUEST['id'];
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ class Share extends Plugin {
|
||||||
AND owner_uid = ?");
|
AND owner_uid = ?");
|
||||||
$sth->execute([$id, $_SESSION['uid']]);
|
$sth->execute([$id, $_SESSION['uid']]);
|
||||||
|
|
||||||
print "OK";
|
print __("Article unshared");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hook_prefs_tab_section($id) {
|
function hook_prefs_tab_section($id) {
|
||||||
|
@ -52,16 +51,14 @@ class Share extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Silent
|
|
||||||
function clearArticleKeys() {
|
function clearArticleKeys() {
|
||||||
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = '' WHERE
|
||||||
owner_uid = ?");
|
owner_uid = ?");
|
||||||
$sth->execute([$_SESSION['uid']]);
|
$sth->execute([$_SESSION['uid']]);
|
||||||
|
|
||||||
return;
|
print __("Shared URLs cleared.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function newkey() {
|
function newkey() {
|
||||||
$id = $_REQUEST['id'];
|
$id = $_REQUEST['id'];
|
||||||
$uuid = uniqid_short();
|
$uuid = uniqid_short();
|
||||||
|
@ -70,26 +67,25 @@ class Share extends Plugin {
|
||||||
AND owner_uid = ?");
|
AND owner_uid = ?");
|
||||||
$sth->execute([$uuid, $id, $_SESSION['uid']]);
|
$sth->execute([$uuid, $id, $_SESSION['uid']]);
|
||||||
|
|
||||||
print json_encode(array("link" => $uuid));
|
print json_encode(["link" => $uuid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hook_article_button($line) {
|
function hook_article_button($line) {
|
||||||
$img_class = $line['uuid'] ? "shared" : "";
|
$icon_class = !empty($line['uuid']) ? "is-shared" : "";
|
||||||
|
|
||||||
return "<i id='SHARE-IMG-".$line['int_id']."' class='material-icons icon-share $img_class'
|
return "<i class='material-icons icon-share share-icon-".$line['int_id']." $icon_class'
|
||||||
style='cursor : pointer' onclick=\"Plugins.Share.shareArticle(".$line['int_id'].")\"
|
style='cursor : pointer' onclick=\"Plugins.Share.shareArticle(".$line['int_id'].")\"
|
||||||
title='".__('Share by URL')."'>link</i>";
|
title='".__('Share by URL')."'>link</i>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function shareArticle() {
|
function shareDialog() {
|
||||||
$param = $_REQUEST['param'];
|
$id = (int)clean($_REQUEST['id'] ?? 0);
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT uuid FROM ttrss_user_entries WHERE int_id = ?
|
$sth = $this->pdo->prepare("SELECT uuid FROM ttrss_user_entries WHERE int_id = ?
|
||||||
AND owner_uid = ?");
|
AND owner_uid = ?");
|
||||||
$sth->execute([$param, $_SESSION['uid']]);
|
$sth->execute([$id, $_SESSION['uid']]);
|
||||||
|
|
||||||
if ($row = $sth->fetch()) {
|
if ($row = $sth->fetch()) {
|
||||||
|
|
||||||
$uuid = $row['uuid'];
|
$uuid = $row['uuid'];
|
||||||
|
|
||||||
if (!$uuid) {
|
if (!$uuid) {
|
||||||
|
@ -97,27 +93,26 @@ class Share extends Plugin {
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET uuid = ? WHERE int_id = ?
|
||||||
AND owner_uid = ?");
|
AND owner_uid = ?");
|
||||||
$sth->execute([$uuid, $param, $_SESSION['uid']]);
|
$sth->execute([$uuid, $id, $_SESSION['uid']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$url_path = htmlspecialchars(get_self_url_prefix() . "/public.php?op=share&key=$uuid");
|
$url_path = get_self_url_prefix() . "/public.php?op=share&key=$uuid";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<header><?= __("You can share this article by the following unique URL:") ?></header>
|
<header><?= __("You can share this article by the following unique URL:") ?></header>
|
||||||
|
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<div class='panel text-center'>
|
<div class='panel text-center'>
|
||||||
<a id='gen_article_url' href="<?= $url_path ?>"
|
<a class='target-url' href="<?= htmlspecialchars($url_path) ?>"
|
||||||
target='_blank' rel='noopener noreferrer'><?= $url_path ?></a>
|
target='_blank' rel='noopener noreferrer'><?= htmlspecialchars($url_path) ?></a>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print "Article not found.";
|
print format_error(__("Article not found."));
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
i.icon-share.shared {
|
i.material-icons.icon-share.is-shared {
|
||||||
color : #0a0;
|
color : #0a0;
|
||||||
}
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
/* global Plugins, xhrJson, Notify, fox, xhrPost, __ */
|
/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */
|
||||||
|
|
||||||
Plugins.Share = {
|
Plugins.Share = {
|
||||||
shareArticle: function(id) {
|
shareArticle: function(id) {
|
||||||
const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id);
|
|
||||||
|
|
||||||
const dialog = new fox.SingleUseDialog({
|
const dialog = new fox.SingleUseDialog({
|
||||||
id: "shareArticleDlg",
|
id: "shareArticleDlg",
|
||||||
title: __("Share article by URL"),
|
title: __("Share article by URL"),
|
||||||
|
@ -17,20 +15,23 @@ Plugins.Share = {
|
||||||
xhrJson("backend.php", query, (reply) => {
|
xhrJson("backend.php", query, (reply) => {
|
||||||
if (reply) {
|
if (reply) {
|
||||||
const new_link = reply.link;
|
const new_link = reply.link;
|
||||||
const e = $('gen_article_url');
|
const target = dialog.domNode.querySelector(".target-url");
|
||||||
|
|
||||||
if (new_link) {
|
if (new_link && target) {
|
||||||
|
|
||||||
e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
|
target.innerHTML = target.innerHTML.replace(/&key=.*$/,
|
||||||
"&key=" + new_link);
|
"&key=" + new_link);
|
||||||
|
|
||||||
e.href = e.href.replace(/\&key=.*$/,
|
target.href = target.href.replace(/&key=.*$/,
|
||||||
"&key=" + new_link);
|
"&key=" + new_link);
|
||||||
|
|
||||||
new Effect.Highlight(e);
|
// eslint-disable-next-line no-new
|
||||||
|
new Effect.Highlight(target);
|
||||||
|
|
||||||
const img = $("SHARE-IMG-" + id);
|
const icon = document.querySelector(".share-icon-" + id);
|
||||||
img.addClassName("shared");
|
|
||||||
|
if (icon)
|
||||||
|
icon.addClassName("is-shared");
|
||||||
|
|
||||||
Notify.close();
|
Notify.close();
|
||||||
|
|
||||||
|
@ -44,32 +45,35 @@ Plugins.Share = {
|
||||||
},
|
},
|
||||||
unshare: function () {
|
unshare: function () {
|
||||||
if (confirm(__("Remove sharing for this article?"))) {
|
if (confirm(__("Remove sharing for this article?"))) {
|
||||||
|
xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "unshare", id: id}, (transport) => {
|
||||||
|
Notify.info(transport.responseText);
|
||||||
|
|
||||||
const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
|
const icon = document.querySelector(".share-icon-" + id);
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
if (icon)
|
||||||
try {
|
icon.removeClassName("is-shared");
|
||||||
const img = $("SHARE-IMG-" + id);
|
|
||||||
|
|
||||||
if (img) {
|
dialog.hide();
|
||||||
img.removeClassName("shared");
|
|
||||||
img.up("div[id*=RROW]").removeClassName("shared");
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.hide();
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
href: query
|
content: __("Loading, please wait...")
|
||||||
|
});
|
||||||
|
|
||||||
|
const tmph = dojo.connect(dialog, 'onShow', function () {
|
||||||
|
dojo.disconnect(tmph);
|
||||||
|
|
||||||
|
xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "shareDialog", id: id}, (transport) => {
|
||||||
|
dialog.attr('content', transport.responseText)
|
||||||
|
|
||||||
|
const icon = document.querySelector(".share-icon-" + id);
|
||||||
|
|
||||||
|
if (icon)
|
||||||
|
icon.addClassName("is-shared");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
const img = $("SHARE-IMG-" + id);
|
|
||||||
img.addClassName("shared");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
/* global Plugins, Notify, xhrPost */
|
||||||
|
|
||||||
Plugins.Share = {
|
Plugins.Share = {
|
||||||
clearKeys: function() {
|
clearKeys: function() {
|
||||||
if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) {
|
if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) {
|
||||||
Notify.progress("Clearing URLs...");
|
Notify.progress("Clearing URLs...");
|
||||||
|
|
||||||
const query = {op: "pluginhandler", plugin: "share", method: "clearArticleKeys"};
|
xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "clearArticleKeys"}, (transport) => {
|
||||||
|
Notify.info(transport.responseText);
|
||||||
xhrPost("backend.php", query, () => {
|
|
||||||
Notify.info("Shared URLs cleared.");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue