1ffc0a61fSGreg Roach<?php 2ffc0a61fSGreg Roach 3ffc0a61fSGreg Roach/** 4ffc0a61fSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6ffc0a61fSGreg Roach * This program is free software: you can redistribute it and/or modify 7ffc0a61fSGreg Roach * it under the terms of the GNU General Public License as published by 8ffc0a61fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9ffc0a61fSGreg Roach * (at your option) any later version. 10ffc0a61fSGreg Roach * This program is distributed in the hope that it will be useful, 11ffc0a61fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12ffc0a61fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13ffc0a61fSGreg Roach * GNU General Public License for more details. 14ffc0a61fSGreg 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/>. 16ffc0a61fSGreg Roach */ 17ffc0a61fSGreg Roach 18ffc0a61fSGreg Roachdeclare(strict_types=1); 19ffc0a61fSGreg Roach 20ffc0a61fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21ffc0a61fSGreg Roach 228256f465SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Auth; 24ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 256b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 264991f205SGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService; 274991f205SGreg Roachuse Fisharebest\Webtrees\Services\LinkedRecordService; 28b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 29ffc0a61fSGreg Roachuse Psr\Http\Message\ResponseInterface; 30ffc0a61fSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 31ffc0a61fSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 32ffc0a61fSGreg Roach 33ffc0a61fSGreg Roachuse function redirect; 34ffc0a61fSGreg Roach 35ffc0a61fSGreg Roach/** 36ffc0a61fSGreg Roach * Show a submitter's page. 37ffc0a61fSGreg Roach */ 38ffc0a61fSGreg Roachclass SubmitterPage implements RequestHandlerInterface 39ffc0a61fSGreg Roach{ 40ffc0a61fSGreg Roach use ViewResponseTrait; 41ffc0a61fSGreg Roach 424991f205SGreg Roach private ClipboardService $clipboard_service; 434991f205SGreg Roach 444991f205SGreg Roach private LinkedRecordService $linked_record_service; 454991f205SGreg Roach 464991f205SGreg Roach /** 474991f205SGreg Roach * @param ClipboardService $clipboard_service 484991f205SGreg Roach * @param LinkedRecordService $linked_record_service 494991f205SGreg Roach */ 504991f205SGreg Roach public function __construct(ClipboardService $clipboard_service, LinkedRecordService $linked_record_service) 514991f205SGreg Roach { 524991f205SGreg Roach $this->clipboard_service = $clipboard_service; 534991f205SGreg Roach $this->linked_record_service = $linked_record_service; 544991f205SGreg Roach } 554991f205SGreg Roach 56ffc0a61fSGreg Roach /** 57ffc0a61fSGreg Roach * @param ServerRequestInterface $request 58ffc0a61fSGreg Roach * 59ffc0a61fSGreg Roach * @return ResponseInterface 60ffc0a61fSGreg Roach */ 61ffc0a61fSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 62ffc0a61fSGreg Roach { 63b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 64b55cbc6bSGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 65b55cbc6bSGreg Roach $slug = Validator::attributes($request)->string('slug', ''); 660f5fd22fSGreg Roach $record = Registry::submitterFactory()->make($xref, $tree); 670f5fd22fSGreg Roach $record = Auth::checkSubmitterAccess($record, false); 68ffc0a61fSGreg Roach 69ffc0a61fSGreg Roach // Redirect to correct xref/slug 70b55cbc6bSGreg Roach if ($record->xref() !== $xref || Registry::slugFactory()->make($record) !== $slug) { 710f5fd22fSGreg Roach return redirect($record->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY); 72ffc0a61fSGreg Roach } 73ffc0a61fSGreg Roach 740f5fd22fSGreg Roach return $this->viewResponse('record-page', [ 754991f205SGreg Roach 'clipboard_facts' => $this->clipboard_service->pastableFacts($record), 764991f205SGreg Roach 'linked_families' => $this->linked_record_service->linkedFamilies($record), 774991f205SGreg Roach 'linked_individuals' => $this->linked_record_service->linkedIndividuals($record), 784991f205SGreg Roach 'linked_locations' => null, 790f5fd22fSGreg Roach 'linked_media_objects' => null, 800f5fd22fSGreg Roach 'linked_notes' => null, 814991f205SGreg Roach 'linked_repositories' => null, 820f5fd22fSGreg Roach 'linked_sources' => null, 835962a3c2SGreg Roach 'linked_submitters' => null, 842406e0e0SGreg Roach 'meta_description' => '', 852406e0e0SGreg Roach 'meta_robots' => 'index,follow', 860f5fd22fSGreg Roach 'record' => $record, 870f5fd22fSGreg Roach 'title' => $record->fullName(), 88ffc0a61fSGreg Roach 'tree' => $tree, 89*15c4f62cSGreg Roach ])->withHeader('Link', '<' . $record->url() . '>; rel="canonical"'); 90ffc0a61fSGreg Roach } 91ffc0a61fSGreg Roach} 92