This script imports your entries from pMachine 2.0 into WordPress in the following order:
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.
Importing $nb_categories categories from $pm_weblog..."; echo "
Categories and members imported OK.
When ready, proceed to Step 2: import posts & comments.
"; break; case 2: ?>"; 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 = "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.