diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php
index f5a0662982..1e5a37f264 100644
--- a/wp-admin/import/wordpress.php
+++ b/wp-admin/import/wordpress.php
@@ -9,6 +9,9 @@ class WP_Import {
var $mtnames = array ();
var $newauthornames = array ();
var $allauthornames = array ();
+
+ var $author_ids = array ();
+
var $j = -1;
var $fetch_attachments = false;
var $url_remap = array ();
@@ -44,56 +47,48 @@ class WP_Import {
return $return;
}
- function users_form($n) {
- global $wpdb, $testing;
- $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users ORDER BY user_login");
-?>
- mtnames))) { //a new mt author name is found
- ++ $this->j;
- $this->mtnames[$this->j] = $author; //add that new mt author name to an array
- $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
- if (!$user_id) { //banging my head against the desk now.
- if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
- $user_id = wp_create_user($author, $pass);
- $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank.
- } else {
- $user_id = wp_create_user($this->newauthornames[$this->j], $pass);
- }
- } else {
- return $user_id; // return pre-existing wp username if it exists
- }
- } else {
- $key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array
- $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames
- }
-
- return $user_id;
+
+ function fopen($filename, $mode='r') {
+ if ( $this->has_gzip() )
+ return gzopen($filename, $mode);
+ return fopen($filename, $mode);
+ }
+
+ function feof($fp) {
+ if ( $this->has_gzip() )
+ return gzeof($fp);
+ return feof($fp);
+ }
+
+ function fgets($fp, $len=8192) {
+ if ( $this->has_gzip() )
+ return gzgets($fp, $len);
+ return fgets($fp, $len);
+ }
+
+ function fclose($fp) {
+ if ( $this->has_gzip() )
+ return gzclose($fp);
+ return fclose($fp);
}
function get_entries($process_post_func=NULL) {
set_magic_quotes_runtime(0);
$doing_entry = false;
+ $is_wxr_file = false;
- $fp = fopen($this->file, 'r');
+ $fp = $this->fopen($this->file, 'r');
if ($fp) {
- while ( !feof($fp) ) {
- $importline = rtrim(fgets($fp));
+ while ( !$this->feof($fp) ) {
+ $importline = rtrim($this->fgets($fp));
+
+ // this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
+ if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) )
+ $is_wxr_file = true;
if ( false !== strpos($importline, ' admins entries.'); ?> '.__('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)')."
'.sprintf(__('Create user %1$s or map to existing'), '
');
- $this->users_form($j);
+ echo '
';
+ $this->users_form($j, $author);
echo '
'.__('Please upload a valid WXR (WordPress eXtended RSS) export file.').'
'; + } } + // fetch the user ID for a given author name, respecting the mapping preferences + function checkauthor($author) { + global $current_user; + + if ( !empty($this->author_ids[$author]) ) + return $this->author_ids[$author]; + + // failsafe: map to the current user + return $current_user->ID; + } + + + function process_categories() { global $wpdb; @@ -515,10 +568,20 @@ class WP_Import { $headers = wp_get_http($url, $upload['file']); // make sure the fetch was successful - if ( $headers['response'] != '200' ) - return new WP_Error( 'import_file_error', __(sprintf('Remote file returned error response %d', intval($headers['response']))) ); - elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) + if ( $headers['response'] != '200' ) { + @unlink($upload['file']); + return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %d'), intval($headers['response'])) ); + } + elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) { + @unlink($upload['file']); return new WP_Error( 'import_file_error', __('Remote file is incorrect size') ); + } + + $max_size = $this->max_attachment_size(); + if ( !empty($max_size) and filesize($upload['file']) > $max_size ) { + @unlink($upload['file']); + return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', size_format($max_size))) ); + } // keep track of the old and new urls so we can substitute them later $this->url_remap[$url] = $upload['url']; @@ -570,13 +633,31 @@ class WP_Import { return $key; } + // give the user the option of creating new users to represent authors in the import file? + function allow_create_users() { + return apply_filters('import_allow_create_users', true); + } + + // give the user the option of downloading and importing attached files + function allow_fetch_attachments() { + return apply_filters('import_allow_fetch_attachments', true); + } + + function max_attachment_size() { + // can be overridden with a filter - 0 means no limit + return apply_filters('import_attachment_size_limit', 0); + } + + function import($id, $fetch_attachments = false) { $this->id = (int) $id; - $this->fetch_attachments = (bool) $fetch_attachments; + $this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments); add_filter('import_post_meta_key', array($this, 'is_valid_meta_key')); + do_action('import_start'); $file = get_attached_file($this->id); $this->import_file($file); + do_action('import_end'); } function import_file($file) { @@ -647,4 +728,4 @@ $wp_import = new WP_Import(); register_importer('wordpress', 'WordPress', __('Import posts, comments, custom fields, pages, and categories from a WordPress export file'), array ($wp_import, 'dispatch')); -?> +?> \ No newline at end of file diff --git a/wp-admin/includes/import.php b/wp-admin/includes/import.php index 6752ed6ec0..35fd141b17 100644 --- a/wp-admin/includes/import.php +++ b/wp-admin/includes/import.php @@ -20,6 +20,7 @@ function wp_import_cleanup( $id ) { function wp_import_handle_upload() { $overrides = array( 'test_form' => false, 'test_type' => false ); + $_FILES['import']['name'] .= '.import'; $file = wp_handle_upload( $_FILES['import'], $overrides ); if ( isset( $file['error'] ) )