From 7302462b28f81419951548de8a64ebead821a3cf Mon Sep 17 00:00:00 2001 From: fisharebest Date: Sat, 24 Apr 2010 16:14:58 +0000 Subject: Remove gedcom upload/creation code from gedcom config editor --- editconfig_gedcom.php | 371 ++++++-------------------------------------------- 1 file changed, 39 insertions(+), 332 deletions(-) (limited to 'editconfig_gedcom.php') diff --git a/editconfig_gedcom.php b/editconfig_gedcom.php index 0d8ac0d7fd..5e07a09034 100644 --- a/editconfig_gedcom.php +++ b/editconfig_gedcom.php @@ -34,21 +34,11 @@ define('WT_SCRIPT_NAME', 'editconfig_gedcom.php'); require './includes/session.php'; require WT_ROOT.'includes/functions/functions_edit.php'; -// editconfig.php and uploadgedcom.php make extensive use of -// import_request_variables and are heavily inter-dependent. -@import_request_variables('cgp'); - -if (isset($_REQUEST['action'])) $action = $_REQUEST['action']; -if (empty($action)) $action = ""; -if (isset($_REQUEST['source'])) $source = $_REQUEST['source']; -if (empty($source)) $source=""; // Set when loaded from uploadgedcom.php if (!WT_USER_GEDCOM_ADMIN) { header("Location: editgedcoms.php"); exit; } - global $whichFile; // This is needed for error messages - /** * find the name of the first GEDCOM file in a zipfile * @param string $zipfile the path and filename @@ -91,178 +81,19 @@ function GetGEDFromZIP($zipfile, $extract=true) { return $zipfile; } -if (isset($_REQUEST['path'])) $path = $_REQUEST['path']; -if (isset($_REQUEST['oldged'])) $oldged = $_REQUEST['oldged']; -if (isset($_REQUEST['GEDFILENAME'])) $GEDFILENAME = $_REQUEST['GEDFILENAME']; -if (isset($_REQUEST['GEDCOMPATH'])) $GEDCOMPATH = $_REQUEST['GEDCOMPATH']; -if (isset($_REQUEST['ged'])) $ged = $_REQUEST['ged']; -if (isset($_REQUEST['gedcom_title'])) $gedcom_title = $_REQUEST['gedcom_title']; -if (isset($_REQUEST['THEME_DIR'])) $THEME_DIR = $_REQUEST['THEME_DIR']; - -if (empty($oldged)) $oldged = ""; -else $ged = $oldged; -if (!isset($path)) $path = ""; -if (!isset($GEDFILENAME)) $GEDFILENAME = ""; - -if (isset($GEDCOMPATH)) { - $ctupload = count($_FILES); - if ($ctupload > 0) { - // NOTE: Extract the GEDCOM filename - if (!empty($path)) { - $GEDFILENAME = basename($path); - } else { - $GEDFILENAME = $_FILES['GEDCOMPATH']['name']; - } - if ($path=="" || dirname($path) == ".") { - $upload_path = $INDEX_DIRECTORY; - } else { - $upload_path = dirname($path)."/"; - } - if (empty($GEDFILENAME)) { - $GEDFILENAME = $_FILES['GEDCOMPATH']['name']; - } - - //-- remove any funny characters from uploaded files - $GEDFILENAME = preg_replace('/[\+\&\%\$@]/', "_", $GEDFILENAME); - - // NOTE: When uploading a file check if it doesn't exist yet - if ($action=="replace" || !in_array($GEDFILENAME, get_all_gedcoms()) && !file_exists($upload_path.$GEDFILENAME)) { - if (move_uploaded_file($_FILES['GEDCOMPATH']['tmp_name'], $upload_path.$GEDFILENAME)) { - AddToLog("Gedcom ".$path.$GEDFILENAME." uploaded", 'config'); - $GEDCOMPATH = $upload_path.$GEDFILENAME; - } else { - $error = i18n::translate('There was an error uploading your file.')."
".file_upload_error_text($_FILES['GEDCOMPATH']['error']); - $action = "upload_form"; - } - } else { - // NOTE: If the file exists we will make a backup file - if (move_uploaded_file($_FILES['GEDCOMPATH']['tmp_name'], $upload_path.$GEDFILENAME.".bak")) { - $bakfile = $upload_path.$GEDFILENAME.".bak"; - $GEDCOMPATH = $upload_path.$GEDFILENAME; - } else { - $error = i18n::translate('There was an error uploading your file.')."
".file_upload_error_text($_FILES['GEDCOMPATH']['error']); - $action = "upload_form"; - } - } - } - //-- check if there was an error during the upload - if (empty($error)) { - // NOTE: Extract the GEDCOM filename - if (!empty($path)) { - $GEDFILENAME = basename($path); - } else { - $GEDFILENAME = basename($GEDCOMPATH); - } - // NOTE: Check if the input contains a valid path otherwise check if there is one in the GEDCOMPATH - if (!is_dir($path)) { - if (!empty($path)) { - $parts = preg_split("/[\/\\\]/", $path); - } else { - $parts = preg_split("/[\/\\\]/", $GEDCOMPATH); - } - $path = ""; - $ctparts = count($parts)-1; - if (count($parts) == 1) { - $path = $INDEX_DIRECTORY; - } else { - foreach ($parts as $key => $pathpart) { - if ($key < $ctparts) $path .= $pathpart."/"; - } - } - } - // NOTE: Check if it is a zipfile - if (strstr(strtolower(trim($GEDFILENAME)), ".zip")==".zip") { - $GEDFILENAME = GetGEDFromZIP($path.$GEDFILENAME); - } - $ged = $GEDFILENAME; +$gedcom_config = $INDEX_DIRECTORY.WT_GEDCOM."_conf.php"; +$gedcom_privacy = $INDEX_DIRECTORY.WT_GEDCOM."_priv.php"; + +if (empty($gedcom_title)) { + if (!empty($_POST["gedcom_title"])) { + $gedcom_title=$_POST["gedcom_title"]; } else { - $action = ""; + $gedcom_title=i18n::translate('Genealogy from [%s]', WT_GEDCOM); } } -if (isset($ged)) { - $ged_id=get_id_from_gedcom($ged); - if ($ged_id) { - $GEDCOMPATH = get_gedcom_setting($ged_id, 'path'); - if (empty($path)) { - $path = ""; - $parts = preg_split("/[\/\\\]/", $GEDCOMPATH); - $ctparts = count($parts)-1; - if (count($parts) == 1) { - $path = $INDEX_DIRECTORY; - } else { - foreach ($parts as $key => $pathpart) { - if ($key < $ctparts) $path .= $pathpart."/"; - } - } - } - $GEDFILENAME = $ged; - if (!isset($gedcom_title)) { - $gedcom_title = get_gedcom_setting($ged_id, 'title'); - } - $gedcom_config = get_config_file($ged_id); - $gedcom_privacy = get_privacy_file($ged_id); - $FILE = $ged; - $oldged = $ged; - } else { - if (empty($_POST["GEDCOMPATH"])) { - $GEDCOMPATH = ""; - $gedcom_title = ""; - } - $gedcom_config = "config_gedcom.php"; - $gedcom_privacy = "privacy.php"; - } -} else { - $GEDCOMPATH = ""; - $gedcom_title = ""; - $gedcom_config = "config_gedcom.php"; - $gedcom_privacy = "privacy.php"; - $path = ""; - $GEDFILENAME = ""; -} -$USERLANG = $LANGUAGE; -$temp = $THEME_DIR; -require $gedcom_config; -if (!isset($_POST["GEDCOMLANG"])) { - $GEDCOMLANG = $LANGUAGE; -} else { - $GEDCOMLANG = $_POST["GEDCOMLANG"]; -} -$LANGUAGE = $USERLANG; -$error_msg = ""; - -if (!file_exists($path.$GEDFILENAME) && $source != "add_new_form") { - $action="add"; -} -if ($action=="update") { - $errors = false; - $FILE=$GEDFILENAME; - $newgedcom=false; - $gedcom_config="config_gedcom.php"; - if (copy($gedcom_config, $INDEX_DIRECTORY.$FILE."_conf.php")) { - $gedcom_config = "\${INDEX_DIRECTORY}".$FILE."_conf.php"; - } - if (!file_exists($INDEX_DIRECTORY.$FILE."_priv.php")) { - if (copy($gedcom_privacy, $INDEX_DIRECTORY.$FILE."_priv.php")) { - $gedcom_privacy = "\${INDEX_DIRECTORY}".$FILE."_priv.php"; - } - } else { - $gedcom_privacy = "\${INDEX_DIRECTORY}".$FILE."_priv.php"; - } - - if (empty($gedcom_title)) { - if (!empty($_POST["gedcom_title"])) { - $gedcom_title=$_POST["gedcom_title"]; - } else { - $gedcom_title=i18n::translate('Genealogy from [%s]', $FILE); - } - } - // Create the gedcom if it doesn't already exist - $ged_id=get_id_from_gedcom($FILE, true); - set_gedcom_setting($ged_id, 'config', $gedcom_config); - set_gedcom_setting($ged_id, 'privacy', $gedcom_privacy); - set_gedcom_setting($ged_id, 'title', $gedcom_title); - set_gedcom_setting($ged_id, 'path', $path.$GEDFILENAME); +if (safe_POST('action')=='update') { + $errors = false; // Check that add/remove common surnames are separated by [,;] blank $_POST["NEW_COMMON_NAMES_REMOVE"] = preg_replace("/[,;]\b/", ", ", $_POST["NEW_COMMON_NAMES_REMOVE"]); @@ -276,7 +107,7 @@ if ($action=="update") { $boolarray["no"]="false"; $boolarray[false]="false"; $boolarray[true]="true"; - $configtext = implode('', file("config_gedcom.php")); + $configtext = file_get_contents($gedcom_config); $_POST["NEW_MEDIA_DIRECTORY"] = preg_replace('/\\\/', '/', $_POST["NEW_MEDIA_DIRECTORY"]); $ct = preg_match("'/$'", $_POST["NEW_MEDIA_DIRECTORY"]); @@ -431,7 +262,7 @@ if ($action=="update") { // create the media directory // if NEW_MEDIA_FIREWALL_ROOTDIR is the INDEX_DIRECTORY, PGV will have perms to create it // if PGV is unable to create the directory, tell the user to create it - if (($NEW_USE_MEDIA_FIREWALL=='yes') || $USE_MEDIA_FIREWALL) { + if (($_POST["NEW_USE_MEDIA_FIREWALL"]=='yes') || $USE_MEDIA_FIREWALL) { if (!is_dir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY)) { @mkdir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY, WT_PERM_EXE); if (!is_dir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY)) { @@ -443,7 +274,7 @@ if ($action=="update") { } if (!$errors) { // create the thumbs dir to make sure we have write perms - if (($NEW_USE_MEDIA_FIREWALL=='yes') || $USE_MEDIA_FIREWALL) { + if (($_POST["NEW_USE_MEDIA_FIREWALL"]=='yes') || $USE_MEDIA_FIREWALL) { if (!is_dir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY."thumbs")) { @mkdir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY."thumbs", WT_PERM_EXE); if (!is_dir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY."thumbs")) { @@ -455,7 +286,7 @@ if ($action=="update") { } if (!$errors) { // copy the .htaccess file from INDEX_DIRECTORY to NEW_MEDIA_FIREWALL_ROOTDIR in case it is still in a web-accessible area - if (($NEW_USE_MEDIA_FIREWALL=='yes') || $USE_MEDIA_FIREWALL) { + if (($_POST["NEW_USE_MEDIA_FIREWALL"]=='yes') || $USE_MEDIA_FIREWALL) { if ( (file_exists($INDEX_DIRECTORY.".htaccess")) && (is_dir($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY)) && (!file_exists($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY.".htaccess")) ) { @copy($INDEX_DIRECTORY.".htaccess", $NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY.".htaccess"); if (!file_exists($NEW_MEDIA_FIREWALL_ROOTDIR.$MEDIA_DIRECTORY.".htaccess")) { @@ -468,28 +299,9 @@ if ($action=="update") { if (!$errors) { $configtext = preg_replace('/\$MEDIA_FIREWALL_ROOTDIR\s*=\s*".*";/', "\$MEDIA_FIREWALL_ROOTDIR = \"".$_POST["NEW_MEDIA_FIREWALL_ROOTDIR"]."\";", $configtext); } - if (file_exists($NTHEME_DIR)) - $configtext = preg_replace('/\$THEME_DIR\s*=\s*".*";/', "\$THEME_DIR = \"".$_POST["NTHEME_DIR"]."\";", $configtext); - else { - $errors = true; - } - $whichFile = $INDEX_DIRECTORY.$FILE."_conf.php"; - if (!is_writable($whichFile)) { - $errors = true; - $error_msg .= "".i18n::translate('E R R O R !!!
Could not write to file %s. Please check it for proper Write permissions.', $whichFile)."

"; - } - $fp = @fopen($whichFile, "wb"); - if (!$fp) { - $errors = true; - $error_msg .= "".i18n::translate('E R R O R !!!
Could not write to file %s. Please check it for proper Write permissions.', $whichFile)."

\n"; - } - else { - fwrite($fp, $configtext); - fclose($fp); - } - + file_put_contents($gedcom_config, $configtext); - if (($NEW_USE_MEDIA_FIREWALL=='yes') && !$USE_MEDIA_FIREWALL) { + if (($_POST["NEW_USE_MEDIA_FIREWALL"]=='yes') && !$USE_MEDIA_FIREWALL) { AddToLog("Media Firewall enabled", 'config'); if (!$errors) { @@ -527,7 +339,7 @@ if ($action=="update") { } } - } elseif (($NEW_USE_MEDIA_FIREWALL=='no') && $USE_MEDIA_FIREWALL) { + } elseif (($_POST["NEW_USE_MEDIA_FIREWALL"]=='no') && $USE_MEDIA_FIREWALL) { AddToLog("Media Firewall disabled", 'config'); if (file_exists($MEDIA_DIRECTORY.".htaccess")) { @@ -556,67 +368,36 @@ if ($action=="update") { unlink ($INDEX_DIRECTORY.$FILE."_upcoming.php"); } } - foreach ($_POST as $key=>$value) { - if ($key != "path") { - $key=str_replace("NEW_", "", $key); - if ($value=='yes') { - $$key=true; - } elseif ($value=='no') { - $$key=false; - } else { - $$key=$value; - } - } - } //-- delete the cache files for the Home Page blocks require_once WT_ROOT.'includes/index_cache.php'; clearCache(); - $logline = AddToLog("Gedcom configuration ".$INDEX_DIRECTORY.$FILE."_conf.php"." updated", 'config'); - $gedcomconfname = $FILE."_conf.php"; + $logline = AddToLog("Gedcom configuration ".$INDEX_DIRECTORY.WT_GEDCOM."_conf.php"." updated", 'config'); + $gedcomconfname = WT_GEDCOM."_conf.php"; if (!$errors) { - $gednews = getUserNews($FILE); + $gednews = getUserNews(WT_GEDCOM); if (count($gednews)==0) { $news = array(); $news["title"] = i18n::translate('Welcome to Your Genealogy'); - $news["username"] = $FILE; + $news["username"] = WT_GEDCOM; $news["text"] = i18n::translate('The genealogy information on this website is powered by webtrees. This page provides an introduction and overview to this genealogy.

To begin working with the data, choose one of the charts from the Charts menu, go to the Individual list, or search for a name or place.

If you have trouble using the site, you can click on the Help icon to give you information on how to use the page that you are currently viewing.

Thank you for visiting this site.'); $news["date"] = client_time(); addNews($news); } - if ($source == "upload_form") { - $check = "upload"; - } elseif ($source == "add_form") { - $check = "add"; - } elseif ($source == "add_new_form") { - $check = "add_new"; - } - if (!isset($bakfile)) { - $bakfile = ""; - } - if ($source !== "") { - header("Location: ".encode_url("uploadgedcom.php?action=$source&check=$check&step=2&GEDFILENAME={$GEDFILENAME}&path={$path}&verify=verify_gedcom&bakfile={$bakfile}", false)); - } else { - header("Location: editgedcoms.php"); - } + header("Location: editgedcoms.php"); exit; } } -else if ($action=="replace") { - header("Location: ".encode_url("uploadgedcom.php?action=upload_form&GEDFILENAME={$GEDFILENAME}&path={$path}&verify=validate_form", false)); -} + +require $gedcom_config; //-- output starts here print_header(i18n::translate('GEDCOM Configuration')); -if ($ENABLE_AUTOCOMPLETE && $source=='') require WT_ROOT.'js/autocomplete.js.htm'; +if ($ENABLE_AUTOCOMPLETE) require WT_ROOT.'js/autocomplete.js.htm'; if (!isset($GENERATE_UIDS)) $GENERATE_UIDS = false; -$temp2 = $THEME_DIR; -$THEME_DIR = $temp; -$THEME_DIR = $temp2; -if (!isset($NTHEME_DIR)) $NTHEME_DIR=$THEME_DIR; if (!isset($themeselect)) $themeselect=""; if (!empty($error)) print "".$error.""; ?> @@ -643,24 +424,13 @@ if (!empty($error)) print "".$error.""; ", i18n::translate('GEDCOM Configuration'), " - "; - if (WT_GED_ID) { - echo PrintReady(get_gedcom_setting(WT_GED_ID, 'title')); - } elseif ($source == "add_form") { - echo i18n::translate('Add GEDCOM'); - } elseif ($source == "upload_form") { - echo i18n::translate('Upload GEDCOM'); - } elseif ($source == "add_new_form") { - echo i18n::translate('Create a new GEDCOM'); - } elseif ($source == "replace_form") { - echo i18n::translate('Upload Replacement'); - } + echo PrintReady(get_gedcom_setting(WT_GED_ID, 'title')); echo ""; echo ""; echo i18n::translate('Return to the GEDCOM management menu'); echo "

"; ?> -