| 1 |
<?php
|
| 2 |
include_once "includes/bootstrap.inc";
|
| 3 |
include_once "includes/common.inc";
|
| 4 |
?>
|
| 5 |
|
| 6 |
<html>
|
| 7 |
<head>
|
| 8 |
<title>Import MovableType data to Drupal</title>
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
|
| 12 |
<?php
|
| 13 |
|
| 14 |
//set variable defaults
|
| 15 |
$hostname = "";
|
| 16 |
$username = "";
|
| 17 |
$password = "";
|
| 18 |
$db = "";
|
| 19 |
$node->uid = 1;
|
| 20 |
$node->type = "blog"; // node type (defaults to "blog"--if using blog, make sure to enable that module)
|
| 21 |
$node->promote = 1; // promote to front page? (defaults to 1 = yes)
|
| 22 |
$comment->score = 0;
|
| 23 |
|
| 24 |
// get next node number from sequences table
|
| 25 |
$link = mysql_connect($hostname,$username,$password) or die("Could not connect to server");
|
| 26 |
mysql_select_db($db) or die("Could not select database ".$db);
|
| 27 |
|
| 28 |
$first_nid = db_num_rows(db_query("SELECT * FROM node"));
|
| 29 |
//echo "Nodes: " . db_num_rows($first_nid) . "<br>";
|
| 30 |
$first_cid = db_num_rows(db_query("SELECT * FROM comments"));
|
| 31 |
//echo "Comments: " . db_num_rows($first_cid) . "<br>";
|
| 32 |
$first_uid = db_num_rows(db_query("SELECT * FROM users"));
|
| 33 |
//echo "Users: " . db_num_rows($first_uid) . "<br>";
|
| 34 |
|
| 35 |
<MTEntries lastn="1000" sort_order="ascend">
|
| 36 |
|
| 37 |
$node_title = <<<NT
|
| 38 |
<$MTEntryTitle remove_html="1"$>
|
| 39 |
NT;
|
| 40 |
$node->title = $node_title;
|
| 41 |
|
| 42 |
$node_body = <<<NB
|
| 43 |
<$MTEntryBody$><$MTEntryMore$>
|
| 44 |
NB;
|
| 45 |
$node->body = $node_body;
|
| 46 |
|
| 47 |
//get post status
|
| 48 |
$status = strtolower("<$MTEntryStatus$>");
|
| 49 |
|
| 50 |
if ($status == "publish")
|
| 51 |
{
|
| 52 |
$node->status = 1;
|
| 53 |
}
|
| 54 |
else
|
| 55 |
{
|
| 56 |
$node->status = 0;
|
| 57 |
}
|
| 58 |
|
| 59 |
// Are comments allowed?
|
| 60 |
$node->comment = 0; //comments not allowed
|
| 61 |
<MTEntryIfAllowComments>
|
| 62 |
$node->comment = 1; //comments read-only
|
| 63 |
<MTEntryIfCommentsOpen>
|
| 64 |
$node->comment = 2; //comments read and write
|
| 65 |
</MTEntryIfCommentsOpen>
|
| 66 |
</MTEntryIfAllowComments>
|
| 67 |
|
| 68 |
$node->created = strtotime('<$MTEntryDate format="%Y-%m-%d %H:%M:%S"$>');
|
| 69 |
$node->changed = strtotime('<$MTEntryModifiedDate format="%Y-%m-%d %H:%M:%S"$>');
|
| 70 |
|
| 71 |
// check if the node is valid, if not, print out the error message and stop the script
|
| 72 |
node_validate($node, $error);
|
| 73 |
if (!$error) {
|
| 74 |
$nid = node_save($node);
|
| 75 |
}
|
| 76 |
else {
|
| 77 |
print_r($error);
|
| 78 |
exit;
|
| 79 |
}
|
| 80 |
|
| 81 |
<MTComments sort_order="ascend">
|
| 82 |
|
| 83 |
$comment_title = <<<CT
|
| 84 |
<$MTCommentBody remove_html="1"$>
|
| 85 |
CT;
|
| 86 |
|
| 87 |
$comment_text = <<<CT
|
| 88 |
<$MTCommentBody$>
|
| 89 |
CT;
|
| 90 |
|
| 91 |
// grab the first five words of the comment as the comment subject
|
| 92 |
$subject = "";
|
| 93 |
$arr = explode(" ",$comment_title);
|
| 94 |
|
| 95 |
for($i=0; $i<5; $i++) { $comment_subject .= $arr[$i]." "; }
|
| 96 |
|
| 97 |
// check if user already exists, otherwise add them
|
| 98 |
$user_name = "<$MTCommentAuthor$>";
|
| 99 |
$user_mail = "<$MTCommentEmail$>";
|
| 100 |
|
| 101 |
// is user e-mail as the key
|
| 102 |
|
| 103 |
$user = user_load(array(mail => $user_mail));
|
| 104 |
$uid = $user->uid;
|
| 105 |
|
| 106 |
if (!$uid)
|
| 107 |
{
|
| 108 |
$user = user_load(array(name => $user_name));
|
| 109 |
$uid = $user->uid;
|
| 110 |
|
| 111 |
if (!$uid)
|
| 112 |
{
|
| 113 |
$uid = user_save($account, array("name" => $user_name, "mail" => $user_mail, "status" => 1, "rid" => _user_authenticated_id()));
|
| 114 |
$uid = $uid->uid;
|
| 115 |
}
|
| 116 |
else {
|
| 117 |
echo "Duplicate user: <br>";
|
| 118 |
echo "Username = " . $user_name . "<br>";
|
| 119 |
echo "Mail = " . $user_mail . "<br>";
|
| 120 |
echo "UID = " . $uid . "<br>";
|
| 121 |
echo "Node ID = " . $nid . "<br>";
|
| 122 |
echo "Using UID of original user...<br>";
|
| 123 |
}
|
| 124 |
}
|
| 125 |
|
| 126 |
//$comments_insert_query = "INSERT INTO comments (cid, pid, nid, uid, subject, comment, hostname, timestamp, score, status, thread, users) VALUES (NULL, 0, $nid, $uid, '$subject', '$comment_text', '<$MTCommentIP$>', UNIX_TIMESTAMP('<$MTCommentDate format="%Y-%m-%d %H:%M:%S"$><$MTBlogTimezone$>'), $comment->score, 0, '1/', 'a:1:{i:0;i:0;}');";
|
| 127 |
|
| 128 |
// strtotime('<$MTEntryDate format="%Y-%m-%d %H:%M:%S"$>');
|
| 129 |
|
| 130 |
// create the $user class used in comment_post()
|
| 131 |
$user->uid = $uid;
|
| 132 |
|
| 133 |
$cid = commment_post(array("subject" => $comment_subject, "comment" => $comment_text, "pid" => 0, "nid" => $nid,
|
| 134 |
|
| 135 |
mysql_query($comments_insert_query);
|
| 136 |
|
| 137 |
if (mysql_errno($link))
|
| 138 |
{
|
| 139 |
echo "Error: " . mysql_errno($link) . ": " . mysql_error($link) . "\n";
|
| 140 |
}
|
| 141 |
|
| 142 |
$comments_rows++;
|
| 143 |
</MTComments>
|
| 144 |
|
| 145 |
</MTEntries>
|
| 146 |
|
| 147 |
// echo the number of items added to the nodes table
|
| 148 |
echo(db_num_rows(db_query("SELECT * FROM node")) - $first_nid." nodes, ");
|
| 149 |
|
| 150 |
// echo the number of items added to the users table
|
| 151 |
echo(db_num_rows(db_query("SELECT * FROM users")) - $first_uid." users, and ");
|
| 152 |
|
| 153 |
// echo the number of rows added to the comments table
|
| 154 |
echo(db_num_rows(db_query("SELECT * FROM comments")) - $first_cid." comments inserted.");
|
| 155 |
mysql_query("INSERT into sequences (name,id) VALUES ('comments_cid',$comments_rows+1)");
|
| 156 |
if (mysql_errno($link))
|
| 157 |
{
|
| 158 |
echo "Error: " . mysql_errno($link) . ": " . mysql_error($link) . "\n";
|
| 159 |
}
|
| 160 |
|
| 161 |
mysql_close($link);
|
| 162 |
?>
|
| 163 |
|
| 164 |
</body>
|
| 165 |
</html>
|