From: Matthias Schmidt Date: Mon, 19 Apr 2021 12:34:32 +0000 (+0200) Subject: Add dialog with anonymous/personalized links for RSS feeds (#4123) X-Git-Tag: 5.4.0_Alpha_1~76 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9c9588a6ddaeb15999ad472b9a14a5cd949da737;p=GitHub%2FWoltLab%2FWCF.git Add dialog with anonymous/personalized links for RSS feeds (#4123) Close #3661 --- diff --git a/com.woltlab.wcf/templates/articleList.tpl b/com.woltlab.wcf/templates/articleList.tpl index 18849b803a..c27c753972 100644 --- a/com.woltlab.wcf/templates/articleList.tpl +++ b/com.woltlab.wcf/templates/articleList.tpl @@ -14,7 +14,7 @@ {/capture} {capture assign='headerNavigation'} -
  • +
  • {if ARTICLE_ENABLE_VISIT_TRACKING}
  • {/if} diff --git a/com.woltlab.wcf/templates/categoryArticleList.tpl b/com.woltlab.wcf/templates/categoryArticleList.tpl index 60b3e32636..33b310afec 100644 --- a/com.woltlab.wcf/templates/categoryArticleList.tpl +++ b/com.woltlab.wcf/templates/categoryArticleList.tpl @@ -19,7 +19,7 @@ {/capture} {capture assign='headerNavigation'} -
  • +
  • {if $__wcf->user->userID}
  • {/if} diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index 64560c01dc..27d2649b7f 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -147,7 +147,13 @@ window.addEventListener('pageshow', function(event) { 'wcf.message.share.permalink.html': '{jslang}wcf.message.share.permalink.html{/jslang}', 'wcf.message.share.socialMedia': '{jslang}wcf.message.share.socialMedia{/jslang}', 'wcf.message.share.copy': '{jslang}wcf.message.share.copy{/jslang}', - 'wcf.message.share.copy.success': '{jslang}wcf.message.share.copy.success{/jslang}' + 'wcf.message.share.copy.success': '{jslang}wcf.message.share.copy.success{/jslang}', + 'wcf.global.button.rss': '{jslang}wcf.global.button.rss{/jslang}', + 'wcf.global.rss.copy': '{jslang}wcf.global.rss.copy{/jslang}', + 'wcf.global.rss.copy.success': '{jslang}wcf.global.rss.copy.success{/jslang}', + 'wcf.global.rss.accessToken.info': '{jslang}wcf.global.rss.accessToken.info{/jslang}', + 'wcf.global.rss.withoutAccessToken': '{jslang}wcf.global.rss.withoutAccessToken{/jslang}', + 'wcf.global.rss.withAccessToken': '{jslang}wcf.global.rss.withAccessToken{/jslang}' {if MODULE_LIKE} ,'wcf.like.button.like': '{jslang}wcf.like.button.like{/jslang}', 'wcf.like.button.dislike': '{jslang}wcf.like.button.dislike{/jslang}', diff --git a/com.woltlab.wcf/templates/notificationList.tpl b/com.woltlab.wcf/templates/notificationList.tpl index 33338e7f13..d2a661f54c 100644 --- a/com.woltlab.wcf/templates/notificationList.tpl +++ b/com.woltlab.wcf/templates/notificationList.tpl @@ -22,7 +22,7 @@ {/capture} {capture assign='headerNavigation'} -
  • +
  • {/capture} {include file='userMenuSidebar'} diff --git a/ts/WoltLabSuite/Core/BootstrapFrontend.ts b/ts/WoltLabSuite/Core/BootstrapFrontend.ts index d58f13ce66..61c5f8f270 100644 --- a/ts/WoltLabSuite/Core/BootstrapFrontend.ts +++ b/ts/WoltLabSuite/Core/BootstrapFrontend.ts @@ -17,6 +17,8 @@ import * as UiMessageUserConsent from "./Ui/Message/UserConsent"; import * as Ajax from "./Ajax"; import * as UiMessageShareDialog from "./Ui/Message/Share/Dialog"; import * as UiMessageShareProviders from "./Ui/Message/Share/Providers"; +import * as UiFeedDialog from "./Ui/Feed/Dialog"; +import User from "./User"; interface BoostrapOptions { backgroundQueue: { @@ -91,4 +93,8 @@ export function setup(options: BoostrapOptions): void { UiMessageShareProviders.enableShareProviders(options.shareButtonProviders || []); UiMessageShareDialog.setup(); + + if (User.userId) { + UiFeedDialog.setup(); + } } diff --git a/ts/WoltLabSuite/Core/Ui/Feed/Dialog.ts b/ts/WoltLabSuite/Core/Ui/Feed/Dialog.ts new file mode 100644 index 0000000000..925ed6afe6 --- /dev/null +++ b/ts/WoltLabSuite/Core/Ui/Feed/Dialog.ts @@ -0,0 +1,83 @@ +/** + * Shows a dialog with an anonymous and personalized link for RSS feeds with access tokens. + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Feed/Dialog + */ + +import UiDialog from "../Dialog"; +import * as StringUtil from "../../StringUtil"; +import * as Language from "../../Language"; +import * as Clipboard from "../../Clipboard"; +import * as UiNotification from "../Notification"; + +/** + * Copies one of links to the clipboard. + */ +async function copy(event: Event): Promise { + event.preventDefault(); + + const target = event.currentTarget as HTMLElement; + const input = target.parentNode!.querySelector('input[type="text"]') as HTMLInputElement; + + await Clipboard.copyTextToClipboard(input.value); + + UiNotification.show(Language.get("wcf.global.rss.copy.success")); +} + +/** + * Opens the dialog with an anonymous and personalized link after clicking on the RSS feed link. + */ +function openDialog(event: Event): void { + event.preventDefault(); + + const alternative = event.currentTarget as HTMLAnchorElement; + const linkWithAccessToken = alternative.href; + + const linkWithoutAccessToken = linkWithAccessToken.replace(/(\\?|&)at=[^&]*&?/, "$1").replace(/(\?|&)$/, ""); + + UiDialog.openStatic( + "feedLinkDialog", + ` +

    ${Language.get("wcf.global.rss.accessToken.info")}

    +
    +
    ${Language.get("wcf.global.rss.withoutAccessToken")}
    +
    +
    + + +
    +
    +
    +
    +
    ${Language.get("wcf.global.rss.withAccessToken")}
    +
    +
    + + +
    +
    +
    +`, + { + onSetup(content: HTMLElement) { + content + .querySelectorAll(".feedLinkDialogCopyButton") + .forEach((el) => el.addEventListener("click", (ev) => copy(ev))); + }, + title: alternative.title || Language.get("wcf.global.button.rss"), + }, + ); +} + +export function setup(): void { + document.querySelectorAll("a.rssFeed").forEach((link: HTMLAnchorElement) => { + link.addEventListener("click", (ev) => openDialog(ev)); + }); +} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js index b5623a30e2..474c1893f9 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @module WoltLabSuite/Core/BootstrapFrontend */ -define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Controller/Style/Changer", "./Controller/Popover", "./Ui/User/Ignore", "./Ui/Page/Header/Menu", "./Ui/Message/UserConsent", "./Ajax", "./Ui/Message/Share/Dialog", "./Ui/Message/Share/Providers"], function (require, exports, tslib_1, BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent, Ajax, UiMessageShareDialog, UiMessageShareProviders) { +define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Controller/Style/Changer", "./Controller/Popover", "./Ui/User/Ignore", "./Ui/Page/Header/Menu", "./Ui/Message/UserConsent", "./Ajax", "./Ui/Message/Share/Dialog", "./Ui/Message/Share/Providers", "./Ui/Feed/Dialog", "./User"], function (require, exports, tslib_1, BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent, Ajax, UiMessageShareDialog, UiMessageShareProviders, UiFeedDialog, User_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setup = void 0; @@ -20,6 +20,8 @@ define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Co Ajax = tslib_1.__importStar(Ajax); UiMessageShareDialog = tslib_1.__importStar(UiMessageShareDialog); UiMessageShareProviders = tslib_1.__importStar(UiMessageShareProviders); + UiFeedDialog = tslib_1.__importStar(UiFeedDialog); + User_1 = tslib_1.__importDefault(User_1); /** * Initializes user profile popover. */ @@ -72,6 +74,9 @@ define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Co UiMessageUserConsent.init(); UiMessageShareProviders.enableShareProviders(options.shareButtonProviders || []); UiMessageShareDialog.setup(); + if (User_1.default.userId) { + UiFeedDialog.setup(); + } } exports.setup = setup; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Feed/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Feed/Dialog.js new file mode 100644 index 0000000000..70d4077698 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Feed/Dialog.js @@ -0,0 +1,71 @@ +/** + * Shows a dialog with an anonymous and personalized link for RSS feeds with access tokens. + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Feed/Dialog + */ +define(["require", "exports", "tslib", "../Dialog", "../../StringUtil", "../../Language", "../../Clipboard", "../Notification"], function (require, exports, tslib_1, Dialog_1, StringUtil, Language, Clipboard, UiNotification) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.setup = void 0; + Dialog_1 = tslib_1.__importDefault(Dialog_1); + StringUtil = tslib_1.__importStar(StringUtil); + Language = tslib_1.__importStar(Language); + Clipboard = tslib_1.__importStar(Clipboard); + UiNotification = tslib_1.__importStar(UiNotification); + /** + * Copies one of links to the clipboard. + */ + async function copy(event) { + event.preventDefault(); + const target = event.currentTarget; + const input = target.parentNode.querySelector('input[type="text"]'); + await Clipboard.copyTextToClipboard(input.value); + UiNotification.show(Language.get("wcf.global.rss.copy.success")); + } + /** + * Opens the dialog with an anonymous and personalized link after clicking on the RSS feed link. + */ + function openDialog(event) { + event.preventDefault(); + const alternative = event.currentTarget; + const linkWithAccessToken = alternative.href; + const linkWithoutAccessToken = linkWithAccessToken.replace(/(\\?|&)at=[^&]*&?/, "$1").replace(/(\?|&)$/, ""); + Dialog_1.default.openStatic("feedLinkDialog", ` +

    ${Language.get("wcf.global.rss.accessToken.info")}

    +
    +
    ${Language.get("wcf.global.rss.withoutAccessToken")}
    +
    +
    + + +
    +
    +
    +
    +
    ${Language.get("wcf.global.rss.withAccessToken")}
    +
    +
    + + +
    +
    +
    +`, { + onSetup(content) { + content + .querySelectorAll(".feedLinkDialogCopyButton") + .forEach((el) => el.addEventListener("click", (ev) => copy(ev))); + }, + title: alternative.title || Language.get("wcf.global.button.rss"), + }); + } + function setup() { + document.querySelectorAll("a.rssFeed").forEach((link) => { + link.addEventListener("click", (ev) => openDialog(ev)); + }); + } + exports.setup = setup; +}); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 61114990b9..6e8bdb3976 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3962,6 +3962,11 @@ Dateianhänge: + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 7d6850b3a9..48b22a0852 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3909,6 +3909,11 @@ Attachments: + + + + +