Add support for the CKEditor license key
authorAlexander Ebert <ebert@woltlab.com>
Tue, 26 Sep 2023 15:03:50 +0000 (17:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 26 Sep 2023 15:03:50 +0000 (17:03 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
ts/WoltLabSuite/Core/Component/Ckeditor.ts
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js
wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php
wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php

index c5783014ba23ab80c63e1cb27d4a554e3eadf662..f8875342848e3a60c4ba9592edce961990fbb100 100644 (file)
                        {/foreach}
                ];
 
-               void setupCkeditor(element, features, bbcodes, codeBlockLanguages);
+               void setupCkeditor(element, features, bbcodes, codeBlockLanguages, '{@$__wcf->getBBCodeHandler()->getCkeditorLicenseKey()|encodeJS}');
        });
 </script>
index 88e5cd32409ce787a1c010ecd277ab64d4c0181f..0eaa6b303c03e13f371b8eff6974dc771e5434cc 100644 (file)
@@ -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<CKEditor> {
   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);
 
index c5783014ba23ab80c63e1cb27d4a554e3eadf662..f8875342848e3a60c4ba9592edce961990fbb100 100644 (file)
                        {/foreach}
                ];
 
-               void setupCkeditor(element, features, bbcodes, codeBlockLanguages);
+               void setupCkeditor(element, features, bbcodes, codeBlockLanguages, '{@$__wcf->getBBCodeHandler()->getCkeditorLicenseKey()|encodeJS}');
        });
 </script>
index e3b713d4cb26e0135b6e50c802859792d37e7df9..5b968abdd82b3e93c78112cc1360a44db5bd9e21 100644 (file)
@@ -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);
index a8597db42e280897aa52af6cac93a881176ecabd..b7b80806cb8ef8ef583d6d46d498279baf92442e 100644 (file)
@@ -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'] ?? '';
+    }
 }
index 80f059e592f51b1d7ad7a80923ea247d899365c9..dbe9962c346b5ee069541934f336e2ff0f543541 100644 (file)
@@ -43,8 +43,13 @@ final class LicenseApi
             self::LICENSE_FILE,
             \sprintf(
                 <<<'EOT'
-                return '%s';
+                <?php
+                /* GENERATED AT %s -- DO NOT EDIT */
+                return <<<'JSON'
+                %s
+                JSON;
                 EOT,
+                \gmdate('r', \TIME_NOW),
                 $this->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);