summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2011-04-20 02:39:24 +0300
committerTheo Chatzimichos <tampakrap@gentoo.org>2011-04-20 02:39:24 +0300
commitf7473515da3333b21b699f9c4b3c1674b7172271 (patch)
tree0616a2f980ddff7d069fd36653e222b64c9379a8 /plugins/wordpress-importer
parentImprove sample entry for themes in the update-wordpress script (diff)
downloadblogs-gentoo-f7473515da3333b21b699f9c4b3c1674b7172271.tar.gz
blogs-gentoo-f7473515da3333b21b699f9c4b3c1674b7172271.tar.bz2
blogs-gentoo-f7473515da3333b21b699f9c4b3c1674b7172271.zip
Update wordpress-importer and smart-youtube
Diffstat (limited to 'plugins/wordpress-importer')
-rw-r--r--plugins/wordpress-importer/parsers.php10
-rw-r--r--plugins/wordpress-importer/readme.txt49
-rw-r--r--plugins/wordpress-importer/wordpress-importer.php60
3 files changed, 97 insertions, 22 deletions
diff --git a/plugins/wordpress-importer/parsers.php b/plugins/wordpress-importer/parsers.php
index 17247296..87c3b9d9 100644
--- a/plugins/wordpress-importer/parsers.php
+++ b/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'] ) )
@@ -211,7 +214,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',
@@ -525,6 +528,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(
@@ -551,6 +558,7 @@ 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' ),
);
}
}
diff --git a/plugins/wordpress-importer/readme.txt b/plugins/wordpress-importer/readme.txt
index 06689a0d..554232f4 100644
--- a/plugins/wordpress-importer/readme.txt
+++ b/plugins/wordpress-importer/readme.txt
@@ -4,38 +4,81 @@ Donate link:
Tags: importer, wordpress
Requires at least: 3.0
Tested up to: 3.1
-Stable tag: 0.2
+Stable tag: 0.4
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.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.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/plugins/wordpress-importer/wordpress-importer.php b/plugins/wordpress-importer/wordpress-importer.php
index 36285e20..966182ac 100644
--- a/plugins/wordpress-importer/wordpress-importer.php
+++ b/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.4
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 );
@@ -393,7 +394,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 +410,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 +438,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 +448,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 +476,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 +492,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 )
@@ -566,6 +573,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 +654,8 @@ 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'];
+ if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
+ $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
}
ksort( $newcomments );
@@ -667,7 +690,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 +823,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 +845,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 +888,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'];