11635452cSGreg Roach<?php 21635452cSGreg Roach 31635452cSGreg Roach/** 41635452cSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 61635452cSGreg Roach * This program is free software: you can redistribute it and/or modify 71635452cSGreg Roach * it under the terms of the GNU General Public License as published by 81635452cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 91635452cSGreg Roach * (at your option) any later version. 101635452cSGreg Roach * This program is distributed in the hope that it will be useful, 111635452cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 121635452cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131635452cSGreg Roach * GNU General Public License for more details. 141635452cSGreg 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/>. 161635452cSGreg Roach */ 171635452cSGreg Roach 181635452cSGreg Roachdeclare(strict_types=1); 191635452cSGreg Roach 201635452cSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 211635452cSGreg Roach 221635452cSGreg Roachuse Fig\Http\Message\StatusCodeInterface; 231635452cSGreg Roachuse Fisharebest\Webtrees\Auth; 2455134edcSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 256b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 26b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 271635452cSGreg Roachuse Illuminate\Support\Collection; 281635452cSGreg Roachuse Psr\Http\Message\ResponseInterface; 291635452cSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 301635452cSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 311635452cSGreg Roach 321635452cSGreg Roachuse function redirect; 331635452cSGreg Roach 341635452cSGreg Roach/** 351635452cSGreg Roach * Show a header's page. 361635452cSGreg Roach */ 371635452cSGreg Roachclass HeaderPage implements RequestHandlerInterface 381635452cSGreg Roach{ 391635452cSGreg Roach use ViewResponseTrait; 401635452cSGreg Roach 411635452cSGreg Roach /** 421635452cSGreg Roach * @param ServerRequestInterface $request 431635452cSGreg Roach * 441635452cSGreg Roach * @return ResponseInterface 451635452cSGreg Roach */ 461635452cSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 471635452cSGreg Roach { 48b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 49b55cbc6bSGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 50b55cbc6bSGreg Roach $slug = Validator::attributes($request)->string('slug', ''); 516b9cb339SGreg Roach $header = Registry::headerFactory()->make($xref, $tree); 521635452cSGreg Roach $header = Auth::checkHeaderAccess($header, false); 531635452cSGreg Roach 541635452cSGreg Roach // Redirect to correct xref/slug 55b55cbc6bSGreg Roach if ($header->xref() !== $xref || Registry::slugFactory()->make($header) !== $slug) { 561635452cSGreg Roach return redirect($header->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY); 571635452cSGreg Roach } 581635452cSGreg Roach 590f5fd22fSGreg Roach return $this->viewResponse('record-page', [ 600f5fd22fSGreg Roach 'clipboard_facts' => new Collection(), 610f5fd22fSGreg Roach 'linked_families' => null, 620f5fd22fSGreg Roach 'linked_individuals' => null, 634991f205SGreg Roach 'linked_locations' => null, 640f5fd22fSGreg Roach 'linked_media_objects' => null, 650f5fd22fSGreg Roach 'linked_notes' => null, 664991f205SGreg Roach 'linked_repositories' => null, 670f5fd22fSGreg Roach 'linked_sources' => null, 685962a3c2SGreg Roach 'linked_submitters' => null, 691635452cSGreg Roach 'meta_description' => '', 701635452cSGreg Roach 'meta_robots' => 'index,follow', 710f5fd22fSGreg Roach 'record' => $header, 721635452cSGreg Roach 'title' => $header->fullName(), 731635452cSGreg Roach 'tree' => $tree, 74*15c4f62cSGreg Roach ])->withHeader('Link', '<' . $header->url() . '>; rel="canonical"'); 751635452cSGreg Roach } 761635452cSGreg Roach} 77