media-library search, MIME-type and virtual-folder filters, persisted

folder and alt-text editing, and safe defaults for legacy uploads
This commit is contained in:
2026-11-30 16:51:14 +01:00
parent 1ec2d9c8e1
commit e1767dcd2c
7 changed files with 654 additions and 9 deletions
@@ -26,6 +26,15 @@ class WebsiteManager implements WebsiteManagerContract
exit();
}
if ($route === 'media' && $action === 'update_metadata') {
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
exit();
}
$this->handleUpdateMediaMetadata();
exit();
}
if ($route === 'quality' && $action === 'scan' && ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
if (! function_exists('phpb_validate_csrf') || ! phpb_validate_csrf()) {
http_response_code(403);
@@ -83,6 +92,45 @@ class WebsiteManager implements WebsiteManagerContract
}
}
/**
* Handle a CSRF-protected update to upload metadata.
*/
public function handleUpdateMediaMetadata(): bool
{
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
return false;
}
if (! function_exists('phpb_validate_csrf') || ! phpb_validate_csrf()) {
http_response_code(403);
return false;
}
$allowedFields = ['_csrf_token', 'public_id', 'folder', 'alt_text'];
if (array_diff(array_keys($_POST), $allowedFields)) {
return $this->redirectMediaMetadataResult(false);
}
$publicId = $_POST['public_id'] ?? null;
$metadata = array_intersect_key($_POST, array_flip(['folder', 'alt_text']));
if (! is_string($publicId) || $publicId === '' || empty($metadata)) {
return $this->redirectMediaMetadataResult(false);
}
$success = (new UploadRepository)->updateMetadata($publicId, $metadata);
return $this->redirectMediaMetadataResult($success);
}
private function redirectMediaMetadataResult(bool $success): bool
{
phpb_redirect(phpb_url('website_manager', ['tab' => 'files']), [
'message-type' => $success ? 'success' : 'error',
'message' => $success ? 'Media metadata updated.' : 'Media metadata could not be updated.',
]);
return $success;
}
/**
* Handle requests for creating a new page.
*/