Welcome to the Movable Type WordPress import utility. Before getting started, we need some information on your Movable Type database.
Now select the Movable Type blog to import to and provide information about your WordPress database.
All right sparky, this is where the actual import takes place! Do you feel lucky today? :p
";
$sql = "SELECT DISTINCT " . $wp_pref ."users.* FROM " . $wp_pref . "users, " . $wp_pref .
"posts WHERE " . $wp_pref . "users.ID=`post_author`";
$result = mysql_query($sql,$resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($result) {
$cnt = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$sql = trim(str_replace("\n","","INSERT INTO mt_author ".
"(author_name, author_password, author_email, author_is_superuser, author_nickname, " .
"author_created_on, author_url)" .
" VALUES ('" . $row['display_name'] . "','".md5("pass") . "','" .
$row['user_email'] . "',0,'" . $row['user_nicename'] . "','".
$row['user_registered'] . "','" . $row['user_url'] . "');"));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resMT);
$arUser[$row['ID']] = $id;
$cnt = $cnt + 1;
}
echo $cnt . " User record(s) imported!
";
} else {
echo "No User records found!
";
}
// get categories
echo "Importing Category records ...
";
$sql = "SELECT * FROM " . $wp_pref . "categories";
$result = mysql_query($sql,$resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($result) {
$cnt = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$sql = trim(str_replace("\n","","INSERT INTO mt_category ".
"(category_blog_id, category_label,category_description,category_basename) " .
"VALUES ('". $mt_blog ."','".mysql_escape_string($row['cat_name']) .
"','".mysql_escape_string($row['category_description'])."','" .
$row['category_nicename'] . "');"));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resMT);
$arCat[$row['cat_ID']] = $id;
$cnt = $cnt + 1;
}
echo $cnt . " Category record(s) imported!
";
} else {
echo "No Category records found!
";
}
// get entries for blog
echo "Importing Entry records ...
";
$sql = "SELECT * FROM " . $wp_pref . "posts";
$result = mysql_query($sql,$resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($result) {
$cnt = 0;
$cntCom = 0;
$cntCat = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// author ID must be switched to new author ID
$aid = $arUser[$row['post_author']];
// category ID must be switched to new category ID
$cid = $arCat[$row['post_category']];
if (!$cid) {
$cid = '1';
}
$name = str_replace(' ', '', substr($row['post_title'],0,15)) . $row['ID'];
$week = date("YW", strtotime($row['post_date']));
$sql = "INSERT INTO mt_entry " .
"(entry_author_id, entry_blog_id, entry_category_id, entry_basename, entry_title," .
"entry_text, entry_created_on, entry_allow_comments, entry_allow_pings, " .
"entry_convert_breaks, entry_status, entry_excerpt, entry_week_number) " .
"VALUES (" . $aid . "," . $mt_blog . "," . $cid . ",'" .
$row['post_name'] . "','" . mysql_escape_string($row['post_title']) .
"','" . mysql_escape_string($row['post_content']) . "','" . $row['post_date'];
// set comments status
if (($row['comment_status'] == 'open') || ($row['comment_status'] == 'registered_only')) {
$sql .= "',1,";
} else {
$sql .= "',0,";
}
// set ping status
if ($row['ping_status'] == 'open') {
$sql .= "1,";
} else {
$sql .= "0,";
}
// set line break conversion status
$sql .= "'__default__',";
// set entry status, 1-Unpulished, 2-Published
if ($row['post_status'] == 'publish') {
$sql .= "2,'";
} else if ($row['post_status'] == 'draft') {
$sql .= "1,'";
}
$sql .= mysql_escape_string($row['post_excerpt']) . "','" . $week . "');";
$sql = trim(str_replace("\n","", $sql));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resMT);
$eid = $row['ID'];
$cnt = $cnt + 1;
if (($cnt % 100) == 0) {
// flush written records - just for safety
$sql = "COMMIT";
$res = mysql_query($sql, $resMT);
}
echo " Added record ID - $eid
";
// get comments for entry
$sql = "SELECT * FROM " . $wp_pref . "comments WHERE comment_post_ID=" . $eid;
$res = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($res) {
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$sql = trim(str_replace("\n","","INSERT INTO mt_comment ".
"(comment_blog_id, comment_entry_id, comment_author, " .
"comment_email, comment_ip, comment_url, comment_text, comment_visible," .
"comment_created_on) " .
"VALUES (" . $mt_blog . "," . $id. ",'" . mysql_escape_string($row['comment_author']) .
"','" . mysql_escape_string($row['comment_author_email']) .
"','" . mysql_escape_string($row['comment_author_IP']) .
"','" . mysql_escape_string($row['comment_author_url']) .
"','" . mysql_escape_string($row['comment_content']) .
"',1,'" . $row['comment_date'] . "');"));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$cntCom = $cntCom + 1;
}
}
// get categories for entry
$cntTmp = 0;
$sql = "SELECT * FROM " . $wp_pref . "post2cat WHERE post_id=" . $eid;
$res = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($res) {
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$tid = $arCat[$row['category_id']];
$sql = "INSERT INTO mt_placement ".
"(placement_blog_id, placement_category_id, placement_entry_id, placement_is_primary) " .
"VALUES (" . $mt_blog . "," . $tid . "," . $id . ",";
if ($cntTmp == 0) {
$sql .= '1';
} else {
$sql .= '0';
}
$sql .= ");";
$sql = trim(str_replace("\n","", $sql));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$cntCat = $cntCat + 1;
$cntTmp = $cntTmp + 1;
}
}
if ($cntTmp == 0) {
// No categories defined in WP - put it in the default category
$sql = trim(str_replace("\n","","INSERT INTO mt_placement " .
"(placement_blog_id, placement_category_id, placement_entry_id, placement_is_primary) " .
"VALUES (" . $mt_blog . "," . $tid . "," . $id . ",1);"));
$q = mysql_query($sql, $resMT) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$cntCat = $cntCat + 1;
}
}
echo $cnt . " Entry record(s) imported!
";
echo " " . $cntCom . " Comment record(s) imported!
";
echo " " . $cntCat . " Entry Category record(s) imported!
";
} else {
echo "No Entry records found!
";
}
mysql_close($resMT);
mysql_close($resWP);
echo "That's all folks!";
break;
}
?>