From 99b1d551e61adb5cbd014677f151f443b0c6c35f Mon Sep 17 00:00:00 2001 From: hkcomori Date: Thu, 6 Jun 2024 03:58:19 +0900 Subject: Add core extensions: UserCSS, UserJS (#6267) * Copy CustomCSS and CustomJS Original: FreshRSS/Extensions@9f21984 * Rename CustomCSS -> UserCSS * Rename CustomJS -> UserJS * Change metadata The name is used for the directory where the configuration is stored and should not contain spaces. Since the name was changed, I reset the version number and changed to semantic versioning. * Change data directory Changed the location of the configuration file to the user data directory, because it is not `static`. That way, the user's configurations are gathered in the user directory, which makes it easier to backup them. * Edit documentations Remove procedures to install the extension because it is no longer necessary. * Fix wrong variables in the configuration page Remove permission error indication because the storage location is now in the user data directory managed by the application. * Remove the `xExtension-` prefix for core extensions * Set version to 1.0.0 for UserCSS, UserJS * Refactoring * Remove unused variables * Remove version 0.0.1 in Changelog Version 0.0.1 will not be merged, so only version 1.0.0 will remain. * public getFileUrl * Revert more protected * Use entrypoint for extension user path instead of name * Add space to extension name * Add `#[\Override]` * Add explains of User CSS and User JS to docs * Remove README of User CSS and User JS * Add migration code for extension user path --------- Co-authored-by: Alexandre Alapetite --- lib/core-extensions/UserCSS/configure.phtml | 20 +++++++++++++++++ lib/core-extensions/UserCSS/extension.php | 34 +++++++++++++++++++++++++++++ lib/core-extensions/UserCSS/i18n/de/ext.php | 7 ++++++ lib/core-extensions/UserCSS/i18n/en/ext.php | 7 ++++++ lib/core-extensions/UserCSS/i18n/fr/ext.php | 7 ++++++ lib/core-extensions/UserCSS/i18n/ja/ext.php | 7 ++++++ lib/core-extensions/UserCSS/metadata.json | 8 +++++++ lib/core-extensions/UserJS/configure.phtml | 20 +++++++++++++++++ lib/core-extensions/UserJS/extension.php | 34 +++++++++++++++++++++++++++++ lib/core-extensions/UserJS/i18n/de/ext.php | 7 ++++++ lib/core-extensions/UserJS/i18n/en/ext.php | 7 ++++++ lib/core-extensions/UserJS/i18n/fr/ext.php | 7 ++++++ lib/core-extensions/UserJS/i18n/ja/ext.php | 7 ++++++ lib/core-extensions/UserJS/metadata.json | 8 +++++++ 14 files changed, 180 insertions(+) create mode 100644 lib/core-extensions/UserCSS/configure.phtml create mode 100644 lib/core-extensions/UserCSS/extension.php create mode 100644 lib/core-extensions/UserCSS/i18n/de/ext.php create mode 100644 lib/core-extensions/UserCSS/i18n/en/ext.php create mode 100644 lib/core-extensions/UserCSS/i18n/fr/ext.php create mode 100644 lib/core-extensions/UserCSS/i18n/ja/ext.php create mode 100644 lib/core-extensions/UserCSS/metadata.json create mode 100644 lib/core-extensions/UserJS/configure.phtml create mode 100644 lib/core-extensions/UserJS/extension.php create mode 100644 lib/core-extensions/UserJS/i18n/de/ext.php create mode 100644 lib/core-extensions/UserJS/i18n/en/ext.php create mode 100644 lib/core-extensions/UserJS/i18n/fr/ext.php create mode 100644 lib/core-extensions/UserJS/i18n/ja/ext.php create mode 100644 lib/core-extensions/UserJS/metadata.json (limited to 'lib/core-extensions') diff --git a/lib/core-extensions/UserCSS/configure.phtml b/lib/core-extensions/UserCSS/configure.phtml new file mode 100644 index 000000000..22d4ea79a --- /dev/null +++ b/lib/core-extensions/UserCSS/configure.phtml @@ -0,0 +1,20 @@ + +
+ +
+ +
+ +
+
+ +
+
+ + +
+
+
diff --git a/lib/core-extensions/UserCSS/extension.php b/lib/core-extensions/UserCSS/extension.php new file mode 100644 index 000000000..5343fd39a --- /dev/null +++ b/lib/core-extensions/UserCSS/extension.php @@ -0,0 +1,34 @@ +registerTranslates(); + if ($this->hasFile(self::FILENAME)) { + Minz_View::appendStyle($this->getFileUrl(self::FILENAME, 'css', false)); + } + } + + #[\Override] + public function handleConfigureAction(): void { + parent::init(); + + $this->registerTranslates(); + + if (Minz_Request::isPost()) { + $css_rules = html_entity_decode(Minz_Request::paramString('css-rules')); + $this->saveFile(self::FILENAME, $css_rules); + } + + $this->css_rules = ''; + if ($this->hasFile(self::FILENAME)) { + $this->css_rules = htmlentities($this->getFile(self::FILENAME) ?? ''); + } + } +} diff --git a/lib/core-extensions/UserCSS/i18n/de/ext.php b/lib/core-extensions/UserCSS/i18n/de/ext.php new file mode 100644 index 000000000..cafc5f2f0 --- /dev/null +++ b/lib/core-extensions/UserCSS/i18n/de/ext.php @@ -0,0 +1,7 @@ + array( + 'write_css' => 'Benutzerspezifische CSS Regeln', + ), +); diff --git a/lib/core-extensions/UserCSS/i18n/en/ext.php b/lib/core-extensions/UserCSS/i18n/en/ext.php new file mode 100644 index 000000000..b82cd8331 --- /dev/null +++ b/lib/core-extensions/UserCSS/i18n/en/ext.php @@ -0,0 +1,7 @@ + array( + 'write_css' => 'Additional CSS rules', + ), +); diff --git a/lib/core-extensions/UserCSS/i18n/fr/ext.php b/lib/core-extensions/UserCSS/i18n/fr/ext.php new file mode 100644 index 000000000..507d8be45 --- /dev/null +++ b/lib/core-extensions/UserCSS/i18n/fr/ext.php @@ -0,0 +1,7 @@ + array( + 'write_css' => 'Règles CSS supplémentaires', + ), +); diff --git a/lib/core-extensions/UserCSS/i18n/ja/ext.php b/lib/core-extensions/UserCSS/i18n/ja/ext.php new file mode 100644 index 000000000..ce8d17c78 --- /dev/null +++ b/lib/core-extensions/UserCSS/i18n/ja/ext.php @@ -0,0 +1,7 @@ + array( + 'write_css' => '追加のCSSルール', + ), +); diff --git a/lib/core-extensions/UserCSS/metadata.json b/lib/core-extensions/UserCSS/metadata.json new file mode 100644 index 000000000..2de79af8c --- /dev/null +++ b/lib/core-extensions/UserCSS/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "User CSS", + "author": "hkcomori, Marien Fressinaud", + "description": "Give possibility to overwrite the CSS with a user-specific rules.", + "version": "1.0.0", + "entrypoint": "UserCSS", + "type": "user" +} diff --git a/lib/core-extensions/UserJS/configure.phtml b/lib/core-extensions/UserJS/configure.phtml new file mode 100644 index 000000000..88172679d --- /dev/null +++ b/lib/core-extensions/UserJS/configure.phtml @@ -0,0 +1,20 @@ + +
+ +
+ +
+ +
+
+ +
+
+ + +
+
+
diff --git a/lib/core-extensions/UserJS/extension.php b/lib/core-extensions/UserJS/extension.php new file mode 100644 index 000000000..a33114ec5 --- /dev/null +++ b/lib/core-extensions/UserJS/extension.php @@ -0,0 +1,34 @@ +registerTranslates(); + if ($this->hasFile(self::FILENAME)) { + Minz_View::appendScript($this->getFileUrl(self::FILENAME, 'js', false)); + } + } + + #[\Override] + public function handleConfigureAction(): void { + parent::init(); + + $this->registerTranslates(); + + if (Minz_Request::isPost()) { + $js_rules = html_entity_decode(Minz_Request::paramString('js-rules')); + $this->saveFile(self::FILENAME, $js_rules); + } + + $this->js_rules = ''; + if ($this->hasFile(self::FILENAME)) { + $this->js_rules = htmlentities($this->getFile(self::FILENAME) ?? ''); + } + } +} diff --git a/lib/core-extensions/UserJS/i18n/de/ext.php b/lib/core-extensions/UserJS/i18n/de/ext.php new file mode 100644 index 000000000..be57c7553 --- /dev/null +++ b/lib/core-extensions/UserJS/i18n/de/ext.php @@ -0,0 +1,7 @@ + array( + 'write_js' => 'Benutzerspezifische Javascript Regeln', + ), +); diff --git a/lib/core-extensions/UserJS/i18n/en/ext.php b/lib/core-extensions/UserJS/i18n/en/ext.php new file mode 100644 index 000000000..1217a46fa --- /dev/null +++ b/lib/core-extensions/UserJS/i18n/en/ext.php @@ -0,0 +1,7 @@ + array( + 'write_js' => 'Additional JS', + ), +); diff --git a/lib/core-extensions/UserJS/i18n/fr/ext.php b/lib/core-extensions/UserJS/i18n/fr/ext.php new file mode 100644 index 000000000..c12e919d0 --- /dev/null +++ b/lib/core-extensions/UserJS/i18n/fr/ext.php @@ -0,0 +1,7 @@ + array( + 'write_js' => 'JS supplémentaires', + ), +); diff --git a/lib/core-extensions/UserJS/i18n/ja/ext.php b/lib/core-extensions/UserJS/i18n/ja/ext.php new file mode 100644 index 000000000..390ff6a2f --- /dev/null +++ b/lib/core-extensions/UserJS/i18n/ja/ext.php @@ -0,0 +1,7 @@ + array( + 'write_js' => '追加のJS', + ), +); diff --git a/lib/core-extensions/UserJS/metadata.json b/lib/core-extensions/UserJS/metadata.json new file mode 100644 index 000000000..d38958801 --- /dev/null +++ b/lib/core-extensions/UserJS/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "User JS", + "author": "hkcomori, Frans de Jonge", + "description": "Apply user JS.", + "version": "1.0.0", + "entrypoint": "UserJS", + "type": "user" +} -- cgit v1.2.3