diff --git a/js/backend.js b/js/backend.js index de98410..2eb32e1 100644 --- a/js/backend.js +++ b/js/backend.js @@ -1,20 +1,28 @@ /*global $, dotclear */ 'use strict'; -Object.assign(dotclear.msg, dotclear.getData('ts_copied')); +Object.assign(dotclear.msg, dotclear.getData('tweakstore_copied')); -$(function(){ - $("#ts_copy_button").click(function() { - var style = $("#gen_xml").attr('style'); - $("#gen_xml").attr('style', '').attr("contenteditable", true) +$(() => { + + $('#tweakstore_form #tweakstore_submit').hide(); + $('#tweakstore_form #tweakstore_id').on('change', function () { + if (this.value != '0'){this.form.submit();} + }); + dotclear.condSubmit('#tweakstore_form #tweakstore_id', '#tweakstore_form #tweakstore_submit'); + + + $("#tweakstore_copy").click(function() { + var style = $("#tweakstore_gen").attr('style'); + $("#tweakstore_gen").attr('style', '').attr("contenteditable", true) .select() .on("focus", function() { document.execCommand('selectAll', false, null) }) .focus() document.execCommand("Copy"); - $("#gen_xml").removeAttr("contenteditable").attr('style', style); - $("#ts_copy_button").focus(); + $("#tweakstore_gen").removeAttr("contenteditable").attr('style', style); + $("#tweakstore_copy").focus(); alert(dotclear.msg.alert); return false; diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php index 9af6310..ebdcb66 100644 --- a/locales/fr/main.lang.php +++ b/locales/fr/main.lang.php @@ -12,35 +12,28 @@ use Dotclear\Helper\L10n; L10n::$locales['Copied to clipboard'] = 'Copié dans le presse-papier'; +L10n::$locales['Module to parse:'] = 'Module à traiter :'; L10n::$locales['This module has no repository set in its _define.php file.'] = 'Ce module n\'a aucun dépôt tiers définie dans son fichier _define.php'; L10n::$locales['Failed to read third party repository'] = 'Impossible de lire le dépôt tiers'; L10n::$locales['Tweak third-party repositories'] = 'Gestion de dépôts tiers'; -L10n::$locales['File successfully written'] = 'Fichier enregistré avec succès'; L10n::$locales['There is no module to tweak'] = 'Il n\'y a pas de module à gérer'; -L10n::$locales['Check repository'] = 'Vérifier un dépôt tiers'; -L10n::$locales['This checks if dcstore.xml file is present on third party repository.'] = 'Ceci vérifie la présence du fichier dcstore.xml sur le dépôt tiers.'; -L10n::$locales['Module to parse:'] = 'Module à traiter :'; -L10n::$locales['Check'] = 'Obtenir'; -L10n::$locales['Repositiory contents'] = 'Contenu du dépôts tiers'; -L10n::$locales['Generate xml code'] = 'Générer le code XML'; -L10n::$locales['You must configure zip file pattern to complete xml code automatically.'] = 'Vous devez configurer le modèle de fichier zip pour compléter le code XML automatiquement.'; -L10n::$locales['This helps to generate content of dcstore.xml for seleted module.'] = 'Ceci aide à générer le contenu du fichier dcstore.xml pour le module selectionné.'; -L10n::$locales['Generate'] = 'Générer'; -L10n::$locales['Generated code for module: %s'] = 'Code généré pour le module : %s'; +L10n::$locales['Contents from distant repositiory'] = 'Contenu provenant du dépôt distant'; +L10n::$locales['Contents generated from local module definiton'] = 'Contenu généré depuis la définition locale du module'; L10n::$locales['Failed to parse XML code: %s'] = 'Impossible de traiter le code XML : %s'; L10n::$locales['Code is not fully filled: %s'] = 'Le code n\'est pas complet : %s'; +L10n::$locales['File successfully writed'] = 'Fichier écrit avec succès'; L10n::$locales['Code is complete'] = 'Le code est complet'; L10n::$locales['Save to module directory'] = 'Enregistrer dans le répertoire du module'; L10n::$locales['Copy to clipboard'] = 'Copier dans le presse-papier'; -L10n::$locales['You can edit zip file pattern from configuration page.'] = 'Vous pouvez modifier le modèle de fichier zip sur la page de configuration.'; -L10n::$locales['Select a module'] = 'Sélectionner un module'; -L10n::$locales['Enable plugin'] = 'Activer le plugin'; -L10n::$locales['If enabled, new tab "Tweak stores" allows your to perfom actions relative to third-party repositories.'] = 'Si activé, un nouvel onglet "Tweak stores" vous permettra de mener des actions relatives aux dépôts tiers.'; -L10n::$locales['Enable packman behaviors'] = 'Activer les comportements avec pacKman'; -L10n::$locales['If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'] = 'Si activé, le plugin pacKman (re)génèrera à la volée le fichier dcstore.xml'; +L10n::$locales['Check'] = 'Obtenir'; +L10n::$locales['You must configure zip file pattern to complete xml code automatically.'] = 'Vous devez configurer le modèle de fichier zip pour compléter le code XML automatiquement.'; L10n::$locales['Predictable URL to zip file on the external repository'] = 'URL prédictive du fichier zip sur le dépôt externe'; L10n::$locales['You can use widcard like %author%, %type%, %id%, %version%.'] = 'Vous pouvez utiliser les remplacements automatiques tels que %author%, %type%, %id%, %version%.'; L10n::$locales['For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'] = 'Par exemple sur github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'; L10n::$locales['Note: on github, you must create a release and join to it the module zip file.'] = 'Note : sur github, vous devez créer un release et y joindre le fichier zip du module.'; +L10n::$locales['Enable packman behaviors'] = 'Activer les comportements avec pacKman'; +L10n::$locales['If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'] = 'Si activé, le plugin pacKman (re)génèrera à la volée le fichier dcstore.xml'; +L10n::$locales['Select a module'] = 'Sélectionner un module'; +L10n::$locales['Enable plugin'] = 'Activer le plugin'; L10n::$locales['Helper to manage external repositories'] = 'Aide à la gestion de dépôts externes'; L10n::$locales['Tweak stores'] = 'Tweak stores'; diff --git a/locales/fr/main.po b/locales/fr/main.po index 92e494a..5e160be 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -1,108 +1,116 @@ +# Language: Français +# Module: tweakStores - 0.7.1 +# Date: 2023-04-29 13:33:18 +# Author: Jean-Christian Denis +# Translated with translater 2023.04.23 + msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: tweakStores 0.5\n" +"Project-Id-Version: tweakStores 0.7.1\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2023-01-06T08:29:42+00:00\n" +"PO-Revision-Date: 2023-04-29T13:33:18+00:00\n" "Last-Translator: Jean-Christian Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +#: src/BackendBehaviors.php:89 msgid "Copied to clipboard" msgstr "Copié dans le presse-papier" -msgid "This module has no repository set in its _define.php file." -msgstr "Ce module n'a aucun dépôt tiers définie dans son fichier _define.php" - -msgid "Failed to read third party repository" -msgstr "Impossible de lire le dépôt tiers" - -msgid "Tweak third-party repositories" -msgstr "Gestion de dépôts tiers" - -msgid "File successfully written" -msgstr "Fichier enregistré avec succès" - -msgid "There is no module to tweak" -msgstr "Il n'y a pas de module à gérer" - -msgid "Check repository" -msgstr "Vérifier un dépôt tiers" - -msgid "This checks if dcstore.xml file is present on third party repository." -msgstr "Ceci vérifie la présence du fichier dcstore.xml sur le dépôt tiers." - +#: src/BackendBehaviors.php:126 msgid "Module to parse:" msgstr "Module à traiter :" -msgid "Check" -msgstr "Obtenir" +#: src/BackendBehaviors.php:134 +msgid "This module has no repository set in its _define.php file." +msgstr "Ce module n'a aucun dépôt tiers définie dans son fichier _define.php" -msgid "Repositiory contents" -msgstr "Contenu du dépôts tiers" +#: src/BackendBehaviors.php:156 +msgid "Failed to read third party repository" +msgstr "Impossible de lire le dépôt tiers" -msgid "Generate xml code" -msgstr "Générer le code XML" +#: src/BackendBehaviors.php:179 +msgid "Tweak third-party repositories" +msgstr "Gestion de dépôts tiers" -msgid "You must configure zip file pattern to complete xml code automatically." -msgstr "Vous devez configurer le modèle de fichier zip pour compléter le code XML automatiquement." +#: src/BackendBehaviors.php:184 +msgid "There is no module to tweak" +msgstr "Il n'y a pas de module à gérer" -msgid "This helps to generate content of dcstore.xml for seleted module." -msgstr "Ceci aide à générer le contenu du fichier dcstore.xml pour le module selectionné." +#: src/BackendBehaviors.php:198 +msgid "Contents from distant repositiory" +msgstr "Contenu provenant du dépôt distant" -msgid "Generate" -msgstr "Générer" - -msgid "Generated code for module: %s" -msgstr "Code généré pour le module : %s" +#: src/BackendBehaviors.php:222 +msgid "Contents generated from local module definiton" +msgstr "Contenu généré depuis la définition locale du module" +#: src/BackendBehaviors.php:225 msgid "Failed to parse XML code: %s" msgstr "Impossible de traiter le code XML : %s" +#: src/BackendBehaviors.php:228 msgid "Code is not fully filled: %s" msgstr "Le code n'est pas complet : %s" +#: src/BackendBehaviors.php:232 +msgid "File successfully writed" +msgstr "Fichier écrit avec succès" + +#: src/BackendBehaviors.php:234 msgid "Code is complete" msgstr "Le code est complet" +#: src/BackendBehaviors.php:259 msgid "Save to module directory" msgstr "Enregistrer dans le répertoire du module" +#: src/BackendBehaviors.php:260 msgid "Copy to clipboard" msgstr "Copier dans le presse-papier" -msgid "You can edit zip file pattern from configuration page." -msgstr "Vous pouvez modifier le modèle de fichier zip sur la page de configuration." +#: src/BackendBehaviors.php:271 +msgid "Check" +msgstr "Obtenir" +#: src/BackendBehaviors.php:280 +msgid "You must configure zip file pattern to complete xml code automatically." +msgstr "Vous devez configurer le modèle de fichier zip pour compléter le code XML automatiquement." + +#: src/BackendBehaviors.php:285 +msgid "Predictable URL to zip file on the external repository" +msgstr "URL prédictive du fichier zip sur le dépôt externe" + +#: src/BackendBehaviors.php:288 +msgid "You can use widcard like %author%, %type%, %id%, %version%." +msgstr "Vous pouvez utiliser les remplacements automatiques tels que %author%, %type%, %id%, %version%." + +#: src/BackendBehaviors.php:289 +msgid "For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip" +msgstr "Par exemple sur github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip" + +#: src/BackendBehaviors.php:290 +msgid "Note: on github, you must create a release and join to it the module zip file." +msgstr "Note : sur github, vous devez créer un release et y joindre le fichier zip du module." + +#: src/BackendBehaviors.php:294 +msgid "Enable packman behaviors" +msgstr "Activer les comportements avec pacKman" + +#: src/BackendBehaviors.php:296 +msgid "If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module." +msgstr "Si activé, le plugin pacKman (re)génèrera à la volée le fichier dcstore.xml" + +#: src/BackendBehaviors.php:322 msgid "Select a module" msgstr "Sélectionner un module" msgid "Enable plugin" msgstr "Activer le plugin" -msgid "If enabled, new tab \"Tweak stores\" allows your to perfom actions relative to third-party repositories." -msgstr "Si activé, un nouvel onglet \"Tweak stores\" vous permettra de mener des actions relatives aux dépôts tiers." - -msgid "Enable packman behaviors" -msgstr "Activer les comportements avec pacKman" - -msgid "If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module." -msgstr "Si activé, le plugin pacKman (re)génèrera à la volée le fichier dcstore.xml" - -msgid "Predictable URL to zip file on the external repository" -msgstr "URL prédictive du fichier zip sur le dépôt externe" - -msgid "You can use widcard like %author%, %type%, %id%, %version%." -msgstr "Vous pouvez utiliser les remplacements automatiques tels que %author%, %type%, %id%, %version%." - -msgid "For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip" -msgstr "Par exemple sur github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip" - -msgid "Note: on github, you must create a release and join to it the module zip file." -msgstr "Note : sur github, vous devez créer un release et y joindre le fichier zip du module." - msgid "Helper to manage external repositories" msgstr "Aide à la gestion de dépôts externes" diff --git a/src/Backend.php b/src/Backend.php index 7c13a20..35812b3 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -22,10 +22,9 @@ class Backend extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) && My::phpCompliant() - && dcCore::app()->auth->isSuperAdmin() - && dcCore::app()->blog->settings->get(My::id())->get('active'); + && !is_null(dcCore::app()->auth) + && dcCore::app()->auth->isSuperAdmin(); return static::$init; } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 2109f18..d9ab4d2 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -20,11 +20,18 @@ use dcModules; use dcPage; use Dotclear\Helper\File\Files; use Dotclear\Helper\Html\Form\{ + Checkbox, + Div, + Fieldset, Hidden, + Input, Label, + Legend, + Note, Para, Password, Select, + Submit, Textarea }; use Dotclear\Helper\Html\Html; @@ -54,14 +61,31 @@ class BackendBehaviors self::writeXML($define, dcCore::app()->blog->settings->get(My::id())->get('file_pattern')); } - public static function modulesToolsHeaders(bool $is_plugin): string + public static function modulesToolsHeaders(bool $is_theme): string { if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { return ''; } + //save settings (before page header sent) + if (!empty($_POST['tweakstore_save'])) { + try { + $s = new Settings(); + foreach ($s->dump() as $key => $value) { + $s->set($key, $_POST['ts_' . $key] ?? $value); + } + + dcPage::addSuccessNotice( + __('Configuration successfully updated') + ); + dcCore::app()->adminurl?->redirect($is_theme ? 'admin.blog.theme' : 'admin.plugins', ['tab' => My::id()]); + } catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); + } + } + return - dcPage::jsJson('ts_copied', ['alert' => __('Copied to clipboard')]) . + dcPage::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) . dcPage::jsModuleLoad(My::id() . '/js/backend.js') . ( !dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? '' : @@ -72,38 +96,39 @@ class BackendBehaviors public static function pluginsToolsTabsV2(): void { - self::modulesToolsTabs(dcCore::app()->plugins, explode(',', DC_DISTRIB_PLUGINS), (string) dcCore::app()->adminurl?->get('admin.plugins')); + self::modulesToolsTabs(dcCore::app()->plugins, (string) dcCore::app()->adminurl?->get('admin.plugins')); } public static function themesToolsTabsV2(): void { - self::modulesToolsTabs(dcCore::app()->themes, explode(',', DC_DISTRIB_THEMES), (string) dcCore::app()->adminurl?->get('admin.blog.theme')); + self::modulesToolsTabs(dcCore::app()->themes, (string) dcCore::app()->adminurl?->get('admin.blog.theme')); } - private static function modulesToolsTabs(dcModules $modules, array $excludes, string $page_url): void + private static function modulesToolsTabs(dcModules $modules, string $page_url): void { if (is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { return; } + // settings + $s = new Settings(); $page_url .= '#' . My::id(); $user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); $user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); - $file_pattern = (new Settings())->file_pattern; + $file_pattern = $s->file_pattern; + $local_content = $distant_content = ''; - $module = $modules->getDefine($_POST['ts_id'] ?? '-'); - $combo = self::comboModules($modules, $excludes); - $form = (new Para())->class('field')->items([ - (new Label(__('Module to parse:')))->for('ts_id')->class('required'), - (new Select('ts_id'))->default($module->isDefined() ? Html::escapeHTML($module->get('id')) : '-')->items($combo), - ])->render(); + // load module + $module = $modules->getDefine($_POST['tweakstore_id'] ?? '0'); + $combo = self::comboModules($modules); - # check dcstore repo + // execute form actions $url = ''; - if (!empty($_POST['check_xml']) && $module->isDefined()) { + if (!empty($_POST['tweakstore_do']) && $module->isDefined()) { if (empty($module->get('repository'))) { $url = __('This module has no repository set in its _define.php file.'); } else { + // read distant module xml content try { $url = $module->get('repository'); if (false === strpos($url, 'dcstore.xml')) { @@ -117,70 +142,63 @@ class BackendBehaviors curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $file_content = (string) curl_exec($ch); + $distant_content = (string) curl_exec($ch); curl_close($ch); } else { - $file_content = (string) file_get_contents($url); + $distant_content = (string) file_get_contents($url); } } catch (Exception $e) { - $file_content = __('Failed to read third party repository'); + $distant_content = __('Failed to read third party repository'); + } + } + + // generate local module xml content + $local_content = self::generateXML($module, $s->file_pattern); + + // write dcstore.xml file + if (!empty($_POST['tweakstore_write'])) { + if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) { + dcCore::app()->error->add(__('Password verification failed')); + } else { + self::writeXML($module, $s->file_pattern); + if (!empty(self::$failed)) { + dcCore::app()->error->add(implode(' ', self::$failed)); + } } } } - # generate xml code - if (!empty($_POST['build_xml']) && $module->isDefined()) { - $xml_content = self::generateXML($module, $file_pattern); - } - - # write dcstore.xml file - if (!empty($_POST['write_xml'])) { - if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) { - dcCore::app()->error->add(__('Password verification failed')); - } else { - $ret = self::writeXML($module, $file_pattern); - if (!empty(self::$failed)) { - dcCore::app()->error->add(implode(' ', self::$failed)); - } - } - } + // display echo '
' . '

' . __('Tweak third-party repositories') . '

'; - if (!empty($_POST['write_xml'])) { - if (dcCore::app()->error->flag()) { - echo dcCore::app()->error->toHTML(); - } else { - echo '

' . __('File successfully written') . '

'; - } - } + // nothing to display if (count($combo) < 2) { echo - '
' . __('There is no module to tweak') . '
' . + '

' . __('There is no module to tweak') . '

' . '
'; return; } echo - '
' . - '

' . __('Check repository') . '

' . - '

' . __('This checks if dcstore.xml file is present on third party repository.') . '

' . - $form . - '

' . - dcCore::app()->formNonce() . '

' . - '
'; + '
' . + (new Para())->class('field')->items([ + (new Label(__('Module to parse:')))->for('tweakstore_id')->class('required'), + (new Select('tweakstore_id'))->default($module->isDefined() ? Html::escapeHTML($module->getId()) : '0')->items($combo), + ])->render(); + // distant content if (!empty($url)) { echo '
' . - '

' . __('Repositiory contents') . '

' . + '

' . __('Contents from distant repositiory') . '

' . '

' . $url . '

' . ( - empty($file_content) ? '' : + empty($distant_content) ? '' : '
' .
-                    (new Textarea('file_xml', Html::escapeHTML(self::prettyXML($file_content))))
+                    (new Textarea('distant_content', Html::escapeHTML(self::prettyXML($distant_content))))
                     ->cols(165)
                     ->rows(14)
                     ->readonly(true)
@@ -189,96 +207,117 @@ class BackendBehaviors
                 '
' . ( !$user_ui_colorsyntax ? '' : - dcPage::jsRunCodeMirror('editor', 'file_xml', 'dotclear', $user_ui_colorsyntax_theme) + dcPage::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme) ) ) . '
'; } - if (empty($file_pattern)) { - echo sprintf( - '

' . __('Generate xml code') . '

%s

', - dcCore::app()->adminurl->get('admin.plugins', ['module' => My::id(), 'conf' => 1, 'redir' => $page_url]), - __('You must configure zip file pattern to complete xml code automatically.') - ); - } else { + // local_content + if (!empty($local_content) || !empty(self::$failed) || !empty(self::$notice)) { echo - '' . - '

' . __('Generate xml code') . '

' . - '

' . __('This helps to generate content of dcstore.xml for seleted module.') . '

' . - $form . - '

' . - dcCore::app()->formNonce() . '

' . - '
'; - } - if (!empty($_POST['build_xml'])) { - echo - '
' . - '

' . sprintf(__('Generated code for module: %s'), Html::escapeHTML($module->get('id'))) . '

'; + '
' . + '

' . __('Contents generated from local module definiton') . '

'; if (!empty(self::$failed)) { - echo '

' . sprintf(__('Failed to parse XML code: %s'), implode(', ', self::$failed)) . '

'; + echo '

' . sprintf(__('Failed to parse XML code: %s'), implode(', ', self::$failed)) . '

'; } if (!empty(self::$notice)) { - echo '

' . sprintf(__('Code is not fully filled: %s'), implode(', ', self::$notice)) . '

'; + echo '

' . sprintf(__('Code is not fully filled: %s'), implode(', ', self::$notice)) . '

'; } - if (!empty($xml_content)) { - if (empty(self::$failed) && empty(self::$notice)) { - echo '

' . __('Code is complete') . '

'; + if (empty(self::$failed) && empty(self::$notice)) { + if (!empty($_POST['tweakstore_write'])) { + echo '

' . __('File successfully writed') . '

'; } - echo - '
' .
-                    (new Textarea('gen_xml', Html::escapeHTML(self::prettyXML($xml_content))))
-                    ->cols(165)
-                    ->rows(14)
-                    ->readonly(true)
-                    ->class('maximal')
-                    ->render() .
-                '
' . - ( - !$user_ui_colorsyntax ? '' : - dcPage::jsRunCodeMirror('editor', 'gen_xml', 'dotclear', $user_ui_colorsyntax_theme) - ); + echo '

' . __('Code is complete') . '

'; + } - if (empty(self::$failed) - && $module->get('root_writable') - && dcCore::app()->auth->isSuperAdmin() - ) { - echo - (new Para())->class('field')->items([ - (new Label(__('Your password:')))->for('your_pwd2')->class('required'), - (new Password(['your_pwd', 'your_pwd2']))->size(20)->maxlenght(255)->required(true)->placeholder(__('Password'))->autocomplete('current-password'), - ])->render() . - '

' . - '' . __('Copy to clipboard') . '' . - (new Hidden('ts_id', $_POST['ts_id']))->render() . - dcCore::app()->formNonce() . '

'; - } - echo sprintf( - '

%s

', - dcCore::app()->adminurl->get('admin.plugins', ['module' => My::id(), 'conf' => 1, 'redir' => $page_url]), - __('You can edit zip file pattern from configuration page.') - ); - } echo - ''; + '
' .
+                (new Textarea('local_content', Html::escapeHTML(self::prettyXML($local_content))))
+                ->cols(165)
+                ->rows(14)
+                ->readonly(true)
+                ->class('maximal')
+                ->render() .
+            '
' . + ( + !$user_ui_colorsyntax ? '' : + dcPage::jsRunCodeMirror('editor', 'local_content', 'dotclear', $user_ui_colorsyntax_theme) + ); + + if ($module->get('root_writable') + && dcCore::app()->auth->isSuperAdmin() + ) { + echo + (new Para())->class('field')->items([ + (new Label(__('Your password:')))->for('tweakstore_pwd')->class('required'), + (new Password(['your_pwd', 'tweakstore_pwd']))->size(20)->maxlenght(255)->required(true)->placeholder(__('Password'))->autocomplete('current-password'), + ])->render() . + '

' . + '' . __('Copy to clipboard') . '' . + dcCore::app()->formNonce() . '

'; + } + + echo + '
'; } + + // submit form button (hide by js) echo + (new Para())->items([ + (new Submit('tweakstore_submit'))->value(__('Check')), + (new Hidden('tweakstore_do', '1')), + dcCore::app()->formNonce(false), + ])->render() . + '' . + + // settings + '
' . + '

' . sprintf(__('%s configuration'), My::name()) . '

' . + (empty($s->file_pattern) ? '

' . __('You must configure zip file pattern to complete xml code automatically.') . '

' : '') . + + (new Div())->items([ + // s_file_pattern + (new Para())->items([ + (new Label(__('Predictable URL to zip file on the external repository')))->for('ts_file_pattern'), + (new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value($s->file_pattern), + ]), + (new Note())->text(__('You can use widcard like %author%, %type%, %id%, %version%.'))->class('form-note'), + (new Note())->text(__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'))->class('form-note'), + (new Note())->text(__('Note: on github, you must create a release and join to it the module zip file.'))->class('form-note'), + // s_packman + (new Para())->items([ + (new Checkbox('ts_packman', $s->packman))->value(1), + (new Label(__('Enable packman behaviors'), Label::OUTSIDE_LABEL_AFTER))->for('ts_packman')->class('classic'), + ]), + (new Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'), + ])->render() . + + (new Para())->items([ + (new Submit('tweakstore_save'))->value(__('Save')), + dcCore::app()->formNonce(false), + ])->render() . + + '
' . + '
' . ''; } # create list of module for combo and remove official modules - private static function comboModules(dcModules $modules, array $excludes): array + private static function comboModules(dcModules $modules): array { - $combo = [__('Select a module') => '0']; + $combo = []; foreach ($modules->getDefines() as $module) { - if (in_array($module->get('id'), $excludes)) { + if ($module->get('distributed')) { continue; } $combo[$module->get('name') . ' ' . $module->get('version')] = $module->get('id'); } - return $combo; + uasort($combo, fn ($a, $b) => strtolower($a) <=> strtolower($b)); + + return array_merge([__('Select a module') => '0'], $combo); } private static function parseFilePattern(dcModuleDefine $module, string $file_pattern): string diff --git a/src/Config.php b/src/Config.php deleted file mode 100644 index 3dc4d22..0000000 --- a/src/Config.php +++ /dev/null @@ -1,110 +0,0 @@ -auth) - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; - } - - public static function process(): bool - { - if (!static::$init) { - return false; - } - - if (empty($_POST['save'])) { - return true; - } - - $s = new Settings(); - - try { - foreach ($s->listSettings() as $key => $value) { - $s->writeSetting($key, $_POST['ts_' . $key] ?? $value); - } - - dcPage::addSuccessNotice( - __('Configuration successfully updated') - ); - dcCore::app()->adminurl?->redirect( - 'admin.plugins', - ['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] - ); - } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); - } - - return true; - } - - public static function render(): void - { - if (!static::$init) { - return; - } - - $s = new Settings(); - - echo (new Div())->items([ - (new Fieldset())->class('fieldset')->legend(new Legend(__('Interface')))->fields([ - // s_active - (new Para())->items([ - (new Checkbox('ts_active', $s->active))->value(1), - (new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))->for('ts_active')->class('classic'), - ]), - (new Note())->text(__('If enabled, new tab "Tweak stores" allows your to perfom actions relative to third-party repositories.'))->class('form-note'), - // s_file_pattern - (new Para())->items([ - (new Label(__('Predictable URL to zip file on the external repository')))->for('ts_file_pattern'), - (new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value($s->file_pattern), - ]), - (new Note())->text(__('You can use widcard like %author%, %type%, %id%, %version%.'))->class('form-note'), - (new Note())->text(__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'))->class('form-note'), - (new Note())->text(__('Note: on github, you must create a release and join to it the module zip file.'))->class('form-note'), - ]), - (new Fieldset())->class('fieldset')->legend(new Legend(__('Behaviors')))->fields([ - // s_packman - (new Para())->items([ - (new Checkbox('ts_packman', $s->packman))->value(1), - (new Label(__('Enable packman behaviors'), Label::OUTSIDE_LABEL_AFTER))->for('ts_packman')->class('classic'), - ]), - (new Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'), - ]), - ])->render(); - } -} diff --git a/src/Settings.php b/src/Settings.php index fa042db..8b2e128 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -19,9 +19,6 @@ use Exception; class Settings { - // Enable this plugin - public readonly bool $active; - // Enable plugin pacKman behavior public readonly bool $packman; @@ -39,16 +36,10 @@ class Settings $s = dcCore::app()->blog->settings->get(My::id()); - $this->active = (bool) ($s->get('active') ?? false); $this->packman = (bool) ($s->get('packman') ?? false); $this->file_pattern = (string) ($s->get('file_pattern') ?? ''); } - public function getSetting(string $key): mixed - { - return $this->{$key} ?? null; - } - /** * Overwrite a plugin settings (in db) * @@ -57,7 +48,7 @@ class Settings * * @return bool True on success */ - public function writeSetting(string $key, mixed $value): bool + public function set(string $key, mixed $value): bool { if (is_null(dcCore::app()->blog)) { throw new Exception('blog is not set'); @@ -78,7 +69,7 @@ class Settings * * @return array The settings keys */ - public function listSettings(): array + public function dump(): array { return get_object_vars($this); }