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; 2455134edcSGreg Roachuse Fisharebest\Webtrees\Individual; 253340ecd2SGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule; 2655134edcSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule; 276b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 283340ecd2SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 2955134edcSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 3055134edcSGreg Roachuse Fisharebest\Webtrees\Site; 3155134edcSGreg Roachuse Fisharebest\Webtrees\Tree; 32266e9c61SGreg Roachuse Fisharebest\Webtrees\Validator; 3355134edcSGreg Roachuse Psr\Http\Message\ResponseInterface; 3455134edcSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3555134edcSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 3655134edcSGreg Roach 3755134edcSGreg Roach/** 3855134edcSGreg Roach * Redirect URLs created by webtrees 1.x (and PhpGedView). 3955134edcSGreg Roach */ 4055134edcSGreg Roachclass RedirectModulePhp implements RequestHandlerInterface 4155134edcSGreg Roach{ 42*15c4f62cSGreg Roach public function __construct( 43*15c4f62cSGreg Roach private readonly ModuleService $module_service, 44*15c4f62cSGreg Roach private readonly TreeService $tree_service, 45*15c4f62cSGreg Roach ) { 4655134edcSGreg Roach } 4755134edcSGreg Roach 4855134edcSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 4955134edcSGreg Roach { 50266e9c61SGreg Roach $ged = Validator::queryParams($request)->string('ged', Site::getPreference('DEFAULT_GEDCOM')); 51266e9c61SGreg Roach $mod = Validator::queryParams($request)->string('mod', ''); 52266e9c61SGreg Roach $mod_action = Validator::queryParams($request)->string('mod_action', ''); 53266e9c61SGreg Roach $rootid = Validator::queryParams($request)->string('rootid', ''); 5455134edcSGreg Roach $tree = $this->tree_service->all()->get($ged); 5555134edcSGreg Roach 5655134edcSGreg Roach if ($tree instanceof Tree) { 573340ecd2SGreg Roach $individual = Registry::individualFactory()->make($rootid, $tree); 583340ecd2SGreg Roach 593340ecd2SGreg Roach if ($individual instanceof Individual) { 6055134edcSGreg Roach switch ($mod . '/' . $mod_action) { 6155134edcSGreg Roach case 'googlemap/pedigree_map': 623340ecd2SGreg Roach $module = $this->module_service->findByInterface(PedigreeMapModule::class)->first(); 633340ecd2SGreg Roach 643340ecd2SGreg Roach if ($module instanceof PedigreeMapModule) { 65266e9c61SGreg Roach $generations = Validator::queryParams($request)->string('PEDIGREE_GENERATIONS', PedigreeMapModule::DEFAULT_GENERATIONS); 663340ecd2SGreg Roach $url = $module->chartUrl($individual, ['generations' => $generations]); 6755134edcSGreg Roach 68266e9c61SGreg Roach return Registry::responseFactory()->redirectUrl($url, StatusCodeInterface::STATUS_MOVED_PERMANENTLY); 6955134edcSGreg Roach } 703340ecd2SGreg Roach 7155134edcSGreg Roach break; 7255134edcSGreg Roach 7355134edcSGreg Roach case 'tree/treeview': 743340ecd2SGreg Roach $module = $this->module_service->findByInterface(InteractiveTreeModule::class)->first(); 753340ecd2SGreg Roach 763340ecd2SGreg Roach if ($module instanceof InteractiveTreeModule) { 773340ecd2SGreg Roach $url = $module->chartUrl($individual, []); 7855134edcSGreg Roach 79*15c4f62cSGreg Roach return Registry::responseFactory() 80*15c4f62cSGreg Roach ->redirectUrl($url, StatusCodeInterface::STATUS_MOVED_PERMANENTLY) 81*15c4f62cSGreg Roach ->withHeader('Link', '<' . $url . '>; rel="canonical"'); 8255134edcSGreg Roach } 833340ecd2SGreg Roach 843340ecd2SGreg Roach break; 853340ecd2SGreg Roach } 863340ecd2SGreg Roach } 8755134edcSGreg Roach } 8855134edcSGreg Roach 89*15c4f62cSGreg Roach throw new HttpGoneException(); 9055134edcSGreg Roach } 9155134edcSGreg Roach} 92