'; ?>
Connected to database. Exporting data...
"; // export the entries from Movable Type $query1="SELECT entry_id,entry_blog_id,entry_text, entry_status,"; $query1.=" entry_category_id, entry_title, entry_text, entry_text_more,"; $query1.=" entry_created_on FROM ".$data['mt_entry_table']." ORDER BY"; $query1.=" entry_id ASC"; $result = mysql_query($query1); //initialize entry- and comment counters $i=0; $c=0; echo "";
while ($row = mysql_fetch_assoc($result)) {
if ($row['entry_blog_id']==$data['mt_blog_id']){
$i++;
foreach ($row as $a=>$b){
$n=str_replace("\n","
\n", $b);
$row[$a]=mysql_escape_string($n);
}
// MT stores the categories of its entries in a special table
$placement_query="SELECT placement_entry_id,placement_category_id";
$placement_query.=" FROM ".$data['mt_placement_table']." WHERE";
$placement_query.=" placement_entry_id='".$row['entry_id']."'";
$placement_result = mysql_query($placement_query)
or die ("Error: ".mysql_error());
$placement_row = mysql_fetch_assoc($placement_result);
$catid = $placement_row['placement_category_id'];
$catid=$mt_category[$catid];
// category id acquired, so free the resources taken up by that query
mysql_free_result($placement_result);
// if it's a draft in MT, make it a draft in Nucleus
// (too bad you currently can't make a published entry a draft
// in Nucleus like you can in MT)
if ($row['entry_status']==$data['mt_published_status']){
$draft=$data['nucleus_published_status'];
}
else{
$draft=$data['nucleus_draft_status'];
}
// generate the main query to insert the entry
// excuse the strange variable name ;)
$gogo="INSERT into ".$data['nucleus_entry_table'];
$gogo.="(ititle,ibody,imore,iblog,iauthor,itime,iclosed,idraft,";
$gogo.="ikarmapos,icat,ikarmaneg) VALUES ";
$gogo.="('".$row['entry_title']."','".$row['entry_text']."','";
$gogo.=$row['entry_text_more']."','".$data['nucleus_blog_id']."','";
$gogo.=$data['nucleus_blog_author']."','".$row['entry_created_on'];
$gogo.="','0','".$draft."','0','".$catid."','0')";
if ($_GET['commit']==1){
mysql_query($gogo) or die("Could not insert: " . mysql_error());
// get the inserted entry's new id to be used while inserting
// the comments of the entry
$citem=mysql_insert_id();
echo "# Entry: ".$row['entry_id']."=>$citem";
echo " titled \"".$row['entry_title']."\"
";
}
// if requested, display the INSERT query for the entry
// html entities need to be converted for the web page,
// but if the entries already contain entities, those should
// _not_ be converted again
if ($_GET['show']==1) echo htmlentities2($gogo).";
";
// get the comments for the entry
$comments_query = "SELECT comment_entry_id,comment_ip,comment_author";
$comments_query .= ",comment_email,comment_url,comment_text,";
$comments_query .= "comment_created_on FROM ".$data['mt_comment_table'];
$comments_query .= " WHERE comment_entry_id='".$row['entry_id']."'";
$comments_result = mysql_query($comments_query)
or die ("...".mysql_error());
// process all the comments for a particular entry
while ($comments_row = mysql_fetch_assoc($comments_result)){
$c++;
$cmember="";$cuser="";$cmail="";
foreach ($comments_row as $a=>$b)
$comments_row[$a]=mysql_escape_string($b);
$cip=$comments_row['comment_ip'];
// since MT only stores the ip, get the _current_
// hostname for it - not ideal, but will do
$chost=gethostbyaddr($cip);
// if the comment is by the special user, (determined by the string
// defined by the user in $data['mt_special_user'] )
// let's not insert name or email, just the member id in
// $data['nucleus_special_user']
$su=stristr($comments_row['comment_author'],$data['mt_special_user']);
if ((!empty($data['mt_special_user'])) && ($su)){
$cmember=$data['nucleus_special_user'];
}
else{
$cmember=0;
$cuser=$comments_row['comment_author'];
if (strcmp($comments_row['comment_url'],""))
$cmail=$comments_row['comment_email'];
else
$cmail=$comments_row['comment_url'];
}
// the INSERT query for the comment
$cgogo="INSERT into ".$data['nucleus_comment_table']."(cbody,cuser,";
$cgogo.="cmail,cmember,citem,ctime,chost,cip,cblog) VALUES ";
$cgogo.="('".$comments_row['comment_text']."','".$cuser."','";
$cgogo.=$cmail."','".$cmember."','".$citem."','";
$cgogo.=$comments_row['comment_created_on']."','".$chost."','";
$cgogo.=$cip."','1')";
// echo the INSERT row only if the conversion is being committed
if ($_GET['commit']==1){
echo "# --Comment at: ";
echo $comments_row['comment_created_on']."
";
if ($_GET['show']==1) echo htmlentities2($cgogo).";
";
mysql_query($cgogo) or die("Could not insert: " . mysql_error());
}
}
mysql_free_result($comments_result);
}
}
mysql_free_result($result);
echo "
# Conversion successful with $i entries and $c comments.
"; } ?>