1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Http\RequestHandlers; 21 22use Fisharebest\Webtrees\Auth; 23use Fisharebest\Webtrees\Family; 24use Fisharebest\Webtrees\Header; 25use Fisharebest\Webtrees\Http\ViewResponseTrait; 26use Fisharebest\Webtrees\Individual; 27use Fisharebest\Webtrees\Location; 28use Fisharebest\Webtrees\Media; 29use Fisharebest\Webtrees\Note; 30use Fisharebest\Webtrees\Registry; 31use Fisharebest\Webtrees\Repository; 32use Fisharebest\Webtrees\Source; 33use Fisharebest\Webtrees\Submission; 34use Fisharebest\Webtrees\Submitter; 35use Fisharebest\Webtrees\Validator; 36use Illuminate\Support\Collection; 37use Psr\Http\Message\ResponseInterface; 38use Psr\Http\Message\ServerRequestInterface; 39use Psr\Http\Server\RequestHandlerInterface; 40 41use function redirect; 42 43/** 44 * Display non-standard genealogy records. 45 */ 46class GedcomRecordPage implements RequestHandlerInterface 47{ 48 use ViewResponseTrait; 49 50 // These standard genealogy record types have their own pages. 51 private const STANDARD_RECORDS = [ 52 Family::class, 53 Header::class, 54 Individual::class, 55 Location::class, 56 Media::class, 57 Note::class, 58 Repository::class, 59 Source::class, 60 Submission::class, 61 Submitter::class, 62 ]; 63 64 /** 65 * Show a gedcom record's page. 66 * 67 * @param ServerRequestInterface $request 68 * 69 * @return ResponseInterface 70 */ 71 public function handle(ServerRequestInterface $request): ResponseInterface 72 { 73 $tree = Validator::attributes($request)->tree(); 74 $xref = Validator::attributes($request)->isXref()->string('xref'); 75 $record = Registry::gedcomRecordFactory()->make($xref, $tree); 76 $record = Auth::checkRecordAccess($record); 77 78 // Standard genealogy records have their own pages. 79 if ($record->xref() !== $xref || in_array(get_class($record), self::STANDARD_RECORDS, true)) { 80 return redirect($record->url()); 81 } 82 83 return $this->viewResponse('record-page', [ 84 'clipboard_facts' => new Collection(), 85 'linked_families' => $record->linkedFamilies($record->tag()), 86 'linked_individuals' => $record->linkedIndividuals($record->tag()), 87 'linked_media_objects' => $record->linkedMedia($record->tag()), 88 'linked_notes' => $record->linkedNotes($record->tag()), 89 'linked_sources' => $record->linkedSources($record->tag()), 90 'record' => $record, 91 'title' => $record->fullName(), 92 'tree' => $tree, 93 ]); 94 } 95} 96