server, $this->user, $this->password); * * to this: * * @mysql_connect($this->server, $this->user, $this->password, true); * ****************************************************************************/ /*************************************************************************** * SETUP ****************************************************************************/ // phorum.org database $phorum_dbname = ""; $phorum_dbhost = ""; $phorum_dbuser = ""; $phorum_dbpasswd = ""; $phorum_forums_table = "forums"; /* =================================================================== */ define('IN_PHPBB', 1); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'config.'.$phpEx); include($phpbb_root_path . 'includes/constants.'.$phpEx); include($phpbb_root_path . 'includes/functions.'.$phpEx); include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); include($phpbb_root_path . 'includes/functions_post.'.$phpEx); include($phpbb_root_path . 'includes/functions_search.'.$phpEx); include($phpbb_root_path . 'includes/db.'.$phpEx); $phorum_db = new sql_db($phorum_dbhost, $phorum_dbuser, $phorum_dbpasswd, $phorum_dbname, false); set_time_limit(0); /************************************************************************** * from admin/admin_forums.php **************************************************************************/ $forum_auth_ary = array( "auth_view" => AUTH_ALL, "auth_read" => AUTH_ALL, "auth_post" => AUTH_ALL, "auth_reply" => AUTH_ALL, "auth_edit" => AUTH_REG, "auth_delete" => AUTH_REG, "auth_sticky" => AUTH_REG, "auth_announce" => AUTH_MOD, "auth_vote" => AUTH_REG, "auth_pollcreate" => AUTH_REG ); function convert( $a_string = '' ) { $a_string = preg_replace( '#[\\\]+#', '\\', $a_string ); $a_string = str_replace('\\\'', '\'', $a_string); $a_string = str_replace('\\', '\\\\', $a_string); $a_string = str_replace('\'', '\\\'', $a_string); $a_string = trim( $a_string ); return $a_string; } function create_category( $name ) { global $db; $sql = "SELECT MAX(cat_order) AS max_order FROM " . CATEGORIES_TABLE; if( !$result = $db->sql_query($sql) ) { echo "Can't get max cat_order from " . CATEGORIES_TABLE . " table ($sql"; exit; } $row = $db->sql_fetchrow($result); $max_order = $row['max_order']; $next_order = $max_order + 10; $sql = "INSERT INTO " . CATEGORIES_TABLE . " (cat_title, cat_order) VALUES ('$name', $next_order)"; if( !$result = $db->sql_query($sql) ) { echo "Couldn't insert row in categories table '$sql'"; exit; } $cat_id = $db->sql_nextid(); echo "New category '$name', ID: $cat_id\n"; return $cat_id; } echo "
Starting the import...\n";

/**************************************************************************
 * copied from admin/admin_forums.php
 **************************************************************************/
$import_cat_id = create_category( 'Imported from Phorums' );

$phorum_to_phpbb_cat = array();

$sql= "SELECT id,name,folder,parent,description,table_name FROM $phorum_forums_table order by id";

if ( !($result = $phorum_db->sql_query($sql)) ) {
  echo "Could not get list of forums in phorum db ($sql)";
  exit;
}

