mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 22:14:33 +00:00
Compare commits
13 Commits
fix/webdav
...
fix/edit-w
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26af1b3019 | ||
|
|
b1b75676a8 | ||
|
|
12880b6c41 | ||
|
|
32abc7250d | ||
|
|
76de2b037c | ||
|
|
e2e82162c6 | ||
|
|
7a9eb1baa6 | ||
|
|
e800f11f64 | ||
|
|
4808f08590 | ||
|
|
6fd89df5d0 | ||
|
|
99126088e7 | ||
|
|
e53a3848bb | ||
|
|
0f0c71acaf |
@@ -6,11 +6,18 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
|
||||
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
||||
{
|
||||
$script_version = function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.15';
|
||||
$GLOBALS['template']->func_combine_script(array(
|
||||
'id'=>'bratonien_nc_connector_edit_v2',
|
||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
||||
'load'=>'footer',
|
||||
'version'=>function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.10',
|
||||
'version'=>$script_version,
|
||||
));
|
||||
$GLOBALS['template']->func_combine_script(array(
|
||||
'id'=>'bratonien_nc_connector_source_ui',
|
||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_source_ui.js',
|
||||
'load'=>'footer',
|
||||
'version'=>$script_version,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -239,13 +239,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
function rebuildLocalActions(deleteForm, id) {
|
||||
function rebuildLocalActions(deleteForm, id, connectionData) {
|
||||
var actions = deleteForm.parentElement;
|
||||
if (!actions) return;
|
||||
|
||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
||||
var migrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
||||
if (migrate) form.remove();
|
||||
var editStart = form.querySelector('button[value="nc_connector_edit_start"]');
|
||||
if (migrate || editStart) form.remove();
|
||||
});
|
||||
[].slice.call(actions.children).forEach(function (child) {
|
||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
||||
@@ -265,7 +266,8 @@
|
||||
info.textContent = 'WebDAV-Migration wird geprüft …';
|
||||
actions.insertBefore(info, deleteForm);
|
||||
|
||||
loadConnection(id).then(function (data) {
|
||||
var dataPromise = connectionData ? Promise.resolve(connectionData) : loadConnection(id);
|
||||
dataPromise.then(function (data) {
|
||||
var webdav = data.webdav || {};
|
||||
if (webdav.migration_ready) {
|
||||
info.remove();
|
||||
@@ -279,15 +281,44 @@
|
||||
});
|
||||
}
|
||||
|
||||
function rebuildRemoteActions(deleteForm, id) {
|
||||
var actions = deleteForm.parentElement;
|
||||
if (!actions) return;
|
||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
||||
var oldEdit = form.querySelector('button[value="nc_connector_edit_start"]');
|
||||
var oldMigrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
||||
if (oldEdit || oldMigrate) form.remove();
|
||||
});
|
||||
[].slice.call(actions.children).forEach(function (child) {
|
||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
||||
if (child.dataset && child.dataset.ncMigrationInfo) child.remove();
|
||||
});
|
||||
actions.insertBefore(postForm('Bearbeiten', 'nc_connector_edit_start', id, 'edit'), deleteForm);
|
||||
}
|
||||
|
||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_edit_start"]')).forEach(function (button) {
|
||||
var form = button.closest('form');
|
||||
if (form) form.remove();
|
||||
});
|
||||
|
||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
||||
var deleteForm = deleteButton.closest('form');
|
||||
var card = deleteButton.closest('details');
|
||||
if (!deleteForm || !card) return;
|
||||
if (!deleteForm) return;
|
||||
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
||||
if (!idInput) return;
|
||||
var text = card.textContent || '';
|
||||
var isLocal = text.indexOf('bestehende Legacy-Konfiguration') !== -1;
|
||||
if (isLocal) rebuildLocalActions(deleteForm, idInput.value);
|
||||
var id = idInput.value;
|
||||
|
||||
loadConnection(id).then(function (data) {
|
||||
if (data.adapter === 'local') rebuildLocalActions(deleteForm, id, data);
|
||||
else rebuildRemoteActions(deleteForm, id);
|
||||
}).catch(function (error) {
|
||||
var actions = deleteForm.parentElement;
|
||||
if (!actions) return;
|
||||
var info = document.createElement('span');
|
||||
info.className = 'bratonien-main-cache__warning';
|
||||
info.textContent = 'Verbindungstyp konnte nicht geladen werden: '+(error.message || String(error));
|
||||
actions.insertBefore(info, deleteForm);
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
217
js/nc_connector_source_ui.js
Normal file
217
js/nc_connector_source_ui.js
Normal file
@@ -0,0 +1,217 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
||||
});
|
||||
}
|
||||
|
||||
function fieldNodes(form, fieldName) {
|
||||
return [].slice.call(form.querySelectorAll('[name="'+fieldName.replace(/"/g, '\\"')+'"]'));
|
||||
}
|
||||
|
||||
function clearPickerErrors(form) {
|
||||
[].slice.call(form.querySelectorAll('[data-source-picker-error]')).forEach(function (node) { node.remove(); });
|
||||
[].slice.call(form.querySelectorAll('[data-source-picker-invalid="1"]')).forEach(function (field) {
|
||||
field.removeAttribute('data-source-picker-invalid');
|
||||
if (field.getAttribute('aria-invalid') === 'true') field.removeAttribute('aria-invalid');
|
||||
field.style.borderColor = '';
|
||||
field.style.boxShadow = '';
|
||||
});
|
||||
}
|
||||
|
||||
function showPickerError(form, data) {
|
||||
clearPickerErrors(form);
|
||||
var message = data && data.message ? data.message : 'Die Nextcloud-Ordnerauswahl konnte nicht gestartet werden.';
|
||||
var fields = data && Array.isArray(data.fields) ? data.fields : [];
|
||||
|
||||
var summary = document.createElement('div');
|
||||
summary.dataset.sourcePickerError = '1';
|
||||
summary.className = 'bratonien-main-cache__warning';
|
||||
summary.style.margin = '0 0 1rem';
|
||||
summary.style.padding = '.75rem';
|
||||
summary.style.border = '1px solid currentColor';
|
||||
summary.innerHTML = '<strong>Ordnerauswahl nicht möglich:</strong> '+escapeHtml(message);
|
||||
form.insertBefore(summary, form.firstChild);
|
||||
|
||||
var first = null;
|
||||
fields.forEach(function (fieldName) {
|
||||
fieldNodes(form, fieldName).forEach(function (field) {
|
||||
field.dataset.sourcePickerInvalid = '1';
|
||||
field.setAttribute('aria-invalid', 'true');
|
||||
field.style.borderColor = '#d65a5a';
|
||||
field.style.boxShadow = '0 0 0 1px #d65a5a';
|
||||
if (!first) first = field;
|
||||
});
|
||||
});
|
||||
|
||||
if (first) {
|
||||
first.scrollIntoView({block:'center', behavior:'smooth'});
|
||||
window.setTimeout(function () { first.focus(); }, 150);
|
||||
} else {
|
||||
summary.scrollIntoView({block:'center', behavior:'smooth'});
|
||||
}
|
||||
}
|
||||
|
||||
function jsonResponse(response) {
|
||||
return response.json().then(function (data) {
|
||||
if (!response.ok || !data.ok) throw data;
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
function startSourcePicker(form, button) {
|
||||
clearPickerErrors(form);
|
||||
if (!form.reportValidity()) return;
|
||||
|
||||
button.disabled = true;
|
||||
var originalText = button.textContent;
|
||||
button.textContent = 'Verbindung prüfen …';
|
||||
|
||||
var saveBody = new FormData(form);
|
||||
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
||||
method:'POST',
|
||||
credentials:'same-origin',
|
||||
cache:'no-store',
|
||||
headers:{'Accept':'application/json'},
|
||||
body:saveBody
|
||||
})
|
||||
.then(jsonResponse)
|
||||
.then(function () {
|
||||
button.textContent = 'Nextcloud-Ordner laden …';
|
||||
var pickerBody = new FormData();
|
||||
var token = form.querySelector('input[name="pwg_token"]');
|
||||
var id = form.querySelector('input[name="connection_id"]');
|
||||
pickerBody.append('pwg_token', token ? token.value : '');
|
||||
pickerBody.append('connection_id', id ? id.value : '');
|
||||
return fetch('plugins/bratonien_tools/nc-connector-source-picker-start.php', {
|
||||
method:'POST',
|
||||
credentials:'same-origin',
|
||||
cache:'no-store',
|
||||
headers:{'Accept':'application/json'},
|
||||
body:pickerBody
|
||||
}).then(jsonResponse);
|
||||
})
|
||||
.then(function () {
|
||||
try {
|
||||
sessionStorage.setItem('bratonienNcWizardMode', 'migrate');
|
||||
sessionStorage.setItem('bratonienNcWizardOpen', '1');
|
||||
} catch (e) {}
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (error) {
|
||||
showPickerError(form, error && typeof error === 'object' ? error : {message:String(error), fields:[]});
|
||||
button.disabled = false;
|
||||
button.textContent = originalText;
|
||||
});
|
||||
}
|
||||
|
||||
function enhanceMigrationButtons(root) {
|
||||
[].slice.call(root.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
||||
button.textContent = 'Nextcloud-Ordner auswählen & migrieren';
|
||||
button.title = 'Die WebDAV-Quelle wird im Nextcloud-Ordnerbrowser ausgewählt. Der bestehende SMB-/Legacy-Speicher wird nicht als WebDAV-Quelle übernommen.';
|
||||
});
|
||||
}
|
||||
|
||||
function enhanceEditor(root) {
|
||||
var form = root.querySelector('[data-edit-v2-form]');
|
||||
if (!form || form.dataset.sourceUiEnhanced === '1') return;
|
||||
form.dataset.sourceUiEnhanced = '1';
|
||||
|
||||
var headings = [].slice.call(form.querySelectorAll('h5'));
|
||||
var webdavHeading = headings.find(function (node) {
|
||||
return (node.textContent || '').trim() === 'Nextcloud / WebDAV';
|
||||
});
|
||||
var legacyHeading = headings.find(function (node) {
|
||||
return (node.textContent || '').trim() === 'Bestehender Legacy-Weg';
|
||||
});
|
||||
var storageHeading = headings.find(function (node) {
|
||||
return (node.textContent || '').trim() === 'Speicherorte';
|
||||
});
|
||||
var storageList = form.querySelector('[data-storage-list]');
|
||||
var addStorage = form.querySelector('[data-add-storage]');
|
||||
|
||||
if (webdavHeading && !form.querySelector('[data-webdav-source-picker]')) {
|
||||
var webdavGrid = webdavHeading.nextElementSibling;
|
||||
while (webdavGrid && !webdavGrid.classList.contains('bratonien-form-grid')) webdavGrid = webdavGrid.nextElementSibling;
|
||||
if (webdavGrid) {
|
||||
var picker = document.createElement('div');
|
||||
picker.dataset.webdavSourcePicker = '1';
|
||||
picker.style.margin = '.8rem 0 1rem';
|
||||
picker.innerHTML = '<p class="bratonien-base-note" style="margin:.25rem 0 .5rem"><strong>WebDAV-Quelle:</strong> Du musst keinen Pfad kennen. Die Ordner des oben eingetragenen Nextcloud-Benutzers werden automatisch geladen und können anschließend ausgewählt werden.</p>';
|
||||
var button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'buttonLike';
|
||||
button.textContent = 'Nextcloud-Ordner automatisch auswählen';
|
||||
button.addEventListener('click', function () { startSourcePicker(form, button); });
|
||||
picker.appendChild(button);
|
||||
webdavGrid.insertAdjacentElement('afterend', picker);
|
||||
}
|
||||
}
|
||||
|
||||
if (legacyHeading && !form.querySelector('[data-webdav-source-note]')) {
|
||||
var note = document.createElement('p');
|
||||
note.dataset.webdavSourceNote = '1';
|
||||
note.className = 'bratonien-main-cache__warning';
|
||||
note.innerHTML = '<strong>Wichtig:</strong> Der folgende SMB-/lokale Speicher gehört ausschließlich zum bisherigen Legacy-Fallback. Er wird <strong>nicht</strong> als WebDAV-Quelle übernommen.';
|
||||
legacyHeading.insertAdjacentElement('beforebegin', note);
|
||||
}
|
||||
|
||||
if (storageHeading && storageList && addStorage) {
|
||||
storageHeading.textContent = 'Legacy-Speicher (nur Fallback)';
|
||||
|
||||
var details = document.createElement('details');
|
||||
details.dataset.legacyStorageTechnical = '1';
|
||||
details.style.marginTop = '.75rem';
|
||||
var summary = document.createElement('summary');
|
||||
summary.textContent = 'Technische Legacy-Speicherzuordnung bearbeiten';
|
||||
details.appendChild(summary);
|
||||
|
||||
var info = document.createElement('p');
|
||||
info.className = 'bratonien-base-note';
|
||||
info.textContent = 'Diese Felder betreffen nur den alten Fallback-Weg. Für WebDAV werden keine SMB-Adressen oder lokalen Mount-Pfade eingegeben.';
|
||||
details.appendChild(info);
|
||||
|
||||
storageHeading.insertAdjacentElement('beforebegin', details);
|
||||
details.appendChild(storageHeading);
|
||||
details.appendChild(storageList);
|
||||
details.appendChild(addStorage);
|
||||
|
||||
addStorage.textContent = 'Legacy-Speicher manuell hinzufügen';
|
||||
addStorage.title = 'Nur für den alten Legacy-Fallback. WebDAV-Ordner werden im Nextcloud-Ordnerbrowser ausgewählt.';
|
||||
}
|
||||
}
|
||||
|
||||
function enhance(root) {
|
||||
if (!root || root.nodeType !== 1) return;
|
||||
enhanceMigrationButtons(root);
|
||||
if (root.matches && root.matches('#bratonien-nc-connection-edit-v2')) enhanceEditor(root);
|
||||
var dialog = root.querySelector ? root.querySelector('#bratonien-nc-connection-edit-v2') : null;
|
||||
if (dialog) enhanceEditor(dialog);
|
||||
}
|
||||
|
||||
function start() {
|
||||
var section = document.getElementById('nc-connector');
|
||||
if (!section) return;
|
||||
|
||||
enhance(section);
|
||||
enhanceMigrationButtons(document);
|
||||
|
||||
var observer = new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) {
|
||||
[].slice.call(mutation.addedNodes || []).forEach(function (node) {
|
||||
if (node && node.nodeType === 1) enhance(node);
|
||||
});
|
||||
});
|
||||
var dialog = document.getElementById('bratonien-nc-connection-edit-v2');
|
||||
if (dialog) enhanceEditor(dialog);
|
||||
enhanceMigrationButtons(document);
|
||||
});
|
||||
|
||||
observer.observe(document.body, {childList:true, subtree:true});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);
|
||||
else start();
|
||||
})();
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Bratonien Tools
|
||||
Version: 0.9.6.13
|
||||
Version: 0.9.6.16
|
||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||
Author: Bratonien
|
||||
|
||||
104
nc-connector-source-picker-start.php
Normal file
104
nc-connector-source-picker-start.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
$piwigo_root = realpath(dirname(__DIR__, 2));
|
||||
if ($piwigo_root === false)
|
||||
{
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
define('PHPWG_ROOT_PATH', rtrim($piwigo_root, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR);
|
||||
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store, max-age=0');
|
||||
|
||||
function bratonien_tools_nc_source_picker_json($status, array $payload)
|
||||
{
|
||||
http_response_code((int)$status);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_source_picker_fail($message, array $fields = array())
|
||||
{
|
||||
bratonien_tools_nc_source_picker_json(422, array(
|
||||
'ok'=>false,
|
||||
'message'=>(string)$message,
|
||||
'fields'=>array_values(array_unique($fields)),
|
||||
));
|
||||
}
|
||||
|
||||
if (!defined('BRATONIEN_TOOLS_PATH'))
|
||||
{
|
||||
bratonien_tools_nc_source_picker_json(404, array('ok'=>false, 'message'=>'Bratonien Tools ist nicht aktiv.', 'fields'=>array()));
|
||||
}
|
||||
if (!function_exists('is_admin') || !is_admin())
|
||||
{
|
||||
bratonien_tools_nc_source_picker_json(403, array('ok'=>false, 'message'=>'Administratorrechte erforderlich.', 'fields'=>array()));
|
||||
}
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST')
|
||||
{
|
||||
bratonien_tools_nc_source_picker_json(405, array('ok'=>false, 'message'=>'Nur POST ist erlaubt.', 'fields'=>array()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
check_pwg_token();
|
||||
require_once(BRATONIEN_TOOLS_PATH.'include/tool_registry.inc.php');
|
||||
|
||||
$id = (int)($_POST['connection_id'] ?? 0);
|
||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||
if (!$connection)
|
||||
{
|
||||
bratonien_tools_nc_source_picker_fail('Die zu bearbeitende Verbindung wurde nicht gefunden.');
|
||||
}
|
||||
if ((string)$connection['adapter'] !== 'local')
|
||||
{
|
||||
bratonien_tools_nc_source_picker_fail('Die automatische Migrationsauswahl ist nur für die bestehende Legacy-Verbindung vorgesehen.');
|
||||
}
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
|
||||
$base_url = trim((string)($config['nextcloud_url'] ?? ''));
|
||||
$username = trim((string)($credentials['nextcloud_user'] ?? ''));
|
||||
$password = (string)($credentials['nextcloud_password'] ?? '');
|
||||
|
||||
$missing = array();
|
||||
if ($base_url === '') $missing[] = 'nc_nextcloud_url';
|
||||
if ($username === '') $missing[] = 'nc_nextcloud_user';
|
||||
if ($password === '') $missing[] = 'nc_nextcloud_password';
|
||||
if ($missing)
|
||||
{
|
||||
bratonien_tools_nc_source_picker_fail(
|
||||
'Für die automatische Ordnerauswahl müssen Nextcloud-Adresse, Benutzer und Passwort gespeichert sein.',
|
||||
$missing
|
||||
);
|
||||
}
|
||||
|
||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
||||
|
||||
$state = bratonien_tools_nc_wizard_state();
|
||||
if ((int)($state['step'] ?? 0) !== 2 || empty($state['scan_ok']) || empty($state['directory_selection_ready']))
|
||||
{
|
||||
$detail = trim((string)($state['technical_error'] ?? ''));
|
||||
bratonien_tools_nc_source_picker_fail(
|
||||
$detail !== '' ? 'Die Nextcloud-Ordner konnten nicht geladen werden: '.$detail : 'Die Nextcloud-Ordner konnten nicht geladen werden.',
|
||||
array('nc_nextcloud_url','nc_nextcloud_user','nc_nextcloud_password')
|
||||
);
|
||||
}
|
||||
|
||||
bratonien_tools_nc_source_picker_json(200, array(
|
||||
'ok'=>true,
|
||||
'message'=>'Nextcloud-Ordner wurden geladen. Die Auswahl wird geöffnet.',
|
||||
'fields'=>array(),
|
||||
));
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$message = trim($e->getMessage());
|
||||
if ($message === '') $message = 'Die Nextcloud-Ordnerauswahl konnte nicht vorbereitet werden.';
|
||||
bratonien_tools_nc_source_picker_fail(
|
||||
$message,
|
||||
array('nc_nextcloud_url','nc_nextcloud_user','nc_nextcloud_password')
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user