WordPress 1.2 Import script * @author: James Sasitorn * @email camus@onegoodcookie.com * * This file should be put in wp-admin/ * * 1. I assume Nucleus and WordPress share the same mysql database * 2. It allows you to only import one nucleus blog at a time * 3. It imports users, posts, and comments based on unique titles. * 4. It doesnt correctly import blog settings (not a big deal) * 5. User names are imported as Nicknames (doesnt fill in First/last) * 6. It doesnt handle Nucleus karma. * * * 2005.02.14: added table prefix listed below $table_prefix for * nueclues table prefix.. Would be better to put this in the gui * * * also cleaned up a typo in the insertion of categories.. * * stopped that pesky 'We're done. have fun' from being on all screens * * stored blog_id from nucleus as session_var. * Should put table_prefix as a html option * * 2005.03.11: Integrate changes by Naoki Haga (kyodai.com) * * Changes improve user mapping and comment handling * * Story details includes both the excerpt \n\n and the content * * Set default user level to 0 */ if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php."); require_once('../wp-config.php'); require('upgrade-functions.php'); /* configuration.. nucleus table prefix.. blah_nucleus_.. */ //$tbl_prefix="ta_"; $tbl_prefix=""; $step = $_GET['step']; if (!$step) $step = 0; if (isset ($_POST['import_blog_id'])) { $import_blog_id = $_POST['import_blog_id']; session_register('import_blog_id'); } ?> WordPress — Nucleus Conversion

WordPress

Welcome to WordPress. Since you’re upgrading from Nucelus thins will change a bit. Here are some notes on upgrading:

Have you looked at the readme? If you’re all ready, let’s go!

Step 1

Okay first we’re going to set up the links database. You will need to choose which blog you will be importing. We will import the categories, posts, members and comments from this blog. We will not import any blog settings. You will need to do that manually.

Checking for tables...

Select the blog to import.

'; $sql = "SELECT * from ${tbl_prefix}nucleus_blog order by bnumber"; $result = $wpdb->get_results($sql) or print ("Can't query ${tbl_prefix}nucleus_blog
" .$sql ."
" . mysql_error()); ?>

Step 2

Deleting older posts...

"; $wpdb->query($query); $query = "TRUNCATE $tablecomments"; echo $query ."
"; $wpdb->query($query); $query = "TRUNCATE $tableposts"; echo $query ."
"; $wpdb->query($query); $query = "TRUNCATE $tablepost2cat"; echo $query ."
"; $wpdb->query($query); $query = "DELETE FROM $tableusers WHERE ID>1"; echo $query ."
"; $wpdb->query($query); $query = "ALTER TABLE $tableusers AUTO_INCREMENT=2"; echo $query ."
"; $wpdb->query($query); ?>

First we’re going to import categories.

get_results($sql); foreach ($result as $category) { // See if the category exists yet $category->cdesc = str_replace("'", "\\'", $category->cdesc); $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '{$category->cname}'"); if ($cat_id) { echo ".. '{$category->cname}' already exists
\n"; } else if (!$cat_id) { //lowest is 1 $cat_nicename = sanitize_title($category->cname); $query = "INSERT INTO $tablecategories(cat_name,category_nicename,category_description) VALUES ('{$category->cname}', '$cat_nicename', '{$category->cdesc}')"; echo $query ."
"; echo ".. Adding '{$category->cname}'
\n"; $wpdb->query($query); //now map the category for later $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '{$category->cname}'"); //TODO: insert in map } $category_map[$category->catid] = $cat_id; $did_category = 1; } //print_r($category_map); //die; ?>

Next we’re going to import nucleus members.

get_results($sql); foreach ($result as $user) { // See if the category exists yet $user_id = $wpdb->get_var("SELECT ID from $tableusers WHERE user_login = '{$user->mname}'"); if ($user_id != 1) { //lowest is 1 and we auto map that to admin $user->mnotes = str_replace("'", "\\'", $user->mnotes); $query = "INSERT INTO $tableusers (user_login, user_nickname, user_pass,user_email, user_url, ". " user_description, user_domain, user_ip, user_level, user_idmode) VALUES ". " ('{$user->mname}', '{$user->mrealname}', '{$user->mpassword}','{$user->memail}', '{$user->murl}', ". " '{$user->mnotes}', '127.0.0.1','127.0.0.1', 0, 'nickname' )"; //echo $query ."
"; echo ".. Importing {$user->mname}
"; $wpdb->query($query); //now map the user for later $user_id = $wpdb->get_var("SELECT ID from $tableusers WHERE user_login = '{$user->mname}'"); } $user_map[$user->mnumber] = $user_id; $username_map[$user->mnumber] = $user->mname; $usermail_map[$user->mnumber] = $user->memail; $did_members = 1; } ?>

Next we’re going to import nucleus posts.

get_results($sql); foreach ($result as $post) { $post_title = addslashes($post->ititle); $post_id = $wpdb->get_var("SELECT ID from $tableposts WHERE post_title = '$post_title'"); $post_category = $category_map[$post->icat]; if (!$post_id) { if (trim($post->imore) != "") { $post_excerpt = addslashes($post->ibody); $post_content = $post_excerpt ."\n\n". addslashes($post->imore); } else { $post_excerpt = ''; $post_content = addslashes($post->ibody); } $post_excerpt = str_replace("
","", $post_excerpt); $post_content = str_replace("
","", $post_content); $post_excerpt = trim($post_excerpt); $post_content = trim($post_content); $post_date = strtotime($post->itime); $post_date = date('Y-m-d H:i:s', $post_date); $post_date_gmt = get_gmt_from_date("$post_date"); if ($post->iclosed) { $comment_status = 'closed'; } else { $comment_status = 'open'; } if ($post->idraft) { $post_status = 'draft'; } else { $post_status = 'publish'; } $post_author = $user_map[$post->iauthor]; $post_name = sanitize_title($post->ititle); //echo "--- $post_content
\n"; $query =<< "; $wpdb->query($query); $post_id = $wpdb->get_var("SELECT ID from $tableposts WHERE post_title = '$post_title'"); } $post_map[$post->inumber] = $post_id; //make sure post is linked $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_id AND category_id = $post_category"); if (!$exists) { $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_id, $post_category) "); } } //foreach post also add comments $sql = "SELECT * from ${tbl_prefix}nucleus_comment WHERE cblog=$import_blog_id order by cnumber"; $result = $wpdb->get_results($sql); foreach ($result as $comment) { $comment_content = addslashes($comment->cbody); $comment_id = $wpdb->get_var("SELECT comment_ID FROM $tablecomments WHERE comment_date = '{$comment->ctime}' AND comment_content = '$comment_content'"); if (!$comment_id) { $comment_author = addslashes($comment->cuser); $comment_author_email = addslashes($comment->cmail); if ($comment->cmember) { $cmember = $user_map[$comment->cmember]; $comment_author = $username_map[$comment->cmember]; $comment_author_email = $usermail_map[$comment->cmember]; } else { $cmember = 0; } $comment_post_ID = $post_map[$comment->citem]; $comment_date = strtotime($comment->ctime); $comment_date = date('Y-m-d H:i:s', $comment_date); $comment_date_gmt = get_gmt_from_date("$comment_date"); $query =<<cip}') EOF; //echo "$query
"; $wpdb->query($query); $comment_id = $wpdb->get_var("SELECT comment_ID FROM $tablecomments WHERE comment_date = '{$comment->ctime}' AND comment_content = '$comment_content'"); //unused } } echo "

Looks like we are done now. Have fun!

"; } ?>