From 9069ba41a09456614d909039f56913dbafec0900 Mon Sep 17 00:00:00 2001
From: shammash <shammash@autistici.org>
Date: Mon, 10 Oct 2011 21:47:51 +0200
Subject: [PATCH] updated wordpress-importer to 0.5

---
 .../languages/wordpress-importer.pot          | 90 +++++++++----------
 .../plugins/wordpress-importer/parsers.php    | 41 ++++++++-
 .../plugins/wordpress-importer/readme.txt     | 58 +++++++++++-
 .../wordpress-importer/wordpress-importer.php | 81 ++++++++++++-----
 4 files changed, 195 insertions(+), 75 deletions(-)

diff --git a/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot b/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot
index 8dae6cf0d..0ca72e26d 100644
--- a/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot
+++ b/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot
@@ -2,9 +2,9 @@
 # This file is distributed under the same license as the WordPress Importer package.
 msgid ""
 msgstr ""
-"Project-Id-Version: WordPress Importer 0.3\n"
+"Project-Id-Version: WordPress Importer 0.5\n"
 "Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-importer\n"
-"POT-Creation-Date: 2011-02-21 21:07:12+00:00\n"
+"POT-Creation-Date: 2011-07-16 15:45:12+00:00\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
@@ -22,49 +22,49 @@ msgid ""
 "parser..."
 msgstr ""
 
-#: parsers.php:67 parsers.php:72 parsers.php:248 parsers.php:430
+#: parsers.php:67 parsers.php:72 parsers.php:262 parsers.php:451
 msgid ""
 "This does not appear to be a WXR file, missing/invalid WXR version number"
 msgstr ""
 
-#: wordpress-importer.php:133 wordpress-importer.php:142
-#: wordpress-importer.php:193 wordpress-importer.php:201
+#: wordpress-importer.php:134 wordpress-importer.php:143
+#: wordpress-importer.php:194 wordpress-importer.php:202
 msgid "Sorry, there has been an error."
 msgstr ""
 
-#: wordpress-importer.php:134
+#: wordpress-importer.php:135
 msgid "The file does not exist, please try again."
 msgstr ""
 
-#: wordpress-importer.php:177
+#: wordpress-importer.php:178
 msgid "All done."
 msgstr ""
 
-#: wordpress-importer.php:177
+#: wordpress-importer.php:178
 msgid "Have fun!"
 msgstr ""
 
-#: wordpress-importer.php:178
+#: wordpress-importer.php:179
 msgid "Remember to update the passwords and roles of imported users."
 msgstr ""
 
-#: wordpress-importer.php:209
+#: wordpress-importer.php:210
 msgid ""
 "This WXR file (version %s) may not be supported by this version of the "
 "importer. Please consider updating."
 msgstr ""
 
-#: wordpress-importer.php:234
+#: wordpress-importer.php:235
 msgid ""
 "Failed to import author %s. Their posts will be attributed to the current "
 "user."
 msgstr ""
 
-#: wordpress-importer.php:260
+#: wordpress-importer.php:261
 msgid "Assign Authors"
 msgstr ""
 
-#: wordpress-importer.php:261
+#: wordpress-importer.php:262
 msgid ""
 "To make it easier for you to edit and save the imported content, you may "
 "want to reassign the author of the imported item to an existing user of this "
@@ -72,137 +72,137 @@ msgid ""
 "code>s entries."
 msgstr ""
 
-#: wordpress-importer.php:263
+#: wordpress-importer.php:264
 msgid ""
 "If a new user is created by WordPress, a new password will be randomly "
 "generated and the new user&#8217;s role will be set as %s. Manually changing "
 "the new user&#8217;s details will be necessary."
 msgstr ""
 
-#: wordpress-importer.php:273
+#: wordpress-importer.php:274
 msgid "Import Attachments"
 msgstr ""
 
-#: wordpress-importer.php:276
+#: wordpress-importer.php:277
 msgid "Download and import file attachments"
 msgstr ""
 
-#: wordpress-importer.php:280
+#: wordpress-importer.php:281
 msgid "Submit"
 msgstr ""
 
-#: wordpress-importer.php:293
+#: wordpress-importer.php:294
 msgid "Import author:"
 msgstr ""
 
-#: wordpress-importer.php:304
+#: wordpress-importer.php:305
 msgid "or create new user with login name:"
 msgstr ""
 
