diff --git a/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot b/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot index 09f7012ac5b224ee438a439109bcfd185e6aba6f..8dae6cf0dfc1902378bf138d0a07457f1ac162b5 100644 --- a/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot +++ b/wp-content/plugins/wordpress-importer/languages/wordpress-importer.pot @@ -1,178 +1,208 @@ -# Translation of the WordPress plugin WordPress Importer 0.2 by wordpressdotorg. -# Copyright (C) 2010 wordpressdotorg +# Copyright (C) 2011 WordPress Importer # This file is distributed under the same license as the WordPress Importer package. -# FIRST AUTHOR <EMAIL@ADDRESS>, 2010. -# -#, fuzzy msgid "" msgstr "" -"Project-Id-Version: WordPress Importer 0.2\n" +"Project-Id-Version: WordPress Importer 0.3\n" "Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-importer\n" -"POT-Creation-Date: 2010-06-01 13:26+0300\n" +"POT-Creation-Date: 2011-02-21 21:07:12+00:00\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" -#: wordpress-importer.php:55 -msgid "Import WordPress" +#: parsers.php:42 parsers.php:63 +msgid "There was an error when reading this WXR file" msgstr "" -#: wordpress-importer.php:64 +#: parsers.php:43 msgid "" -"Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import " -"the posts, pages, comments, custom fields, categories, and tags into this " -"site." +"Details are shown above. The importer will now try again with a different " +"parser..." msgstr "" -#: wordpress-importer.php:65 +#: parsers.php:67 parsers.php:72 parsers.php:248 parsers.php:430 msgid "" -"Choose a WordPress WXR file to upload, then click Upload file and import." +"This does not appear to be a WXR file, missing/invalid WXR version number" msgstr "" -#: wordpress-importer.php:228 -msgid "Assign Authors" +#: wordpress-importer.php:133 wordpress-importer.php:142 +#: wordpress-importer.php:193 wordpress-importer.php:201 +msgid "Sorry, there has been an error." msgstr "" -#: wordpress-importer.php:229 +#: wordpress-importer.php:134 +msgid "The file does not exist, please try again." +msgstr "" + +#: wordpress-importer.php:177 +msgid "All done." +msgstr "" + +#: wordpress-importer.php:177 +msgid "Have fun!" +msgstr "" + +#: wordpress-importer.php:178 +msgid "Remember to update the passwords and roles of imported users." +msgstr "" + +#: wordpress-importer.php:209 msgid "" -"To make it easier for you to edit and save the imported posts and drafts, " -"you may want to change the name of the author of the posts. For example, you " -"may want to import all the entries as <code>admin</code>s entries." +"This WXR file (version %s) may not be supported by this version of the " +"importer. Please consider updating." msgstr "" -#: wordpress-importer.php:232 +#: wordpress-importer.php:234 msgid "" -"If a new user is created by WordPress, a password will be randomly " -"generated. Manually change the user’s details if necessary." +"Failed to import author %s. Their posts will be attributed to the current " +"user." msgstr "" -#: wordpress-importer.php:245 -msgid "Import author:" +#: wordpress-importer.php:260 +msgid "Assign Authors" +msgstr "" + +#: wordpress-importer.php:261 +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 " +"site. For example, you may want to import all the entries as <code>admin</" +"code>s entries." +msgstr "" + +#: wordpress-importer.php:263 +msgid "" +"If a new user is created by WordPress, a new password will be randomly " +"generated and the new user’s role will be set as %s. Manually changing " +"the new user’s details will be necessary." msgstr "" -#: wordpress-importer.php:253 +#: wordpress-importer.php:273 msgid "Import Attachments" msgstr "" -#: wordpress-importer.php:256 +#: wordpress-importer.php:276 msgid "Download and import file attachments" msgstr "" -#: wordpress-importer.php:263 +#: wordpress-importer.php:280 msgid "Submit" msgstr "" -#: wordpress-importer.php:272 -#, php-format -msgid "Create user %1$s or map to existing" +#: wordpress-importer.php:293 +msgid "Import author:" msgstr "" -#: wordpress-importer.php:275 -msgid "Map to existing" +#: wordpress-importer.php:304 +msgid "or create new user with login name:" msgstr "" -#: wordpress-importer.php:283 -msgid "- Select -" +#: wordpress-importer.php:307 +msgid "as a new user:" msgstr "" -#: wordpress-importer.php:299 -msgid "Invalid file" +#: wordpress-importer.php:315 +msgid "assign posts to an existing user:" msgstr "" -#: wordpress-importer.php:300 -msgid "Please upload a valid WXR (WordPress eXtended RSS) export file." +#: wordpress-importer.php:317 +msgid "or assign posts to an existing user:" msgstr "" -#: wordpress-importer.php:343 -#, php-format -msgid "Importing category <em>%s</em>…" +#: wordpress-importer.php:318 +msgid "- Select -" msgstr "" -#: wordpress-importer.php:365 -#, php-format -msgid "Importing tag <em>%s</em>…" +#: wordpress-importer.php:366 +msgid "" +"Failed to create new user for %s. Their posts will be attributed to the " +"current user." msgstr "" -#: wordpress-importer.php:403 -#, php-format -msgid "Importing <em>%s</em>…" +#: wordpress-importer.php:413 +msgid "Failed to import category %s" msgstr "" -#: wordpress-importer.php:424 -msgid "All done." +#: wordpress-importer.php:449 +msgid "Failed to import post tag %s" msgstr "" -#: wordpress-importer.php:424 -msgid "Have fun!" +#: wordpress-importer.php:491 wordpress-importer.php:603 +msgid "Failed to import %s %s" msgstr "" -#: wordpress-importer.php:488 -#, php-format -msgid "Post <em>%s</em> already exists." +#: wordpress-importer.php:513 +msgid "Failed to import “%s”: Invalid post type %s" msgstr "" -#: wordpress-importer.php:521 -#, php-format -msgid "Importing post <em>%s</em>..." +#: wordpress-importer.php:534 +msgid "%s “%s” already exists." msgstr "" -#: wordpress-importer.php:617 -#, php-format -msgid "(%s comment)" -msgid_plural "(%s comments)" -msgstr[0] "" -msgstr[1] "" - -#: wordpress-importer.php:645 -#, php-format -msgid "Importing attachment <em>%s</em>... " +#: wordpress-importer.php:575 +msgid "Failed to import %s “%s”" msgstr "" -#: wordpress-importer.php:653 -#, php-format -msgid "Remote file error: %s" +#: wordpress-importer.php:712 +msgid "Menu item skipped due to missing menu slug" msgstr "" -#: wordpress-importer.php:661 -msgid "Zero length file, deleting" +#: wordpress-importer.php:719 +msgid "Menu item skipped due to invalid menu slug: %s" msgstr "" -#: wordpress-importer.php:670 -msgid "Invalid file type" +#: wordpress-importer.php:782 +msgid "Fetching attachments is not enabled" msgstr "" -#: wordpress-importer.php:691 -#, php-format -msgid "Skipping attachment <em>%s</em>" +#: wordpress-importer.php:795 +msgid "Invalid file type" msgstr "" -#: wordpress-importer.php:716 +#: wordpress-importer.php:838 msgid "Remote server did not respond" msgstr "" -#: wordpress-importer.php:722 -#, php-format -msgid "Remote file returned error response %1$d %2$s" +#: wordpress-importer.php:844 +msgid "Remote server returned error response %1$d %2$s" msgstr "" -#: wordpress-importer.php:726 +#: wordpress-importer.php:851 msgid "Remote file is incorrect size" msgstr "" -#: wordpress-importer.php:732 -#, php-format +#: wordpress-importer.php:856 +msgid "Zero size file downloaded" +msgstr "" + +#: wordpress-importer.php:862 msgid "Remote file is too large, limit is %s" msgstr "" -#: wordpress-importer.php:864 -msgid "Sorry, there has been an error." +#: wordpress-importer.php:961 +msgid "Import WordPress" +msgstr "" + +#: wordpress-importer.php:968 +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 +msgid "" +"Howdy! Upload your WordPress eXtended RSS (WXR) file and we’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." msgstr "" -#: wordpress-importer.php:914 +#: wordpress-importer.php:1058 msgid "" "Import <strong>posts, pages, comments, custom fields, categories, and tags</" "strong> from a WordPress export file." @@ -188,8 +218,8 @@ msgstr "" #. Description of the plugin/theme msgid "" -"Import posts, pages, comments, custom fields, categories, and tags from a " -"WordPress export file." +"Import posts, pages, comments, custom fields, categories, tags and more from " +"a WordPress export file." msgstr "" #. Author of the plugin/theme diff --git a/wp-content/plugins/wordpress-importer/parsers.php b/wp-content/plugins/wordpress-importer/parsers.php index 014e6697806b8430cb15fbcab70ef81200ab508d..172472960886d2be7377c3640a3852be53604526 100644 --- a/wp-content/plugins/wordpress-importer/parsers.php +++ b/wp-content/plugins/wordpress-importer/parsers.php @@ -68,7 +68,7 @@ class WXR_Parser_SimpleXML { $wxr_version = (string) trim( $wxr_version[0] ); // confirm that we are dealing with the correct file format - if ( ! preg_match( '/^\d\.\d$/', $wxr_version ) ) + if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); $base_url = $xml->xpath('/rss/channel/wp:base_site_url'); @@ -85,6 +85,7 @@ class WXR_Parser_SimpleXML { $a = $author_arr->children( $namespaces['wp'] ); $login = (string) $a->author_login; $authors[$login] = array( + 'author_id' => (int) $a->author_id, 'author_login' => $login, 'author_email' => (string) $a->author_email, 'author_display_name' => (string) $a->author_display_name, @@ -199,7 +200,8 @@ class WXR_Parser_SimpleXML { 'categories' => $categories, 'tags' => $tags, 'terms' => $terms, - 'base_url' => $base_url + 'base_url' => $base_url, + 'version' => $wxr_version ); } } @@ -213,7 +215,7 @@ class WXR_Parser_XML { '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', - 'wp:term_name', 'wp:term_description', 'wp:author_login', 'wp:author_email', 'wp:author_display_name', + 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name', 'wp:author_first_name', 'wp:author_last_name', ); var $wp_sub_tags = array( @@ -223,7 +225,7 @@ class WXR_Parser_XML { ); function parse( $file ) { - $this->is_wxr_file = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; + $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); $xml = xml_parser_create( 'UTF-8' ); @@ -242,7 +244,7 @@ class WXR_Parser_XML { } xml_parser_free( $xml ); - if ( ! $this->is_wxr_file ) + if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); return array( @@ -251,7 +253,8 @@ class WXR_Parser_XML { 'categories' => $this->category, 'tags' => $this->tag, 'terms' => $this->term, - 'base_url' => $this->base_url + 'base_url' => $this->base_url, + 'version' => $this->wxr_version ); } @@ -332,7 +335,7 @@ class WXR_Parser_XML { $this->base_url = $this->cdata; break; case 'wp:wxr_version': - $this->is_wxr_file = preg_match( '/\d+\.\d+/', $this->cdata ); + $this->wxr_version = $this->cdata; break; default: @@ -369,15 +372,15 @@ class WXR_Parser_Regex { } function parse( $file ) { - $is_wxr = $in_post = false; + $wxr_version = $in_post = false; $fp = $this->fopen( $file, 'r' ); if ( $fp ) { while ( ! $this->feof( $fp ) ) { $importline = rtrim( $this->fgets( $fp ) ); - if ( ! $is_wxr && preg_match( '|<wp:wxr_version>\d+\.\d+</wp:wxr_version>|', $importline ) ) - $is_wxr = true; + if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) + $wxr_version = $version[1]; if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) { preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url ); @@ -423,7 +426,7 @@ class WXR_Parser_Regex { $this->fclose($fp); } - if ( ! $is_wxr ) + if ( ! $wxr_version ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); return array( @@ -432,7 +435,8 @@ class WXR_Parser_Regex { 'categories' => $this->categories, 'tags' => $this->tags, 'terms' => $this->terms, - 'base_url' => $this->base_url + 'base_url' => $this->base_url, + 'version' => $wxr_version ); } @@ -480,6 +484,7 @@ class WXR_Parser_Regex { function process_author( $a ) { return array( + 'author_id' => $this->get_tag( $a, 'wp:author_id' ), 'author_login' => $this->get_tag( $a, 'wp:author_login' ), 'author_email' => $this->get_tag( $a, 'wp:author_email' ), 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ), diff --git a/wp-content/plugins/wordpress-importer/readme.txt b/wp-content/plugins/wordpress-importer/readme.txt index ecc5cb427ee676f8509145322da717257a3c8c59..06689a0d934f15d343c21631c4722dc8dd2eea6d 100644 --- a/wp-content/plugins/wordpress-importer/readme.txt +++ b/wp-content/plugins/wordpress-importer/readme.txt @@ -3,7 +3,7 @@ Contributors: wordpressdotorg Donate link: Tags: importer, wordpress Requires at least: 3.0 -Tested up to: 3.1-alpha +Tested up to: 3.1 Stable tag: 0.2 Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file. @@ -23,7 +23,7 @@ Import posts, pages, comments, custom fields, categories, tags and more from a W = 0.3 = * Use an XML Parser if possible * Proper import support for nav menus -* ... and more +* ... and more, see [Trac ticket #15197](http://core.trac.wordpress.org/ticket/15197) = 0.1 = * Initial release @@ -31,7 +31,7 @@ Import posts, pages, comments, custom fields, categories, tags and more from a W == Upgrade Notice == = 0.3 = -Upgrade for a more robust and reliable experience when importing WordPress export file. +Upgrade for a more robust and reliable experience when importing WordPress export files, and for compatibility with WordPress 3.1. == Filters == diff --git a/wp-content/plugins/wordpress-importer/wordpress-importer.php b/wp-content/plugins/wordpress-importer/wordpress-importer.php index aeee0eba89441be3fc012cb687f71ac24a899aa6..36285e206260ca90b911051825f36becbb1ad2d0 100644 --- a/wp-content/plugins/wordpress-importer/wordpress-importer.php +++ b/wp-content/plugins/wordpress-importer/wordpress-importer.php @@ -5,15 +5,16 @@ 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-beta2 -License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html +Version: 0.3 +Text Domain: wordpress-importer +License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) return; /** Display verbose errors */ -define( 'IMPORT_DEBUG', true ); +define( 'IMPORT_DEBUG', false ); // Load Importer API require_once ABSPATH . 'wp-admin/includes/import.php'; @@ -35,8 +36,12 @@ require dirname( __FILE__ ) . '/parsers.php'; */ if ( class_exists( 'WP_Importer' ) ) { class WP_Import extends WP_Importer { - var $id; + var $max_wxr_version = 1.1; // max. supported WXR version + var $id; // WXR attachment ID + + // information to import from WXR file + var $version; var $authors = array(); var $posts = array(); var $terms = array(); @@ -44,7 +49,9 @@ class WP_Import extends WP_Importer { var $tags = array(); var $base_url = ''; + // mappings from old information to new var $processed_authors = array(); + var $author_mapping = array(); var $processed_terms = array(); var $processed_posts = array(); var $post_orphans = array(); @@ -54,6 +61,7 @@ class WP_Import extends WP_Importer { var $fetch_attachments = false; var $url_remap = array(); + var $featured_images = array(); function WP_Import() { /* nothing */ } @@ -80,6 +88,7 @@ class WP_Import extends WP_Importer { $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() ); $this->id = (int) $_POST['import_id']; $file = get_attached_file( $this->id ); + set_time_limit(0); $this->import( $file ); break; } @@ -106,10 +115,10 @@ class WP_Import extends WP_Importer { $this->process_posts(); wp_suspend_cache_invalidation( false ); - // update items with missing/incorrect parent IDs + // update incorrect/missing information in the DB $this->backfill_parents(); - // update attachment references within posts and postmeta $this->backfill_attachment_urls(); + $this->remap_featured_images(); $this->import_end(); } @@ -136,6 +145,7 @@ class WP_Import extends WP_Importer { die(); } + $this->version = $import_data['version']; $this->get_authors_from_import( $import_data ); $this->posts = $import_data['posts']; $this->terms = $import_data['terms']; @@ -164,7 +174,8 @@ class WP_Import extends WP_Importer { wp_defer_term_counting( false ); wp_defer_comment_counting( false ); - echo '<p>' . __( 'All done.' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!' ) . '</a>' . '</p>'; + echo '<p>' . __( 'All done.', 'wordpress-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'wordpress-importer' ) . '</a>' . '</p>'; + echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'wordpress-importer' ) . '</p>'; do_action( 'import_end' ); } @@ -192,6 +203,13 @@ class WP_Import extends WP_Importer { 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; @@ -213,7 +231,7 @@ class WP_Import extends WP_Importer { foreach ( $import_data['posts'] as $post ) { $login = sanitize_user( $post['post_author'], true ); if ( empty( $login ) ) { - _e( sprintf( 'Failed to import author %s. Their posts will be attributed to the current user.', esc_html( $post['post_author'] ) ) ); + printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) ); echo '<br />'; continue; } @@ -239,7 +257,7 @@ class WP_Import extends WP_Importer { <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" /> <?php if ( ! empty( $this->authors ) ) : ?> - <h3><?php _e('Assign Authors', 'wordpress-importer'); ?></h3> + <h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3> <p><?php _e( '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 site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer' ); ?></p> <?php if ( $this->allow_create_users() ) : ?> <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user’s role will be set as %s. Manually changing the new user’s details will be necessary.', 'wordpress-importer' ), esc_html( get_option('default_role') ) ); ?></p> @@ -252,7 +270,7 @@ class WP_Import extends WP_Importer { <?php endif; ?> <?php if ( $this->allow_fetch_attachments() ) : ?> - <h3><?php _e('Import Attachments', 'wordpress-importer'); ?></h3> + <h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3> <p> <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments" /> <label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label> @@ -273,16 +291,35 @@ class WP_Import extends WP_Importer { */ function author_select( $n, $author ) { _e( 'Import author:', 'wordpress-importer' ); - echo ' <strong>' . esc_html( $author['author_display_name'] . ' (' . esc_html( $author['author_login'] ) . ')' ) . '</strong><br />'; + echo ' <strong>' . esc_html( $author['author_display_name'] ); + if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')'; + echo '</strong><br />'; + + if ( $this->version != '1.0' ) + echo '<div style="margin-left:18px">'; + + $create_users = $this->allow_create_users(); + if ( $create_users ) { + if ( $this->version != '1.0' ) { + _e( 'or create new user with login name:', 'wordpress-importer' ); + $value = ''; + } else { + _e( 'as a new user:', 'wordpress-importer' ); + $value = esc_attr( sanitize_user( $author['author_login'], true ) ); + } - if ( $this->allow_create_users() ) { - _e( 'Create new user with login name', 'wordpress-importer' ); - echo ' <input type="text" name="user_new['.$n.']" value="'. esc_attr( sanitize_user( $author['author_login'], true ) ) .'" /><br />'; + echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />'; } - _e( 'Map to existing user', 'wordpress-importer' ); + if ( ! $create_users && $this->version == '1.0' ) + _e( 'assign posts to an existing user:', 'wordpress-importer' ); + else + _e( 'or assign posts to an existing user:', 'wordpress-importer' ); wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) ); echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />'; + + if ( $this->version != '1.0' ) + echo '</div>'; } /** @@ -294,17 +331,24 @@ class WP_Import extends WP_Importer { if ( ! isset( $_POST['imported_authors'] ) ) return; + $create_users = $this->allow_create_users(); + foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) { + $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false; + if ( ! empty( $_POST['user_map'][$i] ) ) { $user = get_userdata( intval($_POST['user_map'][$i]) ); - if ( isset( $user->ID ) ) - $this->processed_authors[$old_login] = $user->ID; - } else if ( $this->allow_create_users() && ! empty($_POST['user_new'][$i]) ) { - $login = sanitize_user( $_POST['user_new'][$i], true ); - $user_id = username_exists( $login ); - if ( ! $user_id ) { + if ( isset( $user->ID ) ) { + if ( $old_id ) + $this->processed_authors[$old_id] = $user->ID; + $this->author_mapping[$old_login] = $user->ID; + } + } else if ( $create_users ) { + if ( ! empty($_POST['user_new'][$i]) ) { + $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() ); + } else if ( $this->version != '1.0' ) { $user_data = array( - 'user_login' => $login, + 'user_login' => $old_login, 'user_pass' => wp_generate_password(), 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '', 'display_name' => $this->authors[$old_login]['author_display_name'], @@ -315,9 +359,11 @@ class WP_Import extends WP_Importer { } if ( ! is_wp_error( $user_id ) ) { - $this->processed_authors[$old_login] = $user_id; + if ( $old_id ) + $this->processed_authors[$old_id] = $user_id; + $this->author_mapping[$old_login] = $user_id; } else { - _e( sprintf( 'Failed to create new user for %s. Their posts will be attributed to the current user.', esc_html( $this->authors[$old_login]['author_display_name'] ) ) ); + 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 ) echo ' ' . $user_id->get_error_message(); echo '<br />'; @@ -325,8 +371,11 @@ class WP_Import extends WP_Importer { } // failsafe: if the user_id was invalid, default to the current user - if ( empty( $this->processed_authors[$old_login] ) ) - $this->processed_authors[$old_login] = (int) get_current_user_id(); + if ( ! isset( $this->author_mapping[$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(); + } } } @@ -361,13 +410,15 @@ class WP_Import extends WP_Importer { if ( ! is_wp_error( $id ) ) { $this->processed_terms[intval($cat['term_id'])] = $id; } else { - echo sprintf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) ); + printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '<br />'; continue; } } + + unset( $this->categories ); } /** @@ -395,13 +446,15 @@ class WP_Import extends WP_Importer { if ( ! is_wp_error( $id ) ) { $this->processed_terms[intval($tag['term_id'])] = $id['term_id']; } else { - echo sprintf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) ); + printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '<br />'; continue; } } + + unset( $this->tags ); } /** @@ -435,13 +488,15 @@ class WP_Import extends WP_Importer { if ( ! is_wp_error( $id ) ) { $this->processed_terms[intval($term['term_id'])] = $id['term_id']; } else { - echo sprintf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) ); + printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '<br />'; continue; } } + + unset( $this->terms ); } /** @@ -455,14 +510,18 @@ class WP_Import extends WP_Importer { function process_posts() { foreach ( $this->posts as $post ) { if ( ! post_type_exists( $post['post_type'] ) ) { - echo sprintf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), - esc_html($post['post_title']), esc_html($post['post_type']) ) . '<br />'; + printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), + esc_html($post['post_title']), esc_html($post['post_type']) ); + echo '<br />'; continue; } if ( isset( $this->processed_posts[$post['post_id']] ) ) continue; + if ( $post['status'] == 'auto-draft' ) + continue; + if ( 'nav_menu_item' == $post['post_type'] ) { $this->process_menu_item( $post ); continue; @@ -490,8 +549,8 @@ class WP_Import extends WP_Importer { // map the post author $author = sanitize_user( $post['post_author'], true ); - if ( isset( $this->processed_authors[$author] ) ) - $author = $this->processed_authors[$author]; + if ( isset( $this->author_mapping[$author] ) ) + $author = $this->author_mapping[$author]; else $author = (int) get_current_user_id(); @@ -513,7 +572,7 @@ class WP_Import extends WP_Importer { } if ( is_wp_error( $post_id ) ) { - echo sprintf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), + printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html($post['post_title']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $post_id->get_error_message(); @@ -541,7 +600,7 @@ class WP_Import extends WP_Importer { if ( ! is_wp_error( $t ) ) { $term_id = $t['term_id']; } else { - echo sprintf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) ); + printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $t->get_error_message(); echo '<br />'; @@ -572,7 +631,7 @@ class WP_Import extends WP_Importer { $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; - $newcomments[$comment_id]['comment_type'] = ! empty( $comment['comment_type'] ) ? $comment['comment_type'] : 'comment'; + $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; } ksort( $newcomments ); @@ -594,16 +653,32 @@ class WP_Import extends WP_Importer { if ( isset( $post['postmeta'] ) ) { foreach ( $post['postmeta'] as $meta ) { $key = apply_filters( 'import_post_meta_key', $meta['key'] ); + $value = false; + + if ( '_edit_last' == $key ) { + if ( isset( $this->processed_authors[intval($meta['value'])] ) ) + $value = $this->processed_authors[intval($meta['value'])]; + else + $key = false; + } + if ( $key ) { // export gets meta straight from the DB so could have a serialized string - $value = maybe_unserialize( $meta['value'] ); + if ( ! $value ) + $value = maybe_unserialize( $meta['value'] ); update_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 + if ( '_thumbnail_id' == $key ) + $this->featured_images[$post_id] = (int) $value; } } } } + + unset( $this->posts ); } /** @@ -641,7 +716,7 @@ class WP_Import extends WP_Importer { $menu_id = term_exists( $menu_slug, 'nav_menu' ); if ( ! $menu_id ) { - _e( sprintf( 'Menu item skipped due to invalid menu slug: %s', esc_html( $menu_slug ) ), 'wordpress-importer' ); + printf( __( 'Menu item skipped due to invalid menu slug: %s', 'wordpress-importer' ), esc_html( $menu_slug ) ); echo '<br />'; return; } else { @@ -842,7 +917,6 @@ class WP_Import extends WP_Importer { */ function backfill_attachment_urls() { global $wpdb; - // make sure we do the longest urls first, in case one is a substring of another uksort( $this->url_remap, array(&$this, 'cmpr_strlen') ); @@ -854,6 +928,21 @@ class WP_Import extends WP_Importer { } } + /** + * Update _thumbnail_id meta to new, imported attachment IDs + */ + function remap_featured_images() { + // cycle through posts that have a featured image + foreach ( $this->featured_images as $post_id => $value ) { + if ( isset( $this->processed_posts[$value] ) ) { + $new_id = $this->processed_posts[$value]; + // only update if there's a difference + if ( $new_id != $value ) + update_post_meta( $post_id, '_thumbnail_id', $new_id ); + } + } + } + /** * Parse a WXR file * @@ -870,6 +959,15 @@ class WP_Import extends WP_Importer { echo '<div class="wrap">'; screen_icon(); echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>'; + + $updates = get_plugin_updates(); + $basename = plugin_basename(__FILE__); + if ( isset( $updates[$basename] ) ) { + $update = $updates[$basename]; + echo '<div class="error"><p><strong>'; + printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version ); + echo '</strong></p></div>'; + } } // Close div.wrap @@ -892,12 +990,12 @@ class WP_Import extends WP_Importer { * Decide if the given meta key maps to information we will want to import * * @param string $key The meta key to check - * @return bool True for keys we do want to save, false if not + * @return string|bool The key if we do want to import, false if not */ function is_valid_meta_key( $key ) { // skip attachment metadata since we'll regenerate it from scratch - // skip _edit_lock and _edit_last as not useful - if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock', '_edit_last' ) ) ) + // skip _edit_lock as not relevant for import + if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) return false; return $key; } @@ -947,16 +1045,16 @@ class WP_Import extends WP_Importer { } } -/** - * WordPress Importer object for registering the import callback - * @global WP_Import $wp_import - */ -$wp_import = new WP_Import(); -register_importer( 'wordpress', 'WordPress', __('Import <strong>posts, pages, comments, custom fields, categories, and tags</strong> from a WordPress export file.', 'wordpress-importer'), array( $wp_import, 'dispatch' ) ); - } // class_exists( 'WP_Importer' ) function wordpress_importer_init() { - load_plugin_textdomain( 'wordpress-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); + load_plugin_textdomain( 'wordpress-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); + + /** + * WordPress Importer object for registering the import callback + * @global WP_Import $wp_import + */ + $GLOBALS['wp_import'] = new WP_Import(); + register_importer( 'wordpress', 'WordPress', __('Import <strong>posts, pages, comments, custom fields, categories, and tags</strong> from a WordPress export file.', 'wordpress-importer'), array( $GLOBALS['wp_import'], 'dispatch' ) ); } -add_action( 'init', 'wordpress_importer_init' ); +add_action( 'admin_init', 'wordpress_importer_init' );