From: Alexander Ebert Date: Tue, 26 Sep 2023 15:03:50 +0000 (+0200) Subject: Add support for the CKEditor license key X-Git-Tag: 6.0.0_RC_2~3^2~15 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2ef8729be834f6b18c4d9d1c4fb5bc644cd58177;p=GitHub%2FWoltLab%2FWCF.git Add support for the CKEditor license key --- diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index c5783014ba..f887534284 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -106,6 +106,6 @@ {/foreach} ]; - void setupCkeditor(element, features, bbcodes, codeBlockLanguages); + void setupCkeditor(element, features, bbcodes, codeBlockLanguages, '{@$__wcf->getBBCodeHandler()->getCkeditorLicenseKey()|encodeJS}'); }); diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor.ts b/ts/WoltLabSuite/Core/Component/Ckeditor.ts index 88e5cd3240..0eaa6b303c 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor.ts @@ -207,7 +207,7 @@ function initializeConfiguration( languages: codeBlockLanguages, }; - (configuration as any).woltlabBbcode = bbcodes; + configuration.woltlabBbcode = bbcodes; if (features.autosave !== "") { initializeAutosave(element, configuration, features.autosave); @@ -252,6 +252,7 @@ export async function setupCkeditor( features: Features, bbcodes: WoltlabBbcodeItem[], codeBlockLanguages: CKEditor5.CodeBlock.CodeBlockConfig["languages"], + licenseKey: string, ): Promise { if (instances.has(element)) { throw new TypeError(`Cannot initialize the editor for '${element.id}' twice.`); @@ -279,6 +280,9 @@ export async function setupCkeditor( } const configuration = initializeConfiguration(element, features, bbcodes, codeBlockLanguages, CKEditor5); + if (licenseKey) { + configuration.licenseKey = licenseKey; + } normalizeLegacyMessage(element); diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index c5783014ba..f887534284 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -106,6 +106,6 @@ {/foreach} ]; - void setupCkeditor(element, features, bbcodes, codeBlockLanguages); + void setupCkeditor(element, features, bbcodes, codeBlockLanguages, '{@$__wcf->getBBCodeHandler()->getCkeditorLicenseKey()|encodeJS}'); }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js index e3b713d4cb..5b968abdd8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js @@ -179,7 +179,7 @@ define(["require", "exports", "tslib", "./Ckeditor/Attachment", "./Ckeditor/Medi } return false; } - async function setupCkeditor(element, features, bbcodes, codeBlockLanguages) { + async function setupCkeditor(element, features, bbcodes, codeBlockLanguages, licenseKey) { if (instances.has(element)) { throw new TypeError(`Cannot initialize the editor for '${element.id}' twice.`); } @@ -200,6 +200,9 @@ define(["require", "exports", "tslib", "./Ckeditor/Attachment", "./Ckeditor/Medi (0, Quote_1.setup)(element); } const configuration = initializeConfiguration(element, features, bbcodes, codeBlockLanguages, CKEditor5); + if (licenseKey) { + configuration.licenseKey = licenseKey; + } (0, Normalizer_1.normalizeLegacyMessage)(element); const cke = await createEditor(element, configuration); const ckeditor = new Ckeditor(cke, features); diff --git a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php index a8597db42e..b7b80806cb 100644 --- a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php @@ -5,6 +5,7 @@ namespace wcf\system\bbcode; use wcf\data\bbcode\BBCode; use wcf\data\bbcode\BBCodeCache; use wcf\system\application\ApplicationHandler; +use wcf\system\package\license\LicenseApi; use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\ArrayUtil; @@ -321,4 +322,17 @@ class BBCodeHandler extends SingletonFactory // yield any module if this locale is (implicitly) requested. return ""; } + + /** + * @since 6.0 + */ + public function getCkeditorLicenseKey(): string + { + $licenseApi = LicenseApi::readFromFile(); + if ($licenseApi === null) { + return ''; + } + + return $licenseApi->getData()['license']['ckeditorLicenseKey'] ?? ''; + } } diff --git a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php index 80f059e592..dbe9962c34 100644 --- a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php +++ b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php @@ -43,8 +43,13 @@ final class LicenseApi self::LICENSE_FILE, \sprintf( <<<'EOT' - return '%s'; + json, ) ); @@ -118,7 +123,7 @@ final class LicenseApi return null; } - $content = \file_get_contents(self::LICENSE_FILE); + $content = require(self::LICENSE_FILE); try { return new LicenseApi($content);