function import()
 {
     if (!current_user_can('import')) {
         echo '<p><strong>' . __('You do not have permission to do that.', 'wc2') . '</strong></p><br />';
         return false;
     }
     list($fname, $fext) = explode('.', $_FILES["import"]["name"], 2);
     if ($fext != 'csv') {
         echo '<p><strong>' . __('The file is not supported.', 'wc2') . $fname . '.' . $fext . '</strong></p><br />';
         return false;
     }
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wc2') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'wc2') . '</strong><br />';
             printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wc2'), esc_html($file['file']));
             echo '</p>';
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $this->file = get_attached_file($this->id);
     $result = $this->process_posts();
     return $result;
 }
 private function import()
 {
     check_admin_referer('import-upload');
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'appthemes') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     }
     $c = $this->process($file['file']);
     if (false === $c) {
         echo scb_admin_notice(__('The file could not be processed.', 'appthemes'), 'error');
     } else {
         echo scb_admin_notice(sprintf(__('Imported %s items.', 'appthemes'), number_format_i18n($c)));
     }
 }
 function import()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'really-simple-csv-importer') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'really-simple-csv-importer') . '</strong><br />';
             printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'really-simple-csv-importer'), esc_html($file['file']));
             echo '</p>';
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $this->file = get_attached_file($this->id);
     $result = $this->process_posts();
     if (is_wp_error($result)) {
         return $result;
     }
 }
 /**
  * The form of the second step.
  *
  * @param  none
  * @return none
  */
 private function step2()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         return new WP_Error('Error', esc_html($file['error']));
     } else {
         if (!file_exists($file['file'])) {
             return new WP_Error('Error', sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer'), esc_html($file['file'])));
         }
     }
     $csv_file = get_attached_file($file['id']);
     $post_objects = Main::get_post_objects($csv_file);
     if (is_wp_error($post_objects)) {
         echo '<p><strong>' . __('Failed to open file.', 'advanced-csv-importer') . '</strong></p>';
         wp_import_cleanup($file['id']);
         return $post_objects;
     } else {
         $inserted_posts = Main::insert_posts($post_objects);
         wp_import_cleanup($file['id']);
         return $inserted_posts;
     }
 }
 private function handle_upload()
 {
     $file = wp_import_handle_upload();
     $this->result = (object) array('success' => FALSE);
     $this->import_data = NULL;
     if (isset($file['error'])) {
         $this->result->message = esc_html($file['error']);
         return FALSE;
     } else {
         if (!file_exists($file['file'])) {
             $this->result->message = sprintf($this->__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.'), esc_html($file['file']));
             return FALSE;
         }
     }
     $this->file_id = (int) $file['id'];
     $this->parse_contents($file['file']);
     if (is_wp_error($this->import_data)) {
         $this->result->message = $this->import_data->get_error_message();
         $this->import_data = NULL;
         return FALSE;
     }
     $this->result = NULL;
     return TRUE;
 }
	function select_authors() {
		$file = wp_import_handle_upload();
		if ( isset($file['error']) ) {
			$this->header();
			echo '<p>'.__('Sorry, there has been an error').'.</p>';
			echo '<p><strong>' . $file['error'] . '</strong></p>';
			$this->footer();
			return;
		}
		$this->file = $file['file'];
		$this->id = (int) $file['id'];

		$this->get_entries();
		$this->mt_authors_form();
	}
Exemple #7
0
 function select_authors()
 {
     if ($_POST['upload_type'] === 'ftp') {
         $file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
         if (!file_exists($file['file'])) {
             $file['error'] = __('<code>mt-export.txt</code> does not exist');
         }
     } else {
         $file = wp_import_handle_upload();
     }
     if (isset($file['error'])) {
         $this->header();
         echo '<p>' . __('Sorry, there has been an error') . '.</p>';
         echo '<p><strong>' . $file['error'] . '</strong></p>';
         $this->footer();
         return;
     }
     $this->file = $file['file'];
     $this->id = (int) $file['id'];
     $this->mt_authors_form();
 }
Exemple #8
0
 function select_authors()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo $file['error'];
         return;
     }
     $this->file = $file['file'];
     $this->id = $file['id'];
     $this->get_entries();
     $this->mt_authors_form();
 }
 public function csv_importer()
 {
     // Load Importer API
     require_once ABSPATH . 'wp-admin/includes/import.php';
     if (!class_exists('WP_Importer')) {
         $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
         if (file_exists($class_wp_importer)) {
             require_once $class_wp_importer;
         }
     }
     if (empty($_FILES)) {
         //echo '<form method="POST" action="" enctype="multipart/form-data">';
         echo "<p>Use the form below to upload your CSV file for importing.</p>";
         echo "<p><strong>Example CSV Data:</strong></p>";
         echo "<p><code>'Title','Body','Client Name','E-Mail Address','Position / Location / Other','Location / Product / Other','Rating','HTID','Featured Image','Categories'</code></p>";
         echo "<p><strong>Please Note:</strong> the first line of the CSV will need to match the text in the above example, for the Import to work.  Featured Image is expecting a path to an accessible image online.  Depending on your server settings, you may need to run the import several times if your script times out.</p>";
         echo '<div class="gp_upload_file_wrapper">';
         ob_start();
         wp_import_upload_form(add_query_arg('step', 1));
         $import_form_html = ob_get_contents();
         $import_form_html = str_replace('<form ', '<div data-gp-ajax-form="1" ', $import_form_html);
         $import_form_html = str_replace('</form>', '</div>', $import_form_html);
         // must remove this hidden "action" input, or the form will not
         // save proerly (it will keep going to options.php)
         $import_form_html = str_replace('<input type="hidden" name="action" value="save" />', '', $import_form_html);
         ob_end_clean();
         echo $import_form_html;
         echo '</div>';
         //echo '</form>';
     } else {
         $file = wp_import_handle_upload();
         echo '<h4>Log</h4>';
         echo '<textarea rows="20" class="import_response">';
         //if there is an error, output a message containing the error
         if (isset($file['error'])) {
             echo "Sorry, there has been an error.\n";
             echo esc_html($file['error']) . "\n";
             // if the file doesn't exists, output a message about it
         } else {
             if (!file_exists($file['file'])) {
                 echo "Sorry, there has been an error.\n";
                 printf("The export file could not be found at %s. It is likely that this was caused by a permissions problem.\n", esc_html($file['file']));
                 // otherwise, if there is no error and the file exists, go ahead and process the file
             } else {
                 $fileid = (int) $file['id'];
                 $file = get_attached_file($fileid);
                 $this->import_testimonials_from_csv($file);
                 echo "\nTestimonials successfully imported!\n";
             }
         }
         echo '</textarea>';
         //close response
         echo '<p><a class="button-primary button" href="/wp-admin/admin.php?page=easy-testimonials-import-export" title="Import More Testimonials">Import More Testimonials</a></p>';
     }
 }
 /**
  * @uses wp_import_handle_upload()
  * @since 2.0.0
  */
 function handle_file_import()
 {
     if (!isset($_REQUEST['_cpac_nonce']) || !wp_verify_nonce($_REQUEST['_cpac_nonce'], 'file-import') || empty($_FILES['import'])) {
         return false;
     }
     // handles upload
     $file = wp_import_handle_upload();
     // any errors?
     $error = false;
     if (isset($file['error'])) {
         $error = __('Sorry, there has been an error.', 'cpac') . '<br />' . esc_html($file['error']);
     } else {
         if (!file_exists($file['file'])) {
             $error = __('Sorry, there has been an error.', 'cpac') . '<br />' . sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'cpac'), esc_html($file['file']));
         }
     }
     if ($error) {
         cpac_admin_message($error, 'error');
         return false;
     }
     // read file contents and start the import
     $content = file_get_contents($file['file']);
     // cleanup
     wp_delete_attachment($file['id']);
     // decode file contents
     $columns = $this->get_decoded_settings($content);
     if (empty($columns)) {
         cpac_admin_message(__('Import failed. File does not contain Admin Column settings.', 'cpac'), 'error');
         return false;
     }
     // store settings
     foreach ($columns as $type => $settings) {
         $storage_model = $this->cpac->get_storage_model($type);
         if (!$storage_model) {
             cpac_admin_message(sprintf(__('Screen %s does not exist.', 'cpac'), "<strong>{$type}</strong>"), 'error');
             continue;
         }
         $storage_model->store($settings);
     }
 }
 public function csv_importer()
 {
     echo '<form method="POST" action="" enctype="multipart/form-data">';
     // Load Importer API
     require_once ABSPATH . 'wp-admin/includes/import.php';
     if (!class_exists('WP_Importer')) {
         $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
         if (file_exists($class_wp_importer)) {
             require_once $class_wp_importer;
         }
     }
     if (empty($_FILES)) {
         echo "<p>Use the below form to upload your CSV file for importing.</p>";
         echo "<p><strong>Example CSV Data:</strong></p>";
         echo "<p><code>'Title','Body','Client Name','Position / Location / Other','Location / Product / Other','Rating','HTID'</code></p>";
         echo "<p><strong>Please Note:</strong> the first line of the CSV will need to match the text in the above example, for the Import to work.  Depending on your server settings, you may need to run the import several times if your script times out.</p>";
         echo '<div class="gp_upload_file_wrapper">';
         wp_import_upload_form(add_query_arg('step', 1));
         echo '</div>';
     } else {
         $file = wp_import_handle_upload();
         if (isset($file['error'])) {
             echo '<p><strong>' . 'Sorry, there has been an error.' . '</strong><br />';
             echo esc_html($file['error']) . '</p>';
             return false;
         } else {
             if (!file_exists($file['file'])) {
                 echo '<p><strong>' . 'Sorry, there has been an error.' . '</strong><br />';
                 printf('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', esc_html($file['file']));
                 echo '</p>';
                 return false;
             }
         }
         $fileid = (int) $file['id'];
         $file = get_attached_file($fileid);
         $result = $this->import_testimonials_from_csv($file);
         if (is_wp_error($result)) {
             echo $result;
         } else {
             echo "<p>Testimonials successfully imported!</p>";
         }
     }
     echo '</form>';
 }