-#: wordpress-importer.php:307
+#: wordpress-importer.php:308
 msgid "as a new user:"
 msgstr ""
 
-#: wordpress-importer.php:315
+#: wordpress-importer.php:316
 msgid "assign posts to an existing user:"
 msgstr ""
 
-#: wordpress-importer.php:317
+#: wordpress-importer.php:318
 msgid "or assign posts to an existing user:"
 msgstr ""
 
-#: wordpress-importer.php:318
+#: wordpress-importer.php:319
 msgid "- Select -"
 msgstr ""
 
-#: wordpress-importer.php:366
+#: wordpress-importer.php:369
 msgid ""
 "Failed to create new user for %s. Their posts will be attributed to the "
 "current user."
 msgstr ""
 
-#: wordpress-importer.php:413
+#: wordpress-importer.php:418
 msgid "Failed to import category %s"
 msgstr ""
 
-#: wordpress-importer.php:449
+#: wordpress-importer.php:456
 msgid "Failed to import post tag %s"
 msgstr ""
 
-#: wordpress-importer.php:491 wordpress-importer.php:603
+#: wordpress-importer.php:500 wordpress-importer.php:626
 msgid "Failed to import %s %s"
 msgstr ""
 
-#: wordpress-importer.php:513
+#: wordpress-importer.php:522
 msgid "Failed to import &#8220;%s&#8221;: Invalid post type %s"
 msgstr ""
 
-#: wordpress-importer.php:534
+#: wordpress-importer.php:543
 msgid "%s &#8220;%s&#8221; already exists."
 msgstr ""
 
-#: wordpress-importer.php:575
+#: wordpress-importer.php:598
 msgid "Failed to import %s &#8220;%s&#8221;"
 msgstr ""
 
-#: wordpress-importer.php:712
+#: wordpress-importer.php:744
 msgid "Menu item skipped due to missing menu slug"
 msgstr ""
 
-#: wordpress-importer.php:719
+#: wordpress-importer.php:751
 msgid "Menu item skipped due to invalid menu slug: %s"
 msgstr ""
 
-#: wordpress-importer.php:782
+#: wordpress-importer.php:814
 msgid "Fetching attachments is not enabled"
 msgstr ""
 
-#: wordpress-importer.php:795
+#: wordpress-importer.php:827
 msgid "Invalid file type"
 msgstr ""
 
-#: wordpress-importer.php:838
+#: wordpress-importer.php:871
 msgid "Remote server did not respond"
 msgstr ""
 
-#: wordpress-importer.php:844
+#: wordpress-importer.php:877
 msgid "Remote server returned error response %1$d %2$s"
 msgstr ""
 
-#: wordpress-importer.php:851
+#: wordpress-importer.php:884
 msgid "Remote file is incorrect size"
 msgstr ""
 
-#: wordpress-importer.php:856
+#: wordpress-importer.php:889
 msgid "Zero size file downloaded"
 msgstr ""
 
-#: wordpress-importer.php:862
+#: wordpress-importer.php:895
 msgid "Remote file is too large, limit is %s"
 msgstr ""
 
-#: wordpress-importer.php:961
+#: wordpress-importer.php:994
 msgid "Import WordPress"
 msgstr ""
 
-#: wordpress-importer.php:968
+#: wordpress-importer.php:1001
 msgid ""
 "A new version of this importer is available. Please update to version %s to "
 "ensure compatibility with newer export files."
 msgstr ""
 
-#: wordpress-importer.php:983
+#: wordpress-importer.php:1016
 msgid ""
 "Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import "
 "the posts, pages, comments, custom fields, categories, and tags into this "
 "site."
 msgstr ""
 
-#: wordpress-importer.php:984
-msgid "Choose a WXR file to upload, then click Upload file and import."
+#: wordpress-importer.php:1017
+msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
 msgstr ""
 
-#: wordpress-importer.php:1058
+#: wordpress-importer.php:1091
 msgid ""
 "Import <strong>posts, pages, comments, custom fields, categories, and tags</"
 "strong> from a WordPress export file."
