wpusers = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users"); $s->wpcats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories"); $step = $_GET['step']; if (!$step) $step = 0; switch ($step) { case "0": _header(); ?>
This script imports your entries from Pivot into WordPress, preserving as much info as we humanly can.
The import will be done in three steps:
Before we continue, make sure that you've got the pivot/ directory (containing at least the db/ directory structure and the pv_cfg_settings.php file) inside your wordpress/ directory. If it's not there, please edit this file (import-pivot.php) before continuing!
In fact, it's so important, I'll check right now and complain if anything is missing...
Danger, Will Robinson!All right sparky! The files are there, we're ready to rock and roll!
Allright, this is what we'll do: I'm going to show you a list of active users that I've found. You can tell me what I should do with every user: either match it to an existing WordPress user, or create a new WordPress user (keeping the Pivot username and password).
At installation time, WordPress creates a user named admin with full privileges; you should map your Administration-user in Pivot to this user. You can always grant a higher userlevel to existing users after we're done importing.
Also, you cannot create a new WordPress users from a Pivot user if the Pivot username already exists in WordPress. If I encounter two matching usernames, I'll pre-select the right WordPress users for you.
If I encounter more usernames during the import (which is possible, since Pivot lets you delete users while keeping their posts), I'll create new WordPress users to match; those users will not be able to log in or post to your weblog until you promote them and give them a sensible password.
If you get any error messages (especially database errors), you might want to go back to the selection list and try the matching process again.
$id) { if ($id > 0) { $s->pivotusers[$match]->wp_id = $id; //echo "Match! '$match' is '$id'Trying to insert user $match...
";
$id = $s->pivotusers[$match]->wp_id = insertuser($s->pivotusers[$match]);
//echo "Insert! '$match' is '$id'
\n";
if ($id) echo "...Succes!";
else echo "...seems to have failed!";
echo "
If there were no errors, we'll continue to the next step: importing the posts. Whenever you think you're ready, take a deap breath, buckle up, brace yourself, cover your ears, pet your lucky rabbit paw, and let her rip!
I'm going to import the posts, which might take a while. If you receive a timeout message, just hit the refresh / reload button in your browser, and I should be able to continue where I was interrupted.
We're done!
//print_r(parseFile("$dbdir/standard-00000/00008.php")); break; case "s": echo '' . print_r($s,true) . ''; break; } function getPivotUsers () { global $pivotdir; $config = file("$pivotdir/pv_cfg_settings.php"); foreach ($config as $line) { if (preg_match('/^user-([^!]+)!(.*)$/', $line, $m)) { $username = &$m[1]; $data = explode('|-|', $m[2]); foreach ($data as $datapart) { list($key,$val) = explode('|', $datapart); $users[$username]->$key = $val; } } } return $users; } function insertuser($user) { global $wpdb, $s; // if the user is there, return the ID foreach ($s->wpusers as $wpuser) { if ($wpuser->user_login == $user->username) { return $wpuser->ID; } } // new user $user_nice = $user->nick ? sanitize_title($user->nick) : sanitize_title($user->username); $idmode = ($user->nick && ($user->nick != $user->username)) ? 'nickname' : 'login'; $now = gmdate('Y-m-d H:i:s'); $level = isset($user->userlevel) ? $user->userlevel : 0; $level = ($level == 4) ? 10 : 1; $wpdb->query("INSERT INTO $wpdb->users (user_login, user_pass, user_email, user_nickname, user_nicename, user_registered, user_level, user_idmode) VALUES ('$user->username', '$user->pass', '$user->email', '$user->nick', '$user_nice', '$now', $level, '$idmode') "); // update user cache $s->wpusers = $wpdb->get_results("SELECT ID,user_login FROM $wpdb->users"); // return return $wpdb->insert_id; } function insertcategory ($category) { global $wpdb, $s; // if the category is there, just return the id and be done with it foreach ($s->wpcats as $wpcat) { if ($wpcat->cat_name == $category) return $wpcat->cat_ID; } // Not there, insert and return insert_id $cat_nicename = sanitize_title($category); $wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename, category_parent) VALUES ('$category', '$cat_nicename', 0) "); $s->wpcats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories"); // return return $wpdb->insert_id; } function parseFile ($theFile) { $serialized_data = trim(implode("", file($theFile))); $serialized_data = str_replace("", "", $serialized_data); if (@$data = unserialize($serialized_data)) { return $data; } else { $temp_serialized_data = preg_replace("/\r\n/", "\n", $serialized_data); if (@$data = unserialize($temp_serialized_data)) { return $data; } else { $temp_serialized_data = preg_replace("/\n/", "\r\n", $serialized_data); if (@$data = unserialize($temp_serialized_data)) { return $data; } else { return false; } } } } function ProcessPost($theFile) { global $wpdb; /* date_gmt post_content post_title post_category post_excerpt post_status (publish) comment_status (open) ping_status (open) post_password post_name to_ping pinged post_modified post_modified_gmt post_content_filtered post_parent guid menu_order */ // date $post_date = $theFile['date']; $post_date = explode('-', $post_date); $post_date_gmt = date('Y-m-d H:i:s', mktime($post_date[3], $post_date[4], 0, $post_date[1], $post_date[2], $post_date[0]) - 3600); $post_date = date('Y-m-d H:i:s', mktime($post_date[3], $post_date[4], 0, $post_date[1], $post_date[2], $post_date[0])); // body $post_content = addslashes($theFile['introduction']); if ($theFile['body']) $post_content .= "\n\n" . addslashes($theFile['body']); // excerpt $post_excerpt = ''; if ($theFile['body'] && $theFile['introduction']) $post_excerpt = addslashes($theFile['introduction']); // title $post_title = addslashes($theFile['title']); $post_name = sanitize_title($post_title); // author if ($s->pivotusers[($theFile['user'])]->wp_id) { $post_author = $s->pivotusers[($theFile['user'])]->wp_id; } else { // user not there, insert him // whip up a fake user first $user->username = $theFile['user']; $user->pass = '***'; $user->level = 0; // insert the user, add him to the list $post_author = insertuser($user); $s->pivotusers[($theFile['user'])]->wp_id = $post_author; } // status if ($theFile['status'] == 'hold') { $status = 'draft'; } else { $status = 'publish'; } // Check if (!$wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'")) { // not in there $query = ("INSERT INTO $wpdb->posts ( post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt) VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$excerpt', '$status', 'open', 'open', '$post_name','$post_date', '$post_date_gmt') "); //echo $query; $wpdb->query($query); $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'"); echo "