WordPress

pMachine 2.0 import - DEBUG MODE (display only)":"DIRECT MODE (databases will be changed)"); ?>

This script imports your entries from pMachine 2.0 into WordPress in the following order:

  1. Categories & users
  2. Posts & comments

BACKUP YOUR EXISTING PMACHINE AND WP SETUPS BEFORE CONTINUING. Use at your own risk.

To run this, you first need to edit this file (import-pmachine2.php) and enter pMachine database details. Let's check if the database connection information works...

DB Connection verified, OK.

When ready, proceed to Step 1: import categories & users.

You can also skip directly to Step 2: import posts & comments if you have already done step 1 and for some reason aborted/stopped.

It looks like your database information is incorrect. Please re-edit this file and double-check all the settings.

Step 1: categories & users

(scroll down results to proceed to Step 2)

Importing $nb_categories categories from $pm_weblog..."; echo "

"; while ($category = mysql_fetch_array($categories)) { echo "[" . $category['id'] . " : " . $category['category'] . "] "; $nice_category = strtolower(str_replace(' ','-',$category['category'])); $query = "INSERT INTO $tablecategories (cat_name, category_nicename, category_description, category_parent) VALUES ('". $category['category'] . "', '$nice_category' ,'','0')"; echo "$query
"; if ($debug_mode=="0") { $result = mysql_query($query, $connection) or die("Invalid query: " . mysql_error()); } } echo "
"; //Import users // ----------------------------------------------------- // Determine how many users in WP. Should be 1 (super-admin) when brand-new install. $wp_users = mysql_query('SELECT * FROM wp_users', $connection); $wp_nb_users = mysql_num_rows($wp_users); // How many users already in WP. $users = mysql_query('SELECT * FROM pm_members', $connection); $nb_users = mysql_num_rows($users); // How many users already in pM. echo "

Importing $nb_users users from $pm_weblog in pMachine to the existing $wp_nb_users users in WP...

"; echo "
"; while ($user = mysql_fetch_array($users)) { // ID, user_login, user_pass, user_firstname, user_lastname, user_nickname, // user_icq, user_email, user_url, user_ip, user_domain, user_browser, // dateYMDhour, user_level, user_aim, user_msn, user_yim, user_idmode, user_description echo "Adding ". $user['username'] . " (" . $user['email'] . ")...
"; // Users in pMachine we care about: Active Users (status=3) and Admin Users (status=8) // If user is level 8 in pMachine, we assign Admin super-user level in WP (10), otherwise we assign 3 (active) $wp_login = $user['username']; $wp_pass = substr($user['password'],0,6); $wp_nickname = $user['username']; $wp_icq = $user['icq']; $wp_email = $user['email']; $wp_url = $user['url']; $wp_ip = $user['ipaddress']; $wp_domain = ''; $wp_browser = ''; $wp_dateYMDhour = date("Y-m-d H:i:s", ($user['joindate'])); $wp_level = ($user['status'] == 8 ? 10 : 3 ); // if the user being imported is admin, set level to 10, otherwise to 3 $wp_aim = $user['aol_im']; $wp_msn = $user['msn_im']; $wp_yim = $user['yahoo_im']; $wp_idmode = 'nickname'; if (!get_magic_quotes_gpc()) { $wp_description = addslashes($user['bio'] . "\nLocation: " . $user['location'] . "\nOccupation: " . $user['occupation'] . "\nInterests: " . $user['interests']) ; } else { $wp_description = $user['bio'] . "\nLocation: " . $user['location'] . "\nOccupation: " . $user['occupation'] . "\nInterests: " . $user['interests'] ; } $query = "INSERT INTO $tableusers ( user_login, user_pass, user_nickname, user_icq, user_email, user_url, user_ip, user_domain, user_browser, dateYMDhour, user_level, user_aim, user_msn, user_yim, user_idmode, user_description ) VALUES ( '$wp_login', '$wp_pass', '$wp_nickname', '$wp_icq', '$wp_email', '$wp_url', '$wp_ip', '$wp_domain', '$wp_browser', '$wp_dateYMDhour', '$wp_level', '$wp_aim', '$wp_msn', '$wp_yim', '$wp_idmode', '$wp_description')"; echo "$query

"; if ($debug_mode=="0") { $result = mysql_query($query, $connection) or die("Invalid query: " . mysql_error()); } } echo "

"; echo "

Categories and members imported OK.

When ready, proceed to Step 2: import posts & comments.

"; break; case 2: ?>

Step 2: posts & comments

Importing $nb_posts posts..."; echo "
"; echo "$query

