Index: trunk/xpressme_integration_kit/class/xpressD3commentContent.class.php
===================================================================
--- trunk/xpressme_integration_kit/class/xpressD3commentContent.class.php	(revision 589)
+++ trunk/xpressme_integration_kit/class/xpressD3commentContent.class.php	(revision 590)
@@ -9,5 +9,6 @@
 		{
 		//	include_once dirname(dirname(__FILE__)).'/include/common_functions.php' ;
-
+			global $forum_id;
+			
 			$db =& Database::getInstance() ;
 			$myts =& MyTextsanitizer::getInstance() ;
@@ -23,17 +24,18 @@
 			
 			$xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
-
+			$blog_info = $this->get_comment_blog_info($forum_id);
 			// query
-			$post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$db->prefix($xpress_prefix."_posts")." WHERE ID=$post_id AND comment_status ='open'" ) ) ;
+			$post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ;
 			if( empty( $post_row ) ) return '' ;
 
 			// dare to convert it irregularly
 			$summary = str_replace( '&amp;' , '&' , htmlspecialchars( xoops_substr( strip_tags( $post_row['post_content'] ) , 0 , 255 ) , ENT_QUOTES ) ) ;
-
+			$uri = preg_replace('/\/$/','',$blog_info['home']);
+			$uri .= '/?p='.$post_row['ID'];
 			return array(
-				'dirname' => $mydirname ,
-				'module_name' => $module->getVar( 'name' ) ,
+				'dirname' => $mydirname. $blog_info['sub_dir'] ,
+				'module_name' => $blog_info['blogname'] ,
 				'subject' => $post_row['post_title'] ,
-				'uri' => XOOPS_URL.'/modules/'.$mydirname.'/?p='.$post_row['ID'] ,
+				'uri' => $uri ,
 				'summary' => $summary ,
 			) ;
@@ -61,4 +63,16 @@
 		function canAddComment($external_link_id)
 		{
+			global $forum_id;
+			global $post;
+			
+			if (is_object($post)){  // in wordpress 
+				if ($post->ID == $external_link_id){
+					if($post->comment_status == 'open'){
+						return true;
+					} else {
+						return false;
+					}
+				}
+			}
 					$db =& Database::getInstance() ;
 					$myts =& MyTextsanitizer::getInstance() ;
@@ -73,8 +87,9 @@
 					if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
 					
+					$blog_info = $this->get_comment_blog_info($forum_id);
 					$xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
 
 					// query
-					$sql = "SELECT * FROM ".$db->prefix($xpress_prefix."_posts")." WHERE ID=$post_id";
+					$sql = "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id";
 					$post_row = $db->fetchArray( $db->query( $sql ) ) ;
 					if( empty( $post_row ) ) return false ;
@@ -156,11 +171,12 @@
 		function validate_id( $link_id )
 		{
+			global $forum_id;
 			$post_id = intval( $link_id ) ;
 			$mydirname = $this->mydirname ;
 			$xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
-			
+			$blog_info = $this->get_comment_blog_info($forum_id);		
 			$db =& Database::getInstance() ;
 			
-			list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix($xpress_prefix."_posts")." WHERE ID=$post_id AND comment_status ='open'" ) ) ;
+			list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$blog_info['mb_table_prefix'] ."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ;
 
 			if( $count <= 0 ) return false ;
