type = "story";
// the vocabulary name is used to create a new taxonomy within
// your new Drupal installation. taxonomies and vocabularies are
// fancy terms for Movable Type categories. you can name the vocab
// here; you can also change it through Drupal at a later date.
$vocabulary['name'] = "Weblog Categories";
$vocabulary['nodes'] = 0;
$vocabulary['multiple'] =0;
$vocabulary['required']=0;
$vocabulary['hierarchy']=0;
$vocabulary['relations']=0;
// newly imported authors are given no passwords whatsoever -
// to generate one for them, you can instruct users to "Request
// new password" from the login block. If, on the other hand,
// you'd like to set a default password for everyone, do so here.
$author['pass'] = "";
// generic settings that probably shouldn't
// be changed unless you have a clue bit.
$node->promote = 1;
$author['status'] = 1;
$timezone = "<$MTBlogTimezone$>";
$timezone = preg_replace('!:!', '', $timezone);
// let's begin this bad boy, eh?
echo "Movable Type => Drupal Conversion
";
$first_cid = db_num_rows(db_query("SELECT * FROM comments"));
// ///////////////////////////////////////////////////////////////////////////
// first thing we do is import the categories of Movable Type //
// (the "terms") into the Drupal taxonomy ($vocabulary_name). //
// ///////////////////////////////////////////////////////////////////////////
echo "Importing Categories
";
$vocabulary = taxonomy_save_vocabulary(array( "name" => $vocabulary['name'], "nodes" => array($node['type']) ) );
echo "- Created new vocabulary '$vocabulary[name]'.
"; // we should do error checking. bah!
$term['tid'] = NULL;
$term['vid'] = $vocabulary['vid'];
$term['name'] = "<$MTCategoryLabel$>";
$term['multiple'] = 0;
$term['required'] = 0;
$term['hierarchy'] = 0;
$term['relations'] = 0;
$term['weight'] = 0;
$term['description'] = <<
CATEGORY_DESCRIPTION;
$term = taxonomy_save_term($term);
echo "- Created new term '$term[name]' in '$vocabulary[name]'.
";
$term_uri="<$MTCategoryArchiveLink$>";
$term_link=ereg_replace('^http://[^/]+/','',$term_uri);
echo "linking taxonomy/page/or/" . $term['tid'] . " to " . $term_link ."
";
path_set_alias("taxonomy/page/or/" . $term['tid'],$term_link);
echo "
";
// ///////////////////////////////////////////////////////////////////////////
// now, let's import the entries. it'd be nice if we could import the //
// authors first, but MT has no loopable author equivalent, so instead //
// we have to do people when we learn about 'em during entry loop. //
// ///////////////////////////////////////////////////////////////////////////
echo "Importing Entries
";
$node->title = <<
ENTRY_TITLE;
// depending on how you've configured
// your movable type entries, you should
// tweak these to be better represented.
$node->teaser = <<
ENTRY_TEASER;
$node->body = <<
ENTRY_BODY;
$permalink = "<$MTEntryPermalink$>";
$path_uri=ereg_replace('^http://[^/]+/','',$permalink);
echo "New Path URI: " . $path_uri . "
";
// do we know this author?
$author['name'] = "<$MTEntryAuthor$>";
$author['mail'] = '<$MTEntryAuthorEmail$>';
$user = user_load(array(mail => $author['mail']));
$user_uid = $user->uid; if (!$user_uid) {
$author['rid'] = array(_user_authenticated_id());
$user = user_save($account, $author);
echo "- Created new user '$author[name]'.
";
} else { echo "- Entry has known user '$author[name]'.
"; }
$node->uid = $user->uid; // node author to uid.
$node->status = strtolower('<$MTEntryStatus$>') == "publish" ? 1 : 0;
$node->created = strtotime("<$MTEntryDate format="%Y-%m-%d %H:%M:%S"$> $timezone");
$node->changed = strtotime("<$MTEntryModifiedDate format="%Y-%m-%d %H:%M:%S"$> $timezone");
$node->comment = 0; // comment status is... ?
$node->comment = 1;
$node->comment = 2;
// for the node validation, it's important NOT to use the return
// $node from _validate, and only check for $error. since we're
// directly adding new entries to the database from previously
// unauthorized users (those MT folks we're importing), node_
// validate will fail the "is this user authorized?" check, and
// return bum data (notably, the entry's ->date and ->created).
node_validate($node, $error); // check existence of $error only!
if (!$error) { $nid = node_save($node); } else { print_r($error); exit; }
echo "- Created new entry '". $node->title ."'.
";
// find the term IDs for all
// assigned to this entry.
$terms = array();
$term = "<$MTCategoryLabel$>";
$matches = taxonomy_get_term_by_name($term);
foreach ($matches as $match) {
if ($match->vid == $vocabulary['vid']) {
array_push($terms, $match->tid);
taxonomy_node_save($nid, $terms); // error check!
echo "- Entry is categorized as '$term'.
";
}
}
// ///////////////////////////////////////////////////////////////////////////
// at this point, we're still inside our entries, but we're going to be //
// working with comments now. the following code will work properly //
// regardless of 4.4.1 (no anonymous named comments) or CVS HEAD. //
// ///////////////////////////////////////////////////////////////////////////
$comment_title = <<
CT;
$comment_text = <<
CT;
// grab the first five words of the comment as the comment subject
$subject = "";
$arr = explode(" ",$comment_title);
for($i=0; $i<5; $i++) { $subject .= $arr[$i]." "; }
// check if user already exists, otherwise add them
$user_name = "<$MTCommentAuthor$>";
$user_mail = "<$MTCommentEmail$>";
// is user e-mail as the key
$user = user_load(array(mail => $user_mail));
$uid = $user->uid;
if (!$uid)
{
$user = user_load(array(name => $user_name));
$uid = $user->uid;
if (!$uid)
{
$user = user_save($account, array("name" => $user_name, "mail" => $user_mail, "status" => 1, "rid" => _user_authenticated_id()));
$uid = $user->uid;
} else {
echo "Duplicate user:
";
echo "Username = " . $user_name . "
";
echo "Mail = " . $user_mail . "
";
echo "UID = " . $uid . "
";
echo "Node ID = " . $nid . "
";
echo "Using UID of original user...
";
}
}
// strtotime('<$MTEntryDate format="%Y-%m-%d %H:%M:%S"$>');
// create the $user class used in comment_post()
$user->uid = $uid;
echo "Comment from " . $uid . " Subject: " . $subject . "
";
$cid = comment_post(array("subject" => $subject, "comment" => $comment_text, "pid" => 0, "nid" => $nid, "uid" => $uid));
$comments_rows++;
path_set_alias("node/view/" . $nid,$path_uri);
echo "path_set_alias(node/view/" . $nid . "," . $path_uri . ")
";
echo "
";
?>