155134edcSGreg Roach<?php 255134edcSGreg Roach 355134edcSGreg Roach/** 455134edcSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 655134edcSGreg Roach * This program is free software: you can redistribute it and/or modify 755134edcSGreg Roach * it under the terms of the GNU General Public License as published by 855134edcSGreg Roach * the Free Software Foundation, either version 3 of the License, or 955134edcSGreg Roach * (at your option) any later version. 1055134edcSGreg Roach * This program is distributed in the hope that it will be useful, 1155134edcSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1255134edcSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1355134edcSGreg Roach * GNU General Public License for more details. 1455134edcSGreg 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/>. 1655134edcSGreg Roach */ 1755134edcSGreg Roach 1855134edcSGreg Roachdeclare(strict_types=1); 1955134edcSGreg Roach 2055134edcSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 2155134edcSGreg Roach 2255134edcSGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23*15c4f62cSGreg Roachuse Fisharebest\Webtrees\Http\Exceptions\HttpGoneException; 24266e9c61SGreg Roachuse Fisharebest\Webtrees\Registry; 2555134edcSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 2655134edcSGreg Roachuse Fisharebest\Webtrees\Site; 2755134edcSGreg Roachuse Fisharebest\Webtrees\Tree; 28266e9c61SGreg Roachuse Fisharebest\Webtrees\Validator; 2955134edcSGreg Roachuse Psr\Http\Message\ResponseInterface; 3055134edcSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3155134edcSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 3255134edcSGreg Roach 3355134edcSGreg Roach/** 3455134edcSGreg Roach * Redirect URLs created by webtrees 1.x (and PhpGedView). 3555134edcSGreg Roach */ 3655134edcSGreg Roachclass RedirectCalendarPhp implements RequestHandlerInterface 3755134edcSGreg Roach{ 38*15c4f62cSGreg Roach public function __construct( 39*15c4f62cSGreg Roach private readonly TreeService $tree_service, 40*15c4f62cSGreg Roach ) { 4155134edcSGreg Roach } 4255134edcSGreg Roach 4355134edcSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 4455134edcSGreg Roach { 45266e9c61SGreg Roach $ged = Validator::queryParams($request)->string('ged', Site::getPreference('DEFAULT_GEDCOM')); 46266e9c61SGreg Roach $cal = Validator::queryParams($request)->string('cal', ''); 47266e9c61SGreg Roach $day = Validator::queryParams($request)->string('day', ''); 48266e9c61SGreg Roach $month = Validator::queryParams($request)->string('month', ''); 49266e9c61SGreg Roach $year = Validator::queryParams($request)->string('year', ''); 50266e9c61SGreg Roach $filterev = Validator::queryParams($request)->string('filterev', ''); 51266e9c61SGreg Roach $filterof = Validator::queryParams($request)->string('filterof', ''); 52266e9c61SGreg Roach $filtersx = Validator::queryParams($request)->string('filtersx', ''); 53266e9c61SGreg Roach $view = Validator::queryParams($request)->string('view', 'day'); 5455134edcSGreg Roach $tree = $this->tree_service->all()->get($ged); 5555134edcSGreg Roach 5655134edcSGreg Roach if ($tree instanceof Tree) { 5774a95fceSGreg Roach $url = route(CalendarPage::class, [ 5855134edcSGreg Roach 'tree' => $tree->name(), 5955134edcSGreg Roach 'view' => $view, 6055134edcSGreg Roach 'cal' => $cal, 6155134edcSGreg Roach 'day' => $day, 6255134edcSGreg Roach 'month' => $month, 6355134edcSGreg Roach 'year' => $year, 6455134edcSGreg Roach 'filterev' => $filterev, 6555134edcSGreg Roach 'filterof' => $filterof, 6655134edcSGreg Roach 'filtersx' => $filtersx, 6755134edcSGreg Roach ]); 6855134edcSGreg Roach 69*15c4f62cSGreg Roach return Registry::responseFactory() 70*15c4f62cSGreg Roach ->redirectUrl($url, StatusCodeInterface::STATUS_MOVED_PERMANENTLY) 71*15c4f62cSGreg Roach ->withHeader('Link', '<' . $url . '>; rel="canonical"'); 7255134edcSGreg Roach } 7355134edcSGreg Roach 74*15c4f62cSGreg Roach throw new HttpGoneException(); 7555134edcSGreg Roach } 7655134edcSGreg Roach} 77