@@ -185,4 +201,7 @@
 		function processCommentNotifications( $mode , $link_id , $forum_id , $topic_id , $post_id )
 		{
+			$blog_info = $this->get_comment_blog_info($forum_id);
+			$wp_full_prefix = $blog_info['mb_table_prefix'];
+
 			$db =& Database::getInstance() ;
 			$myts =& MyTextsanitizer::getInstance() ;
@@ -198,11 +217,11 @@
 			$xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
 			
-			$table_term_relationships = $db->prefix($xpress_prefix."_term_relationships");
-			$table_term_taxonomy = $db->prefix($xpress_prefix."_term_taxonomy");
-			$table_terms = $db->prefix($xpress_prefix."_terms");
+			$table_term_relationships = $wp_full_prefix ."term_relationships";
+			$table_term_taxonomy = $wp_full_prefix."term_taxonomy";
+			$table_terms = $wp_full_prefix."terms";
 			$table_categories = $db->prefix($xpress_prefix."_categories");
 			$table_post2cat = $db->prefix($xpress_prefix."_post2cat");
-			$wp_post = $db->prefix($xpress_prefix."_posts");
-			$wp_options = $db->prefix($xpress_prefix."_options");
+			$wp_post = $wp_full_prefix."posts";
+			$wp_options = $wp_full_prefix."options";
 			$wp_users  = $db->prefix($xpress_prefix."_users");
 						
@@ -268,4 +287,8 @@
 		function sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){
 
+			$blog_info = $this->get_comment_blog_info($forum_id);
+			$wp_full_prefix = $blog_info['mb_table_prefix'];
+			$blog_id = $blog_info['blog_id'];
+			$target_db_prefix = $blog_info['mb_table_prefix'];
 			$mydirname = $this->mydirname ;
 			$xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
@@ -276,6 +299,6 @@
 			$xoopsDB =& Database::getInstance();
 
-			$wp_comments = $xoopsDB->prefix($xpress_prefix . '_comments');
-			$wp_posts = $xoopsDB->prefix($xpress_prefix . '_posts');
+			$wp_comments = $wp_full_prefix . 'comments';
+			$wp_posts = $wp_full_prefix . 'posts';
 			$wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link');
 			$d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts');
@@ -355,7 +378,7 @@
 						
 							$wp_sql  = "INSERT INTO $wp_d3forum_link ";
-							$wp_sql .=    "(comment_ID , post_id) ";
+							$wp_sql .=    "(comment_ID , post_id, forum_id,blog_id) ";
 							$wp_sql .=  "VALUES ";
-							$wp_sql .=    "($comment_ID, $post_id)";		
+							$wp_sql .=    "($comment_ID, $post_id ,$forum_id,$blog_id)";		
 							$wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
 						}
@@ -370,5 +393,5 @@
 						break;
 					case 'edit':
-						$wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id";
+						$wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id ";
 						$wp_res = $xoopsDB->query($wp_sql, 0, 0);
 						if ($wp_res === false){
@@ -427,7 +450,62 @@
 			}
 			return $ret;
-		}				
+		}
 		
-	}
+		function get_comment_blog_info($d3forum_forum_id){
+			$xoopsDB =& Database::getInstance();
+			$xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
+			$xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix);
+			$xp_prefix = $xoopsDB->prefix($xp_prefix);
+			$table_name = 'options';
+			$options_array = array();
+
+
+				$sql = "SHOW TABLES LIKE '" . $xp_prefix  . '%' . $table_name . "'";
+				if($result = $xoopsDB->queryF($sql)){
+					while($row = $xoopsDB->fetchRow($result)){
+						$wp_option_table = $row[0];
+						$pattern = '/'. $table_name . '/';
+						$option['mb_table_prefix'] =  preg_replace($pattern,'',$wp_option_table);
+						if (preg_match('/'. $xp_prefix . '_([0-9]*)_/',$option['mb_table_prefix'],$matchs)){
+							$option['blog_id'] = $matchs[1];
+						} else {
+							$option['blog_id'] = 1;
+						}
+						
+						$option_sql = "SELECT option_name, option_value FROM $wp_option_table WHERE option_name IN ('home','siteurl','blogname','xpressme_option')";
+						if($option_result =  $xoopsDB->query($option_sql, 0, 0)){
+							while($option_row = $xoopsDB->fetchArray($option_result)){
+								$name = $option_row['option_name'];
+								$value = $option_row['option_value'];
+								if ($name == 'xpressme_option'){
+									$value =  @unserialize( $value );
+								}
+								$option[$name] = $value;
+							}
+							$option['siteurl'] = preg_replace('/\/$/','',$option['siteurl']);
+							$option['home'] = preg_replace('/\/$/','',$option['home']);
+							
+							if ($option['blog_id'] === 1){
+								$option['sub_dir'] = '';
+							} else {
+								$xoops_url = str_replace('/','\\/',XOOPS_URL);
+								if (preg_match('/'. $xoops_url . '.*' . $wpdirname . '(.*)/',$option['home'],$matchs)){
+									$option['sub_dir'] = $matchs[1];
+								} else {
+									$option['sub_dir'] = '';
+								}
+							}
+							if ($option['xpressme_option']['d3forum_forum_id'] == $d3forum_forum_id){
+								return $option;
+							}
+						}
+					}
+					return null;
+				}
+		}
+		function repair_d3forum_link($comment_ID, $post_id ,$forum_id,$blog_id,$target_db_prefix){
+		}
+		
+	} // class
 }
 ?>
