$oldThumFile = get_media_firewall_path($oldThumFile); $newThumFile = get_media_firewall_path($newThumFile); } $isMain = file_exists(filename_decode($oldMainFile)); $okMain = !file_exists(filename_decode($newMainFile)); $isThum = file_exists(filename_decode($oldThumFile)); $okThum = !file_exists(filename_decode($newThumFile)); if ($okMain && $okThum) { // make sure the directories exist before moving the files mkdirs(dirname($newMainFile) . "/"); mkdirs(dirname($newThumFile) . "/"); if ($isMain) { $okMain = @rename(filename_decode($oldMainFile), filename_decode($newMainFile)); } if ($isThum) { $okThum = @rename(filename_decode($oldThumFile), filename_decode($newThumFile)); } } // Build text to tell Admin about the success or failure of the requested operation $GLOBALS["oldMediaName"] = $oldFilename; $GLOBALS["newMediaName"] = $filename; $GLOBALS["oldMediaFolder"] = $oldFolder; $GLOBALS["newMediaFolder"] = $folder; $GLOBALS["oldThumbFolder"] = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY . "thumbs/", $oldFolder); $GLOBALS["newThumbFolder"] = str_replace($MEDIA_DIRECTORY, $MEDIA_DIRECTORY . "thumbs/", $folder); $mediaAction = 0; if ($filename != $oldFilename) { $mediaAction = 1; } if ($folder != $oldFolder) { $mediaAction = $mediaAction + 2;
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>'; } echo '</ul>'; } echo '<p><a href="javascript: ', $pgv_lang['close_window'], '" onclick="window.close();">', $pgv_lang['close_window'], '</a></p>'; print_simple_footer();
export_gedcom($GEDCOM, $gedout, $exportOptions); break; case 'gramps': export_gramps($GEDCOM, $gedout, $exportOptions); break; } fclose($gedout); $comment = "Created by " . PGV_PHPGEDVIEW . " " . PGV_VERSION_TEXT . " on " . date("r") . "."; $archive = new PclZip(filename_decode($zipfile)); $v_list = $archive->create(filename_decode($gedname), PCLZIP_OPT_COMMENT, $comment, PCLZIP_OPT_REMOVE_PATH, filename_decode($temppath)); if ($v_list == 0) { print "Error : " . $archive->errorInfo(true); } else { unlink(filename_decode($gedname)); 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;
} if ($isvalid) { if ($media["EXISTS"] && media_filesize($media["FILE"]) != 0) { $imgsize = findImageSize($media["FILE"]); $imgwidth = $imgsize[0] + 40; $imgheight = $imgsize[1] + 150; } else { $imgwidth = 0; $imgheight = 0; } echo "<tr>"; //-- thumbnail field if ($showthumb) { echo "<td class=\"list_value {$TEXT_DIRECTION} width10\">"; if (isset($media["THUMB"])) { echo "<a href=\"javascript:;\" onclick=\"return openImage('", rawurlencode($media["FILE"]), "', {$imgwidth}, {$imgheight});\"><img src=\"", filename_decode($media["THUMB"]), "\" border=\"0\" width=\"50\" alt=\"\" /></a>"; } else { echo " "; } } //-- name and size field echo "<td class=\"list_value {$TEXT_DIRECTION}\">"; if ($media["TITL"] != "") { echo "<b>", PrintReady($media["TITL"]), "</b> "; if ($TEXT_DIRECTION == "rtl") { echo getRLM(); } echo "(", $media["XREF"], ")"; if ($TEXT_DIRECTION == "rtl") { echo getRLM(); }
/** * 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"); } } } }
static function includeFile($params = null) { if (!isset($_GET['ctype']) || $_GET['ctype'] != 'gedcom') { return ''; } if ($params === null) { $params = array(); } if (isset($params[0]) && $params[0] != '') { $fn = $params[0]; } else { return ''; } if (!file_exists($fn) || stristr($fn, 'config.php')) { return ''; } ob_start(); include filename_decode(real_path($fn)); return trim(ob_get_clean()); }