. */ namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\FunctionsExport; use League\Flysystem\Filesystem; use League\Flysystem\ZipArchive\ZipArchiveAdapter; require 'includes/session.php'; $controller = new PageController; $controller ->setPageTitle(I18N::translate($controller->tree()->getTitleHtml()) . ' — ' . I18N::translate('Export a GEDCOM file')) ->restrictAccess(Auth::isManager($controller->tree())); // Validate user parameters $action = Filter::get('action', 'download'); $convert = Filter::get('convert'); $zip = Filter::get('zip'); $media = Filter::get('media'); $media_path = Filter::get('media-path'); $privatize_export = Filter::get('privatize_export', 'none|visitor|user|gedadmin'); if ($action === 'download') { switch ($privatize_export) { default: case 'gedadmin': $access_level = Auth::PRIV_NONE; break; case 'user': $access_level = Auth::PRIV_USER; break; case 'visitor': $access_level = Auth::PRIV_PRIVATE; break; case 'none': $access_level = Auth::PRIV_HIDE; break; } $exportOptions = [ 'privatize' => $privatize_export, 'toANSI' => $convert === 'on' ? 'yes' : 'no', 'path' => $media_path, ]; // What to call the downloaded file $download_filename = $controller->tree()->getName(); if (strtolower(substr($download_filename, -4, 4)) != '.ged') { $download_filename .= '.ged'; } if ($zip === 'on' || $media === 'on') { // Export the GEDCOM to an in-memory stream. $tmp_stream = tmpfile(); FunctionsExport::exportGedcom($controller->tree(), $tmp_stream, $exportOptions); rewind($tmp_stream); // Create a new/empty .ZIP file $temp_zip_file = tempnam(sys_get_temp_dir(), 'webtrees-zip-'); $zip_filesystem = new Filesystem(new ZipArchiveAdapter($temp_zip_file)); $zip_filesystem->writeStream($download_filename, $tmp_stream); if ($media === 'on') { $rows = Database::prepare( "SELECT m_id, m_gedcom FROM `##media` WHERE m_file = :tree_id AND m_filename NOT LIKE '%://%'" )->execute([ 'tree_id' => $controller->tree()->getTreeId(), ])->fetchAll(); $path = $controller->tree()->getPreference('MEDIA_DIRECTORY'); foreach ($rows as $row) { $record = Media::getInstance($row->m_id, $controller->tree(), $row->m_gedcom); if ($record->canShow($access_level) && file_exists($record->getServerFilename())) { $fp = fopen($record->getServerFilename(), 'r'); $zip_filesystem->writeStream($path . $record->getFilename(), $fp); fclose($fp); } } } // The ZipArchiveAdapter may or may not close the stream. if (is_resource($tmp_stream)) { fclose($tmp_stream); } // Need to force-close the filesystem $zip_filesystem = null; header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $download_filename . '.zip"'); header('Content-length: ' . filesize($temp_zip_file)); readfile($temp_zip_file); unlink($temp_zip_file); } else { header('Content-Type: text/plain; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $download_filename . '"'); // Stream the GEDCOM file straight to the browser. $stream = fopen('php://output', 'w'); FunctionsExport::exportGedcom($controller->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()); ?>

getPageTitle() ?>


tree()->getPreference('GEDCOM_MEDIA_PATH')): ?>

' . Html::escape($controller->tree()->getPreference('GEDCOM_MEDIA_PATH')) . '') ?>