. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Factory; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Gedcom; use Fisharebest\Webtrees\Header; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Media; use Fisharebest\Webtrees\Note; use Fisharebest\Webtrees\Repository; use Fisharebest\Webtrees\Source; use Fisharebest\Webtrees\Submission; use Fisharebest\Webtrees\Submitter; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; use function is_string; use function redirect; /** * Display non-standard genealogy records. */ class GedcomRecordPage implements RequestHandlerInterface { use ViewResponseTrait; // These standard genealogy record types have their own pages. private const STANDARD_RECORDS = [ Family::class, Header::class, Individual::class, Media::class, Note::class, Repository::class, Source::class, Submission::class, Submitter::class, ]; /** * Show a gedcom record's page. * * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $xref = $request->getAttribute('xref'); assert(is_string($xref)); $record = Factory::gedcomRecord()->make($xref, $tree); $record = Auth::checkRecordAccess($record); // Standard genealogy records have their own pages. if ($record->xref() !== $xref || in_array(get_class($record), self::STANDARD_RECORDS, true)) { return redirect($record->url()); } if (preg_match('/^0 @' . Gedcom::REGEX_XREF . '@ ([_A-Z0-9]+)/', $record->gedcom(), $match)) { $record_type = $match[1]; } elseif (preg_match('/^0 ([_A-Z0-9]+)/', $record->gedcom(), $match)) { $record_type = $match[1]; } else { $record_type = $record::RECORD_TYPE; } return $this->viewResponse('gedcom-record-page', [ 'facts' => $record->facts(), 'families' => $record->linkedFamilies($record_type), 'individuals' => $record->linkedIndividuals($record_type), 'notes' => $record->linkedNotes($record_type), 'media_objects' => $record->linkedMedia($record_type), 'record' => $record, 'sources' => $record->linkedSources($record_type), 'title' => $record->fullName(), 'tree' => $tree, ]); } }