diff --git a/wp-content/plugins/wordpress-importer/parsers.php b/wp-content/plugins/wordpress-importer/parsers.php
index 172472960..ab4be51a2 100644
--- a/wp-content/plugins/wordpress-importer/parsers.php
+++ b/wp-content/plugins/wordpress-importer/parsers.php
@@ -157,6 +157,9 @@ class WXR_Parser_SimpleXML {
 			$post['post_password'] = (string) $wp->post_password;
 			$post['is_sticky'] = (int) $wp->is_sticky;
 
+			if ( isset($wp->attachment_url) )
+				$post['attachment_url'] = (string) $wp->attachment_url;
+
 			foreach ( $item->category as $c ) {
 				$att = $c->attributes();
 				if ( isset( $att['nicename'] ) )
@@ -170,11 +173,21 @@ class WXR_Parser_SimpleXML {
 			foreach ( $wp->postmeta as $meta ) {
 				$post['postmeta'][] = array(
 					'key' => (string) $meta->meta_key,
-					'value' => (string) $meta->meta_value,
+					'value' => (string) $meta->meta_value
 				);
 			}
 
 			foreach ( $wp->comment as $comment ) {
+				$meta = array();
+				if ( isset( $comment->commentmeta ) ) {
+					foreach ( $comment->commentmeta as $m ) {
+						$meta[] = array(
+							'key' => (string) $m->meta_key,
+							'value' => (string) $m->meta_value
+						);
+					}
+				}
+			
 				$post['comments'][] = array(
 					'comment_id' => (int) $comment->comment_id,
 					'comment_author' => (string) $comment->comment_author,
@@ -188,6 +201,7 @@ class WXR_Parser_SimpleXML {
 					'comment_type' => (string) $comment->comment_type,
 					'comment_parent' => (string) $comment->comment_parent,
 					'comment_user_id' => (int) $comment->comment_user_id,
+					'commentmeta' => $meta,
 				);
 			}
 
@@ -211,7 +225,7 @@ class WXR_Parser_SimpleXML {
  */
 class WXR_Parser_XML {
 	var $wp_tags = array(
-		'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status',
+		'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
 		'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
 		'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
 		'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
@@ -299,10 +313,17 @@ class WXR_Parser_XML {
 	function tag_close( $parser, $tag ) {
 		switch ( $tag ) {
 			case 'wp:comment':
+				unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
 				if ( ! empty( $this->sub_data ) )
 					$this->data['comments'][] = $this->sub_data;
 				$this->sub_data = false;
 				break;
+			case 'wp:commentmeta':
+				$this->sub_data['commentmeta'][] = array(
+					'key' => $this->sub_data['key'],
+					'value' => $this->sub_data['value']
+				);
+				break;
 			case 'category':
 				if ( ! empty( $this->sub_data ) ) {
 					$this->sub_data['name'] = $this->cdata;
@@ -525,6 +546,10 @@ class WXR_Parser_Regex {
 			'menu_order', 'post_type', 'post_password', 'is_sticky'
 		);
 
+		$attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
+		if ( $attachment_url )
+			$postdata['attachment_url'] = $attachment_url;
+
 		preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
 		foreach ( $terms as $t ) {
 			$post_terms[] = array(
@@ -539,6 +564,16 @@ class WXR_Parser_Regex {
 		$comments = $comments[1];
 		if ( $comments ) {
 			foreach ( $comments as $comment ) {
+				preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
+				$commentmeta = $commentmeta[1];
+				$c_meta = array();
+				foreach ( $commentmeta as $m ) {
+					$c_meta[] = array(
+						'key' => $this->get_tag( $m, 'wp:meta_key' ),
+						'value' => $this->get_tag( $m, 'wp:meta_value' ),
+					);
+				}
+
 				$post_comments[] = array(
 					'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
 					'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
@@ -551,6 +586,8 @@ class WXR_Parser_Regex {
 					'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
 					'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
 					'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
+					'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
+					'commentmeta' => $c_meta,
 				);
 			}
 		}
diff --git a/wp-content/plugins/wordpress-importer/readme.txt b/wp-content/plugins/wordpress-importer/readme.txt
index 06689a0d9..e29681491 100644
--- a/wp-content/plugins/wordpress-importer/readme.txt
+++ b/wp-content/plugins/wordpress-importer/readme.txt
@@ -3,39 +3,89 @@ Contributors: wordpressdotorg
 Donate link: 
 Tags: importer, wordpress
 Requires at least: 3.0
-Tested up to: 3.1
-Stable tag: 0.2
+Tested up to: 3.2.1
+Stable tag: 0.5
 
 Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
 
 == Description ==
 
-Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
+The WordPress Importer will import the following content from a WordPress export file:
+
+* Posts, pages and other custom post types
+* Comments
+* Custom fields and post meta
+* Categories, tags and terms from custom taxonomies
+* Authors
+
+For further information and instructions please see the [Codex page on Importing Content](http://codex.wordpress.org/Importing_Content#WordPress)
 
 == Installation ==
 
+The quickest method for installing the importer is:
+
+1. Visit Tools -> Import in the WordPress dashboard
+1. Click on the WordPress link in the list of importers
+1. Click "Install Now"
+1. Finally click "Activate Plugin & Run Importer"
+
+If you would prefer to do things manually then follow these instructions:
+
 1. Upload the `wordpress-importer` folder to the `/wp-content/plugins/` directory
 1. Activate the plugin through the 'Plugins' menu in WordPress
 1. Go to the Tools -> Import screen, click on WordPress
 
 == Changelog ==
 
+= 0.5 =
+* Import comment meta (requires export from WordPress 3.2)
+* Minor bugfixes and enhancements
+
+= 0.4 =
+* Map comment user_id where possible
+* Import attachments from `wp:attachment_url`
+* Upload attachments to correct directory
+* Remap resized image URLs correctly
+
 = 0.3 =
 * Use an XML Parser if possible
 * Proper import support for nav menus
-* ... and more, see [Trac ticket #15197](http://core.trac.wordpress.org/ticket/15197)
+* ... and much more, see [Trac ticket #15197](http://core.trac.wordpress.org/ticket/15197)
 
 = 0.1 =
 * Initial release
 
 == Upgrade Notice ==
 
+= 0.5 =
+Import comment meta and other minor bugfixes and enhancements.
+
+= 0.4 =
+Bug fixes for attachment importing and other small enhancements.
+
 = 0.3 =
 Upgrade for a more robust and reliable experience when importing WordPress export files, and for compatibility with WordPress 3.1.
 
+== Frequently Asked Questions ==
+
+= Help! I'm getting out of memory errors or a blank screen. =
+If your exported file is very large, the import script may run into your host's configured memory limit for PHP.
+
+A message like "Fatal error: Allowed memory size of 8388608 bytes exhausted" indicates that the script can't successfully import your XML file under the current PHP memory limit. If you have access to the php.ini file, you can manually increase the limit; if you do not (your WordPress installation is hosted on a shared server, for instance), you might have to break your exported XML file into several smaller pieces and run the import script one at a time.
+
+For those with shared hosting, the best alternative may be to consult hosting support to determine the safest approach for running the import. A host may be willing to temporarily lift the memory limit and/or run the process directly from their end.
+
+-- [WordPress Codex: Importing Content](http://codex.wordpress.org/Importing_Content#Before_Importing)
+
 == Filters ==
 
 The importer has a couple of filters to allow you to completely enable/block certain features:
+
 * `import_allow_create_users`: return false if you only want to allow mapping to existing users
 * `import_allow_fetch_attachments`: return false if you do not wish to allow importing and downloading of attachments
 * `import_attachment_size_limit`: return an integer value for the maximum file size in bytes to save (default is 0, which is unlimited)
+
+There are also a few actions available to hook into:
+
+* `import_start`: occurs after the export file has been uploaded and author import settings have been chosen
+* `import_end`: called after the last output from the importer
diff --git a/wp-content/plugins/wordpress-importer/wordpress-importer.php b/wp-content/plugins/wordpress-importer/wordpress-importer.php
index 36285e206..5e3848449 100644
--- a/wp-content/plugins/wordpress-importer/wordpress-importer.php
+++ b/wp-content/plugins/wordpress-importer/wordpress-importer.php
@@ -5,7 +5,7 @@ Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/
 Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
 Author: wordpressdotorg
 Author URI: http://wordpress.org/
-Version: 0.3
+Version: 0.5
 Text Domain: wordpress-importer
 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */
@@ -103,6 +103,7 @@ class WP_Import extends WP_Importer {
 	 */
 	function import( $file ) {
 		add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
+		add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
 
 		$this->import_start( $file );
 
@@ -334,6 +335,8 @@ class WP_Import extends WP_Importer {
 		$create_users = $this->allow_create_users();
 
 		foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
+			// Multsite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
+			$santized_old_login = sanitize_user( $old_login, true );
 			$old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
 
 			if ( ! empty( $_POST['user_map'][$i] ) ) {
@@ -341,7 +344,7 @@ class WP_Import extends WP_Importer {
 				if ( isset( $user->ID ) ) {
 					if ( $old_id )
 						$this->processed_authors[$old_id] = $user->ID;
-					$this->author_mapping[$old_login] = $user->ID;
+					$this->author_mapping[$santized_old_login] = $user->ID;
 				}
 			} else if ( $create_users ) {
 				if ( ! empty($_POST['user_new'][$i]) ) {
@@ -361,7 +364,7 @@ class WP_Import extends WP_Importer {
 				if ( ! is_wp_error( $user_id ) ) {
 					if ( $old_id )
 						$this->processed_authors[$old_id] = $user_id;
-					$this->author_mapping[$old_login] = $user_id;
+					$this->author_mapping[$santized_old_login] = $user_id;
 				} else {
 					printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
 					if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
@@ -371,10 +374,10 @@ class WP_Import extends WP_Importer {
 			}
 
 			// failsafe: if the user_id was invalid, default to the current user
-			if ( ! isset( $this->author_mapping[$old_login] ) ) {
+			if ( ! isset( $this->author_mapping[$santized_old_login] ) ) {
 				if ( $old_id )
 					$this->processed_authors[$old_id] = (int) get_current_user_id();
-				$this->author_mapping[$old_login] = (int) get_current_user_id();
+				$this->author_mapping[$santized_old_login] = (int) get_current_user_id();
 			}
 		}
 	}
@@ -393,7 +396,8 @@ class WP_Import extends WP_Importer {
 			$term_id = term_exists( $cat['category_nicename'], 'category' );
 			if ( $term_id ) {
 				if ( is_array($term_id) ) $term_id = $term_id['term_id'];
-				$this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
+				if ( isset($cat['term_id']) )
+					$this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
 				continue;
 			}
 
@@ -408,7 +412,8 @@ class WP_Import extends WP_Importer {
 
 			$id = wp_insert_category( $catarr );
 			if ( ! is_wp_error( $id ) ) {
-				$this->processed_terms[intval($cat['term_id'])] = $id;
+				if ( isset($cat['term_id']) )
+					$this->processed_terms[intval($cat['term_id'])] = $id;
 			} else {
 				printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) );
 				if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
@@ -435,7 +440,8 @@ class WP_Import extends WP_Importer {
 			$term_id = term_exists( $tag['tag_slug'], 'post_tag' );
 			if ( $term_id ) {
 				if ( is_array($term_id) ) $term_id = $term_id['term_id'];
-				$this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
+				if ( isset($tag['term_id']) )
+					$this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
 				continue;
 			}
 
@@ -444,7 +450,8 @@ class WP_Import extends WP_Importer {
 
 			$id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
 			if ( ! is_wp_error( $id ) ) {
-				$this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
+				if ( isset($tag['term_id']) )
+					$this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
 			} else {
 				printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) );
 				if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
@@ -471,7 +478,8 @@ class WP_Import extends WP_Importer {
 			$term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
 			if ( $term_id ) {
 				if ( is_array($term_id) ) $term_id = $term_id['term_id'];
-				$this->processed_terms[intval($term['term_id'])] = (int) $term_id;
+				if ( isset($term['term_id']) )
+					$this->processed_terms[intval($term['term_id'])] = (int) $term_id;
 				continue;
 			}
 
@@ -486,7 +494,8 @@ class WP_Import extends WP_Importer {
 
 			$id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
 			if ( ! is_wp_error( $id ) ) {
-				$this->processed_terms[intval($term['term_id'])] = $id['term_id'];
+				if ( isset($term['term_id']) )
+					$this->processed_terms[intval($term['term_id'])] = $id['term_id'];
 			} else {
 				printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) );
 				if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
@@ -516,7 +525,7 @@ class WP_Import extends WP_Importer {
 				continue;
 			}
 
-			if ( isset( $this->processed_posts[$post['post_id']] ) )
+			if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) )
 				continue;
 
 			if ( $post['status'] == 'auto-draft' )
@@ -566,6 +575,20 @@ class WP_Import extends WP_Importer {
 
 				if ( 'attachment' == $postdata['post_type'] ) {
 					$remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
+
+					// try to use _wp_attached file for upload folder placement to ensure the same location as the export site
+					// e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
+					$postdata['upload_date'] = $post['post_date'];
+					if ( isset( $post['postmeta'] ) ) {
+						foreach( $post['postmeta'] as $meta ) {
+							if ( $meta['key'] == '_wp_attached_file' ) {
+								if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
+									$postdata['upload_date'] = $matches[0];
+								break;
+							}
+						}
+					}
+
 					$comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
 				} else {
 					$comment_post_ID = $post_id = wp_insert_post( $postdata, true );
@@ -633,6 +656,9 @@ class WP_Import extends WP_Importer {
 					$newcomments[$comment_id]['comment_approved']     = $comment['comment_approved'];
 					$newcomments[$comment_id]['comment_type']         = $comment['comment_type'];
 					$newcomments[$comment_id]['comment_parent'] 	  = $comment['comment_parent'];
+					$newcomments[$comment_id]['commentmeta']          = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
+					if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
+						$newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
 				}
 				ksort( $newcomments );
 
@@ -643,6 +669,12 @@ class WP_Import extends WP_Importer {
 							$comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
 						$comment = wp_filter_comment( $comment );
 						$inserted_comments[$key] = wp_insert_comment( $comment );
+
+						foreach( $comment['commentmeta'] as $meta ) {
+							$value = maybe_unserialize( $meta['value'] );
+							add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
+						}
+
 						$num_comments++;
 					}
 				}
@@ -667,7 +699,7 @@ class WP_Import extends WP_Importer {
 						if ( ! $value )
 							$value = maybe_unserialize( $meta['value'] );
 
-						update_post_meta( $post_id, $key, $value );
+						add_post_meta( $post_id, $key, $value );
 						do_action( 'import_post_meta', $post_id, $key, $value );
 
 						// if the post has a featured image, take note of this in case of remap
@@ -800,12 +832,15 @@ class WP_Import extends WP_Importer {
 		$post_id = wp_insert_attachment( $post, $upload['file'] );
 		wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
 
-		// remap the thumbnail url.  this isn't perfect because we're just guessing the original url.
-		if ( preg_match( '@^image/@', $info['type'] ) && $thumb_url = wp_get_attachment_thumb_url( $post_id ) ) {
+		// remap resized image URLs, works by stripping the extension and remapping the URL stub.
+		if ( preg_match( '!^image/!', $info['type'] ) ) {
 			$parts = pathinfo( $url );
-			$ext = $parts['extension'];
-			$name = basename($parts['basename'], ".{$ext}");
-			$this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url;
+			$name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
+
+			$parts_new = pathinfo( $upload['url'] );
+			$name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
+
+			$this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
 		}
 
 		return $post_id;
@@ -819,13 +854,11 @@ class WP_Import extends WP_Importer {
 	 * @return array|WP_Error Local file location details on success, WP_Error otherwise
 	 */
 	function fetch_remote_file( $url, $post ) {
-		add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
-
 		// extract the file name and extension from the url
 		$file_name = basename( $url );
 
 		// get placeholder file in the upload dir with a unique, sanitized filename
-		$upload = wp_upload_bits( $file_name, 0, '', $post['post_date'] );
+		$upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
 		if ( $upload['error'] )
 			return new WP_Error( 'upload_dir_error', $upload['error'] );
 
@@ -864,8 +897,8 @@ class WP_Import extends WP_Importer {
 
 		// keep track of the old and new urls so we can substitute them later
 		$this->url_remap[$url] = $upload['url'];
-		$this->url_remap[$post['guid']] = $upload['url'];
-		// if the remote url is redirected somewhere else, keep track of the destination too
+		$this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed?
+		// keep track of the destination if the remote url is redirected somewhere else
 		if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url )
 			$this->url_remap[$headers['x-final-location']] = $upload['url'];
 
@@ -981,7 +1014,7 @@ class WP_Import extends WP_Importer {
 	function greet() {
 		echo '<div class="narrow">';
 		echo '<p>'.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ).'</p>';
-		echo '<p>'.__( 'Choose a WXR file to upload, then click Upload file and import.', 'wordpress-importer' ).'</p>';
+		echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'</p>';
 		wp_import_upload_form( 'admin.php?import=wordpress&amp;step=1' );
 		echo '</div>';
 	}
-- 
GitLab