| 1 |
<?php
|
| 2 |
include_once 'includes/bootstrap.inc';
|
| 3 |
include_once 'includes/common.inc';
|
| 4 |
|
| 5 |
// Path to attachments (with trailing slash)
|
| 6 |
$attach_path = "";
|
| 7 |
$encoding = ""; //
|
| 8 |
|
| 9 |
// everything needs to be in UTF-8
|
| 10 |
function utf8_me($data, $encoding = "iso-8859-1") {
|
| 11 |
$encoding = strtolower($encoding);
|
| 12 |
|
| 13 |
if ($encoding == 'utf-8') {
|
| 14 |
$out = $data;
|
| 15 |
}
|
| 16 |
else {
|
| 17 |
if (function_exists('iconv')) {
|
| 18 |
$out = @iconv($encoding, 'utf-8', $data);
|
| 19 |
}
|
| 20 |
else if (function_exists('mb_convert_encoding')) {
|
| 21 |
$out = @mb_convert_encoding($data, 'utf-8', $encoding);
|
| 22 |
}
|
| 23 |
else if (function_exists('recode_string')) {
|
| 24 |
$out = @recode_string($encoding . '..utf-8', $data);
|
| 25 |
}
|
| 26 |
else if ((function_exists('utf8_encode')) && ($encoding == "iso-8859-1")) {
|
| 27 |
$out = @utf8_encode($data);
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
die("Import failed: there's no way to convert data to UTF-8.<br>");
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
return $out;
|
| 35 |
}
|
| 36 |
|
| 37 |
global $user;
|
| 38 |
$current_user = $user;
|
| 39 |
|
| 40 |
// create vocabulaory
|
| 41 |
$vocab_nodes = array();
|
| 42 |
$vocab = array();
|
| 43 |
|
| 44 |
$vocab_nodes[] = 'forum';
|
| 45 |
$vocab['name'] = 'Forum'; // vocab name
|
| 46 |
$vocab['nodes'] = $vocab_nodes; // array of node names allowed in vocab
|
| 47 |
$vocab['description'] = 'Forum categories'; // description of vocab
|
| 48 |
$vocab['multiple'] = 0; // boolean for if nodes can have multiple terms
|
| 49 |
$vocab['required'] = 1; // boolean for if nodes require terms
|
| 50 |
$vocab['hierarchy'] = 1; // hierarchy of terms, 0 = none, 1 = single, 2 = multiple
|
| 51 |
$vocab['relations'] = 0; // boolean for if related terms are allowed
|
| 52 |
$vocab['weight'] = 0; // weight for vocab
|
| 53 |
|
| 54 |
$output = taxonomy_save_vocabulary($vocab);
|
| 55 |
$vid = $output['vid'];
|
| 56 |
|
| 57 |
// clean up
|
| 58 |
unset($vocab);
|
| 59 |
unset($output);
|
| 60 |
|
| 61 |
// create forum categories
|
| 62 |
$result = db_query('SELECT cat_id, cat_title FROM phpbb_categories');
|
| 63 |
|
| 64 |
// keep track of categories
|
| 65 |
$cats = array();
|
| 66 |
|
| 67 |
while ($category = db_fetch_object($result)) {
|
| 68 |
$term = array();
|
| 69 |
|
| 70 |
$term['name'] = utf8_me($category->cat_title, $encoding); // term name
|
| 71 |
$term['description'] = utf8_me($category->cat_title, $encoding); // description of term
|
| 72 |
$term['weight'] = 0; // weight for term
|
| 73 |
$term['vid'] = $vid;
|
| 74 |
$term['parent'] = 0; // parent tid
|
| 75 |
|
| 76 |
$output = taxonomy_save_term($term);
|
| 77 |
$cats[$category->cat_id] = $output['tid'];
|
| 78 |
|
| 79 |
$categories = variable_get('forum_containers', array());
|
| 80 |
$categories[] = $output['tid'];
|
| 81 |
variable_set('forum_containers', $categories);
|
| 82 |
|
| 83 |
unset($term);
|
| 84 |
unset($output);
|
| 85 |
}
|
| 86 |
|
| 87 |
// create forums
|
| 88 |
$result = db_query('SELECT forum_id, forum_name, forum_desc, cat_id FROM phpbb_forums');
|
| 89 |
|
| 90 |
// keep track of forums
|
| 91 |
$forums = array();
|
| 92 |
|
| 93 |
while ($forum = db_fetch_object($result)) {
|
| 94 |
$term = array();
|
| 95 |
$term['parent'] = array();
|
| 96 |
|
| 97 |
$term['name'] = utf8_me($forum->forum_name, $encoding); // term name
|
| 98 |
$term['description'] = utf8_me($forum->forum_desc, $encoding); // description of term
|
| 99 |
$term['weight'] = 0; // weight for term
|
| 100 |
$term['vid'] = $vid;
|
| 101 |
$term['parent'][$cats[$forum->cat_id]] = $cats[$forum->cat_id]; // parent tid
|
| 102 |
|
| 103 |
$output = taxonomy_save_term($term);
|
| 104 |
$forums[$forum->forum_id] = $output['tid'];
|
| 105 |
|
| 106 |
unset($term);
|
| 107 |
unset($output);
|
| 108 |
}
|
| 109 |
|
| 110 |
// set up profile fields
|
| 111 |
db_query("INSERT INTO profile_fields (title, name, category, type, register, visibility) VALUES
|
| 112 |
('ICQ number', 'profile_icq', 'Additional information', 'textfield', 1, 2),
|
| 113 |
('AIM screenname', 'profile_aim', 'Additional information', 'textfield', 1, 2),
|
| 114 |
('MSN Messenger screenname', 'profile_msn', 'Additional information', 'textfield', 1, 2),
|
| 115 |
('Yahoo Messenger screenname', 'profile_yahoo', 'Additional information', 'textfield', 1, 2),
|
| 116 |
('Home page', 'profile_homepage', 'Additional information', 'url', 1, 2),
|
| 117 |
('Occupation', 'profile_occupation', 'Additional information', 'textfield', 1, 2),
|
| 118 |
('Location', 'profile_location', 'Additional information', 'textfield', 1, 2),
|
| 119 |
('Interests', 'profile_interests', 'Additional information', 'textfield', 1, 2)
|
| 120 |
");
|
| 121 |
|
| 122 |
// create users
|
| 123 |
$result = db_query('SELECT user_id, username, user_password, user_email, user_sig, user_regdate, user_timezone, user_icq, user_aim, user_msnm, user_yim, user_website, user_occ, user_from, user_interests FROM phpbb_users');
|
| 124 |
|
| 125 |
// keep track of users
|
| 126 |
$users = array();
|
| 127 |
$users[-1] = 0; // anonymous users
|
| 128 |
|
| 129 |
while ($poster = db_fetch_object($result)) {
|
| 130 |
$user = user_load(array('mail' => $poster->user_email));
|
| 131 |
|
| 132 |
if (!isset($user->uid)) {
|
| 133 |
$user->mail = utf8_me($poster->user_email, $encoding);
|
| 134 |
$user->name = utf8_me($poster->username, $encoding);
|
| 135 |
|
| 136 |
$poster->changed = ($poster->user_session_time == 0) ? $poster->user_regdate : $poster->user_session_time;
|
| 137 |
|
| 138 |
$user = user_save(NULL, array(
|
| 139 |
'name' => utf8_me($poster->username, $encoding),
|
| 140 |
'mail' => utf8_me($poster->user_email, $encoding),
|
| 141 |
'status' => 1,
|
| 142 |
'roles' => array(_user_authenticated_id()),
|
| 143 |
'created' => $poster->user_regdate,
|
| 144 |
'pass' => utf8_me($poster->user_password, $encoding),
|
| 145 |
'signature' => utf8_me($poster->user_sig, $encoding),
|
| 146 |
'timezone' => $poster->user_timezone,
|
| 147 |
'profile_icq' => $poster->user_icq,
|
| 148 |
'profile_aim' => utf8_me($poster->user_aim, $encoding),
|
| 149 |
'profile_msn' => utf8_me($poster->user_msnm, $encoding),
|
| 150 |
'profile_yahoo' => utf8_me($poster->user_yim, $encoding),
|
| 151 |
'profile_homepage' => utf8_me($poster->user_website, $encoding),
|
| 152 |
'profile_occupation' => utf8_me($poster->user_occ, $encoding),
|
| 153 |
'profile_location' => utf8_me($poster->user_from, $encoding),
|
| 154 |
'profile_interests' => utf8_me($poster->user_interests, $encoding)
|
| 155 |
));
|
| 156 |
}
|
| 157 |
|
| 158 |
$users[$poster->user_id] = $user->uid;
|
| 159 |
|
| 160 |
unset($user);
|
| 161 |
}
|
| 162 |
|
| 163 |
// create forum topics (nodes)
|
| 164 |
$result = db_query("SELECT MIN(post_id) as post_id FROM phpbb_posts GROUP BY topic_id");
|
| 165 |
|
| 166 |
while ($post_id = db_fetch_object($result)) {
|
| 167 |
$temp[] = $post_id->post_id;
|
| 168 |
}
|
| 169 |
|
| 170 |
$post_ids = implode(",", $temp);
|
| 171 |
|
| 172 |
$result = db_query("SELECT a.post_id, a.topic_id, a.poster_id, a.post_time, a.post_edit_time, a.forum_id, a.post_attachment, REPLACE(b.post_subject, CONCAT(':',b.bbcode_uid),'') AS post_subject, REPLACE(b.post_text, CONCAT(':',b.bbcode_uid),'') AS post_text FROM phpbb_posts AS a, phpbb_posts_text AS b WHERE a.post_id = b.post_id AND a.post_id IN (%s) ORDER BY a.topic_id", $post_ids);
|
| 173 |
|
| 174 |
// keep track of topics
|
| 175 |
$topics = array();
|
| 176 |
|
| 177 |
// keep track of non-comments
|
| 178 |
$posts = array();
|
| 179 |
|
| 180 |
while ($post = db_fetch_object($result)) {
|
| 181 |
$node->taxonomy = array();
|
| 182 |
|
| 183 |
// add attachment links to node bodies
|
| 184 |
if ($post->post_attachment)
|
| 185 |
{
|
| 186 |
$att_result = db_query("SELECT b.physical_filename FROM phpbb_attachments AS a, phpbb_attachments_desc AS b WHERE a.post_id = %d AND a.attach_id = b.attach_id", $post->post_id);
|
| 187 |
|
| 188 |
while ($attachment = db_fetch_object($att_result)) {
|
| 189 |
$post->post_text = $post->post_text . "\r\n[url]" . $attach_path . $attachment->physical_filename . "[/url]"; // attachment link in bbcode
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
$node->type = 'forum';
|
| 194 |
$node->title = utf8_me($post->post_subject, $encoding);
|
| 195 |
$node->body = utf8_me($post->post_text, $encoding);
|
| 196 |
$node->created = $post->post_time;
|
| 197 |
$node->changed = ($post->post_edit_time >= $post->post_time) ? $post->post_edit_time : $post->post_time;
|
| 198 |
$node->uid = $users[$post->poster_id];
|
| 199 |
$node->comment = '2';
|
| 200 |
$node->tid = $forums[$post->forum_id];
|
| 201 |
$node->taxonomy[] = $forums[$post->forum_id];
|
| 202 |
|
| 203 |
$user = user_load(array('uid' => $users[$post->poster_id]));
|
| 204 |
|
| 205 |
$node->nid = node_save($node);
|
| 206 |
|
| 207 |
$topics[$post->topic_id] = $node->nid;
|
| 208 |
$posts[$post->post_id] = TRUE;
|
| 209 |
|
| 210 |
unset($node);
|
| 211 |
}
|
| 212 |
|
| 213 |
// create forum replies (comments)
|
| 214 |
$result = db_query("SELECT a.poster_id, a.topic_id, a.post_id, a.post_time, a.post_username, a.post_attachment, REPLACE(b.post_text, CONCAT(':',b.bbcode_uid),'') AS post_text FROM phpbb_posts AS a, phpbb_posts_text AS b WHERE a.post_id = b.post_id ORDER BY a.post_time");
|
| 215 |
|
| 216 |
while (($comment = db_fetch_object($result))) {
|
| 217 |
if (!$posts[$comment->post_id]) { // if the post isn't the first in a topic
|
| 218 |
$user = user_load(array('uid' => $users[$comment->poster_id]));
|
| 219 |
|
| 220 |
if (!$users[$comment->poster_id]) {
|
| 221 |
$name = utf8_me($comment->post_username, $encoding);
|
| 222 |
}
|
| 223 |
|
| 224 |
// add attachment links to comment bodies
|
| 225 |
if ($comment->post_attachment)
|
| 226 |
{
|
| 227 |
$att_result = db_query("SELECT b.physical_filename FROM phpbb_attachments AS a, phpbb_attachments_desc AS b WHERE a.post_id = %d AND a.attach_id = b.attach_id", $comment->post_id);
|
| 228 |
|
| 229 |
while ($attachment = db_fetch_object($att_result)) {
|
| 230 |
$comment->post_text = $comment->post_text . "\r\n[url]" . $attach_path . $attachment->physical_filename . "[/url]"; // attachment link in bbcode
|
| 231 |
}
|
| 232 |
}
|
| 233 |
|
| 234 |
$cid = comment_post(array(
|
| 235 |
"comment" => utf8_me($comment->post_text, $encoding),
|
| 236 |
"pid" => 0, // no threading in phpbb
|
| 237 |
"nid" => $topics[$comment->topic_id],
|
| 238 |
"timestamp" => $comment->post_time,
|
| 239 |
"name" => $name));
|
| 240 |
|
| 241 |
unset($comment);
|
| 242 |
}
|
| 243 |
}
|
| 244 |
|
| 245 |
echo('<br>If no errors appear above, import was successful.</br>');
|
| 246 |
|
| 247 |
$user = $current_user;
|
| 248 |
?>
|