xref: /webtrees/app/Http/RequestHandlers/UploadMediaPage.php (revision e93a8df2f8d797005750082cc3766c0e80799688)
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;
268ce3bd73SGreg Roachuse Psr\Http\Message\ResponseInterface;
278ce3bd73SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
288ce3bd73SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
298ce3bd73SGreg Roach
308ce3bd73SGreg Roachuse function ini_get;
318ce3bd73SGreg Roach
328ce3bd73SGreg Roach/**
338ce3bd73SGreg Roach * Manage media from the control panel.
348ce3bd73SGreg Roach */
358ce3bd73SGreg Roachclass UploadMediaPage implements RequestHandlerInterface
368ce3bd73SGreg Roach{
378ce3bd73SGreg Roach    use ViewResponseTrait;
388ce3bd73SGreg Roach
398ce3bd73SGreg Roach    // How many files to upload on one form.
408ce3bd73SGreg Roach    private const MAX_UPLOAD_FILES = 10;
418ce3bd73SGreg Roach
42c4943cffSGreg Roach    private MediaFileService $media_file_service;
438ce3bd73SGreg Roach
448ce3bd73SGreg Roach    /**
458ce3bd73SGreg Roach     * @param MediaFileService $media_file_service
468ce3bd73SGreg Roach     */
478ce3bd73SGreg Roach    public function __construct(MediaFileService $media_file_service)
488ce3bd73SGreg Roach    {
498ce3bd73SGreg Roach        $this->media_file_service = $media_file_service;
508ce3bd73SGreg Roach    }
518ce3bd73SGreg Roach
528ce3bd73SGreg Roach    /**
538ce3bd73SGreg Roach     * @param ServerRequestInterface $request
548ce3bd73SGreg Roach     *
558ce3bd73SGreg Roach     * @return ResponseInterface
568ce3bd73SGreg Roach     */
578ce3bd73SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
588ce3bd73SGreg Roach    {
598ce3bd73SGreg Roach        $this->layout = 'layouts/administration';
608ce3bd73SGreg Roach
618ce3bd73SGreg Roach        $data_filesystem = Registry::filesystem()->data();
628ce3bd73SGreg Roach
638ce3bd73SGreg Roach        $media_folders = $this->media_file_service->allMediaFolders($data_filesystem);
648ce3bd73SGreg Roach
658ce3bd73SGreg Roach        $filesize = ini_get('upload_max_filesize') ?: '2M';
668ce3bd73SGreg Roach
678ce3bd73SGreg Roach        $title = I18N::translate('Upload media files');
688ce3bd73SGreg Roach
698ce3bd73SGreg Roach        return $this->viewResponse('admin/media-upload', [
708ce3bd73SGreg Roach            'max_upload_files' => self::MAX_UPLOAD_FILES,
718ce3bd73SGreg Roach            'filesize'         => $filesize,
728ce3bd73SGreg Roach            'media_folders'    => $media_folders,
738ce3bd73SGreg Roach            'title'            => $title,
748ce3bd73SGreg Roach        ]);
758ce3bd73SGreg Roach    }
768ce3bd73SGreg Roach}
77