19927f70fSGreg Roach<?php 29927f70fSGreg Roach 39927f70fSGreg Roach/** 49927f70fSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 69927f70fSGreg Roach * This program is free software: you can redistribute it and/or modify 79927f70fSGreg Roach * it under the terms of the GNU General Public License as published by 89927f70fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 99927f70fSGreg Roach * (at your option) any later version. 109927f70fSGreg Roach * This program is distributed in the hope that it will be useful, 119927f70fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 129927f70fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 139927f70fSGreg Roach * GNU General Public License for more details. 149927f70fSGreg Roach * You should have received a copy of the GNU General Public License 159927f70fSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 169927f70fSGreg Roach */ 179927f70fSGreg Roach 189927f70fSGreg Roachdeclare(strict_types=1); 199927f70fSGreg Roach 209927f70fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 219927f70fSGreg Roach 229927f70fSGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService; 238d9c2b68SGreg Roachuse Fisharebest\Webtrees\Validator; 249927f70fSGreg Roachuse Psr\Http\Message\ResponseInterface; 259927f70fSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 269927f70fSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 279927f70fSGreg Roach 289927f70fSGreg Roachuse function redirect; 299927f70fSGreg Roach 309927f70fSGreg Roach/** 319927f70fSGreg Roach * Empty the clipboard. 329927f70fSGreg Roach */ 339927f70fSGreg Roachclass EmptyClipboard implements RequestHandlerInterface 349927f70fSGreg Roach{ 359927f70fSGreg Roach private ClipboardService $clipboard_service; 369927f70fSGreg Roach 379927f70fSGreg Roach /** 389927f70fSGreg Roach * @param ClipboardService $clipboard_service 399927f70fSGreg Roach */ 409927f70fSGreg Roach public function __construct(ClipboardService $clipboard_service) 419927f70fSGreg Roach { 429927f70fSGreg Roach $this->clipboard_service = $clipboard_service; 439927f70fSGreg Roach } 449927f70fSGreg Roach 459927f70fSGreg Roach /** 469927f70fSGreg Roach * Paste a fact from the clipboard into a record. 479927f70fSGreg Roach * 489927f70fSGreg Roach * @param ServerRequestInterface $request 499927f70fSGreg Roach * 509927f70fSGreg Roach * @return ResponseInterface 519927f70fSGreg Roach */ 529927f70fSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 539927f70fSGreg Roach { 549927f70fSGreg Roach $this->clipboard_service->emptyClipboard(); 559927f70fSGreg Roach 568d9c2b68SGreg Roach $default_url = $request->getHeaderLine('Referer'); 57f507cef9SGreg Roach $url = Validator::parsedBody($request)->isLocalUrl()->string('url', $default_url); 58551ad4afSGreg Roach 599927f70fSGreg Roach return redirect($url); 609927f70fSGreg Roach } 619927f70fSGreg Roach} 62