master
Jean-Christian Paul Denis 2021-11-04 11:17:26 +01:00
parent 540872a178
commit 403f09a4f5
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 64 additions and 23 deletions

View File

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief tweakStores, a plugin for Dotclear 2 * @brief tweakStores, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -30,11 +29,21 @@ if (!$core->blog->settings->tweakStores->active) {
if ($core->blog->settings->tweakStores->packman) { if ($core->blog->settings->tweakStores->packman) {
$core->addBehavior('packmanBeforeCreatePackage', ['tweakStoresBehaviors', 'packmanBeforeCreatePackage']); $core->addBehavior('packmanBeforeCreatePackage', ['tweakStoresBehaviors', 'packmanBeforeCreatePackage']);
} }
$core->addBehavior('pluginsToolsHeaders', ['tweakStoresBehaviors', 'modulesToolsHeaders']);
$core->addBehavior('themesToolsHeaders', ['tweakStoresBehaviors', 'modulesToolsHeaders']);
$core->addBehavior('pluginsToolsTabs', ['tweakStoresBehaviors', 'pluginsToolsTabs']); $core->addBehavior('pluginsToolsTabs', ['tweakStoresBehaviors', 'pluginsToolsTabs']);
$core->addBehavior('themesToolsTabs', ['tweakStoresBehaviors', 'themesToolsTabs']); $core->addBehavior('themesToolsTabs', ['tweakStoresBehaviors', 'themesToolsTabs']);
class tweakStoresBehaviors class tweakStoresBehaviors
{ {
# addd some js
public static function modulesToolsHeaders(dcCore $core, $plugin)
{
return
dcPage::jsVars(['dotclear.ts_copied' => __('Copied to clipboard')]) .
dcPage::jsLoad(dcPage::getPF('tweakStores/js/admin.js'));
}
# create dcstore.xml file on the fly when pack a module # create dcstore.xml file on the fly when pack a module
public static function packmanBeforeCreatePackage(dcCore $core, $module) public static function packmanBeforeCreatePackage(dcCore $core, $module)
{ {
@ -44,13 +53,13 @@ class tweakStoresBehaviors
# admin plugins page tab # admin plugins page tab
public static function pluginsToolsTabs(dcCore $core) public static function pluginsToolsTabs(dcCore $core)
{ {
self::modulesToolsTabs($core, $core->plugins->getModules(), explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins').'#tweakStores'); self::modulesToolsTabs($core, $core->plugins->getModules(), explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins') . '#tweakStores');
} }
# admin themes page tab # admin themes page tab
public static function themesToolsTabs(dcCore $core) public static function themesToolsTabs(dcCore $core)
{ {
self::modulesToolsTabs($core, $core->themes->getModules(), explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme').'#tweakStores'); self::modulesToolsTabs($core, $core->themes->getModules(), explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme') . '#tweakStores');
} }
# generic page tab # generic page tab
@ -89,7 +98,7 @@ class tweakStoresBehaviors
} }
} }
if (count($combo) < 2) { if (count($combo) < 2) {
echo echo
'<div class="info">' . __('There is no module to tweak') . '</div>' . '<div class="info">' . __('There is no module to tweak') . '</div>' .
'</div>'; '</div>';
@ -102,7 +111,7 @@ class tweakStoresBehaviors
__('You must configure zip file pattern to complete xml code automatically.') __('You must configure zip file pattern to complete xml code automatically.')
); );
} else { } else {
echo echo
'<form method="post" action="' . $page_url . '" id="buildxml" class="fieldset">' . '<form method="post" action="' . $page_url . '" id="buildxml" class="fieldset">' .
'<h4>' . __('Generate xml code') . '</h4>' . '<h4>' . __('Generate xml code') . '</h4>' .
'<p>' . __('This helps to generate content of dcstore.xml for seleted module.') . '</p>' . '<p>' . __('This helps to generate content of dcstore.xml for seleted module.') . '</p>' .
@ -114,7 +123,7 @@ class tweakStoresBehaviors
'</form>'; '</form>';
} }
if (!empty($_POST['buildxml_id'])) { if (!empty($_POST['buildxml_id'])) {
echo echo
'<form method="post" action="' . $page_url . '" id="writexml" class="fieldset">' . '<form method="post" action="' . $page_url . '" id="writexml" class="fieldset">' .
'<h4>' . sprintf(__('Generated code for module: %s'), html::escapeHTML($_POST['buildxml_id'])) . '</h4>'; '<h4>' . sprintf(__('Generated code for module: %s'), html::escapeHTML($_POST['buildxml_id'])) . '</h4>';
@ -131,20 +140,24 @@ class tweakStoresBehaviors
echo echo
'<pre>' . form::textArea('gen_xml', 165, 14, html::escapeHTML(str_replace('><', ">\n<", $xml_content)), 'maximal') . '</pre>'; '<pre>' . form::textArea('gen_xml', 165, 14, html::escapeHTML(str_replace('><', ">\n<", $xml_content)), 'maximal') . '</pre>';
if (empty(tweakStores::$failed) if (empty(tweakStores::$failed)
&& $modules[$_POST['buildxml_id']]['root_writable'] && $modules[$_POST['buildxml_id']]['root_writable']
&& $core->auth->isSuperAdmin() && $core->auth->isSuperAdmin()
) { ) {
echo echo
'<p class="field"><label for="your_pwd2" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label> ' . '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label> ' .
form::password(['your_pwd', 'your_pwd2'], 20, 255, form::password(
['your_pwd', 'your_pwd2'],
20,
255,
[ [
'extra_html' => 'required placeholder="' . __('Password') . '"', 'extra_html' => 'required placeholder="' . __('Password') . '"',
'autocomplete' => 'current-password' 'autocomplete' => 'current-password'
] ]
) . '</p>' . ) . '</p>' .
'<p><input type="submit" name="write_xml" value="' . __('Save to module directory') . '" />' . '<p><input type="submit" name="write_xml" value="' . __('Save to module directory') . '" /> ' .
form::hidden('buildxml_id', $_POST['buildxml_id']) . '<a class="hidden-if-no-js button" href="#tweakStores" id="ts_copy_button">' . __('Copy to clipboard') . '</a>' .
form::hidden('buildxml_id', $_POST['buildxml_id']) .
$core->formNonce() . '</p>'; $core->formNonce() . '</p>';
} }
echo sprintf( echo sprintf(
@ -156,20 +169,21 @@ class tweakStoresBehaviors
echo echo
'</form>'; '</form>';
} }
echo echo
'</div>'; '</div>';
} }
# create list of module for combo and remove official modules # create list of module for combo and remove official modules
protected static function comboModules($modules, array $excludes) protected static function comboModules($modules, array $excludes)
{ {
$combo = [ __('Select a module') => '0']; $combo = [__('Select a module') => '0'];
foreach ($modules as $id => $module) { foreach ($modules as $id => $module) {
if (in_array($id, $excludes)) { if (in_array($id, $excludes)) {
continue; continue;
} }
$combo[$module['name'] . ' '. $module['version']] = $id; $combo[$module['name'] . ' ' . $module['version']] = $id;
} }
return $combo; return $combo;
} }
} }

