X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7688c6ba71852cd89123b62b2d57683535e4702a..refs/tags/wordpress-2.9:/wp-admin/import/wordpress.php
diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php
index d15f3a43..83c90acf 100644
--- a/wp-admin/import/wordpress.php
+++ b/wp-admin/import/wordpress.php
@@ -1,18 +1,41 @@
XML fragment, [1] => New post ID]
+ var $post_ids_processed = array ();
+ var $orphans = array ();
var $file;
var $id;
var $mtnames = array ();
var $newauthornames = array ();
+ var $allauthornames = array ();
+
+ var $author_ids = array ();
+ var $tags = array ();
+ var $categories = array ();
+ var $terms = array ();
+
var $j = -1;
+ var $fetch_attachments = false;
+ var $url_remap = array ();
function header() {
echo '
';
+ screen_icon();
echo '
'.__('Import WordPress').'
';
}
@@ -28,7 +51,7 @@ class WP_Import {
function greet() {
echo '
';
- echo '
'.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, comments, custom fields, and categories into this blog.').'
';
+ echo '
'.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this blog.').'
';
echo '
'.__('Choose a WordPress WXR file to upload, then click Upload file and import.').'
';
@@ -42,61 +65,54 @@ class WP_Import {
return $return;
}
- function users_form($n) {
- global $wpdb, $testing;
- $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users ORDER BY user_login");
-?>
- 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
- }
+ function fopen($filename, $mode='r') {
+ if ( $this->has_gzip() )
+ return gzopen($filename, $mode);
+ return fopen($filename, $mode);
+ }
+
+ function feof($fp) {
+ if ( $this->has_gzip() )
+ return gzeof($fp);
+ return feof($fp);
+ }
- return $user_id;
+ function fgets($fp, $len=8192) {
+ if ( $this->has_gzip() )
+ return gzgets($fp, $len);
+ return fgets($fp, $len);
}
- function get_entries() {
+ function fclose($fp) {
+ if ( $this->has_gzip() )
+ return gzclose($fp);
+ return fclose($fp);
+ }
+
+ function get_entries($process_post_func=NULL) {
set_magic_quotes_runtime(0);
- $this->posts = array();
- $this->categories = array();
- $this->tags = array();
- $num = 0;
$doing_entry = false;
+ $is_wxr_file = false;
- $fp = fopen($this->file, 'r');
+ $fp = $this->fopen($this->file, 'r');
if ($fp) {
- while ( !feof($fp) ) {
- $importline = rtrim(fgets($fp));
+ while ( !$this->feof($fp) ) {
+ $importline = rtrim($this->fgets($fp));
+
+ // this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
+ if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) )
+ $is_wxr_file = true;
+ if ( false !== strpos($importline, '') ) {
+ preg_match('|(.*?)|is', $importline, $url);
+ $this->base_url = $url[1];
+ continue;
+ }
if ( false !== strpos($importline, '') ) {
preg_match('|(.*?)|is', $importline, $category);
$this->categories[] = $category[1];
@@ -107,45 +123,37 @@ class WP_Import {
$this->tags[] = $tag[1];
continue;
}
+ if ( false !== strpos($importline, '') ) {
+ preg_match('|(.*?)|is', $importline, $term);
+ $this->terms[] = $term[1];
+ continue;
+ }
if ( false !== strpos($importline, '') ) {
- $this->posts[$num] = '';
+ $this->post = '';
$doing_entry = true;
continue;
}
if ( false !== strpos($importline, '') ) {
- $num++;
$doing_entry = false;
+ if ($process_post_func)
+ call_user_func($process_post_func, $this->post);
continue;
}
if ( $doing_entry ) {
- $this->posts[$num] .= $importline . "\n";
- }
- }
-
- foreach ($this->posts as $post) {
- $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
- if ($post_ID) {
- $this->posts_processed[$post_ID][0] = &$post;
- $this->posts_processed[$post_ID][1] = 0;
+ $this->post .= $importline . "\n";
}
}
- fclose($fp);
+ $this->fclose($fp);
}
+
+ return $is_wxr_file;
+
}
function get_wp_authors() {
- $temp = array ();
- $i = -1;
- foreach ($this->posts as $post) {
- if ('' != trim($post)) {
- ++ $i;
- $author = $this->get_tag( $post, 'dc:creator' );
- array_push($temp, "$author"); //store the extracted author names in a temporary array
- }
- }
-
// 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.
+ $temp = $this->allauthornames;
$authors[0] = array_shift($temp);
$y = count($temp) + 1;
for ($x = 1; $x < $y; $x ++) {
@@ -158,71 +166,133 @@ class WP_Import {
}
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");
- }
+ global $current_user;
- $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]");
+ // this will populate $this->author_ids with a list of author_names => user_ids
+
+ foreach ( $_POST['author_in'] as $i => $in_author_name ) {
+
+ if ( !empty($_POST['user_select'][$i]) ) {
+ // an existing user was selected in the dropdown list
+ $user = get_userdata( intval($_POST['user_select'][$i]) );
+ if ( isset($user->ID) )
+ $this->author_ids[$in_author_name] = $user->ID;
+ }
+ elseif ( $this->allow_create_users() ) {
+ // nothing was selected in the dropdown list, so we'll use the name in the text field
+
+ $new_author_name = trim($_POST['user_create'][$i]);
+ // if the user didn't enter a name, assume they want to use the same name as in the import file
+ if ( empty($new_author_name) )
+ $new_author_name = $in_author_name;
+
+ $user_id = username_exists($new_author_name);
+ if ( !$user_id ) {
+ $user_id = wp_create_user($new_author_name, wp_generate_password());
+ }
+
+ $this->author_ids[$in_author_name] = $user_id;
+ }
+
+ // failsafe: if the user_id was invalid, default to the current user
+ if ( empty($this->author_ids[$in_author_name]) ) {
+ $this->author_ids[$in_author_name] = intval($current_user->ID);
}
}
+
}
function wp_authors_form() {
?>
admins entries.'); ?>
-
- allow_create_users() ) {
+ echo '
'.__('If a new user is created by WordPress, a password will be randomly generated. Manually change the user’s details if necessary.')."
\n";
+ }
$authors = $this->get_wp_authors();
- echo '';
echo '';
- echo '';
}
+ function users_form($n, $author) {
+
+ if ( $this->allow_create_users() ) {
+ printf(' ');
+ }
+ else {
+ echo __('Map to existing').' ';
+ }
+
+ // keep track of $n => $author name
+ echo '';
+
+ $users = get_users_of_blog();
+?>
+ '.__('Sorry, there has been an error.').'';
- echo '
';
- printf(__('Post %s already exists.'), stripslashes($post_title));
+ 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 ($parent = $this->posts_processed[$post_parent]) {
- if (!$parent[1]) {
- $result = $this->process_post($parent[0]); // If not yet, process the parent first.
- if ( is_wp_error( $result ) )
- return $result;
+ if ($post_parent) {
+ // if we already know the parent, map it to the local ID
+ if ( $parent = $this->post_ids_processed[$post_parent] ) {
+ $post_parent = $parent; // new ID of the parent
+ }
+ else {
+ // record the parent for later
+ $this->orphans[intval($post_ID)] = $post_parent;
}
- $post_parent = $parent[1]; // New ID of the parent;
}
echo '