"; while ($post = mysql_fetch_array($posts)) { // post_id, member_id, t_stamp, title, blurb, body, more, custom1, custom2, custom3, // status, month, year, day, weblog, category, c_total, c_date, c_hits, m_hits, preview, // nl2brBlurb, nl2brBody, nl2brMore, nl2brC1, nl2brC2, nl2brC3 $posted = date("Y-m-d H:i:s",$post['t_stamp']); $title = $post['title']; // Combine pMachine's blurb, body and more as you wish, don't forget you can also use // WP Template Tags (http://wiki.wordpress.org/index.php/TemplateTags) in the templates // to better reproduce your pMachine setup if (!get_magic_quotes_gpc()) { $content = addslashes($post['body'] . "

" . $post['more']); $excerpt = addslashes($post['blurb']); } else { $content = $post['body'] . "

" . $post['more']; $excerpt = $post['blurb']; } $post_name = sanitize_title($title); // Find category IDs equivalencies // this could be optimized by putting it in an array instead of making a query everytime $query = "SELECT pm.id, wpc.category_nicename, pm.category, wpc.cat_ID, wpc.cat_name FROM wp_categories as wpc, pm_categories as pm WHERE (LOWER(REPLACE(pm.category,' ','-'))=wpc.category_nicename) AND (pm.id='" . $post['category'] . "')"; $equiv_cats = mysql_query($query, $connection); $equiv_cat = mysql_fetch_array($equiv_cats); $category = $equiv_cat['cat_ID']; if ($one_user_blog_id == "1") { $post_author_id = $one_user_blog_id; } else { $post_author_id = $wp_nb_users+$post['member_id']; } echo "Calculating category equivalency for this post : pMachine (" . $equiv_cat['id'] . ") = WP (" . $equiv_cat['cat_ID'] . ")
$query

"; $query = "INSERT INTO $tableposts (post_author, post_date, post_content, post_title, post_category, post_excerpt, post_name, post_status, post_modified) VALUES ('$post_author_id', '$posted', '$content', '$title', '$category', '$excerpt', '$post_name', 'publish', '$posted')"; echo "Inserting post "$title"
"; echo "$query

"; if ($debug_mode=="0") { $result = mysql_query($query, $connection) or die("Invalid query: " . mysql_error()); } // Get wordpress post id $wp_post_ID = $wpdb->get_var("SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1"); // Insert category in the multiple categories table. pMachine has 1 category/post so, 1 cat is inserted. $query = "INSERT INTO wp_post2cat (post_id, category_id) VALUES ('$wp_post_ID', '$category')"; echo "Inserting category for this post : " . $equiv_cat['cat_name'] . "
$query

"; if ($debug_mode=="0") { $result = mysql_query($query, $connection) or die("Invalid query: " . mysql_error()); } // Now let's insert comments if there are any for the PM post $pm_id = $post['post_id']; $comments = mysql_query("SELECT * FROM pm_comments WHERE (post_id = $pm_id)"); if ($comments) { while($comment = mysql_fetch_object($comments)) { if ( substr($comment->member_id,0,2)=="NM" ) { // if comment from non-member, fetch its info - ATTENTION: id has "NM" prefix $query = "SELECT id, signature, email, url, ipaddress FROM pm_nonmembers WHERE id='" . substr($comment->member_id,2,2) . "'"; echo "**** Comment by non-member $comment->signature
$query

"; $comment_author_infos = mysql_query($query); $comment_author_info = mysql_fetch_object($comment_author_infos); $comment_author = $comment_author_info->signature; $comment_ip = $comment_author_info->ipaddress; } else { // if comment from member, fetch its info $query = "SELECT id, username, email url FROM pm_members WHERE id='" . $comment->member_id . "'"; echo "**** Comment by member $comment->username
$query

"; $comment_author_infos = mysql_query($query); $comment_author_info = mysql_fetch_object($comment_author_infos); $comment_author = $comment_author_info->username; $comment_ip = ''; } $comment_time = $comment->t_stamp; if (!get_magic_quotes_gpc()) { $comment_body = addslashes($comment->body); } else { $comment_body = $comment->body; } // comment_id, post_id, member_id, t_stamp, body, weblog, preview // For some reason here "posted" is a real MySQL date, so we don't have to do anything about it $query = "INSERT INTO $tablecomments ( comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content ) VALUES ( $wp_post_ID, '$comment_author', '$comment_author_info->email', '$comment_author_info->url', '$comment_ip', '" . date("Y-m-d H:i:s",$comment_time) . "', '$comment_body')"; echo "  $query

"; if ($debug_mode=="0") { $result = mysql_query($query, $connection) or die("Invalid query: " . mysql_error()); } } // comments loop } // comments condition } // posts loop // upgrade_all(); ?>

All done. Wasn’t that fun? Have fun.