18ce3bd73SGreg Roach<?php 28ce3bd73SGreg Roach 38ce3bd73SGreg Roach/** 48ce3bd73SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68ce3bd73SGreg Roach * This program is free software: you can redistribute it and/or modify 78ce3bd73SGreg Roach * it under the terms of the GNU General Public License as published by 88ce3bd73SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98ce3bd73SGreg Roach * (at your option) any later version. 108ce3bd73SGreg Roach * This program is distributed in the hope that it will be useful, 118ce3bd73SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128ce3bd73SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138ce3bd73SGreg Roach * GNU General Public License for more details. 148ce3bd73SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 168ce3bd73SGreg Roach */ 178ce3bd73SGreg Roach 188ce3bd73SGreg Roachdeclare(strict_types=1); 198ce3bd73SGreg Roach 208ce3bd73SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 218ce3bd73SGreg Roach 228ce3bd73SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 238ce3bd73SGreg Roachuse Fisharebest\Webtrees\I18N; 248ce3bd73SGreg Roachuse Fisharebest\Webtrees\Registry; 258ce3bd73SGreg Roachuse Fisharebest\Webtrees\Services\MediaFileService; 26748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 278ce3bd73SGreg Roachuse Psr\Http\Message\ResponseInterface; 288ce3bd73SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 298ce3bd73SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 308ce3bd73SGreg Roach 318ce3bd73SGreg Roach/** 328ce3bd73SGreg Roach * Manage media from the control panel. 338ce3bd73SGreg Roach */ 348ce3bd73SGreg Roachclass ManageMediaPage implements RequestHandlerInterface 358ce3bd73SGreg Roach{ 368ce3bd73SGreg Roach use ViewResponseTrait; 378ce3bd73SGreg Roach 38c4943cffSGreg Roach private MediaFileService $media_file_service; 398ce3bd73SGreg Roach 408ce3bd73SGreg Roach /** 418ce3bd73SGreg Roach * @param MediaFileService $media_file_service 428ce3bd73SGreg Roach */ 438ce3bd73SGreg Roach public function __construct(MediaFileService $media_file_service) 448ce3bd73SGreg Roach { 458ce3bd73SGreg Roach $this->media_file_service = $media_file_service; 468ce3bd73SGreg Roach } 478ce3bd73SGreg Roach 488ce3bd73SGreg Roach /** 498ce3bd73SGreg Roach * @param ServerRequestInterface $request 508ce3bd73SGreg Roach * 518ce3bd73SGreg Roach * @return ResponseInterface 528ce3bd73SGreg Roach */ 538ce3bd73SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 548ce3bd73SGreg Roach { 558ce3bd73SGreg Roach $this->layout = 'layouts/administration'; 568ce3bd73SGreg Roach 578ce3bd73SGreg Roach $data_filesystem = Registry::filesystem()->data(); 588ce3bd73SGreg Roach $data_filesystem_name = Registry::filesystem()->dataName(); 598ce3bd73SGreg Roach 60748dbe15SGreg Roach $files = Validator::queryParams($request)->isInArray(['local', 'external', 'unused'])->string('files', 'local'); 61748dbe15SGreg Roach $subfolders = Validator::queryParams($request)->isInArray(['include', 'exclude'])->string('subfolders', 'exclude'); 628ce3bd73SGreg Roach $media_folders = $this->media_file_service->allMediaFolders($data_filesystem); 63748dbe15SGreg Roach $media_folder = Validator::queryParams($request)->string('media_folder', $media_folders->first() ?? ''); 64455a30feSGreg Roach $media_types = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->values(); 658ce3bd73SGreg Roach 668ce3bd73SGreg Roach $title = I18N::translate('Manage media'); 678ce3bd73SGreg Roach 688ce3bd73SGreg Roach return $this->viewResponse('admin/media', [ 698ce3bd73SGreg Roach 'data_folder' => $data_filesystem_name, 708ce3bd73SGreg Roach 'files' => $files, 718ce3bd73SGreg Roach 'media_folder' => $media_folder, 728ce3bd73SGreg Roach 'media_folders' => $media_folders, 73455a30feSGreg Roach 'media_types' => $media_types, 748ce3bd73SGreg Roach 'subfolders' => $subfolders, 758ce3bd73SGreg Roach 'title' => $title, 768ce3bd73SGreg Roach ]); 778ce3bd73SGreg Roach } 788ce3bd73SGreg Roach} 79