'.sprintf(__('Go to Authors & Users, where you can modify the new user(s) or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.'), 'users.php', '_parent').'
';
- echo '
'.__('For security, click the link below to reset this importer.').'
';
- echo '
';
- }
-
- // Figures out what to do, then does it.
- function start() {
- if ( isset($_POST['restart']) )
- $this->restart();
-
- $options = get_option('blogger_importer');
-
- if ( is_array($options) )
- foreach ( $options as $key => $value )
- $this->$key = $value;
-
- if ( isset( $_REQUEST['blog'] ) ) {
- $blog = is_array($_REQUEST['blog']) ? array_shift( $keys = array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
- $blog = (int) $blog;
- $result = $this->import_blog( $blog );
- if ( is_wp_error( $result ) )
- echo $result->get_error_message();
- } elseif ( isset($_GET['token']) )
- $this->auth();
- elseif ( isset($this->token) && $this->token_is_valid() )
- $this->show_blogs();
- else
- $this->greet();
-
- $saved = $this->save_vars();
-
- if ( $saved && !isset($_GET['noheader']) ) {
- $restart = __('Restart');
- $message = __('We have saved some information about your Blogger account in your WordPress database. Clearing this information will allow you to start over. Restarting will not affect any posts you have already imported. If you attempt to re-import a blog, duplicate posts and comments will be skipped.');
- $submit = esc_attr__('Clear account information');
- echo "
'.__('Howdy! This importer allows you to extract posts from Blogware XML export file into your site. Pick a Blogware file to upload and click Import.').'
'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from DotClear, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'
';
- echo '
'.__('Users').'
';
- echo '
'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn’t have that login in DotClear, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and DotClear uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Log in and change it.'), '/wp-login.php').'
';
- echo '
'.__('Preserving Authors').'
';
- echo '
'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'
';
- echo '
'.__('Textile').'
';
- echo '
'.__('Also, since you’re coming from DotClear, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me… You’ll want it.').'
';
- echo '
'.__('WordPress Resources').'
';
- echo '
'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'
';
- return new WP_Error( 'insert_post_failed', __( 'Failed to create post.' ) );
- }
-
- // Handle all the metadata for this post
- $this->insert_postmeta( $post_id, $post );
- }
- echo '';
- }
-
- // Convert lj-user tags to links to that user
- function translate_lj_user( $str ) {
- return preg_replace( '||', '$1', $str );
- }
-
- function insert_postmeta( $post_id, $post ) {
- // Need the original LJ id for comments
- add_post_meta( $post_id, 'lj_itemid', $post['itemid'] );
-
- // And save the permalink on LJ in case we want to link back or something
- add_post_meta( $post_id, 'lj_permalink', $post['url'] );
-
- // Supports the following "props" from LJ, saved as lj_ in wp_postmeta
- // Adult Content - adult_content
- // Location - current_coords + current_location
- // Mood - current_mood (translated from current_moodid)
- // Music - current_music
- // Userpic - picture_keyword
- foreach ( array( 'adult_content', 'current_coords', 'current_location', 'current_moodid', 'current_music', 'picture_keyword' ) as $prop ) {
- if ( !empty( $post['props'][$prop] ) ) {
- if ( 'current_moodid' == $prop ) {
- $prop = 'current_mood';
- $val = $this->moods[ $post['props']['current_moodid'] ];
- } else {
- $val = $post['props'][$prop];
- }
- add_post_meta( $post_id, 'lj_' . $prop, $val );
- }
- }
- }
-
- // Set up a session (authenticate) with LJ
- function get_session() {
- // Get a session via XMLRPC
- $cookie = $this->lj_ixr( 'sessiongenerate', array( 'ver' => 1, 'expiration' => 'short' ) );
- if ( is_wp_error( $cookie ) )
- return new WP_Error( 'cookie', __( 'Could not get a cookie from LiveJournal. Please try again soon.' ) );
- return new WP_Http_Cookie( array( 'name' => 'ljsession', 'value' => $cookie['ljsession'] ) );
- }
-
- // Loops through and gets comment meta from LJ in batches
- function download_comment_meta() {
- $cookie = $this->get_session();
- if ( is_wp_error( $cookie ) )
- return $cookie;
-
- // Load previous state (if any)
- $this->usermap = (array) get_option( 'ljapi_usermap' );
- $maxid = get_option( 'ljapi_maxid' ) ? get_option( 'ljapi_maxid' ) : 1;
- $highest_id = get_option( 'ljapi_highest_id' ) ? get_option( 'ljapi_highest_id' ) : 0;
-
- // We need to loop over the metadata request until we have it all
- while ( $maxid > $highest_id ) {
- // Now get the meta listing
- $results = wp_remote_get( $this->comments_url . '?get=comment_meta&startid=' . ( $highest_id + 1 ),
- array( 'cookies' => array( $cookie ), 'timeout' => 20 ) );
- if ( is_wp_error( $results ) )
- return new WP_Error( 'comment_meta', __( 'Failed to retrieve comment meta information from LiveJournal. Please try again soon.' ) );
-
- $results = wp_remote_retrieve_body( $results );
-
- // Get the maxid so we know if we have them all yet
- preg_match( '|(\d+)|', $results, $matches );
- if ( 0 == $matches[1] ) {
- // No comment meta = no comments for this journal
- echo '
' . __( 'You have no comments to import!' ) . '
';
- update_option( 'ljapi_highest_id', 1 );
- update_option( 'ljapi_highest_comment_id', 1 );
- return false; // Bail out of comment importing entirely
- }
- $maxid = !empty( $matches[1] ) ? $matches[1] : $maxid;
-
- // Parse comments and get highest id available
- preg_match_all( '| $highest_id )
- $highest_id = $id;
- }
-
- // Parse out the list of user mappings, and add it to the known list
- preg_match_all( '||', $results, $matches );
- foreach ( $matches[1] as $count => $userid )
- $this->usermap[$userid] = $matches[2][$count]; // need this in memory for translating ids => names
-
- wp_cache_flush();
- }
- // endwhile - should have seen all comment meta at this point
-
- update_option( 'ljapi_usermap', $this->usermap );
- update_option( 'ljapi_maxid', $maxid );
- update_option( 'ljapi_highest_id', $highest_id );
-
- echo '
mt-export.txt in your /wp-content/ directory and then click “Import mt-export.txt”.' ); ?>
-
-
-
-
out of memory error try splitting up the import file into pieces.'); ?>
-
-footer();
- }
-
- function users_form($n) {
- $users = get_users_of_blog();
-?>
- 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 to check the authorname and do the mapping
- function checkauthor($author) {
- //mtnames is an array with the names in the mt import file
- $pass = wp_generate_password();
- if (!(in_array($author, $this->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 get_mt_authors() {
- $temp = array();
- $authors = array();
-
- $handle = $this->fopen($this->file, 'r');
- if ( $handle == null )
- return false;
-
- $in_comment = false;
- while ( $line = $this->fgets($handle) ) {
- $line = trim($line);
-
- if ( 'COMMENT:' == $line )
- $in_comment = true;
- else if ( '-----' == $line )
- $in_comment = false;
-
- if ( $in_comment || 0 !== strpos($line,"AUTHOR:") )
- continue;
-
- $temp[] = trim( substr($line, strlen("AUTHOR:")) );
- }
-
- //we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.
- $authors[0] = array_shift($temp);
- $y = count($temp) + 1;
- for ($x = 1; $x < $y; $x ++) {
- $next = array_shift($temp);
- if (!(in_array($next, $authors)))
- array_push($authors, $next);
- }
-
- $this->fclose($handle);
-
- return $authors;
- }
-
- function get_authors_from_post() {
- $formnames = array ();
- $selectnames = array ();
-
- foreach ($_POST['user'] as $key => $line) {
- $newname = trim(stripslashes($line));
- if ($newname == '')
- $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form.
- array_push($formnames, $newname);
- } // $formnames is the array with the form entered names
-
- foreach ($_POST['userselect'] as $user => $key) {
- $selected = trim(stripslashes($key));
- array_push($selectnames, $selected);
- }
-
- $count = count($formnames);
- for ($i = 0; $i < $count; $i ++) {
- if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form
- array_push($this->newauthornames, "$selectnames[$i]");
- } else {
- array_push($this->newauthornames, "$formnames[$i]");
- }
- }
- }
-
- function mt_authors_form() {
-?>
-
-
-
-
-
italics. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.'); ?>
manage those links.'), $link_count, $cat_id, 'link-manager.php') ?>
-
-" . __("You need to supply your OPML url. Press back on your browser and try again") . "\n";
-} // end else
-
-if ( ! $blogrolling )
- do_action( 'wp_delete_file', $opml_url);
- @unlink($opml_url);
-?>
-
'.__('Howdy! This importer allows you to extract posts from an RSS 2.0 file into your WordPress site. This is useful if you want to import your posts from a system that is not handled by a custom import tool. Pick an RSS file to upload and click Import.').'
'.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'
';
- echo '
'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'
';
- echo '
'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'
';
- echo '
'.__('Don’t be stupid - backup your database before proceeding!').'
';
-
- // read in all the STP tag -> post settings
- $posts = $this->get_stp_posts();
-
- // if we didn't get any tags back, that's all there is folks!
- if ( !is_array($posts) ) {
- echo '
' . __('No posts were found to have tags!') . '
';
- return false;
- }
- else {
- // if there's an existing entry, delete it
- if ( get_option('stpimp_posts') ) {
- delete_option('stpimp_posts');
- }
-
- add_option('stpimp_posts', $posts);
- $count = count($posts);
- echo '
' . sprintf( _n('Done! %s tag to post relationships were read.', 'Done! %s tags to post relationships were read.', $count), $count ) . '
';
- }
-
- echo '';
- echo '
';
- }
-
-
- function import_t2p ( ) {
- echo '
';
- echo '
'.__('Adding Tags to Posts…').'
';
-
- // run that funky magic!
- $tags_added = $this->tag2post();
-
- echo '
' . sprintf( _n('Done! %s tag was added!', 'Done! %s tags were added!', $tags_added), $tags_added ) . '
';
- echo '';
- echo '
';
- }
-
- function get_stp_posts ( ) {
- global $wpdb;
- // read in all the posts from the STP post->tag table: should be wp_post2tag
- $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
- $posts = $wpdb->get_results($posts_query);
- return $posts;
- }
-
- function tag2post ( ) {
- global $wpdb;
-
- // get the tags and posts we imported in the last 2 steps
- $posts = get_option('stpimp_posts');
-
- // null out our results
- $tags_added = 0;
-
- // loop through each post and add its tags to the db
- foreach ( $posts as $this_post ) {
- $the_post = (int) $this_post->post_id;
- $the_tag = $wpdb->escape($this_post->tag_name);
- // try to add the tag
- wp_add_post_tags($the_post, $the_tag);
- $tags_added++;
- }
-
- // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
- return $tags_added;
- }
-
- function cleanup_import ( ) {
- delete_option('stpimp_posts');
- $this->done();
- }
-
- function done ( ) {
- echo '
';
- echo '
'.__('Import Complete!').'
';
- echo '
' . __('OK, so we lied about this being a 4-step program! You’re done!') . '
';
- echo '
' . __('Now wasn’t that easy?') . '
';
- echo '
';
- }
-
- function STP_Import ( ) {
- // Nothing.
- }
-}
-
-// create the import object
-$stp_import = new STP_Import();
-
-// add it to the import page!
-register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch'));
-?>
diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php
deleted file mode 100644
index be5f72eedd..0000000000
--- a/wp-admin/import/textpattern.php
+++ /dev/null
@@ -1,691 +0,0 @@
-get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
- }
-}
-
-if(!function_exists('link_exists'))
-{
- /**
- * Check whether link already exists.
- *
- * @package WordPress
- * @subpackage Textpattern_Import
- *
- * @param string $linkname
- * @return int
- */
- function link_exists($linkname)
- {
- global $wpdb;
- return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) );
- }
-}
-
-/**
- * TextPattern Importer Class
- *
- * @since unknown
- */
-class Textpattern_Import {
-
- function header()
- {
- echo '
';
- screen_icon();
- echo '
'.__('Import Textpattern').'
';
- echo '
'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'
';
- }
-
- function footer()
- {
- echo '
';
- }
-
- function greet() {
- echo '
';
- echo '
'.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this site.').'
';
- echo '
'.__('This has not been tested on previous versions of Textpattern. Mileage may vary.').'
';
- echo '
'.__('Your Textpattern Configuration settings are as follows:').'
';
- echo '';
- echo '
';
- }
-
- function get_txp_cats()
- {
- global $wpdb;
- // General Housekeeping
- $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
- set_magic_quotes_runtime(0);
- $prefix = get_option('tpre');
-
- // Get Categories
- return $txpdb->get_results('SELECT
- id,
- name,
- title
- FROM '.$prefix.'txp_category
- WHERE type = "article"',
- ARRAY_A);
- }
-
- function get_txp_users()
- {
- global $wpdb;
- // General Housekeeping
- $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
- set_magic_quotes_runtime(0);
- $prefix = get_option('tpre');
-
- // Get Users
-
- return $txpdb->get_results('SELECT
- user_id,
- name,
- RealName,
- email,
- privs
- FROM '.$prefix.'txp_users', ARRAY_A);
- }
-
- function get_txp_posts()
- {
- // General Housekeeping
- $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
- set_magic_quotes_runtime(0);
- $prefix = get_option('tpre');
-
- // Get Posts
- return $txpdb->get_results('SELECT
- ID,
- Posted,
- AuthorID,
- LastMod,
- Title,
- Body,
- Excerpt,
- Category1,
- Category2,
- Status,
- Keywords,
- url_title,
- comments_count
- FROM '.$prefix.'textpattern
- ', ARRAY_A);
- }
-
- function get_txp_comments()
- {
- global $wpdb;
- // General Housekeeping
- $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
- set_magic_quotes_runtime(0);
- $prefix = get_option('tpre');
-
- // Get Comments
- return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A);
- }
-
- function get_txp_links()
- {
- //General Housekeeping
- $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
- set_magic_quotes_runtime(0);
- $prefix = get_option('tpre');
-
- return $txpdb->get_results('SELECT
- id,
- date,
- category,
- url,
- linkname,
- description
- FROM '.$prefix.'txp_link',
- ARRAY_A);
- }
-
- function cat2wp($categories='')
- {
- // General Housekeeping
- global $wpdb;
- $count = 0;
- $txpcat2wpcat = array();
- // Do the Magic
- if(is_array($categories))
- {
- echo '
'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'
';
- echo '
'.__('Users').'
';
- echo '
'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn’t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So log in and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'
';
- echo '
'.__('Preserving Authors').'
';
- echo '
'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'
';
- echo '
'.__('Textile').'
';
- echo '
'.__('Also, since you’re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You’ll want it.').'
';
- echo '
'.__('WordPress Resources').'
';
- echo '
'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'
'.__('Howdy! This imports tags from Ultimate Tag Warrior 3 into WordPress tags.').'
';
- echo '
'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'
';
- echo '
'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'
';
- echo '
'.__('Don’t be stupid - backup your database before proceeding!').'
' . __('If you don’t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '
';
-
-
- }
-
- echo '';
- echo '
';
- }
-
-
- function import_posts ( ) {
- echo '
';
- echo '
'.__('Reading UTW Post Tags…').'
';
-
- // read in all the UTW tag -> post settings
- $posts = $this->get_utw_posts();
-
- // if we didn't get any tags back, that's all there is folks!
- if ( !is_array($posts) ) {
- echo '
';
-
- // run that funky magic!
- $tags_added = $this->tag2post();
-
- echo '
' . sprintf( _n( 'Done! %s tag were added!', 'Done! %s tags were added!', $tags_added ), $tags_added ) . '
';
-
- echo '';
- echo '
';
-
- }
-
-
- function get_utw_tags ( ) {
-
- global $wpdb;
-
- // read in all the tags from the UTW tags table: should be wp_tags
- $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
-
- $tags = $wpdb->get_results($tags_query);
-
- // rearrange these tags into something we can actually use
- foreach ( $tags as $tag ) {
-
- $new_tags[$tag->tag_id] = $tag->tag;
-
- }
-
- return $new_tags;
-
- }
-
- function get_utw_posts ( ) {
-
- global $wpdb;
-
- // read in all the posts from the UTW post->tag table: should be wp_post2tag
- $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
-
- $posts = $wpdb->get_results($posts_query);
-
- return $posts;
-
- }
-
-
- function tag2post ( ) {
-
- // get the tags and posts we imported in the last 2 steps
- $tags = get_option('utwimp_tags');
- $posts = get_option('utwimp_posts');
-
- // null out our results
- $tags_added = 0;
-
- // loop through each post and add its tags to the db
- foreach ( $posts as $this_post ) {
-
- $the_post = (int) $this_post->post_id;
- $the_tag = (int) $this_post->tag_id;
-
- // what's the tag name for that id?
- $the_tag = $tags[$the_tag];
-
- // screw it, just try to add the tag
- wp_add_post_tags($the_post, $the_tag);
-
- $tags_added++;
-
- }
-
- // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
- return $tags_added;
-
-
- }
-
-
- function cleanup_import ( ) {
-
- delete_option('utwimp_tags');
- delete_option('utwimp_posts');
-
- $this->done();
-
- }
-
-
- function done ( ) {
-
- echo '
';
- echo '
'.__('Import Complete!').'
';
-
- echo '
' . __('OK, so we lied about this being a 5-step program! You’re done!') . '
';
-
- echo '
' . __('Now wasn’t that easy?') . '
';
-
- echo '
';
-
- }
-
-
- function UTW_Import ( ) {
-
- // Nothing.
-
- }
-
-}
-
-
-// create the import object
-$utw_import = new UTW_Import();
-
-// add it to the import page!
-register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into WordPress tags.'), array($utw_import, 'dispatch'));
-
-?>
diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php
deleted file mode 100644
index 1f46a2697b..0000000000
--- a/wp-admin/import/wordpress.php
+++ /dev/null
@@ -1,898 +0,0 @@
-';
- screen_icon();
- echo '
'.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.').'
';
- echo '
'.__('Choose a WordPress WXR file to upload, then click Upload file and import.').'
';
- printf(__('Post %s already exists.'), stripslashes($post_title));
- $comment_post_ID = $post_id = $post_exists;
- } else {
-
- // If it has parent, process parent first.
- $post_parent = (int) $post_parent;
- if ($post_parent) {
- // if we already know the parent, map it to the local ID
- if ( isset( $this->post_ids_processed[$post_parent] ) ) {
- $post_parent = $this->post_ids_processed[$post_parent]; // new ID of the parent
- }
- else {
- // record the parent for later
- $this->orphans[intval($post_ID)] = $post_parent;
- }
- }
-
- echo '
';
-
- $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
-
- $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password');
- $postdata['import_id'] = $post_ID;
- if ($post_type == 'attachment') {
- $remote_url = $this->get_tag( $post, 'wp:attachment_url' );
- if ( !$remote_url )
- $remote_url = $guid;
-
- $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
- if ( !$post_id or is_wp_error($post_id) )
- return $post_id;
- }
- else {
- printf(__('Importing post %s...') . "\n", stripslashes($post_title));
- $comment_post_ID = $post_id = wp_insert_post($postdata);
- if ( $post_id && $is_sticky == 1 )
- stick_post( $post_id );
-
- }
-
- if ( is_wp_error( $post_id ) )
- return $post_id;
-
- // Memorize old and new ID.
- if ( $post_id && $post_ID ) {
- $this->post_ids_processed[intval($post_ID)] = intval($post_id);
- }
-
- // Add categories.
- if (count($categories) > 0) {
- $post_cats = array();
- foreach ($categories as $category) {
- if ( '' == $category )
- continue;
- $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
- $cat = get_term_by('slug', $slug, 'category');
- $cat_ID = 0;
- if ( ! empty($cat) )
- $cat_ID = $cat->term_id;
- if ($cat_ID == 0) {
- $category = $wpdb->escape($category);
- $cat_ID = wp_insert_category(array('cat_name' => $category));
- if ( is_wp_error($cat_ID) )
- continue;
- }
- $post_cats[] = $cat_ID;
- }
- wp_set_post_categories($post_id, $post_cats);
- }
-
- // Add tags.
- if (count($tags) > 0) {
- $post_tags = array();
- foreach ($tags as $tag) {
- if ( '' == $tag )
- continue;
- $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
- $tag_obj = get_term_by('slug', $slug, 'post_tag');
- $tag_id = 0;
- if ( ! empty($tag_obj) )
- $tag_id = $tag_obj->term_id;
- if ( $tag_id == 0 ) {
- $tag = $wpdb->escape($tag);
- $tag_id = wp_insert_term($tag, 'post_tag');
- if ( is_wp_error($tag_id) )
- continue;
- $tag_id = $tag_id['term_id'];
- }
- $post_tags[] = intval($tag_id);
- }
- wp_set_post_tags($post_id, $post_tags);
- }
- }
-
- // Now for comments
- preg_match_all('|(.*?)|is', $post, $comments);
- $comments = $comments[1];
- $num_comments = 0;
- $inserted_comments = array();
- if ( $comments) {
- foreach ($comments as $comment) {
- $comment_id = $this->get_tag( $comment, 'wp:comment_id');
- $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
- $newcomments[$comment_id]['comment_author'] = $this->get_tag( $comment, 'wp:comment_author');
- $newcomments[$comment_id]['comment_author_email'] = $this->get_tag( $comment, 'wp:comment_author_email');
- $newcomments[$comment_id]['comment_author_IP'] = $this->get_tag( $comment, 'wp:comment_author_IP');
- $newcomments[$comment_id]['comment_author_url'] = $this->get_tag( $comment, 'wp:comment_author_url');
- $newcomments[$comment_id]['comment_date'] = $this->get_tag( $comment, 'wp:comment_date');
- $newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag( $comment, 'wp:comment_date_gmt');
- $newcomments[$comment_id]['comment_content'] = $this->get_tag( $comment, 'wp:comment_content');
- $newcomments[$comment_id]['comment_approved'] = $this->get_tag( $comment, 'wp:comment_approved');
- $newcomments[$comment_id]['comment_type'] = $this->get_tag( $comment, 'wp:comment_type');
- $newcomments[$comment_id]['comment_parent'] = $this->get_tag( $comment, 'wp:comment_parent');
- }
- // Sort by comment ID, to make sure comment parents exist (if there at all)
- ksort($newcomments);
- foreach ($newcomments as $key => $comment) {
- // if this is a new post we can skip the comment_exists() check
- if ( !$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date']) ) {
- if (isset($inserted_comments[$comment['comment_parent']]))
- $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
- $comment = wp_filter_comment($comment);
- $inserted_comments[$key] = wp_insert_comment($comment);
- $num_comments++;
- }
- }
- }
-
- if ( $num_comments )
- printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);
-
- // Now for post meta
- preg_match_all('|(.*?)|is', $post, $postmeta);
- $postmeta = $postmeta[1];
- if ( $postmeta) { foreach ($postmeta as $p) {
- $key = $this->get_tag( $p, 'wp:meta_key' );
- $value = $this->get_tag( $p, 'wp:meta_value' );
- $value = stripslashes($value); // add_post_meta() will escape.
- // get_post_meta would have done this but we read straight from the db on export so we could have a serialized string
- $value = maybe_unserialize($value);
-
- $this->process_post_meta($post_id, $key, $value);
-
- } }
-
- do_action('import_post_added', $post_id);
- print "
\n";
- }
-
- function process_post_meta($post_id, $key, $value) {
- // the filter can return false to skip a particular metadata key
- $_key = apply_filters('import_post_meta_key', $key);
- if ( $_key ) {
- add_post_meta( $post_id, $_key, $value );
- do_action('import_post_meta', $post_id, $_key, $value);
- }
- }
-
- function process_attachment($postdata, $remote_url) {
- if ($this->fetch_attachments and $remote_url) {
- printf( __('Importing attachment %s... '), htmlspecialchars($remote_url) );
-
- // If the URL is absolute, but does not contain http, upload it assuming the base_site_url variable
- if ( preg_match('/^\/[\w\W]+$/', $remote_url) )
- $remote_url = rtrim($this->base_url,'/').$remote_url;
-
- $upload = $this->fetch_remote_file($postdata, $remote_url);
- if ( is_wp_error($upload) ) {
- printf( __('Remote file error: %s'), htmlspecialchars($upload->get_error_message()) );
- return $upload;
- }
- else {
- print '('.size_format(filesize($upload['file'])).')';
- }
-
- if ( 0 == filesize( $upload['file'] ) ) {
- print __( "Zero length file, deleting" ) . "\n";
- unlink( $upload['file'] );
- return;
- }
-
- if ( $info = wp_check_filetype($upload['file']) ) {
- $postdata['post_mime_type'] = $info['type'];
- }
- else {
- print __('Invalid file type');
- return;
- }
-
- $postdata['guid'] = $upload['url'];
-
- // as per wp-admin/includes/upload.php
- $post_id = wp_insert_attachment($postdata, $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) ) {
- $parts = pathinfo($remote_url);
- $ext = $parts['extension'];
- $name = basename($parts['basename'], ".{$ext}");
- $this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url;
- }
-
- return $post_id;
- }
- else {
- printf( __('Skipping attachment %s'), htmlspecialchars($remote_url) );
- }
- }
-
- function fetch_remote_file( $post, $url ) {
- add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
-
- $upload = wp_upload_dir($post['post_date']);
-
- // 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']);
- if ( $upload['error'] ) {
- echo $upload['error'];
- return new WP_Error( 'upload_dir_error', $upload['error'] );
- }
-
- // fetch the remote url and write it to the placeholder file
- $headers = wp_get_http($url, $upload['file']);
-
- //Request failed
- if ( ! $headers ) {
- @unlink($upload['file']);
- return new WP_Error( 'import_file_error', __('Remote server did not respond') );
- }
-
- // make sure the fetch was successful
- if ( $headers['response'] != '200' ) {
- @unlink($upload['file']);
- return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %1$d %2$s'), $headers['response'], get_status_header_desc($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'];
- $this->url_remap[$post['guid']] = $upload['url'];
- // if the remote url is redirected somewhere else, keep track of the destination too
- if ( $headers['x-final-location'] != $url )
- $this->url_remap[$headers['x-final-location']] = $upload['url'];
-
- return $upload;
-
- }
-
- /**
- * Bump up the request timeout for http requests
- *
- * @param int $val
- * @return int
- */
- function bump_request_timeout( $val ) {
- return 60;
- }
-
- // sort by strlen, longest string first
- function cmpr_strlen($a, $b) {
- return strlen($b) - strlen($a);
- }
-
- // update url references in post bodies to point to the new local files
- function backfill_attachment_urls() {
-
- // make sure we do the longest urls first, in case one is a substring of another
- uksort($this->url_remap, array(&$this, 'cmpr_strlen'));
-
- global $wpdb;
- foreach ($this->url_remap as $from_url => $to_url) {
- // remap urls in post_content
- $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, '%s', '%s')", $from_url, $to_url) );
- // remap enclosure urls
- $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, '%s', '%s') WHERE meta_key='enclosure'", $from_url, $to_url) );
- }
- }
-
- // update the post_parent of orphans now that we know the local id's of all parents
- function backfill_parents() {
- global $wpdb;
-
- foreach ($this->orphans as $child_id => $parent_id) {
- $local_child_id = $local_parent_id = false;
- if ( isset( $this->post_ids_processed[$child_id] ) )
- $local_child_id = $this->post_ids_processed[$child_id];
- if ( isset( $this->post_ids_processed[$parent_id] ) )
- $local_parent_id = $this->post_ids_processed[$parent_id];
-
- if ($local_child_id and $local_parent_id) {
- $wpdb->update($wpdb->posts, array('post_parent' => $local_parent_id), array('ID' => $local_child_id) );
- }
- }
- }
-
- function is_valid_meta_key($key) {
- // skip attachment metadata since we'll regenerate it from scratch
- if ( $key == '_wp_attached_file' || $key == '_wp_attachment_metadata' )
- return false;
- 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_start() {
- wp_defer_term_counting(true);
- wp_defer_comment_counting(true);
- do_action('import_start');
- }
-
- function import_end() {
- do_action('import_end');
-
- // clear the caches after backfilling
- foreach ($this->post_ids_processed as $post_id)
- clean_post_cache($post_id);
-
- wp_defer_term_counting(false);
- wp_defer_comment_counting(false);
- }
-
- function import($id, $fetch_attachments = false) {
- $this->id = (int) $id;
- $this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments);
-
- add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
- $file = get_attached_file($this->id);
- $this->import_file($file);
- }
-
- function import_file($file) {
- $this->file = $file;
-
- $this->import_start();
- $this->get_authors_from_post();
- wp_suspend_cache_invalidation(true);
- $this->get_entries();
- $this->process_categories();
- $this->process_tags();
- $this->process_terms();
- $result = $this->process_posts();
- wp_suspend_cache_invalidation(false);
- $this->backfill_parents();
- $this->backfill_attachment_urls();
- $this->import_end();
-
- if ( is_wp_error( $result ) )
- return $result;
- }
-
- function handle_upload() {
- $file = wp_import_handle_upload();
- if ( isset($file['error']) ) {
- echo '
' . sprintf( _n( 'Convert Category to Tag.', 'Convert Categories (%d) to Tags.', $cat_num ), $cat_num ) . '
';
- echo '
';
- echo '
' . __('Hey there. Here you can selectively convert existing categories to tags. To get started, check the categories you wish to be converted, then click the Convert button.') . '
';
- echo '
' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '
' . sprintf( _n( 'Convert Tag to Category.', 'Convert Tags (%d) to Categories.', $tags_num ), $tags_num ) . '
';
- echo '
';
- echo '
' . __('Here you can selectively convert existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '
';
- echo '
' . __('The newly created categories will still be associated with the same posts.') . '
' . sprintf( __('* This category is also a tag. The converter has added that tag to all posts currently in the category. If you want to remove it, please confirm that all tags were added successfully, then delete it from the Manage Categories page.'), 'categories.php') . '
';
- echo '
' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag' ) . '
';
- }
-
- function convert_tags() {
- global $wpdb;
-
- if ( (!isset($_POST['tags_to_convert']) || !is_array($_POST['tags_to_convert'])) && empty($this->tags_to_convert)) {
- echo '
' . sprintf( __('* This tag is also a category. The converter has added all posts from it to the category. If you want to remove it, please confirm that all posts were added successfully, then delete it from the Manage Tags page.'), 'edit-tags.php') . '
';
- echo '
' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag&step=3' ) . '
';
- }
-
- function init() {
-
- $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
-
- $this->header();
-
- if ( current_user_can('manage_categories') ) {
-
- switch ($step) {
- case 1 :
- $this->categories_tab();
- break;
-
- case 2 :
- check_admin_referer('import-cat2tag');
- $this->convert_categories();
- break;
-
- case 3 :
- $this->tags_tab();
- break;
-
- case 4 :
- check_admin_referer('import-cat2tag');
- $this->convert_tags();
- break;
- }
- }
-
- $this->footer();
- }
-
- function WP_Categories_to_Tags() {
- // Do nothing.
- }
-}
-
-$wp_cat2tag_importer = new WP_Categories_to_Tags();
-
-register_importer('wp-cat2tag', __('Categories and Tags Converter'), __('Convert existing categories to tags or tags to categories, selectively.'), array(&$wp_cat2tag_importer, 'init'));
-
-?>