Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php	(revision 584)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php	(revision 590)
@@ -115,9 +115,11 @@
 
 function get_d3forum_post_ID($wp_comment_ID){
-	global $xoops_db;
+	global $xoops_db,$blog_id;
+	
+	if (empty($blog_id)) $blog_id =1;
 
 	$wp_d3forum_link = get_wp_prefix() . 'd3forum_link';
 	
-	$sql  =	"SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $wp_comment_ID";
+	$sql  =	"SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $wp_comment_ID AND blog_id = $blog_id";
 	$post_id = $xoops_db->get_var($sql);
 	return $post_id;
@@ -125,9 +127,11 @@
 
 function get_wp_comment_ID($d3forum_post_ID){
-	global $xoops_db;
+	global $xoops_db,$blog_id;
+	
+	if (empty($blog_id)) $blog_id =1;
 
 	$wp_d3forum_link = get_wp_prefix() . 'd3forum_link';
 	
-	$sql  =	"SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID";
+	$sql  =	"SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID AND blog_id = $blog_id";
 	$comment_ID = $xoops_db->get_var($sql);
 	return $comment_ID;
@@ -167,4 +171,6 @@
 	global $xpress_config,$xoops_db;
 	
+	$d3f_forum_id = $xpress_config->d3forum_forum_id;
+	
 	if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. ');
 	$d3f_forum_dir  = $xpress_config->d3forum_module_dir;
@@ -174,5 +180,5 @@
 		$sql  = "UPDATE $d3f_topic ";
 		$sql .= "SET topic_locked = $lock ";
-		$sql .= "WHERE topic_external_link_id = $wp_post_id" ;
+		$sql .= "WHERE topic_external_link_id = $wp_post_id AND forum_id = $d3f_forum_id" ;
 		$xoops_db->query($sql);
 }
@@ -180,5 +186,5 @@
 // All comments of WordPress are exported to the D3Forum comment. 
 function wp_to_d3forum($forum_id = 1, $d3f_prefix = 'd3forum'){
-	global $xpress_config,$xoops_db;
+	global $xpress_config,$xoops_db,$wpdb;
 
 	if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. ');
@@ -187,7 +193,7 @@
 	$xpress_prefix = get_wp_prefix();
 	
-	$wp_comments = $xpress_prefix . 'comments';
+	$wp_comments = $wpdb->comments;
 	$wp_d3forum_link = $xpress_prefix . 'd3forum_link';
-	$wp_posts = $xpress_prefix . 'posts';
+	$wp_posts = $wpdb->posts;
 	$d3f_topic = $d3forum_prefix . 'topics';	// delete key forum_id
 	$d3f_forums = $d3forum_prefix . 'forums';	// delete key forum_id
@@ -239,5 +245,5 @@
 
 	$comment_count = 0;
-	$comments = $xoops_db->get_results($sql);
+	$comments = $wpdb->get_results($sql);
 	foreach($comments as $comment){
 		$comment_ID = $comment->comment_ID;
@@ -254,5 +260,5 @@
 // All comments of D3Forum are import to the WordPress comment. 
 function d3forum_to_wp($forum_id = 1, $d3f_prefix = 'd3forum'){
-	global $xpress_config,$xoops_db;
+	global $xpress_config,$xoops_db,$wpdb;
 	if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. ');
 	
@@ -260,8 +266,7 @@
 	$xpress_prefix = get_wp_prefix() ;
 	
-	$wp_comments = $xpress_prefix . 'comments';
+	$wp_comments = $wpdb->comments;
 	$wp_d3forum_link = $xpress_prefix . 'd3forum_link';
 	$wp_dummy = $xpress_prefix . 'dummy';
-	$wp_d3forum_link  = $xpress_prefix . 'd3forum_link';
 	
 	$d3f_topic = $d3forum_prefix . 'topics';
@@ -287,5 +292,5 @@
 
 	//All wp post comment count clear
-	$wp_posts = $xpress_prefix . 'posts';
+	$wp_posts = $wpdb->posts;
 	$xoops_db->query("UPDATE $wp_posts SET  comment_count = 0 WHERE 1 ");
 		
@@ -327,4 +332,5 @@
 	$d3forum_dirname = $xpress_config->d3forum_module_dir;
 	$d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_';
+	$d3forum_forum_id = $xpress_config->d3forum_forum_id;
 
 	$post_id = intval( $post_id ) ;
@@ -332,5 +338,5 @@
 	$d3f_topics = $d3forum_prefix . 'topics';
 	
-	$sql = "SELECT topic_id,topic_first_post_id FROM $d3f_topics WHERE topic_external_link_id = $post_id";
+	$sql = "SELECT topic_id,topic_first_post_id FROM $d3f_topics WHERE topic_external_link_id = $post_id AND forum_id = $d3forum_forum_id";
 	$row = $xoops_db->get_row($sql) ;
 	
@@ -346,12 +352,16 @@
 
 function d3forum_sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){
-	global $xpress_config,$xoops_db;
+	global $xpress_config,$xoops_db,$wpdb,$blog_id;
 
 	if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. ');
+
+	if (empty($blog_id)) $blog_id =1;
+	$d3f_forum_id = $xpress_config->d3forum_forum_id;
+
 	$d3forum_prefix = get_xoops_prefix() . $xpress_config->d3forum_module_dir . '_';
 	$xpress_prefix = get_wp_prefix();
 	
-	$wp_comments = $xpress_prefix . 'comments';
-	$wp_posts = $xpress_prefix . 'posts';
+	$wp_comments = $wpdb->comments;
+	$wp_posts = $wpdb->posts;
 	$wp_d3forum_link = $xpress_prefix . 'd3forum_link';
 	
@@ -424,7 +434,7 @@
 				$xoops_db->query($wp_sql);
 				$wp_sql  = "INSERT INTO $wp_d3forum_link ";
-				$wp_sql .=    "(comment_ID , post_id) ";
+				$wp_sql .=    "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) ";
 				$wp_sql .=  "VALUES ";
-				$wp_sql .=    "($comment_ID, $post_id)";		
+				$wp_sql .=    "($comment_ID, $post_id, $link_id, $d3f_forum_id, $blog_id)";		
 				$xoops_db->query($wp_sql);				
 				if ($comment_approved ==0)	do_CommentWaiting($comment_ID, $post_id);
@@ -458,5 +468,7 @@
 //  The content is reflected in the D3Forum comment when there is a change in the WordPress comment. 
 function wp_comment_sync_to_d3forum($comment_ID = 0,$sync_mode){
-	global $xpress_config,$xoops_db,$xoops_config;
+	global $xpress_config,$xoops_db,$xoops_config,$wpdb,$blog_id;
+	
+	if (empty($blog_id)) $blog_id =1;
 	
 	if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. ');
@@ -468,6 +480,8 @@
 	$d3forum_prefix = get_xoops_prefix() . $d3f_forum_dir . '_';
 	$xpress_prefix = get_wp_prefix();
-	$wp_comments = $xpress_prefix . 'comments';
-	$wp_posts = $xpress_prefix . 'posts';
+	$wp_comments =  $wpdb->comments;
+//	$wp_comments = $xpress_prefix . 'comments';
+	$wp_posts = $wpdb->posts;
+//	$wp_posts = $xpress_prefix . 'posts';
 	$wp_d3forum_link = $xpress_prefix . 'd3forum_link';
 	$d3f_topic = $d3forum_prefix . 'topics';
@@ -484,5 +498,6 @@
 	$sql .=	"WHERE (comment_ID = $comment_ID) AND ($wp_comments.comment_approved NOT LIKE 'spam') ";
 
-	$row = $xoops_db->get_row($sql) ;
+//	$row = $xoops_db->get_row($sql) ;
+	$row = $wpdb->get_row($sql) ;
 	if(empty($row)) die( 'READ ' . $wp_comments . '_NG...' .$sql);
 	if (! empty($row->comment_type)) return;
@@ -513,5 +528,5 @@
 	if ($sync_mode == 'delete'){
 		$mode = 'delete';
-		$delete_post_id = $xoops_db->get_var("SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $comment_ID");
+		$delete_post_id = $xoops_db->get_var("SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $comment_ID AND  blog_id = $blog_id");
 		if (empty($delete_post_id)) return;
 		$topic_id = $xoops_db->get_var("SELECT topic_id FROM $d3f_topic WHERE topic_external_link_id = $topic_external_link_id AND forum_id = $forum_id");
@@ -528,5 +543,5 @@
 			
 			// if comment on same ID exists then edits comment else reply comment
-			$row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID") ;
+			$row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID AND blog_id = $blog_id" ) ;
 			
 			if (!empty($row)){
@@ -629,7 +644,7 @@
 			
 			$wp_sql  = "INSERT INTO $wp_d3forum_link ";
-			$wp_sql .=    "(comment_ID , post_id) ";
+			$wp_sql .=    "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) ";
 			$wp_sql .=  "VALUES ";
-			$wp_sql .=    "($comment_ID, $post_id)";
+			$wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id, $d3f_forum_id, $blog_id)";		
 			$xoops_db->query($wp_sql);
 			
@@ -666,7 +681,7 @@
 			
 			$wp_sql  = "INSERT INTO $wp_d3forum_link ";
-			$wp_sql .=    "(comment_ID , post_id , wp_post_ID) ";
+			$wp_sql .=    "(comment_ID , post_id , wp_post_ID, forum_id, blog_id) ";
 			$wp_sql .=  "VALUES ";
-			$wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id)";		
+			$wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id, $d3f_forum_id, $blog_id)";		
 			$xoops_db->query($wp_sql);
 
@@ -701,6 +716,10 @@
 function wp_d3forum_delete_post_recursive( $d3forum_dirname , $post_id ,$isChild = false)
 {
+	global $wpdb,$blog_id;
+	global $xpress_config,$xoops_db;
 	$post_id = intval( $post_id ) ; // post_id is d3forum post(comments) id.
-	global $xpress_config,$xoops_db;
+	if (empty($blog_id)) $blog_id =1;
+
+	
 	$d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_';
 	$xpress_prefix = get_wp_prefix();
@@ -718,18 +737,18 @@
 	$xoops_db->query( "DELETE FROM ".$d3forum_prefix."post_votes WHERE post_id=$post_id" ) ;
 	
-	$wp_comments = $xpress_prefix . 'comments';
-	$wp_posts = $xpress_prefix . 'posts';
+	$wp_comments = $wpdb->comments;
+	$wp_posts = $wpdb->posts;
 	$wp_d3forum_link = $xpress_prefix . 'd3forum_link';
 
 	$comment_ID = get_wp_comment_ID($post_id);  // get wordpress comment ID
 	if ($comment_ID > 0){
-		$comment_post_ID = $xoops_db->get_var("SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID");
+		$comment_post_ID = $wpdb->get_var("SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID");
 		if ($isChild){		//The first comment is deleted on the WordPress side. 
-			$xoops_db->query("DELETE FROM $wp_comments WHERE comment_ID = $comment_ID");
+			$wpdb->query("DELETE FROM $wp_comments WHERE comment_ID = $comment_ID");
 			if (!empty($comment_post_ID)){
-				$xoops_db->query("UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID");
+				$wpdb->query("UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID");
 			}
 		}	
-		$xoops_db->query("DELETE FROM $wp_d3forum_link WHERE post_id = $post_id");
+		$xoops_db->query("DELETE FROM $wp_d3forum_link WHERE post_id = $post_id AND blog_id = $blog_id");
 	}
 }
@@ -741,5 +760,4 @@
 	global $xpress_config,$xoops_db;
 	$d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_';
-	$xpress_prefix = get_wp_prefix();
 
 	$topic_id = intval( $topic_id ) ;
Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php	(revision 584)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php	(revision 590)
@@ -644,4 +644,6 @@
 		global $xoops_db,$xoops_config;
 		
+		$multi_blog_use_d3forum = true;
+		
 		$d3frum_list = array();
 		$module_dir_path = get_xoops_root_path();
@@ -654,5 +656,5 @@
 			$selected = '';
 		
-		if (xpress_is_multiblog()) {
+		if (xpress_is_multiblog() && $multi_blog_use_d3forum) {
 			$forum_list .= '<option value="none"' . $selected . '>' . __('WordPress MultiBlog cannot integrate the comments.', 'xpressme') . "</option>\n";
 		} else {	
