From ff2a17b2643c0ad40321f328731f19e23705b8cc Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 27 Aug 2021 11:47:27 +0200 Subject: [PATCH] add write dcstore.xml from plugins tab --- _admin.php | 36 +++++++++++++++++++++++++++++------- inc/class.tweakstores.php | 13 +++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/_admin.php b/_admin.php index 224078e..328feb3 100644 --- a/_admin.php +++ b/_admin.php @@ -52,14 +52,25 @@ class tweakStoresBehaviors $plugins[$module['name'] . ' '. $module['version']] = $id; } - if (!empty($_POST['build_xml']) && !empty($_POST['buildxml_id']) && in_array($_POST['buildxml_id'], $plugins)) { + if (!empty($_POST['buildxml_id']) && in_array($_POST['buildxml_id'], $plugins)) { $xml_content = tweakStores::generateXML($_POST['buildxml_id'], $modules[$_POST['buildxml_id']], $file_pattern); } + if (!empty($_POST['write_xml'])) { + if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) { + $core->error->add(__('Password verification failed')); + } else { + $ret = tweakStores::writeXML($_POST['buildxml_id'], $modules[$_POST['buildxml_id']], $file_pattern); + if (!empty(tweakStores::$failed)) { + $core->error->add(implode(' ', tweakStores::$failed)); + } + } + } + echo '
' . '

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

' . - +/* '
' . '

' . __('Update an existing plugin') . '

' . '

' . __('Put URL to a dcstore.xml file for selected plugin to update it.') . '

' . @@ -81,7 +92,7 @@ class tweakStoresBehaviors '

' . $core->formNonce() . '

' . '
' . - +//*/ '
' . '

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

' . '

' . __('This help to generate content of dcstore.xml for seleted plugin.') . '

' . @@ -89,10 +100,13 @@ class tweakStoresBehaviors form::combo('buildxml_id', $plugins, empty($_POST['buildxml_id']) ? '-' : html::escapeHTML($_POST['buildxml_id'])) . '

' . '

' . - $core->formNonce() . '

'; + $core->formNonce() . '

' . + '
'; if (!empty($_POST['buildxml_id'])) { - echo '
' . sprintf(__('Generated code for module : %s'), html::escapeHTML($_POST['buildxml_id'])) . '
'; + echo + '
' . + '
' . sprintf(__('Generated code for module : %s'), html::escapeHTML($_POST['buildxml_id'])) . '
'; if (!empty(tweakStores::$failed)) { echo sprintf('
' . __('Failed to parse XML code : %s') . '
', implode(', ', tweakStores::$failed)); @@ -108,6 +122,11 @@ class tweakStoresBehaviors '
' . form::textArea('gen_xml', 165, 14, html::escapeHTML($xml_content), 'maximal') . '
'; if (!empty($file_pattern) && $modules[$_POST['buildxml_id']]['root_writable'] && $core->auth->isSuperAdmin()) { + if ($core->error->flag()) { + echo '
' . implode(' ', $core->error->getErrors()) . '
'; + } elseif (!empty($_POST['write_xml'])) { + echo '
' . __('File successfully write') . '
'; + } echo '

' . form::password(['your_pwd', 'your_pwd2'], 20, 255, @@ -116,9 +135,13 @@ class tweakStoresBehaviors 'autocomplete' => 'current-password' ] ) . '

' . - '

'; + '

' . + form::hidden('buildxml_id', $_POST['buildxml_id']); } } + echo + '

' . $core->formNonce() . '

' . + '
'; } if (empty($file_pattern)) { echo '

' . @@ -126,7 +149,6 @@ class tweakStoresBehaviors } echo - '' . '

'; } } \ No newline at end of file diff --git a/inc/class.tweakstores.php b/inc/class.tweakstores.php index 319be20..64aaf29 100644 --- a/inc/class.tweakstores.php +++ b/inc/class.tweakstores.php @@ -105,38 +105,38 @@ class tweakStores # name if (empty($module['name'])) { - self::$failed[] = 'no module name'; + self::$failed[] = 'no module name set in _define.php'; } $xml[] = sprintf('%s', html::escapeHTML($module['name'])); # version if (empty($module['version'])) { - self::$failed[] = 'no module version'; + self::$failed[] = 'no module version set in _define.php'; } $xml[] = sprintf('%s', html::escapeHTML($module['version'])); # author if (empty($module['author'])) { - self::$failed[] = 'no module author'; + self::$failed[] = 'no module author set in _define.php'; } $xml[] = sprintf('%s', html::escapeHTML($module['author'])); # desc if (empty($module['desc'])) { - self::$failed[] = 'no module description'; + self::$failed[] = 'no module description set in _define.php'; } $xml[] = sprintf('%s', html::escapeHTML($module['desc'])); # repository if (empty($module['repository'])) { - self::$failed[] = 'no repository'; + self::$failed[] = 'no repository set in _define.php'; } # file $file_pattern = self::parseFilePattern($id, $module, $file_pattern); if (empty($file_pattern)) { - self::$failed[] = 'no zip file pattern'; + self::$failed[] = 'no zip file pattern set in Tweak Store configuration'; } $xml[] = sprintf('%s', html::escapeHTML($file_pattern)); @@ -169,6 +169,7 @@ class tweakStores public static function writeXML($id, $module, $file_pattern) { + self::$failed = []; if (!$module['root_writable']) { return false; }