XPressME Integration Kit

Trac

Changeset 106


Ignore:
Timestamp:
Mar 14, 2009, 11:27:03 PM (15 years ago)
Author:
toemon
Message:

D3Forumコメント統合で WP側からのコメント追加編集削除をD3Forum側へ同期する部分を完了
後は、一括のエクスポート、インポート機能の実装でD3Forumコメント統合は終わり

File:
1 edited

Legend:

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

    r105 r106  
    569569        switch($mode){ 
    570570                case 'edit': 
    571                         $sql = "SELECT pid  FROM $d3f_posts WHERE post_id= $edit_post_id "; 
    572                         $edit_post_pid = $xoops_db->get_var($sql); 
    573                         if(empty($edit_post_pid)) die( 'READ ' . $d3forum_comments . '_NG...' .$sql); 
     571                        $edit_post = $xoops_db->get_row("SELECT * FROM $d3f_posts WHERE post_id= $edit_post_id "); 
     572                        if(empty($edit_post)) die( 'READ ' . $d3forum_comments . '_NG...' .$sql); 
    574573                        // approval 
    575574                        if( $approval ) { 
     
    593592                        $sql = "UPDATE ".$d3f_posts." SET $set4sql WHERE post_id=$edit_post_id"; 
    594593                        $xoops_db->query($sql); 
    595                         if( ! $xoops_db->query($sql) ) die( "DB ERROR IN UPDATE post" ) ; 
     594                        $xoops_db->query($sql) ; 
    596595                        if ($edit_post_pid == 0){ 
    597596                                $sql = "UPDATE ".$d3f_topic." SET topic_invisible=$topic_invisible WHERE topic_id=$topic_id"; 
    598                                 if( ! $xoops_db->query($sql) ) die( "DB ERROR IN UPDATE post" ) ; 
     597                                $xoops_db->query($sql); 
    599598                        } 
    600599                        wp_d3forum_sync_topic( $d3forum_dirname , $topic_id , true , ! $edit_post_pid ) ; 
     
    620619                        // create post under specified post_id 
    621620                        $sql = "INSERT INTO ".$d3f_posts." SET $set4sql,pid=$reply_pid,topic_id=$topic_id,post_time=$post_time,poster_ip=$poster_ip"; 
    622                         if( ! $xoops_db->query($sql) ) die( "DB ERROR IN INSERT post $sql" ) ; 
     621                        $xoops_db->query($sql) ; 
    623622                        $post_id = mysql_insert_id(); 
    624623                        wp_d3forum_sync_topic( $d3forum_dirname , $topic_id ) ; 
     
    653652                        // create topic and get a new topic_id 
    654653                        $sql = "INSERT INTO ".$d3f_topic." SET forum_id=$forum_id,topic_invisible=$topic_invisible,topic_external_link_id='".addslashes($topic_external_link_id)."'"; 
    655                         if( ! $xoops_db->query($sql) ) die( "DB ERROR IN INSERT topic $sql" ) ; 
     654                        $xoops_db->query($sql) ; 
    656655                        $topic_id = mysql_insert_id(); 
    657656                        // create post in the topic 
    658657                        $sql = "INSERT INTO ".$d3f_posts." SET $set4sql,topic_id=$topic_id,post_time=$post_time,poster_ip=$poster_ip"; 
    659                         if( ! $xoops_db->query($sql) ) die( "DB ERROR IN INSERT post $sql" ) ; 
     658                        $xoops_db->query($sql) ; 
    660659                        $post_id = mysql_insert_id(); 
    661660                        wp_d3forum_sync_topic( $d3forum_dirname , $topic_id , true , true ) ; 
     
    697696function wp_d3forum_delete_post_recursive( $d3forum_dirname , $post_id ,$isChild = false) 
    698697{ 
    699         $post_id = intval( $post_id ) ; 
     698        $post_id = intval( $post_id ) ; // post_id is d3forum post(comments) id. 
    700699        global $XPressME,$xoops_db; 
    701700        $d3forum_prefix = get_xoops_prefix() . $d3forum_dirname . '_'; 
    702701        $xpress_prefix = get_wp_prefix(); 
    703702         
     703        $topic_id = $xoops_db->get_var("SELECT topic_id FROM ".$d3forum_prefix."posts WHERE post_id=$post_id"); 
     704         
     705        //It deletes it if there is a child comment.  
    704706        $sql = "SELECT post_id FROM ".$d3forum_prefix ."posts"." WHERE pid=$post_id" ; 
    705         $found_id = $xoops_db->get_var($sql);  
    706         if( empty($found_id))  die( "DB ERROR in wp_d3forum_delete_post_recursive ($sql)" ) ; 
    707  
    708         list( $topic_id ) = $xoops_db->get_results( "SELECT topic_id FROM ".$d3forum_prefix."posts WHERE post_id=$post_id" ); 
    709         $sql = "SELECT * FROM ".$d3forum_prefix."posts"." WHERE post_id=$post_id"; 
    710         $topics= $xoops_db->get_results($sql); 
    711         foreach($topics as $topic){ 
    712                 $child_post_id = $topic->post_id ; 
    713                 wp_d3forum_delete_post_recursive( $d3forum_dirname , $child_post_id ,true) ; 
    714         } 
    715  
     707        $child_comments = $xoops_db->get_results("SELECT post_id FROM ".$d3forum_prefix ."posts"." WHERE pid=$post_id");  
     708        foreach($child_comments as $child_comment){ 
     709                        wp_d3forum_delete_post_recursive( $d3forum_dirname , $child_comment->post_id ,true) ; 
     710        } 
    716711        wp_d3forum_transact_make_post_history( $d3forum_dirname , $post_id , true ) ; 
    717         $xoops_db->query( "DELETE FROM ".$d3forum_prefix."_posts WHERE post_id=$post_id" ) ; 
    718         $xoops_db->query( "DELETE FROM ".$d3forum_prefix."_post_votes WHERE post_id=$post_id" ) ; 
     712        $xoops_db->query( "DELETE FROM ".$d3forum_prefix."posts WHERE post_id=$post_id" ) ; 
     713        $xoops_db->query( "DELETE FROM ".$d3forum_prefix."post_votes WHERE post_id=$post_id" ) ; 
    719714         
    720715        $wp_comments = $xpress_prefix . 'comments'; 
     
    722717        $wp_d3forum_link = $xpress_prefix . 'd3forum_link'; 
    723718 
    724         $comment_ID = get_wp_comment_ID($post_id); 
     719        $comment_ID = get_wp_comment_ID($post_id);  // get wordpress comment ID 
    725720        if ($comment_ID > 0){ 
    726                 $sql = "SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID"; 
    727                 $comment_post_ID = $xoops_db->get_var($sql); 
    728  
     721                $comment_post_ID = $xoops_db->get_var("SELECT comment_post_ID FROM $wp_comments WHERE comment_ID = $comment_ID"); 
    729722                if ($isChild){          //The first comment is deleted on the WordPress side.  
    730                         $wp_sql = "DELETE FROM $wp_comments WHERE comment_ID = $comment_ID"; 
    731                         $xoops_db->query($wp_sql); 
     723                        $xoops_db->query("DELETE FROM $wp_comments WHERE comment_ID = $comment_ID"); 
    732724                        if (!empty($comment_post_ID)){ 
    733                                 $wp_sql  = "UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID"; 
    734                                 $xoops_db->query($wp_sql); 
    735                         } 
    736                 }                
    737                 $wp_sql = "DELETE FROM $wp_d3forum_link WHERE post_id = $post_id"; 
    738                 $xoops_db->query($wp_sql); 
     725                                $xoops_db->query("UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID"); 
     726                        } 
     727                }        
     728                $xoops_db->query("DELETE FROM $wp_d3forum_link WHERE post_id = $post_id"); 
    739729        } 
    740730} 
     
    752742        // delete posts 
    753743        if( $delete_also_posts ) { 
    754                 $sql = "SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id" ; 
    755                 $posts = $xoops_db->query($sql); 
    756                 if( empty($posts)) die( 'SQL ERROR '.__LINE__ ) ; 
    757                 foreach($posts as $post){ 
    758                         wp_d3forum_delete_post_recursive( $d3forum_dirname , $post->post_id ) ; 
     744                $posts = $xoops_db->query("SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id"); 
     745                if( !empty($posts)) { 
     746                        foreach($posts as $post){ 
     747                                wp_d3forum_delete_post_recursive( $d3forum_dirname , $post->post_id ) ; 
     748                        } 
    759749                } 
    760750        } 
     
    763753 
    764754        // delete topic 
    765         if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" )) die( 'SQL ERROR '.__LINE__ ) ; 
    766  
     755        $xoops_db->query( "DELETE FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" ); 
    767756        // delete u2t 
    768         if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."users2topics WHERE topic_id=$topic_id" )) die( 'SQL ERROR '.__LINE__ ) ; 
     757        $xoops_db->query( "DELETE FROM ".$d3forum_prefix."users2topics WHERE topic_id=$topic_id" ); 
    769758} 
    770759 
     
    780769        $topic_id = intval( $topic_id ) ; 
    781770 
    782         $sql = "SELECT forum_id FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" ; 
    783         if( ! $forum_id = $xoops_db->get_var($sql) ) die( "ERROR SELECT topic in sync topic" ) ; 
    784  
     771        $forum_id = $xoops_db->get_var("SELECT forum_id FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id"); 
    785772 
    786773        // get first_post_id 
    787         $sql = "SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id AND pid=0" ; 
    788         if( ! $first_post_id = $xoops_db->get_var($sql) ) die( "ERROR SELECT first_post in sync topic" ) ; 
     774        $first_post_id = $xoops_db->get_var("SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id AND pid=0"); 
    789775 
    790776        // get last_post_id and total_posts 
    791777        $sql = "SELECT MAX(post_id) as last_post_id,COUNT(post_id) as total_posts FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id" ; 
    792         if( ! $row = $xoops_db->get_row($sql) ) die( "ERROR SELECT last_post in sync topic" ) ; 
     778        $row = $xoops_db->get_row($sql); 
    793779        $last_post_id = $row->last_post_id; 
    794780        $total_posts = $row->total_posts; 
     
    812798                $topictitle4set = $sync_topic_title ? "topic_title='".addslashes($first_subject)."'," : "" ; 
    813799 
    814                 if( ! $xoops_db->query( "UPDATE ".$d3forum_prefix."topics SET {$topictitle4set} topic_posts_count=$total_posts, topic_first_uid=$first_uid, topic_first_post_id=$first_post_id, topic_first_post_time=$first_post_time, topic_last_uid=$last_uid, topic_last_post_id=$last_post_id, topic_last_post_time=$last_post_time WHERE topic_id=$topic_id" ) ) die( 'SQL ERROR '.__LINE__ ) ; 
     800                $xoops_db->query( "UPDATE ".$d3forum_prefix."topics SET {$topictitle4set} topic_posts_count=$total_posts, topic_first_uid=$first_uid, topic_first_post_id=$first_post_id, topic_first_post_time=$first_post_time, topic_last_uid=$last_uid, topic_last_post_id=$last_post_id, topic_last_post_time=$last_post_time WHERE topic_id=$topic_id" ); 
    815801 
    816802                // rebuild tree informations 
     
    899885        $posts_count = $row->posts_count; 
    900886 
    901         if( ! $result = $xoops_db->query( "UPDATE ".$d3forum_prefix."forums SET forum_topics_count=".intval($topics_count).",forum_posts_count=".intval($posts_count).", forum_last_post_id=".intval($last_post_id).", forum_last_post_time=".intval($last_post_time)." WHERE forum_id=$forum_id" ) ) die( 'SQL ERROR '.__LINE__ ) ; 
     887        $xoops_db->query( "UPDATE ".$d3forum_prefix."forums SET forum_topics_count=".intval($topics_count).",forum_posts_count=".intval($posts_count).", forum_last_post_id=".intval($last_post_id).", forum_last_post_time=".intval($last_post_time)." WHERE forum_id=$forum_id" ) ; 
    902888 
    903889        if( $sync_also_category ) return wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) ; 
     
    905891} 
    906892 
     893function get_d3forum_all_child_catid($d3forum_prefix,$sel_id, $order="", $idarray = array()) 
     894{ 
     895        global $xoops_db; 
     896        $sql = "SELECT * FROM ".$d3forum_prefix."categories WHERE pid =".$sel_id.""; 
     897        if ( $order != "" ) { 
     898                $sql .= " ORDER BY $order"; 
     899        } 
     900        $categories =$xoops_db->get_results($sql); 
     901        if ( empty($cat_ids)) { 
     902                return $idarray; 
     903        } 
     904        foreach( categories as $categorie ) { 
     905                $r_id = $categorie->cat_id; 
     906                array_push($idarray, $r_id); 
     907                $idarray = get_d3forum_all_child_catid($d3forum_prefix, $r_id,$order,$idarray); 
     908        } 
     909        return $idarray; 
     910} 
     911 
    907912// store redundant informations to a category from its forums 
    908913function wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) 
     
    914919 
    915920        // get children 
    916         include_once get_xoops_root_path()."/class/xoopstree.php" ; 
    917         $mytree = new XoopsTree( $d3forum_prefix."categories" , "cat_id" , "pid" ) ; 
    918         $children = $mytree->getAllChildId( $cat_id ) ; 
     921        $children = get_d3forum_all_child_catid( $d3forum_prefix."categories" , $cat_id ) ; 
    919922        $children[] = $cat_id ; 
    920923        $children = array_map( 'intval' , $children ) ; 
     
    937940 
    938941        // update query 
    939         if( ! $result = $xoops_db->query( "UPDATE ".$d3forum_prefix."categories SET cat_topics_count=".intval($topics_count).",cat_posts_count=".intval($posts_count).", cat_last_post_id=".intval($last_post_id).", cat_last_post_time=".intval($last_post_time).",cat_topics_count_in_tree=".intval($topics_count_in_tree).",cat_posts_count_in_tree=".intval($posts_count_in_tree).", cat_last_post_id_in_tree=".intval($last_post_id_in_tree).", cat_last_post_time_in_tree=".intval($last_post_time_in_tree)." WHERE cat_id=$cat_id" ) ) die( 'SQL ERROR '.__LINE__ ) ; 
     942        $xoops_db->query( "UPDATE ".$d3forum_prefix."categories SET cat_topics_count=".intval($topics_count).",cat_posts_count=".intval($posts_count).", cat_last_post_id=".intval($last_post_id).", cat_last_post_time=".intval($last_post_time).",cat_topics_count_in_tree=".intval($topics_count_in_tree).",cat_posts_count_in_tree=".intval($posts_count_in_tree).", cat_last_post_id_in_tree=".intval($last_post_id_in_tree).", cat_last_post_time_in_tree=".intval($last_post_time_in_tree)." WHERE cat_id=$cat_id" ); 
    940943 
    941944        // do sync parents 
     
    972975        } 
    973976 
    974         if( ! $xoops_db->query( "INSERT INTO ".$d3forum_prefix."post_histories SET post_id=$post_id, history_time=UNIX_TIMESTAMP(), data='".mysql_real_escape_string( serialize( $data ) )."'" ) ) die( "DB ERROR ON making post_history".__LINE__ ) ; 
     977        $xoops_db->query( "INSERT INTO ".$d3forum_prefix."post_histories SET post_id=$post_id, history_time=UNIX_TIMESTAMP(), data='".mysql_real_escape_string( serialize( $data ) )."'" ) ; 
    975978} 
    976979 
Note: See TracChangeset for help on using the changeset viewer.