Welcome to Geeklog, Anonymous Tuesday, December 10 2024 @ 07:53 pm EST
Geeklog Forums
Converting Geeklog users and forum posts to phpbb3.
Status: offline
grant
Forum User
Junior
Registered: 12/14/05
Posts: 21
Location:Iowa City, IA
I needed to do this so I'll share my code in case anyone else wants to try.
A few notes:
<?php
require_once('MDB2.php');
// http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
$_DB = array(
'username' => 'mysqlusername',
'password' => 'mysqlpassword',
'host' => 'localhost',
'geeklog_database' => 'name of database with geeklog posts and users', );
$_DSN = 'mysql://'. $_DB['username'] .':'. $_DB['password'] .'@'. $_DB['host'] .'/' . $_DB['geeklog_database'];
define('IN_PHPBB', true);
define('PHPBB_ROOT_PATH' , '/path/to/phpbb3/' );
// use this, if it doesn't work then specify your own path
// something like this $phpbb_root_path = './public/forum/';
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('common');
$mdb2 =& MDB2::connect( $_DSN , $options);
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
echo add_phpbb_users( get_geeklog_users( $mdb2 ));
echo "<ol>\r\n". get_geeklog_posts( $mdb2 ) ."</ol>\r\n";
$mdb2->disconnect();
function check_topic_exists( $mdb2 , $topic_id ){
$sql = "SELECT * FROM `phpbb3`.`phpbb_topics` WHERE `topic_id` = $topic_id";
$result = do_query( $mdb2 , $sql );
return $result;
}
function check_post_exists( $mdb2 , $post_id ){
$sql = "SELECT * FROM `phpbb3`.`phpbb_posts` WHERE `post_id` = $post_id";
$result = do_query( $mdb2 , $sql );
return $result;
}
function do_query( $mdb2 , $sql ){
$res =& $mdb2->query( $sql );
$i = 0;
if ( PEAR::isError( $res ) ){
echo $sql;
die( $res->getMessage());
}
while (($row = $res->fetchRow())){
$result[$i] = $row;
$i++;
}
return $result;
}
function get_geeklog_users( $mdb2 ){
$sql = 'SELECT * FROM `gl_users` WHERE `uid` != 1';
$result = do_query( $mdb2 , $sql );
$size = sizeof( $result );
for ( $i = 0 ; $i < $size; $i++ ){
$user[$i] = array(
'user_id' => $result[$i][0] + 100,
'user_type' => 0,
'group_id' => 2,
'user_regdate' => strtotime( $result[$i][9] ),
'username' => $result[$i][1],
'user_password' => $result[$i][5],
'user_email' => $result[$i][6],
);
}
return $user;
}
function create_topic( $data , $result){
$topic = array(
'topic_id' => $data['topic_id'],
'forum_id' => $data['forum_id'],
'icon_id' => $data['icon_id'],
'topic_attachment' => 0,
'topic_approved' => $data['post_approved'],
'topic_reported' => $data['post_reported'],
'topic_title' => $data['post_subject'],
'topic_poster' => $data['poster_id'],
'topic_time' => $data['post_time'],
'topic_time_limit' => 0,
'topic_views' => $result[14],
'topic_replies' => $result[13],
'topic_replies_real' => $result[13],
'topic_status' => 0,
'topic_type' => 0,
'topic_first_post_id' => $data['topic_id'],
'topic_first_poster_name' => $result[4],
'topic_first_poster_colour' => '',
'topic_last_post_id' => 0,
'topic_last_poster_id' => 0,
'topic_Last_poster_name' => '',
'topic_last_poster_colour' => '',
'topic_last_post_subject' => '',
'topic_last_post_time' => 0,
'topic_last_view_time' => 0,
'topic_moved_id' => 0,
'topic_bumped' => 0,
'topic_bumper' => 0,
'poll_title' => '',
'poll_start' => 0,
'poll_length' => 0,
'poll_max_options' => 1,
'poll_last_vote' => 0,
'poll_vote_change' => 0,
);
return $topic;
}
function add_post( $mdb2 , $post_array ){
$arr_to_string = implode( "' , '" , $post_array );
$sql = "INSERT INTO `phpbb3`.`phpbb_posts` VALUES ( '$arr_to_string' )";
return insert_into_db( $mdb2 , $sql );
}
function add_topic( $mdb2 , $topic_array ){
$arr_to_string = implode( "' , '" , $topic_array );
$sql = "INSERT INTO `phpbb3`.`phpbb_topics` VALUES ( '$arr_to_string' )";
return insert_into_db( $mdb2 , $sql );
}
function insert_into_db( $mdb2 , $sql ){
$affected =& $mdb2->exec($sql);
// Always check that result is not an error
if (PEAR::isError($affected)) {
die($affected->getMessage());
}
return $affected;
}
function get_geeklog_posts( $mdb2 ){
$sql = "SELECT * FROM `gl_forum_topic`";
$result = do_query( $mdb2 , $sql );
$size = sizeof( $result );
for( $i = 0 ; $i < $size ; $i++ ){
$text = $result[$i][11];
$uid = $bitfield = $flags = '';
generate_text_for_storage( &$text , &$uid , &$bitfield , &$flags , true , true , true );
$data[$i] = array(
'post_id' => $result[$i][0],
'topic_id' => create_topic_id( $result[$i][2] , $result[$i][0] ),
'forum_id' => forum_conversion( $result[$i][1] ),
'poster_id' => $result[$i][3] + 100,
'icon_id' => 0,
'poster_ip' => $result[$i][15],
'post_time' => $result[$i][5],
'post_approved' => 1,
'post_reported' => 0,
'enable_bbcode' => 1,
'enable_smilies' => 1,
'enable_magic_url' => 1,
'enable_sig' => 1,
'post_username' => '',
'post_subject' => addslashes($result[$i][10]),
'post_text' => addslashes($text),
'post_checksum' => md5( $text ),
'post_attachment' => '',
'bbcode_bitfield' => '$bitfield',
'bbcode_uid' => '$uid',
'post_postcount' => 1,
'post_edit_time' => 0,
'post_edit_reason' => '',
'post_edit_user' => 0,
'post_edit_count' => 0,
'post_edit_locked' => 0,
);
if ( $result[$i][2] == 0 ){
$check = check_topic_exists( $mdb2, $data[$i]['topic_id'] );
if ( $check[0][0] < 1 ){
$topic_array = create_topic( $data[$i] , $result[$i] );
$output .= "<li><b>Created topic {$topic_array['topic_title']}</b></li>\r\n";
$output .= "<ul><li>" . add_topic( $mdb2 , $topic_array ) ."</li></ul>\r\n";
}
else{
$output .= "<li>Already created topic {$check[0][6]}</li>\r\n";
}
}
if ( check_post_exists( $mdb2 , $data[$i]['post_id'] ) == NULL ){
$output .= "<li><b>Added post {$data[$i]['post_id']} ( {$data[$i]['post_subject']} ) to topic {$data[$i]['topic_id']} .</b></li>\r\n";
$output .= "<ul><li>" . add_post( $mdb2 , $data[$i] ) ."</li></ul>\r\n";
$output .= "<ul><li> {$data[$i]['post_text']} </li></ul>\r\n";
update_post_information('topic' , $data[$i]['topic_id'] , false );
update_post_information('forum' , $data[$i]['forum_id'] , false );
}
else{
$output .= "<li>Already found post {$data[$i]['post_id']} ( {$data[$i]['post_subject']} ) in topic {$data[$i]['topic_id']} .</li>\r\n";
update_post_information('topic' , $data[$i]['topic_id'] , false );
update_post_information('forum' , $data[$i]['forum_id'] , false );
}
}
return $output;
}
function create_topic_id( $topic_id , $post_id ){
//we need to know if its 0 to create a new topic, if it's not zero use that number
if ( $topic_id == 0 ){
return $post_id;
}
else{
return $topic_id;
}
}
function forum_conversion( $forum_id ){
$ids = array(
1 => 4,
2 => 5,
4 => 6,
5 => 11,
3 => 8,
7 => 10, );
return $ids[ $forum_id ];
}
function topic_id( $pid , $post_id ){
if ( $pid == 0 ){ //is a thread starter
$topic_id = $post_id;
}
else{
$topic_id = $pid;
}
return $topic_id;
}
function add_phpbb_users( $users ){
$size = sizeof( $users );
$output = "Size = $size <br />\r\n<ol>\r\n";
for ( $i = 0 ; $i < $size ; $i++ ){
$check_name = validate_username( $users[$i]['username'] );
if ( !$check_name ){
user_add( $users[$i] );
$output .= "<li>Added: {$users[$i]['username']} to phpbb! " . print_r( $check_name, true ) ."</li>\r\n";
}
else{
$output .= "<li>{$users[$i]['username']} Already exists! $check_name </li>\r\n";
}
}
$output .= "</ol>\r\n\r\n";
update_last_username();
return $output;
}
?>
Hope this can help someone else.
A few notes:
- I'm using mdb2 instead of the phpbb3 database functions.
- I hard coded "phpbb3" as the database name for my phpbb3 installation, you should only have to change it in four places. Sorry .
- I also hard coded gl_ and phpbb_ as the table prefixes. Sorry.
- I manually made the same forums with the ACP in phpbb3 so I made a function to convert the geeklog forum ids to the new forum ids in phpbb3 in case they aren't the same.
- This is on line 204:
- Text Formatted Codefunction forum_conversion( $forum_id ){
$ids = array(
1 => 4,
2 => 5,
4 => 6,
5 => 11,
3 => 8,
7 => 10, );
return $ids[ $forum_id ];
}
- The key is the Geeklog forum id the value is the phpbb3 forum id.
- This is on line 204:
Text Formatted Code
<?php
require_once('MDB2.php');
// http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
$_DB = array(
'username' => 'mysqlusername',
'password' => 'mysqlpassword',
'host' => 'localhost',
'geeklog_database' => 'name of database with geeklog posts and users', );
$_DSN = 'mysql://'. $_DB['username'] .':'. $_DB['password'] .'@'. $_DB['host'] .'/' . $_DB['geeklog_database'];
define('IN_PHPBB', true);
define('PHPBB_ROOT_PATH' , '/path/to/phpbb3/' );
// use this, if it doesn't work then specify your own path
// something like this $phpbb_root_path = './public/forum/';
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('common');
$mdb2 =& MDB2::connect( $_DSN , $options);
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
echo add_phpbb_users( get_geeklog_users( $mdb2 ));
echo "<ol>\r\n". get_geeklog_posts( $mdb2 ) ."</ol>\r\n";
$mdb2->disconnect();
function check_topic_exists( $mdb2 , $topic_id ){
$sql = "SELECT * FROM `phpbb3`.`phpbb_topics` WHERE `topic_id` = $topic_id";
$result = do_query( $mdb2 , $sql );
return $result;
}
function check_post_exists( $mdb2 , $post_id ){
$sql = "SELECT * FROM `phpbb3`.`phpbb_posts` WHERE `post_id` = $post_id";
$result = do_query( $mdb2 , $sql );
return $result;
}
function do_query( $mdb2 , $sql ){
$res =& $mdb2->query( $sql );
$i = 0;
if ( PEAR::isError( $res ) ){
echo $sql;
die( $res->getMessage());
}
while (($row = $res->fetchRow())){
$result[$i] = $row;
$i++;
}
return $result;
}
function get_geeklog_users( $mdb2 ){
$sql = 'SELECT * FROM `gl_users` WHERE `uid` != 1';
$result = do_query( $mdb2 , $sql );
$size = sizeof( $result );
for ( $i = 0 ; $i < $size; $i++ ){
$user[$i] = array(
'user_id' => $result[$i][0] + 100,
'user_type' => 0,
'group_id' => 2,
'user_regdate' => strtotime( $result[$i][9] ),
'username' => $result[$i][1],
'user_password' => $result[$i][5],
'user_email' => $result[$i][6],
);
}
return $user;
}
function create_topic( $data , $result){
$topic = array(
'topic_id' => $data['topic_id'],
'forum_id' => $data['forum_id'],
'icon_id' => $data['icon_id'],
'topic_attachment' => 0,
'topic_approved' => $data['post_approved'],
'topic_reported' => $data['post_reported'],
'topic_title' => $data['post_subject'],
'topic_poster' => $data['poster_id'],
'topic_time' => $data['post_time'],
'topic_time_limit' => 0,
'topic_views' => $result[14],
'topic_replies' => $result[13],
'topic_replies_real' => $result[13],
'topic_status' => 0,
'topic_type' => 0,
'topic_first_post_id' => $data['topic_id'],
'topic_first_poster_name' => $result[4],
'topic_first_poster_colour' => '',
'topic_last_post_id' => 0,
'topic_last_poster_id' => 0,
'topic_Last_poster_name' => '',
'topic_last_poster_colour' => '',
'topic_last_post_subject' => '',
'topic_last_post_time' => 0,
'topic_last_view_time' => 0,
'topic_moved_id' => 0,
'topic_bumped' => 0,
'topic_bumper' => 0,
'poll_title' => '',
'poll_start' => 0,
'poll_length' => 0,
'poll_max_options' => 1,
'poll_last_vote' => 0,
'poll_vote_change' => 0,
);
return $topic;
}
function add_post( $mdb2 , $post_array ){
$arr_to_string = implode( "' , '" , $post_array );
$sql = "INSERT INTO `phpbb3`.`phpbb_posts` VALUES ( '$arr_to_string' )";
return insert_into_db( $mdb2 , $sql );
}
function add_topic( $mdb2 , $topic_array ){
$arr_to_string = implode( "' , '" , $topic_array );
$sql = "INSERT INTO `phpbb3`.`phpbb_topics` VALUES ( '$arr_to_string' )";
return insert_into_db( $mdb2 , $sql );
}
function insert_into_db( $mdb2 , $sql ){
$affected =& $mdb2->exec($sql);
// Always check that result is not an error
if (PEAR::isError($affected)) {
die($affected->getMessage());
}
return $affected;
}
function get_geeklog_posts( $mdb2 ){
$sql = "SELECT * FROM `gl_forum_topic`";
$result = do_query( $mdb2 , $sql );
$size = sizeof( $result );
for( $i = 0 ; $i < $size ; $i++ ){
$text = $result[$i][11];
$uid = $bitfield = $flags = '';
generate_text_for_storage( &$text , &$uid , &$bitfield , &$flags , true , true , true );
$data[$i] = array(
'post_id' => $result[$i][0],
'topic_id' => create_topic_id( $result[$i][2] , $result[$i][0] ),
'forum_id' => forum_conversion( $result[$i][1] ),
'poster_id' => $result[$i][3] + 100,
'icon_id' => 0,
'poster_ip' => $result[$i][15],
'post_time' => $result[$i][5],
'post_approved' => 1,
'post_reported' => 0,
'enable_bbcode' => 1,
'enable_smilies' => 1,
'enable_magic_url' => 1,
'enable_sig' => 1,
'post_username' => '',
'post_subject' => addslashes($result[$i][10]),
'post_text' => addslashes($text),
'post_checksum' => md5( $text ),
'post_attachment' => '',
'bbcode_bitfield' => '$bitfield',
'bbcode_uid' => '$uid',
'post_postcount' => 1,
'post_edit_time' => 0,
'post_edit_reason' => '',
'post_edit_user' => 0,
'post_edit_count' => 0,
'post_edit_locked' => 0,
);
if ( $result[$i][2] == 0 ){
$check = check_topic_exists( $mdb2, $data[$i]['topic_id'] );
if ( $check[0][0] < 1 ){
$topic_array = create_topic( $data[$i] , $result[$i] );
$output .= "<li><b>Created topic {$topic_array['topic_title']}</b></li>\r\n";
$output .= "<ul><li>" . add_topic( $mdb2 , $topic_array ) ."</li></ul>\r\n";
}
else{
$output .= "<li>Already created topic {$check[0][6]}</li>\r\n";
}
}
if ( check_post_exists( $mdb2 , $data[$i]['post_id'] ) == NULL ){
$output .= "<li><b>Added post {$data[$i]['post_id']} ( {$data[$i]['post_subject']} ) to topic {$data[$i]['topic_id']} .</b></li>\r\n";
$output .= "<ul><li>" . add_post( $mdb2 , $data[$i] ) ."</li></ul>\r\n";
$output .= "<ul><li> {$data[$i]['post_text']} </li></ul>\r\n";
update_post_information('topic' , $data[$i]['topic_id'] , false );
update_post_information('forum' , $data[$i]['forum_id'] , false );
}
else{
$output .= "<li>Already found post {$data[$i]['post_id']} ( {$data[$i]['post_subject']} ) in topic {$data[$i]['topic_id']} .</li>\r\n";
update_post_information('topic' , $data[$i]['topic_id'] , false );
update_post_information('forum' , $data[$i]['forum_id'] , false );
}
}
return $output;
}
function create_topic_id( $topic_id , $post_id ){
//we need to know if its 0 to create a new topic, if it's not zero use that number
if ( $topic_id == 0 ){
return $post_id;
}
else{
return $topic_id;
}
}
function forum_conversion( $forum_id ){
$ids = array(
1 => 4,
2 => 5,
4 => 6,
5 => 11,
3 => 8,
7 => 10, );
return $ids[ $forum_id ];
}
function topic_id( $pid , $post_id ){
if ( $pid == 0 ){ //is a thread starter
$topic_id = $post_id;
}
else{
$topic_id = $pid;
}
return $topic_id;
}
function add_phpbb_users( $users ){
$size = sizeof( $users );
$output = "Size = $size <br />\r\n<ol>\r\n";
for ( $i = 0 ; $i < $size ; $i++ ){
$check_name = validate_username( $users[$i]['username'] );
if ( !$check_name ){
user_add( $users[$i] );
$output .= "<li>Added: {$users[$i]['username']} to phpbb! " . print_r( $check_name, true ) ."</li>\r\n";
}
else{
$output .= "<li>{$users[$i]['username']} Already exists! $check_name </li>\r\n";
}
}
$output .= "</ol>\r\n\r\n";
update_last_username();
return $output;
}
?>
Hope this can help someone else.
14
17
Quote
myiptest.com
Anonymous
Thanks,
I gust commented: 'user_id' => $result[$i][0] + 100, because of mysql error with duplicate keys.
I gust commented: 'user_id' => $result[$i][0] + 100, because of mysql error with duplicate keys.
15
17
Quote
Status: offline
grant
Forum User
Junior
Registered: 12/14/05
Posts: 21
Location:Iowa City, IA
Quote by: myiptest.com
Thanks,
I gust commented: 'user_id' => $result[$i][0] + 100, because of mysql error with duplicate keys.
Yeah that just adds 100 to the userid stored in the geeklog database because phpbb ships with bots using all the low numbers. You could use any number you want but unfortunately you'd have to change it in several places. Glad it helped somebody.
14
16
Quote
All times are EST. The time is now 07:53 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content