Skip to content
Snippets Groups Projects
Commit 5489cb4b authored by lucha's avatar lucha
Browse files

[auto] plugin: wordpress-importer 0.6.4

parent b9de8022
No related branches found
No related tags found
No related merge requests found
...@@ -437,7 +437,16 @@ class WXR_Parser_Regex { ...@@ -437,7 +437,16 @@ class WXR_Parser_Regex {
} }
function parse( $file ) { function parse( $file ) {
$wxr_version = $in_post = false; $wxr_version = $in_multiline = false;
$multiline_content = '';
$multiline_tags = array(
'item' => array( 'posts', array( $this, 'process_post' ) ),
'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
);
$fp = $this->fopen( $file, 'r' ); $fp = $this->fopen( $file, 'r' );
if ( $fp ) { if ( $fp ) {
...@@ -452,39 +461,37 @@ class WXR_Parser_Regex { ...@@ -452,39 +461,37 @@ class WXR_Parser_Regex {
$this->base_url = $url[1]; $this->base_url = $url[1];
continue; continue;
} }
if ( false !== strpos( $importline, '<wp:category>' ) ) {
preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category );
$this->categories[] = $this->process_category( $category[1] );
continue;
}
if ( false !== strpos( $importline, '<wp:tag>' ) ) {
preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag );
$this->tags[] = $this->process_tag( $tag[1] );
continue;
}
if ( false !== strpos( $importline, '<wp:term>' ) ) {
preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term );
$this->terms[] = $this->process_term( $term[1] );
continue;
}
if ( false !== strpos( $importline, '<wp:author>' ) ) { if ( false !== strpos( $importline, '<wp:author>' ) ) {
preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author ); preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
$a = $this->process_author( $author[1] ); $a = $this->process_author( $author[1] );
$this->authors[$a['author_login']] = $a; $this->authors[$a['author_login']] = $a;
continue; continue;
} }
if ( false !== strpos( $importline, '<item>' ) ) {
$post = ''; foreach ( $multiline_tags as $tag => $handler ) {
$in_post = true; // Handle multi-line tags on a singular line
continue; if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
$this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );
} elseif ( false !== ( $pos = strpos( $importline, "<$tag>" ) ) ) {
// Take note of any content after the opening tag
$multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) );
// We don't want to have this line added to `$is_multiline` below.
$importline = '';
$in_multiline = $tag;
} elseif ( false !== ( $pos = strpos( $importline, "</$tag>" ) ) ) {
$in_multiline = false;
$multiline_content .= trim( substr( $importline, 0, $pos ) );
$this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content );
} }
if ( false !== strpos( $importline, '</item>' ) ) {
$in_post = false;
$this->posts[] = $this->process_post( $post );
continue;
} }
if ( $in_post ) {
$post .= $importline . "\n"; if ( $in_multiline && $importline ) {
$multiline_content .= $importline . "\n";
} }
} }
......
=== WordPress Importer === === WordPress Importer ===
Contributors: wordpressdotorg Contributors: wordpressdotorg
Donate link: https://wordpressfoundation.org/donate/
Tags: importer, wordpress Tags: importer, wordpress
Requires at least: 3.0 Requires at least: 3.6
Tested up to: 4.6 Tested up to: 4.9
Stable tag: 0.6.3 Stable tag: 0.6.4
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: https://www.gnu.org/licenses/gpl-2.0.html
Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file. Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
...@@ -19,7 +20,7 @@ The WordPress Importer will import the following content from a WordPress export ...@@ -19,7 +20,7 @@ The WordPress Importer will import the following content from a WordPress export
* Categories, tags and terms from custom taxonomies * Categories, tags and terms from custom taxonomies
* Authors * Authors
For further information and instructions please see the [Codex page on Importing Content](http://codex.wordpress.org/Importing_Content#WordPress) For further information and instructions please see the [Codex page on Importing Content](https://codex.wordpress.org/Importing_Content#WordPress)
== Installation == == Installation ==
...@@ -38,6 +39,12 @@ If you would prefer to do things manually then follow these instructions: ...@@ -38,6 +39,12 @@ If you would prefer to do things manually then follow these instructions:
== Changelog == == Changelog ==
= 0.6.4 =
* Improve PHP7 compatibility.
* Fix bug that caused slashes to be stripped from imported comments.
* Fix for various deprecation notices including `wp_get_http()` and `screen_icon()`.
* Fix for importing export files with multiline term meta data.
= 0.6.3 = = 0.6.3 =
* Add support for import term metadata. * Add support for import term metadata.
* Fix bug that caused slashes to be stripped from imported content. * Fix bug that caused slashes to be stripped from imported content.
...@@ -45,7 +52,7 @@ If you would prefer to do things manually then follow these instructions: ...@@ -45,7 +52,7 @@ If you would prefer to do things manually then follow these instructions:
* Fix PHP notices. * Fix PHP notices.
= 0.6.2 = = 0.6.2 =
* Add wp_import_existing_post filter. See: https://core.trac.wordpress.org/ticket/33721 * Add `wp_import_existing_post` filter, see [Trac ticket #33721](https://core.trac.wordpress.org/ticket/33721).
= 0.6 = = 0.6 =
* Support for WXR 1.2 and multiple CDATA sections * Support for WXR 1.2 and multiple CDATA sections
...@@ -68,7 +75,7 @@ an export file is uploaded to a server with bad permissions and WordPress 3.3 or ...@@ -68,7 +75,7 @@ an export file is uploaded to a server with bad permissions and WordPress 3.3 or
= 0.3 = = 0.3 =
* Use an XML Parser if possible * Use an XML Parser if possible
* Proper import support for nav menus * Proper import support for nav menus
* ... and much more, see [Trac ticket #15197](http://core.trac.wordpress.org/ticket/15197) * ... and much more, see [Trac ticket #15197](https://core.trac.wordpress.org/ticket/15197)
= 0.1 = = 0.1 =
* Initial release * Initial release
...@@ -99,7 +106,7 @@ A message like "Fatal error: Allowed memory size of 8388608 bytes exhausted" ind ...@@ -99,7 +106,7 @@ A message like "Fatal error: Allowed memory size of 8388608 bytes exhausted" ind
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. 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) -- [WordPress Codex: Importing Content](https://codex.wordpress.org/Importing_Content#Before_Importing)
== Filters == == Filters ==
......
<?php <?php
/* /*
Plugin Name: WordPress Importer Plugin Name: WordPress Importer
Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/ Plugin URI: https://wordpress.org/plugins/wordpress-importer/
Description: 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.
Author: wordpressdotorg Author: wordpressdotorg
Author URI: http://wordpress.org/ Author URI: https://wordpress.org/
Version: 0.6.3 Version: 0.6.4
Text Domain: wordpress-importer Text Domain: wordpress-importer
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/ */
...@@ -786,6 +786,7 @@ class WP_Import extends WP_Importer { ...@@ -786,6 +786,7 @@ class WP_Import extends WP_Importer {
if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) { if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
if ( isset( $inserted_comments[$comment['comment_parent']] ) ) if ( isset( $inserted_comments[$comment['comment_parent']] ) )
$comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
$comment = wp_slash( $comment );
$comment = wp_filter_comment( $comment ); $comment = wp_filter_comment( $comment );
$inserted_comments[$key] = wp_insert_comment( $comment ); $inserted_comments[$key] = wp_insert_comment( $comment );
do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post ); do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
...@@ -881,7 +882,7 @@ class WP_Import extends WP_Importer { ...@@ -881,7 +882,7 @@ class WP_Import extends WP_Importer {
} }
foreach ( $item['postmeta'] as $meta ) foreach ( $item['postmeta'] as $meta )
$$meta['key'] = $meta['value']; ${$meta['key']} = $meta['value'];
if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) { if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) {
$_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)]; $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)];
...@@ -988,7 +989,13 @@ class WP_Import extends WP_Importer { ...@@ -988,7 +989,13 @@ class WP_Import extends WP_Importer {
return new WP_Error( 'upload_dir_error', $upload['error'] ); return new WP_Error( 'upload_dir_error', $upload['error'] );
// fetch the remote url and write it to the placeholder file // fetch the remote url and write it to the placeholder file
$headers = wp_get_http( $url, $upload['file'] ); $remote_response = wp_safe_remote_get( $url, array(
'timeout' => 300,
'stream' => true,
'filename' => $upload['file'],
) );
$headers = wp_remote_retrieve_headers( $remote_response );
// request failed // request failed
if ( ! $headers ) { if ( ! $headers ) {
...@@ -996,10 +1003,12 @@ class WP_Import extends WP_Importer { ...@@ -996,10 +1003,12 @@ class WP_Import extends WP_Importer {
return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') ); return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
} }
$remote_response_code = wp_remote_retrieve_response_code( $remote_response );
// make sure the fetch was successful // make sure the fetch was successful
if ( $headers['response'] != '200' ) { if ( $remote_response_code != '200' ) {
@unlink( $upload['file'] ); @unlink( $upload['file'] );
return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($headers['response']), get_status_header_desc($headers['response']) ) ); return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($remote_response_code), get_status_header_desc($remote_response_code) ) );
} }
$filesize = filesize( $upload['file'] ); $filesize = filesize( $upload['file'] );
...@@ -1048,8 +1057,10 @@ class WP_Import extends WP_Importer { ...@@ -1048,8 +1057,10 @@ class WP_Import extends WP_Importer {
if ( isset( $this->processed_posts[$parent_id] ) ) if ( isset( $this->processed_posts[$parent_id] ) )
$local_parent_id = $this->processed_posts[$parent_id]; $local_parent_id = $this->processed_posts[$parent_id];
if ( $local_child_id && $local_parent_id ) if ( $local_child_id && $local_parent_id ) {
$wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' ); $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
clean_post_cache( $local_child_id );
}
} }
// all other posts/terms are imported, retry menu items with missing associated object // all other posts/terms are imported, retry menu items with missing associated object
...@@ -1115,7 +1126,6 @@ class WP_Import extends WP_Importer { ...@@ -1115,7 +1126,6 @@ class WP_Import extends WP_Importer {
// Display import page title // Display import page title
function header() { function header() {
echo '<div class="wrap">'; echo '<div class="wrap">';
screen_icon();
echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>'; echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';
$updates = get_plugin_updates(); $updates = get_plugin_updates();
...@@ -1206,7 +1216,7 @@ class WP_Import extends WP_Importer { ...@@ -1206,7 +1216,7 @@ class WP_Import extends WP_Importer {
} // class_exists( 'WP_Importer' ) } // class_exists( 'WP_Importer' )
function wordpress_importer_init() { function wordpress_importer_init() {
load_plugin_textdomain( 'wordpress-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); load_plugin_textdomain( 'wordpress-importer' );
/** /**
* WordPress Importer object for registering the import callback * WordPress Importer object for registering the import callback
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment