XPressME Integration Kit

Trac


Ignore:
Timestamp:
Apr 28, 2010, 4:20:08 PM (15 years ago)
Author:
toemon
Message:

D3Forumコメント統合のマルチブログ対応 Fixes#311

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/d3forum_comment_synchro.php

    r264 r590  
    115115 
    116116function get_d3forum_post_ID($wp_comment_ID){ 
    117         global $xoops_db; 
     117        global $xoops_db,$blog_id; 
     118         
     119        if (empty($blog_id)) $blog_id =1; 
    118120 
    119121        $wp_d3forum_link = get_wp_prefix() . 'd3forum_link'; 
    120122         
    121         $sql  = "SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $wp_comment_ID"; 
     123        $sql  = "SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $wp_comment_ID AND blog_id = $blog_id"; 
    122124        $post_id = $xoops_db->get_var($sql); 
    123125        return $post_id; 
     
    125127 
    126128function get_wp_comment_ID($d3forum_post_ID){ 
    127         global $xoops_db; 
     129        global $xoops_db,$blog_id; 
     130         
     131        if (empty($blog_id)) $blog_id =1; 
    128132 
    129133        $wp_d3forum_link = get_wp_prefix() . 'd3forum_link'; 
    130134         
    131         $sql  = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID"; 
     135        $sql  = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID AND blog_id = $blog_id"; 
    132136        $comment_ID = $xoops_db->get_var($sql); 
    133137        return $comment_ID; 
     
    167171        global $xpress_config,$xoops_db; 
    168172         
     173        $d3f_forum_id = $xpress_config->d3forum_forum_id; 
     174         
    169175        if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. '); 
    170176        $d3f_forum_dir  = $xpress_config->d3forum_module_dir; 
     
    174180                $sql  = "UPDATE $d3f_topic "; 
    175181                $sql .= "SET topic_locked = $lock "; 
    176                 $sql .= "WHERE topic_external_link_id = $wp_post_id" ; 
     182                $sql .= "WHERE topic_external_link_id = $wp_post_id AND forum_id = $d3f_forum_id" ; 
    177183                $xoops_db->query($sql); 
    178184} 
     
    180186// All comments of WordPress are exported to the D3Forum comment.  
    181187function wp_to_d3forum($forum_id = 1, $d3f_prefix = 'd3forum'){ 
    182         global $xpress_config,$xoops_db; 
     188        global $xpress_config,$xoops_db,$wpdb; 
    183189 
    184190        if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. '); 
     
    187193        $xpress_prefix = get_wp_prefix(); 
    188194         
    189         $wp_comments = $xpress_prefix . 'comments'; 
     195        $wp_comments = $wpdb->comments; 
    190196        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    191         $wp_posts = $xpress_prefix . 'posts'; 
     197        $wp_posts = $wpdb->posts; 
    192198        $d3f_topic = $d3forum_prefix . 'topics';        // delete key forum_id 
    193199        $d3f_forums = $d3forum_prefix . 'forums';       // delete key forum_id 
     
    239245 
    240246        $comment_count = 0; 
    241         $comments = $xoops_db->get_results($sql); 
     247        $comments = $wpdb->get_results($sql); 
    242248        foreach($comments as $comment){ 
    243249                $comment_ID = $comment->comment_ID; 
     
    254260// All comments of D3Forum are import to the WordPress comment.  
    255261function d3forum_to_wp($forum_id = 1, $d3f_prefix = 'd3forum'){ 
    256         global $xpress_config,$xoops_db; 
     262        global $xpress_config,$xoops_db,$wpdb; 
    257263        if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. '); 
    258264         
     
    260266        $xpress_prefix = get_wp_prefix() ; 
    261267         
    262         $wp_comments = $xpress_prefix . 'comments'; 
     268        $wp_comments = $wpdb->comments; 
    263269        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    264270        $wp_dummy = $xpress_prefix . 'dummy'; 
    265         $wp_d3forum_link  = $xpress_prefix . 'd3forum_link'; 
    266271         
    267272        $d3f_topic = $d3forum_prefix . 'topics'; 
     
    287292 
    288293        //All wp post comment count clear 
    289         $wp_posts = $xpress_prefix . 'posts'; 
     294        $wp_posts = $wpdb->posts; 
    290295        $xoops_db->query("UPDATE $wp_posts SET  comment_count = 0 WHERE 1 "); 
    291296                 
     
    327332        $d3forum_dirname = $xpress_config->d3forum_module_dir; 
    328333        $d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_'; 
     334        $d3forum_forum_id = $xpress_config->d3forum_forum_id; 
    329335 
    330336        $post_id = intval( $post_id ) ; 
     
    332338        $d3f_topics = $d3forum_prefix . 'topics'; 
    333339         
    334         $sql = "SELECT topic_id,topic_first_post_id FROM $d3f_topics WHERE topic_external_link_id = $post_id"; 
     340        $sql = "SELECT topic_id,topic_first_post_id FROM $d3f_topics WHERE topic_external_link_id = $post_id AND forum_id = $d3forum_forum_id"; 
    335341        $row = $xoops_db->get_row($sql) ; 
    336342         
     
    346352 
    347353function d3forum_sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){ 
    348         global $xpress_config,$xoops_db; 
     354        global $xpress_config,$xoops_db,$wpdb,$blog_id; 
    349355 
    350356        if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. '); 
     357 
     358        if (empty($blog_id)) $blog_id =1; 
     359        $d3f_forum_id = $xpress_config->d3forum_forum_id; 
     360 
    351361        $d3forum_prefix = get_xoops_prefix() . $xpress_config->d3forum_module_dir . '_'; 
    352362        $xpress_prefix = get_wp_prefix(); 
    353363         
    354         $wp_comments = $xpress_prefix . 'comments'; 
    355         $wp_posts = $xpress_prefix . 'posts'; 
     364        $wp_comments = $wpdb->comments; 
     365        $wp_posts = $wpdb->posts; 
    356366        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    357367         
     
    424434                                $xoops_db->query($wp_sql); 
    425435                                $wp_sql  = "INSERT INTO $wp_d3forum_link "; 
    426                                 $wp_sql .=    "(comment_ID , post_id) "; 
     436                                $wp_sql .=    "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) "; 
    427437                                $wp_sql .=  "VALUES "; 
    428                                 $wp_sql .=    "($comment_ID, $post_id)";                 
     438                                $wp_sql .=    "($comment_ID, $post_id, $link_id, $d3f_forum_id, $blog_id)";              
    429439                                $xoops_db->query($wp_sql);                               
    430440                                if ($comment_approved ==0)      do_CommentWaiting($comment_ID, $post_id); 
     
    458468//  The content is reflected in the D3Forum comment when there is a change in the WordPress comment.  
    459469function wp_comment_sync_to_d3forum($comment_ID = 0,$sync_mode){ 
    460         global $xpress_config,$xoops_db,$xoops_config; 
     470        global $xpress_config,$xoops_db,$xoops_config,$wpdb,$blog_id; 
     471         
     472        if (empty($blog_id)) $blog_id =1; 
    461473         
    462474        if (!is_d3forum_setting()) die('The setting of the D3Forum comment integration is wrong. '); 
     
    468480        $d3forum_prefix = get_xoops_prefix() . $d3f_forum_dir . '_'; 
    469481        $xpress_prefix = get_wp_prefix(); 
    470         $wp_comments = $xpress_prefix . 'comments'; 
    471         $wp_posts = $xpress_prefix . 'posts'; 
     482        $wp_comments =  $wpdb->comments; 
     483//      $wp_comments = $xpress_prefix . 'comments'; 
     484        $wp_posts = $wpdb->posts; 
     485//      $wp_posts = $xpress_prefix . 'posts'; 
    472486        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    473487        $d3f_topic = $d3forum_prefix . 'topics'; 
     
    484498        $sql .= "WHERE (comment_ID = $comment_ID) AND ($wp_comments.comment_approved NOT LIKE 'spam') "; 
    485499 
    486         $row = $xoops_db->get_row($sql) ; 
     500//      $row = $xoops_db->get_row($sql) ; 
     501        $row = $wpdb->get_row($sql) ; 
    487502        if(empty($row)) die( 'READ ' . $wp_comments . '_NG...' .$sql); 
    488503        if (! empty($row->comment_type)) return; 
     
    513528        if ($sync_mode == 'delete'){ 
    514529                $mode = 'delete'; 
    515                 $delete_post_id = $xoops_db->get_var("SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $comment_ID"); 
     530                $delete_post_id = $xoops_db->get_var("SELECT post_id FROM $wp_d3forum_link WHERE comment_ID = $comment_ID AND  blog_id = $blog_id"); 
    516531                if (empty($delete_post_id)) return; 
    517532                $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"); 
     
    528543                         
    529544                        // if comment on same ID exists then edits comment else reply comment 
    530                         $row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID") ; 
     545                        $row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID AND blog_id = $blog_id" ) ; 
    531546                         
    532547                        if (!empty($row)){ 
     
    629644                         
    630645                        $wp_sql  = "INSERT INTO $wp_d3forum_link "; 
    631                         $wp_sql .=    "(comment_ID , post_id) "; 
     646                        $wp_sql .=    "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) "; 
    632647                        $wp_sql .=  "VALUES "; 
    633                         $wp_sql .=    "($comment_ID, $post_id)"; 
     648                        $wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id, $d3f_forum_id, $blog_id)";               
    634649                        $xoops_db->query($wp_sql); 
    635650                         
     
    666681                         
    667682                        $wp_sql  = "INSERT INTO $wp_d3forum_link "; 
    668                         $wp_sql .=    "(comment_ID , post_id , wp_post_ID) "; 
     683                        $wp_sql .=    "(comment_ID , post_id , wp_post_ID, forum_id, blog_id) "; 
    669684                        $wp_sql .=  "VALUES "; 
    670                         $wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id)";                
     685                        $wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id, $d3f_forum_id, $blog_id)";               
    671686                        $xoops_db->query($wp_sql); 
    672687 
     
    701716function wp_d3forum_delete_post_recursive( $d3forum_dirname , $post_id ,$isChild = false) 
    702717{ 
     718        global $wpdb,$blog_id; 
     719        global $xpress_config,$xoops_db; 
    703720        $post_id = intval( $post_id ) ; // post_id is d3forum post(comments) id. 
    704         global $xpress_config,$xoops_db; 
     721        if (empty($blog_id)) $blog_id =1; 
     722 
     723         
    705724        $d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_'; 
    706725        $xpress_prefix = get_wp_prefix(); 
     
    718737        $xoops_db->query( "DELETE FROM ".$d3forum_prefix."post_votes WHERE post_id=$post_id" ) ; 
    719738         
    720         $wp_comments = $xpress_prefix . 'comments'; 
    721         $wp_posts = $xpress_prefix . 'posts'; 
     739        $wp_comments = $wpdb->comments; 
     740        $wp_posts = $wpdb->posts; 
    722741        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    723742 
    724743        $comment_ID = get_wp_comment_ID($post_id);  // get wordpress comment ID 
    725744        if ($comment_ID > 0){ 
    726                 $comment_post_ID = $xoops_db->get_var("SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID"); 
     745                $comment_post_ID = $wpdb->get_var("SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID"); 
    727746                if ($isChild){          //The first comment is deleted on the WordPress side.  
    728                         $xoops_db->query("DELETE FROM $wp_comments WHERE comment_ID = $comment_ID"); 
     747                        $wpdb->query("DELETE FROM $wp_comments WHERE comment_ID = $comment_ID"); 
    729748                        if (!empty($comment_post_ID)){ 
    730                                 $xoops_db->query("UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID"); 
     749                                $wpdb->query("UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID"); 
    731750                        } 
    732751                }        
    733                 $xoops_db->query("DELETE FROM $wp_d3forum_link WHERE post_id = $post_id"); 
     752                $xoops_db->query("DELETE FROM $wp_d3forum_link WHERE post_id = $post_id AND blog_id = $blog_id"); 
    734753        } 
    735754} 
     
    741760        global $xpress_config,$xoops_db; 
    742761        $d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_'; 
    743         $xpress_prefix = get_wp_prefix(); 
    744762 
    745763        $topic_id = intval( $topic_id ) ; 
Note: See TracChangeset for help on using the changeset viewer.