if ( $row = $db->sql_fetchrow( $result ) )  {
  
  do {
    $tablename = $row['table_name'];
    $forumname = $row['name'];
    $forumdesc = $row['description'];
    
    if ( $row['folder'] == '1' ) {
      $phorum_to_phpbb_cat[ $row['id'] ] = create_category( convert( $forumname ) );
    }
    else {
      if ( $row['parent'] != 0 ) {
	if ( ! array_key_exists( $row['parent'], $phorum_to_phpbb_cat ) ) {
	  echo "Folder parent (" . $row['parent'] . ") could not be found in phorum_to_phpbb_cat\n";
	  var_dump( $phorum_to_phpbb_cat );
	  exit;
	}
	
	$cat_id = $phorum_to_phpbb_cat[ $row['parent'] ];
      }
      else {
	$cat_id = $import_cat_id;
      }
      
      $result_tmp = $phorum_db->sql_query( "SELECT COUNT(id) as forum_posts FROM $tablename");
      $forum_posts = $phorum_db->sql_fetchfield('forum_posts');
      if ( $forum_posts == '' ) { $forum_posts = 0; }
      
      $result_tmp = $phorum_db->sql_query( "SELECT COUNT(id) as forum_topics FROM $tablename WHERE parent=0");
      $forum_topics = $phorum_db->sql_fetchfield('forum_topics');
      if ( $forum_topics == '' ) { $forum_topics = 0; }
      
      $sql = "SELECT MAX(forum_order) AS max_order FROM " . FORUMS_TABLE . " WHERE cat_id = $cat_id";
      if( !$result_tmp = $db->sql_query($sql) ) {
	echo "Couldn't get order number from phpBB forums table ($sql)";
	exit;
      }
      $row_tmp = $db->sql_fetchrow($result_tmp);
      
      $max_order = $row_tmp['max_order'];
      $next_order = $max_order + 10;
      
      $sql = "SELECT MAX(forum_id) AS max_id FROM " . FORUMS_TABLE;
      if( !$result_tmp = $db->sql_query($sql) ) {
	echo "Couldn't get max forum_id forums table ($sql)";
	exit;
      }
      $row_tmp = $db->sql_fetchrow($result_tmp);
      
      $max_id = $row_tmp['max_id'];
      $next_id = $max_id + 1;
      
      //
      // Default permissions of public
      //
      $field_sql = "";
      $value_sql = "";
      while( list($field, $value) = each($forum_auth_ary) ) {
	$field_sql .= ", $field";
	$value_sql .= ", $value";
      }
      
      $sql = ( "INSERT INTO " . FORUMS_TABLE . 
	       " (forum_id,cat_id,forum_name,forum_desc,forum_order,forum_posts,forum_topics,forum_status, prune_enable $field_sql)" . 
	       " VALUES ($next_id,$cat_id, '" . convert( $forumname ) . "', '" . convert( $forumdesc ) . 
	       "', $next_order, $forum_posts, $forum_topics, 0, 0 $value_sql)" );
      
      if ( !$result_tmp = $db->sql_query($sql) ) {
	echo "Couldn't insert row in categories table ($sql)";
	exit;
      }
      
      $forum_id = $next_id;
      echo "  Added new forum '$forumname', ID: $forum_id\n";
      
      $sql = "SELECT thread,subject,datestamp FROM $tablename WHERE parent=0";
      if ( !($post_result = $phorum_db->sql_query($sql)) ) {
	echo "Couldn't select threads from phorum $tablename ($sql)";
	exit;
      }
      
      if ( $post_row = $phorum_db->sql_fetchrow($post_result) ) {
	do {
	  $thread = $post_row['thread'];
	  $subject = convert( $post_row['subject'] );
	  $ds = $post_row['datestamp'];
	  $datestamp = mktime(substr($ds, 11, 2),substr($ds, 14, 2),substr($ds, 17, 2),substr($ds, 5, 2),substr($ds, 8, 2),substr($ds, 0, 4));
	  
	  $sql = "SELECT COUNT(id) as replies FROM $tablename WHERE thread=$thread AND parent <> 0";
	  if( !$result_tmp = $phorum_db->sql_query($sql) ) {
	    echo "Couldn't get thread count from $tablename where thread=$thread ($sql)";
	    exit;
	  }
	  $row_tmp = $phorum_db->sql_fetchrow($result_tmp);
	  $replies = $row_tmp['replies'];
	  unset( $row_tmp );
	  
	  $sql = ( "INSERT INTO " . TOPICS_TABLE . 
		   " (forum_id,topic_title,topic_poster,topic_time,topic_replies) " . 
		   "VALUES ($forum_id, '" .  convert( $subject ) . "', -1, $datestamp, $replies)" );
	  
	  if( !$result_tmp = $db->sql_query($sql) ) {
	    echo "Couldn't insert post into " . TOPICS_TABLE . " table phpBB ($sql)";
	    exit;
	  }
	  
	  $topic_id = $db->sql_nextid();
	  
	  echo "    Added new topic '$subject', ID: $topic_id\n";
	  
	  $sql = ( "SELECT " . $tablename . "_bodies.body, subject, author, datestamp FROM ".$tablename." inner join ".$tablename."_bodies on ". 
		   $tablename . ".id = ".$tablename."_bodies.id WHERE ".$tablename.".thread=$thread ORDER BY ".$tablename.".id" );
	  
	  if ( !($replies_result = $phorum_db->sql_query($sql)) ) {
	    echo "Couldn't select replies from phorum $tablename ($sql)";
	    exit;
	  }
	  
	  if ( $replies_row = $phorum_db->sql_fetchrow($replies_result) ) {
	    $topic_first_post_id = 0;
	    $topic_last_post_id  =  0;
	    
	    do {
	      $author = convert( $replies_row['author'] );
	      $author = substr( $author, 0, 24);
	      $sub = convert( $replies_row['subject'] );
	      $body = convert( $replies_row['body'] );
	      
	      $ds = $replies_row['datestamp'];
	      $datestamp= mktime(substr($ds, 11, 2),substr($ds, 14, 2),substr($ds, 17, 2),substr($ds, 5, 2),substr($ds, 8, 2),substr($ds, 0, 4));
	      
	      $sql = ( "INSERT INTO " . POSTS_TABLE . " (topic_id,forum_id,poster_id,post_time,post_username,enable_bbcode,enable_smilies) " . 
		       "VALUES ($topic_id, $forum_id, -1, $datestamp, '$author', 1, 1)" );
	      
	      if( !$result_tmp = $db->sql_query($sql) ) {
		echo "Couldn't insert new post into " . POSTS_TABLE . " table '$sql'";
		exit;
	      }
	      
	      $post_id = $db->sql_nextid();
	      if ( $topic_first_post_id == 0 ) $topic_first_post_id = $post_id;
	      $topic_last_post_id = $post_id;
	      
	      
	      $sql = "INSERT INTO " . POSTS_TEXT_TABLE . "(post_id,post_subject,post_text) VALUES ($post_id,'$sub','$body')";
	      if( !$result_tmp = $db->sql_query($sql) ) {
		echo "Couldn't insert new post_text into " . POSTS_TEXT_TABLE . "row in categories table '$sql'";
		exit;
	      }
	      
	      unset( $result_tmp );
	      add_search_words($post_id, stripslashes($body), stripslashes($sub));
	      
	      // The database package keeps every sql query statment around.
	      //   this is bad as it will eat up memory until PHP dies
	      // This clears the cache and clears up the memory.
	      unset( $db->last_query_text );
	      unset( $db->row );
	      $db->num_queries = 0;
	      $db->in_transaction = 0;
	      
	      echo "      Added replies '$subject', ID: $post_id\n";
	    }  while( $replies_row = $phorum_db->sql_fetchrow($replies_result) );
	    
	    $sql = "UPDATE " . TOPICS_TABLE . " SET topic_last_post_id=$topic_last_post_id, topic_first_post_id=$topic_first_post_id WHERE topic_id=$topic_id";
	    if( !$result_tmp = $db->sql_query($sql) ) {
	      echo "Can't update " . TOPICS_TABLE . " table '$sql'";
	      exit;
	    }
	    
	    echo "      Update topics ID: $topic_id :  $topic_first_post_id - $topic_last_post_id\n";
	  }
	  
	} while( $post_row = $phorum_db->sql_fetchrow($post_result) );

	$sql = "UPDATE " . FORUMS_TABLE . " SET forum_last_post_id=$topic_last_post_id WHERE forum_id=$forum_id";
	if( !$result_tmp = $db->sql_query($sql) ) {
	  echo "Can't update " . FORUMS_TABLE . " table '$sql'";
	  exit;
	}
      }
    }
  } while ( $row = $db->sql_fetchrow($result) );
}
else {
  echo 'No forums in phorum db';
}
?>