XPressME Integration Kit

Trac

Changeset 105 for trunk


Ignore:
Timestamp:
Mar 14, 2009, 12:40:43 PM (16 years ago)
Author:
toemon
Message:

D3Forumコメント統合 WPからD3Fへの同期機能 暫定版

File:
1 edited

Legend:

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

    r104 r105  
    3131{ 
    3232        global $wpdb; 
    33         $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $commentID"); 
     33        $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 
    3434        if (!empty($comment_type)) return ;      
    3535        return wp_comment_sync_to_d3forum($comment_ID,'post'); 
     
    3838{ 
    3939        global $wpdb; 
    40         $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $commentID"); 
     40        $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 
    4141        if (!empty($comment_type)) return ;      
    4242        return wp_comment_sync_to_d3forum($comment_ID,'edit'); 
     
    4545{ 
    4646        global $wpdb; 
    47         $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $commentID"); 
     47        $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 
    4848        if (!empty($comment_type)) return ;      
    4949        return wp_comment_sync_to_d3forum($comment_ID,'delete'); 
     
    6666} 
    6767 
    68 function onaction_comment_apobe($commentID){ 
     68function onaction_comment_apobe($comment_ID){ 
    6969        global $wpdb; 
    70         $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $commentID"); 
    71         $status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $commentID"); 
     70        $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 
     71        $status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $comment_ID"); 
    7272        if(is_null($status)) return; 
    73         //      $status = wp_get_comment_status($commentID); 
     73        //      $status = wp_get_comment_status($comment_ID); 
    7474        switch($status){ 
    7575                case 'approved': 
    7676                case 1: 
    77                         if (empty($comment_type)) onaction_edit_comment($commentID); 
     77                        if (empty($comment_type)) onaction_edit_comment($comment_ID); 
    7878                        break; 
    7979                case 'unapproved': 
    8080                case 0: 
    81                         if (empty($comment_type)) onaction_edit_comment($commentID); 
     81                        if (empty($comment_type)) onaction_edit_comment($comment_ID); 
    8282                        break; 
    8383                default: 
     
    490490        $forum_id = $d3f_forum_id; 
    491491        $d3forum_dirname =$d3f_forum_dir; 
    492         $topic_external_link_id = $row->comment_post_ID; 
     492        $topic_external_link_id = $row->comment_post_ID; //There is information on WP post_ID in topic_external_link_id of D3Forum 
    493493        $topic_title = 'Re.' . addSlashes($row->post_title); 
    494494        $post_time = strtotime($row->comment_date);             // or   $row2['comment_date_gmt'] 
     
    513513                if (empty($topic_id)) return; 
    514514        }else{ 
     515                // Does the first comment (= topic) on the post exist? 
    515516                $sql  = "SELECT * FROM $d3f_topic WHERE topic_external_link_id = $topic_external_link_id AND forum_id = $forum_id"; 
    516517                $row = $xoops_db->get_row($sql) ; 
     518                $topic_first_post_id = $row->topic_first_post_id; 
    517519                if (empty($row)){ 
    518520                        $mode = $mode = 'newtopic'; 
    519521                } else { 
    520522                        $topic_id = $row->topic_id; 
    521                         $reply_pid = $row->topic_first_post_id; //reply_first_comment 
     523                         
     524                        // if comment on same ID exists then edits comment else reply comment 
    522525                        $row = $xoops_db->get_row("SELECT * FROM $wp_d3forum_link WHERE comment_ID = $comment_ID") ; 
     526                         
    523527                        if (!empty($row)){ 
    524528                                $mode = $mode = 'edit'; 
     
    531535                                } 
    532536                                if ($reply_pid == 0) { 
    533                                         $reply_pid = $row->topic_first_post_id; //reply_first_comment 
     537                                        $reply_pid = $topic_first_post_id; //reply_first_comment 
    534538                                } 
    535539                        } 
     
    624628                        $wp_sql .=  "VALUES "; 
    625629                        $wp_sql .=    "($comment_ID, $post_id)"; 
    626                         $xoops_db->query($sql); 
     630                        $xoops_db->query($wp_sql); 
    627631                         
    628632                        break; 
     
    661665                        $wp_sql .=  "VALUES "; 
    662666                        $wp_sql .=    "($comment_ID, $post_id, $topic_external_link_id)";                
    663                         $xoops_db->query($sql); 
     667                        $xoops_db->query($wp_sql); 
    664668 
    665669                        break; 
     
    750754                $sql = "SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id" ; 
    751755                $posts = $xoops_db->query($sql); 
    752                 if( empty($posts)) die( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     756                if( empty($posts)) die( 'SQL ERROR '.__LINE__ ) ; 
    753757                foreach($posts as $post){ 
    754758                        wp_d3forum_delete_post_recursive( $d3forum_dirname , $post->post_id ) ; 
     
    759763 
    760764        // delete topic 
    761         if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" )) die( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     765        if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" )) die( 'SQL ERROR '.__LINE__ ) ; 
    762766 
    763767        // delete u2t 
    764         if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."users2topics WHERE topic_id=$topic_id" )) die( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     768        if( ! $xoops_db->query( "DELETE FROM ".$d3forum_prefix."users2topics WHERE topic_id=$topic_id" )) die( 'SQL ERROR '.__LINE__ ) ; 
    765769} 
    766770 
     
    777781 
    778782        $sql = "SELECT forum_id FROM ".$d3forum_prefix."topics WHERE topic_id=$topic_id" ; 
    779         if( ! $results = $xoops_db->get_results($sql) ) die( "ERROR SELECT topic in sync topic" ) ; 
    780         list( $forum_id ) = $results ; 
     783        if( ! $forum_id = $xoops_db->get_var($sql) ) die( "ERROR SELECT topic in sync topic" ) ; 
     784 
    781785 
    782786        // get first_post_id 
    783787        $sql = "SELECT post_id FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id AND pid=0" ; 
    784         if( ! $results = $xoops_db->get_results($sql) ) die( "ERROR SELECT first_post in sync topic" ) ; 
    785         list( $first_post_id ) = $results ; 
     788        if( ! $first_post_id = $xoops_db->get_var($sql) ) die( "ERROR SELECT first_post in sync topic" ) ; 
    786789 
    787790        // get last_post_id and total_posts 
    788         $sql = "SELECT MAX(post_id),COUNT(post_id) FROM ".$d3forum_prefix."posts WHERE topic_id=$topic_id" ; 
    789         if( ! $results = $xoops_db->get_results($sql) ) die( "ERROR SELECT last_post in sync topic" ) ; 
    790         list( $last_post_id , $total_posts ) = $results ; 
     791        $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" ) ; 
     793        $last_post_id = $row->last_post_id; 
     794        $total_posts = $row->total_posts; 
    791795 
    792796        if( empty( $total_posts ) ) { 
     
    797801 
    798802                // update redundant columns in topics table 
    799                 list( $first_post_time , $first_uid , $first_subject , $unique_path ) = $xoops_db->get_results( "SELECT post_time,uid,subject,unique_path FROM ".$d3forum_prefix."posts WHERE post_id=$first_post_id" ) ; 
    800                 list( $last_post_time , $last_uid ) = $xoops_db->get_results( "SELECT post_time,uid FROM ".$d3forum_prefix."posts WHERE post_id=$last_post_id" )  ; 
    801  
     803                $row = $xoops_db->get_row( "SELECT post_time,uid,subject,unique_path FROM ".$d3forum_prefix."posts WHERE post_id=$first_post_id" ) ; 
     804                $first_post_time = $row->post_time; 
     805                $first_uid = $row->uid; 
     806                $first_subject = $row->subject; 
     807                $unique_path = $row->unique_path; 
     808                $row = $xoops_db->get_row( "SELECT post_time,uid FROM ".$d3forum_prefix."posts WHERE post_id=$last_post_id" ) ; 
     809                $last_post_time = $row->post_time; 
     810                $last_uid = $row->uid; 
    802811                // sync topic_title same as first post's subject if specified 
    803812                $topictitle4set = $sync_topic_title ? "topic_title='".addslashes($first_subject)."'," : "" ; 
    804813 
    805                 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( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     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__ ) ; 
    806815 
    807816                // rebuild tree informations 
    808                 $tree_array = wp_d3forum_maketree_recursive( $db->prefix($d3forum_dirname."_posts") , intval( $first_post_id ) , 'post_id' , array() , 0 , empty( $unique_path ) ? '.1' : $unique_path ) ; 
    809                 if( ! empty( $tree_array ) ) foreach( $tree_array as $key => $val ) { 
    810                         $xoops_db->query( "UPDATE ".$d3forum_prefix."posts SET depth_in_tree=".$val['depth'].", order_in_tree=".($key+1).", unique_path='".addslashes($val['unique_path'])."' WHERE post_id=".$val['post_id'] ) ; 
    811                 } 
    812         } 
    813  
    814         if( $sync_also_forum ) return wp_d3forum_sync_forum( $d3forum_dirname , $forum_id ) ; 
    815         else return true ; 
     817                $tree_array = wp_d3forum_maketree_recursive( $d3forum_prefix."posts" , intval( $first_post_id ) , 'post_id' , array() , 0 , empty( $unique_path ) ? '.1' : $unique_path ) ; 
     818                if( ! empty( $tree_array ) ) { 
     819                        foreach( $tree_array as $key => $val ) { 
     820                                $xoops_db->query( "UPDATE ".$d3forum_prefix."posts SET depth_in_tree=".$val['depth'].", order_in_tree=".($key+1).", unique_path='".addslashes($val['unique_path'])."' WHERE post_id=".$val['post_id'] ) ; 
     821                        } 
     822                } 
     823        } 
     824 
     825        if( $sync_also_forum )  
     826                return wp_d3forum_sync_forum( $d3forum_dirname , $forum_id ) ; 
     827        else  
     828                return true ; 
    816829} 
    817830 
     
    828841        $new_post_ids = array() ; 
    829842        $max_count_of_last_level = 0 ; 
    830         while( list( $new_post_id , $new_unique_path ) = $db->fetchRow( $result ) ) { 
     843        foreach($result as $row){ 
     844                $new_post_id = $row->post_id; 
     845                $new_unique_path = $row->unique_path; 
    831846                $new_post_ids[ intval( $new_post_id ) ] = $new_unique_path ; 
    832847                if( ! empty( $new_unique_path ) ) { 
     
    857872                return $parray ; 
    858873        } 
    859         while( list( $new_cat_id , $new_cat_title ) = $results ) { 
     874        foreach($result as $row){ 
     875                $new_cat_id = $row->cat_id; 
     876                $new_cat_title = $row->cat_title; 
    860877                $parray = wp_d3forum_makecattree_recursive( $tablename , $new_cat_id , $order , $parray , $depth + 1 , $new_cat_title ) ; 
    861878        } 
     
    873890 
    874891        $sql = "SELECT cat_id FROM ".$d3forum_prefix."forums WHERE forum_id=$forum_id" ; 
    875         if( ! $results = $xoops_db->get_results( $sql ) ) die( "ERROR SELECT forum in sync forum" ) ; 
    876         list( $cat_id ) = $results ; 
    877  
    878         $sql = "SELECT MAX(topic_last_post_id),MAX(topic_last_post_time),COUNT(topic_id),SUM(topic_posts_count) FROM ".$d3forum_prefix."topics WHERE forum_id=$forum_id" ; 
    879         if( ! $results = $xoops_db->get_results( $sql ) ) die( "ERROR SELECT topics in sync forum" ) ; 
    880         list( $last_post_id , $last_post_time , $topics_count , $posts_count ) = $results ; 
    881  
    882         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( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     892        if( ! $cat_id = $xoops_db->get_var( $sql ) ) die( "ERROR SELECT forum in sync forum" ) ; 
     893 
     894        $sql = "SELECT MAX(topic_last_post_id) as last_post_id ,MAX(topic_last_post_time) as last_post_time ,COUNT(topic_id) as topics_count,SUM(topic_posts_count) as posts_count FROM ".$d3forum_prefix."topics WHERE forum_id=$forum_id" ; 
     895        if( ! $row = $xoops_db->get_row( $sql ) ) die( "ERROR SELECT topics in sync forum" ) ; 
     896        $last_post_id = $row->last_post_id; 
     897        $last_post_time = $row->last_post_time; 
     898        $topics_count = $row->topics_count; 
     899        $posts_count = $row->posts_count; 
     900 
     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__ ) ; 
    883902 
    884903        if( $sync_also_category ) return wp_d3forum_sync_category( $d3forum_dirname , $cat_id ) ; 
     
    902921 
    903922        // topics/posts information belonging this category directly 
    904         $sql = "SELECT MAX(forum_last_post_id),MAX(forum_last_post_time),SUM(forum_topics_count),SUM(forum_posts_count) FROM ".$d3forum_prefix."forums WHERE cat_id=$cat_id" ; 
    905         if( ! $results = $xoops_db->get_results( $sql ) ) die( "ERROR SELECT forum in sync category" ) ; 
    906         list( $last_post_id , $last_post_time , $topics_count , $posts_count ) = $results ; 
     923        $sql = "SELECT MAX(forum_last_post_id) as last_post_id,MAX(forum_last_post_time) as last_post_time,SUM(forum_topics_count) as topics_count,SUM(forum_posts_count) as posts_count FROM ".$d3forum_prefix."forums WHERE cat_id=$cat_id" ; 
     924        if( ! $row = $xoops_db->get_row( $sql ) ) die( "ERROR SELECT forum in sync category" ) ; 
     925        $last_post_id = $row->last_post_id ; 
     926        $last_post_time = $row->last_post_time ; 
     927        $topics_count = $row->topics_count ; 
     928        $posts_count = $row->posts_count ; 
    907929 
    908930        // topics/posts information belonging this category and/or subcategories 
    909         $sql = "SELECT MAX(forum_last_post_id),MAX(forum_last_post_time),SUM(forum_topics_count),SUM(forum_posts_count) FROM ".$d3forum_prefix."forums WHERE cat_id IN (".implode(",",$children).")" ; 
    910         if( ! $results = $xoops_db->get_results( $sql ) ) die( "ERROR SELECT forum in sync category" ) ; 
    911         list( $last_post_id_in_tree , $last_post_time_in_tree , $topics_count_in_tree , $posts_count_in_tree ) = $results ; 
     931        $sql = "SELECT MAX(forum_last_post_id) as last_post_id_in_tree,MAX(forum_last_post_time) as last_post_time_in_tree,SUM(forum_topics_count) as topics_count_in_tree,SUM(forum_posts_count) as posts_count_in_tree FROM ".$d3forum_prefix."forums WHERE cat_id IN (".implode(",",$children).")" ; 
     932        if( ! $row = $xoops_db->get_row( $sql ) ) die( "ERROR SELECT forum in sync category" ) ; 
     933        $last_post_id_in_tree = $row->last_post_id_in_tree ; 
     934        $last_post_time_in_tree = $row->last_post_time_in_tree ; 
     935        $topics_count_in_tree = $row->topics_count_in_tree ; 
     936        $posts_count_in_tree = $row->posts_count_in_tree ; 
    912937 
    913938        // update query 
    914         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( _MD_D3FORUM_ERR_SQL.__LINE__ ) ; 
     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__ ) ; 
    915940 
    916941        // do sync parents 
    917         list( $pid ) = $xoops_db->get_results( "SELECT pid FROM ".$d3forum_prefix."categories WHERE cat_id=$cat_id" )  ; 
     942        $pid = $xoops_db->get_var( "SELECT pid FROM ".$d3forum_prefix."categories WHERE cat_id=$cat_id" )  ; 
    918943        if( $pid != $cat_id && $pid > 0 ) { 
    919944                wp_d3forum_sync_category( $d3forum_dirname , $pid ) ; 
     
    941966 
    942967        // check the latest data in history 
    943         $results = $xoops_db->get_results( "SELECT data FROM ".$d3forum_prefix."post_histories WHERE post_id=$post_id ORDER BY history_time DESC" ) ; 
    944         if( !empty( $results ) ) { 
    945                 list( $old_data_serialized ) = $results ; 
     968        $old_data_serialized = $xoops_db->get_var( "SELECT data FROM ".$d3forum_prefix."post_histories WHERE post_id=$post_id ORDER BY history_time DESC" ) ; 
     969        if( !empty( $old_data_serialized ) ) { 
    946970                $old_data = unserialize( $old_data_serialized ) ; 
    947971                if( $old_data == $data ) return ; 
Note: See TracChangeset for help on using the changeset viewer.