16d576906SGreg Roach<?php 26d576906SGreg Roach 36d576906SGreg Roach/** 46d576906SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 66d576906SGreg Roach * This program is free software: you can redistribute it and/or modify 76d576906SGreg Roach * it under the terms of the GNU General Public License as published by 86d576906SGreg Roach * the Free Software Foundation, either version 3 of the License, or 96d576906SGreg Roach * (at your option) any later version. 106d576906SGreg Roach * This program is distributed in the hope that it will be useful, 116d576906SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126d576906SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136d576906SGreg Roach * GNU General Public License for more details. 146d576906SGreg 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/>. 166d576906SGreg Roach */ 176d576906SGreg Roach 186d576906SGreg Roachdeclare(strict_types=1); 196d576906SGreg Roach 206d576906SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 216d576906SGreg Roach 226d576906SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 236d576906SGreg Roachuse Fisharebest\Webtrees\I18N; 24b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 256d576906SGreg Roachuse Psr\Http\Message\ResponseInterface; 266d576906SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 276d576906SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 286d576906SGreg Roach 2916ecfcafSGreg Roachuse function date; 306d576906SGreg Roachuse function e; 3116ecfcafSGreg Roachuse function extension_loaded; 32eb2f4c2aSGreg Roachuse function pathinfo; 33eb2f4c2aSGreg Roachuse function strtolower; 3416ecfcafSGreg Roachuse function substr; 35eb2f4c2aSGreg Roach 36eb2f4c2aSGreg Roachuse const PATHINFO_EXTENSION; 376d576906SGreg Roach 386d576906SGreg Roach/** 396d576906SGreg Roach * Show download forms/optiosn. 406d576906SGreg Roach */ 416d576906SGreg Roachclass ExportGedcomPage implements RequestHandlerInterface 426d576906SGreg Roach{ 436d576906SGreg Roach use ViewResponseTrait; 446d576906SGreg Roach 456d576906SGreg Roach /** 466d576906SGreg Roach * @param ServerRequestInterface $request 476d576906SGreg Roach * 486d576906SGreg Roach * @return ResponseInterface 496d576906SGreg Roach */ 506d576906SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 516d576906SGreg Roach { 52b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 536d576906SGreg Roach $title = I18N::translate('Export a GEDCOM file') . ' — ' . e($tree->title()); 546d576906SGreg Roach 556d576906SGreg Roach $this->layout = 'layouts/administration'; 566d576906SGreg Roach 57eb2f4c2aSGreg Roach $filename = $tree->name(); 58eb2f4c2aSGreg Roach 59eb2f4c2aSGreg Roach // Force a ".ged" suffix 6016ecfcafSGreg Roach if (strtolower(pathinfo($filename, PATHINFO_EXTENSION)) === 'ged') { 6116ecfcafSGreg Roach $download_filename = substr($filename, 0, -4); 6216ecfcafSGreg Roach } else { 6316ecfcafSGreg Roach $download_filename = $filename; 64eb2f4c2aSGreg Roach } 65eb2f4c2aSGreg Roach 6616ecfcafSGreg Roach $download_filenames = [ 6716ecfcafSGreg Roach $download_filename => $download_filename, 6816ecfcafSGreg Roach $download_filename . date('-Y-m-d') => $download_filename . date('-Y-m-d'), 6916ecfcafSGreg Roach ]; 7016ecfcafSGreg Roach 716d576906SGreg Roach return $this->viewResponse('admin/trees-export', [ 7216ecfcafSGreg Roach 'download_filenames' => $download_filenames, 73eb2f4c2aSGreg Roach 'filename' => $filename, 746d576906SGreg Roach 'title' => $title, 756d576906SGreg Roach 'tree' => $tree, 7616ecfcafSGreg Roach 'zip_available' => extension_loaded('zip'), 776d576906SGreg Roach ]); 786d576906SGreg Roach } 796d576906SGreg Roach} 80