if ($export) { $ged_id = get_id_from_gedcom($export); $filename = get_gedcom_setting($ged_id, 'path'); echo '<h1>', $pgv_lang['ged_export'], '</h1>'; echo '<p>', htmlspecialchars(filename_decode($export)), ' => ', $filename, '</p>'; flush(); $gedout = fopen($filename . '.tmp', 'w'); if ($gedout) { $start = microtime(true); $exportOptions = array(); $exportOptions['privatize'] = 'none'; $exportOptions['toANSI'] = 'no'; $exportOptions['noCustomTags'] = 'no'; $exportOptions['path'] = $MEDIA_DIRECTORY; $exportOptions['slashes'] = 'forward'; export_gedcom($export, $gedout, $exportOptions); $end = microtime(true); fclose($gedout); unlink($filename); rename($filename . '.tmp', $filename); $stat = stat($filename); echo sprintf('<p>%d bytes, %0.3f seconds</p>', $stat['size'], $end - $start); } else { echo '<p>Error: could not open file for writing</p>'; } } else { echo '<h1>Export data from database to gedcom file</h1>'; echo '<ul>'; foreach ($gedcoms as $ged_id => $gedcom) { echo '<li><a href="?export=', urlencode($gedcom), '">', $gedcom, ' => ', htmlspecialchars(filename_decode(realpath(get_gedcom_setting($ged_id, 'path')))), '</a></li>'; }
/** * generate the backup zip file * */ function backup() { global $INDEX_DIRECTORY, $GEDCOMS, $GEDCOM; global $MEDIA_DIRECTORY, $USE_MEDIA_FIREWALL, $MEDIA_FIREWALL_ROOTDIR; $this->flist = array(); // Backup user information if (isset($_POST["um_usinfo"])) { // If in pure DB mode, we must first create new .dat files and authenticate.php // First delete the old files if (file_exists($INDEX_DIRECTORY . "authenticate.php")) { unlink($INDEX_DIRECTORY . "authenticate.php"); } if (file_exists($INDEX_DIRECTORY . "news.dat")) { unlink($INDEX_DIRECTORY . "news.dat"); } if (file_exists($INDEX_DIRECTORY . "messages.dat")) { unlink($INDEX_DIRECTORY . "messages.dat"); } if (file_exists($INDEX_DIRECTORY . "blocks.dat")) { unlink($INDEX_DIRECTORY . "blocks.dat"); } if (file_exists($INDEX_DIRECTORY . "favorites.dat")) { unlink($INDEX_DIRECTORY . "favorites.dat"); } // Then make the new ones um_export($this->proceed); // Make filelist for files to ZIP if (file_exists($INDEX_DIRECTORY . "authenticate.php")) { $this->flist[] = $INDEX_DIRECTORY . "authenticate.php"; } if (file_exists($INDEX_DIRECTORY . "news.dat")) { $this->flist[] = $INDEX_DIRECTORY . "news.dat"; } if (file_exists($INDEX_DIRECTORY . "messages.dat")) { $this->flist[] = $INDEX_DIRECTORY . "messages.dat"; } if (file_exists($INDEX_DIRECTORY . "blocks.dat")) { $this->flist[] = $INDEX_DIRECTORY . "blocks.dat"; } if (file_exists($INDEX_DIRECTORY . "favorites.dat")) { $this->flist[] = $INDEX_DIRECTORY . "favorites.dat"; } } // Backup config.php if (isset($_POST["um_config"])) { $this->flist[] = "config.php"; } // Backup gedcoms and media if (isset($_POST["um_gedcoms"]) || isset($_POST["um_media"])) { $exportOptions = array(); $exportOptions['privatize'] = 'none'; $exportOptions['toANSI'] = 'no'; $exportOptions['noCustomTags'] = 'no'; $exportOptions['slashes'] = 'forward'; foreach ($GEDCOMS as $key => $gedcom) { //-- load the gedcom configuration settings require get_config_file($key); if (isset($_POST["um_gedcoms"])) { //-- backup the original gedcom file if (file_exists($gedcom["path"])) { $this->flist[] = $gedcom["path"]; } //-- recreate the GEDCOM file from the DB //-- backup the DB in case of GEDCOM corruption $gedname = $INDEX_DIRECTORY . $key . ".bak"; $gedout = fopen(filename_decode($gedname), "wb"); $exportOptions['path'] = $MEDIA_DIRECTORY; export_gedcom($key, $gedout, $exportOptions); fclose($gedout); $this->flist[] = $gedname; } if (isset($_POST["um_media"])) { // backup media files $dir = dir($MEDIA_DIRECTORY); while (false !== ($entry = $dir->read())) { if ($entry[0] != ".") { if ($entry != "thumbs") { $this->flist[] = $MEDIA_DIRECTORY . $entry; } } } if ($USE_MEDIA_FIREWALL) { $dir = dir($MEDIA_FIREWALL_ROOTDIR . $MEDIA_DIRECTORY); while (false !== ($entry = $dir->read())) { if ($entry[0] != ".") { if ($entry != "thumbs" && $entry != "watermark") { $this->flist[] = $MEDIA_FIREWALL_ROOTDIR . $MEDIA_DIRECTORY . $entry; } } } } } } //-- restore the old configuration file require get_config_file($GEDCOM); $this->flist[] = $INDEX_DIRECTORY . "pgv_changes.php"; } // Backup gedcom settings if (isset($_POST["um_gedsets"])) { // Gedcoms file if (file_exists($INDEX_DIRECTORY . "gedcoms.php")) { $this->flist[] = $INDEX_DIRECTORY . "gedcoms.php"; } foreach ($GEDCOMS as $key => $gedcom) { // Config files if (file_exists($INDEX_DIRECTORY . $gedcom["gedcom"] . "_conf.php")) { $this->flist[] = $INDEX_DIRECTORY . $gedcom["gedcom"] . "_conf.php"; } // Privacy files if (file_exists($INDEX_DIRECTORY . $gedcom["gedcom"] . "_priv.php")) { $this->flist[] = $INDEX_DIRECTORY . $gedcom["gedcom"] . "_priv.php"; } } } // Backup logfiles and counters if (isset($_POST["um_logs"])) { foreach ($GEDCOMS as $key => $gedcom) { // Gedcom counters if (file_exists($INDEX_DIRECTORY . $gedcom["gedcom"] . "pgv_counters.php")) { $this->flist[] = $INDEX_DIRECTORY . $gedcom["gedcom"] . "pgv_counters.php"; } // Gedcom searchlogs and changelogs $dir_var = opendir($INDEX_DIRECTORY); while ($file = readdir($dir_var)) { if (strpos($file, ".log") > 0 && (strstr($file, "srch-" . $gedcom["gedcom"]) !== false || strstr($file, "ged-" . $gedcom["gedcom"]) !== false)) { $this->flist[] = $INDEX_DIRECTORY . $file; } } closedir($dir_var); } // PhpGedView logfiles $dir_var = opendir($INDEX_DIRECTORY); while ($file = readdir($dir_var)) { if (strpos($file, ".log") > 0 && strstr($file, "pgv-") !== false) { $this->flist[] = $INDEX_DIRECTORY . $file; } } closedir($dir_var); } // Make the zip if (count($this->flist) > 0) { require_once "includes/pclzip.lib.php"; $this->buname = date("YmdHis") . ".zip"; $this->fname = $INDEX_DIRECTORY . $this->buname; $comment = "Created by " . PGV_PHPGEDVIEW . " " . PGV_VERSION_TEXT . " on " . date("r") . "."; $archive = new PclZip($this->fname); //-- remove ../ from file paths when creating zip $ct = preg_match("~((\\.\\./)+)~", $INDEX_DIRECTORY, $match); $rmpath = ""; if ($ct > 0) { $rmpath = $match[1]; } $this->v_list = $archive->create($this->flist, PCLZIP_OPT_COMMENT, $comment, PCLZIP_OPT_REMOVE_PATH, $rmpath); if ($this->v_list == 0) { $this->errorMsg = "Error : " . $archive->errorInfo(true); } if (isset($_POST["um_usinfo"])) { // Remove temporary files again if (file_exists($INDEX_DIRECTORY . "authenticate.php")) { unlink($INDEX_DIRECTORY . "authenticate.php"); } if (file_exists($INDEX_DIRECTORY . "news.dat")) { unlink($INDEX_DIRECTORY . "news.dat"); } if (file_exists($INDEX_DIRECTORY . "messages.dat")) { unlink($INDEX_DIRECTORY . "messages.dat"); } if (file_exists($INDEX_DIRECTORY . "blocks.dat")) { unlink($INDEX_DIRECTORY . "blocks.dat"); } if (file_exists($INDEX_DIRECTORY . "favorites.dat")) { unlink($INDEX_DIRECTORY . "favorites.dat"); } } } }
if ($removeTempDir) { rmdir(filename_decode($temppath)); } header("Location: " . encode_url("downloadbackup.php?fname={$zipname}", false)); exit; } exit; } if ($action == "download") { header("Content-Type: text/plain; charset={$CHARACTER_SET}"); // We could open "php://compress.zlib" to create a .gz file or "php://compress.bzip2" to create a .bz2 file $gedout = fopen('php://output', 'w'); switch ($filetype) { case 'gedcom': header('Content-Disposition: attachment; filename="' . $ged . '"'); export_gedcom($GEDCOM, $gedout, $exportOptions); break; case 'gramps': header('Content-Disposition: attachment; filename="' . $ged . '.gramps"'); export_gramps($GEDCOM, $gedout, $exportOptions); break; } fclose($gedout); exit; } print_header($pgv_lang["download_gedcom"]); ?> <div class="center"><h2><?php print $pgv_lang["download_gedcom"]; ?> </h2></div>
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); WT_File::delete($temp_dir); } } else { Zend_Session::writeClose(); 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'); export_gedcom(WT_GEDCOM, $stream, $exportOptions); fclose($stream); } exit; } $controller->pageHeader(); ?> <h2><?php echo $controller->getPageTitle(); ?> - <?php echo WT_Filter::escapeHtml(WT_GEDCOM); ?> </h2> <form name="convertform" method="get"> <input type="hidden" name="action" value="download">