21
js/admin.js 100644
View File

@ -0,0 +1,21 @@
/*global $, dotclear */
'use strict';
$(function(){
$("#ts_copy_button").click(function() {
tsCopy("#gen_xml");
return false;
});
function tsCopy(element_id) {
$(element_id).attr("contenteditable", true)
.select()
.on("focus", function() {
document.execCommand('selectAll', false, null)
})
.focus()
document.execCommand("Copy");
$(element_id).removeAttr("contenteditable");
alert(dotclear.ts_copied);
}
});

View File

@ -1,15 +1,18 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: tweakStores 0.1.0\n" "Project-Id-Version: tweakStores 0.2.0\n"
"POT-Creation-Date: \n" "POT-Creation-Date: \n"
"PO-Revision-Date: 2021-09-27T22:20:49+00:00\n" "PO-Revision-Date: 2021-11-04T10:06:45+00:00\n"
"Last-Translator: Jean-Christian Denis\n" "Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "Copied to clipboard"
msgstr "Copié dans le presse-papier"
msgid "Tweak third-party repositories" msgid "Tweak third-party repositories"
msgstr "Gestion de dépôts tiers" msgstr "Gestion de dépôts tiers"
@ -19,6 +22,9 @@ msgstr "Fichier enregistré avec succès"
msgid "There is no module to tweak" msgid "There is no module to tweak"
msgstr "Il n'y a pas de module à gérer" msgstr "Il n'y a pas de module à gérer"
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."
msgid "Generate xml code" msgid "Generate xml code"
msgstr "Générer le code XML" msgstr "Générer le code XML"
@ -46,8 +52,8 @@ msgstr "Le code est complet"
msgid "Save to module directory" msgid "Save to module directory"
msgstr "Enregistrer dans le répertoire du module" msgstr "Enregistrer dans le répertoire du module"
msgid "You must configure zip file pattern to complete xml code automatically." msgid "Copy to clipboard"
msgstr "Vous devez configurer le modèle de fichier zip pour compléter le code XML automatiquement." msgstr "Copier dans le presse-papier"
msgid "You can edit zip file pattern from configuration page." 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." msgstr "Vous pouvez modifier le modèle de fichier zip sur la page de configuration."