1*701f5d18SGreg Roach<?php 2*701f5d18SGreg Roach 3*701f5d18SGreg Roach/** 4*701f5d18SGreg Roach * webtrees: online genealogy 5*701f5d18SGreg Roach * Copyright (C) 2022 webtrees development team 6*701f5d18SGreg Roach * This program is free software: you can redistribute it and/or modify 7*701f5d18SGreg Roach * it under the terms of the GNU General Public License as published by 8*701f5d18SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*701f5d18SGreg Roach * (at your option) any later version. 10*701f5d18SGreg Roach * This program is distributed in the hope that it will be useful, 11*701f5d18SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*701f5d18SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*701f5d18SGreg Roach * GNU General Public License for more details. 14*701f5d18SGreg Roach * You should have received a copy of the GNU General Public License 15*701f5d18SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16*701f5d18SGreg Roach */ 17*701f5d18SGreg Roach 18*701f5d18SGreg Roachdeclare(strict_types=1); 19*701f5d18SGreg Roach 20*701f5d18SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*701f5d18SGreg Roach 22*701f5d18SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23*701f5d18SGreg Roachuse Fisharebest\Webtrees\Auth; 24*701f5d18SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 25*701f5d18SGreg Roachuse Fisharebest\Webtrees\Registry; 26*701f5d18SGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService; 27*701f5d18SGreg Roachuse Fisharebest\Webtrees\Services\LinkedRecordService; 28*701f5d18SGreg Roachuse Fisharebest\Webtrees\Validator; 29*701f5d18SGreg Roachuse Psr\Http\Message\ResponseInterface; 30*701f5d18SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 31*701f5d18SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 32*701f5d18SGreg Roach 33*701f5d18SGreg Roachuse function redirect; 34*701f5d18SGreg Roach 35*701f5d18SGreg Roach/** 36*701f5d18SGreg Roach * Show a shared-note's page. 37*701f5d18SGreg Roach */ 38*701f5d18SGreg Roachclass SharedNotePage implements RequestHandlerInterface 39*701f5d18SGreg Roach{ 40*701f5d18SGreg Roach use ViewResponseTrait; 41*701f5d18SGreg Roach 42*701f5d18SGreg Roach private ClipboardService $clipboard_service; 43*701f5d18SGreg Roach 44*701f5d18SGreg Roach private LinkedRecordService $linked_record_service; 45*701f5d18SGreg Roach 46*701f5d18SGreg Roach /** 47*701f5d18SGreg Roach * @param ClipboardService $clipboard_service 48*701f5d18SGreg Roach * @param LinkedRecordService $linked_record_service 49*701f5d18SGreg Roach */ 50*701f5d18SGreg Roach public function __construct(ClipboardService $clipboard_service, LinkedRecordService $linked_record_service) 51*701f5d18SGreg Roach { 52*701f5d18SGreg Roach $this->clipboard_service = $clipboard_service; 53*701f5d18SGreg Roach $this->linked_record_service = $linked_record_service; 54*701f5d18SGreg Roach } 55*701f5d18SGreg Roach 56*701f5d18SGreg Roach /** 57*701f5d18SGreg Roach * @param ServerRequestInterface $request 58*701f5d18SGreg Roach * 59*701f5d18SGreg Roach * @return ResponseInterface 60*701f5d18SGreg Roach */ 61*701f5d18SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 62*701f5d18SGreg Roach { 63*701f5d18SGreg Roach $tree = Validator::attributes($request)->tree(); 64*701f5d18SGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 65*701f5d18SGreg Roach $slug = Validator::attributes($request)->string('slug', ''); 66*701f5d18SGreg Roach $record = Registry::sharedNoteFactory()->make($xref, $tree); 67*701f5d18SGreg Roach $record = Auth::checkSharedNoteAccess($record, false); 68*701f5d18SGreg Roach 69*701f5d18SGreg Roach // Redirect to correct xref/slug 70*701f5d18SGreg Roach if ($record->xref() !== $xref || Registry::slugFactory()->make($record) !== $slug) { 71*701f5d18SGreg Roach return redirect($record->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY); 72*701f5d18SGreg Roach } 73*701f5d18SGreg Roach 74*701f5d18SGreg Roach $linked_families = $this->linked_record_service->linkedFamilies($record); 75*701f5d18SGreg Roach $linked_individuals = $this->linked_record_service->linkedIndividuals($record); 76*701f5d18SGreg Roach $linked_locations = $this->linked_record_service->linkedLocations($record); 77*701f5d18SGreg Roach $linked_media = $this->linked_record_service->linkedMedia($record); 78*701f5d18SGreg Roach $linked_repositories = $this->linked_record_service->linkedRepositories($record); 79*701f5d18SGreg Roach $linked_sources = $this->linked_record_service->linkedSources($record); 80*701f5d18SGreg Roach $linked_submitters = $this->linked_record_service->linkedSubmitters($record); 81*701f5d18SGreg Roach 82*701f5d18SGreg Roach return $this->viewResponse('shared-note-page', [ 83*701f5d18SGreg Roach 'clipboard_facts' => $this->clipboard_service->pastableFacts($record), 84*701f5d18SGreg Roach 'linked_families' => $linked_families, 85*701f5d18SGreg Roach 'linked_individuals' => $linked_individuals, 86*701f5d18SGreg Roach 'linked_locations' => $linked_locations->isEmpty() ? null : $linked_locations, 87*701f5d18SGreg Roach 'linked_media_objects' => $linked_media, 88*701f5d18SGreg Roach 'linked_repositories' => $linked_repositories, 89*701f5d18SGreg Roach 'linked_sources' => $linked_sources, 90*701f5d18SGreg Roach 'linked_submitters' => $linked_submitters, 91*701f5d18SGreg Roach 'meta_description' => '', 92*701f5d18SGreg Roach 'meta_robots' => 'index,follow', 93*701f5d18SGreg Roach 'record' => $record, 94*701f5d18SGreg Roach 'title' => $record->fullName(), 95*701f5d18SGreg Roach 'tree' => $tree, 96*701f5d18SGreg Roach ]); 97*701f5d18SGreg Roach } 98*701f5d18SGreg Roach} 99