. */ namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\FunctionsExport; use PclZip; /** @global Tree $WT_TREE */ global $WT_TREE; require 'includes/session.php'; $controller = new PageController; $controller ->setPageTitle(I18N::translate($WT_TREE->getTitleHtml()) . ' — ' . I18N::translate('Export a GEDCOM file')) ->restrictAccess(Auth::isManager($WT_TREE)); // Validate user parameters $action = Filter::get('action', 'download'); $convert = Filter::get('convert', 'yes|no', 'no'); $zip = Filter::get('zip', 'yes|no', 'no'); $conv_path = Filter::get('conv_path'); $privatize_export = Filter::get('privatize_export', 'none|visitor|user|gedadmin'); if ($action === 'download') { $exportOptions = [ 'privatize' => $privatize_export, 'toANSI' => $convert, 'path' => $conv_path, ]; // What to call the downloaded file $download_filename = $WT_TREE->getName(); if (strtolower(substr($download_filename, -4, 4)) != '.ged') { $download_filename .= '.ged'; } if ($zip === 'yes') { $temp_dir = WT_DATA_DIR . 'tmp-' . $WT_TREE->getName() . '-' . date('YmdHis') . '/'; $zip_file = $download_filename . '.zip'; if (!File::mkdir($temp_dir)) { echo 'Error : Could not create temporary path!'; return; } // Create the unzipped GEDCOM on disk, so we can ZIP it. $stream = fopen($temp_dir . $download_filename, 'w'); FunctionsExport::exportGedcom($WT_TREE, $stream, $exportOptions); fclose($stream); // Create a ZIP file containing the GEDCOM file. $comment = 'Created by ' . WT_WEBTREES . ' ' . WT_VERSION . ' on ' . date('r') . '.'; $archive = new PclZip($temp_dir . $zip_file); $v_list = $archive->add($temp_dir . $download_filename, \PCLZIP_OPT_COMMENT, $comment, \PCLZIP_OPT_REMOVE_PATH, $temp_dir); if ($v_list == 0) { echo 'Error : ' . $archive->errorInfo(true); } else { header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $zip_file . '"'); header('Content-length: ' . filesize($temp_dir . $zip_file)); readfile($temp_dir . $zip_file); File::delete($temp_dir); } } else { header('Content-Type: text/plain; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $download_filename . '"'); // Stream the GEDCOM file straight to the browser. // We could open "php://compress.zlib" to create a .gz file or "php://compress.bzip2" to create a .bz2 file $stream = fopen('php://output', 'w'); FunctionsExport::exportGedcom($WT_TREE, $stream, $exportOptions); fclose($stream); } return; } $controller->pageHeader(); echo Bootstrap4::breadcrumbs([ 'admin.php' => I18N::translate('Control panel'), 'admin_trees_manage.php' => I18N::translate('Manage family trees'), ], $controller->getPageTitle()); ?>