- Timestamp:
- Apr 28, 2010, 4:20:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xpressme_integration_kit/class/xpressD3commentContent.class.php
r583 r590 9 9 { 10 10 // include_once dirname(dirname(__FILE__)).'/include/common_functions.php' ; 11 11 global $forum_id; 12 12 13 $db =& Database::getInstance() ; 13 14 $myts =& MyTextsanitizer::getInstance() ; … … 23 24 24 25 $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname); 25 26 $blog_info = $this->get_comment_blog_info($forum_id); 26 27 // query 27 $post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$ db->prefix($xpress_prefix."_posts")."WHERE ID=$post_id AND comment_status ='open'" ) ) ;28 $post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ; 28 29 if( empty( $post_row ) ) return '' ; 29 30 30 31 // dare to convert it irregularly 31 32 $summary = str_replace( '&' , '&' , htmlspecialchars( xoops_substr( strip_tags( $post_row['post_content'] ) , 0 , 255 ) , ENT_QUOTES ) ) ; 32 33 $uri = preg_replace('/\/$/','',$blog_info['home']); 34 $uri .= '/?p='.$post_row['ID']; 33 35 return array( 34 'dirname' => $mydirname ,35 'module_name' => $ module->getVar( 'name' ),36 'dirname' => $mydirname. $blog_info['sub_dir'] , 37 'module_name' => $blog_info['blogname'] , 36 38 'subject' => $post_row['post_title'] , 37 'uri' => XOOPS_URL.'/modules/'.$mydirname.'/?p='.$post_row['ID'],39 'uri' => $uri , 38 40 'summary' => $summary , 39 41 ) ; … … 61 63 function canAddComment($external_link_id) 62 64 { 65 global $forum_id; 66 global $post; 67 68 if (is_object($post)){ // in wordpress 69 if ($post->ID == $external_link_id){ 70 if($post->comment_status == 'open'){ 71 return true; 72 } else { 73 return false; 74 } 75 } 76 } 63 77 $db =& Database::getInstance() ; 64 78 $myts =& MyTextsanitizer::getInstance() ; … … 73 87 if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ; 74 88 89 $blog_info = $this->get_comment_blog_info($forum_id); 75 90 $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname); 76 91 77 92 // query 78 $sql = "SELECT * FROM ".$ db->prefix($xpress_prefix."_posts")."WHERE ID=$post_id";93 $sql = "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id"; 79 94 $post_row = $db->fetchArray( $db->query( $sql ) ) ; 80 95 if( empty( $post_row ) ) return false ; … … 156 171 function validate_id( $link_id ) 157 172 { 173 global $forum_id; 158 174 $post_id = intval( $link_id ) ; 159 175 $mydirname = $this->mydirname ; 160 176 $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname); 161 177 $blog_info = $this->get_comment_blog_info($forum_id); 162 178 $db =& Database::getInstance() ; 163 179 164 list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$ db->prefix($xpress_prefix."_posts")."WHERE ID=$post_id AND comment_status ='open'" ) ) ;180 list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$blog_info['mb_table_prefix'] ."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ; 165 181 166 182 if( $count <= 0 ) return false ; … … 185 201 function processCommentNotifications( $mode , $link_id , $forum_id , $topic_id , $post_id ) 186 202 { 203 $blog_info = $this->get_comment_blog_info($forum_id); 204 $wp_full_prefix = $blog_info['mb_table_prefix']; 205 187 206 $db =& Database::getInstance() ; 188 207 $myts =& MyTextsanitizer::getInstance() ; … … 198 217 $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname); 199 218 200 $table_term_relationships = $ db->prefix($xpress_prefix."_term_relationships");201 $table_term_taxonomy = $ db->prefix($xpress_prefix."_term_taxonomy");202 $table_terms = $ db->prefix($xpress_prefix."_terms");219 $table_term_relationships = $wp_full_prefix ."term_relationships"; 220 $table_term_taxonomy = $wp_full_prefix."term_taxonomy"; 221 $table_terms = $wp_full_prefix."terms"; 203 222 $table_categories = $db->prefix($xpress_prefix."_categories"); 204 223 $table_post2cat = $db->prefix($xpress_prefix."_post2cat"); 205 $wp_post = $ db->prefix($xpress_prefix."_posts");206 $wp_options = $ db->prefix($xpress_prefix."_options");224 $wp_post = $wp_full_prefix."posts"; 225 $wp_options = $wp_full_prefix."options"; 207 226 $wp_users = $db->prefix($xpress_prefix."_users"); 208 227 … … 268 287 function sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){ 269 288 289 $blog_info = $this->get_comment_blog_info($forum_id); 290 $wp_full_prefix = $blog_info['mb_table_prefix']; 291 $blog_id = $blog_info['blog_id']; 292 $target_db_prefix = $blog_info['mb_table_prefix']; 270 293 $mydirname = $this->mydirname ; 271 294 $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname); … … 276 299 $xoopsDB =& Database::getInstance(); 277 300 278 $wp_comments = $ xoopsDB->prefix($xpress_prefix . '_comments');279 $wp_posts = $ xoopsDB->prefix($xpress_prefix . '_posts');301 $wp_comments = $wp_full_prefix . 'comments'; 302 $wp_posts = $wp_full_prefix . 'posts'; 280 303 $wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link'); 281 304 $d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts'); … … 355 378 356 379 $wp_sql = "INSERT INTO $wp_d3forum_link "; 357 $wp_sql .= "(comment_ID , post_id ) ";380 $wp_sql .= "(comment_ID , post_id, forum_id,blog_id) "; 358 381 $wp_sql .= "VALUES "; 359 $wp_sql .= "($comment_ID, $post_id )";382 $wp_sql .= "($comment_ID, $post_id ,$forum_id,$blog_id)"; 360 383 $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); 361 384 } … … 370 393 break; 371 394 case 'edit': 372 $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id ";395 $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id "; 373 396 $wp_res = $xoopsDB->query($wp_sql, 0, 0); 374 397 if ($wp_res === false){ … … 427 450 } 428 451 return $ret; 429 } 452 } 430 453 431 } 454 function get_comment_blog_info($d3forum_forum_id){ 455 $xoopsDB =& Database::getInstance(); 456 $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ; 457 $xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix); 458 $xp_prefix = $xoopsDB->prefix($xp_prefix); 459 $table_name = 'options'; 460 $options_array = array(); 461 462 463 $sql = "SHOW TABLES LIKE '" . $xp_prefix . '%' . $table_name . "'"; 464 if($result = $xoopsDB->queryF($sql)){ 465 while($row = $xoopsDB->fetchRow($result)){ 466 $wp_option_table = $row[0]; 467 $pattern = '/'. $table_name . '/'; 468 $option['mb_table_prefix'] = preg_replace($pattern,'',$wp_option_table); 469 if (preg_match('/'. $xp_prefix . '_([0-9]*)_/',$option['mb_table_prefix'],$matchs)){ 470 $option['blog_id'] = $matchs[1]; 471 } else { 472 $option['blog_id'] = 1; 473 } 474 475 $option_sql = "SELECT option_name, option_value FROM $wp_option_table WHERE option_name IN ('home','siteurl','blogname','xpressme_option')"; 476 if($option_result = $xoopsDB->query($option_sql, 0, 0)){ 477 while($option_row = $xoopsDB->fetchArray($option_result)){ 478 $name = $option_row['option_name']; 479 $value = $option_row['option_value']; 480 if ($name == 'xpressme_option'){ 481 $value = @unserialize( $value ); 482 } 483 $option[$name] = $value; 484 } 485 $option['siteurl'] = preg_replace('/\/$/','',$option['siteurl']); 486 $option['home'] = preg_replace('/\/$/','',$option['home']); 487 488 if ($option['blog_id'] === 1){ 489 $option['sub_dir'] = ''; 490 } else { 491 $xoops_url = str_replace('/','\\/',XOOPS_URL); 492 if (preg_match('/'. $xoops_url . '.*' . $wpdirname . '(.*)/',$option['home'],$matchs)){ 493 $option['sub_dir'] = $matchs[1]; 494 } else { 495 $option['sub_dir'] = ''; 496 } 497 } 498 if ($option['xpressme_option']['d3forum_forum_id'] == $d3forum_forum_id){ 499 return $option; 500 } 501 } 502 } 503 return null; 504 } 505 } 506 function repair_d3forum_link($comment_ID, $post_id ,$forum_id,$blog_id,$target_db_prefix){ 507 } 508 509 } // class 432 510 } 433 511 ?>
Note: See TracChangeset
for help on using the changeset viewer.