xref: /webtrees/app/Http/RequestHandlers/SubmissionPage.php (revision 0f5fd22fb1857ad87285e5357592434d47b1f3bf)
11635452cSGreg Roach<?php
21635452cSGreg Roach
31635452cSGreg Roach/**
41635452cSGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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;
241635452cSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
256b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry;
261635452cSGreg Roachuse Fisharebest\Webtrees\Tree;
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 assert;
331635452cSGreg Roachuse function is_string;
341635452cSGreg Roachuse function redirect;
351635452cSGreg Roach
361635452cSGreg Roach/**
371635452cSGreg Roach * Show a submission's page.
381635452cSGreg Roach */
391635452cSGreg Roachclass SubmissionPage implements RequestHandlerInterface
401635452cSGreg Roach{
411635452cSGreg Roach    use ViewResponseTrait;
421635452cSGreg Roach
431635452cSGreg Roach    /**
441635452cSGreg Roach     * @param ServerRequestInterface $request
451635452cSGreg Roach     *
461635452cSGreg Roach     * @return ResponseInterface
471635452cSGreg Roach     */
481635452cSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
491635452cSGreg Roach    {
501635452cSGreg Roach        $tree = $request->getAttribute('tree');
511635452cSGreg Roach        assert($tree instanceof Tree);
521635452cSGreg Roach
531635452cSGreg Roach        $xref = $request->getAttribute('xref');
541635452cSGreg Roach        assert(is_string($xref));
551635452cSGreg Roach
56*0f5fd22fSGreg Roach        $record = Registry::submissionFactory()->make($xref, $tree);
57*0f5fd22fSGreg Roach        $record = Auth::checkSubmissionAccess($record, false);
581635452cSGreg Roach
591635452cSGreg Roach        // Redirect to correct xref/slug
60*0f5fd22fSGreg Roach        $slug = Registry::slugFactory()->make($record);
61194b0938SGreg Roach
62*0f5fd22fSGreg Roach        if ($record->xref() !== $xref || $request->getAttribute('slug') !== $slug) {
63*0f5fd22fSGreg Roach            return redirect($record->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY);
641635452cSGreg Roach        }
651635452cSGreg Roach
66*0f5fd22fSGreg Roach        return $this->viewResponse('record-page', [
67*0f5fd22fSGreg Roach            'clipboard_facts'      => new Collection(),
68*0f5fd22fSGreg Roach            'linked_families'      => null,
69*0f5fd22fSGreg Roach            'linked_individuals'   => null,
70*0f5fd22fSGreg Roach            'linked_media_objects' => null,
71*0f5fd22fSGreg Roach            'linked_notes'         => null,
72*0f5fd22fSGreg Roach            'linked_sources'       => null,
731635452cSGreg Roach            'meta_description'     => '',
741635452cSGreg Roach            'meta_robots'          => 'index,follow',
75*0f5fd22fSGreg Roach            'record'               => $record,
76*0f5fd22fSGreg Roach            'title'                => $record->fullName(),
771635452cSGreg Roach            'tree'                 => $tree,
781635452cSGreg Roach        ]);
791635452cSGreg Roach    }
801635452cSGreg Roach}
81