/** * Do what the user said to do. */ function run_user_action() { global $wpdb; if (!empty($_POST['delete_data'])) { clean_out_dictionary_data(); } if (!empty($_POST['save_settings'])) { update_option("publicationStatus", $_POST['publicationStatus']); update_option("include_partial_words", $_POST['include_partial_words']); $displaySubentriesAsMainEntries = 'no'; if (isset($_POST['DisplaySubentriesAsMainEntries'])) { $displaySubentriesAsMainEntries = 1; } update_option("DisplaySubentriesAsMainEntries", $displaySubentriesAsMainEntries); update_option("languagecode", $_POST['languagecode']); update_option("vernacular_alphabet", $_POST['vernacular_alphabet']); $IncludeCharactersWithDiacritics = 'no'; if (isset($_POST['IncludeCharactersWithDiacritics'])) { $IncludeCharactersWithDiacritics = 1; } update_option("IncludeCharactersWithDiacritics", $IncludeCharactersWithDiacritics); update_option("reversal1_langcode", $_POST['reversal1_langcode']); update_option("reversal1_alphabet", $_POST['reversal1_alphabet']); update_option("reversal2_alphabet", $_POST['reversal2_alphabet']); update_option("reversal2_langcode", $_POST['reversal2_langcode']); if (trim(strlen($_POST['txtVernacularName'])) == 0) { echo "<br><span style=\"color:red\">Please fill out the textfields for the language names, as they will appear in a dropdown below the searcbhox.</span><br>"; } $arrLanguages[0]['name'] = "txtVernacularName"; $arrLanguages[0]['code'] = "languagecode"; $arrLanguages[1]['name'] = "txtReversalName"; $arrLanguages[1]['code'] = "reversal_langcode"; $arrLanguages[2]['name'] = "txtReversal2Name"; $arrLanguages[2]['code'] = "reversal2_langcode"; foreach ($arrLanguages as $language) { if (strlen(trim($_POST[$language['code']])) != 0) { $sql = "INSERT INTO {$wpdb->terms} (name,slug) VALUES ('" . $_POST[$language['name']] . "','" . $_POST[$language['code']] . "')\n\t\t \t\tON DUPLICATE KEY UPDATE name = '" . $_POST[$language['name']] . "'"; $wpdb->query($sql); $lastid = $wpdb->insert_id; if ($lastid != 0) { $sql = "INSERT INTO {$wpdb->term_taxonomy} (term_id, taxonomy,description,count) VALUES (" . $lastid . ", 'sil_writing_systems', '" . $_POST[$language['name']] . "',999999)\n\t\t\t \t\tON DUPLICATE KEY UPDATE description = '" . $_POST[$language['name']] . "'"; $wpdb->query($sql); } } } echo "<br>" . _e('Settings saved'); } }
public function import($_headers) { $authenticated = $this->verifyAdminPrivileges($email); if ($authenticated) { $arrDirectory = wp_upload_dir(); $uploadPath = $arrDirectory['path']; $destinationPath = $uploadPath . "/" . str_replace(".zip", "", $_FILES['file']['name']); $unzipped = $this->unzip($_FILES['file'], $uploadPath, $destinationPath); //program can be closed now, the import will run in the background flush(); if ($unzipped) { $fileConfigured = $destinationPath . "/configured.xhtml"; $xhtmlConfigured = file_get_contents($fileConfigured); $fileReversal1 = $destinationPath . "/reversal1.xhtml"; $xhtmlReversal1 = file_get_contents($fileReversal1); $fileReversal2 = $destinationPath . "/reversal2.xhtml"; $xhtmlReversal2 = file_get_contents($fileReversal2); //moving style sheet file if (file_exists($destinationPath . "/configured.css")) { copy($destinationPath . "/configured.css", $uploadPath . "/imported-with-xhtml.css"); error_log("Renamed configured.css to " . $uploadPath . "/imported-with-xhtml.css"); unlink($destinationPath . "/configured.css"); } //copy folder files (which includes audio and image folders and files) if (file_exists($destinationPath . "/files")) { //first delete any existing files $this->recursiveRemoveDir($uploadPath . "/images/thumbnail"); $this->recursiveRemoveDir($uploadPath . "/images/original"); $this->recursiveRemoveDir($uploadPath . "/audio"); //then copy everything under files $this->recursiveCopy($destinationPath . "/files", $uploadPath); $this->recursiveRemoveDir($destinationPath . "/files"); } } if (isset($xhtmlConfigured)) { //we first delete all existing posts (in category Webonary) remove_entries('flexlinks'); //deletes data that comes with the posts, but gets stored separately (e.g. "parts of speech") clean_out_dictionary_data(); $filetype = "configured"; $xhtmlFileURL = $fileConfigured; require "run_import.php"; } if (isset($xhtmlReversal1)) { $filetype = "reversal"; $xhtmlFileURL = $fileReversal1; require "run_import.php"; } if (isset($xhtmlReversal2)) { $filetype = "reversal"; $xhtmlFileURL = $fileReversal2; require "run_import.php"; } if (file_exists($destinationPath)) { //deletes the extracted zip folder //update 21 April 2015: We no longer remove the directory, instead just the individual files //get deleted as we are now running the import in an external process and the files would otherwise be missing //$this->recursiveRemoveDir($destinationPath); } $message = "The export to Webonary is completed.\n"; $message .= "Go here to configure more settings: " . get_site_url() . "/wp-admin/admin.php?page=webonary"; wp_mail($email, 'Webonary Export complete', $message); return "import completed"; } else { echo "authentication failed\n"; flush(); } return; }