/**
 * Import names from a csv file into directory
 */
function name_directory_import()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'name-directory'));
    }
    global $wpdb;
    global $table_directory;
    global $table_directory_name;
    $directory_id = intval($_GET['dir']);
    $import_success = false;
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $file = wp_import_handle_upload();
        if (isset($file['error'])) {
            echo $file['error'];
            return;
        }
        $csv = array_map('str_getcsv', file($file['file']));
        wp_import_cleanup($file['id']);
        array_shift($csv);
        $names_imported = 0;
        $names_duplicate = 0;
        foreach ($csv as $entry) {
            if (!($prepared_row = name_directory_prepared_import_row($entry))) {
                continue;
            }
            if (name_directory_name_exists_in_directory($prepared_row['name'], $directory_id)) {
                $names_duplicate++;
                continue;
            }
            $wpdb->insert($table_directory_name, array('directory' => $directory_id, 'name' => stripslashes_deep($prepared_row['name']), 'letter' => name_directory_get_first_char($prepared_row['name']), 'description' => stripslashes_deep($prepared_row['description']), 'published' => $prepared_row['published'], 'submitted_by' => $prepared_row['submitted_by']), array('%d', '%s', '%s', '%s', '%d', '%s'));
            $names_imported++;
        }
        $notice_class = 'updated';
        $import_success = true;
        $import_message = sprintf(__('Imported %d entries in this directory', 'name-directory'), $names_imported);
        if ($names_imported === 0) {
            $notice_class = 'error';
            $import_success = false;
            $import_message = __('Could not import any names into Name Directory', 'name-directory');
        }
        if ($names_duplicate > 0) {
            $ignored = count($csv) == $names_duplicate ? __('all', 'name-directory') : $names_duplicate;
            echo '<div class="error" style="border-left: 4px solid #ffba00;"><p>' . sprintf(__('Ignored %s names, because they were duplicate (already in the directory)', 'name-directory'), $ignored) . '</p></div>';
        } elseif ($names_imported === 0) {
            $import_message .= ', ' . __('please check your .csv-file', 'name-directory');
        }
        echo '<div class="' . $notice_class . '"><p>' . $import_message . '</p></div>';
    }
    $wp_file = admin_url('options-general.php');
    $wp_page = $_GET['page'];
    $wp_sub = $_GET['sub'];
    $overview_url = sprintf("%s?page=%s", $wp_file, $wp_page);
    $wp_url_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, $wp_sub, $directory_id);
    $wp_ndir_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, 'manage-directory', $directory_id);
    $directory = $wpdb->get_row("SELECT * FROM " . $table_directory . " WHERE `id` = " . $directory_id, ARRAY_A);
    echo '<div class="wrap">';
    echo '<h2>' . sprintf(__('Import names for %s', 'name-directory'), $directory['name']) . '</h2>';
    echo '<div class="narrow"><p>';
    if (!$import_success && empty($names_duplicate)) {
        echo __('Use the upload form below to upload a .csv-file containing all of your names (in the first column), description and submitter are optional.', 'name-directory') . ' ';
        echo '<h4>' . __('If you saved it from Excel or OpenOffice, please ensure that:', 'name-directory') . '</h4> ';
        echo '<ol><li>' . __('There is a header row (this contains the column names, the first row will NOT be imported)', 'name-directory');
        echo '</li><li>' . __('Fields are encapsulated by double quotes', 'name-directory');
        echo '</li><li>' . __('Fields are comma-separated', 'name-directory');
        echo '</li></ol>';
        echo '<h4>' . __('If uploading or importing fails, these are your options', 'name-directory') . ':</h4><ol><li>';
        echo sprintf(__('Please check out %s first and ensure your file is formatted the same.', 'name-directory'), '<a href="http://plugins.svn.wordpress.org/name-directory/assets/name-directory-import-example.csv" target="_blank">' . __('the example import file', 'name-directory') . '</a>') . '</li>';
        echo '<li>
                <a href="https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Calc_Guide/Saving_spreadsheets#Saving_as_a_CSV_file">OpenOffice csv-export help</a>
              </li>
              <li>
                <a href="https://support.office.com/en-us/article/Import-or-export-text-txt-or-csv-files-e8ab9ff3-be8d-43f1-9d52-b5e8a008ba5c?CorrelationId=fa46399d-2d7a-40bd-b0a5-27b99e96cf68&ui=en-US&rs=en-US&ad=US#bmexport">Excel csv-export help</a>
              </li>
              <li>
                <a href="http://www.freefileconvert.com" target="_blank">' . __('Use an online File Convertor', 'name-directory') . '</a>
              </li><li>';
        echo sprintf(__('If everything else fails, you can always ask a question at the %s.', 'name-directory'), '<a href="https://wordpress.org/support/plugin/name-directory" target="_blank">' . __('plugin support forums', 'name-directory') . '</a>') . ' ';
        echo '</li></ol></p>';
        if (!function_exists('str_getcsv')) {
            echo '<div class="error"><p>';
            echo __('Name Directory Import requires PHP 5.3, you seem to have in older version. Importing names will not work for your website.', 'name-directory');
            echo '</p></div>';
        }
        echo '<h3>' . __('Upload your .csv-file', 'name-directory') . '</h3>';
        wp_import_upload_form($wp_url_path);
    }
    echo '</div></div>';
    echo '<a href="' . $wp_ndir_path . '">' . sprintf(__('Back to %s', 'name-directory'), '<i>' . $directory['name'] . '</i>') . '</a>';
    echo ' | ';
    echo '<a href="' . $overview_url . '">' . __('Go to Name Directory Overview', 'name-directory') . '</a>';
}
Exemple #13
0
 private function handle_upload()
 {
     // Get the upload file
     $file = wp_import_handle_upload();
     // If the 'error' property is set, show the error message and return FALSE
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, an error has been encountered.', 'wprss') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
         // If the file does not exist, then show the error message and return FALSE
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . __('Sorry, it seems your uploaded file has been misplaced!', 'wprss') . '</strong><br />';
             echo __('The uploaded file could not be found at ', 'wprss') . '<code>' . esc_html($file['file']) . '</code>';
             echo __('It is likely that this was caused by a permissions problem.', 'wprss');
             echo '</p>';
             return false;
         }
     }
     $this->id = (int) $file['id'];
     return true;
 }
 function select_authors()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p>' . __('Sorry, there has been an error.') . '</p>';
         echo '<p><strong>' . $file['error'] . '</strong></p>';
         return;
     }
     $this->file = $file['file'];
     $this->id = (int) $file['id'];
     $this->parse_blogml();
     $this->wp_authors_form();
 }
 private function lastfmimport_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo $file['error'];
         return;
     }
     $this->importfile = $file['file'];
     $this->extractzip();
     $this->lastfmimport_import();
     //if ( is_wp_error( $result ) )
     //	return $result;
     wp_import_cleanup($file['id']);
     $this->rm_r($this->tmpdir);
     $this->tmpdir = null;
     echo '<h3>';
     printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
     echo '</h3>';
 }
 /**
  * Handles the WXR upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'blogger-importer') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'blogger-importer') . '</strong><br />';
             printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'blogger-importer'), esc_html($file['file']));
             echo '</p>';
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $import_data = $file['file'];
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'blogger-importer') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         return false;
     }
     $this->get_authors_from_import($import_data);
     return true;
 }
Exemple #17
0
/*----------------------------------------------------------------------
*
*	import
*
*---------------------------------------------------------------------*/
require_once ABSPATH . 'wp-admin/includes/import.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
// Checkpoint: Upload directory errors
$upload_dir = wp_upload_dir();
if (!empty($upload_dir['error'])) {
    $this->admin_error($upload_dir['error']);
    return;
}
// get file
$file = wp_import_handle_upload();
// Checkpoint: File Error
if (isset($file['error'])) {
    $this->admin_error($file['error']);
    return;
}
// Checkpoint: File Type
$pos = strpos($file['file'], '.xml');
if ($pos === false) {
    $this->admin_error('File uploaded is not a valid ACF export .xml file');
    return;
}
// Start Importing!
$posts = simplexml_load_file($file['file']);
// Checkpoint: Import File must not be empty
if (!$posts) {
 /**
  * Handles the WXR upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p class="text-style"><strong>' . theme_locals('sorry') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         echo '<a class="btn-link" href="' . $this->step1 . '">' . theme_locals('try_again') . '</a>.</p>';
         $this->log(date('Y-m-d H:i:s'));
         $this->log(esc_html($file['error']) . theme_locals('try_again') . PHP_EOL);
         return false;
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . theme_locals('sorry') . '</strong><br />';
             printf(theme_locals('export_file'), esc_html($file['file']));
             echo '</p>';
             $this->log(date('Y-m-d H:i:s'));
             $this->log('The export file could not be found at <code>' . esc_html($file['file']) . '</code>. It is likely that this was caused by a permissions problem' . PHP_EOL);
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $import_data = $this->parse($file['file']);
     if (is_wp_error($import_data)) {
         echo '<p class="text-style"><strong>' . theme_locals('sorry') . '</strong><br/>';
         echo esc_html($import_data->get_error_message());
         echo '. ' . theme_locals('please') . ', <a class="btn-link" href="' . $this->step1 . '">' . theme_locals('try_again') . '</a>.</p>';
         $this->log(date('Y-m-d H:i:s'));
         $this->log(esc_html($import_data->get_error_message()) . '. ' . theme_locals('try_again') . PHP_EOL);
         return false;
     }
     $this->version = $import_data['version'];
     if ($this->version > $this->max_wxr_version) {
         echo '<div class="error"><p><strong>';
         printf(theme_locals('WXR_file'), esc_html($import_data['version']));
         echo '</strong></p></div>';
         $this->log(date('Y-m-d H:i:s'));
         $this->log('This WXR file (version ' . esc_html($import_data["version"]) . ') may not be supported by this version of the importer. Please consider updating' . PHP_EOL);
     }
     $this->get_authors_from_import($import_data);
     return true;
 }
 /**
  * Handles the CSV upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 public function handle_upload()
 {
     if (empty($_POST['file_url'])) {
         $file = wp_import_handle_upload();
         if (isset($file['error'])) {
             $this->import_error($file['error']);
         }
         $this->id = absint($file['id']);
     } elseif (file_exists(ABSPATH . $_POST['file_url'])) {
         $this->file_url = esc_attr($_POST['file_url']);
     } else {
         $this->import_error();
     }
     return true;
 }
 /**
  * Handles the WXR upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     }
     $this->id = (int) $file['id'];
     $import_data = $this->parse($file['file']);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         return false;
     }
     $this->version = $import_data['version'];
     if ($this->version > $this->max_wxr_version) {
         echo '<div class="error"><p><strong>';
         printf(__('This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer'), esc_html($import_data['version']));
         echo '</strong></p></div>';
     }
     $this->get_authors_from_import($import_data);
     return true;
 }
	function import() {
		$file = wp_import_handle_upload();
		if ( isset($file['error']) ) {
			echo $file['error'];
			return;
		}

		$this->file = $file['file'];
		$this->import_posts();
		wp_import_cleanup($file['id']);
		
		echo '<h3>';
		printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
		echo '</h3>';
	}
Exemple #22
0
 function import()
 {
     $options = get_option('html_import');
     if ($_POST['import_files'] == 'file') {
         // preserve original file name so we can use it for slugs later ( maybe )
         $this->filename = $_FILES['import']['name'];
         // upload the file
         $file = wp_import_handle_upload();
         if (isset($file['error'])) {
             echo $file['error'];
             return;
         }
         echo '<h2>' . __('Importing HTML file...', 'import-html-pages') . '</h2>';
         $this->file = $file['file'];
         $this->get_single_file();
         $this->print_results($options['type']);
         wp_import_cleanup($file['id']);
         if ($options['import_images']) {
             $this->find_images();
         }
         if ($options['import_documents']) {
             $this->find_documents();
         }
         if ($options['fix_links']) {
             $this->find_internal_links();
         }
     } elseif ($_POST['import_files'] == 'directory') {
         // in case they entered something dumb and didn't fix it when we showed an error on the options page...
         if (validate_import_file($options['root_directory']) > 0) {
             wp_die(__("The beginning directory you entered is not an absolute path. Relative paths are not allowed here.", 'import-html-pages'));
         }
         $this->table = '';
         $this->redirects = '';
         $this->filearr = array();
         $skipdirs = explode(",", $options['skipdirs']);
         $this->skip = array_merge($skipdirs, array('.', '..', '_vti_cnf', '_notes'));
         $this->allowed = explode(",", $options['file_extensions']);
         echo '<h2>' . __('Importing HTML files...', 'import-html-pages') . '</h2>';
         $this->get_files_from_directory($options['root_directory']);
         $this->print_results($options['type']);
         if (isset($options['import_images']) && $options['import_images']) {
             $this->find_images();
         }
         if (isset($options['import_documents']) && $options['import_documents']) {
             $this->find_documents();
         }
         if (isset($options['fix_links']) && $options['fix_links']) {
             $this->find_internal_links();
         }
     } else {
         _e("Your file upload didn't work. Try again?", 'html-import-pages');
     }
     do_action('import_done', 'html');
 }
Exemple #23
0
 /**
  * import
  *
  * The main controller for the actual import stage. Contains all the import steps.
  *
  * @param none
  * @return none
  */
 public function import()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         \Timber::render('importer/error.twig', array('error' => esc_html($file['error'])));
         return false;
     } else {
         if (!file_exists($file['file'])) {
             \Timber::render('importer/error.twig', array('error' => sprintf(__("The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.", TEXTDOMAIN), esc_html($file['file']))));
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $this->file = get_attached_file($this->id);
     $result = $this->process_posts();
     if (is_wp_error($result)) {
         return $result;
     }
 }
Exemple #24
0
 /**
  *
  */
 function import()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'appthemes') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     }
     $this->process($file['file']);
     echo '<h3>';
     printf(__('All done. <a href="%s">Have fun!</a>', 'appthemes'), home_url());
     echo '</h3>';
 }
 /**
  * Handles the CSV upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 function handle_upload()
 {
     if (empty($_POST['file_url'])) {
         $file = wp_import_handle_upload();
         if (isset($file['error'])) {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'woocommerce') . '</strong><br />';
             echo esc_html($file['error']) . '</p>';
             return false;
         }
         $this->id = (int) $file['id'];
     } else {
         if (file_exists(ABSPATH . $_POST['file_url'])) {
             $this->file_url = esc_attr($_POST['file_url']);
         } else {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'woocommerce') . '</strong></p>';
             return false;
         }
     }
     return true;
 }
	function import() {
		$file = wp_import_handle_upload();
		if ( isset($file['error']) ) {
			echo $file['error'];
			return;
		}

		$this->file = $file['file'];
		$result = $this->import_posts();
		if ( is_wp_error( $result ) )
			return $result;
		wp_import_cleanup($file['id']);
		do_action('import_done', 'blogware');
		echo '<h3>';
		printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
		echo '</h3>';
	}
 function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</p>';
         echo '<p><strong>' . $file['error'] . '</strong></p>';
         return false;
     }
     $this->file = $file['file'];
     $this->id = (int) $file['id'];
     return true;
 }
 /**
  * Handles the JSON upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 private function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), esc_html($file['error']));
     }
     if (!isset($file['file'], $file['id'])) {
         return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), esc_html__('The file did not upload properly. Please try again.', 'wp-options-importer'));
     }
     $this->file_id = intval($file['id']);
     if (!file_exists($file['file'])) {
         wp_import_cleanup($this->file_id);
         return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), sprintf(esc_html__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wp-options-importer'), esc_html($file['file'])));
     }
     if (!is_file($file['file'])) {
         wp_import_cleanup($this->file_id);
         return $this->error_message(esc_html__('Sorry, there has been an error.', 'wordpress-importer'), esc_html__('The path is not a file, please try again.', 'wordpress-importer'));
     }
     $file_contents = file_get_contents($file['file']);
     $this->import_data = json_decode($file_contents, true);
     set_transient($this->transient_key(), $this->import_data, DAY_IN_SECONDS);
     wp_import_cleanup($this->file_id);
     return $this->run_data_check();
 }
Exemple #29
0
 /**
  * Handles the WXR upload and initial parsing of the file to prepare for
  * displaying author import options
  *
  * @return bool False if error uploading or invalid file, true otherwise
  */
 function handle_upload()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'radium') . '</strong><br />';
         echo esc_html($file['error']) . '</p>';
         return false;
     } else {
         if (!file_exists($file['file'])) {
             echo '<p><strong>' . __('Sorry, there has been an error.', 'radium') . '</strong><br />';
             printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'radium'), esc_html($file['file']));
             echo '</p>';
             return false;
         }
     }
     $this->id = (int) $file['id'];
     $import_data = $this->parse($file['file']);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'radium') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         return false;
     }
     $this->version = $import_data['version'];
     if ($this->version > $this->max_wxr_version) {
         echo '<div class="error"><p><strong>';
         printf(__('This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'radium'), esc_html($import_data['version']));
         echo '</strong></p></div>';
     }
     $this->get_authors_from_import($import_data);
     return true;
 }
Exemple #30
0
 private function import()
 {
     check_admin_referer('import-upload');
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         echo scb_admin_notice(__('Sorry, there has been an error.', APP_TD), 'error');
         echo scb_admin_notice(esc_html($file['error']), 'error');
         return false;
     }
     $c = $this->process($file['file']);
     if ($this->attachments) {
         $this->backfill_attachment_urls();
     }
     if (false === $c) {
         echo scb_admin_notice(__('The file could not be processed.', APP_TD), 'error');
     } else {
         echo scb_admin_notice(sprintf(__('Imported %s items.', APP_TD), number_format_i18n($c)));
     }
 }