Welcome to the WordPress b2evolution import utility. Before getting started, we need some information on your b2evolution database.
Now select the b2evolution blog to import 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 : " . $sql);
if ($result) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$filepath_wp = $row['option_value']."/";
}
$filepath_b2 = "http://".$_POST['b2url']."/media/";
echo "b2Evolution file path: ".$filepath_b2."
";
echo "WordPress file path: ".$filepath_wp."
";
*/
/*
// get authors for blog
echo "Importing User records ...
";
$sql = "SELECT DISTINCT evo_users.* FROM evo_users, evo_posts WHERE " .
"evo_users.`ID`=`post_author` AND `user_login`<>'admin'";
$result = mysql_query($sql,$resB2) 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 `". $wp_pref ."users` ".
"(`user_login`,`user_pass`,`user_firstname`,`user_lastname`,`user_nickname`,`user_icq`," .
"`user_email`,`user_url`,`user_ip`,`user_domain`,`user_browser`,`user_registered`,`user_level`," .
"`user_aim`,`user_msn`,`user_yim`,`user_idmode`)" .
" VALUES ('".$row['user_login']."','".$row['user_pass']."','".$row['user_firstname']."','".$row['user_lastname']."','".$row['user_nickname']."','".$row['user_icq']."','" .
$row['user_email']."','".$row['user_url']."','".$row['user_ip']."','".$row['user_domain']."','".$row['user_browser']."','".$row['dateYMDhour']."','".$row['user_level']."','".
$row['user_aim']."','".$row['user_msn']."','".$row['user_yim']."','".$row['user_idmode']."');"));
$q = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resWP);
$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 evo_categories";
$result = mysql_query($sql,$resB2) 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 `". $wp_pref ."categories` ".
"(`cat_name`,`category_nicename`,`category_description`)" .
" VALUES ('". mysql_escape_string($row['cat_name']) ."','".mysql_escape_string($row['cat_description'])."','".mysql_escape_string($row['cat_longdesc'])."');"));
$q = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resWP);
$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 evo_posts";
$result = mysql_query($sql,$resB2) 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']];
$aid = 1; //Set to Admin User.
// category ID must be switched to new category ID
//$cid = $arCat[$row['post_category']];
//if (!$cid) {
// $cid = '1';
//}
$cid = 0; //設定為 "未分類"
// status mapping
$stat = $row['post_status'];
if ($stat == 'published') {
$stat = 'publish';
} else if ($stat == 'deprecated') {
$stat = 'publish';
} else if ($stat == 'protected') {
$stat = 'private';
} else if ($stat == 'private') {
$stat = 'private';
} else if ($stat == 'draft') {
$stat = 'draft';
}
// update urls in the post content
$post_content = $row['post_content'];
$post_content = str_replace($filepath_b2, $filepath_wp, $post_content);
$sql = trim(str_replace("\n","","INSERT INTO `". $wp_pref ."posts` ".
"(`post_author`,`post_date`,`post_content`,`post_title`,`post_category`,`post_status`)" .
" VALUES ('".$aid."','".$row['post_issue_date']."','".mysql_escape_string($post_content)."','" .
mysql_escape_string($row['post_title'])."','".$cid."','".$stat."');"));
echo "$sql
";
$q = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$id = mysql_insert_id($resWP);
$eid = $row['ID'];
$cnt = $cnt + 1;
// get comments for entry
$sql = "SELECT * FROM evo_comments WHERE comment_post_ID=" . $eid;
$res = mysql_query($sql, $resB2) 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 `". $wp_pref ."comments` ".
"(`comment_post_ID`,`comment_author`,`comment_author_email`," .
"`comment_author_url`,`comment_author_IP`,`comment_date`," .
"`comment_content`,`comment_karma`)" .
" VALUES ('".$id."','" . mysql_escape_string($row['comment_author']) . "','" . mysql_escape_string($row['comment_author_email']) .
"','" . mysql_escape_string($row['comment_author_url']) . "','" . $row['comment_author_IP'] . "','" . $row['comment_date'] .
"','" . mysql_escape_string($row['comment_content'])."','". $row['comment_karma'] ."');"));
$q = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$cntCom = $cntCom + 1;
}
}
// get categories for entry
$cntTmp = 0;
$sql = "SELECT * FROM evo_postcats WHERE postcat_post_ID=" . $eid;
$res = mysql_query($sql, $resB2) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
if ($res) {
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$cid = $arCat[$row['postcat_cat_ID']];
$sql = trim(str_replace("\n","","INSERT INTO `". $wp_pref ."post2cat` ".
"(`post_id`,`category_id`)" .
" VALUES ('" . $id . "','" . $cid . "');"));
$q = mysql_query($sql, $resWP) or die("Invalid query: " . mysql_error() . "
SQL : " . $sql);
$cntCat = $cntCat + 1;
$cntTmp = $cntTmp + 1;
}
}
if ($cntTmp == 0) {
// No categories defined in b2evo - put it in the default category
$sql = trim(str_replace("\n","","INSERT INTO `". $wp_pref ."post2cat` ".
"(`post_id`,`category_id`)" .
" VALUES ('" . $id . "','1');"));
$q = mysql_query($sql, $resWP) 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($resB2);
mysql_close($resWP);
echo "That's all folks!";
break;
}
?>