Index: trunk/xpressme_integration_kit/include/oninstall.php
===================================================================
--- trunk/xpressme_integration_kit/include/oninstall.php	(revision 589)
+++ trunk/xpressme_integration_kit/include/oninstall.php	(revision 590)
@@ -110,4 +110,6 @@
   		post_id int(10) unsigned NOT NULL default '0' ,
   		wp_post_ID bigint(20) unsigned NOT NULL default '0',
+  		forum_id bigint(20) unsigned NOT NULL default '0',
+  		blog_id bigint(20) unsigned NOT NULL default '0',
   		KEY post_id (post_id)
 		)$charset_collate;";
Index: trunk/xpressme_integration_kit/include/onupdate.php
===================================================================
--- trunk/xpressme_integration_kit/include/onupdate.php	(revision 589)
+++ trunk/xpressme_integration_kit/include/onupdate.php	(revision 590)
@@ -223,14 +223,33 @@
 	}
 	
+	$d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
 	if (! enhanced_table_check($mydirname,'d3forum_link')){
-		$d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
 		$queries ="CREATE TABLE $d3forum_link (
 	  		comment_ID bigint(20) unsigned NOT NULL default '0',
 	  		post_id int(10) unsigned NOT NULL default '0' ,
 	  		wp_post_ID bigint(20) unsigned NOT NULL default '0',
+			forum_id bigint(20) unsigned NOT NULL default '0',
+			blog_id bigint(20) unsigned NOT NULL default '0',
 	  		KEY post_id (post_id)
 			)TYPE=MyISAM";
 		$db->queryF( $queries ) ;
 		$msgs[] = "$d3forum_link table of XPressME was made.";
+	} else {
+		if (!is_found_table_column($d3forum_link,'forum_id')){
+			$queries ="ALTER TABLE $d3forum_link ADD forum_id bigint(20) unsigned NOT NULL default '0' AFTER wp_post_ID";
+			$db->queryF( $queries ) ;
+			$msgs[] = "$d3forum_link  ADD forum_id .";
+			// The table is repaired.
+//			$update_sql = "UPDATE $d3forum_link SET forum_id = 1 WHERE(forum_id IS NULL OR forum_id < 1)";
+//			$db->queryF( $update_sql ) ;
+		}
+		if (!is_found_table_column($d3forum_link,'blog_id')){
+			$queries ="ALTER TABLE $d3forum_link ADD blog_id bigint(20)  unsigned NOT NULL default '0' AFTER forum_id";
+			$db->queryF( $queries ) ;
+			$msgs[] = "$d3forum_link  ADD blog_id .";
+			// The table is repaired.
+			$update_sql = "UPDATE $d3forum_link SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)";
+			$db->queryF( $update_sql ) ;
+		}
 	}
 
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 589)
+++ 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 589)
+++ 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 {	
